Commit a74dd39b by Edward Thomson

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.
parent b78bcbb9
......@@ -74,14 +74,6 @@ IF (APPLE)
ENDIF()
IF(MSVC)
# This option is only available when building with MSVC. By default, libgit2
# is build using the cdecl calling convention, which is useful if you're
# writing C. However, the CLR and Win32 API both expect stdcall.
#
# If you are writing a CLR program and want to link to libgit2, you'll want
# to turn this on by invoking CMake with the "-DSTDCALL=ON" argument.
OPTION(STDCALL "Build libgit2 with the __stdcall convention" OFF)
# This option must match the settings used in your program, in particular if you
# are linking statically
OPTION(STATIC_CRT "Link the static CRT libraries" ON)
......@@ -125,10 +117,8 @@ IF (MSVC)
# /MP - Parallel build
SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
IF (STDCALL)
# /Gz - stdcall calling convention
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz")
ENDIF ()
# /Gd - explicitly set cdecl calling convention
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
IF (STATIC_CRT)
SET(CRT_FLAG_DEBUG "/MTd")
......
......@@ -255,7 +255,6 @@ The following CMake variables are declared:
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
- `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
- `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON)
To list all build options and their current value, you can do the
following:
......
......@@ -43,7 +43,7 @@ typedef size_t size_t;
__attribute__((visibility("default"))) \
type
#elif defined(_MSC_VER)
# define GIT_EXTERN(type) __declspec(dllexport) type
# define GIT_EXTERN(type) __declspec(dllexport) type __cdecl
#else
# define GIT_EXTERN(type) extern type
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment