summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-06-09 15:46:03 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2014-06-09 15:46:03 (GMT)
commit135f11b54ea8e9c257d17514edc16d4a392a0659 (patch)
tree6c684e1483bca1d2fe7421c8ba51f57cc46f31c1
parent426e7437e10719b215dc5aeb46e48bcf90ae3831 (diff)
downloadlz4-135f11b54ea8e9c257d17514edc16d4a392a0659.zip
lz4-135f11b54ea8e9c257d17514edc16d4a392a0659.tar.gz
lz4-135f11b54ea8e9c257d17514edc16d4a392a0659.tar.bz2
Obsolete "external allocation" functions
(convergence towards LZ4_compress_continue() )
-rwxr-xr-xlz4.c91
-rw-r--r--lz4.h48
-rwxr-xr-xprograms/fullbench.c6
-rw-r--r--programs/fuzzer.c8
4 files changed, 70 insertions, 83 deletions
diff --git a/lz4.c b/lz4.c
index c264cc3..d926393 100755
--- a/lz4.c
+++ b/lz4.c
@@ -611,9 +611,9 @@ _last_literals:
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;
@@ -631,9 +631,9 @@ int LZ4_compress(const char* source, char* dest, int inputSize)
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;
@@ -649,45 +649,14 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in
}
-/*****************************
- 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;
}
@@ -705,7 +674,7 @@ int LZ4_loadDict (void* LZ4_dict, const char* dictionary, int dictSize)
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)
@@ -805,7 +774,7 @@ int LZ4_compress_limitedOutput_continue (void* LZ4_stream, const char* source, c
// 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;
@@ -854,7 +823,7 @@ int LZ4_moveDict (void* LZ4_dict, char* safeBuffer, int dictSize)
* 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,
@@ -886,11 +855,10 @@ int LZ4_decompress_generic(
/* 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)
{
@@ -902,11 +870,7 @@ int LZ4_decompress_generic(
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 */
@@ -1076,11 +1040,11 @@ int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize,
/* 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;
}
@@ -1093,7 +1057,7 @@ int LZ4_resetStreamState(void* state, const char* inputBuffer)
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;
}
@@ -1102,9 +1066,34 @@ char* LZ4_slideInputBuffer (void* LZ4_Data)
{
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);
+}
diff --git a/lz4.h b/lz4.h
index 5afc133..f2975d4 100644
--- a/lz4.h
+++ b/lz4.h
@@ -88,6 +88,13 @@ LZ4_decompress_safe() :
*/
+/*
+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
**************************************/
@@ -150,39 +157,24 @@ LZ4_decompress_safe_partial() :
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();
@@ -190,8 +182,8 @@ int LZ4_free (void* LZ4_stream);
/*
* 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);
@@ -246,13 +238,19 @@ int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int origi
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);
diff --git a/programs/fullbench.c b/programs/fullbench.c
index 23ca5b7..154de78 100755
--- a/programs/fullbench.c
+++ b/programs/fullbench.c
@@ -282,15 +282,15 @@ static int local_LZ4_compress_limitedOutput_continue(const char* in, char* out,
}
-LZ4_dict_t LZ4_dict;
+LZ4_stream_t LZ4_dict;
static void* local_LZ4_resetDictT(const char* fake)
{
(void)fake;
- memset(&LZ4_dict, 0, sizeof(LZ4_dict_t));
+ memset(&LZ4_dict, 0, sizeof(LZ4_stream_t));
return NULL;
}
-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);
static int local_LZ4_compress_forceDict(const char* in, char* out, int inSize)
{
return LZ4_compress_forceExtDict(&LZ4_dict, in, out, inSize);
diff --git a/programs/fuzzer.c b/programs/fuzzer.c
index 608340c..d209fd3 100644
--- a/programs/fuzzer.c
+++ b/programs/fuzzer.c
@@ -205,7 +205,7 @@ int FUZ_test(U32 seed, int nbCycles, int startCycle, double compressibility) {
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;
@@ -436,19 +436,19 @@ int FUZ_test(U32 seed, int nbCycles, int startCycle, double compressibility) {
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");