commit: add keep-alives for those that need conversion to pointer receivers

We can't work on the copies here, we need to have pointer receivers so we know
we're keeping alive the object whose finalizer would free the unmanaged memory
we're working with.
This commit is contained in:
Carlos Martín Nieto 2017-07-07 23:36:04 +02:00
parent 5d466ffbc0
commit 0e9336be3f
1 changed files with 28 additions and 15 deletions

View File

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