[WIP/RFC] Pointer indirection #196

Merged
pks-t merged 15 commits from pointer-indirection into master 2015-05-30 15:23:23 -05:00
2 changed files with 11 additions and 4 deletions
Showing only changes of commit e919653755 - Show all commits

13
odb.go
View File

@ -98,8 +98,12 @@ type foreachData struct {
} }
//export odbForEachCb //export odbForEachCb
func odbForEachCb(id *C.git_oid, payload unsafe.Pointer) int { func odbForEachCb(id *C.git_oid, handle unsafe.Pointer) int {
data := (*foreachData)(payload) data, ok := pointerHandles.Get(handle).(*foreachData)
if !ok {
panic("could not retrieve handle")
}
err := data.callback(newOidFromC(id)) err := data.callback(newOidFromC(id))
if err != nil { if err != nil {
@ -119,7 +123,10 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() 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 { if ret == C.GIT_EUSER {
return data.err return data.err
} else if ret < 0 { } else if ret < 0 {

View File

@ -81,7 +81,7 @@ func TestOdbForeach(t *testing.T) {
checkFatal(t, err) checkFatal(t, err)
if count != expect { if count != expect {
t.Fatalf("Expected %v objects, got %v") t.Fatalf("Expected %v objects, got %v", expect, count)
} }
expect = 1 expect = 1