refactor: use ffi Arena for resource management

This commit is contained in:
Aleksey Kulikov 2021-08-25 18:33:17 +03:00
parent d0bb7aaa0f
commit 747996b40c
17 changed files with 629 additions and 582 deletions

View file

@ -13,16 +13,17 @@ import '../util.dart';
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reflog> read(Pointer<git_repository> repo, String name) {
final out = calloc<Pointer<git_reflog>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reflog_read(out, repo, nameC);
calloc.free(nameC);
return using((Arena arena) {
final out = arena<Pointer<git_reflog>>();
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
final error = libgit2.git_reflog_read(out, repo, nameC);
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;
}
});
}
/// Get the number of log entries in a reflog.