From 11b5beb7ba92ae1214f1fec91d8e13df2e6dca01 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 27 Feb 2013 15:07:28 -0800 Subject: [PATCH 1/4] use cdecl for hashsig sorting functions on Windows --- src/hashsig.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hashsig.c b/src/hashsig.c index 60649fd11..9fe8f6671 100644 --- a/src/hashsig.c +++ b/src/hashsig.c @@ -19,7 +19,14 @@ typedef uint64_t hashsig_state; #define HASHSIG_HEAP_SIZE ((1 << 7) - 1) -typedef int (*hashsig_cmp)(const void *a, const void *b); +/* going to use qsort so jump through some Windows hoops */ +#ifdef GIT_WIN32 +#define GIT_CDECL __cdecl +#else +#define GIT_CDECL +#endif + +typedef int (GIT_CDECL *hashsig_cmp)(const void *a, const void *b); typedef struct { int size, asize; @@ -53,13 +60,13 @@ static void hashsig_heap_init(hashsig_heap *h, hashsig_cmp cmp) h->cmp = cmp; } -static int hashsig_cmp_max(const void *a, const void *b) +static int GIT_CDECL hashsig_cmp_max(const void *a, const void *b) { hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; return (av < bv) ? -1 : (av > bv) ? 1 : 0; } -static int hashsig_cmp_min(const void *a, const void *b) +static int GIT_CDECL hashsig_cmp_min(const void *a, const void *b) { hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; return (av > bv) ? -1 : (av < bv) ? 1 : 0; From f708c89fa6e0d156d7b083de53d311babd3d2d8c Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 27 Feb 2013 15:15:39 -0800 Subject: [PATCH 2/4] fixing some warnings on Windows --- src/hashsig.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hashsig.c b/src/hashsig.c index 9fe8f6671..b6020e7f3 100644 --- a/src/hashsig.c +++ b/src/hashsig.c @@ -190,8 +190,8 @@ static void hashsig_initial_window( /* insert initial hash if we just finished */ if (win_len == HASHSIG_HASH_WINDOW) { - hashsig_heap_insert(&sig->mins, state); - hashsig_heap_insert(&sig->maxs, state); + hashsig_heap_insert(&sig->mins, (hashsig_t)state); + hashsig_heap_insert(&sig->maxs, (hashsig_t)state); sig->considered = 1; } @@ -231,8 +231,8 @@ static int hashsig_add_hashes( state = (state * HASHSIG_HASH_SHIFT) & HASHSIG_HASH_MASK; state = (state + ch) & HASHSIG_HASH_MASK; - hashsig_heap_insert(&sig->mins, state); - hashsig_heap_insert(&sig->maxs, state); + hashsig_heap_insert(&sig->mins, (hashsig_t)state); + hashsig_heap_insert(&sig->maxs, (hashsig_t)state); sig->considered++; prog->window[prog->win_pos] = ch; @@ -314,7 +314,7 @@ int git_hashsig_create_fromfile( while (!error) { if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) { - if ((error = buflen) < 0) + if ((error = (int)buflen) < 0) giterr_set(GITERR_OS, "Read error on '%s' calculating similarity hashes", path); break; From 97b7137459a64e24fbe5ef16bee254cae6b018a1 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 28 Feb 2013 14:14:45 -0800 Subject: [PATCH 3/4] Add GIT_STDLIB_CALL This removes the one-off GIT_CDECL and adds a new standard way of doing this named GIT_STDLIB_CALL with a src/win32 specific def when on the Windows platform. --- src/common.h | 2 ++ src/hashsig.c | 13 +++---------- src/win32/msvc-compat.h | 2 ++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/common.h b/src/common.h index ca203ee5c..48c4b5453 100644 --- a/src/common.h +++ b/src/common.h @@ -41,6 +41,8 @@ # ifdef GIT_THREADS # include # endif +#define GIT_STDLIB_CALL + #endif #include "git2/types.h" diff --git a/src/hashsig.c b/src/hashsig.c index b6020e7f3..e9c5164a4 100644 --- a/src/hashsig.c +++ b/src/hashsig.c @@ -19,14 +19,7 @@ typedef uint64_t hashsig_state; #define HASHSIG_HEAP_SIZE ((1 << 7) - 1) -/* going to use qsort so jump through some Windows hoops */ -#ifdef GIT_WIN32 -#define GIT_CDECL __cdecl -#else -#define GIT_CDECL -#endif - -typedef int (GIT_CDECL *hashsig_cmp)(const void *a, const void *b); +typedef int (GIT_STDLIB_CALL *hashsig_cmp)(const void *a, const void *b); typedef struct { int size, asize; @@ -60,13 +53,13 @@ static void hashsig_heap_init(hashsig_heap *h, hashsig_cmp cmp) h->cmp = cmp; } -static int GIT_CDECL hashsig_cmp_max(const void *a, const void *b) +static int GIT_STDLIB_CALL hashsig_cmp_max(const void *a, const void *b) { hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; return (av < bv) ? -1 : (av > bv) ? 1 : 0; } -static int GIT_CDECL hashsig_cmp_min(const void *a, const void *b) +static int GIT_STDLIB_CALL hashsig_cmp_min(const void *a, const void *b) { hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b; return (av > bv) ? -1 : (av < bv) ? 1 : 0; diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h index 714a85e21..df2111dc8 100644 --- a/src/win32/msvc-compat.h +++ b/src/win32/msvc-compat.h @@ -39,4 +39,6 @@ typedef SSIZE_T ssize_t; #endif +#define GIT_STDLIB_CALL __cdecl + #endif /* INCLUDE_msvc_compat__ */ From f443a72d334f8f52c3431e6b4181704a3f125d5e Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 28 Feb 2013 14:41:26 -0800 Subject: [PATCH 4/4] Fix some deprecation warnings on Windows This fixes some snprintf and vsnprintf related deprecation warnings we've been having on Windows with recent compilers. --- src/common.h | 4 +--- src/win32/msvc-compat.h | 7 +++++++ src/win32/posix_w32.c | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common.h b/src/common.h index 48c4b5453..e3a9e1984 100644 --- a/src/common.h +++ b/src/common.h @@ -33,11 +33,9 @@ # include "win32/pthread.h" #endif -# define snprintf _snprintf - #else -# include +# include # ifdef GIT_THREADS # include # endif diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h index df2111dc8..50865ed17 100644 --- a/src/win32/msvc-compat.h +++ b/src/win32/msvc-compat.h @@ -37,6 +37,13 @@ /* MSVC doesn't define ssize_t at all */ typedef SSIZE_T ssize_t; +/* define snprintf using variadic macro support if available */ +#if _MSC_VER >= 1400 +# define snprintf(BUF, SZ, FMT, ...) _snprintf_s(BUF, SZ, _TRUNCATE, FMT, __VA_ARGS__) +#else +# define snprintf _snprintf +#endif + #endif #define GIT_STDLIB_CALL __cdecl diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index f533eaa5e..83b11ff41 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -375,7 +375,8 @@ int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) #ifdef _MSC_VER int len; - if (count == 0 || (len = _vsnprintf(buffer, count, format, argptr)) < 0) + if (count == 0 || + (len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr)) < 0) return _vscprintf(format, argptr); return len;