Commit 42d5f11084c67f8c96693bd42b424b0262be3f84

Edward Thomson 2020-12-08T14:33:31

win32: provide macros for calling conventions Provide more clarity for Win32 calling conventions - now that we always compile to __cdecl on Win32, we'll define that as the the libgit2 calling convention. Also offer NTAPI (__stdcall) calling conventions for things that need callbacks from NTAPI code (eg fiber-local storage).

diff --git a/src/common.h b/src/common.h
index a4ddcf9..bda3edb 100644
--- a/src/common.h
+++ b/src/common.h
@@ -63,7 +63,9 @@
 #	include <pthread.h>
 #	include <sched.h>
 # endif
-#define GIT_STDLIB_CALL
+
+#define GIT_LIBGIT2_CALL
+#define GIT_SYSTEM_CALL
 
 #ifdef GIT_USE_STAT_ATIMESPEC
 # define st_atim st_atimespec
diff --git a/src/util.c b/src/util.c
index 18a02a2..87ccf32 100644
--- a/src/util.c
+++ b/src/util.c
@@ -687,7 +687,7 @@ typedef struct {
 	void *payload;
 } git__qsort_r_glue;
 
-static int GIT_STDLIB_CALL git__qsort_r_glue_cmp(
+static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp(
 	void *payload, const void *a, const void *b)
 {
 	git__qsort_r_glue *glue = payload;
diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h
index 4cf471f..03f9f36 100644
--- a/src/win32/msvc-compat.h
+++ b/src/win32/msvc-compat.h
@@ -23,6 +23,14 @@ typedef SSIZE_T ssize_t;
 
 #endif
 
-#define GIT_STDLIB_CALL __cdecl
+/*
+ * Offer GIT_LIBGIT2_CALL for our calling conventions (__cdecl, always).
+ * This is useful for providing callbacks to userspace code.
+ *
+ * Offer GIT_SYSTEM_CALL for the system calling conventions (__stdcall on
+ * Win32).  Useful for providing callbacks to system libraries.
+ */
+#define GIT_LIBGIT2_CALL __cdecl
+#define GIT_SYSTEM_CALL NTAPI
 
 #endif