From de45a4b8ed991cd46e64a1836e25dd9b182c821f Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 23 Apr 2015 10:33:00 +0200 Subject: submodule: use HandleList for C function callbacks --- submodule.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'submodule.go') diff --git a/submodule.go b/submodule.go index 7c6c922..0588ec5 100644 --- a/submodule.go +++ b/submodule.go @@ -97,17 +97,24 @@ func (repo *Repository) LookupSubmodule(name string) (*Submodule, error) { type SubmoduleCbk func(sub *Submodule, name string) int //export SubmoduleVisitor -func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, cfct unsafe.Pointer) C.int { +func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer) C.int { sub := &Submodule{(*C.git_submodule)(csub)} - fct := *(*SubmoduleCbk)(cfct) - return (C.int)(fct(sub, C.GoString(name))) + + if callback, ok := pointerHandles.Get(handle).(SubmoduleCbk); ok { + return (C.int)(callback(sub, C.GoString(name))) + } else { + return -1 + } } func (repo *Repository) ForeachSubmodule(cbk SubmoduleCbk) error { runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C._go_git_visit_submodule(repo.ptr, unsafe.Pointer(&cbk)) + handle := pointerHandles.Track(cbk) + defer pointerHandles.Untrack(handle) + + ret := C._go_git_visit_submodule(repo.ptr, handle) if ret < 0 { return MakeGitError(ret) } -- cgit v1.2.3 From d95932c84a2b9c926490def345d71d45bb19f344 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 22 May 2015 08:58:21 +0200 Subject: handles: panic when we cannot retrieve handle data --- index.go | 6 ++---- submodule.go | 2 +- tree.go | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'submodule.go') diff --git a/index.go b/index.go index c344bf8..c1bfb74 100644 --- a/index.go +++ b/index.go @@ -234,12 +234,10 @@ func (v *Index) RemoveAll(pathspecs []string, callback IndexMatchedPathCallback) //export indexMatchedPathCallback func indexMatchedPathCallback(cPath, cMatchedPathspec *C.char, payload unsafe.Pointer) int { - if payload == nil { - return 0 - } else if callback, ok := pointerHandles.Get(payload).(IndexMatchedPathCallback); ok { + if callback, ok := pointerHandles.Get(payload).(IndexMatchedPathCallback); ok { return callback(C.GoString(cPath), C.GoString(cMatchedPathspec)) } else { - return -1 + panic("invalid matched path callback") } } diff --git a/submodule.go b/submodule.go index 0588ec5..3882462 100644 --- a/submodule.go +++ b/submodule.go @@ -103,7 +103,7 @@ func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer) if callback, ok := pointerHandles.Get(handle).(SubmoduleCbk); ok { return (C.int)(callback(sub, C.GoString(name))) } else { - return -1 + panic("invalid submodule visitor callback") } } diff --git a/tree.go b/tree.go index 70a3a3f..cbba08b 100644 --- a/tree.go +++ b/tree.go @@ -97,7 +97,7 @@ func CallbackGitTreeWalk(_root unsafe.Pointer, _entry unsafe.Pointer, ptr unsafe if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok { return C.int(callback(root, newTreeEntry(entry))) } else { - return C.int(-1) + panic("invalid treewalk callback") } } -- cgit v1.2.3