KeepAlive all the things #393

Merged
carlosmn merged 5 commits from cmn/keepalive-all-the-things into master 2017-07-08 09:51:22 -05:00
1 changed files with 28 additions and 15 deletions
Showing only changes of commit 0e9336be3f - Show all commits

View File

@ -18,15 +18,19 @@ type Commit struct {
cast_ptr *C.git_commit cast_ptr *C.git_commit
} }
func (c Commit) Message() string { func (c *Commit) Message() string {
return C.GoString(C.git_commit_message(c.cast_ptr)) ret := C.GoString(C.git_commit_message(c.cast_ptr))
runtime.KeepAlive(c)
return ret
} }
func (c Commit) RawMessage() string { func (c *Commit) RawMessage() string {
return C.GoString(C.git_commit_message_raw(c.cast_ptr)) ret := C.GoString(C.git_commit_message_raw(c.cast_ptr))
runtime.KeepAlive(c)
return ret
} }
func (c Commit) ExtractSignature() (string, string, error) { func (c *Commit) ExtractSignature() (string, string, error) {
var c_signed C.git_buf var c_signed C.git_buf
defer C.git_buf_free(&c_signed) defer C.git_buf_free(&c_signed)
@ -40,7 +44,7 @@ func (c Commit) ExtractSignature() (string, string, error) {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_commit_extract_signature(&c_signature, &c_signed, repo, oid.toC(), nil) ret := C.git_commit_extract_signature(&c_signature, &c_signed, repo, oid.toC(), nil)
runtime.KeepAlive(oid)
if ret < 0 { if ret < 0 {
return "", "", MakeGitError(ret) return "", "", MakeGitError(ret)
} else { } else {
@ -49,17 +53,20 @@ func (c Commit) ExtractSignature() (string, string, error) {
} }
func (c Commit) Summary() string { func (c *Commit) Summary() string {
return C.GoString(C.git_commit_summary(c.cast_ptr)) ret := C.GoString(C.git_commit_summary(c.cast_ptr))
runtime.KeepAlive(c)
return ret
} }
func (c Commit) Tree() (*Tree, error) { func (c *Commit) Tree() (*Tree, error) {
var ptr *C.git_tree var ptr *C.git_tree
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
err := C.git_commit_tree(&ptr, c.cast_ptr) err := C.git_commit_tree(&ptr, c.cast_ptr)
runtime.KeepAlive(c)
if err < 0 { if err < 0 {
return nil, MakeGitError(err) return nil, MakeGitError(err)
} }
@ -67,18 +74,24 @@ func (c Commit) Tree() (*Tree, error) {
return allocTree(ptr, c.repo), nil return allocTree(ptr, c.repo), nil
} }
func (c Commit) TreeId() *Oid { func (c *Commit) TreeId() *Oid {
return newOidFromC(C.git_commit_tree_id(c.cast_ptr)) ret := newOidFromC(C.git_commit_tree_id(c.cast_ptr))
runtime.KeepAlive(c)
return c
} }
func (c Commit) Author() *Signature { func (c *Commit) Author() *Signature {
cast_ptr := C.git_commit_author(c.cast_ptr) cast_ptr := C.git_commit_author(c.cast_ptr)
return newSignatureFromC(cast_ptr) ret := newSignatureFromC(cast_ptr)
runtime.KeepAlive(c)
return ret
} }
func (c Commit) Committer() *Signature { func (c *Commit) Committer() *Signature {
cast_ptr := C.git_commit_committer(c.cast_ptr) cast_ptr := C.git_commit_committer(c.cast_ptr)
return newSignatureFromC(cast_ptr) ret := newSignatureFromC(cast_ptr)
runtime.KeepAlive(c)
return ret
} }
func (c *Commit) Parent(n uint) *Commit { func (c *Commit) Parent(n uint) *Commit {