Commit b5e8272f by lhchavez

Attempt at fixing the MingW64 compilation

It seems like MingW64's size_t is defined differently than in Linux.
parent 7b453e7e
DISABLE_WARNINGS(implicit-fallthrough)
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
FILE(GLOB SRC_ZLIB "*.c" "*.h") FILE(GLOB SRC_ZLIB "*.c" "*.h")
INCLUDE_DIRECTORIES(".") INCLUDE_DIRECTORIES(".")
......
...@@ -47,9 +47,17 @@ ...@@ -47,9 +47,17 @@
/* Define the printf format specifer to use for size_t output */ /* Define the printf format specifer to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
# if (SIZE_MAX == ULLONG_MAX)
# define PRIuZ "I64u"
# define PRIxZ "I64x"
# define PRIdZ "I64d"
# else
# define PRIuZ "Iu" # define PRIuZ "Iu"
# define PRIxZ "Ix" # define PRIxZ "Ix"
# define PRIdZ "Id" # define PRIdZ "Id"
# endif
#else #else
# define PRIuZ "zu" # define PRIuZ "zu"
# define PRIxZ "zx" # define PRIxZ "zx"
......
...@@ -55,18 +55,26 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t ...@@ -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 */ /* Use clang/gcc compiler intrinsics whenever possible */
#if (SIZE_MAX == ULLONG_MAX) && (__has_builtin(__builtin_uaddl_overflow) || \ #if (__has_builtin(__builtin_add_overflow) || \
(defined(__GNUC__) && (__GNUC__ >= 5))) (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) \ # define git__add_sizet_overflow(out, one, two) \
__builtin_uaddl_overflow(one, two, out) __builtin_uaddl_overflow(one, two, out)
# define git__multiply_sizet_overflow(out, one, two) \ # define git__multiply_sizet_overflow(out, one, two) \
__builtin_umull_overflow(one, two, out) __builtin_umull_overflow(one, two, out)
#elif (__has_builtin(__builtin_add_overflow) || \ # else
(defined(__GNUC__) && (__GNUC__ >= 5)))
# define git__add_sizet_overflow(out, one, two) \ # define git__add_sizet_overflow(out, one, two) \
__builtin_add_overflow(one, two, out) __builtin_add_overflow(one, two, out)
# define git__multiply_sizet_overflow(out, one, two) \ # define git__multiply_sizet_overflow(out, one, two) \
__builtin_mul_overflow(one, two, out) __builtin_mul_overflow(one, two, out)
# endif
#else #else
/** /**
......
#include <stdint.h>
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "vector.h" #include "vector.h"
...@@ -66,14 +68,14 @@ void test_core_vector__2(void) ...@@ -66,14 +68,14 @@ void test_core_vector__2(void)
static int compare_them(const void *a, const void *b) 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 */ /* insert_sorted */
void test_core_vector__3(void) void test_core_vector__3(void)
{ {
git_vector x; git_vector x;
long i; intptr_t i;
git_vector_init(&x, 1, &compare_them); git_vector_init(&x, 1, &compare_them);
for (i = 0; i < 10; i += 2) { for (i = 0; i < 10; i += 2) {
...@@ -96,7 +98,7 @@ void test_core_vector__3(void) ...@@ -96,7 +98,7 @@ void test_core_vector__3(void)
void test_core_vector__4(void) void test_core_vector__4(void)
{ {
git_vector x; git_vector x;
long i; intptr_t i;
git_vector_init(&x, 1, &compare_them); git_vector_init(&x, 1, &compare_them);
for (i = 0; i < 10; i += 2) { for (i = 0; i < 10; i += 2) {
......
...@@ -123,8 +123,8 @@ static void check_stat_data(git_index *index, const char *path, bool match) ...@@ -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_ctime == entry->ctime.seconds);
cl_assert(st.st_mtime == entry->mtime.seconds); cl_assert(st.st_mtime == entry->mtime.seconds);
cl_assert(st.st_size == entry->file_size); cl_assert(st.st_size == entry->file_size);
cl_assert(st.st_uid == entry->uid); cl_assert(st.st_uid == (uid_t)entry->uid);
cl_assert(st.st_gid == entry->gid); cl_assert(st.st_gid == (gid_t)entry->gid);
cl_assert_equal_i_fmt( cl_assert_equal_i_fmt(
GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o"); GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
if (cl_is_chmod_supported()) if (cl_is_chmod_supported())
......
...@@ -150,7 +150,7 @@ static void test_remove_namespace(const wchar_t *in, const wchar_t *expected) ...@@ -150,7 +150,7 @@ static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
cl_assert(wcslen(in) < MAX_PATH); cl_assert(wcslen(in) < MAX_PATH);
wcscpy(canonical, in); 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); cl_assert_equal_wcs(expected, canonical);
#else #else
GIT_UNUSED(in); GIT_UNUSED(in);
......
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