Fixed Visual 2005 issues (warning/linking)
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Mon, 13 Aug 2012 07:30:58 +0000 (07:30 +0000)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Mon, 13 Aug 2012 07:30:58 +0000 (07:30 +0000)
git-svn-id: https://lz4.googlecode.com/svn/trunk@75 650e7d94-2a16-8b24-b05c-7c0b3f6821cd

bench.c
lz4.c
lz4demo.c
lz4hc.c

diff --git a/bench.c b/bench.c
index 0595dfe..f379f99 100644 (file)
--- a/bench.c
+++ b/bench.c
@@ -25,8 +25,9 @@
 //**************************************\r
 // Compiler Options\r
 //**************************************\r
-// Visual warning messages\r
+// Disable some Visual warning messages\r
 #define _CRT_SECURE_NO_WARNINGS\r
+#define _CRT_SECURE_NO_DEPRECATE     // VS2005\r
 \r
 // Under Linux at least, pull in the *64 commands\r
 #define _LARGEFILE64_SOURCE\r
@@ -146,7 +147,7 @@ static int BMK_GetMilliStart()
   struct timeb tb;\r
   int nCount;\r
   ftime( &tb );\r
-  nCount = tb.millitm + (tb.time & 0xfffff) * 1000;\r
+  nCount = (int) (tb.millitm + (tb.time & 0xfffff) * 1000);\r
   return nCount;\r
 }\r
 \r
@@ -307,7 +308,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
          // Alloc\r
          chunkP = (struct chunkParameters*) malloc(((benchedsize / chunkSize)+1) * sizeof(struct chunkParameters));\r
          in_buff = malloc((size_t )benchedsize);\r
-         nbChunks = (benchedsize / chunkSize) + 1;\r
+         nbChunks = (int) (benchedsize / chunkSize) + 1;\r
          maxCChunkSize = LZ4_compressBound(chunkSize);\r
          out_buff_size = nbChunks * maxCChunkSize;\r
          out_buff = malloc((size_t )out_buff_size);\r
@@ -332,7 +333,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
                  {\r
                          chunkP[i].id = i;\r
                          chunkP[i].inputBuffer = in; in += chunkSize;\r
-                         if ((int)remaining > chunkSize) { chunkP[i].inputSize = chunkSize; remaining -= chunkSize; } else { chunkP[i].inputSize = remaining; remaining = 0; }\r
+                         if ((int)remaining > chunkSize) { chunkP[i].inputSize = chunkSize; remaining -= chunkSize; } else { chunkP[i].inputSize = (int)remaining; remaining = 0; }\r
                          chunkP[i].outputBuffer = out; out += maxCChunkSize;\r
                          chunkP[i].outputSize = 0;\r
                  }\r
@@ -352,7 +353,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
          }\r
 \r
          // Calculating input Checksum\r
-         crcc = BMK_checksum_MMH3A(in_buff, benchedsize);\r
+         crcc = BMK_checksum_MMH3A(in_buff, (unsigned int)benchedsize);\r
 \r
 \r
          // Bench\r
@@ -407,7 +408,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
                  DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\r", loopNb, infilename, (int)benchedsize, (int)cSize, ratio, (double)benchedsize / fastestC / 1000., (double)benchedsize / fastestD / 1000.);\r
 \r
                  // CRC Checking\r
-                 crcd = BMK_checksum_MMH3A(in_buff, benchedsize);\r
+                 crcd = BMK_checksum_MMH3A(in_buff, (unsigned int)benchedsize);\r
                  if (crcc!=crcd) { DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", infilename, (unsigned)crcc, (unsigned)crcd); break; }\r
                }\r
 \r
diff --git a/lz4.c b/lz4.c
index ea327d5..8bb7a45 100644 (file)
--- a/lz4.c
+++ b/lz4.c
 \r
 #ifdef _MSC_VER  // Visual Studio\r
 #  define inline __forceinline           // Visual is not C99, but supports some kind of inline\r
