From: Yann Collet Date: Fri, 30 Oct 2015 05:40:22 +0000 (+0100) Subject: fix Visual Studio projects X-Git-Tag: zstd-0.3.0^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4114f95ce993164dbf59c3b8f9cf7619881dfb28;p=thirdparty%2Fzstd.git fix Visual Studio projects --- diff --git a/lib/bitstream.h b/lib/bitstream.h index 20e40ec66..e6c2228e9 100644 --- a/lib/bitstream.h +++ b/lib/bitstream.h @@ -150,7 +150,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits); MEM_STATIC unsigned BIT_highbit32 (register U32 val) { # if defined(_MSC_VER) /* Visual */ - unsigned long r; + unsigned long r=0; _BitScanReverse ( &r, val ); return (unsigned) r; # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ diff --git a/lib/error.h b/lib/error.h index a6981dd3b..1e2e06257 100644 --- a/lib/error.h +++ b/lib/error.h @@ -62,6 +62,7 @@ extern "C" { #define ERROR_LIST(ITEM) \ ITEM(PREFIX(No_Error)) ITEM(PREFIX(GENERIC)) \ + ITEM(PREFIX(memory_allocation)) \ ITEM(PREFIX(dstSize_tooSmall)) ITEM(PREFIX(srcSize_wrong)) \ ITEM(PREFIX(prefix_unknown)) ITEM(PREFIX(corruption_detected)) \ ITEM(PREFIX(tableLog_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooSmall)) \ diff --git a/lib/zstd.c b/lib/zstd.c index 7e69169a4..43832f01d 100644 --- a/lib/zstd.c +++ b/lib/zstd.c @@ -39,7 +39,7 @@ * Increasing memory usage improves compression ratio * Reduced memory usage can improve speed, due to cache effect */ -#define ZSTD_MEMORY_USAGE 17 +#define ZSTD_MEMORY_USAGE 16 /*! * HEAPMODE : @@ -533,7 +533,7 @@ static const BYTE* ZSTD_updateMatch(U32* table, const BYTE* p, const BYTE* start U32 h = ZSTD_hashPtr(p); const BYTE* r; r = table[h] + start; - ZSTD_addPtr(table, p, start); + table[h] = (U32)(p-start); return r; } @@ -559,23 +559,29 @@ static size_t ZSTD_compressBlock(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, c /* init */ + if (ip-base < 4) + { + ZSTD_addPtr(HashTable, ip+0, base); + ZSTD_addPtr(HashTable, ip+1, base); + ZSTD_addPtr(HashTable, ip+2, base); + ZSTD_addPtr(HashTable, ip+3, base); + ip += 4; + } ZSTD_resetSeqStore(seqStorePtr); /* Main Search Loop */ - while (ip < ilimit) + while (ip <= ilimit) { - const BYTE* match = (const BYTE*) ZSTD_updateMatch(HashTable, ip, base); + const BYTE* match = ZSTD_updateMatch(HashTable, ip, base); - if (!ZSTD_checkMatch(match,ip)) { ip += ((ip-anchor) >> g_searchStrength) + 1; continue; } - /* catch up */ - while ((ip>anchor) && (match>base) && (ip[-1] == match[-1])) { ip--; match--; } + if (ZSTD_checkMatch(ip-offset_2,ip)) match = ip-offset_2; + if (!ZSTD_checkMatch(match,ip)) { ip += ((ip-anchor) >> g_searchStrength) + 1; offset_2 = offset_1; continue; } + while ((ip>anchor) && (match>base) && (ip[-1] == match[-1])) { ip--; match--; } /* catch up */ { size_t litLength = ip-anchor; size_t matchLength = ZSTD_count(ip+MINMATCH, match+MINMATCH, iend); - size_t offsetCode; - if (litLength) offset_2 = offset_1; - offsetCode = ip-match; + size_t offsetCode = ip-match; if (offsetCode == offset_2) offsetCode = 0; offset_2 = offset_1; offset_1 = ip-match; @@ -584,8 +590,8 @@ static size_t ZSTD_compressBlock(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, c /* Fill Table */ ZSTD_addPtr(HashTable, ip+1, base); ip += matchLength + MINMATCH; - if (ip<=iend-8) ZSTD_addPtr(HashTable, ip-2, base); anchor = ip; + if (ip <= ilimit) ZSTD_addPtr(HashTable, ip-2, base); } } @@ -1089,7 +1095,7 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState) /* Offset */ { - static const size_t offsetPrefix[MaxOff+1] = { /* note : size_t faster than U32 */ + static const U32 offsetPrefix[MaxOff+1] = { 1 /*fake*/, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, /*fake*/ 1, 1, 1, 1, 1 }; diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h index bc03534d3..09fa1923e 100644 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@ -52,7 +52,7 @@ static size_t ZSTD_read_ARCH(const void* p) { size_t r; memcpy(&r, p, sizeof(r)) static unsigned ZSTD_highbit(U32 val) { # if defined(_MSC_VER) /* Visual */ - unsigned long r; + unsigned long r=0; _BitScanReverse(&r, val); return (unsigned)r; # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */ @@ -91,7 +91,7 @@ MEM_STATIC unsigned ZSTD_NbCommonBytes (register size_t val) else /* 32 bits */ { # if defined(_MSC_VER) - unsigned long r; + unsigned long r=0; _BitScanForward( &r, (U32)val ); return (int)(r>>3); # elif defined(__GNUC__) && (__GNUC__ >= 3) diff --git a/lib/zstdhc.c b/lib/zstdhc.c index e74ab2598..9c70d79aa 100644 --- a/lib/zstdhc.c +++ b/lib/zstdhc.c @@ -89,8 +89,8 @@ size_t ZSTD_HC_freeCCtx(ZSTD_HC_CCtx* cctx) return 0; } -static void ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc, - ZSTD_HC_parameters params) +static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc, + ZSTD_HC_parameters params) { /* validate params */ if (params.windowLog > ZSTD_HC_WINDOWLOG_MAX) params.windowLog = ZSTD_HC_WINDOWLOG_MAX; @@ -111,6 +111,7 @@ static void ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc, free(zc->workSpace); zc->workSpaceSize = neededSpace; zc->workSpace = malloc(neededSpace); + if (zc->workSpace == NULL) return ERROR(memory_allocation); } zc->hashTable = (U32*)zc->workSpace; zc->chainTable = zc->hashTable + (1 << params.hashLog); @@ -132,6 +133,7 @@ static void ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc, zc->seqStore.matchLengthStart = zc->seqStore.litLengthStart + (BLOCKSIZE>>2); zc->seqStore.dumpsStart = zc->seqStore.matchLengthStart + (BLOCKSIZE>>2); + return 0; } @@ -144,7 +146,7 @@ static U32 ZSTD_HC_hash(U32 u, U32 h) { return (u * KNUTH) >> (32-h) ; } static U32 ZSTD_HC_hashPtr(const void* ptr, U32 h) { return ZSTD_HC_hash(MEM_read32(ptr), h); } //static const U64 prime5bytes = 889523592379ULL; -//static U32 ZSTD_HC_hashPtr(const void* p, U32 h) { return ((MEM_read64(p) * prime5bytes) << (64-40)) >> (64-h); } +//static U32 ZSTD_HC_hashPtr(const void* p, U32 h) { return (U32)((MEM_read64(p) * prime5bytes) << (64-40)) >> (64-h); } #define NEXT_IN_CHAIN(d) chainTable[(d) & chainMask] /* flexible, CHAINSIZE dependent */ @@ -258,8 +260,8 @@ static size_t ZSTD_HC_compressBlock(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstS { /* repcode */ if (MEM_read32(ip) == MEM_read32(ip - offset_2)) - /* store sequence */ { + /* store sequence */ size_t matchLength = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_2, iend); size_t litLength = ip-anchor; size_t offset = offset_2; @@ -271,12 +273,13 @@ static size_t ZSTD_HC_compressBlock(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstS continue; } + offset_2 = offset_1; /* failed once : necessarily offset_1 now */ + /* repcode at ip+1 */ if (MEM_read32(ip+1) == MEM_read32(ip+1 - offset_1)) { size_t matchLength = ZSTD_count(ip+1+MINMATCH, ip+1+MINMATCH-offset_1, iend); size_t litLength = ip+1-anchor; - offset_2 = offset_1; ZSTD_storeSeq(seqStorePtr, litLength, anchor, 0, matchLength); ip += 1+matchLength+MINMATCH; anchor = ip; @@ -287,11 +290,10 @@ static size_t ZSTD_HC_compressBlock(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstS { const BYTE* match; size_t matchLength = ZSTD_HC_insertAndFindBestMatch(ctx, ip, iend, &match, maxSearches); - if (!matchLength) { ip++; offset_2 = offset_1; continue; } + if (!matchLength) { ip++; continue; } /* store sequence */ { size_t litLength = ip-anchor; - offset_2 = offset_1; offset_1 = ip-match; ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset_1, matchLength-MINMATCH); ip += matchLength; @@ -381,7 +383,7 @@ size_t ZSTD_HC_compressContinue (ZSTD_HC_CCtx* ctxPtr, if (ip != ctxPtr->end) { if (ctxPtr->end != NULL) - ZSTD_HC_resetCCtx_advanced(ctxPtr, ctxPtr->params); /* reset */ + ZSTD_HC_resetCCtx_advanced(ctxPtr, ctxPtr->params); /* just reset, but no need to re-alloc */ ctxPtr->base = ip; } @@ -394,8 +396,10 @@ size_t ZSTD_HC_compressBegin_advanced(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const ZSTD_HC_parameters params) { + size_t errorCode; if (maxDstSize < 4) return ERROR(dstSize_tooSmall); - ZSTD_HC_resetCCtx_advanced(ctx, params); + errorCode = ZSTD_HC_resetCCtx_advanced(ctx, params); + if (ZSTD_isError(errorCode)) return errorCode; MEM_writeLE32(dst, ZSTD_magicNumber); /* Write Header */ return 4; } @@ -432,6 +436,7 @@ size_t ZSTD_HC_compress_advanced (ZSTD_HC_CCtx* ctx, { BYTE* const ostart = (BYTE*)dst; BYTE* op = ostart; + size_t oSize; /* correct params, to use less memory */ U32 srcLog = ZSTD_highbit((U32)srcSize-1) + 1; @@ -439,7 +444,7 @@ size_t ZSTD_HC_compress_advanced (ZSTD_HC_CCtx* ctx, if (params.chainLog > srcLog) params.chainLog = srcLog; /* Header */ - size_t oSize = ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, params); + oSize = ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, params); if(ZSTD_isError(oSize)) return oSize; op += oSize; maxDstSize -= oSize; diff --git a/programs/bench.c b/programs/bench.c index 3742655cc..5c410f39a 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -419,7 +419,7 @@ static int BMK_benchOneFile(char* inFileName, int cLevel) U64 inFileSize; size_t benchedSize, readSize; void* srcBuffer; - int result; + int result=0; /* Check file existence */ inFile = fopen(inFileName, "rb"); @@ -476,7 +476,7 @@ static int BMK_syntheticTest(int cLevel, double compressibility) { size_t benchedSize = 10000000; void* srcBuffer = malloc(benchedSize); - int result; + int result=0; char name[20] = {0}; /* Memory allocation */ diff --git a/programs/fileio.c b/programs/fileio.c index 315a38c37..84720330b 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -520,7 +520,7 @@ unsigned long long FIO_decompressFilename(const char* output_filename, const cha ZSTD_resetDCtx(dctx); toRead = ZSTD_nextSrcSizeToDecompress(dctx) - sizeof(ZSTD_magicNumber); if (toRead > MAXHEADERSIZE) EXM_THROW(30, "Not enough memory to read header"); - sizeCheck = fread(header+sizeof(ZSTD_magicNumber), (size_t)1, toRead, finput); + sizeCheck = fread(&header[sizeof(ZSTD_magicNumber)], 1, toRead, finput); if (sizeCheck != toRead) EXM_THROW(31, "Read error : cannot read header"); sizeCheck = ZSTD_decompressContinue(dctx, NULL, 0, header, sizeof(ZSTD_magicNumber)+toRead); // Decode frame header if (ZSTD_isError(sizeCheck)) EXM_THROW(32, "Error decoding header"); diff --git a/visual/2012/fuzzer/fuzzer.vcxproj b/visual/2012/fuzzer/fuzzer.vcxproj index 9cc2a2d44..861012d6b 100644 --- a/visual/2012/fuzzer/fuzzer.vcxproj +++ b/visual/2012/fuzzer/fuzzer.vcxproj @@ -163,6 +163,7 @@ + @@ -174,6 +175,9 @@ + + + diff --git a/visual/2012/fuzzer/fuzzer.vcxproj.filters b/visual/2012/fuzzer/fuzzer.vcxproj.filters index 45e7a6d97..bb412fa7c 100644 --- a/visual/2012/fuzzer/fuzzer.vcxproj.filters +++ b/visual/2012/fuzzer/fuzzer.vcxproj.filters @@ -36,6 +36,9 @@ Fichiers sources + + Fichiers sources + @@ -65,5 +68,14 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + \ No newline at end of file diff --git a/visual/2012/zstd/zstd.vcxproj b/visual/2012/zstd/zstd.vcxproj index 531c4e8ff..0a35dd902 100644 --- a/visual/2012/zstd/zstd.vcxproj +++ b/visual/2012/zstd/zstd.vcxproj @@ -23,6 +23,7 @@ + @@ -35,6 +36,9 @@ + + + diff --git a/visual/2012/zstd/zstd.vcxproj.filters b/visual/2012/zstd/zstd.vcxproj.filters index cc5950b7e..a9b5393cd 100644 --- a/visual/2012/zstd/zstd.vcxproj.filters +++ b/visual/2012/zstd/zstd.vcxproj.filters @@ -39,6 +39,9 @@ Fichiers sources + + Fichiers sources + @@ -71,5 +74,14 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + \ No newline at end of file