Skip to content

Commit b5e8272

Browse files
committed
Attempt at fixing the MingW64 compilation
It seems like MingW64's size_t is defined differently than in Linux.
1 parent 7b453e7 commit b5e8272

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

deps/zlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
DISABLE_WARNINGS(implicit-fallthrough)
12
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
23
FILE(GLOB SRC_ZLIB "*.c" "*.h")
34
INCLUDE_DIRECTORIES(".")

src/cc-compat.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@
4747

4848
/* Define the printf format specifer to use for size_t output */
4949
#if defined(_MSC_VER) || defined(__MINGW32__)
50-
# define PRIuZ "Iu"
51-
# define PRIxZ "Ix"
52-
# define PRIdZ "Id"
50+
51+
# if (SIZE_MAX == ULLONG_MAX)
52+
# define PRIuZ "I64u"
53+
# define PRIxZ "I64x"
54+
# define PRIdZ "I64d"
55+
# else
56+
# define PRIuZ "Iu"
57+
# define PRIxZ "Ix"
58+
# define PRIdZ "Id"
59+
# endif
60+
5361
#else
5462
# define PRIuZ "zu"
5563
# define PRIxZ "zx"

src/integer.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,26 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t
5555
}
5656

5757
/* Use clang/gcc compiler intrinsics whenever possible */
58-
#if (SIZE_MAX == ULLONG_MAX) && (__has_builtin(__builtin_uaddl_overflow) || \
59-
(defined(__GNUC__) && (__GNUC__ >= 5)))
60-
# define git__add_sizet_overflow(out, one, two) \
61-
__builtin_uaddl_overflow(one, two, out)
62-
# define git__multiply_sizet_overflow(out, one, two) \
63-
__builtin_umull_overflow(one, two, out)
64-
#elif (__has_builtin(__builtin_add_overflow) || \
65-
(defined(__GNUC__) && (__GNUC__ >= 5)))
66-
# define git__add_sizet_overflow(out, one, two) \
67-
__builtin_add_overflow(one, two, out)
68-
# define git__multiply_sizet_overflow(out, one, two) \
69-
__builtin_mul_overflow(one, two, out)
58+
#if (__has_builtin(__builtin_add_overflow) || \
59+
(defined(__GNUC__) && (__GNUC__ >= 5)))
60+
61+
# if (ULONG_MAX == ULLONG_MAX) && defined(_WIN64)
62+
# define git__add_sizet_overflow(out, one, two) \
63+
__builtin_uaddll_overflow(one, two, out)
64+
# define git__multiply_sizet_overflow(out, one, two) \
65+
__builtin_umulll_overflow(one, two, out)
66+
# elif (ULONG_MAX == ULLONG_MAX)
67+
# define git__add_sizet_overflow(out, one, two) \
68+
__builtin_uaddl_overflow(one, two, out)
69+
# define git__multiply_sizet_overflow(out, one, two) \
70+
__builtin_umull_overflow(one, two, out)
71+
# else
72+
# define git__add_sizet_overflow(out, one, two) \
73+
__builtin_add_overflow(one, two, out)
74+
# define git__multiply_sizet_overflow(out, one, two) \
75+
__builtin_mul_overflow(one, two, out)
76+
# endif
77+
7078
#else
7179

7280
/**

tests/core/vector.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdint.h>
2+
13
#include "clar_libgit2.h"
24
#include "vector.h"
35

@@ -66,14 +68,14 @@ void test_core_vector__2(void)
6668

6769
static int compare_them(const void *a, const void *b)
6870
{
69-
return (int)((long)a - (long)b);
71+
return (int)((intptr_t)a - (intptr_t)b);
7072
}
7173

7274
/* insert_sorted */
7375
void test_core_vector__3(void)
7476
{
7577
git_vector x;
76-
long i;
78+
intptr_t i;
7779
git_vector_init(&x, 1, &compare_them);
7880

7981
for (i = 0; i < 10; i += 2) {
@@ -96,7 +98,7 @@ void test_core_vector__3(void)
9698
void test_core_vector__4(void)
9799
{
98100
git_vector x;
99-
long i;
101+
intptr_t i;
100102
git_vector_init(&x, 1, &compare_them);
101103

102104
for (i = 0; i < 10; i += 2) {

tests/index/addall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ static void check_stat_data(git_index *index, const char *path, bool match)
123123
cl_assert(st.st_ctime == entry->ctime.seconds);
124124
cl_assert(st.st_mtime == entry->mtime.seconds);
125125
cl_assert(st.st_size == entry->file_size);
126-
cl_assert(st.st_uid == entry->uid);
127-
cl_assert(st.st_gid == entry->gid);
126+
cl_assert(st.st_uid == (uid_t)entry->uid);
127+
cl_assert(st.st_gid == (gid_t)entry->gid);
128128
cl_assert_equal_i_fmt(
129129
GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
130130
if (cl_is_chmod_supported())

tests/path/win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
150150
cl_assert(wcslen(in) < MAX_PATH);
151151
wcscpy(canonical, in);
152152

153-
cl_must_pass(git_win32_path_remove_namespace(canonical, wcslen(in)));
153+
git_win32_path_remove_namespace(canonical, wcslen(in));
154154
cl_assert_equal_wcs(expected, canonical);
155155
#else
156156
GIT_UNUSED(in);

0 commit comments

Comments
 (0)