Fixed clash when projects are already using xxHash

Undefing XXH_* macros allows the `.c` to build standalone without clashes. Removing `xxhash.c` and only including the header is the correct usage (according to `XXH_PRIVATE_API`).
This commit is contained in:
Carl Woffenden 2020-04-07 18:17:59 +02:00
parent 4e6027f8ca
commit 3eaa525138
2 changed files with 24 additions and 14 deletions

View File

@ -1,7 +1,7 @@
/** /**
* \file zstd.c * \file zstd.c
* Single-file Zstandard library. * Single-file Zstandard library.
* *
* Generate using: * Generate using:
* \code * \code
* combine.sh -r ../../lib -r ../../lib/common -r ../../lib/compress -r ../../lib/decompress -k zstd.h -o zstd.c zstd-in.c * combine.sh -r ../../lib -r ../../lib/common -r ../../lib/compress -r ../../lib/decompress -k zstd.h -o zstd.c zstd-in.c
@ -18,19 +18,25 @@
*/ */
/* /*
* Settings to bake for the single library file. * Settings to bake for the single library file.
* *
* Note: It's important that none of these affects 'zstd.h' (only the * Note: It's important that none of these affects 'zstd.h' (only the
* implementation files we're amalgamating). * implementation files we're amalgamating).
* *
* Note: MEM_MODULE stops xxhash redefining BYTE, U16, etc., which are also * Note: MEM_MODULE stops xxhash redefining BYTE, U16, etc., which are also
* defined in mem.h (breaking C99 compatibility). * defined in mem.h (breaking C99 compatibility).
* *
* Note: the undefs for xxHash allow Zstd's implementation to coinside with with
* standalone xxHash usage (with global defines).
*
* Note: multithreading is enabled for all platforms apart from Emscripten. * Note: multithreading is enabled for all platforms apart from Emscripten.
*/ */
#define DEBUGLEVEL 0 #define DEBUGLEVEL 0
#define MEM_MODULE #define MEM_MODULE
#undef XXH_NAMESPACE
#define XXH_NAMESPACE ZSTD_ #define XXH_NAMESPACE ZSTD_
#undef XXH_PRIVATE_API
#define XXH_PRIVATE_API #define XXH_PRIVATE_API
#undef XXH_INLINE_ALL
#define XXH_INLINE_ALL #define XXH_INLINE_ALL
#define ZSTD_LEGACY_SUPPORT 0 #define ZSTD_LEGACY_SUPPORT 0
#define ZSTD_LIB_DICTBUILDER 0 #define ZSTD_LIB_DICTBUILDER 0
@ -40,17 +46,16 @@
#define ZSTD_MULTITHREAD #define ZSTD_MULTITHREAD
#endif #endif
/* common */ /* lib/common */
#include "debug.c" #include "debug.c"
#include "entropy_common.c" #include "entropy_common.c"
#include "error_private.c" #include "error_private.c"
#include "fse_decompress.c" #include "fse_decompress.c"
#include "threading.c" #include "threading.c"
#include "pool.c" #include "pool.c"
#include "xxhash.c"
#include "zstd_common.c" #include "zstd_common.c"
/* compress */ /* lib/compress */
#include "fse_compress.c" #include "fse_compress.c"
#include "hist.c" #include "hist.c"
#include "huf_compress.c" #include "huf_compress.c"
@ -67,7 +72,7 @@
#include "zstdmt_compress.c" #include "zstdmt_compress.c"
#endif #endif
/* decompress */ /* lib/decompress */
#include "huf_decompress.c" #include "huf_decompress.c"
#include "zstd_ddict.c" #include "zstd_ddict.c"
#include "zstd_decompress.c" #include "zstd_decompress.c"

View File

@ -1,7 +1,7 @@
/** /**
* \file zstddeclib.c * \file zstddeclib.c
* Single-file Zstandard decompressor. * Single-file Zstandard decompressor.
* *
* Generate using: * Generate using:
* \code * \code
* combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c * combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c
@ -18,17 +18,23 @@
*/ */
/* /*
* Settings to bake for the standalone decompressor. * Settings to bake for the standalone decompressor.
* *
* Note: It's important that none of these affects 'zstd.h' (only the * Note: It's important that none of these affects 'zstd.h' (only the
* implementation files we're amalgamating). * implementation files we're amalgamating).
* *
* Note: MEM_MODULE stops xxhash redefining BYTE, U16, etc., which are also * Note: MEM_MODULE stops xxhash redefining BYTE, U16, etc., which are also
* defined in mem.h (breaking C99 compatibility). * defined in mem.h (breaking C99 compatibility).
*
* Note: the undefs for xxHash allow Zstd's implementation to coinside with with
* standalone xxHash usage (with global defines).
*/ */
#define DEBUGLEVEL 0 #define DEBUGLEVEL 0
#define MEM_MODULE #define MEM_MODULE
#undef XXH_NAMESPACE
#define XXH_NAMESPACE ZSTD_ #define XXH_NAMESPACE ZSTD_
#undef XXH_PRIVATE_API
#define XXH_PRIVATE_API #define XXH_PRIVATE_API
#undef XXH_INLINE_ALL
#define XXH_INLINE_ALL #define XXH_INLINE_ALL
#define ZSTD_LEGACY_SUPPORT 0 #define ZSTD_LEGACY_SUPPORT 0
#define ZSTD_LIB_COMPRESSION 0 #define ZSTD_LIB_COMPRESSION 0
@ -36,15 +42,14 @@
#define ZSTD_NOBENCH #define ZSTD_NOBENCH
#define ZSTD_STRIP_ERROR_STRINGS #define ZSTD_STRIP_ERROR_STRINGS
/* common */ /* lib/common */
#include "debug.c" #include "debug.c"
#include "entropy_common.c" #include "entropy_common.c"
#include "error_private.c" #include "error_private.c"
#include "fse_decompress.c" #include "fse_decompress.c"
#include "xxhash.c"
#include "zstd_common.c" #include "zstd_common.c"
/* decompress */ /* lib/decompress */
#include "huf_decompress.c" #include "huf_decompress.c"
#include "zstd_ddict.c" #include "zstd_ddict.c"
#include "zstd_decompress.c" #include "zstd_decompress.c"