From 85fee2565364cb31b72252a07538c97a52e48ca7 Mon Sep 17 00:00:00 2001 From: Marcus Geelnard Date: Wed, 8 May 2019 14:59:06 +0200 Subject: MinGW fix: Use _MSC_VER instead of _WIN32 where appropriate Use _MSC_VER (instead of _WIN32) for things that are specific for Visual Studio. Also remove #include from hiredis.h, as it leaks too many symbols and defines into the global namespace, which is undesirable for a public interface header. Anyone who uses the the affected parts of the hiredis API needs to include the appropriate headers anyway in order to declare struct timeval variables. --- async.c | 6 ++---- hiredis.h | 4 ++-- sds.h | 2 +- sockcompat.h | 2 ++ win32.h | 10 ++++++++++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/async.c b/async.c index 171fabd..e46573f 100644 --- a/async.c +++ b/async.c @@ -32,11 +32,8 @@ #include "fmacros.h" #include #include -#ifndef _WIN32 +#ifndef _MSC_VER #include -#else -#define strcasecmp stricmp -#define strncasecmp strnicmp #endif #include #include @@ -46,6 +43,7 @@ #include "dict.c" #include "sds.h" #include "sslio.h" +#include "win32.h" #define _EL_ADD_READ(ctx) \ do { \ diff --git a/hiredis.h b/hiredis.h index 1ae1c0a..63eef3a 100644 --- a/hiredis.h +++ b/hiredis.h @@ -35,10 +35,10 @@ #define __HIREDIS_H #include "read.h" #include /* for va_list */ -#ifndef _WIN32 +#ifndef _MSC_VER #include /* for struct timeval */ #else -#include +struct timeval; /* forward declaration */ #endif #include /* uintXX_t, etc */ #include "sds.h" /* for sds */ diff --git a/sds.h b/sds.h index eafe2cf..bc92389 100644 --- a/sds.h +++ b/sds.h @@ -34,7 +34,7 @@ #define __SDS_H #define SDS_MAX_PREALLOC (1024*1024) -#ifdef _WIN32 +#ifdef _MSC_VER #define __attribute__(x) #endif diff --git a/sockcompat.h b/sockcompat.h index e0b2e5e..56006c1 100644 --- a/sockcompat.h +++ b/sockcompat.h @@ -50,7 +50,9 @@ #include #include +#ifdef _MSC_VER typedef signed long ssize_t; +#endif /* Emulate the parts of the BSD socket API that we need (override the winsock signatures). */ int win32_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); diff --git a/win32.h b/win32.h index 7cb5706..04289c6 100644 --- a/win32.h +++ b/win32.h @@ -2,10 +2,20 @@ #define _WIN32_HELPER_INCLUDE #ifdef _MSC_VER +#include /* for struct timeval */ + #ifndef inline #define inline __inline #endif +#ifndef strcasecmp +#define strcasecmp stricmp +#endif + +#ifndef strncasecmp +#define strncasecmp strnicmp +#endif + #ifndef va_copy #define va_copy(d,s) ((d) = (s)) #endif -- cgit v1.2.3 From 173f16ab55766ad8792d0c077829efdba188e560 Mon Sep 17 00:00:00 2001 From: Marcus Geelnard Date: Wed, 8 May 2019 16:04:34 +0200 Subject: MSVC: Fix some compiler warnings in sds.h --- sds.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/sds.h b/sds.h index bc92389..3f9a964 100644 --- a/sds.h +++ b/sds.h @@ -135,20 +135,20 @@ static inline void sdssetlen(sds s, size_t newlen) { case SDS_TYPE_5: { unsigned char *fp = ((unsigned char*)s)-1; - *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); + *fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS)); } break; case SDS_TYPE_8: - SDS_HDR(8,s)->len = newlen; + SDS_HDR(8,s)->len = (uint8_t)newlen; break; case SDS_TYPE_16: - SDS_HDR(16,s)->len = newlen; + SDS_HDR(16,s)->len = (uint16_t)newlen; break; case SDS_TYPE_32: - SDS_HDR(32,s)->len = newlen; + SDS_HDR(32,s)->len = (uint32_t)newlen; break; case SDS_TYPE_64: - SDS_HDR(64,s)->len = newlen; + SDS_HDR(64,s)->len = (uint64_t)newlen; break; } } @@ -159,21 +159,21 @@ static inline void sdsinclen(sds s, size_t inc) { case SDS_TYPE_5: { unsigned char *fp = ((unsigned char*)s)-1; - unsigned char newlen = SDS_TYPE_5_LEN(flags)+inc; + unsigned char newlen = SDS_TYPE_5_LEN(flags)+(unsigned char)inc; *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); } break; case SDS_TYPE_8: - SDS_HDR(8,s)->len += inc; + SDS_HDR(8,s)->len += (uint8_t)inc; break; case SDS_TYPE_16: - SDS_HDR(16,s)->len += inc; + SDS_HDR(16,s)->len += (uint16_t)inc; break; case SDS_TYPE_32: - SDS_HDR(32,s)->len += inc; + SDS_HDR(32,s)->len += (uint32_t)inc; break; case SDS_TYPE_64: - SDS_HDR(64,s)->len += inc; + SDS_HDR(64,s)->len += (uint64_t)inc; break; } } @@ -203,16 +203,16 @@ static inline void sdssetalloc(sds s, size_t newlen) { /* Nothing to do, this type has no total allocation info. */ break; case SDS_TYPE_8: - SDS_HDR(8,s)->alloc = newlen; + SDS_HDR(8,s)->alloc = (uint8_t)newlen; break; case SDS_TYPE_16: - SDS_HDR(16,s)->alloc = newlen; + SDS_HDR(16,s)->alloc = (uint16_t)newlen; break; case SDS_TYPE_32: - SDS_HDR(32,s)->alloc = newlen; + SDS_HDR(32,s)->alloc = (uint32_t)newlen; break; case SDS_TYPE_64: - SDS_HDR(64,s)->alloc = newlen; + SDS_HDR(64,s)->alloc = (uint64_t)newlen; break; } } -- cgit v1.2.3 From 687997c410bc81ecd46d9ac23abbcfc7053c449a Mon Sep 17 00:00:00 2001 From: Marcus Geelnard Date: Wed, 8 May 2019 16:25:12 +0200 Subject: Travis: Add a MinGW cross compilation test --- .travis.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.travis.yml b/.travis.yml index 51171c0..037b502 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,3 +56,20 @@ script: - cmake .. ${EXTRA_CMAKE_OPTS} - make VERBOSE=1 - ctest -V + +matrix: + include: + # Windows MinGW cross compile on Linux + - os: linux + dist: xenial + compiler: mingw + addons: + apt: + packages: + - ninja-build + - gcc-mingw-w64-x86-64 + - g++-mingw-w64-x86-64 + script: + - mkdir build && cd build + - CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_WITH_INSTALL_RPATH=on + - ninja -v -- cgit v1.2.3 From bbbafc5324aa0986c486756f260853fc8e8faf93 Mon Sep 17 00:00:00 2001 From: Marcus Geelnard Date: Wed, 8 May 2019 16:32:49 +0200 Subject: Travis: Add a Windows MSVC 2017 compilation test --- .travis.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index 037b502..4a29823 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,3 +73,19 @@ matrix: - mkdir build && cd build - CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_WITH_INSTALL_RPATH=on - ninja -v + + # Windows MSVC 2017 + - os: windows + compiler: msvc + env: + - MATRIX_EVAL="CC=cl.exe && CXX=cl.exe" + before_install: + - eval "${MATRIX_EVAL}" + install: + - choco install ninja + script: + - mkdir build && cd build + - cmd.exe /C '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 && + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release && + ninja -v' + - ctest -V -- cgit v1.2.3