diff options
author | lhchavez <lhchavez@lhchavez.com> | 2019-01-06 08:29:56 -0800 |
---|---|---|
committer | lhchavez <lhchavez@lhchavez.com> | 2019-01-06 08:29:56 -0800 |
commit | b5e8272fdcab4e7f238a72d0b9c9fc9c753fd381 (patch) | |
tree | 413dcc28a6d67e6301028e2b77ca316c620efff7 | |
parent | 7b453e7e39c6e27d63be0922a153e1cb47f33218 (diff) | |
download | libgit2-b5e8272fdcab4e7f238a72d0b9c9fc9c753fd381.tar.gz |
Attempt at fixing the MingW64 compilation
It seems like MingW64's size_t is defined differently than in Linux.
-rw-r--r-- | deps/zlib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/cc-compat.h | 14 | ||||
-rw-r--r-- | src/integer.h | 32 | ||||
-rw-r--r-- | tests/core/vector.c | 8 | ||||
-rw-r--r-- | tests/index/addall.c | 4 | ||||
-rw-r--r-- | tests/path/win32.c | 2 |
6 files changed, 40 insertions, 21 deletions
diff --git a/deps/zlib/CMakeLists.txt b/deps/zlib/CMakeLists.txt index b0cb7f7ea..afa5a19af 100644 --- a/deps/zlib/CMakeLists.txt +++ b/deps/zlib/CMakeLists.txt @@ -1,3 +1,4 @@ +DISABLE_WARNINGS(implicit-fallthrough) ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) FILE(GLOB SRC_ZLIB "*.c" "*.h") INCLUDE_DIRECTORIES(".") diff --git a/src/cc-compat.h b/src/cc-compat.h index 0f05cd2d9..5d3e652b1 100644 --- a/src/cc-compat.h +++ b/src/cc-compat.h @@ -47,9 +47,17 @@ /* Define the printf format specifer to use for size_t output */ #if defined(_MSC_VER) || defined(__MINGW32__) -# define PRIuZ "Iu" -# define PRIxZ "Ix" -# define PRIdZ "Id" + +# if (SIZE_MAX == ULLONG_MAX) +# define PRIuZ "I64u" +# define PRIxZ "I64x" +# define PRIdZ "I64d" +# else +# define PRIuZ "Iu" +# define PRIxZ "Ix" +# define PRIdZ "Id" +# endif + #else # define PRIuZ "zu" # define PRIxZ "zx" diff --git a/src/integer.h b/src/integer.h index d56b19dd8..a10ee992a 100644 --- a/src/integer.h +++ b/src/integer.h @@ -55,18 +55,26 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t } /* Use clang/gcc compiler intrinsics whenever possible */ -#if (SIZE_MAX == ULLONG_MAX) && (__has_builtin(__builtin_uaddl_overflow) || \ - (defined(__GNUC__) && (__GNUC__ >= 5))) -# define git__add_sizet_overflow(out, one, two) \ - __builtin_uaddl_overflow(one, two, out) -# define git__multiply_sizet_overflow(out, one, two) \ - __builtin_umull_overflow(one, two, out) -#elif (__has_builtin(__builtin_add_overflow) || \ - (defined(__GNUC__) && (__GNUC__ >= 5))) -# define git__add_sizet_overflow(out, one, two) \ - __builtin_add_overflow(one, two, out) -# define git__multiply_sizet_overflow(out, one, two) \ - __builtin_mul_overflow(one, two, out) +#if (__has_builtin(__builtin_add_overflow) || \ + (defined(__GNUC__) && (__GNUC__ >= 5))) + +# if (ULONG_MAX == ULLONG_MAX) && defined(_WIN64) +# define git__add_sizet_overflow(out, one, two) \ + __builtin_uaddll_overflow(one, two, out) +# define git__multiply_sizet_overflow(out, one, two) \ + __builtin_umulll_overflow(one, two, out) +# elif (ULONG_MAX == ULLONG_MAX) +# define git__add_sizet_overflow(out, one, two) \ + __builtin_uaddl_overflow(one, two, out) +# define git__multiply_sizet_overflow(out, one, two) \ + __builtin_umull_overflow(one, two, out) +# else +# define git__add_sizet_overflow(out, one, two) \ + __builtin_add_overflow(one, two, out) +# define git__multiply_sizet_overflow(out, one, two) \ + __builtin_mul_overflow(one, two, out) +# endif + #else /** diff --git a/tests/core/vector.c b/tests/core/vector.c index 2be7e86bd..a7e1a0325 100644 --- a/tests/core/vector.c +++ b/tests/core/vector.c @@ -1,3 +1,5 @@ +#include <stdint.h> + #include "clar_libgit2.h" #include "vector.h" @@ -66,14 +68,14 @@ void test_core_vector__2(void) static int compare_them(const void *a, const void *b) { - return (int)((long)a - (long)b); + return (int)((intptr_t)a - (intptr_t)b); } /* insert_sorted */ void test_core_vector__3(void) { git_vector x; - long i; + intptr_t i; git_vector_init(&x, 1, &compare_them); for (i = 0; i < 10; i += 2) { @@ -96,7 +98,7 @@ void test_core_vector__3(void) void test_core_vector__4(void) { git_vector x; - long i; + intptr_t i; git_vector_init(&x, 1, &compare_them); for (i = 0; i < 10; i += 2) { diff --git a/tests/index/addall.c b/tests/index/addall.c index 49e507901..12b05a741 100644 --- a/tests/index/addall.c +++ b/tests/index/addall.c @@ -123,8 +123,8 @@ static void check_stat_data(git_index *index, const char *path, bool match) cl_assert(st.st_ctime == entry->ctime.seconds); cl_assert(st.st_mtime == entry->mtime.seconds); cl_assert(st.st_size == entry->file_size); - cl_assert(st.st_uid == entry->uid); - cl_assert(st.st_gid == entry->gid); + cl_assert(st.st_uid == (uid_t)entry->uid); + cl_assert(st.st_gid == (gid_t)entry->gid); cl_assert_equal_i_fmt( GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o"); if (cl_is_chmod_supported()) diff --git a/tests/path/win32.c b/tests/path/win32.c index f45bf58b4..3ed7d7a6a 100644 --- a/tests/path/win32.c +++ b/tests/path/win32.c @@ -150,7 +150,7 @@ static void test_remove_namespace(const wchar_t *in, const wchar_t *expected) cl_assert(wcslen(in) < MAX_PATH); wcscpy(canonical, in); - cl_must_pass(git_win32_path_remove_namespace(canonical, wcslen(in))); + git_win32_path_remove_namespace(canonical, wcslen(in)); cl_assert_equal_wcs(expected, canonical); #else GIT_UNUSED(in); |