odb: use HandleList for C function callbacks.

This commit is contained in:
Patrick Steinhardt 2015-04-24 09:55:06 +02:00
parent 9bbec34885
commit e919653755
2 changed files with 11 additions and 4 deletions

13
odb.go
View File

@ -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 {

View File

@ -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