From 54001f3dbccce12496be78eebf3c543b8376cced Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Sep 2018 14:46:09 -0700 Subject: [PATCH 1/3] fix mingw compatibility only enable backtraces for platforms we know support it aka mac OS-X and Linux. can be extended later. --- programs/fileio.c | 12 ++++++++---- programs/util.h | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 5f6b12e5..e08920ba 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -20,6 +20,9 @@ # define _POSIX_SOURCE 1 /* disable %llu warnings with MinGW on Windows */ #endif +#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) +# define BACKTRACES_ENABLE 1 +#endif /*-************************************* * Includes @@ -31,8 +34,8 @@ #include /* strcmp, strlen */ #include /* errno */ #include -#ifndef _WIN32 -#include /* backtrace, backtrace_symbols */ +#ifdef BACKTRACES_ENABLE +# include /* backtrace, backtrace_symbols */ #endif #if defined (_MSC_VER) @@ -162,9 +165,10 @@ static void clearHandler(void) /*-********************************************************* * Termination signal trapping (Print debug stack trace) ***********************************************************/ +#ifdef BACKTRACES_ENABLE + #define MAX_STACK_FRAMES 50 -#ifndef _WIN32 static void ABRThandler(int sig) { const char* name; void* addrlist[MAX_STACK_FRAMES]; @@ -202,7 +206,7 @@ static void ABRThandler(int sig) { void FIO_addAbortHandler() { -#ifndef _WIN32 +#ifdef BACKTRACES_ENABLE signal(SIGABRT, ABRThandler); signal(SIGFPE, ABRThandler); signal(SIGILL, ABRThandler); diff --git a/programs/util.h b/programs/util.h index 8993bf96..e8288b8f 100644 --- a/programs/util.h +++ b/programs/util.h @@ -170,7 +170,11 @@ static int g_utilDisplayLevel; return ((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom); } -#elif (PLATFORM_POSIX_VERSION >= 200112L) && (defined __UCLIBC__ || ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2)) +#elif (PLATFORM_POSIX_VERSION >= 200112L) \ + && (defined(__UCLIBC__) \ + || (defined(__GLIBC__) \ + && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) \ + || (__GLIBC__ > 2)))) #define UTIL_TIME_INITIALIZER { 0, 0 } typedef struct timespec UTIL_freq_t; From 123fac6b6dd168b9ed8c4844eba9080d7084acb1 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Sep 2018 17:36:00 -0700 Subject: [PATCH 2/3] fix pzstd compatibility with mingw some details changed with introduction of gcc7 --- contrib/pzstd/Options.cpp | 11 ----------- contrib/pzstd/Pzstd.cpp | 9 +-------- zlibWrapper/gzguts.h | 4 ++-- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/contrib/pzstd/Options.cpp b/contrib/pzstd/Options.cpp index 1590d85e..2123f889 100644 --- a/contrib/pzstd/Options.cpp +++ b/contrib/pzstd/Options.cpp @@ -18,17 +18,6 @@ #include #include -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || \ - defined(__CYGWIN__) -#include /* _isatty */ -#define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) -#elif defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) || \ - defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* https://sourceforge.net/p/predef/wiki/OperatingSystems/ */ -#include /* isatty */ -#define IS_CONSOLE(stdStream) isatty(fileno(stdStream)) -#else -#define IS_CONSOLE(stdStream) 0 -#endif namespace pzstd { diff --git a/contrib/pzstd/Pzstd.cpp b/contrib/pzstd/Pzstd.cpp index 1eb4ce14..6c580b3b 100644 --- a/contrib/pzstd/Pzstd.cpp +++ b/contrib/pzstd/Pzstd.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). */ +#include "platform.h" /* Large Files support, SET_BINARY_MODE */ #include "Pzstd.h" #include "SkippableFrame.h" #include "utils/FileSystem.h" @@ -21,14 +22,6 @@ #include #include -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) -# include /* _O_BINARY */ -# include /* _setmode, _isatty */ -# define SET_BINARY_MODE(file) { if (_setmode(_fileno(file), _O_BINARY) == -1) perror("Cannot set _O_BINARY"); } -#else -# include /* isatty */ -# define SET_BINARY_MODE(file) -#endif namespace pzstd { diff --git a/zlibWrapper/gzguts.h b/zlibWrapper/gzguts.h index 84651b88..05bf4d9f 100644 --- a/zlibWrapper/gzguts.h +++ b/zlibWrapper/gzguts.h @@ -1,5 +1,5 @@ /* gzguts.h contains minimal changes required to be compiled with zlibWrapper: - * - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h" + * - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h" * - gz_statep was converted to union to work with -Wstrict-aliasing=1 */ /* gzguts.h -- zlib internal header definitions for gz* operations @@ -44,7 +44,7 @@ # include #endif -#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) # define WIDECHAR #endif From 71a521061756291e42e6d608d5c8010dccf3d428 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Sep 2018 17:40:30 -0700 Subject: [PATCH 3/3] avoid recompiling dll every time under mingw --- lib/Makefile | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index cf8e45b0..70fb649f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -94,8 +94,6 @@ else SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) endif -LIBZSTD = libzstd.$(SHARED_EXT_VER) - .PHONY: default all clean install uninstall @@ -111,19 +109,28 @@ libzstd.a: $(ZSTD_OBJ) libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD libzstd.a-mt: libzstd.a +ifneq (,$(filter Windows%,$(OS))) + +LIBZSTD = dll\libzstd.dll +$(LIBZSTD): $(ZSTD_FILES) + @echo compiling dynamic library $(LIBVER) + @$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o $@ + dlltool -D $@ -d dll\libzstd.def -l dll\libzstd.lib + +else + +LIBZSTD = libzstd.$(SHARED_EXT_VER) $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden $(LIBZSTD): $(ZSTD_FILES) @echo compiling dynamic library $(LIBVER) -ifneq (,$(filter Windows%,$(OS))) - @$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll - dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib -else @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ @echo creating versioned links @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR) @ln -sf $@ libzstd.$(SHARED_EXT) + endif + libzstd : $(LIBZSTD) libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD