From 5913c2c97adae0070bd138d144ed63a5c39ab2c7 Mon Sep 17 00:00:00 2001 From: Igor Gorbunov Date: Tue, 21 Aug 2012 11:06:22 +0400 Subject: [PATCH] Using cdecl for calling native functions and providing callbacks. --- LibGit2Sharp/Core/NativeMethods.cs | 340 +++++++++++++++-------------- 1 file changed, 181 insertions(+), 159 deletions(-) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index f6dc11aa7..91cfa0222 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -73,41 +73,53 @@ public static bool RepositoryStateChecker(RepositorySafeHandle repositoryPtr, Fu return (res == 1); } - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention=CallingConvention.Cdecl)] public static extern GitErrorSafeHandle giterr_last(); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_blob_create_fromdisk( ref GitOid oid, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_blob_create_fromfile( ref GitOid oid, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int source_callback( IntPtr content, int max_length, IntPtr data); - [DllImport(libgit2)] + /* + // An example of callback definition (taken from http://www.codeproject.com/Tips/318140/How-to-make-a-callback-to-Csharp-from-C-Cplusplus) + // define a progress callback delegate + source_callback fileCallback = + (content, max_length, data) => + { + blah-blah-blah++; + return 0; + }; + */ + + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_blob_create_fromchunks( ref GitOid oid, RepositorySafeHandle repositoryPtr, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath hintpath, - source_callback fileCallback, + [MarshalAs(UnmanagedType.FunctionPtr)] source_callback fileCallback, IntPtr data); - - [DllImport(libgit2)] + + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr git_blob_rawcontent(GitObjectSafeHandle blob); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_blob_rawsize(GitObjectSafeHandle blob); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_branch_create( out GitOid oid_out, RepositorySafeHandle repo, @@ -115,38 +127,39 @@ public static extern int git_branch_create( GitObjectSafeHandle target, [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_branch_delete( RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string branch_name, GitBranchType branch_type); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int branch_foreach_callback( IntPtr branch_name, GitBranchType branch_type, IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_branch_foreach( RepositorySafeHandle repo, GitBranchType branch_type, - branch_foreach_callback branch_cb, + [MarshalAs(UnmanagedType.FunctionPtr)] branch_foreach_callback branch_cb, IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_branch_move( RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string old_branch_name, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string new_branch_name, [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr git_commit_author(GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr git_commit_committer(GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_commit_create( out GitOid oid, RepositorySafeHandle repo, @@ -159,107 +172,107 @@ public static extern int git_commit_create( int parentCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)] [In] IntPtr[] parents); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_commit_message(GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_commit_message_encoding(GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_commit_parent(out GitObjectSafeHandle parentCommit, GitObjectSafeHandle commit, uint n); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern uint git_commit_parentcount(GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_commit_tree(out GitObjectSafeHandle tree, GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern OidSafeHandle git_commit_tree_oid(GitObjectSafeHandle commit); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_delete(ConfigurationSafeHandle cfg, string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_find_global(byte[] global_config_path, uint length); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_find_system(byte[] system_config_path, uint length); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_config_free(IntPtr cfg); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_get_bool( [MarshalAs(UnmanagedType.Bool)] out bool value, ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_get_int32( out int value, ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_get_int64( out long value, ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_get_string( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] out string value, ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_add_file_ondisk( ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path, int priority); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_new(out ConfigurationSafeHandle cfg); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_open_global(out ConfigurationSafeHandle cfg); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_open_ondisk( out ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_set_bool( ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name, [MarshalAs(UnmanagedType.Bool)] bool value); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_set_int32( ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name, int value); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_set_int64( ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name, long value); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_config_set_string( ConfigurationSafeHandle cfg, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_diff_list_free(IntPtr diff); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_tree_to_tree( RepositorySafeHandle repo, GitDiffOptions options, @@ -267,36 +280,38 @@ public static extern int git_diff_tree_to_tree( GitObjectSafeHandle newTree, out DiffListSafeHandle diff); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_index_to_tree( RepositorySafeHandle repo, GitDiffOptions options, GitObjectSafeHandle oldTree, out DiffListSafeHandle diff); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_merge( DiffListSafeHandle onto, DiffListSafeHandle from); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_workdir_to_index( RepositorySafeHandle repo, GitDiffOptions options, out DiffListSafeHandle diff); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_workdir_to_tree( RepositorySafeHandle repo, GitDiffOptions options, GitObjectSafeHandle oldTree, out DiffListSafeHandle diff); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int git_diff_file_fn( IntPtr data, GitDiffDelta delta, float progress); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int git_diff_hunk_fn( IntPtr data, GitDiffDelta delta, @@ -304,29 +319,30 @@ internal delegate int git_diff_hunk_fn( IntPtr header, uint headerLen); - [DllImport(libgit2)] - public static extern int git_diff_foreach( - DiffListSafeHandle diff, - IntPtr callbackData, - git_diff_file_fn fileCallback, - git_diff_hunk_fn hunkCallback, - git_diff_data_fn lineCallback); - + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int git_diff_data_fn( IntPtr data, GitDiffDelta delta, - GitDiffRange range, + GitDiffRange range, GitDiffLineOrigin lineOrigin, IntPtr content, uint contentLen); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] + public static extern int git_diff_foreach( + DiffListSafeHandle diff, + IntPtr callbackData, + [MarshalAs(UnmanagedType.FunctionPtr)] git_diff_file_fn fileCallback, + [MarshalAs(UnmanagedType.FunctionPtr)] git_diff_hunk_fn hunkCallback, + [MarshalAs(UnmanagedType.FunctionPtr)] git_diff_data_fn lineCallback); + + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_print_patch( DiffListSafeHandle diff, IntPtr data, git_diff_data_fn printCallback); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_diff_blobs( GitObjectSafeHandle oldBlob, GitObjectSafeHandle newBlob, @@ -336,60 +352,60 @@ public static extern int git_diff_blobs( git_diff_hunk_fn hunkCallback, git_diff_data_fn lineCallback); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_add( IndexSafeHandle index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path, int stage = 0); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_add2( IndexSafeHandle index, GitIndexEntry entry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern uint git_index_entrycount(IndexSafeHandle index); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_find( IndexSafeHandle index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_index_free(IntPtr index); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern IndexEntrySafeHandle git_index_get(IndexSafeHandle index, uint n); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_open( out IndexSafeHandle index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath indexpath); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_read_tree(IndexSafeHandle index, GitObjectSafeHandle tree); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_remove(IndexSafeHandle index, int n); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_index_write(IndexSafeHandle index); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_merge_base( out GitOid mergeBase, RepositorySafeHandle repo, GitObjectSafeHandle one, GitObjectSafeHandle two); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_message_prettify( byte[] message_out, // NB: This is more properly a StringBuilder, but it's UTF8 int buffer_size, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string message, bool strip_comments); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_note_create( out GitOid noteOid, RepositorySafeHandle repo, @@ -399,24 +415,24 @@ public static extern int git_note_create( ref GitOid oid, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string note); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_note_free(IntPtr note); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_note_message(NoteSafeHandle note); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern OidSafeHandle git_note_oid(NoteSafeHandle note); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_note_read( out NoteSafeHandle note, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, ref GitOid oid); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_note_remove( RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, @@ -424,47 +440,48 @@ public static extern int git_note_remove( SignatureSafeHandle committer, ref GitOid oid); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_note_default_ref( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] out string notes_ref, RepositorySafeHandle repo); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int notes_foreach_callback( GitNoteData noteData, IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_note_foreach( RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string notes_ref, - notes_foreach_callback callback, + [MarshalAs(UnmanagedType.FunctionPtr)] notes_foreach_callback callback, IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_odb_exists(ObjectDatabaseSafeHandle odb, ref GitOid id); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_odb_free(IntPtr odb); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_object_free(IntPtr obj); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern OidSafeHandle git_object_id(GitObjectSafeHandle obj); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_object_lookup(out GitObjectSafeHandle obj, RepositorySafeHandle repo, ref GitOid id, GitObjectType type); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_object_lookup_prefix(out GitObjectSafeHandle obj, RepositorySafeHandle repo, ref GitOid id, uint len, GitObjectType type); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern GitObjectType git_object_type(GitObjectSafeHandle obj); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_oid_cmp(ref GitOid a, ref GitOid b); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_create_oid( out ReferenceSafeHandle reference, RepositorySafeHandle repo, @@ -472,7 +489,7 @@ public static extern int git_reference_create_oid( ref GitOid oid, [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_create_symbolic( out ReferenceSafeHandle reference, RepositorySafeHandle repo, @@ -480,82 +497,83 @@ public static extern int git_reference_create_symbolic( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string target, [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_delete(ReferenceSafeHandle reference); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int ref_glob_callback( IntPtr reference_name, IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_foreach_glob( RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string glob, GitReferenceType flags, - ref_glob_callback callback, + [MarshalAs(UnmanagedType.FunctionPtr)] ref_glob_callback callback, IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_reference_free(IntPtr reference); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_lookup( out ReferenceSafeHandle reference, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_reference_name(ReferenceSafeHandle reference); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern OidSafeHandle git_reference_oid(ReferenceSafeHandle reference); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_rename( ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string newName, [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_resolve(out ReferenceSafeHandle resolvedReference, ReferenceSafeHandle reference); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_set_oid(ReferenceSafeHandle reference, ref GitOid id); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_reference_set_target( ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string target); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_reference_target(ReferenceSafeHandle reference); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern GitReferenceType git_reference_type(ReferenceSafeHandle reference); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_remote_free(IntPtr remote); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_remote_load( out RemoteSafeHandle remote, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_remote_name(RemoteSafeHandle remote); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_remote_add( out RemoteSafeHandle remote, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string url); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_remote_new( out RemoteSafeHandle remote, RepositorySafeHandle repo, @@ -563,22 +581,22 @@ public static extern int git_remote_new( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string url, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string fetchrefspec); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_remote_url(RemoteSafeHandle remote); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_remote_save(RemoteSafeHandle remote); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_config( out ConfigurationSafeHandle cfg, RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_odb(out ObjectDatabaseSafeHandle odb, RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_discover( byte[] repository_path, // NB: This is more properly a StringBuilder, but it's UTF8 int size, @@ -586,90 +604,90 @@ public static extern int git_repository_discover( [MarshalAs(UnmanagedType.Bool)] bool across_fs, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath ceiling_dirs); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_repository_free(IntPtr repository); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_head_detached(RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_head_orphan(RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_index(out IndexSafeHandle index, RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_init( out RepositorySafeHandle repository, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path, [MarshalAs(UnmanagedType.Bool)] bool isBare); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_is_bare(RepositorySafeHandle handle); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_is_empty(RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_open( out RepositorySafeHandle repository, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] public static extern FilePath git_repository_path(RepositorySafeHandle repository); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_repository_set_config( RepositorySafeHandle repository, ConfigurationSafeHandle index); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_repository_set_index( RepositorySafeHandle repository, IndexSafeHandle index); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_repository_set_workdir( RepositorySafeHandle repository, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath workdir, bool update_gitlink); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] public static extern FilePath git_repository_workdir(RepositorySafeHandle repository); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_revparse_single( out GitObjectSafeHandle obj, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string spec); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_revwalk_free(IntPtr walker); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_revwalk_hide(RevWalkerSafeHandle walker, ref GitOid oid); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_revwalk_new(out RevWalkerSafeHandle walker, RepositorySafeHandle repo); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_revwalk_next(out GitOid oid, RevWalkerSafeHandle walker); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_revwalk_push(RevWalkerSafeHandle walker, ref GitOid oid); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_revwalk_reset(RevWalkerSafeHandle walker); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_revwalk_sorting(RevWalkerSafeHandle walk, GitSortOptions sort); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_signature_free(IntPtr signature); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_signature_new( out SignatureSafeHandle signature, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name, @@ -677,21 +695,25 @@ public static extern int git_signature_new( long time, int offset); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_status_file( out FileStatus statusflags, RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath filepath); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int status_callback( IntPtr statuspath, uint statusflags, IntPtr payload); - [DllImport(libgit2)] - public static extern int git_status_foreach(RepositorySafeHandle repo, status_callback callback, IntPtr payload); + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] + public static extern int git_status_foreach( + RepositorySafeHandle repo, + [MarshalAs(UnmanagedType.FunctionPtr)] status_callback callback, + IntPtr payload); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_tag_create( out GitOid oid, RepositorySafeHandle repo, @@ -702,7 +724,7 @@ public static extern int git_tag_create( [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_tag_create_lightweight( out GitOid oid, RepositorySafeHandle repo, @@ -711,77 +733,77 @@ public static extern int git_tag_create_lightweight( [MarshalAs(UnmanagedType.Bool)] bool force); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_tag_delete( RepositorySafeHandle repo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string tagName); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_tag_message(GitObjectSafeHandle tag); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_tag_name(GitObjectSafeHandle tag); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr git_tag_tagger(GitObjectSafeHandle tag); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern OidSafeHandle git_tag_target_oid(GitObjectSafeHandle tag); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_threads_init(); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_threads_shutdown(); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_tree_create_fromindex(out GitOid treeOid, IndexSafeHandle index); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_tree_entry_to_object( out GitObjectSafeHandle obj, RepositorySafeHandle repo, TreeEntrySafeHandle_Owned entry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern uint git_tree_entry_attributes(SafeHandle entry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern TreeEntrySafeHandle git_tree_entry_byindex(GitObjectSafeHandle tree, uint idx); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern TreeEntrySafeHandle git_tree_entry_byname( GitObjectSafeHandle tree, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath filename); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_tree_entry_bypath( out TreeEntrySafeHandle_Owned tree, GitObjectSafeHandle root, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath treeentry_path); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_tree_entry_free(IntPtr treeEntry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern OidSafeHandle git_tree_entry_id(SafeHandle entry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] public static extern string git_tree_entry_name(SafeHandle entry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern GitObjectType git_tree_entry_type(SafeHandle entry); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern uint git_tree_entrycount(GitObjectSafeHandle tree); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_treebuilder_create(out TreeBuilderSafeHandle builder, IntPtr src); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_treebuilder_insert( IntPtr entry_out, TreeBuilderSafeHandle builder, @@ -789,10 +811,10 @@ public static extern int git_treebuilder_insert( ref GitOid id, uint attributes); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern int git_treebuilder_write(out GitOid oid, RepositorySafeHandle repo, TreeBuilderSafeHandle bld); - [DllImport(libgit2)] + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] public static extern void git_treebuilder_free(IntPtr bld); } }