Commit 08db2e2c authored by Carlos Martín Nieto's avatar Carlos Martín Nieto Committed by GitHub

Merge pull request #393 from libgit2/cmn/keepalive-all-the-things

KeepAlive all the things
parents 29c0b730 55a10961
...@@ -76,6 +76,7 @@ func (v *Repository) BlameFile(path string, opts *BlameOptions) (*Blame, error) ...@@ -76,6 +76,7 @@ func (v *Repository) BlameFile(path string, opts *BlameOptions) (*Blame, error)
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ecode := C.git_blame_file(&blamePtr, v.ptr, cpath, copts) ecode := C.git_blame_file(&blamePtr, v.ptr, cpath, copts)
runtime.KeepAlive(v)
if ecode < 0 { if ecode < 0 {
return nil, MakeGitError(ecode) return nil, MakeGitError(ecode)
} }
...@@ -88,11 +89,15 @@ type Blame struct { ...@@ -88,11 +89,15 @@ type Blame struct {
} }
func (blame *Blame) HunkCount() int { func (blame *Blame) HunkCount() int {
return int(C.git_blame_get_hunk_count(blame.ptr)) ret := int(C.git_blame_get_hunk_count(blame.ptr))
runtime.KeepAlive(blame)
return ret
} }
func (blame *Blame) HunkByIndex(index int) (BlameHunk, error) { func (blame *Blame) HunkByIndex(index int) (BlameHunk, error) {
ptr := C.git_blame_get_hunk_byindex(blame.ptr, C.uint32_t(index)) ptr := C.git_blame_get_hunk_byindex(blame.ptr, C.uint32_t(index))
runtime.KeepAlive(blame)
if ptr == nil { if ptr == nil {
return BlameHunk{}, ErrInvalid return BlameHunk{}, ErrInvalid
} }
...@@ -101,6 +106,7 @@ func (blame *Blame) HunkByIndex(index int) (BlameHunk, error) { ...@@ -101,6 +106,7 @@ func (blame *Blame) HunkByIndex(index int) (BlameHunk, error) {
func (blame *Blame) HunkByLine(lineno int) (BlameHunk, error) { func (blame *Blame) HunkByLine(lineno int) (BlameHunk, error) {
ptr := C.git_blame_get_hunk_byline(blame.ptr, C.size_t(lineno)) ptr := C.git_blame_get_hunk_byline(blame.ptr, C.size_t(lineno))
runtime.KeepAlive(blame)
if ptr == nil { if ptr == nil {
return BlameHunk{}, ErrInvalid return BlameHunk{}, ErrInvalid
} }
......
...@@ -21,13 +21,19 @@ type Blob struct { ...@@ -21,13 +21,19 @@ type Blob struct {
} }
func (v *Blob) Size() int64 { func (v *Blob) Size() int64 {
return int64(C.git_blob_rawsize(v.cast_ptr)) ret := int64(C.git_blob_rawsize(v.cast_ptr))
runtime.KeepAlive(v)
return ret
} }
func (v *Blob) Contents() []byte { func (v *Blob) Contents() []byte {
size := C.int(C.git_blob_rawsize(v.cast_ptr)) size := C.int(C.git_blob_rawsize(v.cast_ptr))
buffer := unsafe.Pointer(C.git_blob_rawcontent(v.cast_ptr)) buffer := unsafe.Pointer(C.git_blob_rawcontent(v.cast_ptr))
return C.GoBytes(buffer, size)
goBytes := C.GoBytes(buffer, size)
runtime.KeepAlive(v)
return goBytes
} }
func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) { func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
...@@ -53,6 +59,7 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) { ...@@ -53,6 +59,7 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
} }
ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size) ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
runtime.KeepAlive(repo)
if ecode < 0 { if ecode < 0 {
return nil, MakeGitError(ecode) return nil, MakeGitError(ecode)
} }
...@@ -102,16 +109,18 @@ func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, err ...@@ -102,16 +109,18 @@ func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, err
return nil, MakeGitError(ecode) return nil, MakeGitError(ecode)
} }
return newBlobWriteStreamFromC(stream), nil return newBlobWriteStreamFromC(stream, repo), nil
} }
type BlobWriteStream struct { type BlobWriteStream struct {
ptr *C.git_writestream ptr *C.git_writestream
repo *Repository
} }
func newBlobWriteStreamFromC(ptr *C.git_writestream) *BlobWriteStream { func newBlobWriteStreamFromC(ptr *C.git_writestream, repo *Repository) *BlobWriteStream {
stream := &BlobWriteStream{ stream := &BlobWriteStream{
ptr: ptr, ptr: ptr,
repo: repo,
} }
runtime.SetFinalizer(stream, (*BlobWriteStream).Free) runtime.SetFinalizer(stream, (*BlobWriteStream).Free)
...@@ -128,6 +137,7 @@ func (stream *BlobWriteStream) Write(p []byte) (int, error) { ...@@ -128,6 +137,7 @@ func (stream *BlobWriteStream) Write(p []byte) (int, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ecode := C._go_git_writestream_write(stream.ptr, ptr, size) ecode := C._go_git_writestream_write(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ecode < 0 { if ecode < 0 {
return 0, MakeGitError(ecode) return 0, MakeGitError(ecode)
} }
...@@ -147,6 +157,7 @@ func (stream *BlobWriteStream) Commit() (*Oid, error) { ...@@ -147,6 +157,7 @@ func (stream *BlobWriteStream) Commit() (*Oid, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ecode := C.git_blob_create_fromstream_commit(&oid, stream.ptr) ecode := C.git_blob_create_fromstream_commit(&oid, stream.ptr)
runtime.KeepAlive(stream)
if ecode < 0 { if ecode < 0 {
return nil, MakeGitError(ecode) return nil, MakeGitError(ecode)
} }
......
...@@ -88,6 +88,7 @@ func (repo *Repository) NewBranchIterator(flags BranchType) (*BranchIterator, er ...@@ -88,6 +88,7 @@ func (repo *Repository) NewBranchIterator(flags BranchType) (*BranchIterator, er
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ecode := C.git_branch_iterator_new(&ptr, repo.ptr, refType) ecode := C.git_branch_iterator_new(&ptr, repo.ptr, refType)
runtime.KeepAlive(repo)
if ecode < 0 { if ecode < 0 {
return nil, MakeGitError(ecode) return nil, MakeGitError(ecode)
} }
...@@ -106,6 +107,8 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo ...@@ -106,6 +107,8 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_create(&ptr, repo.ptr, cBranchName, target.cast_ptr, cForce) ret := C.git_branch_create(&ptr, repo.ptr, cBranchName, target.cast_ptr, cForce)
runtime.KeepAlive(repo)
runtime.KeepAlive(target)
if ret < 0 { if ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
...@@ -117,6 +120,7 @@ func (b *Branch) Delete() error { ...@@ -117,6 +120,7 @@ func (b *Branch) Delete() error {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_delete(b.Reference.ptr) ret := C.git_branch_delete(b.Reference.ptr)
runtime.KeepAlive(b.Reference)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -133,6 +137,7 @@ func (b *Branch) Move(newBranchName string, force bool) (*Branch, error) { ...@@ -133,6 +137,7 @@ func (b *Branch) Move(newBranchName string, force bool) (*Branch, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_move(&ptr, b.Reference.ptr, cNewBranchName, cForce) ret := C.git_branch_move(&ptr, b.Reference.ptr, cNewBranchName, cForce)
runtime.KeepAlive(b.Reference)
if ret < 0 { if ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
...@@ -145,6 +150,7 @@ func (b *Branch) IsHead() (bool, error) { ...@@ -145,6 +150,7 @@ func (b *Branch) IsHead() (bool, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_is_head(b.Reference.ptr) ret := C.git_branch_is_head(b.Reference.ptr)
runtime.KeepAlive(b.Reference)
switch ret { switch ret {
case 1: case 1:
return true, nil return true, nil
...@@ -165,6 +171,7 @@ func (repo *Repository) LookupBranch(branchName string, bt BranchType) (*Branch, ...@@ -165,6 +171,7 @@ func (repo *Repository) LookupBranch(branchName string, bt BranchType) (*Branch,
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_lookup(&ptr, repo.ptr, cName, C.git_branch_t(bt)) ret := C.git_branch_lookup(&ptr, repo.ptr, cName, C.git_branch_t(bt))
runtime.KeepAlive(repo)
if ret < 0 { if ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
...@@ -179,6 +186,7 @@ func (b *Branch) Name() (string, error) { ...@@ -179,6 +186,7 @@ func (b *Branch) Name() (string, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_name(&cName, b.Reference.ptr) ret := C.git_branch_name(&cName, b.Reference.ptr)
runtime.KeepAlive(b.Reference)
if ret < 0 { if ret < 0 {
return "", MakeGitError(ret) return "", MakeGitError(ret)
} }
...@@ -196,6 +204,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) { ...@@ -196,6 +204,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_remote_name(&nameBuf, repo.ptr, cName) ret := C.git_branch_remote_name(&nameBuf, repo.ptr, cName)
runtime.KeepAlive(repo)
if ret < 0 { if ret < 0 {
return "", MakeGitError(ret) return "", MakeGitError(ret)
} }
...@@ -212,6 +221,7 @@ func (b *Branch) SetUpstream(upstreamName string) error { ...@@ -212,6 +221,7 @@ func (b *Branch) SetUpstream(upstreamName string) error {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_set_upstream(b.Reference.ptr, cName) ret := C.git_branch_set_upstream(b.Reference.ptr, cName)
runtime.KeepAlive(b.Reference)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -225,6 +235,7 @@ func (b *Branch) Upstream() (*Reference, error) { ...@@ -225,6 +235,7 @@ func (b *Branch) Upstream() (*Reference, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_upstream(&ptr, b.Reference.ptr) ret := C.git_branch_upstream(&ptr, b.Reference.ptr)
runtime.KeepAlive(b.Reference)
if ret < 0 { if ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
...@@ -241,6 +252,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error) ...@@ -241,6 +252,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error)
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_branch_upstream_name(&nameBuf, repo.ptr, cName) ret := C.git_branch_upstream_name(&nameBuf, repo.ptr, cName)
runtime.KeepAlive(repo)
if ret < 0 { if ret < 0 {
return "", MakeGitError(ret) return "", MakeGitError(ret)
} }
......
...@@ -188,6 +188,7 @@ func (v *Repository) CheckoutHead(opts *CheckoutOpts) error { ...@@ -188,6 +188,7 @@ func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
defer freeCheckoutOpts(cOpts) defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_head(v.ptr, cOpts) ret := C.git_checkout_head(v.ptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -211,6 +212,7 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error { ...@@ -211,6 +212,7 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
defer freeCheckoutOpts(cOpts) defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_index(v.ptr, iptr, cOpts) ret := C.git_checkout_index(v.ptr, iptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -226,6 +228,7 @@ func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error { ...@@ -226,6 +228,7 @@ func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error {
defer freeCheckoutOpts(cOpts) defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_tree(v.ptr, tree.ptr, cOpts) ret := C.git_checkout_tree(v.ptr, tree.ptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
......
...@@ -66,6 +66,8 @@ func (v *Repository) Cherrypick(commit *Commit, opts CherrypickOptions) error { ...@@ -66,6 +66,8 @@ func (v *Repository) Cherrypick(commit *Commit, opts CherrypickOptions) error {
defer freeCherrypickOpts(cOpts) defer freeCherrypickOpts(cOpts)
ecode := C.git_cherrypick(v.ptr, commit.cast_ptr, cOpts) ecode := C.git_cherrypick(v.ptr, commit.cast_ptr, cOpts)
runtime.KeepAlive(v)
runtime.KeepAlive(commit)
if ecode < 0 { if ecode < 0 {
return MakeGitError(ecode) return MakeGitError(ecode)
} }
......
...@@ -18,15 +18,19 @@ type Commit struct { ...@@ -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)
...@@ -35,29 +39,34 @@ func (c Commit) ExtractSignature() (string, string, error) { ...@@ -35,29 +39,34 @@ func (c Commit) ExtractSignature() (string, string, error) {
defer C.git_buf_free(&c_signature) defer C.git_buf_free(&c_signature)
oid := c.Id() oid := c.Id()
repo := C.git_commit_owner(c.cast_ptr) repo := C.git_commit_owner(c.cast_ptr)
runtime.LockOSThread()
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 {
return C.GoString(c_signature.ptr), C.GoString(c_signed.ptr), nil return C.GoString(c_signature.ptr), C.GoString(c_signed.ptr), nil
} }
} }
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)
} }
...@@ -65,18 +74,24 @@ func (c Commit) Tree() (*Tree, error) { ...@@ -65,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 ret
} }
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 {
...@@ -86,15 +101,21 @@ func (c *Commit) Parent(n uint) *Commit { ...@@ -86,15 +101,21 @@ func (c *Commit) Parent(n uint) *Commit {
return nil return nil
} }
return allocCommit(cobj, c.repo) parent := allocCommit(cobj, c.repo)
runtime.KeepAlive(c)
return parent
} }
func (c *Commit) ParentId(n uint) *Oid { func (c *Commit) ParentId(n uint) *Oid {
return newOidFromC(C.git_commit_parent_id(c.cast_ptr, C.uint(n))) ret := newOidFromC(C.git_commit_parent_id(c.cast_ptr, C.uint(n)))
runtime.KeepAlive(c)
return ret
} }
func (c *Commit) ParentCount() uint { func (c *Commit) ParentCount() uint {
return uint(C.git_commit_parentcount(c.cast_ptr)) ret := uint(C.git_commit_parentcount(c.cast_ptr))
runtime.KeepAlive(c)
return ret
} }
func (c *Commit) Amend(refname string, author, committer *Signature, message string, tree *Tree) (*Oid, error) { func (c *Commit) Amend(refname string, author, committer *Signature, message string, tree *Tree) (*Oid, error) {
...@@ -127,6 +148,9 @@ func (c *Commit) Amend(refname string, author, committer *Signature, message str ...@@ -127,6 +148,9 @@ func (c *Commit) Amend(refname string, author, committer *Signature, message str
oid := new(Oid) oid := new(Oid)
cerr := C.git_commit_amend(oid.toC(), c.cast_ptr, cref, authorSig, committerSig, nil, cmsg, tree.cast_ptr) cerr := C.git_commit_amend(oid.toC(), c.cast_ptr, cref, authorSig, committerSig, nil, cmsg, tree.cast_ptr)
runtime.KeepAlive(oid)
runtime.KeepAlive(c)
runtime.KeepAlive(tree)
if cerr < 0 { if cerr < 0 {
return nil, MakeGitError(cerr) return nil, MakeGitError(cerr)
} }
......
...@@ -78,6 +78,7 @@ func (c *Config) AddFile(path string, level ConfigLevel, force bool) error { ...@@ -78,6 +78,7 @@ func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), cbool(force)) ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), cbool(force))
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -94,6 +95,7 @@ func (c *Config) LookupInt32(name string) (int32, error) { ...@@ -94,6 +95,7 @@ func (c *Config) LookupInt32(name string) (int32, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_get_int32(&out, c.ptr, cname) ret := C.git_config_get_int32(&out, c.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return 0, MakeGitError(ret) return 0, MakeGitError(ret)
} }
...@@ -110,6 +112,7 @@ func (c *Config) LookupInt64(name string) (int64, error) { ...@@ -110,6 +112,7 @@ func (c *Config) LookupInt64(name string) (int64, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_get_int64(&out, c.ptr, cname) ret := C.git_config_get_int64(&out, c.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return 0, MakeGitError(ret) return 0, MakeGitError(ret)
} }
...@@ -126,7 +129,9 @@ func (c *Config) LookupString(name string) (string, error) { ...@@ -126,7 +129,9 @@ func (c *Config) LookupString(name string) (string, error) {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
if ret := C.git_config_get_string_buf(&valBuf, c.ptr, cname); ret < 0 { ret := C.git_config_get_string_buf(&valBuf, c.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return "", MakeGitError(ret) return "", MakeGitError(ret)
} }
defer C.git_buf_free(&valBuf) defer C.git_buf_free(&valBuf)
...@@ -143,6 +148,7 @@ func (c *Config) LookupBool(name string) (bool, error) { ...@@ -143,6 +148,7 @@ func (c *Config) LookupBool(name string) (bool, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_get_bool(&out, c.ptr, cname) ret := C.git_config_get_bool(&out, c.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return false, MakeGitError(ret) return false, MakeGitError(ret)
} }
...@@ -162,7 +168,7 @@ func (c *Config) NewMultivarIterator(name, regexp string) (*ConfigIterator, erro ...@@ -162,7 +168,7 @@ func (c *Config) NewMultivarIterator(name, regexp string) (*ConfigIterator, erro
defer C.free(unsafe.Pointer(cregexp)) defer C.free(unsafe.Pointer(cregexp))
} }
iter := new(ConfigIterator) iter := &ConfigIterator{cfg: c}
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
...@@ -179,7 +185,7 @@ func (c *Config) NewMultivarIterator(name, regexp string) (*ConfigIterator, erro ...@@ -179,7 +185,7 @@ func (c *Config) NewMultivarIterator(name, regexp string) (*ConfigIterator, erro
// NewIterator creates an iterator over each entry in the // NewIterator creates an iterator over each entry in the
// configuration // configuration
func (c *Config) NewIterator() (*ConfigIterator, error) { func (c *Config) NewIterator() (*ConfigIterator, error) {
iter := new(ConfigIterator) iter := &ConfigIterator{cfg: c}
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
...@@ -195,7 +201,7 @@ func (c *Config) NewIterator() (*ConfigIterator, error) { ...@@ -195,7 +201,7 @@ func (c *Config) NewIterator() (*ConfigIterator, error) {
// NewIteratorGlob creates an iterator over each entry in the // NewIteratorGlob creates an iterator over each entry in the
// configuration whose name matches the given regular expression // configuration whose name matches the given regular expression
func (c *Config) NewIteratorGlob(regexp string) (*ConfigIterator, error) { func (c *Config) NewIteratorGlob(regexp string) (*ConfigIterator, error) {
iter := new(ConfigIterator) iter := &ConfigIterator{cfg: c}
cregexp := C.CString(regexp) cregexp := C.CString(regexp)
defer C.free(unsafe.Pointer(cregexp)) defer C.free(unsafe.Pointer(cregexp))
...@@ -221,6 +227,7 @@ func (c *Config) SetString(name, value string) (err error) { ...@@ -221,6 +227,7 @@ func (c *Config) SetString(name, value string) (err error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_set_string(c.ptr, cname, cvalue) ret := C.git_config_set_string(c.ptr, cname, cvalue)
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -241,6 +248,7 @@ func (c *Config) SetInt32(name string, value int32) (err error) { ...@@ -241,6 +248,7 @@ func (c *Config) SetInt32(name string, value int32) (err error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_set_int32(c.ptr, cname, C.int32_t(value)) ret := C.git_config_set_int32(c.ptr, cname, C.int32_t(value))
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -256,6 +264,7 @@ func (c *Config) SetInt64(name string, value int64) (err error) { ...@@ -256,6 +264,7 @@ func (c *Config) SetInt64(name string, value int64) (err error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_set_int64(c.ptr, cname, C.int64_t(value)) ret := C.git_config_set_int64(c.ptr, cname, C.int64_t(value))
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -271,6 +280,7 @@ func (c *Config) SetBool(name string, value bool) (err error) { ...@@ -271,6 +280,7 @@ func (c *Config) SetBool(name string, value bool) (err error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_set_bool(c.ptr, cname, cbool(value)) ret := C.git_config_set_bool(c.ptr, cname, cbool(value))
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -292,6 +302,7 @@ func (c *Config) SetMultivar(name, regexp, value string) (err error) { ...@@ -292,6 +302,7 @@ func (c *Config) SetMultivar(name, regexp, value string) (err error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_set_multivar(c.ptr, cname, cregexp, cvalue) ret := C.git_config_set_multivar(c.ptr, cname, cregexp, cvalue)
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -307,7 +318,7 @@ func (c *Config) Delete(name string) error { ...@@ -307,7 +318,7 @@ func (c *Config) Delete(name string) error {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_delete_entry(c.ptr, cname) ret := C.git_config_delete_entry(c.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 { if ret < 0 {
return MakeGitError(ret) return MakeGitError(ret)
} }
...@@ -323,6 +334,8 @@ func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) { ...@@ -323,6 +334,8 @@ func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_config_open_level(&config.ptr, parent.ptr, C.git_config_level_t(level)) ret := C.git_config_open_level(&config.ptr, parent.ptr, C.git_config_level_t(level))
runtime.KeepAlive(c)
runtime.KeepAlive(parent)
if ret < 0 { if ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
...@@ -349,6 +362,7 @@ func OpenOndisk(parent *Config, path string) (*Config, error) { ...@@ -349,6 +362,7 @@ func OpenOndisk(parent *Config, path string) (*Config, error) {
type ConfigIterator struct { type ConfigIterator struct {
ptr *C.git_config_iterator ptr *C.git_config_iterator
cfg *Config
} }
// Next returns the next entry for this iterator // Next returns the next entry for this iterator
...@@ -363,7 +377,10 @@ func (iter *ConfigIterator) Next() (*ConfigEntry, error) { ...@@ -363,7 +377,10 @@ func (iter *ConfigIterator) Next() (*ConfigEntry, error) {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
return newConfigEntryFromC(centry), nil entry := newConfigEntryFromC(centry)
runtime.KeepAlive(iter)
return entry, nil
} }
func (iter *ConfigIterator) Free() { func (iter *ConfigIterator) Free() {
......
...@@ -128,6 +128,7 @@ func (c *Commit) Describe(opts *DescribeOptions) (*DescribeResult, error) { ...@@ -128,6 +128,7 @@ func (c *Commit) Describe(opts *DescribeOptions) (*DescribeResult, error) {