summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-03-10 15:57:42 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-03-10 15:57:42 (GMT)
commitceec6fa8492a5ff0ed163c96516716a3c2b09461 (patch)
tree2e478ef1c6960cb419760761e432471f115522c5
parent6b0c39b839b8343da195252a8c46e6d93138f3b8 (diff)
downloadlz4-ceec6fa8492a5ff0ed163c96516716a3c2b09461.zip
lz4-ceec6fa8492a5ff0ed163c96516716a3c2b09461.tar.gz
lz4-ceec6fa8492a5ff0ed163c96516716a3c2b09461.tar.bz2
g++ compatibility
-rw-r--r--.travis.yml2
-rw-r--r--Makefile4
-rw-r--r--NEWS2
-rw-r--r--lib/lz4.c10
-rw-r--r--lib/lz4frame.c92
-rw-r--r--lib/lz4frame.h2
-rw-r--r--programs/bench.c11
-rw-r--r--programs/bench.h17
-rw-r--r--programs/datagen.c4
-rw-r--r--programs/frametest.c11
-rw-r--r--[-rwxr-xr-x]programs/fullbench.c2
-rw-r--r--programs/fuzzer.c2
-rw-r--r--programs/lz4cli.c29
-rw-r--r--programs/lz4io.c178
-rw-r--r--programs/lz4io.h6
15 files changed, 92 insertions, 280 deletions
diff --git a/.travis.yml b/.travis.yml
index 9eff075..650fba1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,6 +3,7 @@ compiler: gcc
script: make test-travis
before_install:
- sudo apt-get update -qq
+ - sudo apt-get install -qq g++-multilib
- sudo apt-get install -qq gcc-multilib
- sudo apt-get install -qq valgrind
@@ -10,6 +11,7 @@ env:
- LZ4_TRAVIS_CI_ENV=travis-install
- LZ4_TRAVIS_CI_ENV=streaming-examples
- LZ4_TRAVIS_CI_ENV=cmake
+ - LZ4_TRAVIS_CI_ENV=gpptest
- LZ4_TRAVIS_CI_ENV=dist
- LZ4_TRAVIS_CI_ENV=test-lz4
- LZ4_TRAVIS_CI_ENV=test-lz4c
diff --git a/Makefile b/Makefile
index 5c7c69e..65bbfde 100644
--- a/Makefile
+++ b/Makefile
@@ -127,6 +127,10 @@ test-travis: $(TRAVIS_TARGET)
cmake:
@cd cmake_unofficial; cmake CMakeLists.txt; $(MAKE)
+gpptest:
+ export CC=g++; export CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align"; $(MAKE) -e all
+
+
streaming-examples:
cd examples; $(MAKE) -e test
diff --git a/NEWS b/NEWS
index dbea778..1de6466 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
r128:
New : command -m, to compress multiple files in a single command
Fixed : Restored lz4hc compression ratio (slightly lower since r124)
+New : g++ compatibility test
+New : datagen can generate sparse files
Fixed : Fuzzer + frametest compatibility with NetBSD (issue #48)
Added : Visual project directory
diff --git a/lib/lz4.c b/lib/lz4.c
index a8b4531..d1a2849 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -190,7 +190,7 @@ static U16 LZ4_readLE16(const void* memPtr)
return *(U16*)memPtr;
else
{
- const BYTE* p = memPtr;
+ const BYTE* p = (const BYTE*)memPtr;
return (U16)((U16)p[0] + (p[1]<<8));
}
}
@@ -204,7 +204,7 @@ static void LZ4_writeLE16(void* memPtr, U16 value)
}
else
{
- BYTE* p = memPtr;
+ BYTE* p = (BYTE*)memPtr;
p[0] = (BYTE) value;
p[1] = (BYTE)(value>>8);
}
@@ -285,9 +285,9 @@ static void LZ4_copy8(void* dstPtr, const void* srcPtr)
/* customized version of memcpy, which may overwrite up to 7 bytes beyond dstEnd */
static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd)
{
- BYTE* d = dstPtr;
- const BYTE* s = srcPtr;
- BYTE* e = dstEnd;
+ BYTE* d = (BYTE*)dstPtr;
+ const BYTE* s = (const BYTE*)srcPtr;
+ BYTE* e = (BYTE*)dstEnd;
do { LZ4_copy8(d,s); d+=8; s+=8; } while (d<e);
}
diff --git a/lib/lz4frame.c b/lib/lz4frame.c
index 5183f22..d81690f 100644
--- a/lib/lz4frame.c
+++ b/lib/lz4frame.c
@@ -1,6 +1,7 @@
/*
LZ4 auto-framing library
Copyright (C) 2011-2014, Yann Collet.
+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
@@ -32,8 +33,8 @@ You can contact the author at :
*/
/* LZ4F is a stand-alone API to create LZ4-compressed Frames
-* fully conformant to specification v1.4.1.
-* All related operations, including memory management, are handled by the library.
+* in full conformance with specification v1.4.1.
+* All related operations, including memory management, are handled by the library.
* */
@@ -46,13 +47,12 @@ Compiler Options
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wmissing-braces" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
-# pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
+# pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* GCC bug 53119 : doesn't accept {0} nor {} as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
#endif
/**************************************
-Memory routines
+* Memory routines
**************************************/
#include <stdlib.h> /* malloc, calloc, free */
#define ALLOCATOR(s) calloc(1,s)
@@ -62,7 +62,7 @@ Memory routines
/**************************************
-Includes
+* Includes
**************************************/
#include "lz4frame_static.h"
#include "lz4.h"
@@ -71,7 +71,7 @@ Includes
/**************************************
-Basic Types
+* Basic Types
**************************************/
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
# include <stdint.h>
@@ -90,7 +90,7 @@ typedef unsigned long long U64;
/**************************************
-Constants
+* Constants
**************************************/
#define KB *(1<<10)
#define MB *(1<<20)
@@ -110,7 +110,7 @@ Constants
static const U32 minHClevel = 3;
/**************************************
-Structures and local types
+* Structures and local types
**************************************/
typedef struct
{
@@ -150,12 +150,7 @@ typedef struct
/**************************************
-Macros
-**************************************/
-
-
-/**************************************
-Error management
+* Error management
**************************************/
#define LZ4F_GENERATE_STRING(STRING) #STRING,
static const char* LZ4F_errorStrings[] = { LZ4F_LIST_ERRORS(LZ4F_GENERATE_STRING) };
@@ -175,7 +170,7 @@ const char* LZ4F_getErrorName(LZ4F_errorCode_t code)
/**************************************
-Private functions
+* Private functions
**************************************/
static size_t LZ4F_getBlockSize(unsigned blockSizeID)
{
@@ -215,14 +210,15 @@ static BYTE LZ4F_headerChecksum (const BYTE* header, size_t length)
/**************************************
-Simple compression functions
+* Simple compression functions
**************************************/
size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
{
- LZ4F_preferences_t prefs = { 0 };
+ LZ4F_preferences_t prefs;
size_t headerSize;
size_t streamSize;
+ memset(&prefs, 0, sizeof(prefs));
if (preferencesPtr!=NULL) prefs = *preferencesPtr;
{
blockSizeID_t proposedBSID = max64KB;
@@ -234,7 +230,7 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere
prefs.frameInfo.blockSizeID = proposedBSID;
break;
}
- proposedBSID++;
+ proposedBSID = (blockSizeID_t)( ((int)proposedBSID) + 1);
maxBlockSize <<= 2;
}
}
@@ -258,14 +254,17 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere
*/
size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
{
- LZ4F_cctx_internal_t cctxI = { 0 }; /* works because no allocation */
- LZ4F_preferences_t prefs = { 0 };
- LZ4F_compressOptions_t options = { 0 };
+ LZ4F_cctx_internal_t cctxI;
+ LZ4F_preferences_t prefs;
+ LZ4F_compressOptions_t options;
LZ4F_errorCode_t errorCode;
BYTE* const dstStart = (BYTE*) dstBuffer;
BYTE* dstPtr = dstStart;
BYTE* const dstEnd = dstStart + dstMaxSize;
+ memset(&cctxI, 0, sizeof(cctxI)); /* works because no allocation */
+ memset(&prefs, 0, sizeof(prefs));
+ memset(&options, 0, sizeof(options));
cctxI.version = LZ4F_VERSION;
cctxI.maxBufferSize = 5 MB; /* mess with real buffer size to prevent allocation; works because autoflush==1 & stableSrc==1 */
@@ -281,7 +280,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
prefs.frameInfo.blockSizeID = proposedBSID;
break;
}
- proposedBSID++;
+ proposedBSID = (blockSizeID_t)((int)proposedBSID + 1);
maxBlockSize <<= 2;
}
}
@@ -361,7 +360,7 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_comp
*/
size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_preferences_t* preferencesPtr)
{
- LZ4F_preferences_t prefNull = { 0 };
+ LZ4F_preferences_t prefNull;
LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext;
BYTE* const dstStart = (BYTE*)dstBuffer;
BYTE* dstPtr = dstStart;
@@ -370,6 +369,7 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
if (dstMaxSize < LZ4F_MAXHEADERFRAME_SIZE) return (size_t)-ERROR_dstMaxSize_tooSmall;
if (cctxPtr->cStage != 0) return (size_t)-ERROR_GENERIC;
+ memset(&prefNull, 0, sizeof(prefNull));
if (preferencesPtr == NULL) preferencesPtr = &prefNull;
cctxPtr->prefs = *preferencesPtr;
@@ -436,7 +436,7 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
* */
size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
{
- const LZ4F_preferences_t prefsNull = { 0 };
+ const LZ4F_preferences_t prefsNull = {}; /* init to zero */
const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr;
blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID;
size_t blockSize = LZ4F_getBlockSize(bid);
@@ -444,9 +444,8 @@ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesP
size_t lastBlockSize = prefsPtr->autoFlush ? srcSize % blockSize : blockSize;
size_t blockInfo = 4; /* default, without block CRC option */
size_t frameEnd = 4 + (prefsPtr->frameInfo.contentChecksumFlag*4);
- size_t result = (blockInfo * nbBlocks) + (blockSize * (nbBlocks-1)) + lastBlockSize + frameEnd;
- return result;
+ return (blockInfo * nbBlocks) + (blockSize * (nbBlocks-1)) + lastBlockSize + frameEnd;;
}
@@ -712,7 +711,7 @@ LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_compressionContext_t* LZ4F
{
LZ4F_dctx_internal_t* dctxPtr;
- dctxPtr = ALLOCATOR(sizeof(LZ4F_dctx_internal_t));
+ dctxPtr = (LZ4F_dctx_internal_t*)ALLOCATOR(sizeof(LZ4F_dctx_internal_t));
if (dctxPtr==NULL) return (LZ4F_errorCode_t)-ERROR_GENERIC;
dctxPtr->version = versionNumber;
@@ -732,11 +731,12 @@ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_compressionContext_t LZ4F_de
/* Decompression */
-static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const BYTE* srcPtr, size_t srcSize)
+static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVoidPtr, size_t srcSize)
{
BYTE FLG, BD, HC;
unsigned version, blockMode, blockChecksumFlag, contentSizeFlag, contentChecksumFlag, dictFlag, blockSizeID;
size_t bufferNeeded;
+ const BYTE* srcPtr = (const BYTE*)srcVoidPtr;
/* need to decode header to get frameInfo */
if (srcSize < 7) return (size_t)-ERROR_GENERIC; /* minimal header size */
@@ -747,7 +747,7 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const BYTE* srcPt
/* Flags */
FLG = srcPtr[0];
- version = (FLG>>6)&_2BITS;
+ version = (FLG>>6) & _2BITS;
blockMode = (FLG>>5) & _1BIT;
blockChecksumFlag = (FLG>>4) & _1BIT;
contentSizeFlag = (FLG>>3) & _1BIT;
@@ -761,19 +761,19 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const BYTE* srcPt
if (HC != srcPtr[2]) return (size_t)-ERROR_GENERIC; /* Bad header checksum error */
/* validate */
- if (version != 1) return (size_t)-ERROR_GENERIC; /* Version Number, only supported value */
- if (blockChecksumFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */
+ if (version != 1) return (size_t)-ERROR_GENERIC; /* Version Number, only supported value */
+ if (blockChecksumFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */
if (contentSizeFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */
- if (((FLG>>1)&_1BIT) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bit */
- if (dictFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */
+ if (((FLG>>1)&_1BIT) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bit */
+ if (dictFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */
if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bit */
- if (blockSizeID < 4) return (size_t)-ERROR_GENERIC; /* Only supported values for the time being */
- if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */
+ if (blockSizeID < 4) return (size_t)-ERROR_GENERIC; /* 4-7 only supported values for the time being */
+ if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */
/* save */
- dctxPtr->frameInfo.blockMode = blockMode;
- dctxPtr->frameInfo.contentChecksumFlag = contentChecksumFlag;
- dctxPtr->frameInfo.blockSizeID = blockSizeID;
+ dctxPtr->frameInfo.blockMode = (blockMode_t)blockMode;
+ dctxPtr->frameInfo.contentChecksumFlag = (contentChecksum_t)contentChecksumFlag;
+ dctxPtr->frameInfo.blockSizeID = (blockSizeID_t)blockSizeID;
dctxPtr->maxBlockSize = LZ4F_getBlockSize(blockSizeID);
/* init */
@@ -786,9 +786,9 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const BYTE* srcPt
FREEMEM(dctxPtr->tmpIn);
FREEMEM(dctxPtr->tmpOutBuffer);
dctxPtr->maxBufferSize = bufferNeeded;
- dctxPtr->tmpIn = ALLOCATOR(dctxPtr->maxBlockSize);
+ dctxPtr->tmpIn = (BYTE*)ALLOCATOR(dctxPtr->maxBlockSize);
if (dctxPtr->tmpIn == NULL) return (size_t)-ERROR_GENERIC;
- dctxPtr->tmpOutBuffer= ALLOCATOR(dctxPtr->maxBufferSize);
+ dctxPtr->tmpOutBuffer= (BYTE*)ALLOCATOR(dctxPtr->maxBufferSize);
if (dctxPtr->tmpOutBuffer== NULL) return (size_t)-ERROR_GENERIC;
}
dctxPtr->tmpInSize = 0;
@@ -880,15 +880,6 @@ static void LZ4F_updateDict(LZ4F_dctx_internal_t* dctxPtr, const BYTE* dstPtr, s
if (withinTmp) /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
{
-#if 0
- size_t savedDictSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
- memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart- savedDictSize, savedDictSize);
- dctxPtr->dict = dctxPtr->tmpOutBuffer;
- dctxPtr->dictSize = savedDictSize + dctxPtr->tmpOutStart + dstSize;
- return;
-
-#else
-
size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
size_t copySize = 64 KB - dctxPtr->tmpOutSize;
BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
@@ -900,7 +891,6 @@ static void LZ4F_updateDict(LZ4F_dctx_internal_t* dctxPtr, const BYTE* dstPtr, s
dctxPtr->dict = dctxPtr->tmpOutBuffer;
dctxPtr->dictSize = preserveSize + dctxPtr->tmpOutStart + dstSize;
return;
-#endif
}
if (dctxPtr->dict == dctxPtr->tmpOutBuffer) /* copy dst into tmp to complete dict */
diff --git a/lib/lz4frame.h b/lib/lz4frame.h
index d73e3e2..f52ed2f 100644
--- a/lib/lz4frame.h
+++ b/lib/lz4frame.h
@@ -215,7 +215,7 @@ size_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t ctx,
* The number of bytes read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value).
* You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr)
* The function result is an hint of how many srcSize bytes LZ4F_decompress() expects for next call,
- * or an error code which can be tested using LZ4F_isError().
+ * or an error code which can be tested using LZ4F_isError().
*/
size_t LZ4F_decompress(LZ4F_decompressionContext_t ctx,
diff --git a/programs/bench.c b/programs/bench.c
index 77120f2..0ed7fcb 100644
--- a/programs/bench.c
+++ b/programs/bench.c
@@ -1,6 +1,7 @@
/*
- bench.c - Demo program to benchmark open-source compression algorithm
+ bench.c - Demo program to benchmark open-source compression algorithms
Copyright (C) Yann Collet 2012-2015
+
GPL v2 License
This program is free software; you can redistribute it and/or modify
@@ -141,15 +142,15 @@ static int chunkSize = DEFAULT_CHUNKSIZE;
static int nbIterations = NBLOOPS;
static int BMK_pause = 0;
-void BMK_SetBlocksize(int bsize) { chunkSize = bsize; }
+void BMK_setBlocksize(int bsize) { chunkSize = bsize; }
-void BMK_SetNbIterations(int nbLoops)
+void BMK_setNbIterations(int nbLoops)
{
nbIterations = nbLoops;
DISPLAY("- %i iterations -\n", nbIterations);
}
-void BMK_SetPause(void) { BMK_pause = 1; }
+void BMK_setPause(void) { BMK_pause = 1; }
/*********************************************************
@@ -234,7 +235,7 @@ static U64 BMK_GetFileSize(const char* infilename)
* Public function
**********************************************************/
-int BMK_benchFile(const char** fileNamesTable, int nbFiles, int cLevel)
+int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
{
int fileIdx=0;
char* orig_buff;
diff --git a/programs/bench.h b/programs/bench.h
index 2a20cdb..3231727 100644
--- a/programs/bench.h
+++ b/programs/bench.h
@@ -22,21 +22,12 @@
*/
#pragma once
-#if defined (__cplusplus)
-extern "C" {
-#endif
-
/* Main function */
-int BMK_benchFile(const char** fileNamesTable, int nbFiles, int cLevel);
+int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel);
/* Set Parameters */
-void BMK_SetBlocksize(int bsize);
-void BMK_SetNbIterations(int nbLoops);
-void BMK_SetPause(void);
-
-
+void BMK_setBlocksize(int bsize);
+void BMK_setNbIterations(int nbLoops);
+void BMK_setPause(void);
-#if defined (__cplusplus)
-}
-#endif
diff --git a/programs/datagen.c b/programs/datagen.c
index 2a10b81..743691e 100644
--- a/programs/datagen.c
+++ b/programs/datagen.c
@@ -90,7 +90,7 @@ static unsigned int RDG_rand(U32* src)
#define LTMASK (LTSIZE-1)
static void* RDG_createLiteralDistrib(double ld)
{
- BYTE* lt = malloc(LTSIZE);
+ BYTE* lt = (BYTE*)malloc(LTSIZE);
U32 i = 0;
BYTE character = '0';
BYTE firstChar = '(';
@@ -117,7 +117,7 @@ static void* RDG_createLiteralDistrib(double ld)
static char RDG_genChar(U32* seed, const void* ltctx)
{
- const BYTE* lt = ltctx;
+ const BYTE* lt = (const BYTE*)ltctx;
U32 id = RDG_rand(seed) & LTMASK;
return lt[id];
}
diff --git a/programs/frametest.c b/programs/frametest.c
index a5a23c2..df37e5f 100644
--- a/programs/frametest.c
+++ b/programs/frametest.c
@@ -229,11 +229,12 @@ int basicTests(U32 seed, double compressibility)
void* decodedBuffer;
U32 randState = seed;
size_t cSize, testSize;
- LZ4F_preferences_t prefs = { 0 };
+ LZ4F_preferences_t prefs;
LZ4F_decompressionContext_t dCtx;
U64 crcOrig;
// Create compressible test buffer
+ memset(&prefs, 0, sizeof(prefs));
CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
compressedBuffer = malloc(LZ4F_compressFrameBound(COMPRESSIBLE_NOISE_LENGTH, NULL));
decodedBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
@@ -441,7 +442,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
unsigned BMId = FUZ_rand(&randState) & 1;
unsigned CCflag = FUZ_rand(&randState) & 1;
unsigned autoflush = (FUZ_rand(&randState) & 7) == 2;
- LZ4F_preferences_t prefs = { 0 };
+ LZ4F_preferences_t prefs;
LZ4F_compressOptions_t cOptions = { 0 };
LZ4F_decompressOptions_t dOptions = { 0 };
unsigned nbBits = (FUZ_rand(&randState) % (FUZ_highbit(srcDataLength-1) - 1)) + 1;
@@ -452,6 +453,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
LZ4F_preferences_t* prefsPtr = &prefs;
(void)FUZ_rand(&coreRand); // update rand seed
+ memset(&prefs, 0, sizeof(prefs));
prefs.frameInfo.blockMode = (blockMode_t)BMId;
prefs.frameInfo.blockSizeID = (blockSizeID_t)BSId;
prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)CCflag;
@@ -523,17 +525,14 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
if (oSize > (size_t)(oend-op)) oSize = oend-op;
dOptions.stableDst = FUZ_rand(&randState) & 1;
if (nonContiguousDst==2) dOptions.stableDst = 0;
- //if (ip == compressedBuffer+62073) DISPLAY("oSize : %i : pos %i \n", (int)oSize, (int)(op-(BYTE*)decodedBuffer));
result = LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, &dOptions);
- //if (op+oSize >= (BYTE*)decodedBuffer+94727) DISPLAY("iSize : %i : pos %i \n", (int)iSize, (int)(ip-(BYTE*)compressedBuffer));
- //if ((int)result<0) DISPLAY("iSize : %i : pos %i \n", (int)iSize, (int)(ip-(BYTE*)compressedBuffer));
if (result == (size_t)-ERROR_checksum_invalid) locateBuffDiff((BYTE*)srcBuffer+srcStart, decodedBuffer, srcSize, nonContiguousDst);
CHECK(LZ4F_isError(result), "Decompression failed (error %i:%s)", (int)result, LZ4F_getErrorName((LZ4F_errorCode_t)result));
XXH64_update(&xxh64, op, (U32)oSize);
op += oSize;
ip += iSize;
op += nonContiguousDst;
- if (nonContiguousDst==2) op = decodedBuffer; // overwritten destination
+ if (nonContiguousDst==2) op = (BYTE*)decodedBuffer; /* overwritten destination */
}
CHECK(result != 0, "Frame decompression failed (error %i)", (int)result);
crcDecoded = XXH64_digest(&xxh64);
diff --git a/programs/fullbench.c b/programs/fullbench.c
index 756357a..6ae28d7 100755..100644
--- a/programs/fullbench.c
+++ b/programs/fullbench.c
@@ -687,7 +687,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles)
milliTime = BMK_GetMilliStart();
while(BMK_GetMilliSpan(milliTime) < TIMELOOP)
{
- if (initFunction!=NULL) ctx = initFunction(chunkP[0].origBuffer);
+ if (initFunction!=NULL) ctx = (LZ4_stream_t*)initFunction(chunkP[0].origBuffer);
for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
{
chunkP[chunkNb].compressedSize = compressionFunction(chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize);
diff --git a/programs/fuzzer.c b/programs/fuzzer.c
index f9467d9..ee2beb8 100644
--- a/programs/fuzzer.c
+++ b/programs/fuzzer.c
@@ -323,6 +323,7 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do
U32 crcOrig, crcCheck;
U32 coreRandState = seed;
U32 randState = coreRandState ^ PRIME3;
+ int result = 0;
// init
@@ -688,7 +689,6 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do
// unalloc
{
- int result = 0;
_exit:
free(CNBuffer);
free(compressedBuffer);
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 0a4d71d..10b980f 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -83,11 +83,6 @@
/*****************************
* Constants
******************************/
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-# undef LZ4_VERSION
-# define LZ4_VERSION "EXPERIMENTAL_SPARSE_FILE"
-#endif
-
#define COMPRESSOR_NAME "LZ4 command line interface"
#ifndef LZ4_VERSION
# define LZ4_VERSION "r128"
@@ -192,10 +187,6 @@ static int usage_advanced(void)
DISPLAY( " -y : overwrite output without prompting \n");
DISPLAY( " -s : suppress warnings \n");
#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- DISPLAY( "Experimental : Sparse file\n");
- DISPLAY( " -x : enable sparse file\n");
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
EXTENDED_HELP;
return 0;
}
@@ -288,9 +279,6 @@ int main(int argc, char** argv)
/* Init */
programName = argv[0];
LZ4IO_setOverwrite(0);
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- LZ4IO_setSparseFile(0);
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
blockSize = LZ4IO_setBlockSizeID(LZ4_BLOCKSIZEID_DEFAULT);
/* lz4cat predefined behavior */
@@ -387,7 +375,7 @@ int main(int argc, char** argv)
{
int B = argument[1] - '0';
blockSize = LZ4IO_setBlockSizeID(B);
- BMK_SetBlocksize(blockSize);
+ BMK_setBlocksize(blockSize);
argument++;
break;
}
@@ -405,13 +393,13 @@ int main(int argc, char** argv)
/* Benchmark */
case 'b': bench=1; multiple_inputs=1;
if (inFileNames == NULL)
- inFileNames = malloc(argc * sizeof(char*));
+ inFileNames = (const char**) malloc(argc * sizeof(char*));
break;
/* Treat non-option args as input files. See https://code.google.com/p/lz4/issues/detail?id=151 */
case 'm': multiple_inputs=1;
if (inFileNames == NULL)
- inFileNames = malloc(argc * sizeof(char*));
+ inFileNames = (const char**) malloc(argc * sizeof(char*));
break;
/* Modify Nb Iterations (benchmark only) */
@@ -419,18 +407,13 @@ int main(int argc, char** argv)
if ((argument[1] >='1') && (argument[1] <='9'))
{
int iters = argument[1] - '0';
- BMK_SetNbIterations(iters);
+ BMK_setNbIterations(iters);
argument++;
}
break;
/* Pause at the end (hidden option) */
- case 'p': main_pause=1; BMK_SetPause(); break;
-
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- /* Experimental : Enable sparse file */
- case 'x': LZ4IO_setSparseFile(1); break;
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
+ case 'p': main_pause=1; BMK_setPause(); break;
/* Specific commands for customized versions */
EXTENDED_ARGUMENTS;
@@ -471,7 +454,7 @@ int main(int argc, char** argv)
if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) badusage();
/* Check if benchmark is selected */
- if (bench) return BMK_benchFile(inFileNames, ifnIdx, cLevel);
+ if (bench) return BMK_benchFiles(inFileNames, ifnIdx, cLevel);
/* No output filename ==> try to select one automatically (when possible) */
while (!output_filename)
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 9d5bee5..fd98247 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -39,20 +39,15 @@
#endif
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
-#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wmissing-braces" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
-# pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
-#endif
#define _LARGE_FILES /* Large file support on 32-bits AIX */
#define _FILE_OFFSET_BITS 64 /* Large file support on 32-bits unix */
-#define _POSIX_SOURCE 1 /* for fileno() within <stdio.h> on unix */
/****************************
* Includes
*****************************/
-#include <stdio.h> /* fprintf, fopen, fread, _fileno, stdin, stdout */
+#include <stdio.h> /* fprintf, fopen, fread, stdin, stdout */
#include <stdlib.h> /* malloc, free */
#include <string.h> /* strcmp, strlen */
#include <time.h> /* clock */
@@ -62,55 +57,18 @@
#include "lz4frame.h"
-/**************************************
- Basic Types
-**************************************/
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
-# include <stdint.h>
- typedef uint8_t BYTE;
- typedef uint16_t U16;
- typedef uint32_t U32;
- typedef int32_t S32;
- typedef uint64_t U64;
-#else
- typedef unsigned char BYTE;
- typedef unsigned short U16;
- typedef unsigned int U32;
- typedef signed int S32;
- typedef unsigned long long U64;
-#endif
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
-
-
/****************************
* OS-specific Includes
*****************************/
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
# include <fcntl.h> /* _O_BINARY */
-# include <io.h> /* _setmode, _isatty */
-# ifdef __MINGW32__
- int _fileno(FILE *stream); /* MINGW somehow forgets to include this windows declaration into <stdio.h> */
-# endif
+# include <io.h> /* _setmode, _fileno */
+# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
# if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Avoid MSVC fseek()'s 2GiB barrier */
# define fseek _fseeki64
# endif
-# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
-# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
-# if defined(LZ4IO_ENABLE_SPARSE_FILE)
-# include <windows.h>
-# define SET_SPARSE_FILE_MODE(file) do { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); } while(0)
-# if defined(_MSC_VER) && (_MSC_VER >= 1400)
-# define fseek _fseeki64
-# endif
-# endif /* LZ4IO_ENABLE_SPARSE_FILE */
#else
-# include <unistd.h> /* isatty */
# define SET_BINARY_MODE(file)
-# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
-# if defined(LZ4IO_ENABLE_SPARSE_FILE)
-# define SET_SPARSE_FILE_MODE(file)
-# endif /* LZ4IO_ENABLE_SPARSE_FILE */
#endif
@@ -164,9 +122,6 @@ static int globalBlockSizeId = LZ4S_BLOCKSIZEID_DEFAULT;
static int blockChecksum = 0;
static int streamChecksum = 1;
static int blockIndependence = 1;
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-static int sparseFile = 0;
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
static const int minBlockSizeID = 4;
static const int maxBlockSizeID = 7;
@@ -193,7 +148,6 @@ static const int maxBlockSizeID = 7;
#define EXTENDED_ARGUMENTS
#define EXTENDED_HELP
#define EXTENDED_FORMAT
-#define DEFAULT_COMPRESSOR compress_file
#define DEFAULT_DECOMPRESSOR decodeLZ4S
@@ -208,75 +162,6 @@ int LZ4IO_setOverwrite(int yes)
return overwrite;
}
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-/* Default setting : sparseFile = 0; (Disable)
- return : sparse file mode (0:Disable / 1:Enable) */
-int LZ4IO_setSparseFile(int yes)
-{
- sparseFile = yes;
- return sparseFile;
-}
-
-static int isSparse(const void* p, size_t size)
-{
-#if 0
- /* naive */
- const char* p8 = p;
- for(; size; --size)
- {
- if(*p8 != 0)
- {
- return 0;
- }
- ++p8;
- }
- return 1;
-#elif 0
- /* xz method */
- const U64* p64 = (const U64*) p;
- const char* p8 = (const char*) p;
- const size_t n = size / sizeof(*p64);
- size_t i;
-
- for (i = 0; i < n; ++i)
- {
- if (p64[i] != 0)
- {
- return 0;
- }
- }
-
- for(i = n * sizeof(*p64); i < size; ++i)
- {
- if (p8[i] != 0)
- {
- return 0;
- }
- }
-
- return 1;
-#elif 0
- /* Neil's */
- const char* buf = (const char*) p;
- return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
-#else
- /* GNU Core Utilities : coreutils/src/system.h / is_nul() */
- const U64* wp = (const U64*) p;
- const char* cbuf = (const char*) p;
- const char* cp;
-
- // Find first nonzero *word*, or the word with the sentinel.
- while(*wp++ == 0) ;
-
- // Find the first nonzero *byte*, or the sentinel.
- cp = (const char*) (wp - 1);
- while(*cp++ == 0) ;
-
- return cbuf + size < cp;
-#endif
-}
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
-
/* blockSizeID : valid values : 4-5-6-7 */
int LZ4IO_setBlockSizeID(int bsid)
{
@@ -386,7 +271,7 @@ static int get_fileHandle(const char* input_filename, const char* output_filenam
/* unoptimized version; solves endianess & alignment issues */
static void LZ4IO_writeLE32 (void* p, unsigned value32)
{
- unsigned char* dstPtr = p;
+ unsigned char* dstPtr = (unsigned char*)p;
dstPtr[0] = (unsigned char)value32;
dstPtr[1] = (unsigned char)(value32 >> 8);
dstPtr[2] = (unsigned char)(value32 >> 16);
@@ -483,11 +368,12 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena
size_t sizeCheck, headerSize, readSize, outBuffSize;
LZ4F_compressionContext_t ctx;
LZ4F_errorCode_t errorCode;
- LZ4F_preferences_t prefs = {0};
+ LZ4F_preferences_t prefs;
/* Init */
start = clock();
+ memset(&prefs, 0, sizeof(prefs));
if ((displayLevel==2) && (compressionLevel>=3)) displayLevel=3;
errorCode = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION);
if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode));
@@ -497,9 +383,9 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena
/* Set compression parameters */
prefs.autoFlush = 1;
prefs.compressionLevel = compressionLevel;
- prefs.frameInfo.blockMode = blockIndependence;
- prefs.frameInfo.blockSizeID = globalBlockSizeId;
- prefs.frameInfo.contentChecksumFlag = streamChecksum;
+ prefs.frameInfo.blockMode = (blockMode_t)blockIndependence;
+ prefs.frameInfo.blockSizeID = (blockSizeID_t)globalBlockSizeId;
+ prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)streamChecksum;
/* Allocate Memory */
in_buff = (char*)malloc(blockSize);
@@ -578,7 +464,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize,
for (i=0; i<ifntSize; i++)
{
size_t ifnSize = strlen(inFileNamesTable[i]);
- if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = malloc(ofnSize); }
+ if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); }
strcpy(outFileName, inFileNamesTable[i]);
strcat(outFileName, suffix);
LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel);
@@ -595,7 +481,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize,
static unsigned LZ4IO_readLE32 (const void* s)
{
- const unsigned char* srcPtr = s;
+ const unsigned char* srcPtr = (const unsigned char*)s;
unsigned value32 = srcPtr[0];
value32 += (srcPtr[1]<<8);
value32 += (srcPtr[2]<<16);
@@ -663,9 +549,6 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
LZ4F_decompressionContext_t ctx;
LZ4F_errorCode_t errorCode;
LZ4F_frameInfo_t frameInfo;
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- size_t sparsePending = 0;
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
/* init */
errorCode = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION);
@@ -687,12 +570,7 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
outBuffSize = LZ4IO_setBlockSizeID(frameInfo.blockSizeID);
inBuffSize = outBuffSize + 4;
inBuff = (char*)malloc(inBuffSize);
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- outBuff = (char*)malloc(outBuffSize+sizeof(U64));
- *(U64*) &outBuff[outBuffSize] = (U64) -1; /* sentinel */
-#else /* LZ4IO_ENABLE_SPARSE_FILE */
outBuff = (char*)malloc(outBuffSize);
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
if (!inBuff || !outBuff) EXM_THROW(65, "Allocation error : not enough memory");
/* Main Loop */
@@ -712,35 +590,9 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
filesize += decodedBytes;
/* Write Block */
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- if(sparseFile)
- {
- if(isSparse(outBuff, decodedBytes))
- {
- sparsePending += decodedBytes;
- continue;
- }
- if(sparsePending > 0)
- {
- fseek(foutput, sparsePending, SEEK_CUR);
- sparsePending = 0;
- }
- }
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
sizeCheck = fwrite(outBuff, 1, decodedBytes, foutput);
if (sizeCheck != decodedBytes) EXM_THROW(68, "Write error : cannot write decoded block\n");
}
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- if(sparseFile)
- {
- if(sparsePending > 0)
- {
- fseek(foutput, sparsePending-1, SEEK_CUR);
- fputc(0, foutput);
- sparsePending = 0;
- }
- }
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
/* Free */
free(inBuff);
@@ -803,14 +655,6 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file
start = clock();
get_fileHandle(input_filename, output_filename, &finput, &foutput);
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
- if (sparseFile!=0 && foutput!=0)
- {
- DISPLAY("Experimental : Using sparse file\n");
- SET_SPARSE_FILE_MODE(foutput);
- }
-#endif /* LZ4IO_ENABLE_SPARSE_FILE */
-
/* Loop over multiple streams */
do
{
diff --git a/programs/lz4io.h b/programs/lz4io.h
index 1c9b837..f99e8bb 100644
--- a/programs/lz4io.h
+++ b/programs/lz4io.h
@@ -29,6 +29,7 @@
- The license of this source file is GPLv2.
*/
+#pragma once
/* ************************************************** */
/* Special input/output values */
@@ -77,8 +78,3 @@ int LZ4IO_setStreamChecksumMode(int xxhash);
/* Default setting : 0 (no notification) */
int LZ4IO_setNotificationLevel(int level);
-
-#if defined(LZ4IO_ENABLE_SPARSE_FILE)
-/* Default setting : 0 (sparseFile = 0; disable sparse file) */
-int LZ4IO_setSparseFile(int yes);
-#endif