Skip to content

Commit 3649da6

Browse files
committed
Remove AsIntPtr
1 parent 97abee2 commit 3649da6

File tree

6 files changed

+43
-51
lines changed

6 files changed

+43
-51
lines changed

LibGit2Sharp/Core/Handles/Libgit2Object.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ internal unsafe Libgit2Object(IntPtr ptr, bool owned)
110110

111111
public override bool IsInvalid => handle == IntPtr.Zero;
112112

113-
internal IntPtr AsIntPtr() => DangerousGetHandle();
114-
115113
protected override void Dispose(bool disposing)
116114
{
117115
#if LEAKS_IDENTIFYING

LibGit2Sharp/Core/Handles/Objects.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected override bool ReleaseHandle()
2525

2626
public static implicit operator git_tree_entry*(TreeEntryHandle handle)
2727
{
28-
return (git_tree_entry*)handle.AsIntPtr();
28+
return (git_tree_entry*)handle.DangerousGetHandle();
2929
}
3030
}
3131

@@ -50,7 +50,7 @@ protected override bool ReleaseHandle()
5050

5151
public static implicit operator git_reference*(ReferenceHandle handle)
5252
{
53-
return (git_reference*)handle.AsIntPtr();
53+
return (git_reference*)handle.DangerousGetHandle();
5454
}
5555
}
5656

@@ -75,7 +75,7 @@ protected override bool ReleaseHandle()
7575

7676
public static implicit operator git_repository*(RepositoryHandle handle)
7777
{
78-
return (git_repository*)handle.AsIntPtr();
78+
return (git_repository*)handle.DangerousGetHandle();
7979
}
8080
}
8181

@@ -100,7 +100,7 @@ protected override bool ReleaseHandle()
100100

101101
public static implicit operator git_signature*(SignatureHandle handle)
102102
{
103-
return (git_signature*)handle.AsIntPtr();
103+
return (git_signature*)handle.DangerousGetHandle();
104104
}
105105
}
106106

@@ -125,7 +125,7 @@ protected override bool ReleaseHandle()
125125

126126
public static implicit operator git_status_list*(StatusListHandle handle)
127127
{
128-
return (git_status_list*)handle.AsIntPtr();
128+
return (git_status_list*)handle.DangerousGetHandle();
129129
}
130130
}
131131

@@ -150,7 +150,7 @@ protected override bool ReleaseHandle()
150150

151151
public static implicit operator git_blame*(BlameHandle handle)
152152
{
153-
return (git_blame*)handle.AsIntPtr();
153+
return (git_blame*)handle.DangerousGetHandle();
154154
}
155155
}
156156

@@ -175,7 +175,7 @@ protected override bool ReleaseHandle()
175175

176176
public static implicit operator git_diff*(DiffHandle handle)
177177
{
178-
return (git_diff*)handle.AsIntPtr();
178+
return (git_diff*)handle.DangerousGetHandle();
179179
}
180180
}
181181

@@ -200,7 +200,7 @@ protected override bool ReleaseHandle()
200200

201201
public static implicit operator git_patch*(PatchHandle handle)
202202
{
203-
return (git_patch*)handle.AsIntPtr();
203+
return (git_patch*)handle.DangerousGetHandle();
204204
}
205205
}
206206

@@ -225,7 +225,7 @@ protected override bool ReleaseHandle()
225225

226226
public static implicit operator git_config*(ConfigurationHandle handle)
227227
{
228-
return (git_config*)handle.AsIntPtr();
228+
return (git_config*)handle.DangerousGetHandle();
229229
}
230230
}
231231

@@ -250,7 +250,7 @@ protected override bool ReleaseHandle()
250250

251251
public static implicit operator git_index_conflict_iterator*(ConflictIteratorHandle handle)
252252
{
253-
return (git_index_conflict_iterator*)handle.AsIntPtr();
253+
return (git_index_conflict_iterator*)handle.DangerousGetHandle();
254254
}
255255
}
256256

@@ -275,7 +275,7 @@ protected override bool ReleaseHandle()
275275

276276
public static implicit operator git_index*(IndexHandle handle)
277277
{
278-
return (git_index*)handle.AsIntPtr();
278+
return (git_index*)handle.DangerousGetHandle();
279279
}
280280
}
281281

