Skip to content

Commit a74dd39

Browse files
committed
Use cdecl calling conventions on Win32
The recommendation from engineers within Microsoft is that libraries should have a calling convention specified in the public API, and that calling convention should be cdecl unless there are strong reasons to use a different calling convention. We previously offered end-users the choice between cdecl and stdcall calling conventions. We did this for presumed wider compatibility: most Windows applications will use cdecl, but C# and PInvoke default to stdcall for WINAPI compatibility. (On Windows, the standard library functions are are stdcall so PInvoke also defaults to stdcall.) However, C# and PInvoke can easily call cdecl APIs by specifying an annotation. Thus, we will explicitly declare ourselves cdecl and remove the option to build as stdcall.
1 parent b78bcbb commit a74dd39

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

CMakeLists.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ IF (APPLE)
7474
ENDIF()
7575

7676
IF(MSVC)
77-
# This option is only available when building with MSVC. By default, libgit2
78-
# is build using the cdecl calling convention, which is useful if you're
79-
# writing C. However, the CLR and Win32 API both expect stdcall.
80-
#
81-
# If you are writing a CLR program and want to link to libgit2, you'll want
82-
# to turn this on by invoking CMake with the "-DSTDCALL=ON" argument.
83-
OPTION(STDCALL "Build libgit2 with the __stdcall convention" OFF)
84-
8577
# This option must match the settings used in your program, in particular if you
8678
# are linking statically
8779
OPTION(STATIC_CRT "Link the static CRT libraries" ON)
@@ -125,10 +117,8 @@ IF (MSVC)
125117
# /MP - Parallel build
126118
SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
127119

128-
IF (STDCALL)
129-
# /Gz - stdcall calling convention
130-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz")
131-
ENDIF ()
120+
# /Gd - explicitly set cdecl calling convention
121+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
132122

133123
IF (STATIC_CRT)
134124
SET(CRT_FLAG_DEBUG "/MTd")

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ The following CMake variables are declared:
255255
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
256256
- `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
257257
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
258-
- `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON)
259258

260259
To list all build options and their current value, you can do the
261260
following:

include/git2/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef size_t size_t;
4343
__attribute__((visibility("default"))) \
4444
type
4545
#elif defined(_MSC_VER)
46-
# define GIT_EXTERN(type) __declspec(dllexport) type
46+
# define GIT_EXTERN(type) __declspec(dllexport) type __cdecl
4747
#else
4848
# define GIT_EXTERN(type) extern type
4949
#endif

0 commit comments

Comments
 (0)