diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-05-26 09:28:07 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-05-26 09:28:07 +0200 |
| commit | 8a73c75f1a68f2855d03e6d2ce45c95c414aa71a (patch) | |
| tree | 967dae543c50f926ad728be38ffeaa3fefda7147 /object.go | |
| parent | f953d4e5c7c676cd3b3ee797fedce8823b5c930c (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.go | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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) |