@@ -300,7 +300,7 @@ protected override bool ReleaseHandle()
300300

301301
public static implicit operator git_reflog*(ReflogHandle handle)
302302
{
303-
return (git_reflog*)handle.AsIntPtr();
303+
return (git_reflog*)handle.DangerousGetHandle();
304304
}
305305
}
306306

@@ -325,7 +325,7 @@ protected override bool ReleaseHandle()
325325

326326
public static implicit operator git_treebuilder*(TreeBuilderHandle handle)
327327
{
328-
return (git_treebuilder*)handle.AsIntPtr();
328+
return (git_treebuilder*)handle.DangerousGetHandle();
329329
}
330330
}
331331

@@ -350,7 +350,7 @@ protected override bool ReleaseHandle()
350350

351351
public static implicit operator git_packbuilder*(PackBuilderHandle handle)
352352
{
353-
return (git_packbuilder*)handle.AsIntPtr();
353+
return (git_packbuilder*)handle.DangerousGetHandle();
354354
}
355355
}
356356

@@ -375,7 +375,7 @@ protected override bool ReleaseHandle()
375375

376376
public static implicit operator git_note*(NoteHandle handle)
377377
{
378-
return (git_note*)handle.AsIntPtr();
378+
return (git_note*)handle.DangerousGetHandle();
379379
}
380380
}
381381

@@ -400,7 +400,7 @@ protected override bool ReleaseHandle()
400400

401401
public static implicit operator git_describe_result*(DescribeResultHandle handle)
402402
{
403-
return (git_describe_result*)handle.AsIntPtr();
403+
return (git_describe_result*)handle.DangerousGetHandle();
404404
}
405405
}
406406

@@ -425,7 +425,7 @@ protected override bool ReleaseHandle()
425425

426426
public static implicit operator git_submodule*(SubmoduleHandle handle)
427427
{
428-
return (git_submodule*)handle.AsIntPtr();
428+
return (git_submodule*)handle.DangerousGetHandle();
429429
}
430430
}
431431

@@ -450,7 +450,7 @@ protected override bool ReleaseHandle()
450450

451451
public static implicit operator git_annotated_commit*(AnnotatedCommitHandle handle)
452452
{
453-
return (git_annotated_commit*)handle.AsIntPtr();
453+
return (git_annotated_commit*)handle.DangerousGetHandle();
454454
}
455455
}
456456

@@ -475,7 +475,7 @@ protected override bool ReleaseHandle()
475475

476476
public static implicit operator git_odb*(ObjectDatabaseHandle handle)
477477
{
478-
return (git_odb*)handle.AsIntPtr();
478+
return (git_odb*)handle.DangerousGetHandle();
479479
}
480480
}
481481

@@ -500,7 +500,7 @@ protected override bool ReleaseHandle()
500500

501501
public static implicit operator git_revwalk*(RevWalkerHandle handle)
502502
{
503-
return (git_revwalk*)handle.AsIntPtr();
503+
return (git_revwalk*)handle.DangerousGetHandle();
504504
}
505505
}
506506

@@ -525,7 +525,7 @@ protected override bool ReleaseHandle()
525525

526526
public static implicit operator git_remote*(RemoteHandle handle)
527527
{
528-
return (git_remote*)handle.AsIntPtr();
528+
return (git_remote*)handle.DangerousGetHandle();
529529
}
530530
}
531531

@@ -550,7 +550,7 @@ protected override bool ReleaseHandle()
550550

551551
public static implicit operator git_object*(ObjectHandle handle)
552552
{
553-
return (git_object*)handle.AsIntPtr();
553+
return (git_object*)handle.DangerousGetHandle();
554554
}
555555
}
556556

@@ -575,7 +575,7 @@ protected override bool ReleaseHandle()
575575

576576
public static implicit operator git_rebase*(RebaseHandle handle)
577577
{
578-
return (git_rebase*)handle.AsIntPtr();
578+
return (git_rebase*)handle.DangerousGetHandle();
579579
}
580580
}
581581

@@ -600,7 +600,7 @@ protected override bool ReleaseHandle()
600600

601601
public static implicit operator git_odb_stream*(OdbStreamHandle handle)
602602
{
603-
return (git_odb_stream*)handle.AsIntPtr();
603+
return (git_odb_stream*)handle.DangerousGetHandle();
604604
}
605605
}
606606

