Fixes #513 - Segfault during tree walk
This commit is contained in:
parent
94786f9c8f
commit
75a20e5aeb
15
tree.go
15
tree.go
|
@ -47,7 +47,7 @@ func newTreeEntry(entry *C.git_tree_entry) *TreeEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tree) EntryByName(filename string) *TreeEntry {
|
func (t *Tree) EntryByName(filename string) *TreeEntry {
|
||||||
cname := C.CString(filename)
|
cname := C.CString(filename)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func (t Tree) EntryByName(filename string) *TreeEntry {
|
||||||
// free it, but you must not use it after the Tree is freed.
|
// free it, but you must not use it after the Tree is freed.
|
||||||
//
|
//
|
||||||
// Warning: this must examine every entry in the tree, so it is not fast.
|
// Warning: this must examine every entry in the tree, so it is not fast.
|
||||||
func (t Tree) EntryById(id *Oid) *TreeEntry {
|
func (t *Tree) EntryById(id *Oid) *TreeEntry {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func (t Tree) EntryById(id *Oid) *TreeEntry {
|
||||||
|
|
||||||
// EntryByPath looks up an entry by its full path, recursing into
|
// EntryByPath looks up an entry by its full path, recursing into
|
||||||
// deeper trees if necessary (i.e. if there are slashes in the path)
|
// deeper trees if necessary (i.e. if there are slashes in the path)
|
||||||
func (t Tree) EntryByPath(path string) (*TreeEntry, error) {
|
func (t *Tree) EntryByPath(path string) (*TreeEntry, error) {
|
||||||
cpath := C.CString(path)
|
cpath := C.CString(path)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
var entry *C.git_tree_entry
|
var entry *C.git_tree_entry
|
||||||
|
@ -102,7 +102,7 @@ func (t Tree) EntryByPath(path string) (*TreeEntry, error) {
|
||||||
return newTreeEntry(entry), nil
|
return newTreeEntry(entry), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tree) EntryByIndex(index uint64) *TreeEntry {
|
func (t *Tree) EntryByIndex(index uint64) *TreeEntry {
|
||||||
entry := C.git_tree_entry_byindex(t.cast_ptr, C.size_t(index))
|
entry := C.git_tree_entry_byindex(t.cast_ptr, C.size_t(index))
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -113,7 +113,7 @@ func (t Tree) EntryByIndex(index uint64) *TreeEntry {
|
||||||
return goEntry
|
return goEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tree) EntryCount() uint64 {
|
func (t *Tree) EntryCount() uint64 {
|
||||||
num := C.git_tree_entrycount(t.cast_ptr)
|
num := C.git_tree_entrycount(t.cast_ptr)
|
||||||
runtime.KeepAlive(t)
|
runtime.KeepAlive(t)
|
||||||
return uint64(num)
|
return uint64(num)
|
||||||
|
@ -122,9 +122,8 @@ func (t Tree) EntryCount() uint64 {
|
||||||
type TreeWalkCallback func(string, *TreeEntry) int
|
type TreeWalkCallback func(string, *TreeEntry) int
|
||||||
|
|
||||||
//export CallbackGitTreeWalk
|
//export CallbackGitTreeWalk
|
||||||
func CallbackGitTreeWalk(_root *C.char, _entry unsafe.Pointer, ptr unsafe.Pointer) C.int {
|
func CallbackGitTreeWalk(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer) C.int {
|
||||||
root := C.GoString(_root)
|
root := C.GoString(_root)
|
||||||
entry := (*C.git_tree_entry)(_entry)
|
|
||||||
|
|
||||||
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
||||||
return C.int(callback(root, newTreeEntry(entry)))
|
return C.int(callback(root, newTreeEntry(entry)))
|
||||||
|
@ -133,7 +132,7 @@ func CallbackGitTreeWalk(_root *C.char, _entry unsafe.Pointer, ptr unsafe.Pointe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tree) Walk(callback TreeWalkCallback) error {
|
func (t *Tree) Walk(callback TreeWalkCallback) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue