[WIP/RFC] Pointer indirection #196

Merged
pks-t merged 15 commits from pointer-indirection into master 2015-05-30 15:23:23 -05:00
1 changed files with 9 additions and 3 deletions
Showing only changes of commit be3a626f2e - Show all commits

12
tree.go
View File

@ -93,19 +93,25 @@ type TreeWalkCallback func(string, *TreeEntry) int
func CallbackGitTreeWalk(_root unsafe.Pointer, _entry unsafe.Pointer, ptr unsafe.Pointer) C.int {
root := C.GoString((*C.char)(_root))
entry := (*C.git_tree_entry)(_entry)
callback := *(*TreeWalkCallback)(ptr)
return C.int(callback(root, newTreeEntry(entry)))
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
return C.int(callback(root, newTreeEntry(entry)))
} else {
return C.int(-1)
}
}
func (t Tree) Walk(callback TreeWalkCallback) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ptr := pointerHandles.Track(callback)
defer pointerHandles.Untrack(ptr)
err := C._go_git_treewalk(
t.cast_ptr,
C.GIT_TREEWALK_PRE,
unsafe.Pointer(&callback),
ptr,
)
if err < 0 {