@@ -625,7 +625,7 @@ protected override bool ReleaseHandle()
625625

626626
public static implicit operator git_worktree*(WorktreeHandle handle)
627627
{
628-
return (git_worktree*)handle.AsIntPtr();
628+
return (git_worktree*)handle.DangerousGetHandle();
629629
}
630630
}
631631

LibGit2Sharp/Core/Handles/Objects.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ for (var i = 0; i < cNames.Length; i++)
9191

9292
public static implicit operator <#= cNames[i] #>*(<#= csNames[i] #> handle)
9393
{
94-
return (<#= cNames[i] #>*)handle.AsIntPtr();
94+
return (<#= cNames[i] #>*)handle.DangerousGetHandle();
9595
}
9696
}
9797

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ internal static extern void git_branch_iterator_free(
254254
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
255255
internal static extern int git_branch_iterator_new(
256256
out IntPtr iter_out,
257-
IntPtr repo,
257+
RepositoryHandle repo,
258258
GitBranchType branch_type);
259259

260260
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
@@ -560,7 +560,7 @@ internal static extern unsafe int git_config_foreach(
560560
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
561561
internal static extern int git_config_iterator_glob_new(
562562
out IntPtr iter,
563-
IntPtr cfg,
563+
ConfigurationHandle cfg,
564564
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string regexp);
565565

566566
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
@@ -1236,7 +1236,7 @@ internal static extern unsafe int git_reference_lookup(
12361236

12371237
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
12381238
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
1239-
internal static extern unsafe string git_reference_name(git_reference* reference);
1239+
internal static extern unsafe string git_reference_name(ReferenceHandle reference);
12401240

12411241
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
12421242
internal static extern unsafe int git_reference_remove(
@@ -1273,7 +1273,7 @@ internal static extern unsafe int git_reference_symbolic_set_target(
12731273
internal static extern unsafe string git_reference_symbolic_target(git_reference* reference);
12741274

12751275
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1276-
internal static extern unsafe GitReferenceType git_reference_type(git_reference* reference);
1276+
internal static extern unsafe GitReferenceType git_reference_type(ReferenceHandle reference);
12771277

12781278
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
12791279
internal static extern unsafe int git_reference_ensure_log(
@@ -1533,10 +1533,10 @@ internal static extern unsafe int git_repository_fetchhead_foreach(
15331533
internal static extern unsafe void git_repository_free(git_repository* repo);
15341534

15351535
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1536-
internal static extern int git_repository_head_detached(IntPtr repo);
1536+
internal static extern int git_repository_head_detached(RepositoryHandle repo);
15371537

15381538
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1539-
internal static extern int git_repository_head_unborn(IntPtr repo);
1539+
internal static extern int git_repository_head_unborn(RepositoryHandle repo);
15401540

15411541
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
15421542
internal static extern unsafe int git_repository_ident(
@@ -1554,10 +1554,10 @@ internal static extern unsafe int git_repository_init_ext(
15541554
GitRepositoryInitOptions options);
15551555

15561556
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1557-
internal static extern int git_repository_is_bare(IntPtr handle);
1557+
internal static extern int git_repository_is_bare(RepositoryHandle handle);
15581558

15591559
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1560-
internal static extern int git_repository_is_shallow(IntPtr repo);
1560+
internal static extern int git_repository_is_shallow(RepositoryHandle repo);
15611561

15621562
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
15631563
internal static extern unsafe int git_repository_state_cleanup(git_repository* repo);

LibGit2Sharp/Core/Proxy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static unsafe void git_branch_delete(ReferenceHandle reference)
131131
public static IEnumerable<Branch> git_branch_iterator(Repository repo, GitBranchType branchType)
132132
{
133133
IntPtr iter;
134-
var res = NativeMethods.git_branch_iterator_new(out iter, repo.Handle.AsIntPtr(), branchType);
134+
var res = NativeMethods.git_branch_iterator_new(out iter, repo.Handle, branchType);
135135
Ensure.ZeroResult(res);
136136

137137
try
@@ -345,7 +345,7 @@ public static unsafe string git_commit_create_buffer(
345345
try
346346
{
347347
handles = parents.Select(c => Proxy.git_object_lookup(c.repo.Handle, c.Id, GitObjectType.Commit)).ToArray();
348-
var ptrs = handles.Select(p => p.AsIntPtr()).ToArray();
348+
var ptrs = handles.Select(p => p.DangerousGetHandle()).ToArray();
349349
int res;
350350
fixed (IntPtr* objs = ptrs)
351351
{
@@ -624,7 +624,7 @@ public static IEnumerable<ConfigurationEntry<string>> git_config_iterator_glob(
624624
string regexp)
625625
{
626626
IntPtr iter;
627-
var res = NativeMethods.git_config_iterator_glob_new(out iter, config.AsIntPtr(), regexp);
627+
var res = NativeMethods.git_config_iterator_glob_new(out iter, config, regexp);
628628
Ensure.ZeroResult(res);
629629
try
630630
{
@@ -1302,7 +1302,7 @@ public static unsafe ObjectId git_annotated_commit_id(AnnotatedCommitHandle merg
13021302

13031303
public static unsafe void git_merge(RepositoryHandle repo, AnnotatedCommitHandle[] heads, GitMergeOpts mergeOptions, GitCheckoutOpts checkoutOptions, out bool earlyStop)
13041304
{
1305-
IntPtr[] their_heads = heads.Select(head => head.AsIntPtr()).ToArray();
1305+
IntPtr[] their_heads = heads.Select(head => head.DangerousGetHandle()).ToArray();
13061306

13071307
int res = NativeMethods.git_merge(repo,
13081308
their_heads,
@@ -1327,7 +1327,7 @@ public static unsafe void git_merge_analysis(
13271327
out GitMergeAnalysis analysis_out,
13281328
out GitMergePreference preference_out)
13291329
{
1330-
IntPtr[] their_heads = heads.Select(head => head.AsIntPtr()).ToArray();
1330+
IntPtr[] their_heads = heads.Select(head => head.DangerousGetHandle()).ToArray();
13311331

13321332
int res = NativeMethods.git_merge_analysis(out analysis_out,
13331333
out preference_out,
@@ -1955,7 +1955,7 @@ public static unsafe ReferenceHandle git_reference_lookup(RepositoryHandle repo,
19551955
return new ReferenceHandle(handle, true);
19561956
}
19571957

1958-
public static unsafe string git_reference_name(git_reference* reference)
1958+
public static unsafe string git_reference_name(ReferenceHandle reference)
19591959
{
19601960
return NativeMethods.git_reference_name(reference);
19611961
}
@@ -2011,7 +2011,7 @@ public static unsafe string git_reference_symbolic_target(git_reference* referen
20112011
return NativeMethods.git_reference_symbolic_target(reference);
20122012
}
20132013

2014-
public static unsafe GitReferenceType git_reference_type(git_reference* reference)
2014+
public static unsafe GitReferenceType git_reference_type(ReferenceHandle reference)
20152015
{
20162016
return NativeMethods.git_reference_type(reference);
20172017
}
@@ -3779,9 +3779,9 @@ private static ICollection<TResult> git_foreach<T1, T2, T3, T4, TResult>(
37793779
return result;
37803780
}
37813781

3782-
private static unsafe bool RepositoryStateChecker(RepositoryHandle repo, Func<IntPtr, int> checker)
3782+
private static unsafe bool RepositoryStateChecker(RepositoryHandle repo, Func<RepositoryHandle, int> checker)
37833783
{
3784-
int res = checker(repo.AsIntPtr());
3784+
int res = checker(repo);
37853785
Ensure.BooleanResult(res);
37863786

37873787
return (res == 1);

LibGit2Sharp/Reference.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ private protected Reference(IRepository repo, string canonicalName, string targe
3232
this.targetIdentifier = targetIdentifier;
3333
}
3434

35-
// This overload lets public-facing methods avoid having to use the pointers directly
3635
internal static unsafe T BuildFromPtr<T>(ReferenceHandle handle, Repository repo) where T : Reference
37-
{
38-
return BuildFromPtr<T>((git_reference*)handle.AsIntPtr(), repo);
39-
}
40-
41-
internal static unsafe T BuildFromPtr<T>(git_reference* handle, Repository repo) where T : Reference
4236
{
4337
GitReferenceType type = Proxy.git_reference_type(handle);
4438
string name = Proxy.git_reference_name(handle);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy