summaryrefslogtreecommitdiff
path: root/object.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-05-26 09:28:07 +0200
committerCarlos Martín Nieto <[email protected]>2014-05-26 09:28:07 +0200
commit8a73c75f1a68f2855d03e6d2ce45c95c414aa71a (patch)
tree967dae543c50f926ad728be38ffeaa3fefda7147 /object.go
parentf953d4e5c7c676cd3b3ee797fedce8823b5c930c (diff)
Keep a pointer to the repository in the objects and references
Otherwise, the garbage collector might decide it's a good idea to throw away the repository instance while the C object still has a pointer to it. Hilarity ensues.
Diffstat (limited to 'object.go')
-rw-r--r--object.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/object.go b/object.go
index 9241ae2..10f5f7c 100644
--- a/object.go
+++ b/object.go
@@ -27,6 +27,7 @@ type Object interface {
type gitObject struct {
ptr *C.git_object
+ repo *Repository
}
func (t ObjectType) String() (string) {
@@ -69,12 +70,16 @@ func (o *gitObject) Free() {
C.git_object_free(o.ptr)
}
-func allocObject(cobj *C.git_object) Object {
+func allocObject(cobj *C.git_object, repo *Repository) Object {
+ obj := gitObject{
+ ptr: cobj,
+ repo: repo,
+ }
switch ObjectType(C.git_object_type(cobj)) {
case ObjectCommit:
commit := &Commit{
- gitObject: gitObject{cobj},
+ gitObject: obj,
cast_ptr: (*C.git_commit)(cobj),
}
runtime.SetFinalizer(commit, (*Commit).Free)
@@ -82,7 +87,7 @@ func allocObject(cobj *C.git_object) Object {
case ObjectTree:
tree := &Tree{
- gitObject: gitObject{cobj},
+ gitObject: obj,
cast_ptr: (*C.git_tree)(cobj),
}
runtime.SetFinalizer(tree, (*Tree).Free)
@@ -90,7 +95,7 @@ func allocObject(cobj *C.git_object) Object {
case ObjectBlob:
blob := &Blob{
- gitObject: gitObject{cobj},
+ gitObject: obj,
cast_ptr: (*C.git_blob)(cobj),
}
runtime.SetFinalizer(blob, (*Blob).Free)