From cb96f7e6f894577d0e507c5184a7f49e0c9cd811 Mon Sep 17 00:00:00 2001 From: Tino Reichardt Date: Wed, 7 Nov 2018 12:42:56 +0100 Subject: [PATCH] Add some fixes to lzma2 header files - remove disabling of MSVC C4389 warning - update mem.h from current zstd code --- C/fast-lzma2/mem.h | 25 ++++++++++++++++++++----- C/fast-lzma2/util.h | 1 - 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/C/fast-lzma2/mem.h b/C/fast-lzma2/mem.h index f54a45ce..5da24875 100644 --- a/C/fast-lzma2/mem.h +++ b/C/fast-lzma2/mem.h @@ -28,9 +28,6 @@ extern "C" { #if defined(_MSC_VER) /* Visual Studio */ # include /* _byteswap_ulong */ # include /* _byteswap_* */ -# pragma warning(disable : 4389) /* disable: C4389: '==' : signed/unsigned mismatch */ -#endif - #endif #if defined(__GNUC__) # define MEM_STATIC static __inline __attribute__((unused)) @@ -42,6 +39,10 @@ extern "C" { # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif +#ifndef __has_builtin +# define __has_builtin(x) 0 /* compat. with non-clang compilers */ +#endif + /* code only tested on 32 and 64 bits systems */ #define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; } MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); } @@ -60,11 +61,23 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size typedef uint64_t U64; typedef int64_t S64; #else +# include +#if CHAR_BIT != 8 +# error "this implementation requires char to be exactly 8-bit type" +#endif typedef unsigned char BYTE; +#if USHRT_MAX != 65535 +# error "this implementation requires short to be exactly 16-bit type" +#endif typedef unsigned short U16; typedef signed short S16; +#if UINT_MAX != 4294967295 +# error "this implementation requires int to be exactly 32-bit type" +#endif typedef unsigned int U32; typedef signed int S32; +/* note : there are no limits defined for long long type in C90. + * limits exist in C99, however, in such case, is preferred */ typedef unsigned long long U64; typedef signed long long S64; #endif @@ -189,7 +202,8 @@ MEM_STATIC U32 MEM_swap32(U32 in) { #if defined(_MSC_VER) /* Visual Studio */ return _byteswap_ulong(in); -#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) +#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ + || (defined(__clang__) && __has_builtin(__builtin_bswap32)) return __builtin_bswap32(in); #else return ((in << 24) & 0xff000000 ) | @@ -203,7 +217,8 @@ MEM_STATIC U64 MEM_swap64(U64 in) { #if defined(_MSC_VER) /* Visual Studio */ return _byteswap_uint64(in); -#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) +#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ + || (defined(__clang__) && __has_builtin(__builtin_bswap64)) return __builtin_bswap64(in); #else return ((in << 56) & 0xff00000000000000ULL) | diff --git a/C/fast-lzma2/util.h b/C/fast-lzma2/util.h index d5688203..fe8b6fa4 100644 --- a/C/fast-lzma2/util.h +++ b/C/fast-lzma2/util.h @@ -102,7 +102,6 @@ extern "C" { #elif defined(_MSC_VER) # define UTIL_STATIC static __inline # pragma warning(disable : 4996) /* disable: C4996: 'strncpy': This function or variable may be unsafe. */ -# pragma warning(disable : 4389) /* disable: C4389: '==' : signed/unsigned mismatch */ #else # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif