odb: use HandleList for C function callbacks.
This commit is contained in:
parent
9bbec34885
commit
e919653755
13
odb.go
13
odb.go
|
@ -98,8 +98,12 @@ type foreachData struct {
|
|||
}
|
||||
|
||||
//export odbForEachCb
|
||||
func odbForEachCb(id *C.git_oid, payload unsafe.Pointer) int {
|
||||
data := (*foreachData)(payload)
|
||||
func odbForEachCb(id *C.git_oid, handle unsafe.Pointer) int {
|
||||
data, ok := pointerHandles.Get(handle).(*foreachData)
|
||||
|
||||
if !ok {
|
||||
panic("could not retrieve handle")
|
||||
}
|
||||
|
||||
err := data.callback(newOidFromC(id))
|
||||
if err != nil {
|
||||
|
@ -119,7 +123,10 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error {
|
|||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
ret := C._go_git_odb_foreach(v.ptr, unsafe.Pointer(&data))
|
||||
handle := pointerHandles.Track(&data)
|
||||
defer pointerHandles.Untrack(handle)
|
||||
|
||||
ret := C._go_git_odb_foreach(v.ptr, handle)
|
||||
if ret == C.GIT_EUSER {
|
||||
return data.err
|
||||
} else if ret < 0 {
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestOdbForeach(t *testing.T) {
|
|||
|
||||
checkFatal(t, err)
|
||||
if count != expect {
|
||||
t.Fatalf("Expected %v objects, got %v")
|
||||
t.Fatalf("Expected %v objects, got %v", expect, count)
|
||||
}
|
||||
|
||||
expect = 1
|
||||
|
|
Loading…
Reference in New Issue