8000 Improve handling of interop of libgit2 · dotjosh/libgit2sharp@c3c806c · GitHub
[go: up one dir, main page]

Skip to content

Commit c3c806c

Browse files
committed
Improve handling of interop of libgit2
Should fix issue libgit2#46. Credit goes to @txdv for having spotted this.
1 parent bf9ffdc commit c3c806c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

LibGit2Sharp/Core/Libgit2UnsafeHelper.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,39 @@ internal static unsafe class Libgit2UnsafeHelper
77
public static IList<string> ListAllReferenceNames(RepositorySafeHandle repo, GitReferenceType types)
88
{
99
UnSafeNativeMethods.git_strarray strArray 10000 ;
10-
var res = UnSafeNativeMethods.git_reference_listall(&strArray, repo, types);
10+
var res = UnSafeNativeMethods.git_reference_listall(out strArray, repo, types);
1111
Ensure.Success(res);
1212

13-
return BuildListOf(&strArray);
13+
return BuildListOf(strArray);
1414
}
1515

1616
public static IList<string> ListAllTagNames(RepositorySafeHandle repo)
1717
{
1818
UnSafeNativeMethods.git_strarray strArray;
19-
var res = UnSafeNativeMethods.git_tag_list(&strArray, repo);
19+
var res = UnSafeNativeMethods.git_tag_list(out strArray, repo);
2020
Ensure.Success(res);
2121

22-
return BuildListOf(&strArray);
22+
return BuildListOf(strArray);
2323
}
2424

25-
private static IList<string> BuildListOf(UnSafeNativeMethods.git_strarray* strArray)
25+
private static IList<string> BuildListOf(UnSafeNativeMethods.git_strarray strArray)
2626
{
2727
var list = new List<string>();
2828

2929
try
3030
{
31-
int numberOfEntries = strArray->size.ToInt32();
31+
UnSafeNativeMethods.git_strarray* gitStrArray = &strArray;
32+
33+
int numberOfEntries = gitStrArray->size.ToInt32();
3234
for (uint i = 0; i < numberOfEntries; i++)
3335
{
34-
var name = new string(strArray->strings[i]);
36+
var name = new string(gitStrArray->strings[i]);
3537
list.Add(name);
3638
}
3739
}
3840
finally
3941
{
40-
UnSafeNativeMethods.git_strarray_free(strArray);
42+
UnSafeNativeMethods.git_strarray_free(ref strArray);
4143
}
4244

4345
return list;

LibGit2Sharp/Core/UnSafeNativeMethods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ internal static unsafe class UnSafeNativeMethods
88
private const string libgit2 = "git2";
99

1010
[DllImport(libgit2)]
11-
public static extern int git_reference_listall(git_strarray* array, RepositorySafeHandle repo, GitReferenceType flags);
11+
public static extern int git_reference_listall(out git_strarray array, RepositorySafeHandle repo, GitReferenceType flags);
1212

1313
[DllImport(libgit2)]
14-
public static extern int git_tag_list(git_strarray* array, RepositorySafeHandle repo);
14+
public static extern int git_tag_list(out git_strarray array, RepositorySafeHandle repo);
1515

1616
[DllImport(libgit2)]
17-
public static extern void git_strarray_free(git_strarray* array);
17+
public static extern void git_strarray_free(ref git_strarray array);
1818

1919
3C7E #region Nested type: git_strarray
2020

0 commit comments

Comments
 (0)
0