int LZ4_compress(const char* source, char* dest, int inputSize)
{
#if (HEAPMODE)
- void* ctx = ALLOCATOR(LZ4_DICTSIZE_U32, 4); /* Aligned on 4-bytes boundaries */
+ void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U32, 4); /* Aligned on 4-bytes boundaries */
#else
- U32 ctx[LZ4_DICTSIZE_U32] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
+ U32 ctx[LZ4_STREAMSIZE_U32] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
#endif
int result;
int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize)
{
#if (HEAPMODE)
- void* ctx = ALLOCATOR(LZ4_DICTSIZE_U32, 4); /* Aligned on 4-bytes boundaries */
+ void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U32, 4); /* Aligned on 4-bytes boundaries */
#else
- U32 ctx[LZ4_DICTSIZE_U32] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
+ U32 ctx[LZ4_STREAMSIZE_U32] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
#endif
int result;
}
-/*****************************
- User-allocated state
-*****************************/
-
-int LZ4_sizeofState() { return LZ4_DICTSIZE; }
-
-
-int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize)
-{
- if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
- MEM_INIT(state, 0, LZ4_sizeofState());
-
- if (inputSize < (int)LZ4_64KLIMIT)
- return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict);
- else
- return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict);
-}
-
-
-int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
-{
- if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
- MEM_INIT(state, 0, LZ4_sizeofState());
-
- if (inputSize < (int)LZ4_64KLIMIT)
- return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict);
- else
- return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict);
-}
-
-
/*****************************************
Experimental : Streaming functions
*****************************************/
void* LZ4_createStream()
{
- void* lz4s = ALLOCATOR(4, LZ4_DICTSIZE_U32);
- MEM_INIT(lz4s, 0, LZ4_DICTSIZE);
+ void* lz4s = ALLOCATOR(4, LZ4_STREAMSIZE_U32);
+ MEM_INIT(lz4s, 0, LZ4_STREAMSIZE);
return lz4s;
}
const BYTE* const dictEnd = p + dictSize;
const BYTE* base;
- LZ4_STATIC_ASSERT(LZ4_DICTSIZE >= sizeof(LZ4_dict_t_internal)); /* A compilation error here means LZ4_DICTSIZE is not large enough */
+ LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_dict_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */
if (dict->initCheck) MEM_INIT(dict, 0, sizeof(LZ4_dict_t_internal));
if (dictSize < MINMATCH)
// Hidden debug function, to force separate dictionary mode
-int LZ4_compress_forceExtDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize)
+int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize)
{
LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_dict;
int result;
* Note that it is essential this generic function is really inlined,
* in order to remove useless branches during compilation optimisation.
*/
-int LZ4_decompress_generic(
+static int LZ4_decompress_generic(
const char* source,
char* dest,
int inputSize,
/* Special cases */
(void)dictStart; (void)dictSize;
- if ((partialDecoding) && (oexit> oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => decode everything */
+ if ((partialDecoding) && (oexit> oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => decode everything */
if ((endOnInput) && (unlikely(outputSize==0))) return ((inputSize==1) && (*ip==0)) ? 0 : -1; /* Empty output buffer */
if ((!endOnInput) && (unlikely(outputSize==0))) return (*ip==0?1:-1);
-
/* Main Loop */
while (1)
{
if ((length=(token>>ML_BITS)) == RUN_MASK)
{
unsigned s=255;
- while (((endOnInput)?ip<iend:1) && (s==255))
- {
- s = *ip++;
- length += s;
- }
+ while (((endOnInput)?ip<iend:1) && (s==255)) { s = *ip++; length += s; }
}
/* copy literals */
/* Obsolete Streaming functions */
-int LZ4_sizeofStreamState() { return LZ4_DICTSIZE; }
+int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; }
void LZ4_init(LZ4_dict_t_internal* lz4ds, const BYTE* base)
{
- MEM_INIT(lz4ds->hashTable, 0, LZ4_DICTSIZE);
+ MEM_INIT(lz4ds->hashTable, 0, LZ4_STREAMSIZE);
lz4ds->bufferStart = base;
}
void* LZ4_create (const char* inputBuffer)
{
- void* lz4ds = ALLOCATOR(4, LZ4_DICTSIZE_U32);
+ void* lz4ds = ALLOCATOR(4, LZ4_STREAMSIZE_U32);
LZ4_init ((LZ4_dict_t_internal*)lz4ds, (const BYTE*)inputBuffer);
return lz4ds;
}
{
LZ4_dict_t_internal* lz4ds = (LZ4_dict_t_internal*)LZ4_Data;
- LZ4_moveDict((LZ4_dict_t*)LZ4_Data, (char*)lz4ds->bufferStart, 64 KB);
+ LZ4_moveDict((LZ4_stream_t*)LZ4_Data, (char*)lz4ds->bufferStart, 64 KB);
return (char*)(lz4ds->bufferStart + 64 KB);
}
+/* User-allocated state */
+
+int LZ4_sizeofState() { return LZ4_STREAMSIZE; }
+
+int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize)
+{
+ if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
+ MEM_INIT(state, 0, LZ4_sizeofState());
+
+ if (inputSize < (int)LZ4_64KLIMIT)
+ return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict);
+ else
+ return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict);
+}
+
+int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
+{
+ if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
+ MEM_INIT(state, 0, LZ4_sizeofState());
+
+ if (inputSize < (int)LZ4_64KLIMIT)
+ return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict);
+ else
+ return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict);
+}
*/
+/*
+Note :
+ Should you prefer to explicitly allocate compression-table memory using your own allocation method,
+ use the streaming functions provided below, simply reset the memory area between each call to LZ4_compress_continue()
+*/
+
+
/**************************************
Advanced Functions
**************************************/
int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxOutputSize);
-/*
-The following functions are provided should you prefer to allocate table memory using your own allocation methods.
-int LZ4_sizeofState();
-provides the size to allocate for compression tables.
-
-Tables must be aligned on 4-bytes boundaries, otherwise compression will fail (return code 0).
-
-The allocated memory can be provided to the compressions functions using 'void* state' parameter.
-LZ4_compress_withState() and LZ4_compress_limitedOutput_withState() are equivalent to previously described functions.
-They just use the externally allocated memory area instead of allocating their own one (on stack, or on heap).
-*/
-int LZ4_sizeofState(void);
-int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
-int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
-
-
/**************************************
Experimental Streaming Functions
**************************************/
-#define LZ4_DICTSIZE_U32 ((1 << (LZ4_MEMORY_USAGE-2)) + 8)
-#define LZ4_DICTSIZE (LZ4_DICTSIZE_U32 * sizeof(unsigned int))
+#define LZ4_STREAMSIZE_U32 ((1 << (LZ4_MEMORY_USAGE-2)) + 8)
+#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U32 * sizeof(unsigned int))
/*
- * LZ4_dict_t
+ * LZ4_stream_t
* information structure to track an LZ4 stream.
* set it to zero, or use LZ4_loadDict() to init it before first use.
*/
-typedef struct { unsigned int table[LZ4_DICTSIZE_U32]; } LZ4_dict_t;
+typedef struct { unsigned int table[LZ4_STREAMSIZE_U32]; } LZ4_stream_t;
/*
+ * If you prefer dynamic allocation methods,
* LZ4_createStream
- * provides a pointer (void*) towards an initialized LZ4_dict_t structure
+ * provides a pointer (void*) towards an initialized LZ4_stream_t structure.
* LZ4_free just frees it.
*/
void* LZ4_createStream();
/*
* LZ4_loadDict
- * Use this function to load a static dictionary into LZ4_dict.
- * Loading a size of 0 is allowed and init the LZ4_dict_t structure.
+ * Use this function to load a static dictionary into LZ4_stream.
+ * Loading a size of 0 is allowed and init the LZ4_stream_t structure.
* Return : 1 if OK, 0 if error
*/
int LZ4_loadDict (void* LZ4_stream, const char* dictionary, int dictSize);
Obsolete Functions
**************************************/
/*
+Obsolete decompression functions
These function names are deprecated and should no longer be used.
They are only provided here for compatibility with older user programs.
- LZ4_uncompress is the same as LZ4_decompress_fast
- LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe
*/
-int LZ4_uncompress (const char* source, char* dest, int outputSize);
-int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
+int LZ4_uncompress (const char* source, char* dest, int outputSize);
+int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
+
+/* Obsolete external allocation functions */
+int LZ4_sizeofState(void);
+int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
+int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
/* Obsolete streaming functions */
void* LZ4_create (const char* inputBuffer);
void* stateLZ4 = malloc(LZ4_sizeofState());
void* stateLZ4HC = malloc(LZ4_sizeofStateHC());
void* LZ4continue;
- LZ4_dict_t LZ4dict;
+ LZ4_stream_t LZ4dict;
U32 crcOrig, crcCheck;
int displayRefresh;
FUZ_DISPLAYTEST;
dict -= 9;
if (dict < (char*)CNBuffer) dict = (char*)CNBuffer;
- memset(&LZ4dict, 0, sizeof(LZ4_dict_t));
+ memset(&LZ4dict, 0, sizeof(LZ4_stream_t));
LZ4_loadDict(&LZ4dict, dict, dictSize);
blockContinueCompressedSize = LZ4_compress_continue(&LZ4dict, block, compressedBuffer, blockSize);
FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_usingDict failed");
FUZ_DISPLAYTEST;
- memset(&LZ4dict, 0, sizeof(LZ4_dict_t));
+ memset(&LZ4dict, 0, sizeof(LZ4_stream_t));
LZ4_loadDict(&LZ4dict, dict, dictSize);
ret = LZ4_compress_limitedOutput_continue(&LZ4dict, block, compressedBuffer, blockSize, blockContinueCompressedSize-1);
FUZ_CHECKTEST(ret>0, "LZ4_compress_limitedOutput_usingDict should fail : one missing byte for output buffer");
FUZ_DISPLAYTEST;
- memset(&LZ4dict, 0, sizeof(LZ4_dict_t));
+ memset(&LZ4dict, 0, sizeof(LZ4_stream_t));
LZ4_loadDict(&LZ4dict, dict, dictSize);
ret = LZ4_compress_limitedOutput_continue(&LZ4dict, block, compressedBuffer, blockSize, blockContinueCompressedSize);
FUZ_CHECKTEST(ret<=0, "LZ4_compress_limitedOutput_usingDict should work : enough size available within output buffer");