Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rados: Make "operation" code comply to pointer passing rules #597

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions rados/omap.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ type GetOmapStep struct {

// C returned data:
iter C.rados_omap_iter_t
more C.uchar
rval C.int
more *C.uchar
rval *C.int

// internal state:

Expand All @@ -116,6 +116,8 @@ func newGetOmapStep(startAfter, filterPrefix string, maxReturn uint64) *GetOmapS
maxReturn: maxReturn,
cStartAfter: C.CString(startAfter),
cFilterPrefix: C.CString(filterPrefix),
more: (*C.uchar)(C.malloc(C.sizeof_uchar)),
rval: (*C.int)(C.malloc(C.sizeof_int)),
}
runtime.SetFinalizer(gos, opStepFinalizer)
return gos
Expand All @@ -127,16 +129,18 @@ func (gos *GetOmapStep) free() {
C.rados_omap_get_end(gos.iter)
}
gos.iter = nil
gos.more = 0
gos.rval = 0
C.free(unsafe.Pointer(gos.more))
gos.more = nil
C.free(unsafe.Pointer(gos.rval))
gos.rval = nil
C.free(unsafe.Pointer(gos.cStartAfter))
gos.cStartAfter = nil
C.free(unsafe.Pointer(gos.cFilterPrefix))
gos.cFilterPrefix = nil
}

func (gos *GetOmapStep) update() error {
err := getError(gos.rval)
err := getError(*gos.rval)
gos.canIterate = (err == nil)
return err
}
Expand Down Expand Up @@ -168,7 +172,7 @@ func (gos *GetOmapStep) Next() (*OmapKeyValue, error) {
func (gos *GetOmapStep) More() bool {
// tad bit hacky, but go can't automatically convert from
// unsigned char to bool
return gos.more != 0
return *gos.more != 0
}

// removeOmapKeysStep is a write operation step used to track state, especially
Expand Down
4 changes: 2 additions & 2 deletions rados/read_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (r *ReadOp) GetOmapValues(startAfter, filterPrefix string, maxReturn uint64
gos.cFilterPrefix,
C.uint64_t(gos.maxReturn),
&gos.iter,
&gos.more,
&gos.rval,
gos.more,
gos.rval,
)
return gos
}
2 changes: 1 addition & 1 deletion rados/write_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type writeStep struct {
func newWriteStep(b []byte, writeLen, offset uint64) *writeStep {
return &writeStep{
b: b,
cBuffer: (*C.char)(unsafe.Pointer(&b[0])),
cBuffer: (*C.char)(unsafe.Pointer(&b[0])), // TODO: must be pinned
cDataLen: C.size_t(len(b)),
cWriteLen: C.size_t(writeLen),
cOffset: C.uint64_t(offset),
Expand Down