From a54c86cfc62c2b273aab96a5e2a50c241ab42d46 Mon Sep 17 00:00:00 2001
From: Yann Collet `src` should point to the start of a ZSTD encoded frame or skippable frame
@@ -413,12 +411,13 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
however it does mean that all frame data must be present and valid.
srcSize must be >= ZSTD_frameHeaderSize_prefix.
@return : size of the Frame Header,
or an error code (if srcSize is too small)
-zstd 1.3.5 Manual
+zstd 1.3.6 Manual
Contents
@@ -18,20 +18,17 @@
Introduction
@@ -336,15 +333,16 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */
-START OF ADVANCED AND EXPERIMENTAL FUNCTIONS
The definitions in this section are considered experimental.
+
ADVANCED AND EXPERIMENTAL FUNCTIONS
+ The definitions in this section are considered experimental.
They should never be used with a dynamic library, as prototypes may change in the future.
They are provided for advanced scenarios.
Use them only in association with static linking.
-Advanced types
-
+int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */
+
typedef enum { ZSTD_fast=1, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2,
ZSTD_btlazy2, ZSTD_btopt, ZSTD_btultra } ZSTD_strategy; /* from faster to stronger */
@@ -380,7 +378,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
ZSTD_dlm_byRef, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
} ZSTD_dictLoadMethod_e;
-Frame size functions
+Frame size functions
size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
-ZSTD_frameHeaderSize() :
srcSize must be >= ZSTD_frameHeaderSize_prefix.
+
size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
+
+
size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); @@ -508,7 +507,7 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< t
ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);Create a digested dictionary for compression @@ -550,7 +549,7 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< t
Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters
unsigned ZSTD_isFrame(const void* buffer, size_t size);Tells if the content of `buffer` starts with a valid Frame Identifier. @@ -590,7 +589,7 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< t When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code.
size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);/**< pledgedSrcSize must be correct. If it is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs, "0" also disables frame content size field. It may be enabled in the future. */ size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/ @@ -622,14 +621,14 @@ size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t di size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict is referenced, it must outlive decompression session */ size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */
+Buffer-less and synchronous inner streaming functions
This is an advanced API, giving full control over buffer management, for users which need direct control over memory. But it's also a complex one, with several restrictions, documented below. Prefer normal streaming API for an easier experience.-Buffer-less streaming compression (synchronous mode)
+Buffer-less streaming compression (synchronous mode)
A ZSTD_CCtx object is required to track streaming operations. Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource. ZSTD_CCtx object can be re-used multiple times within successive compression operations. @@ -665,7 +664,7 @@ size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */ size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**< note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */
-Buffer-less streaming decompression (synchronous mode)
+Buffer-less streaming decompression (synchronous mode)
A ZSTD_DCtx object is required to track streaming operations. Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it. A ZSTD_DCtx object can be re-used multiple times. @@ -756,7 +755,7 @@ size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long
typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
-New advanced API (experimental)
+New advanced API (experimental)
typedef enum { /* Opened question : should we have a format ZSTD_f_auto ? @@ -1193,9 +1192,11 @@ size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx,
-ZSTD_getFrameHeader_advanced() :
same as ZSTD_getFrameHeader(), +size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, + const void* src, size_t srcSize, ZSTD_format_e format); ++same as ZSTD_getFrameHeader(), with added capability to select a format (like ZSTD_f_zstd1_magicless) -
size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx, ZSTD_outBuffer* output, @@ -1229,7 +1230,7 @@ size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx,
-Block level API
+Block level API
Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). User will have to take in charge required information to regenerate data, such as compressed and content sizes. diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index f375ee2c..2862a6bd 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -679,6 +679,7 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams) CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); CLAMPCHECK(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); CLAMPCHECK(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); + CLAMPCHECK(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); if ((U32)(cParams.strategy) > (U32)ZSTD_btultra) return ERROR(parameter_unsupported); return 0; @@ -699,6 +700,7 @@ ZSTD_clampCParams(ZSTD_compressionParameters cParams) CLAMP(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); CLAMP(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); CLAMP(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); + CLAMP(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); CLAMP(cParams.strategy, ZSTD_fast, ZSTD_btultra); return cParams; } @@ -3782,6 +3784,7 @@ size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) #define ZSTD_MAX_CLEVEL 22 int ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } +int ZSTD_minCLevel(void) { return (int)-ZSTD_TARGETLENGTH_MAX; } static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { { /* "default" - guarantees a monotonically increasing memory budget */ diff --git a/lib/zstd.h b/lib/zstd.h index 277ab7ff..60260d2b 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -71,7 +71,7 @@ extern "C" { /*------ Version ------*/ #define ZSTD_VERSION_MAJOR 1 #define ZSTD_VERSION_MINOR 3 -#define ZSTD_VERSION_RELEASE 5 +#define ZSTD_VERSION_RELEASE 6 #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< useful to check dll version */ @@ -80,7 +80,7 @@ ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< useful to check dll versio #define ZSTD_QUOTE(str) #str #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) -ZSTDLIB_API const char* ZSTD_versionString(void); /* added in v1.3.0 */ +ZSTDLIB_API const char* ZSTD_versionString(void); /* v1.3.0+ */ /*************************************** * Default constant @@ -330,7 +330,7 @@ typedef struct ZSTD_outBuffer_s { * *******************************************************************/ typedef ZSTD_CCtx ZSTD_CStream; /**< CCtx and CStream are now effectively same object (>= v1.3.0) */ - /* Continue to distinguish them for compatibility with versions <= v1.2.0 */ + /* Continue to distinguish them for compatibility with older versions <= v1.2.0 */ /*===== ZSTD_CStream management functions =====*/ ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); @@ -385,21 +385,28 @@ ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output + +#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY) +#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY + /**************************************************************************************** - * START OF ADVANCED AND EXPERIMENTAL FUNCTIONS + * ADVANCED AND EXPERIMENTAL FUNCTIONS + **************************************************************************************** * The definitions in this section are considered experimental. * They should never be used with a dynamic library, as prototypes may change in the future. * They are provided for advanced scenarios. * Use them only in association with static linking. * ***************************************************************************************/ -#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY) -#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY +ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */ -/* --- Constants ---*/ -#define ZSTD_MAGICNUMBER 0xFD2FB528 /* >= v0.8.0 */ +/* --- Constants ---*/ +#define ZSTD_MAGICNUMBER 0xFD2FB528 /* v0.8+ */ +#define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* v0.7+ */ #define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U -#define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* >= v0.7.0 */ + +#define ZSTD_BLOCKSIZELOG_MAX 17 +#define ZSTD_BLOCKSIZE_MAX (1<
= ZSTD_frameHeaderSize_prefix. * @return : size of the Frame Header, * or an error code (if srcSize is too small) */ @@ -1401,7 +1411,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowS ZSTDLIB_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format); -/** ZSTD_getFrameHeader_advanced() : +/*! ZSTD_getFrameHeader_advanced() : * same as ZSTD_getFrameHeader(), * with added capability to select a format (like ZSTD_f_zstd1_magicless) */ ZSTDLIB_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, @@ -1473,8 +1483,6 @@ ZSTDLIB_API void ZSTD_DCtx_reset(ZSTD_DCtx* dctx); Use ZSTD_insertBlock() for such a case. */ -#define ZSTD_BLOCKSIZELOG_MAX 17 -#define ZSTD_BLOCKSIZE_MAX (1< Date: Fri, 21 Sep 2018 15:04:43 -0700 Subject: [PATCH 02/10] fixed tautological tests involving ZSTD_TARGETLENGTH_MIN (== 0) --- lib/compress/zstd_compress.c | 8 ++++++-- lib/zstd.h | 2 +- programs/windres/zstd32.res | Bin 1044 -> 1044 bytes programs/windres/zstd64.res | Bin 1044 -> 1044 bytes 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 2862a6bd..98e9917a 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -679,7 +679,9 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams) CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); CLAMPCHECK(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); CLAMPCHECK(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); - CLAMPCHECK(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); + ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0); + if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX) + return ERROR(parameter_outOfBound); if ((U32)(cParams.strategy) > (U32)ZSTD_btultra) return ERROR(parameter_unsupported); return 0; @@ -700,7 +702,9 @@ ZSTD_clampCParams(ZSTD_compressionParameters cParams) CLAMP(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); CLAMP(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); CLAMP(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); - CLAMP(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); + ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0); + if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX) + cParams.targetLength = ZSTD_TARGETLENGTH_MAX; CLAMP(cParams.strategy, ZSTD_fast, ZSTD_btultra); return cParams; } diff --git a/lib/zstd.h b/lib/zstd.h index 60260d2b..8a39de59 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -424,7 +424,7 @@ ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level a #define ZSTD_SEARCHLENGTH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */ #define ZSTD_SEARCHLENGTH_MIN 3 /* only for ZSTD_btopt, other strategies are limited to 4 */ #define ZSTD_TARGETLENGTH_MAX ZSTD_BLOCKSIZE_MAX -#define ZSTD_TARGETLENGTH_MIN 0 +#define ZSTD_TARGETLENGTH_MIN 0 /* note : comparing this constant to an unsigned results in a tautological test */ #define ZSTD_LDM_MINMATCH_MAX 4096 #define ZSTD_LDM_MINMATCH_MIN 4 #define ZSTD_LDM_BUCKETSIZELOG_MAX 8 diff --git a/programs/windres/zstd32.res b/programs/windres/zstd32.res index 26800ab321c2fc6b0a0d57a28e2710f71c8732c7..276cb20b7871cc800fb8f6f7b792520c5e6e7957 100644 GIT binary patch delta 33 ncmbQjF@ Date: Fri, 21 Sep 2018 17:28:37 -0700 Subject: [PATCH 03/10] fix constant redeclaration in paramgrill --- tests/paramgrill.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 5275f10a..dbddd242 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -70,9 +70,6 @@ static const int g_maxNbVariations = 64; #define FADT_MIN 0 #define FADT_MAX ((U32)-1) -#define ZSTD_TARGETLENGTH_MIN 0 -#define ZSTD_TARGETLENGTH_MAX 999 - #define WLOG_RANGE (ZSTD_WINDOWLOG_MAX - ZSTD_WINDOWLOG_MIN + 1) #define CLOG_RANGE (ZSTD_CHAINLOG_MAX - ZSTD_CHAINLOG_MIN + 1) #define HLOG_RANGE (ZSTD_HASHLOG_MAX - ZSTD_HASHLOG_MIN + 1) @@ -1192,6 +1189,7 @@ static int createContexts(contexts_t* ctx, const char* dictFileName) { return 0; } ctx->dictSize = UTIL_getFileSize(dictFileName); + assert(ctx->dictSize != UTIL_FILESIZE_UNKNOWN); ctx->dictBuffer = malloc(ctx->dictSize); f = fopen(dictFileName, "rb"); From 123fac6b6dd168b9ed8c4844eba9080d7084acb1 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Sep 2018 17:36:00 -0700 Subject: [PATCH 04/10] 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 05/10] 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 From 0e211bdd1825a4bf695c47cb7c62cad674625982 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Sep 2018 18:23:32 -0700 Subject: [PATCH 06/10] fixed constant comparison on 32-bits systems --- tests/paramgrill.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index dbddd242..68e1fbc4 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -1183,38 +1183,42 @@ static int createContexts(contexts_t* ctx, const char* dictFileName) { size_t readSize; ctx->cctx = ZSTD_createCCtx(); ctx->dctx = ZSTD_createDCtx(); + assert(ctx->cctx != NULL); + assert(ctx->dctx != NULL); + if(dictFileName == NULL) { ctx->dictSize = 0; ctx->dictBuffer = NULL; return 0; } - ctx->dictSize = UTIL_getFileSize(dictFileName); - assert(ctx->dictSize != UTIL_FILESIZE_UNKNOWN); + { U64 const dictFileSize = UTIL_getFileSize(dictFileName); + assert(dictFileSize != UTIL_FILESIZE_UNKNOWN); + ctx->dictSize = dictFileSize; + assert((U64)ctx->dictSize == dictFileSize); /* check overflow */ + } ctx->dictBuffer = malloc(ctx->dictSize); f = fopen(dictFileName, "rb"); - if(!f) { + if (f==NULL) { DISPLAY("unable to open file\n"); - fclose(f); freeContexts(*ctx); return 1; } - if(ctx->dictSize > 64 MB || !(ctx->dictBuffer)) { + if (ctx->dictSize > 64 MB || !(ctx->dictBuffer)) { DISPLAY("dictionary too large\n"); fclose(f); freeContexts(*ctx); return 1; } readSize = fread(ctx->dictBuffer, 1, ctx->dictSize, f); - if(readSize != ctx->dictSize) { + fclose(f); + if (readSize != ctx->dictSize) { DISPLAY("unable to read file\n"); - fclose(f); freeContexts(*ctx); return 1; } - fclose(f); return 0; } From 364041c6dd28b09e03ddd729d71f607d6936c5c6 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 22 Sep 2018 16:10:10 -0700 Subject: [PATCH 07/10] enforce minimum compression level limit using ZSTD_minCLevel() --- programs/zstdcli.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 3d4548a4..6b2c5d10 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -37,8 +37,8 @@ #ifndef ZSTD_NODICT # include "dibio.h" /* ZDICT_cover_params_t, DiB_trainFromFiles() */ #endif -#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */ -#include "zstd.h" /* ZSTD_VERSION_STRING */ +#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_minCLevel */ +#include "zstd.h" /* ZSTD_VERSION_STRING, ZSTD_maxCLevel */ /*-************************************ @@ -634,9 +634,11 @@ int main(int argCount, const char* argv[]) if (longCommandWArg(&argument, "--fast")) { /* Parse optional acceleration factor */ if (*argument == '=') { + U32 const maxFast = (U32)-ZSTD_minCLevel(); U32 fastLevel; ++argument; fastLevel = readU32FromChar(&argument); + if (fastLevel > maxFast) fastLevel = maxFast; if (fastLevel) { dictCLevel = cLevel = -(int)fastLevel; } else { From 0fc07eb1fd8bc7f661b0b16ad64f180234a6f443 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 22 Sep 2018 17:21:39 -0700 Subject: [PATCH 08/10] fixed zstd-decompress which cannot support ZSTD_minCLevel() --- programs/zstdcli.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 6b2c5d10..c00d0525 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -631,6 +631,7 @@ int main(int argCount, const char* argv[]) compressionParams.windowLog = ldmWindowLog; continue; } +#ifndef ZSTD_NOCOMPRESS /* linking ZSTD_minCLevel() requires compression support */ if (longCommandWArg(&argument, "--fast")) { /* Parse optional acceleration factor */ if (*argument == '=') { @@ -652,6 +653,7 @@ int main(int argCount, const char* argv[]) } continue; } +#endif /* fall-through, will trigger bad_usage() later on */ } From 292d8e4a831d7fa94be382824e51f3c14b5c7447 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 23 Sep 2018 23:57:30 -0700 Subject: [PATCH 09/10] added some tests based on limits.h in order to ensure proper type mapping when not using stdint.h --- lib/common/mem.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/common/mem.h b/lib/common/mem.h index 47d23001..2051bcad 100644 --- a/lib/common/mem.h +++ b/lib/common/mem.h @@ -57,11 +57,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 From 0250ac74ce261769ca550e93d11918915fd46633 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 24 Sep 2018 00:52:19 -0700 Subject: [PATCH 10/10] fixed minor scan-build warnings --- programs/fileio.c | 1 + programs/zstdcli.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index e08920ba..01944a3a 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1673,6 +1673,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const ch srcFile = FIO_openSrcFile(srcFileName); if (srcFile==NULL) return 1; + ress.srcBufferLoaded = 0; result = FIO_decompressFrames(ress, srcFile, dstFileName, srcFileName); diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 3d4548a4..24e05d83 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -484,8 +484,6 @@ int main(int argCount, const char* argv[]) /* init */ (void)recursive; (void)cLevelLast; /* not used when ZSTD_NOBENCH set */ - (void)dictCLevel; (void)dictSelect; (void)dictID; (void)maxDictSize; /* not used when ZSTD_NODICT set */ - (void)ultra; (void)cLevel; (void)ldmFlag; /* not used when ZSTD_NOCOMPRESS set */ (void)memLimit; /* not used when ZSTD_NODECOMPRESS set */ if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } filenameTable[0] = stdinmark; @@ -956,6 +954,10 @@ int main(int argCount, const char* argv[]) dictParams.zParams = zParams; operationResult = DiB_trainFromFiles(outFileName, maxDictSize, filenameTable, filenameIdx, blockSize, &dictParams, NULL, NULL, 0); } +#else + (void)dictCLevel; (void)dictSelect; (void)dictID; (void)maxDictSize; /* not used when ZSTD_NODICT set */ + DISPLAYLEVEL(1, "training mode not available \n"); + operationResult = 1; #endif goto _end; } @@ -1014,7 +1016,7 @@ int main(int argCount, const char* argv[]) else operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName, suffix, dictFileName, cLevel, &compressionParams); #else - (void)suffix; + (void)suffix; (void)ultra; (void)cLevel; (void)ldmFlag; /* not used when ZSTD_NOCOMPRESS set */ DISPLAY("Compression not supported\n"); #endif } else { /* decompression or test */