rados: C-allocate return parameters in GetOmapStep

Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
Sven Anderson 2021-10-11 23:09:35 +09:00 committed by mergify[bot]
parent bae93ac4ab
commit 3a7f2e2896
2 changed files with 12 additions and 8 deletions

View File

@ -99,8 +99,8 @@ type GetOmapStep struct {
// C returned data: // C returned data:
iter C.rados_omap_iter_t iter C.rados_omap_iter_t
more C.uchar more *C.uchar
rval C.int rval *C.int
// internal state: // internal state:
@ -116,6 +116,8 @@ func newGetOmapStep(startAfter, filterPrefix string, maxReturn uint64) *GetOmapS
maxReturn: maxReturn, maxReturn: maxReturn,
cStartAfter: C.CString(startAfter), cStartAfter: C.CString(startAfter),
cFilterPrefix: C.CString(filterPrefix), cFilterPrefix: C.CString(filterPrefix),
more: (*C.uchar)(C.malloc(C.sizeof_uchar)),
rval: (*C.int)(C.malloc(C.sizeof_int)),
} }
runtime.SetFinalizer(gos, opStepFinalizer) runtime.SetFinalizer(gos, opStepFinalizer)
return gos return gos
@ -127,8 +129,10 @@ func (gos *GetOmapStep) free() {
C.rados_omap_get_end(gos.iter) C.rados_omap_get_end(gos.iter)
} }
gos.iter = nil gos.iter = nil
gos.more = 0 C.free(unsafe.Pointer(gos.more))
gos.rval = 0 gos.more = nil
C.free(unsafe.Pointer(gos.rval))
gos.rval = nil
C.free(unsafe.Pointer(gos.cStartAfter)) C.free(unsafe.Pointer(gos.cStartAfter))
gos.cStartAfter = nil gos.cStartAfter = nil
C.free(unsafe.Pointer(gos.cFilterPrefix)) C.free(unsafe.Pointer(gos.cFilterPrefix))
@ -136,7 +140,7 @@ func (gos *GetOmapStep) free() {
} }
func (gos *GetOmapStep) update() error { func (gos *GetOmapStep) update() error {
err := getError(gos.rval) err := getError(*gos.rval)
gos.canIterate = (err == nil) gos.canIterate = (err == nil)
return err return err
} }
@ -168,7 +172,7 @@ func (gos *GetOmapStep) Next() (*OmapKeyValue, error) {
func (gos *GetOmapStep) More() bool { func (gos *GetOmapStep) More() bool {
// tad bit hacky, but go can't automatically convert from // tad bit hacky, but go can't automatically convert from
// unsigned char to bool // unsigned char to bool
return gos.more != 0 return *gos.more != 0
} }
// removeOmapKeysStep is a write operation step used to track state, especially // removeOmapKeysStep is a write operation step used to track state, especially

View File

@ -77,8 +77,8 @@ func (r *ReadOp) GetOmapValues(startAfter, filterPrefix string, maxReturn uint64
gos.cFilterPrefix, gos.cFilterPrefix,
C.uint64_t(gos.maxReturn), C.uint64_t(gos.maxReturn),
&gos.iter, &gos.iter,
&gos.more, gos.more,
&gos.rval, gos.rval,
) )
return gos return gos
} }