refactor: revert 'use ffi Arena for resource management'

This commit is contained in:
Aleksey Kulikov 2021-08-27 15:05:05 +03:00
parent 6a097c1841
commit a78c38d8e3
9 changed files with 588 additions and 620 deletions

View file

@ -11,16 +11,14 @@ Pointer<git_oid> id(Pointer<git_tree> tree) => libgit2.git_tree_id(tree);
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_tree> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
return using((Arena arena) {
final out = arena<Pointer<git_tree>>();
final error = libgit2.git_tree_lookup(out, repo, id);
final out = calloc<Pointer<git_tree>>();
final error = libgit2.git_tree_lookup(out, repo, id);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
});
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Lookup a tree object from the repository, given a prefix of its identifier (short id).
@ -31,22 +29,15 @@ Pointer<git_tree> lookupPrefix(
Pointer<git_oid> id,
int len,
) {
return using((Arena arena) {
final out = arena<Pointer<git_tree>>();
final error = libgit2.git_tree_lookup_prefix(out, repo, id, len);
final out = calloc<Pointer<git_tree>>();
final error = libgit2.git_tree_lookup_prefix(out, repo, id, len);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
});
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Close an open tree.
///
/// You can no longer use the git_tree pointer after this call.
///
/// IMPORTANT: You MUST call this method when you stop using a tree to release memory.
/// Failure to do so will cause a memory leak.
/// Close an open tree to release memory.
void free(Pointer<git_tree> tree) => libgit2.git_tree_free(tree);