]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix Visual Studio projects
authorYann Collet <yann.collet.73@gmail.com>
Fri, 30 Oct 2015 05:40:22 +0000 (06:40 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Fri, 30 Oct 2015 05:40:22 +0000 (06:40 +0100)
lib/bitstream.h
lib/error.h
lib/zstd.c
lib/zstd_internal.h
lib/zstdhc.c
programs/bench.c
programs/fileio.c
visual/2012/fuzzer/fuzzer.vcxproj
visual/2012/fuzzer/fuzzer.vcxproj.filters
visual/2012/zstd/zstd.vcxproj
visual/2012/zstd/zstd.vcxproj.filters

index 20e40ec66692a372d4090cc73ec8ab80b9d7b9c8..e6c2228e9eece494cecda8891f4e88deace5b1f6 100644 (file)
@@ -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 */
index a6981dd3b0393d645308d2a84aca22cbc345d4e5..1e2e06257d5bf9e2d001072737d3e9e670a1c53f 100644 (file)
@@ -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)) \
index 7e69169a490f1c9fb11e14ae6a14ad385c1a65f4..43832f01d1e2b37a259baa6c2cdb9cdb977ee290 100644 (file)
@@ -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 };
index bc03534d3ca8a3992239a80cc00f9317e28922d7..09fa1923e8e85caea4fa5dd3544e74f308518ad2 100644 (file)
@@ -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)
index e74ab2598ab3cb157183a84a665427d280204b47..9c70d79aa977333482c148fa154d30a5e12566c8 100644 (file)
@@ -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;
index 3742655cce998e312375971ff6cd31832ed479cb..5c410f39a9ead4a53d4e8fd808b8d1e2143b67a6 100644 (file)
@@ -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 */
index 315a38c37e1632318f49a304ff01711b338aa53d..84720330b23dc8a18d4e569d92fa43b6ad7dbe6f 100644 (file)
@@ -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");
index 9cc2a2d44e3b57a3a5f784cdc1ccbf41bbfde9c0..861012d6bcb592e2138df6ec39e6d8bbaf53a5fd 100644 (file)
     <ClCompile Include="..\..\..\lib\huff0.c" />\r
     <ClCompile Include="..\..\..\lib\legacy\zstd_v01.c" />\r
     <ClCompile Include="..\..\..\lib\zstd.c" />\r
+    <ClCompile Include="..\..\..\lib\zstdhc.c" />\r
     <ClCompile Include="..\..\..\programs\datagen.c" />\r
     <ClCompile Include="..\..\..\programs\fuzzer.c" />\r
     <ClCompile Include="..\..\..\programs\xxhash.c" />\r
     <ClInclude Include="..\..\..\lib\huff0_static.h" />\r
     <ClInclude Include="..\..\..\lib\legacy\zstd_v01.h" />\r
     <ClInclude Include="..\..\..\lib\zstd.h" />\r
+    <ClInclude Include="..\..\..\lib\zstdhc.h" />\r
+    <ClInclude Include="..\..\..\lib\zstdhc_static.h" />\r
+    <ClInclude Include="..\..\..\lib\zstd_internal.h" />\r
     <ClInclude Include="..\..\..\lib\zstd_static.h" />\r
     <ClInclude Include="..\..\..\programs\datagen.h" />\r
     <ClInclude Include="..\..\..\programs\xxhash.h" />\r
index 45e7a6d97138bb648d3a8f74797b4357d508196f..bb412fa7c58953b0c40289d164f6f6c36ab09b0f 100644 (file)
@@ -36,6 +36,9 @@
     <ClCompile Include="..\..\..\lib\huff0.c">\r
       <Filter>Fichiers sources</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\lib\zstdhc.c">\r
+      <Filter>Fichiers sources</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\lib\fse.h">\r
     <ClInclude Include="..\..\..\lib\huff0_static.h">\r
       <Filter>Fichiers d%27en-tête</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\..\lib\zstd_internal.h">\r
+      <Filter>Fichiers d%27en-tête</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\lib\zstdhc.h">\r
+      <Filter>Fichiers d%27en-tête</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\lib\zstdhc_static.h">\r
+      <Filter>Fichiers d%27en-tête</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index 531c4e8ffc223033f2cae2fc956aaa76842ede9d..0a35dd9029bc2eb1be13c14328c5149133319b6f 100644 (file)
@@ -23,6 +23,7 @@
     <ClCompile Include="..\..\..\lib\huff0.c" />\r
     <ClCompile Include="..\..\..\lib\legacy\zstd_v01.c" />\r
     <ClCompile Include="..\..\..\lib\zstd.c" />\r
+    <ClCompile Include="..\..\..\lib\zstdhc.c" />\r
     <ClCompile Include="..\..\..\programs\bench.c" />\r
     <ClCompile Include="..\..\..\programs\fileio.c" />\r
     <ClCompile Include="..\..\..\programs\xxhash.c" />\r
@@ -35,6 +36,9 @@
     <ClInclude Include="..\..\..\lib\huff0_static.h" />\r
     <ClInclude Include="..\..\..\lib\legacy\zstd_v01.h" />\r
     <ClInclude Include="..\..\..\lib\zstd.h" />\r
+    <ClInclude Include="..\..\..\lib\zstdhc.h" />\r
+    <ClInclude Include="..\..\..\lib\zstdhc_static.h" />\r
+    <ClInclude Include="..\..\..\lib\zstd_internal.h" />\r
     <ClInclude Include="..\..\..\lib\zstd_static.h" />\r
     <ClInclude Include="..\..\..\programs\bench.h" />\r
     <ClInclude Include="..\..\..\programs\fileio.h" />\r
index cc5950b7e31df126cc9177e337cecaee6d855894..a9b5393cdb7cef714614a9d9478022e0bd275877 100644 (file)
@@ -39,6 +39,9 @@
     <ClCompile Include="..\..\..\lib\huff0.c">\r
       <Filter>Fichiers sources</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\lib\zstdhc.c">\r
+      <Filter>Fichiers sources</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\lib\fse.h">\r
     <ClInclude Include="..\..\..\lib\huff0_static.h">\r
       <Filter>Fichiers d%27en-tête</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\..\lib\zstd_internal.h">\r
+      <Filter>Fichiers d%27en-tête</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\lib\zstdhc.h">\r
+      <Filter>Fichiers d%27en-tête</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\..\..\lib\zstdhc_static.h">\r
+      <Filter>Fichiers d%27en-tête</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file