+#  include <intrin.h>   // For Visual 2005\r
 #  if LZ4_ARCH64       // 64-bit\r
 #    pragma intrinsic(_BitScanForward64) // For Visual 2005\r
 #    pragma intrinsic(_BitScanReverse64) // For Visual 2005\r
@@ -399,7 +400,7 @@ static inline int LZ4_compressCtx(void** ctx,
                while ((ip>anchor) && (ref>(BYTE*)source) && unlikely(ip[-1]==ref[-1])) { ip--; ref--; }\r
 \r
                // Encode Literal length\r
-               length = ip - anchor;\r
+               length = (int)(ip - anchor);\r
                token = op++;\r
                if unlikely(op + length + (2 + 1 + LASTLITERALS) + (length>>8) >= oend) return 0;               // Check output limit\r
 #ifdef _MSC_VER\r
@@ -429,7 +430,7 @@ static inline int LZ4_compressCtx(void** ctx,
 \r
 _next_match:\r
                // Encode Offset\r
-               LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref);\r
+               LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));\r
 \r
                // Start Counting\r
                ip+=MINMATCH; ref+=MINMATCH;   // MinMatch verified\r
@@ -447,7 +448,7 @@ _next_match:
 _endCount:\r
 \r
                // Encode MatchLength\r
-               len = (ip - anchor);\r
+               len = (int)(ip - anchor);\r
                if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }\r
                else *token += len;\r
 \r
@@ -470,7 +471,7 @@ _endCount:
 _last_literals:\r
        // Encode Last Literals\r
        {\r
-               int lastRun = iend - anchor;\r
+               int lastRun = (int)(iend - anchor);\r
                if (((char*)op - dest) + lastRun + 1 + ((lastRun-15)/255) >= maxOutputSize) return 0;\r
                if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }\r
                else *op++ = (lastRun<<ML_BITS);\r
@@ -555,7 +556,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
 \r
                        forwardH = LZ4_HASH64K_VALUE(forwardIp);\r
                        ref = base + HashTable[h];\r
-                       HashTable[h] = ip - base;\r
+                       HashTable[h] = (U16)(ip - base);\r
 \r
                } while (A32(ref) != A32(ip));\r
 \r
@@ -563,7 +564,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
                while ((ip>anchor) && (ref>(BYTE*)source) && (ip[-1]==ref[-1])) { ip--; ref--; }\r
 \r
                // Encode Literal length\r
-               length = ip - anchor;\r
+               length = (int)(ip - anchor);\r
                token = op++;\r
                if unlikely(op + length + (2 + 1 + LASTLITERALS) + (length>>8) >= oend) return 0;               // Check output limit\r
 #ifdef _MSC_VER\r
@@ -593,7 +594,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
 \r
 _next_match:\r
                // Encode Offset\r
-               LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref);\r
+               LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));\r
 \r
                // Start Counting\r
                ip+=MINMATCH; ref+=MINMATCH;   // MinMatch verified\r
@@ -611,7 +612,7 @@ _next_match:
 _endCount:\r
 \r
                // Encode MatchLength\r
-               len = (ip - anchor);\r
+               len = (int)(ip - anchor);\r
                if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }\r
                else *token += len;\r
 \r
@@ -619,11 +620,11 @@ _endCount:
                if (ip > mflimit) { anchor = ip;  break; }\r
 \r
                // Fill table\r
-               HashTable[LZ4_HASH64K_VALUE(ip-2)] = ip - 2 - base;\r
+               HashTable[LZ4_HASH64K_VALUE(ip-2)] = (U16)(ip - 2 - base);\r
 \r
                // Test next position\r
                ref = base + HashTable[LZ4_HASH64K_VALUE(ip)];\r
-               HashTable[LZ4_HASH64K_VALUE(ip)] = ip - base;\r
+               HashTable[LZ4_HASH64K_VALUE(ip)] = (U16)(ip - base);\r
                if (A32(ref) == A32(ip)) { token = op++; *token=0; goto _next_match; }\r
 \r
                // Prepare next loop\r
