created LZ4_initStreamHC()
- promoted LZ4_resetStreamHC_fast() to stable - moved LZ4_resetStreamHC() to deprecated (but do not generate a warning yet) - Updated doc, to highlight difference between init and reset - switched all invocations of LZ4_resetStreamHC() onto LZ4_initStreamHC() - misc: ensure `make all` also builds /tests
This commit is contained in:
parent
f66abc45d9
commit
c491df54ec
6
Makefile
6
Makefile
@ -50,7 +50,7 @@ endif
|
|||||||
default: lib-release lz4-release
|
default: lib-release lz4-release
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: allmost examples manuals
|
all: allmost examples manuals build_tests
|
||||||
|
|
||||||
.PHONY: allmost
|
.PHONY: allmost
|
||||||
allmost: lib lz4
|
allmost: lib lz4
|
||||||
@ -75,6 +75,10 @@ examples: liblz4.a
|
|||||||
manuals:
|
manuals:
|
||||||
@$(MAKE) -C contrib/gen_manual $@
|
@$(MAKE) -C contrib/gen_manual $@
|
||||||
|
|
||||||
|
.PHONY: build_tests
|
||||||
|
build_tests:
|
||||||
|
@$(MAKE) -C $(TESTDIR) all
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
|
@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
|
||||||
|
126
lib/lz4frame.c
126
lib/lz4frame.c
@ -1,41 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
LZ4 auto-framing library
|
* LZ4 auto-framing library
|
||||||
Copyright (C) 2011-2016, Yann Collet.
|
* Copyright (C) 2011-2016, Yann Collet.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
met:
|
* met:
|
||||||
|
*
|
||||||
* Redistributions of source code must retain the above copyright
|
* - Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above
|
* - Redistributions in binary form must reproduce the above
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
in the documentation and/or other materials provided with the
|
* in the documentation and/or other materials provided with the
|
||||||
distribution.
|
* distribution.
|
||||||
|
*
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
You can contact the author at :
|
* You can contact the author at :
|
||||||
- LZ4 homepage : http://www.lz4.org
|
* - LZ4 homepage : http://www.lz4.org
|
||||||
- LZ4 source repository : https://github.com/lz4/lz4
|
* - LZ4 source repository : https://github.com/lz4/lz4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* LZ4F is a stand-alone API to create LZ4-compressed Frames
|
/* LZ4F is a stand-alone API to create LZ4-compressed Frames
|
||||||
* in full conformance with specification v1.6.1 .
|
* in full conformance with specification v1.6.1 .
|
||||||
* This library rely upon memory management capabilities.
|
* This library rely upon memory management capabilities (malloc, free)
|
||||||
* */
|
* provided either by <stdlib.h>,
|
||||||
|
* or redirected towards another library of user's choice
|
||||||
|
* (see Memory Routines below).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
/*-************************************
|
||||||
@ -62,20 +65,27 @@ You can contact the author at :
|
|||||||
/*-************************************
|
/*-************************************
|
||||||
* Memory routines
|
* Memory routines
|
||||||
**************************************/
|
**************************************/
|
||||||
|
/*
|
||||||
|
* User may redirect invocations of
|
||||||
|
* malloc(), calloc() and free()
|
||||||
|
* towards another library or solution of their choice
|
||||||
|
* by modifying below section.
|
||||||
|
*/
|
||||||
#include <stdlib.h> /* malloc, calloc, free */
|
#include <stdlib.h> /* malloc, calloc, free */
|
||||||
#define ALLOC(s) malloc(s)
|
#define ALLOC(s) malloc(s)
|
||||||
#ifndef LZ4_SRC_INCLUDED
|
#ifndef LZ4_SRC_INCLUDED /* avoid redefinition when sources are coalesced */
|
||||||
#define ALLOC_AND_ZERO(s) calloc(1,(s))
|
# define ALLOC_AND_ZERO(s) calloc(1,(s))
|
||||||
#endif
|
#endif
|
||||||
#define FREEMEM(p) free(p)
|
#define FREEMEM(p) free(p)
|
||||||
|
|
||||||
#include <string.h> /* memset, memcpy, memmove */
|
#include <string.h> /* memset, memcpy, memmove */
|
||||||
#ifndef LZ4_SRC_INCLUDED
|
#ifndef LZ4_SRC_INCLUDED /* avoid redefinition when sources are coalesced */
|
||||||
#define MEM_INIT memset
|
# define MEM_INIT memset
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
/*-************************************
|
||||||
* Includes
|
* Library declarations
|
||||||
**************************************/
|
**************************************/
|
||||||
#define LZ4F_STATIC_LINKING_ONLY
|
#define LZ4F_STATIC_LINKING_ONLY
|
||||||
#include "lz4frame.h"
|
#include "lz4frame.h"
|
||||||
@ -606,11 +616,12 @@ size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx* cctxPtr,
|
|||||||
if (cctxPtr->lz4CtxAlloc < ctxTypeID) {
|
if (cctxPtr->lz4CtxAlloc < ctxTypeID) {
|
||||||
FREEMEM(cctxPtr->lz4CtxPtr);
|
FREEMEM(cctxPtr->lz4CtxPtr);
|
||||||
if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
|
if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
|
||||||
cctxPtr->lz4CtxPtr = (void*)LZ4_createStream();
|
cctxPtr->lz4CtxPtr = LZ4_createStream();
|
||||||
} else {
|
} else {
|
||||||
cctxPtr->lz4CtxPtr = (void*)LZ4_createStreamHC();
|
cctxPtr->lz4CtxPtr = LZ4_createStreamHC();
|
||||||
}
|
}
|
||||||
if (cctxPtr->lz4CtxPtr == NULL) return err0r(LZ4F_ERROR_allocation_failed);
|
if (cctxPtr->lz4CtxPtr == NULL)
|
||||||
|
return err0r(LZ4F_ERROR_allocation_failed);
|
||||||
cctxPtr->lz4CtxAlloc = ctxTypeID;
|
cctxPtr->lz4CtxAlloc = ctxTypeID;
|
||||||
cctxPtr->lz4CtxState = ctxTypeID;
|
cctxPtr->lz4CtxState = ctxTypeID;
|
||||||
} else if (cctxPtr->lz4CtxState != ctxTypeID) {
|
} else if (cctxPtr->lz4CtxState != ctxTypeID) {
|
||||||
@ -619,7 +630,7 @@ size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx* cctxPtr,
|
|||||||
if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
|
if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
|
||||||
LZ4_resetStream((LZ4_stream_t *) cctxPtr->lz4CtxPtr);
|
LZ4_resetStream((LZ4_stream_t *) cctxPtr->lz4CtxPtr);
|
||||||
} else {
|
} else {
|
||||||
LZ4_resetStreamHC((LZ4_streamHC_t *) cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
|
LZ4_initStreamHC((LZ4_streamHC_t *) cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel);
|
||||||
}
|
}
|
||||||
cctxPtr->lz4CtxState = ctxTypeID;
|
cctxPtr->lz4CtxState = ctxTypeID;
|
||||||
}
|
}
|
||||||
@ -1268,9 +1279,10 @@ static void LZ4F_updateDict(LZ4F_dctx* dctx,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dstPtr - dstBufferStart + dstSize >= 64 KB) { /* history in dstBuffer becomes large enough to become dictionary */
|
assert(dstPtr >= dstBufferStart);
|
||||||
|
if ((size_t)(dstPtr - dstBufferStart) + dstSize >= 64 KB) { /* history in dstBuffer becomes large enough to become dictionary */
|
||||||
dctx->dict = (const BYTE*)dstBufferStart;
|
dctx->dict = (const BYTE*)dstBufferStart;
|
||||||
dctx->dictSize = dstPtr - dstBufferStart + dstSize;
|
dctx->dictSize = (size_t)(dstPtr - dstBufferStart) + dstSize;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,7 +1298,7 @@ static void LZ4F_updateDict(LZ4F_dctx* dctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (withinTmp) { /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
|
if (withinTmp) { /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
|
||||||
size_t const preserveSize = dctx->tmpOut - dctx->tmpOutBuffer;
|
size_t const preserveSize = (size_t)(dctx->tmpOut - dctx->tmpOutBuffer);
|
||||||
size_t copySize = 64 KB - dctx->tmpOutSize;
|
size_t copySize = 64 KB - dctx->tmpOutSize;
|
||||||
const BYTE* const oldDictEnd = dctx->dict + dctx->dictSize - dctx->tmpOutStart;
|
const BYTE* const oldDictEnd = dctx->dict + dctx->dictSize - dctx->tmpOutStart;
|
||||||
if (dctx->tmpOutSize > 64 KB) copySize = 0;
|
if (dctx->tmpOutSize > 64 KB) copySize = 0;
|
||||||
@ -1371,7 +1383,7 @@ size_t LZ4F_decompress(LZ4F_dctx* dctx,
|
|||||||
|
|
||||||
case dstage_getFrameHeader:
|
case dstage_getFrameHeader:
|
||||||
if ((size_t)(srcEnd-srcPtr) >= maxFHSize) { /* enough to decode - shortcut */
|
if ((size_t)(srcEnd-srcPtr) >= maxFHSize) { /* enough to decode - shortcut */
|
||||||
size_t const hSize = LZ4F_decodeHeader(dctx, srcPtr, srcEnd-srcPtr); /* will update dStage appropriately */
|
size_t const hSize = LZ4F_decodeHeader(dctx, srcPtr, (size_t)(srcEnd-srcPtr)); /* will update dStage appropriately */
|
||||||
if (LZ4F_isError(hSize)) return hSize;
|
if (LZ4F_isError(hSize)) return hSize;
|
||||||
srcPtr += hSize;
|
srcPtr += hSize;
|
||||||
break;
|
break;
|
||||||
@ -1593,13 +1605,13 @@ size_t LZ4F_decompress(LZ4F_dctx* dctx,
|
|||||||
dict, (int)dictSize);
|
dict, (int)dictSize);
|
||||||
if (decodedSize < 0) return err0r(LZ4F_ERROR_GENERIC); /* decompression failed */
|
if (decodedSize < 0) return err0r(LZ4F_ERROR_GENERIC); /* decompression failed */
|
||||||
if (dctx->frameInfo.contentChecksumFlag)
|
if (dctx->frameInfo.contentChecksumFlag)
|
||||||
XXH32_update(&(dctx->xxh), dstPtr, decodedSize);
|
XXH32_update(&(dctx->xxh), dstPtr, (size_t)decodedSize);
|
||||||
if (dctx->frameInfo.contentSize)
|
if (dctx->frameInfo.contentSize)
|
||||||
dctx->frameRemainingSize -= decodedSize;
|
dctx->frameRemainingSize -= (size_t)decodedSize;
|
||||||
|
|
||||||
/* dictionary management */
|
/* dictionary management */
|
||||||
if (dctx->frameInfo.blockMode==LZ4F_blockLinked)
|
if (dctx->frameInfo.blockMode==LZ4F_blockLinked)
|
||||||
LZ4F_updateDict(dctx, dstPtr, decodedSize, dstStart, 0);
|
LZ4F_updateDict(dctx, dstPtr, (size_t)decodedSize, dstStart, 0);
|
||||||
|
|
||||||
dstPtr += decodedSize;
|
dstPtr += decodedSize;
|
||||||
dctx->dStage = dstage_getBlockHeader;
|
dctx->dStage = dstage_getBlockHeader;
|
||||||
@ -1636,10 +1648,10 @@ size_t LZ4F_decompress(LZ4F_dctx* dctx,
|
|||||||
if (decodedSize < 0) /* decompression failed */
|
if (decodedSize < 0) /* decompression failed */
|
||||||
return err0r(LZ4F_ERROR_decompressionFailed);
|
return err0r(LZ4F_ERROR_decompressionFailed);
|
||||||
if (dctx->frameInfo.contentChecksumFlag)
|
if (dctx->frameInfo.contentChecksumFlag)
|
||||||
XXH32_update(&(dctx->xxh), dctx->tmpOut, decodedSize);
|
XXH32_update(&(dctx->xxh), dctx->tmpOut, (size_t)decodedSize);
|
||||||
if (dctx->frameInfo.contentSize)
|
if (dctx->frameInfo.contentSize)
|
||||||
dctx->frameRemainingSize -= decodedSize;
|
dctx->frameRemainingSize -= (size_t)decodedSize;
|
||||||
dctx->tmpOutSize = decodedSize;
|
dctx->tmpOutSize = (size_t)decodedSize;
|
||||||
dctx->tmpOutStart = 0;
|
dctx->tmpOutStart = 0;
|
||||||
dctx->dStage = dstage_flushOut;
|
dctx->dStage = dstage_flushOut;
|
||||||
}
|
}
|
||||||
@ -1767,7 +1779,7 @@ size_t LZ4F_decompress(LZ4F_dctx* dctx,
|
|||||||
&& ((unsigned)(dctx->dStage)-2 < (unsigned)(dstage_getSuffix)-2) ) /* valid stages : [init ... getSuffix[ */
|
&& ((unsigned)(dctx->dStage)-2 < (unsigned)(dstage_getSuffix)-2) ) /* valid stages : [init ... getSuffix[ */
|
||||||
{
|
{
|
||||||
if (dctx->dStage == dstage_flushOut) {
|
if (dctx->dStage == dstage_flushOut) {
|
||||||
size_t const preserveSize = dctx->tmpOut - dctx->tmpOutBuffer;
|
size_t const preserveSize = (size_t)(dctx->tmpOut - dctx->tmpOutBuffer);
|
||||||
size_t copySize = 64 KB - dctx->tmpOutSize;
|
size_t copySize = 64 KB - dctx->tmpOutSize;
|
||||||
const BYTE* oldDictEnd = dctx->dict + dctx->dictSize - dctx->tmpOutStart;
|
const BYTE* oldDictEnd = dctx->dict + dctx->dictSize - dctx->tmpOutStart;
|
||||||
if (dctx->tmpOutSize > 64 KB) copySize = 0;
|
if (dctx->tmpOutSize > 64 KB) copySize = 0;
|
||||||
@ -1791,8 +1803,8 @@ size_t LZ4F_decompress(LZ4F_dctx* dctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*srcSizePtr = (srcPtr - srcStart);
|
*srcSizePtr = (size_t)(srcPtr - srcStart);
|
||||||
*dstSizePtr = (dstPtr - dstStart);
|
*dstSizePtr = (size_t)(dstPtr - dstStart);
|
||||||
return nextSrcSizeHint;
|
return nextSrcSizeHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
132
lib/lz4hc.c
132
lib/lz4hc.c
@ -105,7 +105,7 @@ static void LZ4HC_clearTables (LZ4HC_CCtx_internal* hc4)
|
|||||||
|
|
||||||
static void LZ4HC_init (LZ4HC_CCtx_internal* hc4, const BYTE* start)
|
static void LZ4HC_init (LZ4HC_CCtx_internal* hc4, const BYTE* start)
|
||||||
{
|
{
|
||||||
uptrval startingOffset = hc4->end - hc4->base;
|
uptrval startingOffset = (uptrval)(hc4->end - hc4->base);
|
||||||
if (startingOffset > 1 GB) {
|
if (startingOffset > 1 GB) {
|
||||||
LZ4HC_clearTables(hc4);
|
LZ4HC_clearTables(hc4);
|
||||||
startingOffset = 0;
|
startingOffset = 0;
|
||||||
@ -266,7 +266,7 @@ LZ4HC_InsertAndGetWiderMatch (
|
|||||||
if (LZ4_read16(iLowLimit + longest - 1) == LZ4_read16(matchPtr - lookBackLength + longest - 1)) {
|
if (LZ4_read16(iLowLimit + longest - 1) == LZ4_read16(matchPtr - lookBackLength + longest - 1)) {
|
||||||
if (LZ4_read32(matchPtr) == pattern) {
|
if (LZ4_read32(matchPtr) == pattern) {
|
||||||
int const back = lookBackLength ? LZ4HC_countBack(ip, matchPtr, iLowLimit, lowPrefixPtr) : 0;
|
int const back = lookBackLength ? LZ4HC_countBack(ip, matchPtr, iLowLimit, lowPrefixPtr) : 0;
|
||||||
matchLength = MINMATCH + LZ4_count(ip+MINMATCH, matchPtr+MINMATCH, iHighLimit);
|
matchLength = MINMATCH + (int)LZ4_count(ip+MINMATCH, matchPtr+MINMATCH, iHighLimit);
|
||||||
matchLength -= back;
|
matchLength -= back;
|
||||||
if (matchLength > longest) {
|
if (matchLength > longest) {
|
||||||
longest = matchLength;
|
longest = matchLength;
|
||||||
@ -280,7 +280,7 @@ LZ4HC_InsertAndGetWiderMatch (
|
|||||||
int back = 0;
|
int back = 0;
|
||||||
const BYTE* vLimit = ip + (dictLimit - matchIndex);
|
const BYTE* vLimit = ip + (dictLimit - matchIndex);
|
||||||
if (vLimit > iHighLimit) vLimit = iHighLimit;
|
if (vLimit > iHighLimit) vLimit = iHighLimit;
|
||||||
matchLength = LZ4_count(ip+MINMATCH, matchPtr+MINMATCH, vLimit) + MINMATCH;
|
matchLength = (int)LZ4_count(ip+MINMATCH, matchPtr+MINMATCH, vLimit) + MINMATCH;
|
||||||
if ((ip+matchLength == vLimit) && (vLimit < iHighLimit))
|
if ((ip+matchLength == vLimit) && (vLimit < iHighLimit))
|
||||||
matchLength += LZ4_count(ip+matchLength, lowPrefixPtr, iHighLimit);
|
matchLength += LZ4_count(ip+matchLength, lowPrefixPtr, iHighLimit);
|
||||||
back = lookBackLength ? LZ4HC_countBack(ip, matchPtr, iLowLimit, dictStart) : 0;
|
back = lookBackLength ? LZ4HC_countBack(ip, matchPtr, iLowLimit, dictStart) : 0;
|
||||||
@ -293,11 +293,11 @@ LZ4HC_InsertAndGetWiderMatch (
|
|||||||
|
|
||||||
if (chainSwap && matchLength==longest) { /* better match => select a better chain */
|
if (chainSwap && matchLength==longest) { /* better match => select a better chain */
|
||||||
assert(lookBackLength==0); /* search forward only */
|
assert(lookBackLength==0); /* search forward only */
|
||||||
if (matchIndex + longest <= ipIndex) {
|
if (matchIndex + (U32)longest <= ipIndex) {
|
||||||
U32 distanceToNextMatch = 1;
|
U32 distanceToNextMatch = 1;
|
||||||
int pos;
|
int pos;
|
||||||
for (pos = 0; pos <= longest - MINMATCH; pos++) {
|
for (pos = 0; pos <= longest - MINMATCH; pos++) {
|
||||||
U32 const candidateDist = DELTANEXTU16(chainTable, matchIndex + pos);
|
U32 const candidateDist = DELTANEXTU16(chainTable, matchIndex + (U32)pos);
|
||||||
if (candidateDist > distanceToNextMatch) {
|
if (candidateDist > distanceToNextMatch) {
|
||||||
distanceToNextMatch = candidateDist;
|
distanceToNextMatch = candidateDist;
|
||||||
matchChainPos = pos;
|
matchChainPos = pos;
|
||||||
@ -353,12 +353,14 @@ LZ4HC_InsertAndGetWiderMatch (
|
|||||||
} } /* PA optimization */
|
} } /* PA optimization */
|
||||||
|
|
||||||
/* follow current chain */
|
/* follow current chain */
|
||||||
matchIndex -= DELTANEXTU16(chainTable, matchIndex+matchChainPos);
|
matchIndex -= DELTANEXTU16(chainTable, matchIndex + matchChainPos);
|
||||||
|
|
||||||
} /* while ((matchIndex>=lowestMatchIndex) && (nbAttempts)) */
|
} /* while ((matchIndex>=lowestMatchIndex) && (nbAttempts)) */
|
||||||
|
|
||||||
if (dict == usingDictCtxHc && nbAttempts && ipIndex - lowestMatchIndex < MAX_DISTANCE) {
|
if ( dict == usingDictCtxHc
|
||||||
size_t const dictEndOffset = dictCtx->end - dictCtx->base;
|
&& nbAttempts
|
||||||
|
&& ipIndex - lowestMatchIndex < MAX_DISTANCE) {
|
||||||
|
size_t const dictEndOffset = (size_t)(dictCtx->end - dictCtx->base);
|
||||||
U32 dictMatchIndex = dictCtx->hashTable[LZ4HC_hashPtr(ip)];
|
U32 dictMatchIndex = dictCtx->hashTable[LZ4HC_hashPtr(ip)];
|
||||||
assert(dictEndOffset <= 1 GB);
|
assert(dictEndOffset <= 1 GB);
|
||||||
matchIndex = dictMatchIndex + lowestMatchIndex - (U32)dictEndOffset;
|
matchIndex = dictMatchIndex + lowestMatchIndex - (U32)dictEndOffset;
|
||||||
@ -370,22 +372,19 @@ LZ4HC_InsertAndGetWiderMatch (
|
|||||||
int back = 0;
|
int back = 0;
|
||||||
const BYTE* vLimit = ip + (dictEndOffset - dictMatchIndex);
|
const BYTE* vLimit = ip + (dictEndOffset - dictMatchIndex);
|
||||||
if (vLimit > iHighLimit) vLimit = iHighLimit;
|
if (vLimit > iHighLimit) vLimit = iHighLimit;
|
||||||
mlt = LZ4_count(ip+MINMATCH, matchPtr+MINMATCH, vLimit) + MINMATCH;
|
mlt = (int)LZ4_count(ip+MINMATCH, matchPtr+MINMATCH, vLimit) + MINMATCH;
|
||||||
back = lookBackLength ? LZ4HC_countBack(ip, matchPtr, iLowLimit, dictCtx->base + dictCtx->dictLimit) : 0;
|
back = lookBackLength ? LZ4HC_countBack(ip, matchPtr, iLowLimit, dictCtx->base + dictCtx->dictLimit) : 0;
|
||||||
mlt -= back;
|
mlt -= back;
|
||||||
if (mlt > longest) {
|
if (mlt > longest) {
|
||||||
longest = mlt;
|
longest = mlt;
|
||||||
*matchpos = base + matchIndex + back;
|
*matchpos = base + matchIndex + back;
|
||||||
*startpos = ip + back;
|
*startpos = ip + back;
|
||||||
}
|
} }
|
||||||
}
|
|
||||||
|
|
||||||
{ U32 const nextOffset = DELTANEXTU16(dictCtx->chainTable, dictMatchIndex);
|
{ U32 const nextOffset = DELTANEXTU16(dictCtx->chainTable, dictMatchIndex);
|
||||||
dictMatchIndex -= nextOffset;
|
dictMatchIndex -= nextOffset;
|
||||||
matchIndex -= nextOffset;
|
matchIndex -= nextOffset;
|
||||||
}
|
} } }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return longest;
|
return longest;
|
||||||
}
|
}
|
||||||
@ -518,7 +517,7 @@ LZ4_FORCE_INLINE int LZ4HC_compress_hashChain (
|
|||||||
|
|
||||||
/* Main Loop */
|
/* Main Loop */
|
||||||
while (ip <= mflimit) {
|
while (ip <= mflimit) {
|
||||||
ml = LZ4HC_InsertAndFindBestMatch (ctx, ip, matchlimit, &ref, maxNbAttempts, patternAnalysis, dict);
|
ml = LZ4HC_InsertAndFindBestMatch(ctx, ip, matchlimit, &ref, maxNbAttempts, patternAnalysis, dict);
|
||||||
if (ml<MINMATCH) { ip++; continue; }
|
if (ml<MINMATCH) { ip++; continue; }
|
||||||
|
|
||||||
/* saved, in case we would skip too much */
|
/* saved, in case we would skip too much */
|
||||||
@ -768,29 +767,31 @@ LZ4_FORCE_INLINE int LZ4HC_compress_generic_internal (
|
|||||||
|
|
||||||
static void LZ4HC_setExternalDict(LZ4HC_CCtx_internal* ctxPtr, const BYTE* newBlock);
|
static void LZ4HC_setExternalDict(LZ4HC_CCtx_internal* ctxPtr, const BYTE* newBlock);
|
||||||
|
|
||||||
static int LZ4HC_compress_generic_noDictCtx (
|
static int
|
||||||
LZ4HC_CCtx_internal* const ctx,
|
LZ4HC_compress_generic_noDictCtx (
|
||||||
const char* const src,
|
LZ4HC_CCtx_internal* const ctx,
|
||||||
char* const dst,
|
const char* const src,
|
||||||
int* const srcSizePtr,
|
char* const dst,
|
||||||
int const dstCapacity,
|
int* const srcSizePtr,
|
||||||
int cLevel,
|
int const dstCapacity,
|
||||||
limitedOutput_directive limit
|
int cLevel,
|
||||||
)
|
limitedOutput_directive limit
|
||||||
|
)
|
||||||
{
|
{
|
||||||
assert(ctx->dictCtx == NULL);
|
assert(ctx->dictCtx == NULL);
|
||||||
return LZ4HC_compress_generic_internal(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit, noDictCtx);
|
return LZ4HC_compress_generic_internal(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit, noDictCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LZ4HC_compress_generic_dictCtx (
|
static int
|
||||||
LZ4HC_CCtx_internal* const ctx,
|
LZ4HC_compress_generic_dictCtx (
|
||||||
const char* const src,
|
LZ4HC_CCtx_internal* const ctx,
|
||||||
char* const dst,
|
const char* const src,
|
||||||
int* const srcSizePtr,
|
char* const dst,
|
||||||
int const dstCapacity,
|
int* const srcSizePtr,
|
||||||
int cLevel,
|
int const dstCapacity,
|
||||||
limitedOutput_directive limit
|
int cLevel,
|
||||||
)
|
limitedOutput_directive limit
|
||||||
|
)
|
||||||
{
|
{
|
||||||
const size_t position = ctx->end - ctx->base - ctx->lowLimit;
|
const size_t position = ctx->end - ctx->base - ctx->lowLimit;
|
||||||
assert(ctx->dictCtx != NULL);
|
assert(ctx->dictCtx != NULL);
|
||||||
@ -807,15 +808,16 @@ static int LZ4HC_compress_generic_dictCtx (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LZ4HC_compress_generic (
|
static int
|
||||||
LZ4HC_CCtx_internal* const ctx,
|
LZ4HC_compress_generic (
|
||||||
const char* const src,
|
LZ4HC_CCtx_internal* const ctx,
|
||||||
char* const dst,
|
const char* const src,
|
||||||
int* const srcSizePtr,
|
char* const dst,
|
||||||
int const dstCapacity,
|
int* const srcSizePtr,
|
||||||
int cLevel,
|
int const dstCapacity,
|
||||||
limitedOutput_directive limit
|
int cLevel,
|
||||||
)
|
limitedOutput_directive limit
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (ctx->dictCtx == NULL) {
|
if (ctx->dictCtx == NULL) {
|
||||||
return LZ4HC_compress_generic_noDictCtx(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit);
|
return LZ4HC_compress_generic_noDictCtx(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit);
|
||||||
@ -842,7 +844,7 @@ int LZ4_compress_HC_extStateHC_fastReset (void* state, const char* src, char* ds
|
|||||||
int LZ4_compress_HC_extStateHC (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel)
|
int LZ4_compress_HC_extStateHC (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel)
|
||||||
{
|
{
|
||||||
if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */
|
if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */
|
||||||
LZ4_resetStreamHC ((LZ4_streamHC_t*)state, compressionLevel);
|
LZ4_initStreamHC (state, compressionLevel); /* full initialization, as there is no guarantee on state's content (could be freshly malloc'ed) */
|
||||||
return LZ4_compress_HC_extStateHC_fastReset(state, src, dst, srcSize, dstCapacity, compressionLevel);
|
return LZ4_compress_HC_extStateHC_fastReset(state, src, dst, srcSize, dstCapacity, compressionLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,12 +863,10 @@ int LZ4_compress_HC(const char* src, char* dst, int srcSize, int dstCapacity, in
|
|||||||
return cSize;
|
return cSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LZ4_compress_HC_destSize() :
|
|
||||||
* only compatible with regular HC parser */
|
|
||||||
int LZ4_compress_HC_destSize(void* LZ4HC_Data, const char* source, char* dest, int* sourceSizePtr, int targetDestSize, int cLevel)
|
int LZ4_compress_HC_destSize(void* LZ4HC_Data, const char* source, char* dest, int* sourceSizePtr, int targetDestSize, int cLevel)
|
||||||
{
|
{
|
||||||
LZ4HC_CCtx_internal* const ctx = &((LZ4_streamHC_t*)LZ4HC_Data)->internal_donotuse;
|
LZ4HC_CCtx_internal* const ctx = &((LZ4_streamHC_t*)LZ4HC_Data)->internal_donotuse;
|
||||||
LZ4_resetStreamHC((LZ4_streamHC_t*)LZ4HC_Data, cLevel);
|
LZ4_initStreamHC(LZ4HC_Data, cLevel); /* full initialization, as there is no guarantee on state's content (could be freshly malloc'ed) */
|
||||||
LZ4HC_init(ctx, (const BYTE*) source);
|
LZ4HC_init(ctx, (const BYTE*) source);
|
||||||
return LZ4HC_compress_generic(ctx, source, dest, sourceSizePtr, targetDestSize, cLevel, limitedDestSize);
|
return LZ4HC_compress_generic(ctx, source, dest, sourceSizePtr, targetDestSize, cLevel, limitedDestSize);
|
||||||
}
|
}
|
||||||
@ -877,14 +877,16 @@ int LZ4_compress_HC_destSize(void* LZ4HC_Data, const char* source, char* dest, i
|
|||||||
* Streaming Functions
|
* Streaming Functions
|
||||||
**************************************/
|
**************************************/
|
||||||
/* allocation */
|
/* allocation */
|
||||||
LZ4_streamHC_t* LZ4_createStreamHC(void) {
|
LZ4_streamHC_t* LZ4_createStreamHC(void)
|
||||||
|
{
|
||||||
LZ4_streamHC_t* const LZ4_streamHCPtr = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
|
LZ4_streamHC_t* const LZ4_streamHCPtr = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
|
||||||
if (LZ4_streamHCPtr==NULL) return NULL;
|
if (LZ4_streamHCPtr==NULL) return NULL;
|
||||||
LZ4_resetStreamHC(LZ4_streamHCPtr, LZ4HC_CLEVEL_DEFAULT);
|
LZ4_initStreamHC(LZ4_streamHCPtr, LZ4HC_CLEVEL_DEFAULT); /* full initialization, malloc'ed buffer can be full of garbage */
|
||||||
return LZ4_streamHCPtr;
|
return LZ4_streamHCPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) {
|
int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr)
|
||||||
|
{
|
||||||
DEBUGLOG(4, "LZ4_freeStreamHC(%p)", LZ4_streamHCPtr);
|
DEBUGLOG(4, "LZ4_freeStreamHC(%p)", LZ4_streamHCPtr);
|
||||||
if (!LZ4_streamHCPtr) return 0; /* support free on NULL */
|
if (!LZ4_streamHCPtr) return 0; /* support free on NULL */
|
||||||
free(LZ4_streamHCPtr);
|
free(LZ4_streamHCPtr);
|
||||||
@ -893,9 +895,10 @@ int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) {
|
|||||||
|
|
||||||
|
|
||||||
/* initialization */
|
/* initialization */
|
||||||
void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
|
void LZ4_initStreamHC (void* state, int compressionLevel)
|
||||||
{
|
{
|
||||||
LZ4_STATIC_ASSERT(sizeof(LZ4HC_CCtx_internal) <= sizeof(size_t) * LZ4_STREAMHCSIZE_SIZET); /* if compilation fails here, LZ4_STREAMHCSIZE must be increased */
|
LZ4_streamHC_t* const LZ4_streamHCPtr = (LZ4_streamHC_t*)state;
|
||||||
|
LZ4_STATIC_ASSERT(sizeof(LZ4HC_CCtx_internal) <= LZ4_STREAMHCSIZE); /* if compilation fails here, LZ4_STREAMHCSIZE must be increased */
|
||||||
DEBUGLOG(4, "LZ4_resetStreamHC(%p, %d)", LZ4_streamHCPtr, compressionLevel);
|
DEBUGLOG(4, "LZ4_resetStreamHC(%p, %d)", LZ4_streamHCPtr, compressionLevel);
|
||||||
LZ4_streamHCPtr->internal_donotuse.end = (const BYTE *)(ptrdiff_t)-1;
|
LZ4_streamHCPtr->internal_donotuse.end = (const BYTE *)(ptrdiff_t)-1;
|
||||||
LZ4_streamHCPtr->internal_donotuse.base = NULL;
|
LZ4_streamHCPtr->internal_donotuse.base = NULL;
|
||||||
@ -905,11 +908,17 @@ void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
|
|||||||
LZ4_setCompressionLevel(LZ4_streamHCPtr, compressionLevel);
|
LZ4_setCompressionLevel(LZ4_streamHCPtr, compressionLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* just a stub */
|
||||||
|
void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
|
||||||
|
{
|
||||||
|
return LZ4_initStreamHC(LZ4_streamHCPtr, compressionLevel);
|
||||||
|
}
|
||||||
|
|
||||||
void LZ4_resetStreamHC_fast (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
|
void LZ4_resetStreamHC_fast (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "LZ4_resetStreamHC_fast(%p, %d)", LZ4_streamHCPtr, compressionLevel);
|
DEBUGLOG(4, "LZ4_resetStreamHC_fast(%p, %d)", LZ4_streamHCPtr, compressionLevel);
|
||||||
if (LZ4_streamHCPtr->internal_donotuse.dirty) {
|
if (LZ4_streamHCPtr->internal_donotuse.dirty) {
|
||||||
LZ4_resetStreamHC(LZ4_streamHCPtr, compressionLevel);
|
LZ4_initStreamHC(LZ4_streamHCPtr, compressionLevel);
|
||||||
} else {
|
} else {
|
||||||
LZ4_streamHCPtr->internal_donotuse.end -= (uptrval)LZ4_streamHCPtr->internal_donotuse.base;
|
LZ4_streamHCPtr->internal_donotuse.end -= (uptrval)LZ4_streamHCPtr->internal_donotuse.base;
|
||||||
LZ4_streamHCPtr->internal_donotuse.base = NULL;
|
LZ4_streamHCPtr->internal_donotuse.base = NULL;
|
||||||
@ -938,7 +947,7 @@ int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int
|
|||||||
dictionary += dictSize - 64 KB;
|
dictionary += dictSize - 64 KB;
|
||||||
dictSize = 64 KB;
|
dictSize = 64 KB;
|
||||||
}
|
}
|
||||||
LZ4_resetStreamHC(LZ4_streamHCPtr, ctxPtr->compressionLevel);
|
LZ4_initStreamHC(LZ4_streamHCPtr, ctxPtr->compressionLevel);
|
||||||
LZ4HC_init (ctxPtr, (const BYTE*)dictionary);
|
LZ4HC_init (ctxPtr, (const BYTE*)dictionary);
|
||||||
ctxPtr->end = (const BYTE*)dictionary + dictSize;
|
ctxPtr->end = (const BYTE*)dictionary + dictSize;
|
||||||
if (dictSize >= 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3);
|
if (dictSize >= 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3);
|
||||||
@ -1029,8 +1038,8 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS
|
|||||||
{ U32 const endIndex = (U32)(streamPtr->end - streamPtr->base);
|
{ U32 const endIndex = (U32)(streamPtr->end - streamPtr->base);
|
||||||
streamPtr->end = (const BYTE*)safeBuffer + dictSize;
|
streamPtr->end = (const BYTE*)safeBuffer + dictSize;
|
||||||
streamPtr->base = streamPtr->end - endIndex;
|
streamPtr->base = streamPtr->end - endIndex;
|
||||||
streamPtr->dictLimit = endIndex - dictSize;
|
streamPtr->dictLimit = endIndex - (U32)dictSize;
|
||||||
streamPtr->lowLimit = endIndex - dictSize;
|
streamPtr->lowLimit = endIndex - (U32)dictSize;
|
||||||
if (streamPtr->nextToUpdate < streamPtr->dictLimit) streamPtr->nextToUpdate = streamPtr->dictLimit;
|
if (streamPtr->nextToUpdate < streamPtr->dictLimit) streamPtr->nextToUpdate = streamPtr->dictLimit;
|
||||||
}
|
}
|
||||||
return dictSize;
|
return dictSize;
|
||||||
@ -1061,7 +1070,7 @@ int LZ4_resetStreamStateHC(void* state, char* inputBuffer)
|
|||||||
{
|
{
|
||||||
LZ4HC_CCtx_internal *ctx = &((LZ4_streamHC_t*)state)->internal_donotuse;
|
LZ4HC_CCtx_internal *ctx = &((LZ4_streamHC_t*)state)->internal_donotuse;
|
||||||
if ((((size_t)state) & (sizeof(void*)-1)) != 0) return 1; /* Error : pointer is not aligned for pointer (32 or 64 bits) */
|
if ((((size_t)state) & (sizeof(void*)-1)) != 0) return 1; /* Error : pointer is not aligned for pointer (32 or 64 bits) */
|
||||||
LZ4_resetStreamHC((LZ4_streamHC_t*)state, ((LZ4_streamHC_t*)state)->internal_donotuse.compressionLevel);
|
LZ4_initStreamHC((LZ4_streamHC_t*)state, ((LZ4_streamHC_t*)state)->internal_donotuse.compressionLevel);
|
||||||
LZ4HC_init(ctx, (const BYTE*)inputBuffer);
|
LZ4HC_init(ctx, (const BYTE*)inputBuffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1070,7 +1079,7 @@ void* LZ4_createHC (const char* inputBuffer)
|
|||||||
{
|
{
|
||||||
LZ4_streamHC_t* hc4 = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
|
LZ4_streamHC_t* hc4 = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
|
||||||
if (hc4 == NULL) return NULL; /* not enough memory */
|
if (hc4 == NULL) return NULL; /* not enough memory */
|
||||||
LZ4_resetStreamHC(hc4, 0 /* compressionLevel */);
|
LZ4_initStreamHC(hc4, 0 /* compressionLevel */);
|
||||||
LZ4HC_init (&hc4->internal_donotuse, (const BYTE*)inputBuffer);
|
LZ4HC_init (&hc4->internal_donotuse, (const BYTE*)inputBuffer);
|
||||||
return hc4;
|
return hc4;
|
||||||
}
|
}
|
||||||
@ -1102,7 +1111,7 @@ char* LZ4_slideInputBufferHC(void* LZ4HC_Data)
|
|||||||
|
|
||||||
|
|
||||||
/* ================================================
|
/* ================================================
|
||||||
* LZ4 Optimal parser (levels 10-12)
|
* LZ4 Optimal parser (levels [LZ4HC_CLEVEL_OPT_MIN - LZ4HC_CLEVEL_MAX])
|
||||||
* ===============================================*/
|
* ===============================================*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int price;
|
int price;
|
||||||
@ -1115,8 +1124,9 @@ typedef struct {
|
|||||||
LZ4_FORCE_INLINE int LZ4HC_literalsPrice(int const litlen)
|
LZ4_FORCE_INLINE int LZ4HC_literalsPrice(int const litlen)
|
||||||
{
|
{
|
||||||
int price = litlen;
|
int price = litlen;
|
||||||
|
assert(litlen >= 0);
|
||||||
if (litlen >= (int)RUN_MASK)
|
if (litlen >= (int)RUN_MASK)
|
||||||
price += 1 + (litlen-RUN_MASK)/255;
|
price += 1 + ((litlen-(int)RUN_MASK) / 255);
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1125,11 +1135,13 @@ LZ4_FORCE_INLINE int LZ4HC_literalsPrice(int const litlen)
|
|||||||
LZ4_FORCE_INLINE int LZ4HC_sequencePrice(int litlen, int mlen)
|
LZ4_FORCE_INLINE int LZ4HC_sequencePrice(int litlen, int mlen)
|
||||||
{
|
{
|
||||||
int price = 1 + 2 ; /* token + 16-bit offset */
|
int price = 1 + 2 ; /* token + 16-bit offset */
|
||||||
|
assert(litlen >= 0);
|
||||||
|
assert(mlen >= MINMATCH);
|
||||||
|
|
||||||
price += LZ4HC_literalsPrice(litlen);
|
price += LZ4HC_literalsPrice(litlen);
|
||||||
|
|
||||||
if (mlen >= (int)(ML_MASK+MINMATCH))
|
if (mlen >= (int)(ML_MASK+MINMATCH))
|
||||||
price += 1 + (mlen-(ML_MASK+MINMATCH))/255;
|
price += 1 + ((mlen-(int)(ML_MASK+MINMATCH)) / 255);
|
||||||
|
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
75
lib/lz4hc.h
75
lib/lz4hc.h
@ -84,9 +84,9 @@ LZ4LIB_API int LZ4_compress_HC_extStateHC(void* stateHC, const char* src, char*
|
|||||||
* Will compress as much data as possible from `src`
|
* Will compress as much data as possible from `src`
|
||||||
* to fit into `targetDstSize` budget.
|
* to fit into `targetDstSize` budget.
|
||||||
* Result is provided in 2 parts :
|
* Result is provided in 2 parts :
|
||||||
* @return : the number of bytes written into 'dst'
|
* @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)
|
||||||
* or 0 if compression fails.
|
* or 0 if compression fails.
|
||||||
* `srcSizePtr` : value will be updated to indicate how much bytes were read from `src`
|
* `srcSizePtr` : on success, *srcSizePtr is updated to indicate how much bytes were read from `src`
|
||||||
*/
|
*/
|
||||||
LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
|
LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
|
||||||
const char* src, char* dst,
|
const char* src, char* dst,
|
||||||
@ -103,8 +103,8 @@ LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
|
|||||||
/*! LZ4_createStreamHC() and LZ4_freeStreamHC() :
|
/*! LZ4_createStreamHC() and LZ4_freeStreamHC() :
|
||||||
* These functions create and release memory for LZ4 HC streaming state.
|
* These functions create and release memory for LZ4 HC streaming state.
|
||||||
* Newly created states are automatically initialized.
|
* Newly created states are automatically initialized.
|
||||||
* Existing states can be re-used several times, using LZ4_resetStreamHC().
|
* A same state can be used multiple times consecutively,
|
||||||
* These methods are API and ABI stable, they can be used in combination with a DLL.
|
* starting with LZ4_resetStreamHC_fast() to start a new stream of blocks.
|
||||||
*/
|
*/
|
||||||
LZ4LIB_API LZ4_streamHC_t* LZ4_createStreamHC(void);
|
LZ4LIB_API LZ4_streamHC_t* LZ4_createStreamHC(void);
|
||||||
LZ4LIB_API int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
|
LZ4LIB_API int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
|
||||||
@ -121,35 +121,38 @@ LZ4LIB_API int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
|
|||||||
|
|
||||||
Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
|
Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
|
||||||
or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
|
or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
|
||||||
LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once.
|
LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once,
|
||||||
|
which is automatically the case when state is created using LZ4_createStreamHC().
|
||||||
If state space is provided manually with no guarantee of its content, for example allocated on stack,
|
|
||||||
it must be fully initialized, using LZ4_resetStreamHC().
|
|
||||||
LZ4_resetStreamHC() is heavier, and it's guaranteed to succeed on any valid memory segment.
|
|
||||||
In contrast, LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once.
|
|
||||||
|
|
||||||
After reset, a first "fictional block" can be designated as initial dictionary,
|
After reset, a first "fictional block" can be designated as initial dictionary,
|
||||||
using LZ4_loadDictHC() (Optional).
|
using LZ4_loadDictHC() (Optional).
|
||||||
|
|
||||||
Invoke LZ4_compress_HC_continue() to compress each successive block.
|
Invoke LZ4_compress_HC_continue() to compress each successive block.
|
||||||
The number of blocks is unlimited.
|
The number of blocks is unlimited.
|
||||||
Previous input blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
|
Previous input blocks, including initial dictionary when present,
|
||||||
|
must remain accessible and unmodified during compression.
|
||||||
|
|
||||||
'dst' buffer should be sized to handle worst case scenarios (see LZ4_compressBound()), ensuring compression success.
|
It's allowed to update compression level anytime between blocks,
|
||||||
In case of failure, the API does not guarantee recovery, so the state _must_ be reset.
|
using LZ4_setCompressionLevel() (experimental).
|
||||||
Whenever `dst` buffer size cannot be made >= LZ4_compressBound(),
|
|
||||||
consider using LZ4_compress_HC_continue_destSize() to ensure success.
|
'dst' buffer should be sized to handle worst case scenarios
|
||||||
|
(see LZ4_compressBound(), it ensures compression success).
|
||||||
|
In case of failure, the API does not guarantee recovery,
|
||||||
|
so the state _must_ be reset.
|
||||||
|
To ensure compression success
|
||||||
|
whenever `dst` buffer size cannot be made >= LZ4_compressBound(),
|
||||||
|
consider using LZ4_compress_HC_continue_destSize().
|
||||||
|
|
||||||
Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
|
Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
|
||||||
it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
|
it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
|
||||||
Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
|
Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
|
||||||
|
|
||||||
After completing a streaming compression,
|
After completing a streaming compression,
|
||||||
it's possible to start a new stream of blocks, and re-use the same LZ4_streamHC_t state
|
it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state,
|
||||||
by resetting it, using LZ4_resetStreamHC_fast().
|
just by resetting it, using LZ4_resetStreamHC_fast().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
|
LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, int compressionLevel);
|
||||||
LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
|
LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
|
||||||
|
|
||||||
LZ4LIB_API int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr,
|
LZ4LIB_API int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr,
|
||||||
@ -239,22 +242,31 @@ struct LZ4HC_CCtx_internal
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* do not use these definitions directly.
|
/* Do not use these definitions directly !
|
||||||
* allocate an LZ4_streamHC_t instead. */
|
* Declare or allocate an LZ4_streamHC_t instead.
|
||||||
|
*/
|
||||||
#define LZ4_STREAMHCSIZE (4*LZ4HC_HASHTABLESIZE + 2*LZ4HC_MAXD + 56 + ((sizeof(void*)==16) ? 56 : 0) /* AS400*/ ) /* 262200 or 262256*/
|
#define LZ4_STREAMHCSIZE (4*LZ4HC_HASHTABLESIZE + 2*LZ4HC_MAXD + 56 + ((sizeof(void*)==16) ? 56 : 0) /* AS400*/ ) /* 262200 or 262256*/
|
||||||
#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
|
#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
|
||||||
union LZ4_streamHC_u {
|
union LZ4_streamHC_u {
|
||||||
size_t table[LZ4_STREAMHCSIZE_SIZET];
|
size_t table[LZ4_STREAMHCSIZE_SIZET];
|
||||||
LZ4HC_CCtx_internal internal_donotuse;
|
LZ4HC_CCtx_internal internal_donotuse;
|
||||||
}; /* previously typedef'd to LZ4_streamHC_t */
|
}; /* previously typedef'd to LZ4_streamHC_t */
|
||||||
|
|
||||||
/* LZ4_streamHC_t :
|
/* LZ4_streamHC_t :
|
||||||
* This structure allows static allocation of LZ4 HC streaming state.
|
* This structure allows static allocation of LZ4 HC streaming state.
|
||||||
* State must be initialized using LZ4_resetStreamHC() before first use.
|
* This can be used to allocate statically, on state, or as part of a larger structure.
|
||||||
|
*
|
||||||
|
* Such state **must** be initialized using LZ4_initStreamHC() before first use.
|
||||||
|
*
|
||||||
|
* Note that invoking LZ4_initStreamHC() is not required when
|
||||||
|
* the state was created using LZ4_createStreamHC() (which is recommended).
|
||||||
|
* Using the normal builder, a newly created state is automatically initialized.
|
||||||
*
|
*
|
||||||
* Static allocation shall only be used in combination with static linking.
|
* Static allocation shall only be used in combination with static linking.
|
||||||
* When invoking LZ4 from a DLL, use create/free functions instead, which are API and ABI stable.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
LZ4LIB_API void LZ4_initStreamHC (void* streamHCPtr, int compressionLevel);
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
/*-************************************
|
||||||
* Deprecated Functions
|
* Deprecated Functions
|
||||||
@ -264,11 +276,11 @@ union LZ4_streamHC_u {
|
|||||||
/* deprecated compression functions */
|
/* deprecated compression functions */
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC (const char* source, char* dest, int inputSize);
|
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC (const char* source, char* dest, int inputSize);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
|
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
|
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
|
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
|
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
|
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||||
@ -284,12 +296,23 @@ LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_comp
|
|||||||
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
|
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
|
||||||
LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
|
LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
|
||||||
LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API int LZ4_freeHC (void* LZ4HC_Data);
|
LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API int LZ4_freeHC (void* LZ4HC_Data);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
|
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
|
||||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
||||||
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API int LZ4_sizeofStreamStateHC(void);
|
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API int LZ4_sizeofStreamStateHC(void);
|
||||||
LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") LZ4LIB_API int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
|
LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") LZ4LIB_API int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
|
||||||
|
|
||||||
|
|
||||||
|
/* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
|
||||||
|
* The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
|
||||||
|
* which is now the recommended function to start a new stream of blocks,
|
||||||
|
* but cannot be used to initialize a memory segment containing arbitrary garbage data.
|
||||||
|
*
|
||||||
|
* It is recommended to switch to LZ4_initStreamHC().
|
||||||
|
* LZ4_resetStreamHC() will generate deprecation warnings in a future version.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
|
||||||
|
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -243,7 +243,7 @@ static int local_LZ4_compress_forceDict(const char* in, char* out, int inSize)
|
|||||||
LZ4_streamHC_t LZ4_streamHC;
|
LZ4_streamHC_t LZ4_streamHC;
|
||||||
static void local_LZ4_resetStreamHC(void)
|
static void local_LZ4_resetStreamHC(void)
|
||||||
{
|
{
|
||||||
LZ4_resetStreamHC(&LZ4_streamHC, 0);
|
LZ4_initStreamHC(&LZ4_streamHC, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int local_LZ4_saveDictHC(const char* in, char* out, int inSize)
|
static int local_LZ4_saveDictHC(const char* in, char* out, int inSize)
|
||||||
@ -327,16 +327,19 @@ static int local_LZ4_decompress_safe_partial(const char* in, char* out, int inSi
|
|||||||
/* frame functions */
|
/* frame functions */
|
||||||
static int local_LZ4F_compressFrame(const char* in, char* out, int inSize)
|
static int local_LZ4F_compressFrame(const char* in, char* out, int inSize)
|
||||||
{
|
{
|
||||||
return (int)LZ4F_compressFrame(out, LZ4F_compressFrameBound(inSize, NULL), in, inSize, NULL);
|
assert(inSize >= 0);
|
||||||
|
return (int)LZ4F_compressFrame(out, LZ4F_compressFrameBound((size_t)inSize, NULL), in, (size_t)inSize, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static LZ4F_decompressionContext_t g_dCtx;
|
static LZ4F_decompressionContext_t g_dCtx;
|
||||||
|
|
||||||
static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outSize)
|
static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outSize)
|
||||||
{
|
{
|
||||||
size_t srcSize = inSize;
|
size_t srcSize = (size_t)inSize;
|
||||||
size_t dstSize = outSize;
|
size_t dstSize = (size_t)outSize;
|
||||||
size_t result;
|
size_t result;
|
||||||
|
assert(inSize >= 0);
|
||||||
|
assert(outSize >= 0);
|
||||||
result = LZ4F_decompress(g_dCtx, out, &dstSize, in, &srcSize, NULL);
|
result = LZ4F_decompress(g_dCtx, out, &dstSize, in, &srcSize, NULL);
|
||||||
if (result!=0) { DISPLAY("Error decompressing frame : unfinished frame\n"); exit(8); }
|
if (result!=0) { DISPLAY("Error decompressing frame : unfinished frame\n"); exit(8); }
|
||||||
if (srcSize != (size_t)inSize) { DISPLAY("Error decompressing frame : read size incorrect\n"); exit(9); }
|
if (srcSize != (size_t)inSize) { DISPLAY("Error decompressing frame : read size incorrect\n"); exit(9); }
|
||||||
@ -439,7 +442,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
|
|||||||
char* out = compressed_buff;
|
char* out = compressed_buff;
|
||||||
nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize);
|
nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize);
|
||||||
for (i=0; i<nbChunks; i++) {
|
for (i=0; i<nbChunks; i++) {
|
||||||
chunkP[i].id = i;
|
chunkP[i].id = (U32)i;
|
||||||
chunkP[i].origBuffer = in; in += g_chunkSize;
|
chunkP[i].origBuffer = in; in += g_chunkSize;
|
||||||
if ((int)remaining > g_chunkSize) { chunkP[i].origSize = g_chunkSize; remaining -= g_chunkSize; } else { chunkP[i].origSize = (int)remaining; remaining = 0; }
|
if ((int)remaining > g_chunkSize) { chunkP[i].origSize = g_chunkSize; remaining -= g_chunkSize; } else { chunkP[i].origSize = (int)remaining; remaining = 0; }
|
||||||
chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
|
chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
|
||||||
@ -611,7 +614,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
|
|||||||
PROGRESS("%2i-%-34.34s :%10i -> %7.1f MB/s\r", loopNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000000);
|
PROGRESS("%2i-%-34.34s :%10i -> %7.1f MB/s\r", loopNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000000);
|
||||||
|
|
||||||
/* CRC Checking */
|
/* CRC Checking */
|
||||||
crcDecoded = XXH32(orig_buff, (int)benchedSize, 0);
|
crcDecoded = XXH32(orig_buff, benchedSize, 0);
|
||||||
if (checkResult && (crcOriginal!=crcDecoded)) {
|
if (checkResult && (crcOriginal!=crcDecoded)) {
|
||||||
DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n",
|
DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n",
|
||||||
inFileName, (unsigned)crcOriginal, (unsigned)crcDecoded);
|
inFileName, (unsigned)crcOriginal, (unsigned)crcDecoded);
|
||||||
|
@ -309,13 +309,13 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
unsigned long long hcbytes = 0;
|
unsigned long long hcbytes = 0;
|
||||||
unsigned long long ccbytes = 0;
|
unsigned long long ccbytes = 0;
|
||||||
void* const CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
|
void* const CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
|
||||||
size_t const compressedBufferSize = LZ4_compressBound(FUZ_MAX_BLOCK_SIZE);
|
size_t const compressedBufferSize = (size_t)LZ4_compressBound(FUZ_MAX_BLOCK_SIZE);
|
||||||
char* const compressedBuffer = (char*)malloc(compressedBufferSize);
|
char* const compressedBuffer = (char*)malloc(compressedBufferSize);
|
||||||
char* const decodedBuffer = (char*)malloc(FUZ_MAX_DICT_SIZE + FUZ_MAX_BLOCK_SIZE);
|
char* const decodedBuffer = (char*)malloc(FUZ_MAX_DICT_SIZE + FUZ_MAX_BLOCK_SIZE);
|
||||||
size_t const labSize = 96 KB;
|
size_t const labSize = 96 KB;
|
||||||
void* const lowAddrBuffer = FUZ_createLowAddr(labSize);
|
void* const lowAddrBuffer = FUZ_createLowAddr(labSize);
|
||||||
void* const stateLZ4 = malloc(LZ4_sizeofState());
|
void* const stateLZ4 = malloc((size_t)LZ4_sizeofState());
|
||||||
void* const stateLZ4HC = malloc(LZ4_sizeofStateHC());
|
void* const stateLZ4HC = malloc((size_t)LZ4_sizeofStateHC());
|
||||||
LZ4_stream_t LZ4dict;
|
LZ4_stream_t LZ4dict;
|
||||||
LZ4_streamHC_t LZ4dictHC;
|
LZ4_streamHC_t LZ4dictHC;
|
||||||
U32 coreRandState = seed;
|
U32 coreRandState = seed;
|
||||||
@ -370,7 +370,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
const char* dict = block - dictSize;
|
const char* dict = block - dictSize;
|
||||||
int compressedSize, HCcompressedSize;
|
int compressedSize, HCcompressedSize;
|
||||||
int blockContinueCompressedSize;
|
int blockContinueCompressedSize;
|
||||||
U32 const crcOrig = XXH32(block, blockSize, 0);
|
U32 const crcOrig = XXH32(block, (size_t)blockSize, 0);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
FUZ_displayUpdate(cycleNb);
|
FUZ_displayUpdate(cycleNb);
|
||||||
@ -395,7 +395,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
DISPLAYLEVEL(5, "destSize : %7i/%7i; content%7i/%7i ", ret, targetSize, srcSize, blockSize);
|
DISPLAYLEVEL(5, "destSize : %7i/%7i; content%7i/%7i ", ret, targetSize, srcSize, blockSize);
|
||||||
if (targetSize>0) {
|
if (targetSize>0) {
|
||||||
/* check correctness */
|
/* check correctness */
|
||||||
U32 const crcBase = XXH32(block, srcSize, 0);
|
U32 const crcBase = XXH32(block, (size_t)srcSize, 0);
|
||||||
char const canary = FUZ_rand(&randState) & 255;
|
char const canary = FUZ_rand(&randState) & 255;
|
||||||
FUZ_CHECKTEST((ret==0), "LZ4_compress_destSize() compression failed");
|
FUZ_CHECKTEST((ret==0), "LZ4_compress_destSize() compression failed");
|
||||||
FUZ_DISPLAYTEST();
|
FUZ_DISPLAYTEST();
|
||||||
@ -430,7 +430,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
FUZ_CHECKTEST(srcSize > blockSize, "LZ4_compress_HC_destSize() fed more than src buffer !");
|
FUZ_CHECKTEST(srcSize > blockSize, "LZ4_compress_HC_destSize() fed more than src buffer !");
|
||||||
if (targetSize>0) {
|
if (targetSize>0) {
|
||||||
/* check correctness */
|
/* check correctness */
|
||||||
U32 const crcBase = XXH32(block, srcSize, 0);
|
U32 const crcBase = XXH32(block, (size_t)srcSize, 0);
|
||||||
char const canary = FUZ_rand(&randState) & 255;
|
char const canary = FUZ_rand(&randState) & 255;
|
||||||
FUZ_CHECKTEST((ret==0), "LZ4_compress_HC_destSize() compression failed");
|
FUZ_CHECKTEST((ret==0), "LZ4_compress_HC_destSize() compression failed");
|
||||||
FUZ_DISPLAYTEST();
|
FUZ_DISPLAYTEST();
|
||||||
@ -547,7 +547,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
FUZ_CHECKTEST(ret<0, "LZ4_decompress_safe failed despite amply sufficient space");
|
FUZ_CHECKTEST(ret<0, "LZ4_decompress_safe failed despite amply sufficient space");
|
||||||
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe did not regenerate original data");
|
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe did not regenerate original data");
|
||||||
FUZ_CHECKTEST(decodedBuffer[blockSize+1], "LZ4_decompress_safe overrun specified output buffer size");
|
FUZ_CHECKTEST(decodedBuffer[blockSize+1], "LZ4_decompress_safe overrun specified output buffer size");
|
||||||
{ U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
|
{ U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
|
||||||
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe corrupted decoded data");
|
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe corrupted decoded data");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,7 +582,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
/* Test partial decoding => must work */
|
/* Test partial decoding => must work */
|
||||||
FUZ_DISPLAYTEST("test LZ4_decompress_safe_partial");
|
FUZ_DISPLAYTEST("test LZ4_decompress_safe_partial");
|
||||||
{ size_t const missingBytes = FUZ_rand(&randState) % blockSize;
|
{ size_t const missingBytes = FUZ_rand(&randState) % blockSize;
|
||||||
int const targetSize = (int)(blockSize - missingBytes);
|
int const targetSize = (int)((size_t)blockSize - missingBytes);
|
||||||
char const sentinel = decodedBuffer[targetSize] = block[targetSize] ^ 0x5A;
|
char const sentinel = decodedBuffer[targetSize] = block[targetSize] ^ 0x5A;
|
||||||
int const decResult = LZ4_decompress_safe_partial(compressedBuffer, decodedBuffer, compressedSize, targetSize, blockSize);
|
int const decResult = LZ4_decompress_safe_partial(compressedBuffer, decodedBuffer, compressedSize, targetSize, blockSize);
|
||||||
FUZ_CHECKTEST(decResult<0, "LZ4_decompress_safe_partial failed despite valid input data (error:%i)", decResult);
|
FUZ_CHECKTEST(decResult<0, "LZ4_decompress_safe_partial failed despite valid input data (error:%i)", decResult);
|
||||||
@ -653,7 +653,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
memcpy(decodedBuffer, dict, dictSize);
|
memcpy(decodedBuffer, dict, dictSize);
|
||||||
ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer+dictSize, blockSize, decodedBuffer, dictSize);
|
ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer+dictSize, blockSize, decodedBuffer, dictSize);
|
||||||
FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_decompress_fast_usingDict did not read all compressed block input");
|
FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_decompress_fast_usingDict did not read all compressed block input");
|
||||||
{ U32 const crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0);
|
{ U32 const crcCheck = XXH32(decodedBuffer+dictSize, (size_t)blockSize, 0);
|
||||||
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
|
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
|
||||||
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize);
|
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize);
|
||||||
}
|
}
|
||||||
@ -661,7 +661,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
FUZ_DISPLAYTEST("test LZ4_decompress_safe_usingDict()");
|
FUZ_DISPLAYTEST("test LZ4_decompress_safe_usingDict()");
|
||||||
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize, decodedBuffer, dictSize);
|
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize, decodedBuffer, dictSize);
|
||||||
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
||||||
{ U32 const crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0);
|
{ U32 const crcCheck = XXH32(decodedBuffer+dictSize, (size_t)blockSize, 0);
|
||||||
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -830,7 +830,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
FUZ_DISPLAYTEST("LZ4_compress_HC_continue with an external dictionary");
|
FUZ_DISPLAYTEST("LZ4_compress_HC_continue with an external dictionary");
|
||||||
dict -= (FUZ_rand(&randState) & 7); /* even bigger separation */
|
dict -= (FUZ_rand(&randState) & 7); /* even bigger separation */
|
||||||
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
|
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
|
||||||
LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
|
LZ4_initStreamHC (&LZ4dictHC, compressionLevel);
|
||||||
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
||||||
LZ4_setCompressionLevel(&LZ4dictHC, compressionLevel-1);
|
LZ4_setCompressionLevel(&LZ4dictHC, compressionLevel-1);
|
||||||
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
|
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4dictHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
|
||||||
@ -855,7 +855,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
|
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
|
||||||
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
||||||
FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
|
FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
|
||||||
{ U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
|
{ U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
|
||||||
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
|
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
|
||||||
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
||||||
}
|
}
|
||||||
@ -865,9 +865,9 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
{
|
{
|
||||||
LZ4_streamHC_t LZ4_streamHC;
|
LZ4_streamHC_t LZ4_streamHC;
|
||||||
|
|
||||||
LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
|
LZ4_initStreamHC (&LZ4dictHC, compressionLevel);
|
||||||
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
||||||
LZ4_resetStreamHC (&LZ4_streamHC, compressionLevel);
|
LZ4_initStreamHC (&LZ4_streamHC, compressionLevel);
|
||||||
LZ4_attach_HC_dictionary(&LZ4_streamHC, &LZ4dictHC);
|
LZ4_attach_HC_dictionary(&LZ4_streamHC, &LZ4dictHC);
|
||||||
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4_streamHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
|
blockContinueCompressedSize = LZ4_compress_HC_continue(&LZ4_streamHC, block, compressedBuffer, blockSize, (int)compressedBufferSize);
|
||||||
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_HC_continue with ExtDictCtx failed");
|
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_HC_continue with ExtDictCtx failed");
|
||||||
@ -901,7 +901,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
|
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize, dict, dictSize);
|
||||||
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
||||||
FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
|
FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size");
|
||||||
{ U32 const crcCheck = XXH32(decodedBuffer, blockSize, 0);
|
{ U32 const crcCheck = XXH32(decodedBuffer, (size_t)blockSize, 0);
|
||||||
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
|
if (crcCheck!=crcOrig) FUZ_findDiff(block, decodedBuffer);
|
||||||
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
||||||
}
|
}
|
||||||
@ -912,7 +912,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
{ int const availableSpace = (FUZ_rand(&randState) % blockSize) + 5;
|
{ int const availableSpace = (FUZ_rand(&randState) % blockSize) + 5;
|
||||||
int consumedSize = blockSize;
|
int consumedSize = blockSize;
|
||||||
FUZ_DISPLAYTEST();
|
FUZ_DISPLAYTEST();
|
||||||
LZ4_resetStreamHC (&LZ4dictHC, compressionLevel);
|
LZ4_initStreamHC (&LZ4dictHC, compressionLevel);
|
||||||
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
LZ4_loadDictHC(&LZ4dictHC, dict, dictSize);
|
||||||
blockContinueCompressedSize = LZ4_compress_HC_continue_destSize(&LZ4dictHC, block, compressedBuffer, &consumedSize, availableSpace);
|
blockContinueCompressedSize = LZ4_compress_HC_continue_destSize(&LZ4dictHC, block, compressedBuffer, &consumedSize, availableSpace);
|
||||||
DISPLAYLEVEL(5, " LZ4_compress_HC_continue_destSize : compressed %6i/%6i into %6i/%6i at cLevel=%i\n", consumedSize, blockSize, blockContinueCompressedSize, availableSpace, compressionLevel);
|
DISPLAYLEVEL(5, " LZ4_compress_HC_continue_destSize : compressed %6i/%6i into %6i/%6i at cLevel=%i\n", consumedSize, blockSize, blockContinueCompressedSize, availableSpace, compressionLevel);
|
||||||
@ -925,8 +925,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
|
|||||||
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, consumedSize, dict, dictSize);
|
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, consumedSize, dict, dictSize);
|
||||||
FUZ_CHECKTEST(ret!=consumedSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
FUZ_CHECKTEST(ret!=consumedSize, "LZ4_decompress_safe_usingDict did not regenerate original data");
|
||||||
FUZ_CHECKTEST(decodedBuffer[consumedSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size")
|
FUZ_CHECKTEST(decodedBuffer[consumedSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size")
|
||||||
{ U32 const crcSrc = XXH32(block, consumedSize, 0);
|
{ U32 const crcSrc = XXH32(block, (size_t)consumedSize, 0);
|
||||||
U32 const crcDst = XXH32(decodedBuffer, consumedSize, 0);
|
U32 const crcDst = XXH32(decodedBuffer, (size_t)consumedSize, 0);
|
||||||
if (crcSrc!=crcDst) FUZ_findDiff(block, decodedBuffer);
|
if (crcSrc!=crcDst) FUZ_findDiff(block, decodedBuffer);
|
||||||
FUZ_CHECKTEST(crcSrc!=crcDst, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
FUZ_CHECKTEST(crcSrc!=crcDst, "LZ4_decompress_safe_usingDict corrupted decoded data");
|
||||||
}
|
}
|
||||||
@ -1080,7 +1080,7 @@ static void FUZ_unitTests(int compressionLevel)
|
|||||||
/* simple HC compression test */
|
/* simple HC compression test */
|
||||||
DISPLAYLEVEL(3, " Simple HC round-trip : ");
|
DISPLAYLEVEL(3, " Simple HC round-trip : ");
|
||||||
{ U64 const crc64 = XXH64(testInput, testCompressedSize, 0);
|
{ U64 const crc64 = XXH64(testInput, testCompressedSize, 0);
|
||||||
LZ4_resetStreamHC(&sHC, compressionLevel);
|
LZ4_initStreamHC(&sHC, compressionLevel);
|
||||||
result = LZ4_compress_HC_continue(&sHC, testInput, testCompressed, testCompressedSize, testCompressedSize-1);
|
result = LZ4_compress_HC_continue(&sHC, testInput, testCompressed, testCompressedSize, testCompressedSize-1);
|
||||||
FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() compression failed");
|
FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() compression failed");
|
||||||
FUZ_CHECKTEST(sHC.internal_donotuse.dirty, "Context should be clean");
|
FUZ_CHECKTEST(sHC.internal_donotuse.dirty, "Context should be clean");
|
||||||
@ -1105,7 +1105,7 @@ static void FUZ_unitTests(int compressionLevel)
|
|||||||
memset(block, 0, blockSize);
|
memset(block, 0, blockSize);
|
||||||
((char*)dstBlock)[targetSize] = sentinel;
|
((char*)dstBlock)[targetSize] = sentinel;
|
||||||
|
|
||||||
LZ4_resetStreamHC(&sHC, 3);
|
LZ4_initStreamHC(&sHC, 3);
|
||||||
assert(blockSize < INT_MAX);
|
assert(blockSize < INT_MAX);
|
||||||
srcSize = (int)blockSize;
|
srcSize = (int)blockSize;
|
||||||
assert(targetSize < INT_MAX);
|
assert(targetSize < INT_MAX);
|
||||||
@ -1114,7 +1114,7 @@ static void FUZ_unitTests(int compressionLevel)
|
|||||||
FUZ_CHECKTEST(result!=4116, "LZ4_compress_HC_destSize() : compression must fill dstBuffer completely, but no more !");
|
FUZ_CHECKTEST(result!=4116, "LZ4_compress_HC_destSize() : compression must fill dstBuffer completely, but no more !");
|
||||||
FUZ_CHECKTEST(((char*)dstBlock)[targetSize] != sentinel, "LZ4_compress_HC_destSize()")
|
FUZ_CHECKTEST(((char*)dstBlock)[targetSize] != sentinel, "LZ4_compress_HC_destSize()")
|
||||||
|
|
||||||
LZ4_resetStreamHC(&sHC, 3); /* make sure the context is clean after the test */
|
LZ4_resetStreamHC_fast(&sHC, 3); /* make sure the context is clean after the test */
|
||||||
free(block);
|
free(block);
|
||||||
free(dstBlock);
|
free(dstBlock);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user