#define LZ4F_STATIC_ASSERT(c) { enum { LZ4F_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
-#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=2)
-# include <stdio.h>
-static int g_debuglog_enable = 1;
-# define DEBUGLOG(l, ...) { \
- if ((g_debuglog_enable) && (l<=LZ4_DEBUG)) { \
- fprintf(stderr, __FILE__ ": "); \
- fprintf(stderr, __VA_ARGS__); \
- fprintf(stderr, " \n"); \
- } }
-#else
-# define DEBUGLOG(l, ...) {} /* disabled */
-#endif
/*-************************************
* Basic Types
{
const char* dictStart = (const char*)dictBuffer;
LZ4F_CDict* cdict = (LZ4F_CDict*) malloc(sizeof(*cdict));
- DEBUGLOG(4, "LZ4F_createCDict(%p) -> %p", dictBuffer, cdict);
if (!cdict) return NULL;
if (dictSize > 64 KB) {
dictStart += dictSize - 64 KB;
void LZ4F_freeCDict(LZ4F_CDict* cdict)
{
- DEBUGLOG(4, "LZ4F_freeCDict(%p)", cdict);
if (cdict==NULL) return; /* support free on NULL */
FREEMEM(cdict->dictContent);
LZ4_freeStream(cdict->fastCtx);
static void LZ4F_applyCDict(void* ctx,
const LZ4F_CDict* cdict,
int level) {
- DEBUGLOG(5, "LZ4F_applyCDict(%p, %p)", ctx, cdict);
if (level < LZ4HC_CLEVEL_MIN) {
LZ4_resetStream_fast((LZ4_stream_t *)ctx);
LZ4_attach_dictionary((LZ4_stream_t *)ctx, cdict ? cdict->fastCtx : NULL);
BYTE* dstPtr = dstStart;
BYTE* headerStart;
- DEBUGLOG(4, "LZ4F_compressBegin_usingCDict(%p, %p)", cctxPtr, cdict);
-
if (dstCapacity < maxFHSize) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
MEM_INIT(&prefNull, 0, sizeof(prefNull));
if (preferencesPtr == NULL) preferencesPtr = &prefNull;
LZ4F_lastBlockStatus lastBlockCompressed = notDone;
compressFunc_t const compress = LZ4F_selectCompression(cctxPtr->prefs.frameInfo.blockMode, cctxPtr->prefs.compressionLevel);
- DEBUGLOG(4, "LZ4F_compressUpdate(%p, %p, %zd)", cctxPtr, srcBuffer, srcSize);
if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
if (dstCapacity < LZ4F_compressBound_internal(srcSize, &(cctxPtr->prefs), cctxPtr->tmpInSize))
BYTE* dstPtr = dstStart;
size_t const flushSize = LZ4F_flush(cctxPtr, dstBuffer, dstMaxSize, compressOptionsPtr);
-
- DEBUGLOG(4, "LZ4F_compressEnd(%p)", cctxPtr);
-
if (LZ4F_isError(flushSize)) return flushSize;
dstPtr += flushSize;
**************************************/
static void LZ4HC_clearTables (LZ4HC_CCtx_internal* hc4)
{
- DEBUGLOG(4, "LZ4HC_clearTables(%p)", hc4);
MEM_INIT((void*)hc4->hashTable, 0, sizeof(hc4->hashTable));
MEM_INIT(hc4->chainTable, 0xFF, sizeof(hc4->chainTable));
}
static void LZ4HC_init (LZ4HC_CCtx_internal* hc4, const BYTE* start)
{
uptrval startingOffset = hc4->end - hc4->base;
- DEBUGLOG(4, "LZ4HC_init(%p, %p)", hc4, start);
if (startingOffset > 1 GB) {
LZ4HC_clearTables(hc4);
startingOffset = 0;
/* allocation */
LZ4_streamHC_t* LZ4_createStreamHC(void) {
LZ4_streamHC_t* LZ4_streamHCPtr = (LZ4_streamHC_t*)malloc(sizeof(LZ4_streamHC_t));
- if (LZ4_streamHCPtr != NULL) {
- LZ4_streamHCPtr->internal_donotuse.end = (const BYTE *)(ptrdiff_t)-1;
- LZ4_streamHCPtr->internal_donotuse.base = NULL;
- LZ4_streamHCPtr->internal_donotuse.dictCtx = NULL;
- }
+ LZ4_streamHCPtr->internal_donotuse.end = (const BYTE *)(ptrdiff_t)-1;
+ LZ4_streamHCPtr->internal_donotuse.base = NULL;
+ LZ4_streamHCPtr->internal_donotuse.dictCtx = NULL;
return LZ4_streamHCPtr;
}
dictionary += dictSize - 64 KB;
dictSize = 64 KB;
}
- LZ4_resetStreamHC(LZ4_streamHCPtr, LZ4_streamHCPtr->internal_donotuse.compressionLevel);
LZ4HC_init (ctxPtr, (const BYTE*)dictionary);
+ LZ4HC_clearTables (ctxPtr);
ctxPtr->end = (const BYTE*)dictionary + dictSize;
if (dictSize >= 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3);
return dictSize;
static void LZ4HC_setExternalDict(LZ4HC_CCtx_internal* ctxPtr, const BYTE* newBlock)
{
DEBUGLOG(4, "LZ4HC_setExternalDict(%p, %p)", ctxPtr, newBlock);
- if (ctxPtr->end - ctxPtr->base - ctxPtr->nextToUpdate >= 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3); /* Referencing remaining dictionary content */
+ if (ctxPtr->end >= ctxPtr->base + 4) LZ4HC_Insert (ctxPtr, ctxPtr->end-3); /* Referencing remaining dictionary content */
/* Only one memory segment for extDict, so any previous extDict is lost at this stage */
ctxPtr->lowLimit = ctxPtr->dictLimit;