Skip to content

Commit 50c4330

Browse files
committed
Use cdecl calling conventions
Join the rest of the world and use cdecl calling conventions to pinvoke libgit2.
1 parent ee648a4 commit 50c4330

11 files changed

+417
-352
lines changed

‎LibGit2Sharp/Core/GitCheckoutOpts.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ internal enum CheckoutStrategy
118118
GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED=(1<<17),
119119
}
120120

121+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
121122
internaldelegateintcheckout_notify_cb(
122123
CheckoutNotifyFlagswhy,
123124
IntPtrpath,
@@ -126,12 +127,14 @@ internal delegate int checkout_notify_cb(
126127
IntPtrworkdir,
127128
IntPtrpayload);
128129

130+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
129131
internaldelegatevoidprogress_cb(
130132
IntPtrstrPtr,
131133
UIntPtrcompleted_steps,
132134
UIntPtrtotal_steps,
133135
IntPtrpayload);
134136

137+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
135138
internaldelegateintperfdata_cb(
136139
IntPtrperfdata,
137140
IntPtrpayload);

‎LibGit2Sharp/Core/GitDiff.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ internal enum GitDiffOptionFlags
198198
GIT_DIFF_SHOW_BINARY=(1<<30),
199199
}
200200

201+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
201202
internaldelegateintdiff_notify_cb(
202203
IntPtrdiff_so_far,
203204
IntPtrdelta_to_add,
204205
IntPtrmatched_pathspec,
205206
IntPtrpayload);
206207

208+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
207209
internaldelegateintdiff_progress_cb(
208210
IntPtrdiff_so_far,
209211
IntPtrold_path,

‎LibGit2Sharp/Core/GitFilter.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal class GitFilter
4343
/// before the first use of the filter, so you can defer expensive
4444
/// initialization operations (in case libgit2 is being used in a way that doesn't need the filter).
4545
/// </summary>
46+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
4647
publicdelegateintgit_filter_init_fn(IntPtrfilter);
4748

4849
/// <summary>
@@ -53,6 +54,7 @@ internal class GitFilter
5354
/// will be called once at most and should release resources as needed.
5455
/// Typically this function will free the `git_filter` object itself.
5556
/// </summary>
57+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
5658
publicdelegatevoidgit_filter_shutdown_fn(IntPtrfilter);
5759

5860
/// <summary>
@@ -69,6 +71,7 @@ internal class GitFilter
6971
/// away before the `apply` callback can use it. If a filter allocates and assigns a value to the `payload`, it will need a `cleanup`
7072
/// callback to free the payload.
7173
/// </summary>
74+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
7275
publicdelegateintgit_filter_check_fn(
7376
GitFiltergitFilter,
7477
IntPtrpayload,
@@ -85,13 +88,15 @@ public delegate int git_filter_check_fn(
8588
///
8689
/// The `payload` value will refer to any payload that was set by the `check` callback. It may be read from or written to as needed.
8790
/// </summary>
91+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
8892
publicdelegateintgit_filter_apply_fn(
8993
GitFiltergitFilter,
9094
IntPtrpayload,
9195
IntPtrgitBufTo,
9296
IntPtrgitBufFrom,
9397
IntPtrfilterSource);
9498

99+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
95100
publicdelegateintgit_filter_stream_fn(
96101
outIntPtrgit_writestream_out,
97102
GitFilterself,
@@ -104,6 +109,7 @@ public delegate int git_filter_stream_fn(
104109
/// after the filter has been applied. If the `check` or `apply` callbacks allocated a `payload`
105110
/// to keep per-source filter state, use this callback to free that payload and release resources as required.
106111
/// </summary>
112+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
107113
publicdelegatevoidgit_filter_cleanup_fn(IntPtrgitFilter,IntPtrpayload);
108114
}
109115
/// <summary>

‎LibGit2Sharp/Core/GitOdbBackend.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static GitOdbBackend()
5555
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
5656
/// <param name="oid">[in] The OID which the backend is being asked to look up.</param>
5757
/// <returns>0 if successful; an error code otherwise.</returns>
58+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
5859
publicdelegateintread_callback(
5960
outIntPtrbuffer_p,
6061
outUIntPtrlen_p,
@@ -77,6 +78,7 @@ public delegate int read_callback(
7778
/// <param name="short_oid">[in] The short-form OID which the backend is being asked to look up.</param>
7879
/// <param name="len">[in] The length of the short-form OID (short_oid).</param>
7980
/// <returns>0 if successful; an error code otherwise.</returns>
81+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
8082
publicdelegateintread_prefix_callback(
8183
outGitOidout_oid,
8284
outIntPtrbuffer_p,
@@ -95,6 +97,7 @@ public delegate int read_prefix_callback(
9597
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
9698
/// <param name="oid">[in] The OID which the backend is being asked to look up.</param>
9799
/// <returns>0 if successful; an error code otherwise.</returns>
100+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
98101
publicdelegateintread_header_callback(
99102
outUIntPtrlen_p,
100103
outGitObjectTypetype_p,
@@ -111,6 +114,7 @@ public delegate int read_header_callback(
111114
/// <param name="len">[in] The length of the buffer pointed to by data.</param>
112115
/// <param name="type">[in] The type of the object.</param>
113116
/// <returns>0 if successful; an error code otherwise.</returns>
117+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
114118
publicdelegateintwrite_callback(
115119
IntPtrbackend,
116120
refGitOidoid,
@@ -128,6 +132,7 @@ public delegate int write_callback(
128132
/// <param name="length">[in] The length of the object's contents.</param>
129133
/// <param name="type">[in] The type of the object being written.</param>
130134
/// <returns>0 if successful; an error code otherwise.</returns>
135+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
131136
publicdelegateintwritestream_callback(
132137
outIntPtrstream_out,
133138
IntPtrbackend,
@@ -142,6 +147,7 @@ public delegate int writestream_callback(
142147
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
143148
/// <param name="oid">[in] The object ID that the caller is requesting.</param>
144149
/// <returns>0 if successful; an error code otherwise.</returns>
150+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
145151
publicdelegateintreadstream_callback(
146152
outIntPtrstream_out,
147153
IntPtrbackend,
@@ -154,6 +160,7 @@ public delegate int readstream_callback(
154160
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
155161
/// <param name="oid">[in] The object ID that the caller is requesting.</param>
156162
/// <returns>True if the object exists; false otherwise</returns>
163+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
157164
publicdelegateboolexists_callback(
158165
IntPtrbackend,
159166
refGitOidoid);
@@ -169,6 +176,7 @@ public delegate bool exists_callback(
169176
/// <param name="short_oid">[in] The short-form OID which the backend is being asked to look up.</param>
170177
/// <param name="len">[in] The length of the short-form OID (short_oid).</param>
171178
/// <returns>1 if the object exists, 0 if the object doesn't; an error code otherwise.</returns>
179+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
172180
publicdelegateintexists_prefix_callback(
173181
refGitOidfound_oid,
174182
IntPtrbackend,
@@ -182,6 +190,7 @@ public delegate int exists_prefix_callback(
182190
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
183191
/// <param name="cb">[in] The callback function to invoke.</param>
184192
/// <param name="data">[in] An arbitrary parameter to pass through to the callback</param>
193+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
185194
publicdelegateintforeach_callback(
186195
IntPtrbackend,
187196
foreach_callback_callbackcb,
@@ -191,6 +200,7 @@ public delegate int foreach_callback(
191200
/// The owner of this backend is finished with it. The backend is asked to clean up and shut down.
192201
/// </summary>
193202
/// <param name="backend">[in] A pointer to the backend which is being freed.</param>
203+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
194204
publicdelegatevoidfree_callback(
195205
IntPtrbackend);
196206

@@ -200,6 +210,7 @@ public delegate void free_callback(
200210
/// <param name="oid">The oid of each object in the backing store.</param>
201211
/// <param name="data">The arbitrary parameter given to foreach_callback.</param>
202212
/// <returns>A non-negative result indicates the enumeration should continue. Otherwise, the enumeration should stop.</returns>
213+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
203214
publicdelegateintforeach_callback_callback(
204215
IntPtroid,
205216
IntPtrdata);

‎LibGit2Sharp/Core/GitOdbBackendStream.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,22 @@ static GitOdbBackendStream()
3838

3939
publicstaticintGCHandleOffset;
4040

41+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
4142
publicdelegateintread_callback(
4243
IntPtrstream,
4344
IntPtrbuffer,
4445
UIntPtrlen);
4546

47+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
4648
publicdelegateintwrite_callback(
4749
IntPtrstream,
4850
IntPtrbuffer,
4951
UIntPtrlen);
5052

53+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
5154
publicdelegateintfinalize_write_callback(IntPtrstream,refGitOidoid);
5255

56+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
5357
publicdelegatevoidfree_callback(IntPtrstream);
5458
}
5559
}

‎LibGit2Sharp/Core/GitSmartSubtransport.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ static GitSmartSubtransport()
2323

2424
publicstaticintGCHandleOffset;
2525

26+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
2627
publicdelegateintaction_callback(
2728
outIntPtrstream,
2829
IntPtrsubtransport,
2930
IntPtrurl,
3031
GitSmartSubtransportActionaction);
3132

33+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
3234
publicdelegateintclose_callback(IntPtrsubtransport);
3335

36+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
3437
publicdelegatevoidfree_callback(IntPtrsubtransport);
3538
}
3639
}

‎LibGit2Sharp/Core/GitSmartSubtransportRegistration.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal class GitSmartSubtransportRegistration
1010
publicuintRpc;
1111
publicuintParam;
1212

13+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1314
publicdelegateintcreate_callback(
1415
outIntPtrsubtransport,
1516
IntPtrowner,

‎LibGit2Sharp/Core/GitSmartSubtransportStream.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ static GitSmartSubtransportStream()
2525

2626
publicstaticintGCHandleOffset;
2727

28+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
2829
publicdelegateintread_callback(
2930
IntPtrstream,
3031
IntPtrbuffer,
3132
UIntPtrbuf_size,
3233
outUIntPtrbytes_read);
3334

35+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
3436
publicdelegateintwrite_callback(
3537
IntPtrstream,
3638
IntPtrbuffer,
3739
UIntPtrlen);
3840

41+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
3942
publicdelegatevoidfree_callback(IntPtrstream);
4043
}
4144
}

‎LibGit2Sharp/Core/GitStashApplyOpts.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespaceLibGit2Sharp.Core
55
{
6+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
67
internaldelegateintstash_apply_progress_cb(StashApplyProgressprogress,IntPtrpayload);
78

89
[StructLayout(LayoutKind.Sequential)]

‎LibGit2Sharp/Core/GitWriteStream.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ internal struct GitWriteStream
1515
[MarshalAs(UnmanagedType.FunctionPtr)]
1616
publicfree_fnfree;
1717

18+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1819
publicdelegateintwrite_fn(IntPtrstream,IntPtrbuffer,UIntPtrlen);
20+
21+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1922
publicdelegateintclose_fn(IntPtrstream);
23+
24+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
2025
publicdelegatevoidfree_fn(IntPtrstream);
2126
}
2227
}

0 commit comments

Comments
(0)