From: Yann Collet Date: Wed, 6 Jul 2016 10:35:09 +0000 (+0200) Subject: fixed dictBuilder issue with HC levels. Reported by Bartosz Taudul. X-Git-Tag: v0.7.3^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=517e1ba623a2c922d41ffc45cb4916080edacf6b;p=thirdparty%2Fzstd.git fixed dictBuilder issue with HC levels. Reported by Bartosz Taudul. --- diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 9786ee171..02498aea0 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -710,7 +710,6 @@ static seq_t ZSTD_decodeSequence(seqState_t* seqState) if (ofCode <= 1) { if ((llCode == 0) & (offset <= 1)) offset = 1-offset; - if (offset) { size_t const temp = seqState->prevOffset[offset]; if (offset != 1) seqState->prevOffset[2] = seqState->prevOffset[1]; diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index dfcb4ab48..fa09acb36 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -34,11 +34,6 @@ /*-************************************** * Compiler Options ****************************************/ -/* Disable some Visual warning messages */ -#ifdef _MSC_VER -# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ -#endif - /* Unix Large Files support (>4GB) */ #define _FILE_OFFSET_BITS 64 #if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */ @@ -58,13 +53,15 @@ #include "mem.h" /* read */ #include "error_private.h" -#include "fse.h" +#include "fse.h" /* FSE_normalizeCount, FSE_writeNCount */ #define HUF_STATIC_LINKING_ONLY #include "huf.h" #include "zstd_internal.h" /* includes zstd.h */ #include "xxhash.h" #include "divsufsort.h" -#define ZDICT_STATIC_LINKING_ONLY +#ifndef ZDICT_STATIC_LINKING_ONLY +# define ZDICT_STATIC_LINKING_ONLY +#endif #include "zdict.h" @@ -91,15 +88,15 @@ static const size_t g_min_fast_dictContent = 192; /*-************************************* * Console display ***************************************/ -#define DISPLAY(...) fprintf(stderr, __VA_ARGS__) +#define DISPLAY(...) { fprintf(stderr, __VA_ARGS__); fflush( stderr ); } #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } static unsigned g_displayLevel = 0; /* 0 : no display; 1: errors; 2: default; 4: full information */ #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ - if (ZDICT_GetMilliSpan(g_time) > refreshRate) \ + if (ZDICT_clockSpan(g_time) > refreshRate) \ { g_time = clock(); DISPLAY(__VA_ARGS__); \ if (g_displayLevel>=4) fflush(stdout); } } -static const unsigned refreshRate = 300; +static const unsigned refreshRate = CLOCKS_PER_SEC * 3 / 10; static clock_t g_time = 0; static void ZDICT_printHex(U32 dlevel, const void* ptr, size_t length) @@ -117,11 +114,9 @@ static void ZDICT_printHex(U32 dlevel, const void* ptr, size_t length) /*-******************************************************** * Helper functions **********************************************************/ -static unsigned ZDICT_GetMilliSpan(clock_t nPrevious) +static unsigned ZDICT_clockSpan(clock_t nPrevious) { - clock_t nCurrent = clock(); - unsigned nSpan = (unsigned)(((nCurrent - nPrevious) * 1000) / CLOCKS_PER_SEC); - return nSpan; + return clock() - nPrevious; } unsigned ZDICT_isError(size_t errorCode) { return ERR_isError(errorCode); } @@ -587,7 +582,9 @@ static void ZDICT_countEStats(EStats_ress_t esr, size_t cSize; if (srcSize > ZSTD_BLOCKSIZE_MAX) srcSize = ZSTD_BLOCKSIZE_MAX; /* protection vs large samples */ - ZSTD_copyCCtx(esr.zc, esr.ref); + { size_t const errorCode = ZSTD_copyCCtx(esr.zc, esr.ref); + if (ZSTD_isError(errorCode)) { DISPLAYLEVEL(1, "warning : ZSTD_copyCCtx failed \n"); return; } + } cSize = ZSTD_compressBlock(esr.zc, esr.workPlace, ZSTD_BLOCKSIZE_MAX, src, srcSize); if (ZSTD_isError(cSize)) { DISPLAYLEVEL(1, "warning : could not compress sample size %u \n", (U32)srcSize); return; } @@ -709,9 +706,14 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize, } if (compressionLevel==0) compressionLevel=g_compressionLevel_default; params.cParams = ZSTD_getCParams(compressionLevel, averageSampleSize, dictBufferSize); - params.cParams.strategy = ZSTD_greedy; + //params.cParams.strategy = ZSTD_greedy; params.fParams.contentSizeFlag = 0; - ZSTD_compressBegin_advanced(esr.ref, dictBuffer, dictBufferSize, params, 0); + { size_t const beginResult = ZSTD_compressBegin_advanced(esr.ref, dictBuffer, dictBufferSize, params, 0); + if (ZSTD_isError(beginResult)) { + eSize = ERROR(GENERIC); + DISPLAYLEVEL(1, "error : ZSTD_compressBegin_advanced failed "); + goto _cleanup; + } } /* collect stats on all files */ for (u=0; upos; u++) { U32 l = dictList[u].length; ptr -= l; - if (ptr<(BYTE*)dictBuffer) EXIT(GENERIC); /* should not happen */ + if (ptr<(BYTE*)dictBuffer) return ERROR(GENERIC); /* should not happen */ memcpy(ptr, (const char*)samplesBuffer+dictList[u].pos, l); } } @@ -983,7 +985,7 @@ size_t ZDICT_trainFromBuffer_unsafe( params); } -_cleanup : + /* clean up */ free(dictList); return dictSize; }