handles, merge, odb: changes for Go 1.6 pointer passing rules #282

Merged
ianlancetaylor merged 5 commits from master into master 2016-02-18 06:10:08 -06:00
1 changed files with 5 additions and 3 deletions
Showing only changes of commit dc8b154f4f - Show all commits

8
odb.go
View File

@ -76,13 +76,15 @@ func (v *Odb) Exists(oid *Oid) bool {
func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) {
oid = new(Oid)
cstr := C.CString(string(data))
defer C.free(unsafe.Pointer(cstr))
var cptr unsafe.Pointer
if len(data) > 0 {
cptr = unsafe.Pointer(&data[0])
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(cstr), C.size_t(len(data)), C.git_otype(otype))
ret := C.git_odb_write(oid.toC(), v.ptr, cptr, C.size_t(len(data)), C.git_otype(otype))
if ret < 0 {
return nil, MakeGitError(ret)