@@ -634,7 +635,7 @@ _endCount:
 _last_literals:\r
        // Encode Last Literals\r
        {\r
-               int lastRun = iend - anchor;\r
+               int lastRun = (int)(iend - anchor);\r
                if (((char*)op - dest) + lastRun + 1 + ((lastRun)>>8) >= maxOutputSize) return 0;\r
                if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }\r
                else *op++ = (lastRun<<ML_BITS);\r
index 9bb3392..6367401 100644 (file)
--- a/lz4demo.c
+++ b/lz4demo.c
        The license of the demo program is GPL.\r
 */\r
 \r
-//****************************\r
-// Warning messages\r
-//****************************\r
-#define _CRT_SECURE_NO_WARNINGS    // Visual (must be first line)\r
+//**************************************\r
+// Compiler Options\r
+//**************************************\r
+// Disable some Visual warning messages\r
+#define _CRT_SECURE_NO_WARNINGS\r
+#define _CRT_SECURE_NO_DEPRECATE     // VS2005\r
 \r
 \r
 //****************************\r
@@ -204,7 +206,7 @@ int compress_file(char* input_filename, char* output_filename, int compressionle
        {\r
                int outSize;\r
                // Read Block\r
-           int inSize = fread(in_buff, 1, CHUNKSIZE, finput);\r
+           int inSize = (int) fread(in_buff, (size_t)1, (size_t)CHUNKSIZE, finput);\r
                if( inSize<=0 ) break;\r
                filesize += inSize;\r
                if (displayLevel) DISPLAY("Read : %i MB  \r", (int)(filesize>>20));\r
diff --git a/lz4hc.c b/lz4hc.c
index cca755c..572ffb6 100644 (file)
--- a/lz4hc.c
+++ b/lz4hc.c
 \r
 #ifdef _MSC_VER\r
 #define inline __forceinline    // Visual is not C99, but supports some kind of inline\r
+#include <intrin.h>             // For Visual 2005\r
+#  if LZ4_ARCH64       // 64-bit\r
+#    pragma intrinsic(_BitScanForward64) // For Visual 2005\r
+#    pragma intrinsic(_BitScanReverse64) // For Visual 2005\r
+#  else\r
+#    pragma intrinsic(_BitScanForward)   // For Visual 2005\r
+#    pragma intrinsic(_BitScanReverse)   // For Visual 2005\r
+#  endif\r
 #endif\r
 \r
 #ifdef _MSC_VER  // Visual Studio\r
@@ -350,7 +358,7 @@ inline static int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure* hc4, const
                        if ((ipt<matchlimit) && (*reft == *ipt)) ipt++;\r
 _endCount:\r
 \r
-                       if (ipt-ip > ml) { ml = ipt-ip; *matchpos = ref; }\r
+                       if (ipt-ip > ml) { ml = (int)(ipt-ip); *matchpos = ref; }\r
                }\r
                ref = GETNEXT(ref);\r
        }\r
