From c6e845398a52cbed8af8623351b4ace286b59a70 Mon Sep 17 00:00:00 2001 From: Christophe Chevalier Date: Mon, 7 Dec 2015 17:44:09 +0100 Subject: [PATCH 1/4] Add ZSTDLIB_API macro to prefix all exported methods with__declspec(dllexport) when building a DLL (on windows) --- lib/zstd.h | 42 +++++++++++++++++++++++++++----------- lib/zstd_buffered.h | 32 ++++++++++++++--------------- lib/zstd_buffered_static.h | 2 +- lib/zstd_static.h | 36 ++++++++++++++++---------------- 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/lib/zstd.h b/lib/zstd.h index e4d441497..0795cbb08 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -43,6 +43,24 @@ extern "C" { #include /* size_t */ +/* *************************************************************** +* Tuning parameters +*****************************************************************/ +/*! +* ZSTD_DLL_EXPORT : +* Enable exporting of functions when building a DLL +*/ +#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) +# if _WIN32 +# define ZSTDLIB_API __declspec(dllexport) +# else +# define ZSTDLIB_API extern +# endif +#else +# define ZSTDLIB_API +#endif + + /* ************************************* * Version ***************************************/ @@ -50,18 +68,18 @@ extern "C" { #define ZSTD_VERSION_MINOR 4 /* for new (non-breaking) interface capabilities */ #define ZSTD_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */ #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) -unsigned ZSTD_versionNumber (void); +ZSTDLIB_API unsigned ZSTD_versionNumber (void); /* ************************************* * Simple functions ***************************************/ -size_t ZSTD_compress( void* dst, size_t maxDstSize, - const void* src, size_t srcSize, - int compressionLevel); +ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t maxDstSize, + const void* src, size_t srcSize, + int compressionLevel); -size_t ZSTD_decompress( void* dst, size_t maxOriginalSize, - const void* src, size_t compressedSize); +ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t maxOriginalSize, + const void* src, size_t compressedSize); /** ZSTD_compress() : @@ -83,25 +101,25 @@ ZSTD_decompress() : /* ************************************* * Tool functions ***************************************/ -size_t ZSTD_compressBound(size_t srcSize); /** maximum compressed size (worst case scenario) */ +ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /** maximum compressed size (worst case scenario) */ /* Error Management */ -unsigned ZSTD_isError(size_t code); /** tells if a return value is an error code */ -const char* ZSTD_getErrorName(size_t code); /** provides error code string */ +ZSTDLIB_API unsigned ZSTD_isError(size_t code); /** tells if a return value is an error code */ +ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /** provides error code string */ /* ************************************* * Advanced functions ***************************************/ typedef struct ZSTD_CCtx_s ZSTD_CCtx; /* incomplete type */ -ZSTD_CCtx* ZSTD_createCCtx(void); -size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); +ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); +ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /** ZSTD_compressCCtx() : Same as ZSTD_compress(), but requires a ZSTD_CCtx working space already allocated */ -size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel); +ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel); #if defined (__cplusplus) diff --git a/lib/zstd_buffered.h b/lib/zstd_buffered.h index 80ba819db..80e6e599d 100644 --- a/lib/zstd_buffered.h +++ b/lib/zstd_buffered.h @@ -51,13 +51,13 @@ extern "C" { * Streaming functions ***************************************/ typedef struct ZBUFF_CCtx_s ZBUFF_CCtx; -ZBUFF_CCtx* ZBUFF_createCCtx(void); -size_t ZBUFF_freeCCtx(ZBUFF_CCtx* cctx); +ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx(void); +ZSTDLIB_API size_t ZBUFF_freeCCtx(ZBUFF_CCtx* cctx); -size_t ZBUFF_compressInit(ZBUFF_CCtx* cctx, int compressionLevel); -size_t ZBUFF_compressContinue(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr, const void* src, size_t* srcSizePtr); -size_t ZBUFF_compressFlush(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr); -size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr); +ZSTDLIB_API size_t ZBUFF_compressInit(ZBUFF_CCtx* cctx, int compressionLevel); +ZSTDLIB_API size_t ZBUFF_compressContinue(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr, const void* src, size_t* srcSizePtr); +ZSTDLIB_API size_t ZBUFF_compressFlush(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr); +ZSTDLIB_API size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr); /** ************************************************ * Streaming compression @@ -97,11 +97,11 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* maxDstSizePtr); typedef struct ZBUFF_DCtx_s ZBUFF_DCtx; -ZBUFF_DCtx* ZBUFF_createDCtx(void); -size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx); +ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx(void); +ZSTDLIB_API size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx); -size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx); -size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx, void* dst, size_t* maxDstSizePtr, const void* src, size_t* srcSizePtr); +ZSTDLIB_API size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx); +ZSTDLIB_API size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx, void* dst, size_t* maxDstSizePtr, const void* src, size_t* srcSizePtr); /** ************************************************ * Streaming decompression @@ -129,15 +129,15 @@ size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx, void* dst, size_t* maxDstSizeP /* ************************************* * Tool functions ***************************************/ -unsigned ZBUFF_isError(size_t errorCode); -const char* ZBUFF_getErrorName(size_t errorCode); +ZSTDLIB_API unsigned ZBUFF_isError(size_t errorCode); +ZSTDLIB_API const char* ZBUFF_getErrorName(size_t errorCode); /** The below functions provide recommended buffer sizes for Compression or Decompression operations. * These sizes are not compulsory, they just tend to offer better latency */ -size_t ZBUFF_recommendedCInSize(void); -size_t ZBUFF_recommendedCOutSize(void); -size_t ZBUFF_recommendedDInSize(void); -size_t ZBUFF_recommendedDOutSize(void); +ZSTDLIB_API size_t ZBUFF_recommendedCInSize(void); +ZSTDLIB_API size_t ZBUFF_recommendedCOutSize(void); +ZSTDLIB_API size_t ZBUFF_recommendedDInSize(void); +ZSTDLIB_API size_t ZBUFF_recommendedDOutSize(void); #if defined (__cplusplus) diff --git a/lib/zstd_buffered_static.h b/lib/zstd_buffered_static.h index cba1d6fca..7d9ee27d2 100644 --- a/lib/zstd_buffered_static.h +++ b/lib/zstd_buffered_static.h @@ -52,7 +52,7 @@ extern "C" { /* ************************************* * Advanced Streaming functions ***************************************/ -size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* cctx, ZSTD_parameters params); +ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* cctx, ZSTD_parameters params); #if defined (__cplusplus) diff --git a/lib/zstd_static.h b/lib/zstd_static.h index 5c3156248..6a987026a 100644 --- a/lib/zstd_static.h +++ b/lib/zstd_static.h @@ -85,29 +85,29 @@ typedef struct /** ZSTD_getParams * return ZSTD_parameters structure for a selected compression level and srcSize. * srcSizeHint value is optional, select 0 if not known */ -ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSizeHint); +ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSizeHint); /** ZSTD_validateParams * correct params value to remain within authorized range */ -void ZSTD_validateParams(ZSTD_parameters* params); +ZSTDLIB_API void ZSTD_validateParams(ZSTD_parameters* params); /** ZSTD_compress_advanced * Same as ZSTD_compressCCtx(), with fine-tune control of each compression parameter */ -size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx, - void* dst, size_t maxDstSize, - const void* src, size_t srcSize, - ZSTD_parameters params); +ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx, + void* dst, size_t maxDstSize, + const void* src, size_t srcSize, + ZSTD_parameters params); /* ************************************** * Streaming functions (bufferless mode) ****************************************/ -size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize, int compressionLevel); -size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, ZSTD_parameters params); -size_t ZSTD_compress_insertDictionary(ZSTD_CCtx* ctx, const void* src, size_t srcSize); +ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize, int compressionLevel); +ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, ZSTD_parameters params); +ZSTDLIB_API size_t ZSTD_compress_insertDictionary(ZSTD_CCtx* ctx, const void* src, size_t srcSize); -size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); -size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize); +ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); +ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize); /** Streaming compression, bufferless mode @@ -136,15 +136,15 @@ size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize); typedef struct ZSTD_DCtx_s ZSTD_DCtx; -ZSTD_DCtx* ZSTD_createDCtx(void); -size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); +ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); +ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); -size_t ZSTD_resetDCtx(ZSTD_DCtx* dctx); -size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcSize); -void ZSTD_decompress_insertDictionary(ZSTD_DCtx* ctx, const void* src, size_t srcSize); +ZSTDLIB_API size_t ZSTD_resetDCtx(ZSTD_DCtx* dctx); +ZSTDLIB_API size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcSize); +ZSTDLIB_API void ZSTD_decompress_insertDictionary(ZSTD_DCtx* ctx, const void* src, size_t srcSize); -size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); -size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); +ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); +ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); /** Streaming decompression, bufferless mode From d2199e72501737faaf87c4bdc4a33eb06eddb998 Mon Sep 17 00:00:00 2001 From: Christophe Chevalier Date: Mon, 7 Dec 2015 19:01:41 +0100 Subject: [PATCH 2/4] Added ZSTDLIB_API definition to zstd_buffered.h which does not seem to include zstd.h --- lib/zstd_buffered.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/zstd_buffered.h b/lib/zstd_buffered.h index 80e6e599d..fffa70a05 100644 --- a/lib/zstd_buffered.h +++ b/lib/zstd_buffered.h @@ -47,6 +47,24 @@ extern "C" { #include /* size_t */ +/* *************************************************************** +* Tuning parameters +*****************************************************************/ +/*! +* ZSTD_DLL_EXPORT : +* Enable exporting of functions when building a DLL +*/ +#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) +# if _WIN32 +# define ZSTDLIB_API __declspec(dllexport) +# else +# define ZSTDLIB_API extern +# endif +#else +# define ZSTDLIB_API +#endif + + /* ************************************* * Streaming functions ***************************************/ From 7b05324a712dabf68545a00b4b91fb6579ab67a1 Mon Sep 17 00:00:00 2001 From: Christophe Chevalier Date: Wed, 9 Dec 2015 15:48:22 +0100 Subject: [PATCH 3/4] Only define ZSTDLIB_API when building a Windows DLL --- lib/zstd.h | 10 +++------- lib/zstd_buffered.h | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/zstd.h b/lib/zstd.h index 0795cbb08..b0c841f3a 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -48,14 +48,10 @@ extern "C" { *****************************************************************/ /*! * ZSTD_DLL_EXPORT : -* Enable exporting of functions when building a DLL +* Enable exporting of functions when building a Windows DLL */ -#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) -# if _WIN32 -# define ZSTDLIB_API __declspec(dllexport) -# else -# define ZSTDLIB_API extern -# endif +#if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) +# define ZSTDLIB_API __declspec(dllexport) #else # define ZSTDLIB_API #endif diff --git a/lib/zstd_buffered.h b/lib/zstd_buffered.h index fffa70a05..755728b1b 100644 --- a/lib/zstd_buffered.h +++ b/lib/zstd_buffered.h @@ -52,14 +52,10 @@ extern "C" { *****************************************************************/ /*! * ZSTD_DLL_EXPORT : -* Enable exporting of functions when building a DLL +* Enable exporting of functions when building a Windows DLL */ -#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) -# if _WIN32 -# define ZSTDLIB_API __declspec(dllexport) -# else -# define ZSTDLIB_API extern -# endif +#if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) +# define ZSTDLIB_API __declspec(dllexport) #else # define ZSTDLIB_API #endif From 2abb04d90de5db42ad9f27c911169061aecf25b3 Mon Sep 17 00:00:00 2001 From: Christophe Chevalier Date: Wed, 9 Dec 2015 23:55:23 +0100 Subject: [PATCH 4/4] Added ZSTDLIB_API to new ZSTD_maxCLevel method --- lib/zstd_static.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zstd_static.h b/lib/zstd_static.h index 212cd8371..ebb8c83cf 100644 --- a/lib/zstd_static.h +++ b/lib/zstd_static.h @@ -180,7 +180,7 @@ ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t ma * Pre-defined compression levels ***************************************/ #define ZSTD_MAX_CLEVEL 20 -unsigned ZSTD_maxCLevel (void); +ZSTDLIB_API unsigned ZSTD_maxCLevel (void); static const ZSTD_parameters ZSTD_defaultParameters[4][ZSTD_MAX_CLEVEL+1] = { { /* "default" */ /* W, C, H, S, L, strat */