summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2017-07-07 23:36:04 +0200
committerCarlos Martín Nieto <[email protected]>2017-07-07 23:36:04 +0200
commit0e9336be3f590b900a28a48b265dd2eab7836e03 (patch)
tree89cdcac7ed73d9c2033ec4889c0fbda8cd6f44d4
parent5d466ffbc00bc2fbde0f0589c70e23b8fc7cc7d9 (diff)
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.
-rw-r--r--commit.go43
1 files changed, 28 insertions, 15 deletions
diff --git a/commit.go b/commit.go
index fc04e1e..3ccb5da 100644
--- a/commit.go
+++ b/commit.go
@@ -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 {