@@ -366,7 +374,7 @@ inline static int LZ4HC_InsertAndGetWiderMatch (LZ4HC_Data_Structure* hc4, const
        INITBASE(base,hc4->base);\r
        const BYTE*  ref;\r
        int nbAttempts = MAX_NB_ATTEMPTS;\r
-       int delta = ip-startLimit;\r
+       int delta = (int)(ip-startLimit);\r
 \r
        // First Match\r
        LZ4HC_Insert(hc4, ip);\r
@@ -399,7 +407,7 @@ _endCount:
 \r
                        if ((ipt-startt) > longest)\r
                        {\r
-                               longest = ipt-startt;\r
+                               longest = (int)(ipt-startt);\r
                                *matchpos = reft;\r
                                *startpos = startt;\r
                        }\r
@@ -417,7 +425,7 @@ inline static int LZ4_encodeSequence(const BYTE** ip, BYTE** op, const BYTE** an
        BYTE* token;\r
 \r
        // Encode Literal length\r
-       length = *ip - *anchor;\r
+       length = (int)(*ip - *anchor);\r
        token = (*op)++;\r
        if (length>=(int)RUN_MASK) { *token=(RUN_MASK<<ML_BITS); len = length-RUN_MASK; for(; len > 254 ; len-=255) *(*op)++ = 255;  *(*op)++ = (BYTE)len; } \r
        else *token = (length<<ML_BITS);\r
@@ -426,7 +434,7 @@ inline static int LZ4_encodeSequence(const BYTE** ip, BYTE** op, const BYTE** an
        LZ4_BLINDCOPY(*anchor, *op, length);\r
 \r
        // Encode Offset\r
-       LZ4_WRITE_LITTLEENDIAN_16(*op,*ip-ref);\r
+       LZ4_WRITE_LITTLEENDIAN_16(*op,(U16)(*ip-ref));\r
 \r
        // Encode MatchLength\r
        len = (int)(ml-MINMATCH);\r
@@ -519,8 +527,8 @@ _Search3:
                        int correction;\r
                        int new_ml = ml;\r
                        if (new_ml > OPTIMAL_ML) new_ml = OPTIMAL_ML;\r
-                       if (ip+new_ml > start2 + ml2 - MINMATCH) new_ml = start2 - ip + ml2 - MINMATCH;\r
-                       correction = new_ml - (start2 - ip);\r
+                       if (ip+new_ml > start2 + ml2 - MINMATCH) new_ml = (int)(start2 - ip) + ml2 - MINMATCH;\r
+                       correction = new_ml - (int)(start2 - ip);\r
                        if (correction > 0)\r
                        {\r
                                start2 += correction;\r
@@ -543,8 +551,8 @@ _Search3:
                                {\r
                                        int correction;\r
                                        if (ml > OPTIMAL_ML) ml = OPTIMAL_ML;\r
-                                       if (ip+ml > start2 + ml2 - MINMATCH) ml = start2 - ip + ml2 - MINMATCH;\r
-                                       correction = ml - (start2 - ip);\r
+                                       if (ip+ml > start2 + ml2 - MINMATCH) ml = (int)(start2 - ip) + ml2 - MINMATCH;\r
+                                       correction = ml - (int)(start2 - ip);\r
                                        if (correction > 0)\r
                                        {\r
                                                start2 += correction;\r
@@ -554,7 +562,7 @@ _Search3:
                                }\r
                                else\r
                                {\r
-                                       ml = start2 - ip;\r
+                                       ml = (int)(start2 - ip);\r
                                }\r
                        }\r
                        // Now, encode 2 sequences\r
@@ -570,7 +578,7 @@ _Search3:
                        {\r
                                if (start2 < ip+ml)\r
                                {\r
-                                       int correction = (ip+ml) - start2;\r
+                                       int correction = (int)(ip+ml - start2);\r
                                        start2 += correction;\r
                                        ref2 += correction;\r
                                        ml2 -= correction;\r
@@ -607,8 +615,8 @@ _Search3:
                        {\r
                                int correction;\r
                                if (ml > OPTIMAL_ML) ml = OPTIMAL_ML;\r
-                               if (ip + ml > start2 + ml2 - MINMATCH) ml = start2 - ip + ml2 - MINMATCH;\r
-                               correction = ml - (start2 - ip);\r
+                               if (ip + ml > start2 + ml2 - MINMATCH) ml = (int)(start2 - ip) + ml2 - MINMATCH;\r
+                               correction = ml - (int)(start2 - ip);\r
                                if (correction > 0)\r
                                {\r
                                        start2 += correction;\r
@@ -618,7 +626,7 @@ _Search3:
                        }\r
                        else\r
                        {\r
-                               ml = start2 - ip;\r
+                               ml = (int)(start2 - ip);\r
                        }\r
                }\r
                LZ4_encodeSequence(&ip, &op, &anchor, ml, ref);\r
@@ -637,7 +645,7 @@ _Search3:
 \r
        // Encode Last Literals\r
        {\r
-               int lastRun = iend - anchor;\r
+               int lastRun = (int)(iend - anchor);\r
                if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } \r
                else *op++ = (lastRun<<ML_BITS);\r
                memcpy(op, anchor, iend - anchor);\r