Skip to content

Commit 4e0c8a1

Browse files
authored
Merge pull request libgit2#4930 from libgit2/ethomson/cdecl
Always build a cdecl library
2 parents 6e17bfd + 38e6179 commit 4e0c8a1

38 files changed

+173
-170
lines changed

CMakeLists.txt

Lines changed: 6 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)
@@ -115,6 +107,10 @@ STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "$
115107

116108
# Platform specific compilation flags
117109
IF (MSVC)
110+
IF (STDCALL)
111+
MESSAGE(FATAL_ERROR "The STDCALL option is no longer supported; libgit2 is now always built as a cdecl library. If you're using PInvoke, please add the CallingConventions.Cdecl attribute for support.")
112+
ENDIF()
113+
118114
ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
119115
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
120116
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
@@ -125,10 +121,8 @@ IF (MSVC)
125121
# /MP - Parallel build
126122
SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
127123

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

133127
IF (STATIC_CRT)
134128
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:

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ v0.27 + 1
33

44
### Changes or improvements
55

6+
* The library is now always built with cdecl calling conventions on
7+
Windows; the ability to build a stdcall library has been removed.
8+
69
* Reference log creation now honors `core.logallrefupdates=always`.
710

811
* Fix some issues with the error-reporting in the OpenSSL backend.

include/git2/apply.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ GIT_BEGIN_DECL
3333
* @param delta The delta to be applied
3434
* @param payload User-specified payload
3535
*/
36-
typedef int (*git_apply_delta_cb)(
36+
typedef int GIT_CALLBACK(git_apply_delta_cb)(
3737
const git_diff_delta *delta,
3838
void *payload);
3939

@@ -49,7 +49,7 @@ typedef int (*git_apply_delta_cb)(
4949
* @param hunk The hunk to be applied
5050
* @param payload User-specified payload
5151
*/
52-
typedef int (*git_apply_hunk_cb)(
52+
typedef int GIT_CALLBACK(git_apply_hunk_cb)(
5353
const git_diff_hunk *hunk,
5454
void *payload);
5555

include/git2/attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ GIT_EXTERN(int) git_attr_get_many(
202202
* @return 0 to continue looping, non-zero to stop. This value will be returned
203203
* from git_attr_foreach.
204204
*/
205-
typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *payload);
205+
typedef int GIT_CALLBACK(git_attr_foreach_cb)(const char *name, const char *value, void *payload);
206206

207207
/**
208208
* Loop over all the git attributes for a path.

include/git2/buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ GIT_EXTERN(void) git_buf_dispose(git_buf *buffer);
8181
*
8282
* This function is going to be removed in v0.30.0.
8383
*/
84-
GIT_EXTERN(void) GIT_DEPRECATED(git_buf_free)(git_buf *buffer);
84+
GIT_DEPRECATED(GIT_EXTERN(void)) git_buf_free(git_buf *buffer);
8585

8686
/**
8787
* Resize the buffer allocation to make more space.

include/git2/checkout.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ typedef struct {
220220
} git_checkout_perfdata;
221221

222222
/** Checkout notification callback function */
223-
typedef int (*git_checkout_notify_cb)(
223+
typedef int GIT_CALLBACK(git_checkout_notify_cb)(
224224
git_checkout_notify_t why,
225225
const char *path,
226226
const git_diff_file *baseline,
@@ -229,14 +229,14 @@ typedef int (*git_checkout_notify_cb)(
229229
void *payload);
230230

231231
/** Checkout progress notification function */
232-
typedef void (*git_checkout_progress_cb)(
232+
typedef void GIT_CALLBACK(git_checkout_progress_cb)(
233233
const char *path,
234234
size_t completed_steps,
235235
size_t total_steps,
236236
void *payload);
237237

238238
/** Checkout perfdata notification function */
239-
typedef void (*git_checkout_perfdata_cb)(
239+
typedef void GIT_CALLBACK(git_checkout_perfdata_cb)(
240240
const git_checkout_perfdata *perfdata,
241241
void *payload);
242242

include/git2/clone.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef enum {
6666
* @param payload an opaque payload
6767
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
6868
*/
69-
typedef int (*git_remote_create_cb)(
69+
typedef int GIT_CALLBACK(git_remote_create_cb)(
7070
git_remote **out,
7171
git_repository *repo,
7272
const char *name,
@@ -87,7 +87,7 @@ typedef int (*git_remote_create_cb)(
8787
* @param payload payload specified by the options
8888
* @return 0, or a negative value to indicate error
8989
*/
90-
typedef int (*git_repository_create_cb)(
90+
typedef int GIT_CALLBACK(git_repository_create_cb)(
9191
git_repository **out,
9292
const char *path,
9393
int bare,

include/git2/common.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ 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
5050

51+
/** Declare a callback function for application use. */
52+
#if defined(_MSC_VER)
53+
# define GIT_CALLBACK(name) (__cdecl *name)
54+
#else
55+
# define GIT_CALLBACK(name) (*name)
56+
#endif
57+
5158
/** Declare a function as deprecated. */
5259
#if defined(__GNUC__)
5360
# define GIT_DEPRECATED(func) \

include/git2/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef struct git_config_entry {
6666
const char *value; /**< String value of the entry */
6767
unsigned int include_depth; /**< Depth of includes where this variable was found */
6868
git_config_level_t level; /**< Which config file this was found in */
69-
void (*free)(struct git_config_entry *entry); /**< Free function for this entry */
69+
void GIT_CALLBACK(free)(struct git_config_entry *entry); /**< Free function for this entry */
7070
void *payload; /**< Opaque value for the free function. Do not read or write */
7171
} git_config_entry;
7272

@@ -81,7 +81,7 @@ GIT_EXTERN(void) git_config_entry_free(git_config_entry *);
8181
* @param entry the entry currently being enumerated
8282
* @param payload a user-specified pointer
8383
*/
84-
typedef int (*git_config_foreach_cb)(const git_config_entry *entry, void *payload);
84+
typedef int GIT_CALLBACK(git_config_foreach_cb)(const git_config_entry *entry, void *payload);
8585

8686
/**
8787
* An opaque structure for a configuration iterator

0 commit comments

Comments
 (0)