Skip to content

Use cdecl calling conventions #1653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions LibGit2Sharp/Core/GitCheckoutOpts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal enum CheckoutStrategy
GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1 << 17),
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int checkout_notify_cb(
CheckoutNotifyFlags why,
IntPtr path,
Expand All @@ -126,12 +127,14 @@ internal delegate int checkout_notify_cb(
IntPtr workdir,
IntPtr payload);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void progress_cb(
IntPtr strPtr,
UIntPtr completed_steps,
UIntPtr total_steps,
IntPtr payload);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int perfdata_cb(
IntPtr perfdata,
IntPtr payload);
Expand Down
2 changes: 2 additions & 0 deletions LibGit2Sharp/Core/GitDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ internal enum GitDiffOptionFlags
GIT_DIFF_SHOW_BINARY = (1 << 30),
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int diff_notify_cb(
IntPtr diff_so_far,
IntPtr delta_to_add,
IntPtr matched_pathspec,
IntPtr payload);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int diff_progress_cb(
IntPtr diff_so_far,
IntPtr old_path,
Expand Down
6 changes: 6 additions & 0 deletions LibGit2Sharp/Core/GitFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal class GitFilter
/// before the first use of the filter, so you can defer expensive
/// initialization operations (in case libgit2 is being used in a way that doesn't need the filter).
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int git_filter_init_fn(IntPtr filter);

/// <summary>
Expand All @@ -53,6 +54,7 @@ internal class GitFilter
/// will be called once at most and should release resources as needed.
/// Typically this function will free the `git_filter` object itself.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void git_filter_shutdown_fn(IntPtr filter);

/// <summary>
Expand All @@ -69,6 +71,7 @@ internal class GitFilter
/// away before the `apply` callback can use it. If a filter allocates and assigns a value to the `payload`, it will need a `cleanup`
/// callback to free the payload.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int git_filter_check_fn(
GitFilter gitFilter,
IntPtr payload,
Expand All @@ -85,13 +88,15 @@ public delegate int git_filter_check_fn(
///
/// 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.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int git_filter_apply_fn(
GitFilter gitFilter,
IntPtr payload,
IntPtr gitBufTo,
IntPtr gitBufFrom,
IntPtr filterSource);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int git_filter_stream_fn(
out IntPtr git_writestream_out,
GitFilter self,
Expand All @@ -104,6 +109,7 @@ public delegate int git_filter_stream_fn(
/// after the filter has been applied. If the `check` or `apply` callbacks allocated a `payload`
/// to keep per-source filter state, use this callback to free that payload and release resources as required.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void git_filter_cleanup_fn(IntPtr gitFilter, IntPtr payload);
}
/// <summary>
Expand Down
11 changes: 11 additions & 0 deletions LibGit2Sharp/Core/GitOdbBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static GitOdbBackend()
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
/// <param name="oid">[in] The OID which the backend is being asked to look up.</param>
/// <returns>0 if successful; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int read_callback(
out IntPtr buffer_p,
out UIntPtr len_p,
Expand All @@ -77,6 +78,7 @@ public delegate int read_callback(
/// <param name="short_oid">[in] The short-form OID which the backend is being asked to look up.</param>
/// <param name="len">[in] The length of the short-form OID (short_oid).</param>
/// <returns>0 if successful; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int read_prefix_callback(
out GitOid out_oid,
out IntPtr buffer_p,
Expand All @@ -95,6 +97,7 @@ public delegate int read_prefix_callback(
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
/// <param name="oid">[in] The OID which the backend is being asked to look up.</param>
/// <returns>0 if successful; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int read_header_callback(
out UIntPtr len_p,
out GitObjectType type_p,
Expand All @@ -111,6 +114,7 @@ public delegate int read_header_callback(
/// <param name="len">[in] The length of the buffer pointed to by data.</param>
/// <param name="type">[in] The type of the object.</param>
/// <returns>0 if successful; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int write_callback(
IntPtr backend,
ref GitOid oid,
Expand All @@ -128,6 +132,7 @@ public delegate int write_callback(
/// <param name="length">[in] The length of the object's contents.</param>
/// <param name="type">[in] The type of the object being written.</param>
/// <returns>0 if successful; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int writestream_callback(
out IntPtr stream_out,
IntPtr backend,
Expand All @@ -142,6 +147,7 @@ public delegate int writestream_callback(
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
/// <param name="oid">[in] The object ID that the caller is requesting.</param>
/// <returns>0 if successful; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int readstream_callback(
out IntPtr stream_out,
IntPtr backend,
Expand All @@ -154,6 +160,7 @@ public delegate int readstream_callback(
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
/// <param name="oid">[in] The object ID that the caller is requesting.</param>
/// <returns>True if the object exists; false otherwise</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool exists_callback(
IntPtr backend,
ref GitOid oid);
Expand All @@ -169,6 +176,7 @@ public delegate bool exists_callback(
/// <param name="short_oid">[in] The short-form OID which the backend is being asked to look up.</param>
/// <param name="len">[in] The length of the short-form OID (short_oid).</param>
/// <returns>1 if the object exists, 0 if the object doesn't; an error code otherwise.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int exists_prefix_callback(
ref GitOid found_oid,
IntPtr backend,
Expand All @@ -182,6 +190,7 @@ public delegate int exists_prefix_callback(
/// <param name="backend">[in] A pointer to the backend which is being asked to perform the task.</param>
/// <param name="cb">[in] The callback function to invoke.</param>
/// <param name="data">[in] An arbitrary parameter to pass through to the callback</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int foreach_callback(
IntPtr backend,
foreach_callback_callback cb,
Expand All @@ -191,6 +200,7 @@ public delegate int foreach_callback(
/// The owner of this backend is finished with it. The backend is asked to clean up and shut down.
/// </summary>
/// <param name="backend">[in] A pointer to the backend which is being freed.</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void free_callback(
IntPtr backend);

Expand All @@ -200,6 +210,7 @@ public delegate void free_callback(
/// <param name="oid">The oid of each object in the backing store.</param>
/// <param name="data">The arbitrary parameter given to foreach_callback.</param>
/// <returns>A non-negative result indicates the enumeration should continue. Otherwise, the enumeration should stop.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int foreach_callback_callback(
IntPtr oid,
IntPtr data);
Expand Down
4 changes: 4 additions & 0 deletions LibGit2Sharp/Core/GitOdbBackendStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ static GitOdbBackendStream()

public static int GCHandleOffset;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int read_callback(
IntPtr stream,
IntPtr buffer,
UIntPtr len);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int write_callback(
IntPtr stream,
IntPtr buffer,
UIntPtr len);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int finalize_write_callback(IntPtr stream, ref GitOid oid);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void free_callback(IntPtr stream);
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/Core/GitSmartSubtransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ static GitSmartSubtransport()

public static int GCHandleOffset;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int action_callback(
out IntPtr stream,
IntPtr subtransport,
IntPtr url,
GitSmartSubtransportAction action);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int close_callback(IntPtr subtransport);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void free_callback(IntPtr subtransport);
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/Core/GitSmartSubtransportRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class GitSmartSubtransportRegistration
public uint Rpc;
public uint Param;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int create_callback(
out IntPtr subtransport,
IntPtr owner,
Expand Down
3 changes: 3 additions & 0 deletions LibGit2Sharp/Core/GitSmartSubtransportStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ static GitSmartSubtransportStream()

public static int GCHandleOffset;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int read_callback(
IntPtr stream,
IntPtr buffer,
UIntPtr buf_size,
out UIntPtr bytes_read);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int write_callback(
IntPtr stream,
IntPtr buffer,
UIntPtr len);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void free_callback(IntPtr stream);
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/Core/GitStashApplyOpts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace LibGit2Sharp.Core
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int stash_apply_progress_cb(StashApplyProgress progress, IntPtr payload);

[StructLayout(LayoutKind.Sequential)]
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/Core/GitWriteStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ internal struct GitWriteStream
[MarshalAs(UnmanagedType.FunctionPtr)]
public free_fn free;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int write_fn(IntPtr stream, IntPtr buffer, UIntPtr len);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int close_fn(IntPtr stream);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void free_fn(IntPtr stream);
}
}
Loading