From b93f629681ad3245a09add28e4d0b2e43bcde58a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 18:31:55 +0100 Subject: changed file name --- lz4_Block_format.md | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++ lz4_block_format.txt | 121 --------------------------------------------------- 2 files changed, 121 insertions(+), 121 deletions(-) create mode 100644 lz4_Block_format.md delete mode 100644 lz4_block_format.txt diff --git a/lz4_Block_format.md b/lz4_Block_format.md new file mode 100644 index 0000000..e248fd9 --- /dev/null +++ b/lz4_Block_format.md @@ -0,0 +1,121 @@ +LZ4 Block Format Description +============================ +Last revised: 2015-03-26; +Author : Yann Collet + + + +This small specification intents to provide enough information +to anyone willing to produce LZ4-compatible compressed data blocks +using any programming language. + +LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding. +The most important design principle behind LZ4 is simplicity. +It helps to create an easy to read and maintain source code. +It also helps later on for optimizations, compactness, and speed. +There is no entropy encoder back-end nor framing layer. +The latter is assumed to be handled by other parts of the system. + +This document only describes the block format, +not how the LZ4 compressor nor decompressor actually work. +The correctness of the decompressor should not depend +on implementation details of the compressor, and vice versa. + + + +Compressed block format +----------------------- +An LZ4 compressed block is composed of sequences. +Schematically, a sequence is a suite of literals, followed by a match copy. + +Each sequence starts with a token. +The token is a one byte value, separated into two 4-bits fields. +Therefore each field ranges from 0 to 15. + + +The first field uses the 4 high-bits of the token. +It provides the length of literals to follow. +(Note : a literal is a not-compressed byte). +If the field value is 0, then there is no literal. +If it is 15, then we need to add some more bytes to indicate the full length. +Each additionnal byte then represent a value from 0 to 255, +which is added to the previous value to produce a total length. +When the byte value is 255, another byte is output. +There can be any number of bytes following the token. There is no "size limit". +(Sidenote this is why a not-compressible input block is expanded by 0.4%). + +Example 1 : A length of 48 will be represented as : +- 15 : value for the 4-bits High field +- 33 : (=48-15) remaining length to reach 48 + +Example 2 : A length of 280 will be represented as : +- 15 : value for the 4-bits High field +- 255 : following byte is maxed, since 280-15 >= 255 +- 10 : (=280 - 15 - 255) ) remaining length to reach 280 + +Example 3 : A length of 15 will be represented as : +- 15 : value for the 4-bits High field +- 0 : (=15-15) yes, the zero must be output + +Following the token and optional length bytes, are the literals themselves. +They are exactly as numerous as previously decoded (length of literals). +It's possible that there are zero literal. + + +Following the literals is the match copy operation. + +It starts by the offset. +This is a 2 bytes value, in little endian format. + +The offset represents the position of the match to be copied from. +1 means "current position - 1 byte". +The maximum offset value is 65535, 65536 cannot be coded. +Note that 0 is an invalid value, not used. + +Then we need to extract the match length. +For this, we use the second token field, the low 4-bits. +Value, obviously, ranges from 0 to 15. +However here, 0 means that the copy operation will be minimal. +The minimum length of a match, called minmatch, is 4. +As a consequence, a 0 value means 4 bytes, and a value of 15 means 19+ bytes. +Similar to literal length, on reaching the highest possible value (15), +we output additional bytes, one at a time, with values ranging from 0 to 255. +They are added to total to provide the final match length. +A 255 value means there is another byte to read and add. +There is no limit to the number of optional bytes that can be output this way. +(This points towards a maximum achievable compression ratio of ~250). + +With the offset and the matchlength, +the decoder can now proceed to copy the data from the already decoded buffer. +On decoding the matchlength, we reach the end of the compressed sequence, +and therefore start another one. + + +Parsing restrictions +----------------------- +There are specific parsing rules to respect in order to remain compatible +with assumptions made by the decoder : +1) The last 5 bytes are always literals +2) The last match must start at least 12 bytes before end of block +Consequently, a block with less than 13 bytes cannot be compressed. +These rules are in place to ensure that the decoder +will never read beyond the input buffer, nor write beyond the output buffer. + +Note that the last sequence is also incomplete, +and stops right after literals. + + +Additional notes +----------------------- +There is no assumption nor limits to the way the compressor +searches and selects matches within the source data block. +It could be a fast scan, a multi-probe, a full search using BST, +standard hash chains or MMC, well whatever. + +Advanced parsing strategies can also be implemented, such as lazy match, +or full optimal parsing. + +All these trade-off offer distinctive speed/memory/compression advantages. +Whatever the method used by the compressor, its result will be decodable +by any LZ4 decoder if it follows the format specification described above. + diff --git a/lz4_block_format.txt b/lz4_block_format.txt deleted file mode 100644 index e248fd9..0000000 --- a/lz4_block_format.txt +++ /dev/null @@ -1,121 +0,0 @@ -LZ4 Block Format Description -============================ -Last revised: 2015-03-26; -Author : Yann Collet - - - -This small specification intents to provide enough information -to anyone willing to produce LZ4-compatible compressed data blocks -using any programming language. - -LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding. -The most important design principle behind LZ4 is simplicity. -It helps to create an easy to read and maintain source code. -It also helps later on for optimizations, compactness, and speed. -There is no entropy encoder back-end nor framing layer. -The latter is assumed to be handled by other parts of the system. - -This document only describes the block format, -not how the LZ4 compressor nor decompressor actually work. -The correctness of the decompressor should not depend -on implementation details of the compressor, and vice versa. - - - -Compressed block format ------------------------ -An LZ4 compressed block is composed of sequences. -Schematically, a sequence is a suite of literals, followed by a match copy. - -Each sequence starts with a token. -The token is a one byte value, separated into two 4-bits fields. -Therefore each field ranges from 0 to 15. - - -The first field uses the 4 high-bits of the token. -It provides the length of literals to follow. -(Note : a literal is a not-compressed byte). -If the field value is 0, then there is no literal. -If it is 15, then we need to add some more bytes to indicate the full length. -Each additionnal byte then represent a value from 0 to 255, -which is added to the previous value to produce a total length. -When the byte value is 255, another byte is output. -There can be any number of bytes following the token. There is no "size limit". -(Sidenote this is why a not-compressible input block is expanded by 0.4%). - -Example 1 : A length of 48 will be represented as : -- 15 : value for the 4-bits High field -- 33 : (=48-15) remaining length to reach 48 - -Example 2 : A length of 280 will be represented as : -- 15 : value for the 4-bits High field -- 255 : following byte is maxed, since 280-15 >= 255 -- 10 : (=280 - 15 - 255) ) remaining length to reach 280 - -Example 3 : A length of 15 will be represented as : -- 15 : value for the 4-bits High field -- 0 : (=15-15) yes, the zero must be output - -Following the token and optional length bytes, are the literals themselves. -They are exactly as numerous as previously decoded (length of literals). -It's possible that there are zero literal. - - -Following the literals is the match copy operation. - -It starts by the offset. -This is a 2 bytes value, in little endian format. - -The offset represents the position of the match to be copied from. -1 means "current position - 1 byte". -The maximum offset value is 65535, 65536 cannot be coded. -Note that 0 is an invalid value, not used. - -Then we need to extract the match length. -For this, we use the second token field, the low 4-bits. -Value, obviously, ranges from 0 to 15. -However here, 0 means that the copy operation will be minimal. -The minimum length of a match, called minmatch, is 4. -As a consequence, a 0 value means 4 bytes, and a value of 15 means 19+ bytes. -Similar to literal length, on reaching the highest possible value (15), -we output additional bytes, one at a time, with values ranging from 0 to 255. -They are added to total to provide the final match length. -A 255 value means there is another byte to read and add. -There is no limit to the number of optional bytes that can be output this way. -(This points towards a maximum achievable compression ratio of ~250). - -With the offset and the matchlength, -the decoder can now proceed to copy the data from the already decoded buffer. -On decoding the matchlength, we reach the end of the compressed sequence, -and therefore start another one. - - -Parsing restrictions ------------------------ -There are specific parsing rules to respect in order to remain compatible -with assumptions made by the decoder : -1) The last 5 bytes are always literals -2) The last match must start at least 12 bytes before end of block -Consequently, a block with less than 13 bytes cannot be compressed. -These rules are in place to ensure that the decoder -will never read beyond the input buffer, nor write beyond the output buffer. - -Note that the last sequence is also incomplete, -and stops right after literals. - - -Additional notes ------------------------ -There is no assumption nor limits to the way the compressor -searches and selects matches within the source data block. -It could be a fast scan, a multi-probe, a full search using BST, -standard hash chains or MMC, well whatever. - -Advanced parsing strategies can also be implemented, such as lazy match, -or full optimal parsing. - -All these trade-off offer distinctive speed/memory/compression advantages. -Whatever the method used by the compressor, its result will be decodable -by any LZ4 decoder if it follows the format specification described above. - -- cgit v0.12 From 44793b8be9f18bb51f524b3a210de11bb0df6654 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 18:32:21 +0100 Subject: Updated documentation --- README.md | 46 +++++++++++++--------------------------------- lz4_Block_format.md | 25 ++++++++++++++----------- 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index f960e7d..275085e 100644 --- a/README.md +++ b/README.md @@ -20,41 +20,21 @@ A high compression derivative, called LZ4_HC, is also provided. It trades CPU ti Benchmarks ------------------------- -The benchmark uses the [Open-Source Benchmark program by m^2 (v0.14.2)](http://encode.ru/threads/1371-Filesystem-benchmark?p=33548&viewfull=1#post33548) compiled with GCC v4.6.1 on Linux Ubuntu 64-bits v11.10, -The reference system uses a Core i5-3340M @2.7GHz. +The benchmark uses the [Open-Source Benchmark program by m^2 (v0.14.3)](http://encode.ru/threads/1371-Filesystem-benchmark?p=33548&viewfull=1#post33548) compiled with GCC v4.8.2 on Linux Mint 64-bits v17. +The reference system uses a Core i5-4300U @1.9GHz. Benchmark evaluates the compression of reference [Silesia Corpus](http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia) in single-thread mode. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CompressorRatioCompressionDecompression
LZ4 (r101)2.084422 MB/s1820 MB/s
LZO 2.062.106414 MB/s600 MB/s
QuickLZ 1.5.1b62.237373 MB/s420 MB/s
Snappy 1.1.02.091323 MB/s1070 MB/s
LZF2.077270 MB/s570 MB/s
zlib 1.2.8 -12.73065 MB/s280 MB/s
LZ4 HC (r101)2.72025 MB/s2080 MB/s
zlib 1.2.8 -63.09921 MB/s300 MB/s
- -The LZ4 block compression format is detailed within [lz4_block_format.txt](lz4_block_format.txt). +| Compressor | Ratio | Compression | Decompression | +| ---------- | ----- | ----------- | ------------- | +|**LZ4 (r129)** | 2.101 |**385 MB/s** |**1850 MB/s** | +| LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | +| QuickLZ 1.5.1.b6 | 2.238 | 320 MB/s | 380 MB/s | +| Snappy 1.1.0 | 2.091 | 250 MB/s | 960 MB/s | +| zlib 1.2.8 -1 | 2.730 | 59 MB/s | 250 MB/s | +|**LZ4 HC (r129)** |**2.720**| 22 MB/s |**1830 MB/s** | +| zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | + +The LZ4 block compression format is detailed within [lz4_Block_format](lz4_Block_format.md). For streaming unknown amount of data and compress files of any size, a frame format has been published, and can be consulted within the file LZ4_Frame_Format.html . diff --git a/lz4_Block_format.md b/lz4_Block_format.md index e248fd9..b933a6a 100644 --- a/lz4_Block_format.md +++ b/lz4_Block_format.md @@ -1,10 +1,9 @@ LZ4 Block Format Description ============================ -Last revised: 2015-03-26; +Last revised: 2015-03-26. Author : Yann Collet - This small specification intents to provide enough information to anyone willing to produce LZ4-compatible compressed data blocks using any programming language. @@ -26,7 +25,8 @@ on implementation details of the compressor, and vice versa. Compressed block format ----------------------- An LZ4 compressed block is composed of sequences. -Schematically, a sequence is a suite of literals, followed by a match copy. +A sequence is a suite of literals (not-compressed bytes), +followed by a match copy. Each sequence starts with a token. The token is a one byte value, separated into two 4-bits fields. @@ -35,14 +35,14 @@ Therefore each field ranges from 0 to 15. The first field uses the 4 high-bits of the token. It provides the length of literals to follow. -(Note : a literal is a not-compressed byte). + If the field value is 0, then there is no literal. If it is 15, then we need to add some more bytes to indicate the full length. -Each additionnal byte then represent a value from 0 to 255, +Each additional byte then represent a value from 0 to 255, which is added to the previous value to produce a total length. When the byte value is 255, another byte is output. There can be any number of bytes following the token. There is no "size limit". -(Sidenote this is why a not-compressible input block is expanded by 0.4%). +(Side note : this is why a not-compressible input block is expanded by 0.4%). Example 1 : A length of 48 will be represented as : - 15 : value for the 4-bits High field @@ -65,7 +65,8 @@ It's possible that there are zero literal. Following the literals is the match copy operation. It starts by the offset. -This is a 2 bytes value, in little endian format. +This is a 2 bytes value, in little endian format +(the 1st byte is the "low" byte, the 2nd one is the "high" byte). The offset represents the position of the match to be copied from. 1 means "current position - 1 byte". @@ -95,9 +96,12 @@ Parsing restrictions ----------------------- There are specific parsing rules to respect in order to remain compatible with assumptions made by the decoder : -1) The last 5 bytes are always literals -2) The last match must start at least 12 bytes before end of block -Consequently, a block with less than 13 bytes cannot be compressed. + +1. The last 5 bytes are always literals +2. The last match must start at least 12 bytes before end of block. + + Consequently, a block with less than 13 bytes cannot be compressed. + These rules are in place to ensure that the decoder will never read beyond the input buffer, nor write beyond the output buffer. @@ -118,4 +122,3 @@ or full optimal parsing. All these trade-off offer distinctive speed/memory/compression advantages. Whatever the method used by the compressor, its result will be decodable by any LZ4 decoder if it follows the format specification described above. - -- cgit v0.12 From 6c69dc176c318fba721fa8adade53f3e413cac52 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 18:34:15 +0100 Subject: faster compression in 64 bits mode --- lib/lz4.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/lz4.c b/lib/lz4.c index 881d1af..2a1ae57 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -464,7 +464,24 @@ static U32 LZ4_hashSequence(U32 sequence, tableType_t const tableType) return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG)); } -static U32 LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(LZ4_read32(p), tableType); } +static const U64 prime5bytes = 889523592379ULL; +static U32 LZ4_hashSequence64(size_t sequence, tableType_t const tableType) +{ + const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG; + const U32 hashMask = (1<> (40 - hashLog)) & hashMask; +} + +static U32 LZ4_hashSequenceT(size_t sequence, tableType_t const tableType) +{ + if (LZ4_64bits()) + return LZ4_hashSequence64(sequence, tableType); + return LZ4_hashSequence((U32)sequence, tableType); +} + +static U32 LZ4_hashPosition(const void* p, tableType_t tableType) { return LZ4_hashSequenceT(LZ4_read_ARCH(p), tableType); } + +//static U32 LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(LZ4_read32(p), tableType); } static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase) { -- cgit v0.12 From 2a826193110e5423e7dedcaa78ddb7c1aa1f0950 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 18:39:29 +0100 Subject: fixed fullbench memory allocation error --- programs/fullbench.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/programs/fullbench.c b/programs/fullbench.c index 0c6e05e..6c42ed0 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -544,7 +544,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) return 10; } - // Loop for each file + /* Loop for each fileName */ while (fileIdx inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) @@ -940,7 +940,7 @@ _exit_blockProperties: // Modify Nb Iterations case 'i': - if ((argument[1] >='1') && (argument[1] <='9')) + if ((argument[1] >='0') && (argument[1] <='9')) { int iters = argument[1] - '0'; BMK_SetNbIterations(iters); -- cgit v0.12 From 4c227a487e25c175d98a320386c96dbea6628216 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 21:32:25 +0100 Subject: Added LZ4_compress_fast() --- lib/lz4.c | 90 +++++++++++++++++++++++++++++++++++++--------------- lib/lz4.h | 10 ++++++ programs/fullbench.c | 68 ++++++++++++++++++++------------------- 3 files changed, 109 insertions(+), 59 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 2a1ae57..c8bde3a 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -44,6 +44,12 @@ #define HEAPMODE 0 /* + * ACCELERATION_DEFAULT : + * Select the value of "acceleration" for LZ4_compress_fast() when parameter == 0 + */ +#define ACCELERATION_DEFAULT 17 + +/* * CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS : * By default, the source code expects the compiler to correctly optimize * 4-bytes and 8-bytes read on architectures able to handle it efficiently. @@ -513,15 +519,16 @@ static const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t t } static int LZ4_compress_generic( - void* ctx, - const char* source, - char* dest, - int inputSize, - int maxOutputSize, - limitedOutput_directive outputLimited, - tableType_t const tableType, - dict_directive dict, - dictIssue_directive dictIssue) + void* const ctx, + const char* const source, + char* const dest, + const int inputSize, + const int maxOutputSize, + const limitedOutput_directive outputLimited, + const tableType_t tableType, + const dict_directive dict, + const dictIssue_directive dictIssue, + const U32 acceleration) { LZ4_stream_t_internal* const dictPtr = (LZ4_stream_t_internal*)ctx; @@ -544,7 +551,7 @@ static int LZ4_compress_generic( size_t refDelta=0; /* Init conditions */ - if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ + if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ switch(dict) { case noDict: @@ -576,14 +583,14 @@ static int LZ4_compress_generic( { const BYTE* forwardIp = ip; unsigned step=1; - unsigned searchMatchNb = (1U << LZ4_skipTrigger); + unsigned searchMatchNb = ((1+acceleration) << LZ4_skipTrigger); /* Find a match */ do { U32 h = forwardH; ip = forwardIp; forwardIp += step; - step = searchMatchNb++ >> LZ4_skipTrigger; + step = (searchMatchNb++ >> LZ4_skipTrigger); if (unlikely(forwardIp > mflimit)) goto _last_literals; @@ -724,7 +731,7 @@ _last_literals: } -int LZ4_compress(const char* source, char* dest, int inputSize) +int LZ4_compress(const char* source, char* dest, const int inputSize) { #if (HEAPMODE) void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ @@ -734,9 +741,9 @@ int LZ4_compress(const char* source, char* dest, int inputSize) int result; if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 0); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); #if (HEAPMODE) FREEMEM(ctx); @@ -754,9 +761,40 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in int result; if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 0); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); + +#if (HEAPMODE) + FREEMEM(ctx); +#endif + return result; +} + + +int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +{ +#if (HEAPMODE) + void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ +#else + U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ +#endif + int result; + + if (acceleration == 0) + { + if (inputSize < LZ4_64Klimit) + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); + else + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); + } + else + { + if (inputSize < LZ4_64Klimit) + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + else + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); + } #if (HEAPMODE) FREEMEM(ctx); @@ -875,9 +913,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall, 0); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue, 0); streamPtr->dictSize += (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; return result; @@ -887,9 +925,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall, 0); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue, 0); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; @@ -919,7 +957,7 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; LZ4_renormDictT((LZ4_stream_t_internal*)LZ4_dict, smallest); - result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue); + result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 0); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; @@ -1352,9 +1390,9 @@ int LZ4_compress_withState (void* state, const char* source, char* dest, int inp MEM_INIT(state, 0, LZ4_STREAMSIZE); if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 0); else - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); } int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize) @@ -1363,9 +1401,9 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* MEM_INIT(state, 0, LZ4_STREAMSIZE); if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 0); else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); } /* Obsolete streaming decompression functions */ diff --git a/lib/lz4.h b/lib/lz4.h index de43fc0..eabc40f 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -130,6 +130,16 @@ int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, /* +LZ4_compress_fast() : + Same as LZ4_compress_limitedOutput, but allows to select an "acceleration" factor. + The larger the value, the faster the algorithm, but also the lesser the compression. + So it's a trade-off, which can be fine tuned, selecting whichever value you want. + An acceleration value of "0" means "use Default value", which is typically about 15 (see lz4.c source code). +*/ +int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); + + +/* LZ4_compress_withState() : Same compression functions, but using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, diff --git a/programs/fullbench.c b/programs/fullbench.c index 6c42ed0..cd6e3c8 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -146,9 +146,9 @@ struct chunkParameters -//************************************** -// Benchmark Parameters -//************************************** +/************************************** +* Benchmark Parameters +**************************************/ static int chunkSize = DEFAULT_CHUNKSIZE; static int nbIterations = NBLOOPS; static int BMK_pause = 0; @@ -175,17 +175,17 @@ void BMK_SetPause(void) BMK_pause = 1; } -//********************************************************* -// Private functions -//********************************************************* +/********************************************************* +* Private functions +*********************************************************/ #if defined(BMK_LEGACY_TIMER) static int BMK_GetMilliStart(void) { - // Based on Legacy ftime() - // Rolls over every ~ 12.1 days (0x100000/24/60/60) - // Use GetMilliSpan to correct for rollover + /* Based on Legacy ftime() + * Rolls over every ~ 12.1 days (0x100000/24/60/60) + * Use GetMilliSpan to correct for rollover */ struct timeb tb; int nCount; ftime( &tb ); @@ -197,8 +197,8 @@ static int BMK_GetMilliStart(void) static int BMK_GetMilliStart(void) { - // Based on newer gettimeofday() - // Use GetMilliSpan to correct for rollover + /* Based on newer gettimeofday() + * Use GetMilliSpan to correct for rollover */ struct timeval tv; int nCount; gettimeofday(&tv, NULL); @@ -386,6 +386,11 @@ static int local_LZ4_compress_limitedOutput(const char* in, char* out, int inSiz return LZ4_compress_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)); } +static int local_LZ4_compress_fast(const char* in, char* out, int inSize) +{ + return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 0); +} + static void* stateLZ4; static int local_LZ4_compress_withState(const char* in, char* out, int inSize) { @@ -530,7 +535,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) { int fileIdx=0; char* orig_buff; -# define NB_COMPRESSION_ALGORITHMS 16 +# define NB_COMPRESSION_ALGORITHMS 17 double totalCTime[NB_COMPRESSION_ALGORITHMS+1] = {0}; double totalCSize[NB_COMPRESSION_ALGORITHMS+1] = {0}; # define NB_DECOMPRESSION_ALGORITHMS 9 @@ -568,22 +573,18 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) return 11; } - /* Init */ - stateLZ4 = LZ4_createStream(); - stateLZ4HC = LZ4_createStreamHC(); - - /* Memory allocation & restrictions */ + /* Memory size adjustments */ inFileSize = BMK_GetFileSize(inFileName); if (inFileSize==0) { DISPLAY( "file is empty\n"); return 11; } - benchedSize = (size_t) BMK_findMaxMem(inFileSize); + benchedSize = (size_t) BMK_findMaxMem(inFileSize*2) / 2; /* because 2 buffers */ if (benchedSize==0) { DISPLAY( "not enough memory\n"); return 11; } if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) - { DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); - } - // Alloc + /* Allocation */ + stateLZ4 = LZ4_createStream(); + stateLZ4HC = LZ4_createStreamHC(); chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters)); orig_buff = (char*) malloc((size_t)benchedSize); nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); @@ -602,7 +603,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) return 12; } - // Fill input buffer + /* Fill in src buffer */ DISPLAY("Loading %s... \r", inFileName); readSize = fread(orig_buff, 1, benchedSize, inFile); fclose(inFile); @@ -664,20 +665,21 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) case 4 : compressionFunction = local_LZ4_compress_limitedOutput_withState; compressorName = "LZ4_compress_limitedOutput_withState"; break; case 5 : compressionFunction = local_LZ4_compress_continue; initFunction = LZ4_create; compressorName = "LZ4_compress_continue"; break; case 6 : compressionFunction = local_LZ4_compress_limitedOutput_continue; initFunction = LZ4_create; compressorName = "LZ4_compress_limitedOutput_continue"; break; - case 7 : compressionFunction = LZ4_compressHC; compressorName = "LZ4_compressHC"; break; - case 8 : compressionFunction = local_LZ4_compressHC_limitedOutput; compressorName = "LZ4_compressHC_limitedOutput"; break; - case 9 : compressionFunction = local_LZ4_compressHC_withStateHC; compressorName = "LZ4_compressHC_withStateHC"; break; - case 10: compressionFunction = local_LZ4_compressHC_limitedOutput_withStateHC; compressorName = "LZ4_compressHC_limitedOutput_withStateHC"; break; - case 11: compressionFunction = local_LZ4_compressHC_continue; initFunction = LZ4_createHC; compressorName = "LZ4_compressHC_continue"; break; - case 12: compressionFunction = local_LZ4_compressHC_limitedOutput_continue; initFunction = LZ4_createHC; compressorName = "LZ4_compressHC_limitedOutput_continue"; break; - case 13: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break; - case 14: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame"; + case 7 : compressionFunction = local_LZ4_compress_fast; compressorName = "LZ4_compress_fast"; break; + case 8 : compressionFunction = LZ4_compressHC; compressorName = "LZ4_compressHC"; break; + case 9 : compressionFunction = local_LZ4_compressHC_limitedOutput; compressorName = "LZ4_compressHC_limitedOutput"; break; + case 10 : compressionFunction = local_LZ4_compressHC_withStateHC; compressorName = "LZ4_compressHC_withStateHC"; break; + case 11: compressionFunction = local_LZ4_compressHC_limitedOutput_withStateHC; compressorName = "LZ4_compressHC_limitedOutput_withStateHC"; break; + case 12: compressionFunction = local_LZ4_compressHC_continue; initFunction = LZ4_createHC; compressorName = "LZ4_compressHC_continue"; break; + case 13: compressionFunction = local_LZ4_compressHC_limitedOutput_continue; initFunction = LZ4_createHC; compressorName = "LZ4_compressHC_limitedOutput_continue"; break; + case 14: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break; + case 15: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame"; chunkP[0].origSize = (int)benchedSize; nbChunks=1; break; - case 15: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict"; + case 16: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict"; LZ4_loadDict(&LZ4_dict, chunkP[0].origBuffer, chunkP[0].origSize); break; - case 16: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC"; + case 17: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC"; LZ4_loadDictHC(&LZ4_dictHC, chunkP[0].origBuffer, chunkP[0].origSize); break; default : DISPLAY("ERROR ! Bad algorithm Id !! \n"); free(chunkP); return 1; @@ -724,7 +726,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) totalCSize[cAlgNb] += cSize; } - // Prepare layout for decompression + /* Prepare layout for decompression */ // Init data chunks { int i; -- cgit v0.12 From 4783cb8c57f890211f0c57c78c7e378c4a97075b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 21:38:37 +0100 Subject: Updated readme --- NEWS | 3 +++ README.md | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 2eeb948..d80b138 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +r129: +Added : LZ4_compress_fast() + r128: New : lz4cli sparse file support New : command -m, to compress multiple files in a single command diff --git a/README.md b/README.md index 275085e..f808010 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,19 @@ Benchmark evaluates the compression of reference [Silesia Corpus](http://sun.aei | Compressor | Ratio | Compression | Decompression | | ---------- | ----- | ----------- | ------------- | -|**LZ4 (r129)** | 2.101 |**385 MB/s** |**1850 MB/s** | -| LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | -| QuickLZ 1.5.1.b6 | 2.238 | 320 MB/s | 380 MB/s | -| Snappy 1.1.0 | 2.091 | 250 MB/s | 960 MB/s | -| zlib 1.2.8 -1 | 2.730 | 59 MB/s | 250 MB/s | -|**LZ4 HC (r129)** |**2.720**| 22 MB/s |**1830 MB/s** | -| zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | +| memcpy | 1.000 | 4200 MB/s | 4200 MB/s | +| RLE64 v3.0 | 1.029 | 2800 MB/s | 2800 MB/s | +| density -c1 | 1.592 | 700 MB/s | 920 MB/s | +|**LZ4 fast (r129)**| 1.595 |**680 MB/s** | **2220 MB/s** | +|**LZ4 (r129)** |**2.101**|**385 MB/s** | **1850 MB/s** | +| density -c2 | 2.083 | 370 MB/s | 505 MB/s | +| LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | +| QuickLZ 1.5.1.b6 | 2.238 | 320 MB/s | 380 MB/s | +| Snappy 1.1.0 | 2.091 | 250 MB/s | 960 MB/s | +| density -c3 | 2.370 | 190 MB/s | 185 MB/s | +| zlib 1.2.8 -1 | 2.730 | 59 MB/s | 250 MB/s | +|**LZ4 HC (r129)** |**2.720**| 22 MB/s | **1830 MB/s** | +| zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | The LZ4 block compression format is detailed within [lz4_Block_format](lz4_Block_format.md). -- cgit v0.12 From 5b9fb6971522514ffc02366a32533facfd03c528 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 30 Mar 2015 22:39:08 +0100 Subject: minor tweak --- README.md | 2 +- lib/lz4.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f808010..0f2cd40 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Benchmark evaluates the compression of reference [Silesia Corpus](http://sun.aei | memcpy | 1.000 | 4200 MB/s | 4200 MB/s | | RLE64 v3.0 | 1.029 | 2800 MB/s | 2800 MB/s | | density -c1 | 1.592 | 700 MB/s | 920 MB/s | -|**LZ4 fast (r129)**| 1.595 |**680 MB/s** | **2220 MB/s** | +|**LZ4 fast (r129)**| 1.607 |**680 MB/s** | **2220 MB/s** | |**LZ4 (r129)** |**2.101**|**385 MB/s** | **1850 MB/s** | | density -c2 | 2.083 | 370 MB/s | 505 MB/s | | LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | diff --git a/lib/lz4.c b/lib/lz4.c index c8bde3a..cd6147f 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -583,7 +583,7 @@ static int LZ4_compress_generic( { const BYTE* forwardIp = ip; unsigned step=1; - unsigned searchMatchNb = ((1+acceleration) << LZ4_skipTrigger); + unsigned searchMatchNb = ((acceleration) << LZ4_skipTrigger); /* Find a match */ do { @@ -741,9 +741,9 @@ int LZ4_compress(const char* source, char* dest, const int inputSize) int result; if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 0); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); #if (HEAPMODE) FREEMEM(ctx); @@ -761,9 +761,9 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in int result; if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 0); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); #if (HEAPMODE) FREEMEM(ctx); @@ -913,9 +913,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall, 0); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall, 1); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue, 0); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue, 1); streamPtr->dictSize += (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; return result; @@ -925,9 +925,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall, 0); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall, 1); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue, 0); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue, 1); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; @@ -957,7 +957,7 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; LZ4_renormDictT((LZ4_stream_t_internal*)LZ4_dict, smallest); - result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 0); + result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 1); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; @@ -1390,9 +1390,9 @@ int LZ4_compress_withState (void* state, const char* source, char* dest, int inp MEM_INIT(state, 0, LZ4_STREAMSIZE); if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 0); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); else - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); } int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize) @@ -1401,9 +1401,9 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* MEM_INIT(state, 0, LZ4_STREAMSIZE); if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 0); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 0); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); } /* Obsolete streaming decompression functions */ -- cgit v0.12 From 880381c11bc9838b8609643dff64044fca8856e2 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 09:42:44 +0100 Subject: Removed HTML Frame Format documentation --- LZ4_Frame_Format.html | 1 - images/image00.png | Bin 2908 -> 0 bytes images/image01.png | Bin 5793 -> 0 bytes images/image02.png | Bin 6246 -> 0 bytes images/image03.png | Bin 4089 -> 0 bytes images/image04.png | Bin 3121 -> 0 bytes images/image05.png | Bin 4166 -> 0 bytes images/image06.png | Bin 8028 -> 0 bytes 8 files changed, 1 deletion(-) delete mode 100644 LZ4_Frame_Format.html delete mode 100644 images/image00.png delete mode 100644 images/image01.png delete mode 100644 images/image02.png delete mode 100644 images/image03.png delete mode 100644 images/image04.png delete mode 100644 images/image05.png delete mode 100644 images/image06.png diff --git a/LZ4_Frame_Format.html b/LZ4_Frame_Format.html deleted file mode 100644 index 6622dbb..0000000 --- a/LZ4_Frame_Format.html +++ /dev/null @@ -1 +0,0 @@ -LZ4 Framing format - v1.5.0

LZ4 Framing Format


Notices

Copyright (c) 2013-2015 Yann Collet

Permission is granted to copy and distribute this document for any  purpose and without charge, including translations into other  languages and incorporation into compilations, provided that the copyright notice and this notice are preserved, and that any substantive changes or deletions from the original are clearly marked.

Version

1.5.0

Introduction

The purpose of this document is to define a lossless compressed data format, that is independent of CPU type, operating system, file system and character set, suitable for File compression, Pipe and streaming compression using the LZ4 algorithm : http://code.google.com/p/lz4/

The data can be produced or consumed, even for an arbitrarily long sequentially presented input data stream, using only an a priori bounded amount of intermediate storage, and hence can be used in data communications.  The format uses the LZ4 compression method, and optional xxHash-32 checksum method, for detection of data corruption.

The data format defined by this specification does not attempt to allow random access to compressed data.

This specification is intended for use by implementers of software to compress data into LZ4 format and/or decompress data from LZ4 format. The text of the specification assumes a basic background in programming at the level of bits and other primitive data representations.

Unless otherwise indicated below, a compliant compressor must produce data sets that conform to the specifications presented here. It doesn’t need to support all options though.

A compliant decompressor must be able to decompress at least one working set of parameters that conforms to the specifications presented here. It may also ignore checksums. Whenever it does not support a specific parameter used within the compressed stream, it must produce a non-ambiguous error code and associated error message explaining which parameter is unsupported.

Distribution of this document is unlimited.


Summary :

Introduction

General structure of LZ4 Framing Format

Frame Descriptor

Data Blocks

Skippable Frames

Legacy format

Appendix


General Structure of LZ4 Framing format

Magic Number

4 Bytes, Little endian format.
Value :
0x184D2204

Frame Descriptor

3 to 11 Bytes, to be detailed in the next part.
Most important part of the spec.

Data Blocks

To be detailed later on.
That’s where compressed data is stored.

EndMark

The flow of blocks ends when the last data block has a size of “0”.
The size is expressed as a 32-bits value.

Content Checksum

Content Checksum verify that the full content has been decoded correctly.
The content checksum is the result of
xxh32() hash function digesting the original (decoded) data as input, and a seed of zero.
Content checksum is only present when its
associated flag is set in the framing descriptor. Content Checksum validates the result, that all blocks were fully transmitted in the correct order and without error, and also that the encoding/decoding process itself generated no distortion. Its usage is recommended.

Frame Concatenation

In some circumstances, it may be preferable to append multiple frames, for example in order to add new data to an existing compressed file without re-framing it.

In such case, each frame has its own set of descriptor flags. Each frame is considered independent. The only relation between frames is their sequential order.

The ability to decode multiple concatenated frames within a single stream or file is left outside of this specification. As an example, the reference lz4 command line utility behavior is to decode all concatenated frames in their sequential order.


Frame Descriptor

The descriptor uses a minimum of 3 bytes, and up to 11 bytes depending on optional parameters.
In the picture, bit 7 is highest bit, while bit 0 is lowest.

Version Number :

2-bits field, must be set to “01”.
Any other value cannot be decoded by this
version of the specification.
Other version numbers will use different flag layouts.

Block Independence flag :

If this flag is set to “1”, blocks are independent, and can therefore be decoded independently, in parallel.
If this flag is set to “
0”, each block depends on previous ones for decoding (up to LZ4 window size, which is 64 KB). In this case, it’s necessary to decode all blocks in sequence.

Block dependency improves compression ratio, especially for small blocks. On the other hand, it makes jumps or multi-threaded decoding impossible.

Block checksum flag :

If this flag is set, each data block will be followed by a 4-bytes checksum, calculated by using the xxHash-32 algorithm on the raw (compressed) data block.
The intention is to detect data corruption (storage or transmission errors) immediately, before decoding.
Block ch
ecksum usage is optional.

Content Size flag :

If this flag is set, the original (uncompressed) size of data included within the frame will be present as an 8 bytes unsigned value, little endian format, after the flags.

Recommended value : “0” (not present)

Content checksum flag :

If this flag is set, a content checksum will be appended after the EoS mark.

Recommended value : “1” (content checksum is present)

Block Maximum Size :

This information is intended to help the decoder allocate the right amount of memory.
Size here refers to the original (uncompressed) data size.
Block Maximum Size
is one value among the following table :

The decoder may refuse to allocate block sizes above a (system-specific) size.
Unused values may be used in a future revision of the spec.
A decoder conformant to the current version of the spec is only able to decode blocksizes defined in this spec.

Reserved bits :

Value of reserved bits must be 0 (zero).
Reserved bit might be used in a future version of the specification, to enable any (yet-to-decide) optional feature.
If this happens, a decoder respecting the current version of the specification shall not be able to decode such a frame.

Content Size

This is the original (uncompressed) size.
This information is optional, and only present if the
associated flag is set.
Content size is provided using unsigned 8 Bytes, for a maximum of 16 HexaBytes.
Format is Little endian.
This field has no impact on decoding, it just informs the decoder how much data the frame holds (for example, to display it during decoding process, or for verification purpose). It can be safely skipped by a conformant decoder.

Header Checksum :

One-byte checksum of all descriptor fields, including optional ones when present.
The byte is second byte of
xxh32() : { (xxh32()>>8) & 0xFF } ,
using zero as a seed,
and the full Frame Descriptor as an input (
including optional fields when they are present).
A different checksum indicates an error in the descriptor.


Data Blocks

Block Size

This field uses 4-bytes,  format is little-endian.

The highest bit is “1” if data in the block is uncompressed.

The highest bit is “0” if data in the block is compressed by LZ4.

All other bits give the size, in bytes, of the following data block (the size does not include the checksum if present).

Block Size shall never be larger than Block Maximum Size. Such a thing could happen when the original data is incompressible. In this case, such a data block shall be passed in uncompressed format.

Data

Where the actual data to decode stands. It might be compressed or not, depending on previous field indications.
Uncompressed size of Data can be any size, up to “block maximum size”.
Note that data block is not necessarily
full : an arbitrary “flush” may happen anytime. Any block can be “partially filled”.

Block checksum :

Only present if the associated flag is set.
This is a 4-bytes checksum value, in little endian format,
calculated by using the xxHash-32 algorithm
on the raw (undecoded) data block,
and a seed of zero.

The intention is to detect data corruption (storage or transmission errors)
before decoding.

Block checksum is cumulative with Content checksum.


Skippable Frames

LZ4 Framing Format - Skippable Frame.png

Skippable frames allow the integration of user-defined data into a flow of concatenated frames.
Its design is pretty straightforward, with the sole objective to allow the decoder to quickly skip over user-defined data and continue decoding.

For the purpose of facilitating identification, it is discouraged to start a flow of concatenated frames with a skippable frame. If there is a need to start such a flow with some user data encapsulated into a skippable frame, it’s recommended to start will a zero-byte LZ4 frame followed by a skippable frame. This will make it easier for file type identifiers.

 

Magic Number

4 Bytes, Little endian format.
Value :
0x184D2A5X, which means any value from 0x184D2A50 to 0x184D2A5F. All 16 values are valid to identify a skippable frame.

Frame Size 

This is the size, in bytes, of the following User Data (without including the magic number nor the size field itself).
4 Bytes,
Little endian format, unsigned 32-bits.
This means User Data can’t be bigger than (2^32-1) Bytes.

User Data

User Data can be anything. Data will just be skipped by the decoder.


Legacy frame

The Legacy frame format was defined into the initial versions of “LZ4Demo”.
Newer compressors should not use this format anymore, since it is too restrictive.
It is recommended that decompressors shall be able to decode this format during the transition period.

Main properties of legacy format :
- Fixed block size :
8 MB.
- All blocks must be completely filled, except the last one.
- All blocks are always compressed, even when compression is detri
mental.
- The last block is detected either because it is followed by the “EOF” (End of File) mark
, or because it is followed by a known Frame Magic Number.
- No checksum
- Convention is Little endian

Magic Number

4 Bytes, Little endian format.
Value :
0x184C2102

Block Compressed Size

This is the size, in bytes, of the following compressed data block.
4 Bytes,
Little endian format.

Data

Where the actual data stands.
Data is
always compressed, even when compression is detrimental (i.e. larger than original size).


Appendix  

Version changes

1.4.1 : changed wording from “stream” to “frame”

1.4 : added skippable streams, re-added stream checksum

1.3 : modified header checksum

1.2 : reduced choice of “block size”, to postpone decision on “dynamic size of BlockSize Field”.

1.1 : optional fields are now part of the descriptor

1.0 : changed “block size” specification, adding a compressed/uncompressed flag

0.9 : reduced scale of “block maximum size” table

0.8 : removed : high compression flag

0.7 : removed : stream checksum

0.6 : settled : stream size uses 8 bytes, endian convention is little endian

0.5: added copyright notice

0.4 : changed format to Google Doc compatible OpenDocument

\ No newline at end of file diff --git a/images/image00.png b/images/image00.png deleted file mode 100644 index f4645f2..0000000 Binary files a/images/image00.png and /dev/null differ diff --git a/images/image01.png b/images/image01.png deleted file mode 100644 index 661c465..0000000 Binary files a/images/image01.png and /dev/null differ diff --git a/images/image02.png b/images/image02.png deleted file mode 100644 index a909353..0000000 Binary files a/images/image02.png and /dev/null differ diff --git a/images/image03.png b/images/image03.png deleted file mode 100644 index 8e1b40c..0000000 Binary files a/images/image03.png and /dev/null differ diff --git a/images/image04.png b/images/image04.png deleted file mode 100644 index e82d02b..0000000 Binary files a/images/image04.png and /dev/null differ diff --git a/images/image05.png b/images/image05.png deleted file mode 100644 index 3a8006a..0000000 Binary files a/images/image05.png and /dev/null differ diff --git a/images/image06.png b/images/image06.png deleted file mode 100644 index 69b4ee6..0000000 Binary files a/images/image06.png and /dev/null differ -- cgit v0.12 From f17496423cb7ca9be9d9d855fefcf78fbb70439a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 09:44:56 +0100 Subject: Added : Frame documentation in MarkDown format --- NEWS | 3 +- README.md | 38 ++++-- lz4_Frame_format.md | 385 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 10 deletions(-) mode change 100644 => 100755 README.md create mode 100755 lz4_Frame_format.md diff --git a/NEWS b/NEWS index d80b138..b692b8d 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ r129: -Added : LZ4_compress_fast() +Added : LZ4_compress_fast() +Updated: Documentation converted to MarkDown r128: New : lz4cli sparse file support diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 0f2cd40..69f7397 --- a/README.md +++ b/README.md @@ -1,8 +1,15 @@ LZ4 - Extremely fast compression ================================ -LZ4 is lossless compression algorithm, providing compression speed at 400 MB/s per core, scalable with multi-cores CPU. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems. -A high compression derivative, called LZ4_HC, is also provided. It trades CPU time for compression ratio. +LZ4 is lossless compression algorithm, +providing compression speed at 400 MB/s per core, +scalable with multi-cores CPU. +It also features an extremely fast decoder, +with speed in multiple GB/s per core, +typically reaching RAM speed limits on multi-core systems. + +A high compression derivative, called LZ4_HC, is also provided. +It trades CPU time for compression ratio. |Branch |Status | |------------|---------| @@ -13,16 +20,21 @@ A high compression derivative, called LZ4_HC, is also provided. It trades CPU ti > **Branch Policy:** > - The "master" branch is considered stable, at all times. -> - The "dev" branch is the one where all contributions must be merged before being promoted to master. -> - If you plan to propose a patch, please commit into the "dev" branch. Direct commit to "master" are not permitted. -> - Feature branches can also exist, for dedicated testing of larger modifications before merge into "dev" branch. +> - The "dev" branch is the one where all contributions must be merged + before being promoted to master. +> + If you plan to propose a patch, please commit into the "dev" branch. + Direct commit to "master" are not permitted. +> - Feature branches can also exist, + for dedicated tests of larger modifications before merge into "dev" branch. Benchmarks ------------------------- -The benchmark uses the [Open-Source Benchmark program by m^2 (v0.14.3)](http://encode.ru/threads/1371-Filesystem-benchmark?p=33548&viewfull=1#post33548) compiled with GCC v4.8.2 on Linux Mint 64-bits v17. +The benchmark uses the [Open-Source Benchmark program by m^2 (v0.14.3)] +compiled with GCC v4.8.2 on Linux Mint 64-bits v17. The reference system uses a Core i5-4300U @1.9GHz. -Benchmark evaluates the compression of reference [Silesia Corpus](http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia) in single-thread mode. +Benchmark evaluates the compression of reference [Silesia Corpus] +in single-thread mode. | Compressor | Ratio | Compression | Decompression | | ---------- | ----- | ----------- | ------------- | @@ -40,7 +52,15 @@ Benchmark evaluates the compression of reference [Silesia Corpus](http://sun.aei |**LZ4 HC (r129)** |**2.720**| 22 MB/s | **1830 MB/s** | | zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | -The LZ4 block compression format is detailed within [lz4_Block_format](lz4_Block_format.md). +The LZ4 block compression format is detailed within [lz4_Block_format]. -For streaming unknown amount of data and compress files of any size, a frame format has been published, and can be consulted within the file LZ4_Frame_Format.html . +Block format doesn't deal with header information, +nor how to handle arbitrarily long files or data streams. +This is the purpose of the Frame format. +Interoperable versions of LZ4 should use the same frame format, +defined into [lz4_Frame_format]. +[Open-Source Benchmark program by m^2 (v0.14.3)]: http://encode.ru/threads/1371-Filesystem-benchmark?p=34029&viewfull=1#post34029 +[Silesia Corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia +[lz4_Block_format]: lz4_Block_format.md +[lz4_Frame_format]: lz4_Frame_format.md \ No newline at end of file diff --git a/lz4_Frame_format.md b/lz4_Frame_format.md new file mode 100755 index 0000000..55edaa0 --- /dev/null +++ b/lz4_Frame_format.md @@ -0,0 +1,385 @@ +LZ4 Frame Format Description +============================ + +###Notices + +Copyright (c) 2013-2015 Yann Collet + +Permission is granted to copy and distribute this document +for any purpose and without charge, +including translations into other languages +and incorporation into compilations, +provided that the copyright notice and this notice are preserved, +and that any substantive changes or deletions from the original +are clearly marked. +Distribution of this document is unlimited. + +###Version + +1.5.1 (31/03/2015) + + +Introduction +------------ + +The purpose of this document is to define a lossless compressed data format, +that is independent of CPU type, operating system, +file system and character set, suitable for +File compression, Pipe and streaming compression +using the [LZ4 algorithm](http://www.lz4.info). + +The data can be produced or consumed, +even for an arbitrarily long sequentially presented input data stream, +using only an a priori bounded amount of intermediate storage, +and hence can be used in data communications. +The format uses the LZ4 compression method, +and optional [xxHash-32 checksum method](https://github.com/Cyan4973/xxHash), +for detection of data corruption. + +The data format defined by this specification +does not attempt to allow random access to compressed data. + +This specification is intended for use by implementers of software +to compress data into LZ4 format and/or decompress data from LZ4 format. +The text of the specification assumes a basic background in programming +at the level of bits and other primitive data representations. + +Unless otherwise indicated below, +a compliant compressor must produce data sets +that conform to the specifications presented here. +It doesn’t need to support all options though. + +A compliant decompressor must be able to decompress +at least one working set of parameters +that conforms to the specifications presented here. +It may also ignore checksums. +Whenever it does not support a specific parameter within the compressed stream, +it must produce a non-ambiguous error code +and associated error message explaining which parameter is unsupported. + + +General Structure of LZ4 Frame format +------------------------------------- + +| MagicNb | F. Descriptor | Block | (...) | EndMark | C. Checksum | +|:-------:|:-------------:| ----- | ----- | ------- | ----------- | +| 4 bytes | 3-11 bytes | | | 4 bytes | 4 bytes | + +__Magic Number__ + +4 Bytes, Little endian format. +Value : 0x184D2204 + +__Frame Descriptor__ + +3 to 11 Bytes, to be detailed in the next part. +Most important part of the spec. + +__Data Blocks__ + +To be detailed later on. +That’s where compressed data is stored. + +__EndMark__ + +The flow of blocks ends when the last data block has a size of “0”. +The size is expressed as a 32-bits value. + +__Content Checksum__ + +Content Checksum verify that the full content has been decoded correctly. +The content checksum is the result +of [xxh32() hash function](https://github.com/Cyan4973/xxHash) +digesting the original (decoded) data as input, and a seed of zero. +Content checksum is only present when its associated flag +is set in the frame descriptor. +Content Checksum validates the result, +that all blocks were fully transmitted in the correct order and without error, +and also that the encoding/decoding process itself generated no distortion. +Its usage is recommended. + +__Frame Concatenation__ + +In some circumstances, it may be preferable to append multiple frames, +for example in order to add new data to an existing compressed file +without re-framing it. + +In such case, each frame has its own set of descriptor flags. +Each frame is considered independent. +The only relation between frames is their sequential order. + +The ability to decode multiple concatenated frames +within a single stream or file +is left outside of this specification. +As an example, the reference lz4 command line utility behavior is +to decode all concatenated frames in their sequential order. + + +Frame Descriptor +---------------- + +| FLG | BD | (Content Size) | HC | +| ------- | ------- |:--------------:| ------- | +| 1 byte | 1 byte | 0 - 8 bytes | 1 byte | + +The descriptor uses a minimum of 3 bytes, +and up to 11 bytes depending on optional parameters. + +__FLG byte__ + +| BitNb | 7-6 | 5 | 4 | 3 | 2 | 1-0 | +| ------- | ------- | ------- | --------- | ------- | --------- | -------- | +|FieldName| Version | B.Indep | B.Checksum| C.Size | C.Checksum|*Reserved*| + + +__BD byte__ + +| BitNb | 7 | 6-5-4 | 3-2-1-0 | +| ------- | -------- | ------------ | -------- | +|FieldName|*Reserved*| Block MaxSize|*Reserved*| + +In the tables, bit 7 is highest bit, while bit 0 is lowest. + +__Version Number__ + +2-bits field, must be set to “01”. +Any other value cannot be decoded by this version of the specification. +Other version numbers will use different flag layouts. + +__Block Independence flag__ + +If this flag is set to “1”, blocks are independent. +If this flag is set to “0”, each block depends on previous ones +(up to LZ4 window size, which is 64 KB). +In such case, it’s necessary to decode all blocks in sequence. + +Block dependency improves compression ratio, especially for small blocks. +On the other hand, it makes direct jumps or multi-threaded decoding impossible. + +__Block checksum flag__ + +If this flag is set, each data block will be followed by a 4-bytes checksum, +calculated by using the xxHash-32 algorithm on the raw (compressed) data block. +The intention is to detect data corruption (storage or transmission errors) +immediately, before decoding. +Block checksum usage is optional. + +__Content Size flag__ + +If this flag is set, the uncompressed size of data included within the frame +will be present as an 8 bytes unsigned little endian value, after the flags. +Content Size usage is optional. + +__Content checksum flag__ + +If this flag is set, a content checksum will be appended after the EndMark. + +Recommended value : “1” (content checksum is present) + +__Block Maximum Size__ + +This information is intended to help the decoder allocate memory. +Size here refers to the original (uncompressed) data size. +Block Maximum Size is one value among the following table : + +| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +| --- | --- | --- | --- | ----- | ------ | ---- | ---- | +| N/A | N/A | N/A | N/A | 64 KB | 256 KB | 1 MB | 4 MB | + +The decoder may refuse to allocate block sizes above a (system-specific) size. +Unused values may be used in a future revision of the spec. +A decoder conformant to the current version of the spec +is only able to decode blocksizes defined in this spec. + +__Reserved bits__ + +Value of reserved bits **must** be 0 (zero). +Reserved bit might be used in a future version of the specification, +typically enabling new optional features. +If this happens, a decoder respecting the current version of the specification +shall not be able to decode such a frame. + +__Content Size__ + +This is the original (uncompressed) size. +This information is optional, and only present if the associated flag is set. +Content size is provided using unsigned 8 Bytes, for a maximum of 16 HexaBytes. +Format is Little endian. +This value is informational. +It can be safely skipped by a conformant decoder. + +__Header Checksum__ + +One-byte checksum of combined descriptor fields, including optional ones. +The value is the second byte of xxh32() : ` (xxh32()>>8) & 0xFF } ` +using zero as a seed, +and the full Frame Descriptor as an input +(including optional fields when they are present). +A wrong checksum indicates an error in the descriptor. +Header checksum is informational and can be skipped. + + +Data Blocks +----------- + +| Block Size | data | (Block Checksum) | +|:----------:| ------ |:----------------:| +| 4 bytes | | 0 - 4 bytes | + + +__Block Size__ + +This field uses 4-bytes, format is little-endian. + +The highest bit is “1” if data in the block is uncompressed. + +The highest bit is “0” if data in the block is compressed by LZ4. + +All other bits give the size, in bytes, of the following data block +(the size does not include the block checksum if present). + +Block Size shall never be larger than Block Maximum Size. +Such a thing could happen for incompressible source data. +In such case, such a data block shall be passed in uncompressed format. + +__Data__ + +Where the actual data to decode stands. +It might be compressed or not, depending on previous field indications. +Uncompressed size of Data can be any size, up to “block maximum size”. +Note that data block is not necessarily full : +an arbitrary “flush” may happen anytime. Any block can be “partially filled”. + +__Block checksum__ + +Only present if the associated flag is set. +This is a 4-bytes checksum value, in little endian format, +calculated by using the xxHash-32 algorithm on the raw (undecoded) data block, +and a seed of zero. +The intention is to detect data corruption (storage or transmission errors) +before decoding. + +Block checksum is cumulative with Content checksum. + + +Skippable Frames +---------------- + +| Magic Number | Frame Size | User Data | +|:------------:|:----------:| --------- | +| 4 bytes | 4 bytes | | + +Skippable frames allow the integration of user-defined data +into a flow of concatenated frames. +Its design is pretty straightforward, +with the sole objective to allow the decoder to quickly skip +over user-defined data and continue decoding. + +For the purpose of facilitating identification, +it is discouraged to start a flow of concatenated frames with a skippable frame. +If there is a need to start such a flow with some user data +encapsulated into a skippable frame, +it’s recommended to start with a zero-byte LZ4 frame +followed by a skippable frame. +This will make it easier for file type identifiers. + + +__Magic Number__ + +4 Bytes, Little endian format. +Value : 0x184D2A5X, which means any value from 0x184D2A50 to 0x184D2A5F. +All 16 values are valid to identify a skippable frame. + +__Frame Size__ + +This is the size, in bytes, of the following User Data +(without including the magic number nor the size field itself). +4 Bytes, Little endian format, unsigned 32-bits. +This means User Data can’t be bigger than (2^32-1) Bytes. + +__User Data__ + +User Data can be anything. Data will just be skipped by the decoder. + + +Legacy frame +------------ + +The Legacy frame format was defined into the initial versions of “LZ4Demo”. +Newer compressors should not use this format anymore, as it is too restrictive. + +Main characteristics of the legacy format : + +- Fixed block size : 8 MB. +- All blocks must be completely filled, except the last one. +- All blocks are always compressed, even when compression is detrimental. +- The last block is detected either because + it is followed by the “EOF” (End of File) mark, + or because it is followed by a known Frame Magic Number. +- No checksum +- Convention is Little endian + +| MagicNb | B.CSize | CData | B.CSize | CData | (...) | EndMark | +| ------- | ------- | ----- | ------- | ----- | ------- | ------- | +| 4 bytes | 4 bytes | CSize | 4 bytes | CSize | x times | EOF | + + +__Magic Number__ + +4 Bytes, Little endian format. +Value : 0x184C2102 + +__Block Compressed Size__ + +This is the size, in bytes, of the following compressed data block. +4 Bytes, Little endian format. + +__Data__ + +Where the actual compressed data stands. +Data is always compressed, even when compression is detrimental. + +__EndMark__ + +End of compressed stream is implicit. +It needs to be followed by a standard EOF (End Of File) signal, +wether it is a file or a stream. + +Alternatively, if the frame is followed by a valid Frame Magic Number, +it is considered completed. +It makes legacy frames compatible with frame concatenation. + +Any other value will be interpreted as a block size, +and trigger an error if it does not fit within acceptable range. + + +Version changes +--------------- + +1.5.1 : changed format to MarkDown compatible + +1.5 : removed Dictionary ID from specification + +1.4.1 : changed wording from “stream” to “frame” + +1.4 : added skippable streams, re-added stream checksum + +1.3 : modified header checksum + +1.2 : reduced choice of “block size”, to postpone decision on “dynamic size of BlockSize Field”. + +1.1 : optional fields are now part of the descriptor + +1.0 : changed “block size” specification, adding a compressed/uncompressed flag + +0.9 : reduced scale of “block maximum size” table + +0.8 : removed : high compression flag + +0.7 : removed : stream checksum + +0.6 : settled : stream size uses 8 bytes, endian convention is little endian + +0.5: added copyright notice + +0.4 : changed format to Google Doc compatible OpenDocument \ No newline at end of file -- cgit v0.12 From 7c26b038547e3a488a6cd5fe13df260b6e4d6e08 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 10:22:18 +0100 Subject: Updated make dist --- Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 59c5e3b..59759c0 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ # ################################################################ # Version number -export VERSION=128 +export VERSION=129 export RELEASE=r$(VERSION) DESTDIR?= @@ -47,7 +47,7 @@ TEXT = $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4.h $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4hc.h \ $(LZ4DIR)/lz4frame.c $(LZ4DIR)/lz4frame.h $(LZ4DIR)/lz4frame_static.h \ $(LZ4DIR)/xxhash.c $(LZ4DIR)/xxhash.h \ $(LZ4DIR)/liblz4.pc.in $(LZ4DIR)/Makefile $(LZ4DIR)/LICENSE \ - Makefile lz4_block_format.txt LZ4_Frame_Format.html NEWS README.md \ + Makefile lz4_Block_format.md lz4_Frame_format.md NEWS README.md \ cmake_unofficial/CMakeLists.txt \ $(PRGDIR)/fullbench.c $(PRGDIR)/lz4cli.c \ $(PRGDIR)/datagen.c $(PRGDIR)/datagen.h $(PRGDIR)/datagencli.c $(PRGDIR)/fuzzer.c \ @@ -55,9 +55,7 @@ TEXT = $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4.h $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4hc.h \ $(PRGDIR)/bench.c $(PRGDIR)/bench.h \ $(PRGDIR)/lz4.1 \ $(PRGDIR)/Makefile $(PRGDIR)/COPYING -NONTEXT = images/image00.png images/image01.png images/image02.png \ - images/image03.png images/image04.png images/image05.png \ - images/image06.png +NONTEXT = SOURCES = $(TEXT) $(NONTEXT) @@ -112,7 +110,6 @@ dist: clean @install -dD -m 700 lz4-$(RELEASE)/lib/ @install -dD -m 700 lz4-$(RELEASE)/programs/ @install -dD -m 700 lz4-$(RELEASE)/cmake_unofficial/ - @install -dD -m 700 lz4-$(RELEASE)/images/ @for f in $(TEXT); do \ tr -d '\r' < $$f > .tmp; \ install -m 600 .tmp lz4-$(RELEASE)/$$f; \ -- cgit v0.12 From 3bba55c741293dd8162e5afb9eace5e03fcff023 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 14:47:23 +0100 Subject: Fixed : Windows compilation Added : Appveyor badge --- README.md | 4 +++- lib/lz4frame.c | 6 ++++-- lz4_Frame_format.md | 0 programs/frametest.c | 2 +- programs/lz4io.c | 4 ++++ 5 files changed, 12 insertions(+), 4 deletions(-) mode change 100755 => 100644 README.md mode change 100755 => 100644 lz4_Frame_format.md diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 69f7397..453bb01 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ It trades CPU time for compression ratio. |------------|---------| |master | [![Build Status](https://travis-ci.org/Cyan4973/lz4.svg?branch=master)](https://travis-ci.org/Cyan4973/lz4) | |dev | [![Build Status](https://travis-ci.org/Cyan4973/lz4.svg?branch=dev)](https://travis-ci.org/Cyan4973/lz4) | +|visual | [![Build status](https://ci.appveyor.com/api/projects/status/v6kxv9si529477cq?svg=true)](https://ci.appveyor.com/project/YannCollet/lz4) | + > **Branch Policy:** @@ -63,4 +65,4 @@ defined into [lz4_Frame_format]. [Open-Source Benchmark program by m^2 (v0.14.3)]: http://encode.ru/threads/1371-Filesystem-benchmark?p=34029&viewfull=1#post34029 [Silesia Corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia [lz4_Block_format]: lz4_Block_format.md -[lz4_Frame_format]: lz4_Frame_format.md \ No newline at end of file +[lz4_Frame_format]: lz4_Frame_format.md diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 5f69c95..474b196 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -1088,8 +1088,10 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, doAnotherStage = 0; /* not enough src data, ask for some more */ break; } - LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, dctxPtr->header, dctxPtr->tmpInTarget); - if (LZ4F_isError(errorCode)) return errorCode; + { + LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, dctxPtr->header, dctxPtr->tmpInTarget); + if (LZ4F_isError(errorCode)) return errorCode; + } break; } diff --git a/lz4_Frame_format.md b/lz4_Frame_format.md old mode 100755 new mode 100644 diff --git a/programs/frametest.c b/programs/frametest.c index 96d5acb..4beee23 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -607,7 +607,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi /* create a skippable frame (rare case) */ BYTE* op = (BYTE*)compressedBuffer; FUZ_writeLE32(op, LZ4F_MAGIC_SKIPPABLE_START + (FUZ_rand(&randState) & 15)); - FUZ_writeLE32(op+4, srcSize); + FUZ_writeLE32(op+4, (U32)srcSize); cSize = srcSize+8; } else if ((FUZ_rand(&randState) & 0xF) == 2) diff --git a/programs/lz4io.c b/programs/lz4io.c index 34d24bf..02e03c8 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -75,6 +75,10 @@ # define SET_SPARSE_FILE_MODE(file) #endif +#if !defined(S_ISREG) +# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) +#endif + /***************************** * Constants -- cgit v0.12 From 7db667820fbaf8caec7f33806f5895416194f1a7 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 16:14:54 +0100 Subject: Restored proper credit --- NEWS | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index b692b8d..233dc82 100644 --- a/NEWS +++ b/NEWS @@ -3,21 +3,21 @@ Added : LZ4_compress_fast() Updated: Documentation converted to MarkDown r128: -New : lz4cli sparse file support -New : command -m, to compress multiple files in a single command -Fixed : Restored lz4hc compression ratio (was slightly lower since r124) -New : lz4 cli supports long commands -New : lz4frame & lz4cli frame content size support -New : lz4frame supports skippable frames -Changed:Default "make install" directory is /usr/local -New : lz4 cli supports "pass-through" mode -New : datagen can generate sparse files -New : scan-build tests -New : g++ compatibility tests -New : arm cross-compilation test -Fixed : Fuzzer + frametest compatibility with NetBSD (issue #48) -Added : Visual project directory -Updated:Man page & Specification +New : lz4cli sparse file support (Requested by Neil Wilson, and contributed by Takayuki Matsuoka) +New : command -m, to compress multiple files in a single command (suggested by Kyle J. Harper) +Fixed : Restored lz4hc compression ratio (slightly lower since r124) +New : lz4 cli supports long commands (suggested by Takayuki Matsuoka) +New : lz4frame & lz4cli frame content size support +New : lz4frame supports skippable frames, as requested by Sergey Cherepanov +Changed: Default "make install" directory is /usr/local, as notified by Ron Johnson +New : lz4 cli supports "pass-through" mode, requested by Neil Wilson +New : datagen can generate sparse files +New : scan-build tests, thanks to kind help by Takayuki Matsuoka +New : g++ compatibility tests +New : arm cross-compilation test, thanks to kind help by Takayuki Matsuoka +Fixed : Fuzzer + frametest compatibility with NetBSD (issue #48, reported by Thomas Klausner) +Added : Visual project directory +Updated: Man page & Specification r127: N/A : added a file on SVN -- cgit v0.12 From bf146ec2476f5a6d4128dfee665e9e0d2db00f4d Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 18:38:16 +0100 Subject: Removed .suo & .user files from Visual solutions --- visual/2012/fuzzer/fuzzer.vcxproj.user | 4 ---- visual/2012/lz4.v11.suo | Bin 20992 -> 0 bytes visual/2012/lz4/lz4.vcxproj.user | 4 ---- 3 files changed, 8 deletions(-) delete mode 100644 visual/2012/fuzzer/fuzzer.vcxproj.user delete mode 100644 visual/2012/lz4.v11.suo delete mode 100644 visual/2012/lz4/lz4.vcxproj.user diff --git a/visual/2012/fuzzer/fuzzer.vcxproj.user b/visual/2012/fuzzer/fuzzer.vcxproj.user deleted file mode 100644 index 7cbb321..0000000 --- a/visual/2012/fuzzer/fuzzer.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/visual/2012/lz4.v11.suo b/visual/2012/lz4.v11.suo deleted file mode 100644 index 8321984..0000000 Binary files a/visual/2012/lz4.v11.suo and /dev/null differ diff --git a/visual/2012/lz4/lz4.vcxproj.user b/visual/2012/lz4/lz4.vcxproj.user deleted file mode 100644 index 7cbb321..0000000 --- a/visual/2012/lz4/lz4.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file -- cgit v0.12 From a761546b1b8499bd52ed84876df03cb00e81c02e Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 18:52:52 +0100 Subject: Fix : minor warning under Visual --- lib/lz4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4.c b/lib/lz4.c index cd6147f..3dc44f2 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -731,7 +731,7 @@ _last_literals: } -int LZ4_compress(const char* source, char* dest, const int inputSize) +int LZ4_compress(const char* source, char* dest, int inputSize) { #if (HEAPMODE) void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ -- cgit v0.12 From 08b24af5a014b1410f81c363f799fe5bff4cc695 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 19:12:59 +0100 Subject: Updated Visual 2012 solution : + 3 projects (fullbench, frametest, datagen) --- visual/2012/datagen/datagen.vcxproj | 159 +++++++++++++++++++++++ visual/2012/datagen/datagen.vcxproj.filters | 30 +++++ visual/2012/frametest/frametest.vcxproj | 166 ++++++++++++++++++++++++ visual/2012/frametest/frametest.vcxproj.filters | 51 ++++++++ visual/2012/fullbench/fullbench.vcxproj | 166 ++++++++++++++++++++++++ visual/2012/fullbench/fullbench.vcxproj.filters | 51 ++++++++ visual/2012/fuzzer/fuzzer.vcxproj | 2 + visual/2012/fuzzer/fuzzer.vcxproj.filters | 0 visual/2012/lz4.sln | 40 ++++-- visual/2012/lz4/lz4.vcxproj | 2 + visual/2012/lz4/lz4.vcxproj.filters | 0 11 files changed, 657 insertions(+), 10 deletions(-) create mode 100755 visual/2012/datagen/datagen.vcxproj create mode 100755 visual/2012/datagen/datagen.vcxproj.filters create mode 100755 visual/2012/frametest/frametest.vcxproj create mode 100755 visual/2012/frametest/frametest.vcxproj.filters create mode 100755 visual/2012/fullbench/fullbench.vcxproj create mode 100755 visual/2012/fullbench/fullbench.vcxproj.filters mode change 100644 => 100755 visual/2012/fuzzer/fuzzer.vcxproj mode change 100644 => 100755 visual/2012/fuzzer/fuzzer.vcxproj.filters mode change 100644 => 100755 visual/2012/lz4.sln mode change 100644 => 100755 visual/2012/lz4/lz4.vcxproj mode change 100644 => 100755 visual/2012/lz4/lz4.vcxproj.filters diff --git a/visual/2012/datagen/datagen.vcxproj b/visual/2012/datagen/datagen.vcxproj new file mode 100755 index 0000000..ea61533 --- /dev/null +++ b/visual/2012/datagen/datagen.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D745AE2F-596A-403A-9B91-81A8C6779243} + Win32Proj + datagen + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2012/datagen/datagen.vcxproj.filters b/visual/2012/datagen/datagen.vcxproj.filters new file mode 100755 index 0000000..822d9bc --- /dev/null +++ b/visual/2012/datagen/datagen.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2012/frametest/frametest.vcxproj b/visual/2012/frametest/frametest.vcxproj new file mode 100755 index 0000000..b86f7de --- /dev/null +++ b/visual/2012/frametest/frametest.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7} + Win32Proj + frametest + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2012/frametest/frametest.vcxproj.filters b/visual/2012/frametest/frametest.vcxproj.filters new file mode 100755 index 0000000..19c3d15 --- /dev/null +++ b/visual/2012/frametest/frametest.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2012/fullbench/fullbench.vcxproj b/visual/2012/fullbench/fullbench.vcxproj new file mode 100755 index 0000000..11f8f45 --- /dev/null +++ b/visual/2012/fullbench/fullbench.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E} + Win32Proj + fullbench + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2012/fullbench/fullbench.vcxproj.filters b/visual/2012/fullbench/fullbench.vcxproj.filters new file mode 100755 index 0000000..cdcf599 --- /dev/null +++ b/visual/2012/fullbench/fullbench.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2012/fuzzer/fuzzer.vcxproj b/visual/2012/fuzzer/fuzzer.vcxproj old mode 100644 new mode 100755 index 9ba4fab..6287947 --- a/visual/2012/fuzzer/fuzzer.vcxproj +++ b/visual/2012/fuzzer/fuzzer.vcxproj @@ -117,6 +117,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console @@ -134,6 +135,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console diff --git a/visual/2012/fuzzer/fuzzer.vcxproj.filters b/visual/2012/fuzzer/fuzzer.vcxproj.filters old mode 100644 new mode 100755 diff --git a/visual/2012/lz4.sln b/visual/2012/lz4.sln old mode 100644 new mode 100755 index 2d07075..80d1a54 --- a/visual/2012/lz4.sln +++ b/visual/2012/lz4.sln @@ -5,40 +5,60 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lz4", "lz4\lz4.vcxproj", "{ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fuzzer", "fuzzer\fuzzer.vcxproj", "{18B9F1A7-9C66-4352-898B-30804DADE0FD}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fullbench", "fullbench\fullbench.vcxproj", "{6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "frametest", "frametest\frametest.vcxproj", "{39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "datagen", "datagen\datagen.vcxproj", "{D745AE2F-596A-403A-9B91-81A8C6779243}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Mixed Platforms = Debug|Mixed Platforms Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 - Release|Mixed Platforms = Release|Mixed Platforms Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Win32.ActiveCfg = Debug|Win32 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Win32.Build.0 = Debug|Win32 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|x64.ActiveCfg = Debug|x64 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|x64.Build.0 = Debug|x64 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Mixed Platforms.Build.0 = Release|Win32 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Win32.ActiveCfg = Release|Win32 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Win32.Build.0 = Release|Win32 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|x64.ActiveCfg = Release|x64 {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|x64.Build.0 = Release|x64 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Win32.ActiveCfg = Debug|Win32 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Win32.Build.0 = Debug|Win32 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|x64.ActiveCfg = Debug|x64 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|x64.Build.0 = Debug|x64 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Mixed Platforms.Build.0 = Release|Win32 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Win32.ActiveCfg = Release|Win32 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Win32.Build.0 = Release|Win32 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|x64.ActiveCfg = Release|x64 {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|x64.Build.0 = Release|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|Win32.ActiveCfg = Debug|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|Win32.Build.0 = Debug|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|x64.ActiveCfg = Debug|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|x64.Build.0 = Debug|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|Win32.ActiveCfg = Release|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|Win32.Build.0 = Release|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|x64.ActiveCfg = Release|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|x64.Build.0 = Release|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|Win32.ActiveCfg = Debug|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|Win32.Build.0 = Debug|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|x64.ActiveCfg = Debug|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|x64.Build.0 = Debug|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|Win32.ActiveCfg = Release|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|Win32.Build.0 = Release|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|x64.ActiveCfg = Release|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|x64.Build.0 = Release|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|Win32.ActiveCfg = Debug|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|Win32.Build.0 = Debug|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|x64.ActiveCfg = Debug|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|x64.Build.0 = Debug|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|Win32.ActiveCfg = Release|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|Win32.Build.0 = Release|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|x64.ActiveCfg = Release|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/visual/2012/lz4/lz4.vcxproj b/visual/2012/lz4/lz4.vcxproj old mode 100644 new mode 100755 index 5540d5d..b7e0061 --- a/visual/2012/lz4/lz4.vcxproj +++ b/visual/2012/lz4/lz4.vcxproj @@ -117,6 +117,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console @@ -134,6 +135,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console diff --git a/visual/2012/lz4/lz4.vcxproj.filters b/visual/2012/lz4/lz4.vcxproj.filters old mode 100644 new mode 100755 -- cgit v0.12 From 117ab8c84196474bda1fd819941bc41ce9a574ee Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 20:08:52 +0100 Subject: Added : Visual 2013 solution --- visual/2012/fuzzer/fuzzer.vcxproj | 2 + visual/2012/lz4/lz4.vcxproj | 2 + visual/2013/datagen/datagen.vcxproj | 159 ++++++++++++++++++++++ visual/2013/datagen/datagen.vcxproj.filters | 30 +++++ visual/2013/frametest/frametest.vcxproj | 166 +++++++++++++++++++++++ visual/2013/frametest/frametest.vcxproj.filters | 51 +++++++ visual/2013/fullbench/fullbench.vcxproj | 166 +++++++++++++++++++++++ visual/2013/fullbench/fullbench.vcxproj.filters | 51 +++++++ visual/2013/fuzzer/fuzzer.vcxproj | 163 +++++++++++++++++++++++ visual/2013/fuzzer/fuzzer.vcxproj.filters | 42 ++++++ visual/2013/lz4.sln | 66 +++++++++ visual/2013/lz4/lz4.vcxproj | 170 ++++++++++++++++++++++++ visual/2013/lz4/lz4.vcxproj.filters | 63 +++++++++ 13 files changed, 1131 insertions(+) create mode 100755 visual/2013/datagen/datagen.vcxproj create mode 100755 visual/2013/datagen/datagen.vcxproj.filters create mode 100755 visual/2013/frametest/frametest.vcxproj create mode 100755 visual/2013/frametest/frametest.vcxproj.filters create mode 100755 visual/2013/fullbench/fullbench.vcxproj create mode 100755 visual/2013/fullbench/fullbench.vcxproj.filters create mode 100755 visual/2013/fuzzer/fuzzer.vcxproj create mode 100755 visual/2013/fuzzer/fuzzer.vcxproj.filters create mode 100755 visual/2013/lz4.sln create mode 100755 visual/2013/lz4/lz4.vcxproj create mode 100755 visual/2013/lz4/lz4.vcxproj.filters diff --git a/visual/2012/fuzzer/fuzzer.vcxproj b/visual/2012/fuzzer/fuzzer.vcxproj index 6287947..4da822f 100755 --- a/visual/2012/fuzzer/fuzzer.vcxproj +++ b/visual/2012/fuzzer/fuzzer.vcxproj @@ -89,6 +89,7 @@ Level4 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console @@ -102,6 +103,7 @@ Level4 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console diff --git a/visual/2012/lz4/lz4.vcxproj b/visual/2012/lz4/lz4.vcxproj index b7e0061..8ac9387 100755 --- a/visual/2012/lz4/lz4.vcxproj +++ b/visual/2012/lz4/lz4.vcxproj @@ -89,6 +89,7 @@ Level4 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console @@ -102,6 +103,7 @@ Level4 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true Console diff --git a/visual/2013/datagen/datagen.vcxproj b/visual/2013/datagen/datagen.vcxproj new file mode 100755 index 0000000..0d58b59 --- /dev/null +++ b/visual/2013/datagen/datagen.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D745AE2F-596A-403A-9B91-81A8C6779243} + Win32Proj + datagen + + + + Application + true + v120 + Unicode + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2013/datagen/datagen.vcxproj.filters b/visual/2013/datagen/datagen.vcxproj.filters new file mode 100755 index 0000000..822d9bc --- /dev/null +++ b/visual/2013/datagen/datagen.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2013/frametest/frametest.vcxproj b/visual/2013/frametest/frametest.vcxproj new file mode 100755 index 0000000..50f941d --- /dev/null +++ b/visual/2013/frametest/frametest.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7} + Win32Proj + frametest + + + + Application + true + v120 + Unicode + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2013/frametest/frametest.vcxproj.filters b/visual/2013/frametest/frametest.vcxproj.filters new file mode 100755 index 0000000..19c3d15 --- /dev/null +++ b/visual/2013/frametest/frametest.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2013/fullbench/fullbench.vcxproj b/visual/2013/fullbench/fullbench.vcxproj new file mode 100755 index 0000000..1fcfb6a --- /dev/null +++ b/visual/2013/fullbench/fullbench.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E} + Win32Proj + fullbench + + + + Application + true + v120 + Unicode + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2013/fullbench/fullbench.vcxproj.filters b/visual/2013/fullbench/fullbench.vcxproj.filters new file mode 100755 index 0000000..cdcf599 --- /dev/null +++ b/visual/2013/fullbench/fullbench.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2013/fuzzer/fuzzer.vcxproj b/visual/2013/fuzzer/fuzzer.vcxproj new file mode 100755 index 0000000..eadb17e --- /dev/null +++ b/visual/2013/fuzzer/fuzzer.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {18B9F1A7-9C66-4352-898B-30804DADE0FD} + Win32Proj + fuzzer + + + + Application + true + v120 + Unicode + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2013/fuzzer/fuzzer.vcxproj.filters b/visual/2013/fuzzer/fuzzer.vcxproj.filters new file mode 100755 index 0000000..81002e9 --- /dev/null +++ b/visual/2013/fuzzer/fuzzer.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + \ No newline at end of file diff --git a/visual/2013/lz4.sln b/visual/2013/lz4.sln new file mode 100755 index 0000000..80d1a54 --- /dev/null +++ b/visual/2013/lz4.sln @@ -0,0 +1,66 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2012 for Windows Desktop +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lz4", "lz4\lz4.vcxproj", "{E30329AC-0057-4FE0-8FDA-7F650D398C4C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fuzzer", "fuzzer\fuzzer.vcxproj", "{18B9F1A7-9C66-4352-898B-30804DADE0FD}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fullbench", "fullbench\fullbench.vcxproj", "{6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "frametest", "frametest\frametest.vcxproj", "{39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "datagen", "datagen\datagen.vcxproj", "{D745AE2F-596A-403A-9B91-81A8C6779243}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Win32.ActiveCfg = Debug|Win32 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Win32.Build.0 = Debug|Win32 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|x64.ActiveCfg = Debug|x64 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|x64.Build.0 = Debug|x64 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Win32.ActiveCfg = Release|Win32 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Win32.Build.0 = Release|Win32 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|x64.ActiveCfg = Release|x64 + {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|x64.Build.0 = Release|x64 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Win32.ActiveCfg = Debug|Win32 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Win32.Build.0 = Debug|Win32 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|x64.ActiveCfg = Debug|x64 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|x64.Build.0 = Debug|x64 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Win32.ActiveCfg = Release|Win32 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Win32.Build.0 = Release|Win32 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|x64.ActiveCfg = Release|x64 + {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|x64.Build.0 = Release|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|Win32.ActiveCfg = Debug|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|Win32.Build.0 = Debug|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|x64.ActiveCfg = Debug|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|x64.Build.0 = Debug|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|Win32.ActiveCfg = Release|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|Win32.Build.0 = Release|Win32 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|x64.ActiveCfg = Release|x64 + {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|x64.Build.0 = Release|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|Win32.ActiveCfg = Debug|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|Win32.Build.0 = Debug|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|x64.ActiveCfg = Debug|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|x64.Build.0 = Debug|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|Win32.ActiveCfg = Release|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|Win32.Build.0 = Release|Win32 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|x64.ActiveCfg = Release|x64 + {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|x64.Build.0 = Release|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|Win32.ActiveCfg = Debug|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|Win32.Build.0 = Debug|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|x64.ActiveCfg = Debug|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|x64.Build.0 = Debug|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|Win32.ActiveCfg = Release|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|Win32.Build.0 = Release|Win32 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|x64.ActiveCfg = Release|x64 + {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/visual/2013/lz4/lz4.vcxproj b/visual/2013/lz4/lz4.vcxproj new file mode 100755 index 0000000..3886f3f --- /dev/null +++ b/visual/2013/lz4/lz4.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E30329AC-0057-4FE0-8FDA-7F650D398C4C} + Win32Proj + lz4 + + + + Application + true + v120 + Unicode + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visual/2013/lz4/lz4.vcxproj.filters b/visual/2013/lz4/lz4.vcxproj.filters new file mode 100755 index 0000000..fbe688b --- /dev/null +++ b/visual/2013/lz4/lz4.vcxproj.filters @@ -0,0 +1,63 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + + \ No newline at end of file -- cgit v0.12 From 7b5e94575a5f587553247b685c6686fcc63c2343 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 20:27:34 +0100 Subject: Removed Visual 2013 solution, as AppVeyor automated mode only works with a single solution --- visual/2013/datagen/datagen.vcxproj | 159 ---------------------- visual/2013/datagen/datagen.vcxproj.filters | 30 ----- visual/2013/frametest/frametest.vcxproj | 166 ----------------------- visual/2013/frametest/frametest.vcxproj.filters | 51 ------- visual/2013/fullbench/fullbench.vcxproj | 166 ----------------------- visual/2013/fullbench/fullbench.vcxproj.filters | 51 ------- visual/2013/fuzzer/fuzzer.vcxproj | 163 ----------------------- visual/2013/fuzzer/fuzzer.vcxproj.filters | 42 ------ visual/2013/lz4.sln | 66 --------- visual/2013/lz4/lz4.vcxproj | 170 ------------------------ visual/2013/lz4/lz4.vcxproj.filters | 63 --------- 11 files changed, 1127 deletions(-) delete mode 100755 visual/2013/datagen/datagen.vcxproj delete mode 100755 visual/2013/datagen/datagen.vcxproj.filters delete mode 100755 visual/2013/frametest/frametest.vcxproj delete mode 100755 visual/2013/frametest/frametest.vcxproj.filters delete mode 100755 visual/2013/fullbench/fullbench.vcxproj delete mode 100755 visual/2013/fullbench/fullbench.vcxproj.filters delete mode 100755 visual/2013/fuzzer/fuzzer.vcxproj delete mode 100755 visual/2013/fuzzer/fuzzer.vcxproj.filters delete mode 100755 visual/2013/lz4.sln delete mode 100755 visual/2013/lz4/lz4.vcxproj delete mode 100755 visual/2013/lz4/lz4.vcxproj.filters diff --git a/visual/2013/datagen/datagen.vcxproj b/visual/2013/datagen/datagen.vcxproj deleted file mode 100755 index 0d58b59..0000000 --- a/visual/2013/datagen/datagen.vcxproj +++ /dev/null @@ -1,159 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {D745AE2F-596A-403A-9B91-81A8C6779243} - Win32Proj - datagen - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/visual/2013/datagen/datagen.vcxproj.filters b/visual/2013/datagen/datagen.vcxproj.filters deleted file mode 100755 index 822d9bc..0000000 --- a/visual/2013/datagen/datagen.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Fichiers sources - - - Fichiers sources - - - - - Fichiers d%27en-tête - - - \ No newline at end of file diff --git a/visual/2013/frametest/frametest.vcxproj b/visual/2013/frametest/frametest.vcxproj deleted file mode 100755 index 50f941d..0000000 --- a/visual/2013/frametest/frametest.vcxproj +++ /dev/null @@ -1,166 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7} - Win32Proj - frametest - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/visual/2013/frametest/frametest.vcxproj.filters b/visual/2013/frametest/frametest.vcxproj.filters deleted file mode 100755 index 19c3d15..0000000 --- a/visual/2013/frametest/frametest.vcxproj.filters +++ /dev/null @@ -1,51 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - \ No newline at end of file diff --git a/visual/2013/fullbench/fullbench.vcxproj b/visual/2013/fullbench/fullbench.vcxproj deleted file mode 100755 index 1fcfb6a..0000000 --- a/visual/2013/fullbench/fullbench.vcxproj +++ /dev/null @@ -1,166 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E} - Win32Proj - fullbench - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/visual/2013/fullbench/fullbench.vcxproj.filters b/visual/2013/fullbench/fullbench.vcxproj.filters deleted file mode 100755 index cdcf599..0000000 --- a/visual/2013/fullbench/fullbench.vcxproj.filters +++ /dev/null @@ -1,51 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - \ No newline at end of file diff --git a/visual/2013/fuzzer/fuzzer.vcxproj b/visual/2013/fuzzer/fuzzer.vcxproj deleted file mode 100755 index eadb17e..0000000 --- a/visual/2013/fuzzer/fuzzer.vcxproj +++ /dev/null @@ -1,163 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {18B9F1A7-9C66-4352-898B-30804DADE0FD} - Win32Proj - fuzzer - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/visual/2013/fuzzer/fuzzer.vcxproj.filters b/visual/2013/fuzzer/fuzzer.vcxproj.filters deleted file mode 100755 index 81002e9..0000000 --- a/visual/2013/fuzzer/fuzzer.vcxproj.filters +++ /dev/null @@ -1,42 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - \ No newline at end of file diff --git a/visual/2013/lz4.sln b/visual/2013/lz4.sln deleted file mode 100755 index 80d1a54..0000000 --- a/visual/2013/lz4.sln +++ /dev/null @@ -1,66 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2012 for Windows Desktop -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lz4", "lz4\lz4.vcxproj", "{E30329AC-0057-4FE0-8FDA-7F650D398C4C}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fuzzer", "fuzzer\fuzzer.vcxproj", "{18B9F1A7-9C66-4352-898B-30804DADE0FD}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fullbench", "fullbench\fullbench.vcxproj", "{6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "frametest", "frametest\frametest.vcxproj", "{39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "datagen", "datagen\datagen.vcxproj", "{D745AE2F-596A-403A-9B91-81A8C6779243}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Win32.ActiveCfg = Debug|Win32 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|Win32.Build.0 = Debug|Win32 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|x64.ActiveCfg = Debug|x64 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Debug|x64.Build.0 = Debug|x64 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Win32.ActiveCfg = Release|Win32 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|Win32.Build.0 = Release|Win32 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|x64.ActiveCfg = Release|x64 - {E30329AC-0057-4FE0-8FDA-7F650D398C4C}.Release|x64.Build.0 = Release|x64 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Win32.ActiveCfg = Debug|Win32 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|Win32.Build.0 = Debug|Win32 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|x64.ActiveCfg = Debug|x64 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Debug|x64.Build.0 = Debug|x64 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Win32.ActiveCfg = Release|Win32 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|Win32.Build.0 = Release|Win32 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|x64.ActiveCfg = Release|x64 - {18B9F1A7-9C66-4352-898B-30804DADE0FD}.Release|x64.Build.0 = Release|x64 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|Win32.ActiveCfg = Debug|Win32 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|Win32.Build.0 = Debug|Win32 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|x64.ActiveCfg = Debug|x64 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Debug|x64.Build.0 = Debug|x64 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|Win32.ActiveCfg = Release|Win32 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|Win32.Build.0 = Release|Win32 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|x64.ActiveCfg = Release|x64 - {6A4DF4EF-C77F-43C6-8901-DDCD20879E4E}.Release|x64.Build.0 = Release|x64 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|Win32.ActiveCfg = Debug|Win32 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|Win32.Build.0 = Debug|Win32 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|x64.ActiveCfg = Debug|x64 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Debug|x64.Build.0 = Debug|x64 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|Win32.ActiveCfg = Release|Win32 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|Win32.Build.0 = Release|Win32 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|x64.ActiveCfg = Release|x64 - {39AD6ECC-8BAD-4368-95E4-A1AA2F077BB7}.Release|x64.Build.0 = Release|x64 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|Win32.ActiveCfg = Debug|Win32 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|Win32.Build.0 = Debug|Win32 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|x64.ActiveCfg = Debug|x64 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Debug|x64.Build.0 = Debug|x64 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|Win32.ActiveCfg = Release|Win32 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|Win32.Build.0 = Release|Win32 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|x64.ActiveCfg = Release|x64 - {D745AE2F-596A-403A-9B91-81A8C6779243}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/visual/2013/lz4/lz4.vcxproj b/visual/2013/lz4/lz4.vcxproj deleted file mode 100755 index 3886f3f..0000000 --- a/visual/2013/lz4/lz4.vcxproj +++ /dev/null @@ -1,170 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {E30329AC-0057-4FE0-8FDA-7F650D398C4C} - Win32Proj - lz4 - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - true - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - false - $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/visual/2013/lz4/lz4.vcxproj.filters b/visual/2013/lz4/lz4.vcxproj.filters deleted file mode 100755 index fbe688b..0000000 --- a/visual/2013/lz4/lz4.vcxproj.filters +++ /dev/null @@ -1,63 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - \ No newline at end of file -- cgit v0.12 From 886b19951c08d4155482ae7841cc6773f1f02f46 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 31 Mar 2015 20:29:24 +0100 Subject: Modified files rights --- NEWS | 1 + visual/2012/datagen/datagen.vcxproj | 0 visual/2012/datagen/datagen.vcxproj.filters | 0 visual/2012/frametest/frametest.vcxproj | 0 visual/2012/frametest/frametest.vcxproj.filters | 0 visual/2012/fullbench/fullbench.vcxproj | 0 visual/2012/fullbench/fullbench.vcxproj.filters | 0 visual/2012/fuzzer/fuzzer.vcxproj | 0 visual/2012/fuzzer/fuzzer.vcxproj.filters | 0 visual/2012/lz4.sln | 0 visual/2012/lz4/lz4.vcxproj | 0 visual/2012/lz4/lz4.vcxproj.filters | 0 12 files changed, 1 insertion(+) mode change 100755 => 100644 visual/2012/datagen/datagen.vcxproj mode change 100755 => 100644 visual/2012/datagen/datagen.vcxproj.filters mode change 100755 => 100644 visual/2012/frametest/frametest.vcxproj mode change 100755 => 100644 visual/2012/frametest/frametest.vcxproj.filters mode change 100755 => 100644 visual/2012/fullbench/fullbench.vcxproj mode change 100755 => 100644 visual/2012/fullbench/fullbench.vcxproj.filters mode change 100755 => 100644 visual/2012/fuzzer/fuzzer.vcxproj mode change 100755 => 100644 visual/2012/fuzzer/fuzzer.vcxproj.filters mode change 100755 => 100644 visual/2012/lz4.sln mode change 100755 => 100644 visual/2012/lz4/lz4.vcxproj mode change 100755 => 100644 visual/2012/lz4/lz4.vcxproj.filters diff --git a/NEWS b/NEWS index 233dc82..a1d452a 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ r129: Added : LZ4_compress_fast() +Added : AppVeyor CI environment, for Visual tests - Suggested by Takayuki Matsuoka Updated: Documentation converted to MarkDown r128: diff --git a/visual/2012/datagen/datagen.vcxproj b/visual/2012/datagen/datagen.vcxproj old mode 100755 new mode 100644 diff --git a/visual/2012/datagen/datagen.vcxproj.filters b/visual/2012/datagen/datagen.vcxproj.filters old mode 100755 new mode 100644 diff --git a/visual/2012/frametest/frametest.vcxproj b/visual/2012/frametest/frametest.vcxproj old mode 100755 new mode 100644 diff --git a/visual/2012/frametest/frametest.vcxproj.filters b/visual/2012/frametest/frametest.vcxproj.filters old mode 100755 new mode 100644 diff --git a/visual/2012/fullbench/fullbench.vcxproj b/visual/2012/fullbench/fullbench.vcxproj old mode 100755 new mode 100644 diff --git a/visual/2012/fullbench/fullbench.vcxproj.filters b/visual/2012/fullbench/fullbench.vcxproj.filters old mode 100755 new mode 100644 diff --git a/visual/2012/fuzzer/fuzzer.vcxproj b/visual/2012/fuzzer/fuzzer.vcxproj old mode 100755 new mode 100644 diff --git a/visual/2012/fuzzer/fuzzer.vcxproj.filters b/visual/2012/fuzzer/fuzzer.vcxproj.filters old mode 100755 new mode 100644 diff --git a/visual/2012/lz4.sln b/visual/2012/lz4.sln old mode 100755 new mode 100644 diff --git a/visual/2012/lz4/lz4.vcxproj b/visual/2012/lz4/lz4.vcxproj old mode 100755 new mode 100644 diff --git a/visual/2012/lz4/lz4.vcxproj.filters b/visual/2012/lz4/lz4.vcxproj.filters old mode 100755 new mode 100644 -- cgit v0.12 From 662506890285faa949fd627b8da8394813b37f0b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 14:48:24 +0100 Subject: simplified LZ4_compress() --- lib/lz4.c | 80 +++++++++++++++++++++++++++++++++------------------------------ lib/lz4.h | 6 ++--- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 3dc44f2..a078ced 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -582,8 +582,8 @@ static int LZ4_compress_generic( BYTE* token; { const BYTE* forwardIp = ip; - unsigned step=1; - unsigned searchMatchNb = ((acceleration) << LZ4_skipTrigger); + unsigned step = 1; + unsigned searchMatchNb = acceleration << LZ4_skipTrigger; /* Find a match */ do { @@ -717,13 +717,22 @@ _next_match: _last_literals: /* Encode Last Literals */ { - int lastRun = (int)(iend - anchor); - if ((outputLimited) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) + const size_t lastRun = (size_t)(iend - anchor); + if ((outputLimited) && ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */ - if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } - else *op++ = (BYTE)(lastRun<= RUN_MASK) + { + size_t accumulator = lastRun - RUN_MASK; + *op++ = RUN_MASK << ML_BITS; + for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; + *op++ = (BYTE) accumulator; + } + else + { + *op++ = (BYTE)(lastRun<= LZ4_compressBound(inputSize)) + { + if (inputSize < LZ4_64Klimit) + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); + else + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); + } else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); - + { + if (inputSize < LZ4_64Klimit) + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); + else + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); + } #if (HEAPMODE) FREEMEM(ctx); #endif return result; } -int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) -{ -#if (HEAPMODE) - void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ -#else - U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ -#endif - int result; - - if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); - else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); -#if (HEAPMODE) - FREEMEM(ctx); -#endif - return result; +int LZ4_compress(const char* source, char* dest, int inputSize) +{ + return LZ4_compress_limitedOutput(source, dest, inputSize, LZ4_compressBound(inputSize)); } @@ -807,6 +811,14 @@ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutp * Experimental : Streaming functions *****************************************/ +LZ4_stream_t* LZ4_createStream(void) +{ + LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64); + LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ + LZ4_resetStream(lz4s); + return lz4s; +} + /* * LZ4_initStream * Use this function once, to init a newly allocated LZ4_stream_t structure @@ -817,14 +829,6 @@ void LZ4_resetStream (LZ4_stream_t* LZ4_stream) MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t)); } -LZ4_stream_t* LZ4_createStream(void) -{ - LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64); - LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ - LZ4_resetStream(lz4s); - return lz4s; -} - int LZ4_freeStream (LZ4_stream_t* LZ4_stream) { FREEMEM(LZ4_stream); diff --git a/lib/lz4.h b/lib/lz4.h index eabc40f..7072c37 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -99,7 +99,7 @@ LZ4_decompress_safe() : * Advanced Functions **************************************/ #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */ -#define LZ4_COMPRESSBOUND(isize) ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16) +#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16) /* LZ4_compressBound() : @@ -107,11 +107,11 @@ LZ4_compressBound() : This function is primarily useful for memory allocation purposes (output buffer size). Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example). - isize : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE + inputSize : max supported value is LZ4_MAX_INPUT_SIZE return : maximum output size in a "worst case" scenario or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) */ -int LZ4_compressBound(int isize); +int LZ4_compressBound(int inputSize); /* -- cgit v0.12 From 76a03c1035829116e6fa9e80ad16364524514f9f Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 14:59:42 +0100 Subject: simplified LZ4_compress_withState() --- lib/lz4.c | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index a078ced..31dfc9f 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -740,6 +740,34 @@ _last_literals: } +int LZ4_sizeofState() { return LZ4_STREAMSIZE; } + +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_STREAMSIZE); + + if (maxOutputSize >= LZ4_compressBound(inputSize)) + { + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); + else + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); + } + else + { + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); + else + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); + } +} + +int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize) +{ + return LZ4_compress_limitedOutput_withState(state, source, dest, inputSize, LZ4_compressBound(inputSize)); +} + int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { #if (HEAPMODE) @@ -1384,32 +1412,6 @@ char* LZ4_slideInputBuffer (void* LZ4_Data) return (char*)(ctx->bufferStart + dictSize); } -/* Obsolete compresson functions using 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_STREAMSIZE); - - if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); - else - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); -} - -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_STREAMSIZE); - - if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); - else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); -} - /* Obsolete streaming decompression functions */ int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize) -- cgit v0.12 From 0615eb4814d68579b26b9c5b388c146d9d553228 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 15:05:27 +0100 Subject: Stricter tests : treat warnings as errors --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 59759c0..9cd2a29 100644 --- a/Makefile +++ b/Makefile @@ -131,18 +131,18 @@ test-travis: $(TRAVIS_TARGET) cmake: @cd cmake_unofficial; cmake CMakeLists.txt; $(MAKE) +gpptest: clean + export CC=g++; export CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"; $(MAKE) -e all + clangtest: clean - export CC=clang; $(MAKE) all + export CFLAGS=-Werror; export CC=clang; $(MAKE) all staticAnalyze: clean export CFLAGS=-g; scan-build -v $(MAKE) all -gpptest: clean - export CC=g++; export CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align"; $(MAKE) -e all - armtest: clean - export CC=arm-linux-gnueabi-gcc; cd lib; $(MAKE) -e all - export CC=arm-linux-gnueabi-gcc; cd programs; $(MAKE) -e bins + export CFLAGS=-Werror; export CC=arm-linux-gnueabi-gcc; cd lib; $(MAKE) -e all + export CFLAGS=-Werror; export CC=arm-linux-gnueabi-gcc; cd programs; $(MAKE) -e bins streaming-examples: cd examples; $(MAKE) -e test -- cgit v0.12 From 89eee0d28b2b7c5954e1cb0dce60542e4c597130 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 15:09:32 +0100 Subject: Removed make dist --- .travis.yml | 1 - Makefile | 34 ---------------------------------- 2 files changed, 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fabb1c..8f45f71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ before_install: - sudo apt-get install -qq valgrind env: - - LZ4_TRAVIS_CI_ENV=dist - LZ4_TRAVIS_CI_ENV=travis-install - LZ4_TRAVIS_CI_ENV=streaming-examples - LZ4_TRAVIS_CI_ENV=cmake diff --git a/Makefile b/Makefile index 9cd2a29..284972f 100644 --- a/Makefile +++ b/Makefile @@ -41,22 +41,6 @@ LIBDIR ?= $(PREFIX)/lib INCLUDEDIR=$(PREFIX)/include PRGDIR = programs LZ4DIR = lib -DISTRIBNAME=lz4-$(RELEASE).tar.gz - -TEXT = $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4.h $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4hc.h \ - $(LZ4DIR)/lz4frame.c $(LZ4DIR)/lz4frame.h $(LZ4DIR)/lz4frame_static.h \ - $(LZ4DIR)/xxhash.c $(LZ4DIR)/xxhash.h \ - $(LZ4DIR)/liblz4.pc.in $(LZ4DIR)/Makefile $(LZ4DIR)/LICENSE \ - Makefile lz4_Block_format.md lz4_Frame_format.md NEWS README.md \ - cmake_unofficial/CMakeLists.txt \ - $(PRGDIR)/fullbench.c $(PRGDIR)/lz4cli.c \ - $(PRGDIR)/datagen.c $(PRGDIR)/datagen.h $(PRGDIR)/datagencli.c $(PRGDIR)/fuzzer.c \ - $(PRGDIR)/lz4io.c $(PRGDIR)/lz4io.h \ - $(PRGDIR)/bench.c $(PRGDIR)/bench.h \ - $(PRGDIR)/lz4.1 \ - $(PRGDIR)/Makefile $(PRGDIR)/COPYING -NONTEXT = -SOURCES = $(TEXT) $(NONTEXT) # Select test target for Travis CI's Build Matrix @@ -84,7 +68,6 @@ lz4programs: @cd $(PRGDIR); $(MAKE) -e clean: - @rm -f $(DISTRIBNAME) *.sha1 > $(VOID) @cd $(PRGDIR); $(MAKE) clean > $(VOID) @cd $(LZ4DIR); $(MAKE) clean > $(VOID) @cd examples; $(MAKE) clean > $(VOID) @@ -106,23 +89,6 @@ uninstall: travis-install: sudo $(MAKE) install -dist: clean - @install -dD -m 700 lz4-$(RELEASE)/lib/ - @install -dD -m 700 lz4-$(RELEASE)/programs/ - @install -dD -m 700 lz4-$(RELEASE)/cmake_unofficial/ - @for f in $(TEXT); do \ - tr -d '\r' < $$f > .tmp; \ - install -m 600 .tmp lz4-$(RELEASE)/$$f; \ - done - @rm .tmp - @for f in $(NONTEXT); do \ - install -m 600 $$f lz4-$(RELEASE)/$$f; \ - done - @tar -czf $(DISTRIBNAME) lz4-$(RELEASE)/ - @rm -rf lz4-$(RELEASE) - @sha1sum $(DISTRIBNAME) > $(DISTRIBNAME).sha1 - @echo Distribution $(DISTRIBNAME) built - test: @cd $(PRGDIR); $(MAKE) -e test -- cgit v0.12 From 28e237e954098c418f048a871aa53199d92314f4 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 15:53:08 +0100 Subject: simplified LZ4_compress_limitedOutput() --- lib/lz4.c | 19 +++---------------- lib/lz4.h | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 31dfc9f..b0ce64f 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -771,26 +771,13 @@ int LZ4_compress_withState (void* state, const char* source, char* dest, int inp int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { #if (HEAPMODE) - void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ + void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* malloc-calloc aligned on 8-bytes boundaries */ #else U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ #endif - int result; - if (maxOutputSize >= LZ4_compressBound(inputSize)) - { - if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); - else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); - } - else - { - if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); - else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); - } + int result = LZ4_compress_limitedOutput_withState(ctx, source, dest, inputSize, maxOutputSize); + #if (HEAPMODE) FREEMEM(ctx); #endif diff --git a/lib/lz4.h b/lib/lz4.h index 7072c37..92c8738 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -48,7 +48,7 @@ extern "C" { * Version **************************************/ #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */ -#define LZ4_VERSION_MINOR 6 /* for new (non-breaking) interface capabilities */ +#define LZ4_VERSION_MINOR 7 /* for new (non-breaking) interface capabilities */ #define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */ #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE) int LZ4_versionNumber (void); -- cgit v0.12 From ef7cd83271eb6a513dd4fe389ee37a9bfc8e00e6 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 17:30:36 +0100 Subject: Fixed issue 160, reported by Eric Berge --- lib/lz4frame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 474b196..6c65d0b 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -204,7 +204,7 @@ static U64 LZ4F_readLE64 (const BYTE* srcPtr) U64 value64 = srcPtr[0]; value64 += (srcPtr[1]<<8); value64 += (srcPtr[2]<<16); - value64 += (srcPtr[3]<<24); + value64 += ((U64)srcPtr[3]<<24); value64 += ((U64)srcPtr[4]<<32); value64 += ((U64)srcPtr[5]<<40); value64 += ((U64)srcPtr[6]<<48); -- cgit v0.12 From 78d2dfd42758328c65d8517b8ee8e6124d7f8407 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 1 Apr 2015 18:21:03 +0100 Subject: fullbench : tests of _limitedOutput variants intentionnally provides less memory space than safe (LZ4_compressBound()) --- lib/lz4.c | 43 ++++++++++++++++--------------------------- lib/lz4.h | 1 + programs/Makefile | 5 ++++- programs/fullbench.c | 25 ++++++++++++------------- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index b0ce64f..a06f711 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -119,7 +119,7 @@ # pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ #else # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ -# ifdef __GNUC__ +# if defined(__GNUC__) || defined(__clang__) # define FORCE_INLINE static inline __attribute__((always_inline)) # else # define FORCE_INLINE static inline @@ -429,13 +429,6 @@ static const U32 LZ4_skipTrigger = 6; /* Increase this value ==> compression ru /************************************** -* Local Utils -**************************************/ -int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; } -int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); } - - -/************************************** * Local Structures and types **************************************/ typedef struct { @@ -457,6 +450,14 @@ typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive; typedef enum { full = 0, partial = 1 } earlyEnd_directive; +/************************************** +* Local Utils +**************************************/ +int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; } +int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); } +int LZ4_sizeofState() { return LZ4_STREAMSIZE; } + + /******************************** * Compression functions @@ -487,8 +488,6 @@ static U32 LZ4_hashSequenceT(size_t sequence, tableType_t const tableType) static U32 LZ4_hashPosition(const void* p, tableType_t tableType) { return LZ4_hashSequenceT(LZ4_read_ARCH(p), tableType); } -//static U32 LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(LZ4_read32(p), tableType); } - static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase) { switch (tableType) @@ -740,11 +739,8 @@ _last_literals: } -int LZ4_sizeofState() { return LZ4_STREAMSIZE; } - 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_STREAMSIZE); if (maxOutputSize >= LZ4_compressBound(inputSize)) @@ -757,7 +753,7 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* else { if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); else return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); } @@ -784,7 +780,6 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in return result; } - int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_limitedOutput(source, dest, inputSize, LZ4_compressBound(inputSize)); @@ -904,8 +899,7 @@ static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src) } -FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* source, char* dest, int inputSize, - int maxOutputSize, limitedOutput_directive limit) +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) { LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_stream; const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; @@ -932,9 +926,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, 1); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, 1); streamPtr->dictSize += (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; return result; @@ -944,9 +938,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, 1); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, 1); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; @@ -956,12 +950,7 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { - return LZ4_compress_continue_generic(LZ4_stream, source, dest, inputSize, 0, notLimited); -} - -int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) -{ - return LZ4_compress_continue_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput); + return LZ4_compress_limitedOutput_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize)); } diff --git a/lib/lz4.h b/lib/lz4.h index 92c8738..81a11c9 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -144,6 +144,7 @@ LZ4_compress_withState() : Same compression functions, but using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, and then, provide it as 'void* state' to compression functions. + Note that 'state' must be aligned on 4-bytes boundaries. */ int LZ4_sizeofState(void); int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); diff --git a/programs/Makefile b/programs/Makefile index a324148..0cebdfe 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -27,11 +27,14 @@ # lz4c32: Same as lz4c, but forced to compile in 32-bits mode # fuzzer : Test tool, to check lz4 integrity on target platform # fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode +# frametest : Test tool, to check lz4frame integrity on target platform +# frametest32: Same as frametest, but forced to compile in 32-bits mode # fullbench : Precisely measure speed for each LZ4 function variant # fullbench32: Same as fullbench, but forced to compile in 32-bits mode +# datagen : generates synthetic data samples for tests & benchmarks # ########################################################################## -RELEASE?= r128 +RELEASE?= r129 DESTDIR?= PREFIX ?= /usr/local diff --git a/programs/fullbench.c b/programs/fullbench.c index cd6e3c8..41075bc 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -383,7 +383,7 @@ start: static int local_LZ4_compress_limitedOutput(const char* in, char* out, int inSize) { - return LZ4_compress_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)); + return LZ4_compress_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)-1); } static int local_LZ4_compress_fast(const char* in, char* out, int inSize) @@ -399,7 +399,7 @@ static int local_LZ4_compress_withState(const char* in, char* out, int inSize) static int local_LZ4_compress_limitedOutput_withState(const char* in, char* out, int inSize) { - return LZ4_compress_limitedOutput_withState(stateLZ4, in, out, inSize, LZ4_compressBound(inSize)); + return LZ4_compress_limitedOutput_withState(stateLZ4, in, out, inSize, LZ4_compressBound(inSize)-1); } static LZ4_stream_t* ctx; @@ -410,7 +410,7 @@ static int local_LZ4_compress_continue(const char* in, char* out, int inSize) static int local_LZ4_compress_limitedOutput_continue(const char* in, char* out, int inSize) { - return LZ4_compress_limitedOutput_continue(ctx, in, out, inSize, LZ4_compressBound(inSize)); + return LZ4_compress_limitedOutput_continue(ctx, in, out, inSize, LZ4_compressBound(inSize)-1); } @@ -437,12 +437,12 @@ static int local_LZ4_compressHC_withStateHC(const char* in, char* out, int inSiz static int local_LZ4_compressHC_limitedOutput_withStateHC(const char* in, char* out, int inSize) { - return LZ4_compressHC_limitedOutput_withStateHC(stateLZ4HC, in, out, inSize, LZ4_compressBound(inSize)); + return LZ4_compressHC_limitedOutput_withStateHC(stateLZ4HC, in, out, inSize, LZ4_compressBound(inSize)-1); } static int local_LZ4_compressHC_limitedOutput(const char* in, char* out, int inSize) { - return LZ4_compressHC_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)); + return LZ4_compressHC_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)-1); } static int local_LZ4_compressHC_continue(const char* in, char* out, int inSize) @@ -452,7 +452,7 @@ static int local_LZ4_compressHC_continue(const char* in, char* out, int inSize) static int local_LZ4_compressHC_limitedOutput_continue(const char* in, char* out, int inSize) { - return LZ4_compressHC_limitedOutput_continue((LZ4_streamHC_t*)ctx, in, out, inSize, LZ4_compressBound(inSize)); + return LZ4_compressHC_limitedOutput_continue((LZ4_streamHC_t*)ctx, in, out, inSize, LZ4_compressBound(inSize)-1); } static int local_LZ4F_compressFrame(const char* in, char* out, int inSize) @@ -477,7 +477,6 @@ static int local_LZ4_saveDictHC(const char* in, char* out, int inSize) static int local_LZ4_decompress_fast(const char* in, char* out, int inSize, int outSize) { (void)inSize; - //lz4_decode_sse((BYTE*)out, (BYTE*)in, inSize); LZ4_decompress_fast(in, out, outSize); return outSize; } @@ -617,11 +616,11 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) return 13; } - // Calculating input Checksum + /* Calculating input Checksum */ crcOriginal = XXH32(orig_buff, (unsigned int)benchedSize,0); - // Bench + /* Bench */ { int loopNb, nb_loops, chunkNb, cAlgNb, dAlgNb; size_t cSize=0; @@ -638,7 +637,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) void* (*initFunction)(const char*) = NULL; double bestTime = 100000000.; - // Init data chunks + /* Init data chunks */ { int i; size_t remaining = benchedSize; @@ -691,7 +690,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) int milliTime; PROGRESS("%1i- %-28.28s :%9i ->\r", loopNb, compressorName, (int)benchedSize); - { size_t i; for (i=0; i Date: Wed, 1 Apr 2015 15:47:24 -0300 Subject: Cygwin has fileno, so there's no need to use _fileno. --- programs/lz4cli.c | 2 +- programs/lz4io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index da5da71..888f21e 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -65,7 +65,7 @@ /**************************** * OS-specific Includes *****************************/ -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) # include /* _isatty */ # ifdef __MINGW32__ int _fileno(FILE *stream); /* MINGW somehow forgets to include this prototype into */ diff --git a/programs/lz4io.c b/programs/lz4io.c index 02e03c8..0cf6293 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -61,7 +61,7 @@ /****************************** * OS-specific Includes ******************************/ -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) # include /* _O_BINARY */ # include /* _setmode, _fileno, _get_osfhandle */ # define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY) -- cgit v0.12 From 90c0104c4eaf8f06932990aacf07e60dd21685b9 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 2 Apr 2015 13:25:28 +0100 Subject: Added : progress indicator, in fast and decompression modes --- programs/lz4io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 02e03c8..0d931fe 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -412,7 +412,6 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena /* Init */ start = clock(); memset(&prefs, 0, sizeof(prefs)); - if ((g_displayLevel==2) && (compressionLevel>=3)) g_displayLevel=3; errorCode = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION); if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); get_fileHandle(input_filename, output_filename, &finput, &foutput); @@ -428,6 +427,8 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena { unsigned long long fileSize = LZ4IO_GetFileSize(input_filename); prefs.frameInfo.contentSize = fileSize; /* == 0 if input == stdin */ + if (fileSize==0) + DISPLAYLEVEL(3, "Warning : cannot determine uncompressed frame content size \n"); } /* Allocate Memory */ @@ -456,7 +457,7 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena outSize = LZ4F_compressUpdate(ctx, out_buff, outBuffSize, in_buff, readSize, NULL); if (LZ4F_isError(outSize)) EXM_THROW(34, "Compression failed : %s", LZ4F_getErrorName(outSize)); compressedfilesize += outSize; - DISPLAYUPDATE(3, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100); + DISPLAYUPDATE(2, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100); /* Write Block */ sizeCheck = fwrite(out_buff, 1, outSize, foutput); @@ -639,6 +640,7 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) { /* Write Block */ filesize += decodedBytes; + DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20)); if (g_sparseFileSupport) { size_t* const oBuffStartT = (size_t*)outBuff; /* since outBuff is malloc'ed, it's aligned on size_t */ -- cgit v0.12 From f72761ff44ebeeb5deb19ac588ff4e3905148758 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 2 Apr 2015 15:11:22 +0100 Subject: new tests for large files with content size support (#70) --- programs/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/programs/Makefile b/programs/Makefile index 0cebdfe..9a1bade 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -171,6 +171,11 @@ test-lz4-contentSize: lz4 datagen ./lz4 -v tmp | ./lz4 -t ./lz4 -v --content-size tmp | ./lz4 -d > tmp2 diff -s tmp tmp2 + # test large size [2-4] GB + @./datagen -g3G -P100 | ./lz4 | ./lz4 --decompress --force --sparse - tmp + @ls -ls tmp + ./lz4 --quiet --content-size tmp | ./lz4 --verbose --decompress --force --sparse - tmp2 + @ls -ls tmp2 @rm tmp* test-lz4-frame-concatenation: lz4 datagen -- cgit v0.12 From dd699026e6680e1828f5f00c1929861e0cdc471e Mon Sep 17 00:00:00 2001 From: Yongwoon Cho Date: Fri, 3 Apr 2015 11:52:50 +0900 Subject: Removed unused lines. --- programs/lz4io.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 02e03c8..e526a95 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -587,8 +587,6 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) unsigned long long filesize = 0; void* inBuff; void* outBuff; -# define HEADERMAX 20 - char headerBuff[HEADERMAX]; size_t sizeCheck; const size_t inBuffSize = 256 KB; const size_t outBuffSize = 256 KB; @@ -599,7 +597,6 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) /* init */ errorCode = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create context : %s", LZ4F_getErrorName(errorCode)); - LZ4IO_writeLE32(headerBuff, LZ4IO_MAGICNUMBER); /* regenerated here, as it was already read from finput */ /* Allocate Memory */ inBuff = malloc(256 KB); -- cgit v0.12 From 979a991badffa8359232a6b7b74756a9821d2053 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 3 Apr 2015 23:58:29 +0100 Subject: memcpy speed as reference --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 453bb01..6de310a 100644 --- a/README.md +++ b/README.md @@ -41,15 +41,11 @@ in single-thread mode. | Compressor | Ratio | Compression | Decompression | | ---------- | ----- | ----------- | ------------- | | memcpy | 1.000 | 4200 MB/s | 4200 MB/s | -| RLE64 v3.0 | 1.029 | 2800 MB/s | 2800 MB/s | -| density -c1 | 1.592 | 700 MB/s | 920 MB/s | |**LZ4 fast (r129)**| 1.607 |**680 MB/s** | **2220 MB/s** | |**LZ4 (r129)** |**2.101**|**385 MB/s** | **1850 MB/s** | -| density -c2 | 2.083 | 370 MB/s | 505 MB/s | | LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | | QuickLZ 1.5.1.b6 | 2.238 | 320 MB/s | 380 MB/s | | Snappy 1.1.0 | 2.091 | 250 MB/s | 960 MB/s | -| density -c3 | 2.370 | 190 MB/s | 185 MB/s | | zlib 1.2.8 -1 | 2.730 | 59 MB/s | 250 MB/s | |**LZ4 HC (r129)** |**2.720**| 22 MB/s | **1830 MB/s** | | zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | -- cgit v0.12 From 17f86149c52a3a3c131c23f2b6452f172d9364a6 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 6 Apr 2015 01:02:24 +0100 Subject: added : memtest on fullbench --- programs/Makefile | 3 ++- programs/fullbench.c | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 9a1bade..3ca46d7 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -243,13 +243,14 @@ test-frametest: frametest test-frametest32: frametest32 ./frametest32 -test-mem: lz4 datagen fuzzer frametest +test-mem: lz4 datagen fuzzer frametest fullbench valgrind --leak-check=yes ./datagen -g50M > $(VOID) ./datagen -g16KB > tmp valgrind --leak-check=yes ./lz4 -9 -BD -f tmp $(VOID) ./datagen -g16MB > tmp valgrind --leak-check=yes ./lz4 -9 -B5D -f tmp tmp2 valgrind --leak-check=yes ./lz4 -t tmp2 + valgrind --leak-check=yes ./fullbench -i1 tmp ./datagen -g256MB > tmp valgrind --leak-check=yes ./lz4 -B4D -f -vq tmp $(VOID) rm tmp* diff --git a/programs/fullbench.c b/programs/fullbench.c index 41075bc..7c970e0 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -541,12 +541,6 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) double totalDTime[NB_DECOMPRESSION_ALGORITHMS+1] = {0}; size_t errorCode; - errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION); - if (LZ4F_isError(errorCode)) - { - DISPLAY("dctx allocation issue \n"); - return 10; - } /* Loop for each fileName */ while (fileIdx Date: Mon, 6 Apr 2015 01:03:49 +0100 Subject: updated doc --- README.md | 11 +++++------ lz4_Frame_format.md | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6de310a..bcb8d7c 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,12 @@ in single-thread mode. |**LZ4 HC (r129)** |**2.720**| 22 MB/s | **1830 MB/s** | | zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | -The LZ4 block compression format is detailed within [lz4_Block_format]. +The raw LZ4 block compression format is detailed within [lz4_Block_format]. -Block format doesn't deal with header information, -nor how to handle arbitrarily long files or data streams. -This is the purpose of the Frame format. -Interoperable versions of LZ4 should use the same frame format, -defined into [lz4_Frame_format]. +Compressing an arbitrarily long file or data stream requires multiple blocks. +Organizing these blocks and providing a common header format to handle their content +is the purpose of the Frame format, defined into [lz4_Frame_format]. +Interoperable versions of LZ4 must respect this frame format too. [Open-Source Benchmark program by m^2 (v0.14.3)]: http://encode.ru/threads/1371-Filesystem-benchmark?p=34029&viewfull=1#post34029 [Silesia Corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia diff --git a/lz4_Frame_format.md b/lz4_Frame_format.md index 55edaa0..cb41d47 100644 --- a/lz4_Frame_format.md +++ b/lz4_Frame_format.md @@ -341,8 +341,8 @@ Data is always compressed, even when compression is detrimental. __EndMark__ -End of compressed stream is implicit. -It needs to be followed by a standard EOF (End Of File) signal, +End of legacy frame is implicit only. +It must be followed by a standard EOF (End Of File) signal, wether it is a file or a stream. Alternatively, if the frame is followed by a valid Frame Magic Number, -- cgit v0.12 From 43e053513bb2386b526daad5621e29a817663691 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 7 Apr 2015 07:14:32 +0100 Subject: fix g++ typecast --- programs/fullbench.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/fullbench.c b/programs/fullbench.c index 7c970e0..2f246a2 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -391,7 +391,7 @@ static int local_LZ4_compress_fast(const char* in, char* out, int inSize) return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 0); } -static void* stateLZ4; +static LZ4_stream_t* stateLZ4; static int local_LZ4_compress_withState(const char* in, char* out, int inSize) { return LZ4_compress_withState(stateLZ4, in, out, inSize); @@ -429,7 +429,7 @@ static int local_LZ4_compress_forceDict(const char* in, char* out, int inSize) } -static void* stateLZ4HC; +static LZ4_streamHC_t* stateLZ4HC; static int local_LZ4_compressHC_withStateHC(const char* in, char* out, int inSize) { return LZ4_compressHC_withStateHC(stateLZ4HC, in, out, inSize); -- cgit v0.12 From 327cb04f44a650afd3907701513b1c2e851a3b45 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 8 Apr 2015 09:20:21 +0100 Subject: minor memory leak fix and test --- programs/Makefile | 1 + programs/lz4cli.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/programs/Makefile b/programs/Makefile index 3ca46d7..9585c9f 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -250,6 +250,7 @@ test-mem: lz4 datagen fuzzer frametest fullbench ./datagen -g16MB > tmp valgrind --leak-check=yes ./lz4 -9 -B5D -f tmp tmp2 valgrind --leak-check=yes ./lz4 -t tmp2 + valgrind --leak-check=yes ./lz4 -bi1 tmp valgrind --leak-check=yes ./fullbench -i1 tmp ./datagen -g256MB > tmp valgrind --leak-check=yes ./lz4 -B4D -f -vq tmp $(VOID) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 888f21e..2870c97 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -470,7 +470,12 @@ int main(int argc, char** argv) if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) badusage(); /* Check if benchmark is selected */ - if (bench) return BMK_benchFiles(inFileNames, ifnIdx, cLevel); + if (bench) + { + int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel); + free(inFileNames); + return bmkResult; + } /* No output filename ==> try to select one automatically (when possible) */ while (!output_filename) -- cgit v0.12 From b41137f42a59e6636a02c61f49b67bde7876d4c4 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 8 Apr 2015 09:33:57 +0100 Subject: minor Makefile test refactoring --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 284972f..831f0d3 100644 --- a/Makefile +++ b/Makefile @@ -98,17 +98,17 @@ cmake: @cd cmake_unofficial; cmake CMakeLists.txt; $(MAKE) gpptest: clean - export CC=g++; export CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"; $(MAKE) -e all + $(MAKE) all CC=g++ CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror" clangtest: clean - export CFLAGS=-Werror; export CC=clang; $(MAKE) all + $(MAKE) all CC=clang CFLAGS="-O3 -Werror" staticAnalyze: clean - export CFLAGS=-g; scan-build -v $(MAKE) all + scan-build -v $(MAKE) all CFLAGS=-g armtest: clean - export CFLAGS=-Werror; export CC=arm-linux-gnueabi-gcc; cd lib; $(MAKE) -e all - export CFLAGS=-Werror; export CC=arm-linux-gnueabi-gcc; cd programs; $(MAKE) -e bins + cd lib; $(MAKE) -e all CC=arm-linux-gnueabi-gcc CFLAGS="-O3 -Werror" + cd programs; $(MAKE) -e bins CC=arm-linux-gnueabi-gcc CFLAGS="-O3 -Werror" streaming-examples: cd examples; $(MAKE) -e test -- cgit v0.12 From 1853622360cdd1adf4786f00dc18412e93a352fd Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 8 Apr 2015 10:35:38 +0100 Subject: fixed over-cautious visual warning --- programs/lz4cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 2870c97..47cf7e0 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -473,7 +473,7 @@ int main(int argc, char** argv) if (bench) { int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel); - free(inFileNames); + free((void*)inFileNames); return bmkResult; } -- cgit v0.12 From 2f8a4c32f998e6440a0b580996ecf8f101df2c74 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 9 Apr 2015 13:34:38 +0100 Subject: New LZ4_compress_safe() API --- lib/lz4.c | 39 ++++++++++++----------------- lib/lz4.h | 85 +++++++++++++++++++++++++++------------------------------------ 2 files changed, 53 insertions(+), 71 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index a06f711..9d7e5b6 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -739,14 +739,14 @@ _last_literals: } -int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize) +int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize) { MEM_INIT(state, 0, LZ4_STREAMSIZE); if (maxOutputSize >= LZ4_compressBound(inputSize)) { if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); else return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); } @@ -759,12 +759,7 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* } } -int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize) -{ - return LZ4_compress_limitedOutput_withState(state, source, dest, inputSize, LZ4_compressBound(inputSize)); -} - -int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) +int LZ4_compress_safe(const char* source, char* dest, int inputSize, int maxOutputSize) { #if (HEAPMODE) void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* malloc-calloc aligned on 8-bytes boundaries */ @@ -772,7 +767,7 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ #endif - int result = LZ4_compress_limitedOutput_withState(ctx, source, dest, inputSize, maxOutputSize); + int result = LZ4_compress_safe_extState(ctx, source, dest, inputSize, maxOutputSize); #if (HEAPMODE) FREEMEM(ctx); @@ -780,11 +775,6 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in return result; } -int LZ4_compress(const char* source, char* dest, int inputSize) -{ - return LZ4_compress_limitedOutput(source, dest, inputSize, LZ4_compressBound(inputSize)); -} - int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) { @@ -798,14 +788,14 @@ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutp if (acceleration == 0) { if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); else result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); } else { if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); else result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); } @@ -899,7 +889,7 @@ static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src) } -int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) +int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) { LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_stream; const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; @@ -948,13 +938,8 @@ int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* s } } -int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) -{ - return LZ4_compress_limitedOutput_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize)); -} - -/* Hidden debug function, to force separate dictionary mode */ +/* Hidden debug function, to force external dictionary mode */ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize) { LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_dict; @@ -1347,6 +1332,14 @@ int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compres /*************************************************** * Obsolete Functions ***************************************************/ +/* obsolete compression functions */ +int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_safe(source, dest, inputSize, maxOutputSize); } +int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_safe(source, dest, inputSize, LZ4_compressBound(inputSize)); } +int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_safe_extState(state, src, dst, srcSize, dstSize); } +int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_safe_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize)); } +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_safe_continue(LZ4_stream, source, dest, inputSize, maxOutputSize); } +int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_safe_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize)); } + /* These function names are deprecated and should no longer be used. They are only provided here for compatibility with older user programs. diff --git a/lib/lz4.h b/lib/lz4.h index 81a11c9..659866b 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -70,18 +70,24 @@ int LZ4_versionNumber (void); * Simple Functions **************************************/ -int LZ4_compress (const char* source, char* dest, int sourceSize); +int LZ4_compress_safe (const char* source, char* dest, int sourceSize, int maxOutputSize); int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize); /* -LZ4_compress() : - Compresses 'sourceSize' bytes from 'source' into 'dest'. - Destination buffer must be already allocated, - and must be sized to handle worst cases situations (input data not compressible) - Worst case size evaluation is provided by function LZ4_compressBound() - inputSize : Max supported value is LZ4_MAX_INPUT_SIZE - return : the number of bytes written in buffer dest - or 0 if the compression fails +LZ4_compress_limitedOutput() : + Compresses 'sourceSize' bytes from buffer 'source' + into already allocated 'dest' of size 'maxOutputSize'. + Compression runs faster when 'maxOutputSize' >= LZ4_compressBound(sourceSize). + That's because in such case, it is guaranteed to compress within 'dest' budget, even in worst case scenario. + Compressing into a more limited space budget requires additional checks. + If the function cannot compress 'source' into a limited 'dest' budget, + compression stops *immediately*, and result of the function is zero. + It greatly accelerates behavior on non-compressible input, but as a consequence, 'dest' content is not valid either. + This function never writes outside 'dest' buffer, nor read outside 'source' buffer. + sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE + maxOutputSize : full or partial size of buffer 'dest' (which must be already allocated) + return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize) + or 0 if compression fails LZ4_decompress_safe() : compressedSize : is obviously the source size @@ -89,9 +95,8 @@ LZ4_decompress_safe() : return : the number of bytes decompressed into the destination buffer (necessarily <= maxDecompressedSize) If the destination buffer is not large enough, decoding will stop and output an error code (<0). If the source stream is detected malformed, the function will stop decoding and return a negative result. - This function is protected against buffer overflow exploits, - and never writes outside of output buffer, nor reads outside of input buffer. - It is also protected against malicious data packets. + This function is protected against buffer overflow exploits, including malicious data packets. + It never writes outside of output buffer, nor reads outside of input buffer. */ @@ -113,22 +118,6 @@ LZ4_compressBound() : */ int LZ4_compressBound(int inputSize); - -/* -LZ4_compress_limitedOutput() : - Compress 'sourceSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'. - If it cannot achieve it, compression will stop, and result of the function will be zero. - This saves time and memory on detecting non-compressible (or barely compressible) data. - This function never writes outside of provided output buffer. - - sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE - maxOutputSize : is the size of the destination buffer (which must be already allocated) - return : the number of bytes written in buffer 'dest' - or 0 if compression fails -*/ -int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); - - /* LZ4_compress_fast() : Same as LZ4_compress_limitedOutput, but allows to select an "acceleration" factor. @@ -138,17 +127,15 @@ LZ4_compress_fast() : */ int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); - /* -LZ4_compress_withState() : - Same compression functions, but using an externally allocated memory space to store compression state. +LZ4_compress_safe_withState() : + Same compression function, just using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, and then, provide it as 'void* state' to compression functions. - Note that 'state' must be aligned on 4-bytes boundaries. + Note that 'state' ptr must be aligned on 4-bytes boundaries. */ 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); +int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); /* @@ -164,7 +151,6 @@ LZ4_decompress_fast() : */ int LZ4_decompress_fast (const char* source, char* dest, int originalSize); - /* LZ4_decompress_safe_partial() : This function decompress a compressed block of size 'compressedSize' at position 'source' @@ -220,19 +206,14 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_streamPtr); int LZ4_loadDict (LZ4_stream_t* LZ4_streamPtr, const char* dictionary, int dictSize); /* - * LZ4_compress_continue - * Compress data block 'source', using blocks compressed before as dictionary to improve compression ratio - * Previous data blocks are assumed to still be present at their previous location. - * dest buffer must be already allocated, and sized to at least LZ4_compressBound(inputSize) + * LZ4_compress_safe_continue + * Compress data block 'source', using data from previous blocks to improve compression ratio. + * Important : Previous data blocks are assumed to still be present and unmodified ! + * dest buffer must be already allocated. + * if maxOutpuSize >= (inputSize), compression is guaranteed to succeed. + * if not, and if target size objective cannot be met, compression stops, and function returns a zero. */ -int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); - -/* - * LZ4_compress_limitedOutput_continue - * Same as before, but also specify a maximum target compressed size (maxOutputSize) - * If objective cannot be met, compression exits, and returns a zero. - */ -int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); /* * LZ4_saveDict @@ -299,6 +280,15 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS /************************************** * Obsolete Functions **************************************/ + +/* Obsolete compression functions */ +int LZ4_compress (const char* source, char* dest, int sourceSize); +int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); +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); +int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); + /* Obsolete decompression functions These function names are deprecated and should no longer be used. @@ -310,7 +300,6 @@ It is highly recommended to stop using these functions and migrate to newer ones /* int LZ4_uncompress (const char* source, char* dest, int outputSize); */ /* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */ - /* Obsolete streaming functions; use new streaming interface whenever possible */ void* LZ4_create (const char* inputBuffer); int LZ4_sizeofStreamState(void); -- cgit v0.12 From f344fbd3ca1a0a32668737e79bfdb06f3fadbba7 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 9 Apr 2015 22:59:07 +0100 Subject: Fixed a few warnings from -fsanitize=undefined --- lib/lz4.c | 132 +++++++++++------------------------------------------- lib/lz4frame.c | 17 +++---- lib/xxhash.c | 41 ++++++----------- programs/bench.c | 6 +-- programs/lz4cli.c | 10 +++-- programs/lz4io.c | 9 +++- 6 files changed, 67 insertions(+), 148 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 9d7e5b6..6ed6ab3 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -34,7 +34,7 @@ /************************************** - Tuning parameters +* Tuning parameters **************************************/ /* * HEAPMODE : @@ -49,52 +49,11 @@ */ #define ACCELERATION_DEFAULT 17 -/* - * CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS : - * By default, the source code expects the compiler to correctly optimize - * 4-bytes and 8-bytes read on architectures able to handle it efficiently. - * This is not always the case. In some circumstances (ARM notably), - * the compiler will issue cautious code even when target is able to correctly handle unaligned memory accesses. - * - * You can force the compiler to use unaligned memory access by uncommenting the line below. - * One of the below scenarios will happen : - * 1 - Your target CPU correctly handle unaligned access, and was not well optimized by compiler (good case). - * You will witness large performance improvements (+50% and up). - * Keep the line uncommented and send a word to upstream (https://groups.google.com/forum/#!forum/lz4c) - * The goal is to automatically detect such situations by adding your target CPU within an exception list. - * 2 - Your target CPU correctly handle unaligned access, and was already already optimized by compiler - * No change will be experienced. - * 3 - Your target CPU inefficiently handle unaligned access. - * You will experience a performance loss. Comment back the line. - * 4 - Your target CPU does not handle unaligned access. - * Program will crash. - * If uncommenting results in better performance (case 1) - * please report your configuration to upstream (https://groups.google.com/forum/#!forum/lz4c) - * This way, an automatic detection macro can be added to match your case within later versions of the library. - */ -/* #define CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS 1 */ - /************************************** - CPU Feature Detection +* CPU Feature Detection **************************************/ /* - * Automated efficient unaligned memory access detection - * Based on known hardware architectures - * This list will be updated thanks to feedbacks - */ -#if defined(CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS) \ - || defined(__ARM_FEATURE_UNALIGNED) \ - || defined(__i386__) || defined(__x86_64__) \ - || defined(_M_IX86) || defined(_M_X64) \ - || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_8__) \ - || (defined(_M_ARM) && (_M_ARM >= 7)) -# define LZ4_UNALIGNED_ACCESS 1 -#else -# define LZ4_UNALIGNED_ACCESS 0 -#endif - -/* * LZ4_FORCE_SW_BITCOUNT * Define this parameter if your target system or compiler does not support hardware bit count */ @@ -142,7 +101,7 @@ /************************************** - Memory routines +* Memory routines **************************************/ #include /* malloc, calloc, free */ #define ALLOCATOR(n,s) calloc(n,s) @@ -152,13 +111,13 @@ /************************************** - Includes +* Includes **************************************/ #include "lz4.h" /************************************** - Basic Types +* Basic Types **************************************/ #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ # include @@ -177,7 +136,7 @@ /************************************** - Reading and writing into memory +* Reading and writing into memory **************************************/ #define STEPSIZE sizeof(size_t) @@ -190,10 +149,19 @@ static unsigned LZ4_isLittleEndian(void) } +static U16 LZ4_read16(const void* memPtr) +{ + U16 val16; + memcpy(&val16, memPtr, 2); + return val16; +} + static U16 LZ4_readLE16(const void* memPtr) { - if ((LZ4_UNALIGNED_ACCESS) && (LZ4_isLittleEndian())) - return *(U16*)memPtr; + if (LZ4_isLittleEndian()) + { + return LZ4_read16(memPtr); + } else { const BYTE* p = (const BYTE*)memPtr; @@ -203,10 +171,9 @@ static U16 LZ4_readLE16(const void* memPtr) static void LZ4_writeLE16(void* memPtr, U16 value) { - if ((LZ4_UNALIGNED_ACCESS) && (LZ4_isLittleEndian())) + if (LZ4_isLittleEndian()) { - *(U16*)memPtr = value; - return; + memcpy(memPtr, &value, 2); } else { @@ -216,41 +183,18 @@ static void LZ4_writeLE16(void* memPtr, U16 value) } } - -static U16 LZ4_read16(const void* memPtr) -{ - if (LZ4_UNALIGNED_ACCESS) - return *(U16*)memPtr; - else - { - U16 val16; - memcpy(&val16, memPtr, 2); - return val16; - } -} - static U32 LZ4_read32(const void* memPtr) { - if (LZ4_UNALIGNED_ACCESS) - return *(U32*)memPtr; - else - { - U32 val32; - memcpy(&val32, memPtr, 4); - return val32; - } + U32 val32; + memcpy(&val32, memPtr, 4); + return val32; } static U64 LZ4_read64(const void* memPtr) { - if (LZ4_UNALIGNED_ACCESS) - return *(U64*)memPtr; - else - { - U64 val64; - memcpy(&val64, memPtr, 8); - return val64; - } + U64 val64; + memcpy(&val64, memPtr, 8); + return val64; } static size_t LZ4_read_ARCH(const void* p) @@ -262,31 +206,9 @@ static size_t LZ4_read_ARCH(const void* p) } -static void LZ4_copy4(void* dstPtr, const void* srcPtr) -{ - if (LZ4_UNALIGNED_ACCESS) - { - *(U32*)dstPtr = *(U32*)srcPtr; - return; - } - memcpy(dstPtr, srcPtr, 4); -} +static void LZ4_copy4(void* dstPtr, const void* srcPtr) { memcpy(dstPtr, srcPtr, 4); } -static void LZ4_copy8(void* dstPtr, const void* srcPtr) -{ -#if GCC_VERSION!=409 /* disabled on GCC 4.9, as it generates invalid opcode (crash) */ - if (LZ4_UNALIGNED_ACCESS) - { - if (LZ4_64bits()) - *(U64*)dstPtr = *(U64*)srcPtr; - else - ((U32*)dstPtr)[0] = ((U32*)srcPtr)[0], - ((U32*)dstPtr)[1] = ((U32*)srcPtr)[1]; - return; - } -#endif - memcpy(dstPtr, srcPtr, 8); -} +static void LZ4_copy8(void* dstPtr, const void* srcPtr) { memcpy(dstPtr, srcPtr, 8); } /* customized version of memcpy, which may overwrite up to 7 bytes beyond dstEnd */ static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 6c65d0b..b6dbd20 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -130,6 +130,7 @@ typedef struct LZ4F_frameInfo_t frameInfo; U32 version; U32 dStage; + U64 frameRemainingSize; size_t maxBlockSize; size_t maxBufferSize; const BYTE* srcExpect; @@ -187,7 +188,7 @@ static U32 LZ4F_readLE32 (const BYTE* srcPtr) U32 value32 = srcPtr[0]; value32 += (srcPtr[1]<<8); value32 += (srcPtr[2]<<16); - value32 += (srcPtr[3]<<24); + value32 += ((U32)srcPtr[3])<<24; return value32; } @@ -302,7 +303,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf prefs.frameInfo.contentSize = (U64)srcSize; } if (prefs.frameInfo.contentSize != 0) - prefs.frameInfo.contentSize = (U64)srcSize; /* correct content size if selected (!=0) */ + prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ if (prefs.compressionLevel < minHClevel) { @@ -871,7 +872,7 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo dctxPtr->frameInfo.blockSizeID = (blockSizeID_t)blockSizeID; dctxPtr->maxBlockSize = LZ4F_getBlockSize(blockSizeID); if (contentSizeFlag) - dctxPtr->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6); + dctxPtr->frameRemainingSize = dctxPtr->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6); /* init */ if (contentChecksumFlag) XXH32_reset(&(dctxPtr->xxh), 0); @@ -1158,7 +1159,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, if ((size_t)(dstEnd-dstPtr) < sizeToCopy) sizeToCopy = dstEnd - dstPtr; memcpy(dstPtr, srcPtr, sizeToCopy); if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), srcPtr, sizeToCopy); - if (dctxPtr->frameInfo.contentSize) dctxPtr->frameInfo.contentSize -= sizeToCopy; + if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= sizeToCopy; /* dictionary management */ if (dctxPtr->frameInfo.blockMode==blockLinked) @@ -1231,7 +1232,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, decodedSize = decoder((const char*)selectedIn, (char*)dstPtr, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize); if (decodedSize < 0) return (size_t)-ERROR_GENERIC; /* decompression failed */ if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dstPtr, decodedSize); - if (dctxPtr->frameInfo.contentSize) dctxPtr->frameInfo.contentSize -= decodedSize; + if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= decodedSize; /* dictionary management */ if (dctxPtr->frameInfo.blockMode==blockLinked) @@ -1277,7 +1278,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, decodedSize = decoder((const char*)selectedIn, (char*)dctxPtr->tmpOut, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize); if (decodedSize < 0) return (size_t)-ERROR_decompressionFailed; /* decompression failed */ if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dctxPtr->tmpOut, decodedSize); - if (dctxPtr->frameInfo.contentSize) dctxPtr->frameInfo.contentSize -= decodedSize; + if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= decodedSize; dctxPtr->tmpOutSize = decodedSize; dctxPtr->tmpOutStart = 0; dctxPtr->dStage = dstage_flushOut; @@ -1311,7 +1312,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, case dstage_getSuffix: { size_t suffixSize = dctxPtr->frameInfo.contentChecksumFlag * 4; - if (dctxPtr->frameInfo.contentSize) return (size_t)-ERROR_frameSize_wrong; /* incorrect frame size decoded */ + if (dctxPtr->frameRemainingSize) return (size_t)-ERROR_frameSize_wrong; /* incorrect frame size decoded */ if (suffixSize == 0) /* frame completed */ { nextSrcSizeHint = 0; @@ -1392,7 +1393,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, selectedIn = dctxPtr->header + 4; } - /* case dstage_decodeSBlockSize: */ /* no direct access */ + /* case dstage_decodeSFrameSize: */ /* no direct access */ { size_t SFrameSize = LZ4F_readLE32(selectedIn); dctxPtr->frameInfo.contentSize = SFrameSize; diff --git a/lib/xxhash.c b/lib/xxhash.c index aca1e0a..a4a3fbe 100644 --- a/lib/xxhash.c +++ b/lib/xxhash.c @@ -117,35 +117,20 @@ typedef signed int S32; typedef unsigned long long U64; #endif -#if defined(__GNUC__) && !defined(XXH_USE_UNALIGNED_ACCESS) -# define _PACKED __attribute__ ((packed)) -#else -# define _PACKED -#endif - -#if !defined(XXH_USE_UNALIGNED_ACCESS) && !defined(__GNUC__) -# ifdef __IBMC__ -# pragma pack(1) -# else -# pragma pack(push, 1) -# endif -#endif - -typedef struct _U32_S -{ - U32 v; -} _PACKED U32_S; -typedef struct _U64_S +static U32 XXH_read32(const void* memPtr) { - U64 v; -} _PACKED U64_S; + U32 val32; + memcpy(&val32, memPtr, 4); + return val32; +} -#if !defined(XXH_USE_UNALIGNED_ACCESS) && !defined(__GNUC__) -# pragma pack(pop) -#endif +static U64 XXH_read64(const void* memPtr) +{ + U64 val64; + memcpy(&val64, memPtr, 8); + return val64; +} -#define A32(x) (((U32_S *)(x))->v) -#define A64(x) (((U64_S *)(x))->v) /***************************************** @@ -230,7 +215,7 @@ typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment; FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align) { if (align==XXH_unaligned) - return endian==XXH_littleEndian ? A32(ptr) : XXH_swap32(A32(ptr)); + return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr)); else return endian==XXH_littleEndian ? *(U32*)ptr : XXH_swap32(*(U32*)ptr); } @@ -243,7 +228,7 @@ FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian) FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align) { if (align==XXH_unaligned) - return endian==XXH_littleEndian ? A64(ptr) : XXH_swap64(A64(ptr)); + return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr)); else return endian==XXH_littleEndian ? *(U64*)ptr : XXH_swap64(*(U64*)ptr); } diff --git a/programs/bench.c b/programs/bench.c index e1b5357..a5c72d6 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -403,7 +403,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) milliTime = BMK_GetMilliSpan(milliTime); if ((double)milliTime < fastestD*nbLoops) fastestD = (double)milliTime/nbLoops; - DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\r", loopNb, inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); + DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \r", loopNb, inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); /* CRC Checking */ crcCheck = XXH32(orig_buff, (unsigned int)benchedSize,0); @@ -413,9 +413,9 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) if (crcOrig==crcCheck) { if (ratio<100.) - DISPLAY("%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\n", inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); + DISPLAY("%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \n", inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); else - DISPLAY("%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n", inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); + DISPLAY("%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n", inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); } totals += benchedSize; totalz += cSize; diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 47cf7e0..f33ea82 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -420,11 +420,15 @@ int main(int argc, char** argv) /* Modify Nb Iterations (benchmark only) */ case 'i': - if ((argument[1] >='1') && (argument[1] <='9')) { - int iters = argument[1] - '0'; + unsigned iters = 0; + while ((argument[1] >='0') && (argument[1] <='9')) + { + iters *= 10; + iters += argument[1] - '0'; + argument++; + } BMK_setNbIterations(iters); - argument++; } break; diff --git a/programs/lz4io.c b/programs/lz4io.c index 991d9d7..278b766 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -487,8 +487,15 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena /* Final Status */ end = clock(); DISPLAYLEVEL(2, "\r%79s\r", ""); - DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", + if (filesize == 0) + { + DISPLAYLEVEL(2, "Null size input; converted into %u lz4 stream\n", (unsigned)compressedfilesize); + } + else + { + DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", (unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100); + } { double seconds = (double)(end - start)/CLOCKS_PER_SEC; DISPLAYLEVEL(4, "Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024); -- cgit v0.12 From 33134fb6c8aff71375f2a629d4d9856a28d930d6 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 9 Apr 2015 23:53:55 +0100 Subject: Added : sanitize test --- .travis.yml | 1 + Makefile | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8f45f71..398a0f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ env: - LZ4_TRAVIS_CI_ENV=streaming-examples - LZ4_TRAVIS_CI_ENV=cmake - LZ4_TRAVIS_CI_ENV=clangtest + - LZ4_TRAVIS_CI_ENV=sanitize - LZ4_TRAVIS_CI_ENV=staticAnalyze - LZ4_TRAVIS_CI_ENV=gpptest - LZ4_TRAVIS_CI_ENV=armtest diff --git a/Makefile b/Makefile index 831f0d3..ca1f525 100644 --- a/Makefile +++ b/Makefile @@ -103,6 +103,9 @@ gpptest: clean clangtest: clean $(MAKE) all CC=clang CFLAGS="-O3 -Werror" +sanitize: clean + $(MAKE) test CC=clang CFLAGS="-O3 -g -fsanitize=undefined" + staticAnalyze: clean scan-build -v $(MAKE) all CFLAGS=-g -- cgit v0.12 From a2864fd49d801fb8a132fada94d319f96ad26e96 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 10 Apr 2015 14:24:13 +0100 Subject: Fixed a few minor sanitize warnings --- programs/Makefile | 6 +++--- programs/lz4io.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 9585c9f..a394d4b 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -197,11 +197,11 @@ test-lz4: lz4 datagen test-lz4-sparse test-lz4-contentSize test-lz4-frame-concat ./datagen -g16KB | ./lz4 -9 | ./lz4 -t ./datagen | ./lz4 | ./lz4 -t ./datagen -g6M -P99 | ./lz4 -9BD | ./lz4 -t - ./datagen -g17M | ./lz4 -9v | ./lz4 -tq + ./datagen -g17M | ./lz4 -9v | ./lz4 -qt ./datagen -g33M | ./lz4 --no-frame-crc | ./lz4 -t ./datagen -g256MB | ./lz4 -vqB4D | ./lz4 -t - ./datagen -g6GB | ./lz4 -vqB5D | ./lz4 -t - ./datagen -g6GB | ./lz4 -vq9BD | ./lz4 -t + ./datagen -g6GB | ./lz4 -vqB5D | ./lz4 -qt + ./datagen -g6GB | ./lz4 -vq9BD | ./lz4 -qt @echo ---- test multiple input files ---- @./datagen -s1 > file1 @./datagen -s2 > file2 diff --git a/programs/lz4io.c b/programs/lz4io.c index 278b766..4071b1e 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -493,11 +493,9 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena } else { + double seconds = (double)(end - start)/CLOCKS_PER_SEC; DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", (unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100); - } - { - double seconds = (double)(end - start)/CLOCKS_PER_SEC; DISPLAYLEVEL(4, "Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024); } @@ -825,6 +823,7 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file end = clock(); DISPLAYLEVEL(2, "\r%79s\r", ""); DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize); + if (filesize > 0) { double seconds = (double)(end - start)/CLOCKS_PER_SEC; DISPLAYLEVEL(4, "Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024); -- cgit v0.12 From c22a0e1e1387a9a70b47be4ff5dbc67bbab7da16 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 10 Apr 2015 23:42:17 +0100 Subject: Updated : fuzzer tests can be programmed for a timelength --- Makefile | 2 +- programs/Makefile | 32 +++++++++++----------- programs/frametest.c | 50 +++++++++++++++++++++++++++++----- programs/fuzzer.c | 77 ++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 114 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index ca1f525..32f38aa 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ clangtest: clean $(MAKE) all CC=clang CFLAGS="-O3 -Werror" sanitize: clean - $(MAKE) test CC=clang CFLAGS="-O3 -g -fsanitize=undefined" + $(MAKE) test CC=clang CFLAGS="-O3 -g -fsanitize=undefined" FUZZER_TIME="-T5mn" staticAnalyze: clean scan-build -v $(MAKE) all CFLAGS=-g diff --git a/programs/Makefile b/programs/Makefile index a394d4b..1c9e4b5 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -40,14 +40,11 @@ DESTDIR?= PREFIX ?= /usr/local CFLAGS ?= -O3 CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\" -FLAGS = -I../lib $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) +FLAGS := -I../lib $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -BINDIR=$(PREFIX)/bin -MANDIR=$(PREFIX)/share/man/man1 -LZ4DIR=../lib - -TEST_FILES = COPYING -TEST_TARGETS=test-native +BINDIR := $(PREFIX)/bin +MANDIR := $(PREFIX)/share/man/man1 +LZ4DIR := ../lib # Define *.exe as extension for Windows systems @@ -61,7 +58,10 @@ endif # Select test target for Travis CI's Build Matrix -TRAVIS_TARGET=$(LZ4_TRAVIS_CI_ENV) +TRAVIS_TARGET:= $(LZ4_TRAVIS_CI_ENV) +TEST_FILES := COPYING +TEST_TARGETS := test-native +FUZZER_TIME ?= -T20mn default: lz4 @@ -220,10 +220,10 @@ test-lz4c32: lz4 lz4c32 datagen ./datagen -g16KB | ./lz4c32 -9 | ./lz4 -t ./datagen | ./lz4c32 | ./lz4c32 -t ./datagen | ./lz4c32 | ./lz4 -t - ./datagen -g256MB | ./lz4c32 -vqB4D | ./lz4c32 -t - ./datagen -g256MB | ./lz4c32 -vqB4D | ./lz4 -t - ./datagen -g6GB | ./lz4c32 -vqB5D | ./lz4c32 -t - ./datagen -g6GB | ./lz4c32 -vq9BD | ./lz4 -t + ./datagen -g256MB | ./lz4c32 -vqB4D | ./lz4c32 -qt + ./datagen -g256MB | ./lz4c32 -vqB4D | ./lz4 -qt + ./datagen -g6GB | ./lz4c32 -vqB5D | ./lz4c32 -qt + ./datagen -g6GB | ./lz4c32 -vq9BD | ./lz4 -qt test-fullbench: fullbench ./fullbench --no-prompt $(TEST_FILES) @@ -232,16 +232,16 @@ test-fullbench32: fullbench32 ./fullbench32 --no-prompt $(TEST_FILES) test-fuzzer: fuzzer - ./fuzzer + ./fuzzer $(FUZZER_TIME) test-fuzzer32: fuzzer32 - ./fuzzer32 + ./fuzzer32 $(FUZZER_TIME) test-frametest: frametest - ./frametest + ./frametest $(FUZZER_TIME) test-frametest32: frametest32 - ./frametest32 + ./frametest32 $(FUZZER_TIME) test-mem: lz4 datagen fuzzer frametest fullbench valgrind --leak-check=yes ./datagen -g50M > $(VOID) diff --git a/programs/frametest.c b/programs/frametest.c index 4beee23..5fccd08 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -537,7 +537,7 @@ static void locateBuffDiff(const void* buff1, const void* buff2, size_t size, un static const U32 srcDataLength = 9 MB; /* needs to be > 2x4MB to test large blocks */ -int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressibility) +int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressibility, U32 duration) { unsigned testResult = 0; unsigned testNb = 0; @@ -548,10 +548,15 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi LZ4F_decompressionContext_t dCtx = NULL; LZ4F_compressionContext_t cCtx = NULL; size_t result; + const U32 startTime = FUZ_GetMilliStart(); XXH64_state_t xxh64; # define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \ DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; } + + /* Init */ + duration *= 1000; + /* Create buffers */ result = LZ4F_createDecompressionContext(&dCtx, LZ4F_VERSION); CHECK(LZ4F_isError(result), "Allocation failed (error %i)", (int)result); @@ -566,10 +571,10 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi FUZ_fillCompressibleNoiseBuffer(srcBuffer, srcDataLength, compressibility, &coreRand); /* jump to requested testNb */ - for (testNb =0; testNb < startTest; testNb++) (void)FUZ_rand(&coreRand); // sync randomizer + for (testNb =0; (testNb < startTest); testNb++) (void)FUZ_rand(&coreRand); // sync randomizer /* main fuzzer test loop */ - for ( ; testNb < nbTests; testNb++) + for ( ; (testNb < nbTests) || (duration > FUZ_GetMilliSpan(startTime)) ; testNb++) { U32 randState = coreRand ^ prime1; unsigned BSId = 4 + (FUZ_rand(&randState) & 3); @@ -721,6 +726,7 @@ int FUZ_usage(void) DISPLAY( "\n"); DISPLAY( "Arguments :\n"); DISPLAY( " -i# : Nb of tests (default:%u) \n", nbTestsDefault); + DISPLAY( " -T# : Duration of tests (default: use Nb of tests) \n"); DISPLAY( " -s# : Select seed (default:prompt user)\n"); DISPLAY( " -t# : Select starting test number (default:0)\n"); DISPLAY( " -p# : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT); @@ -739,6 +745,7 @@ int main(int argc, char** argv) int testNb = 0; int proba = FUZ_COMPRESSIBILITY_DEFAULT; int result=0; + U32 duration=0; /* Check command line */ programName = argv[0]; @@ -746,9 +753,9 @@ int main(int argc, char** argv) { char* argument = argv[argNb]; - if(!argument) continue; // Protection if argument empty + if(!argument) continue; /* Protection if argument empty */ - // Decode command (note : aggregated commands are allowed) + /* Decode command (note : aggregated commands are allowed) */ if (argument[0]=='-') { if (!strcmp(argument, "--no-prompt")) @@ -781,7 +788,7 @@ int main(int argc, char** argv) case 'i': argument++; - nbTests=0; + nbTests=0; duration=0; while ((*argument>='0') && (*argument<='9')) { nbTests *= 10; @@ -789,6 +796,35 @@ int main(int argc, char** argv) argument++; } break; + + case 'T': + argument++; + nbTests = 0; duration = 0; + + for (;;) + { + if (argument[0]=='m') + { + duration *= 60; + argument++; + continue; + } + if (argument[0]=='n') + { + argument++; + continue; + } + if ((*argument>='0') && (*argument<='9')) + { + duration *= 10; + duration += *argument - '0'; + argument++; + continue; + } + break; + } + break; + case 's': argument++; seed=0; @@ -841,5 +877,5 @@ int main(int argc, char** argv) if (testNb==0) result = basicTests(seed, ((double)proba) / 100); if (result) return 1; - return fuzzerTests(seed, nbTests, testNb, ((double)proba) / 100); + return fuzzerTests(seed, nbTests, testNb, ((double)proba) / 100, duration); } diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 3d3cf8e..9e2ce1e 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -19,7 +19,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. You can contact the author at : - - LZ4 source repository : http://code.google.com/p/lz4 - LZ4 source mirror : https://github.com/Cyan4973/lz4 - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c */ @@ -210,7 +209,7 @@ static int FUZ_AddressOverflow(void) printf("Overflow tests : "); - // Only possible in 32-bits + /* Only possible in 32-bits */ if (sizeof(void*)==8) { printf("64 bits mode : no overflow \n"); @@ -300,7 +299,7 @@ static void FUZ_displayUpdate(unsigned testNb) } -static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const double compressibility) +static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double compressibility, U32 duration) { unsigned long long bytes = 0; unsigned long long cbytes = 0; @@ -313,7 +312,7 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do int ret; unsigned cycleNb; # define FUZ_CHECKTEST(cond, ...) if (cond) { printf("Test %u : ", testNb); printf(__VA_ARGS__); \ - printf(" (seed %u, cycle %u) \n", seed, cycleNb); goto _output_error; } + printf(" (seed %u, cycle %u) \n", seed, cycleNb); goto _output_error; } # define FUZ_DISPLAYTEST { testNb++; g_displayLevel<3 ? 0 : printf("%2u\b\b", testNb); if (g_displayLevel==4) fflush(stdout); } void* stateLZ4 = malloc(LZ4_sizeofState()); void* stateLZ4HC = malloc(LZ4_sizeofStateHC()); @@ -324,23 +323,25 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do U32 coreRandState = seed; U32 randState = coreRandState ^ PRIME3; int result = 0; + const U32 startTime = FUZ_GetMilliStart(); - // init + /* init */ memset(&LZ4dict, 0, sizeof(LZ4dict)); + duration *= 1000; - // Create compressible test buffer + /* Create compressible test buffer */ CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH); FUZ_fillCompressibleNoiseBuffer(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, compressibility, &randState); compressedBuffer = (char*)malloc(LZ4_compressBound(FUZ_MAX_BLOCK_SIZE)); decodedBuffer = (char*)malloc(FUZ_MAX_DICT_SIZE + FUZ_MAX_BLOCK_SIZE); - // move to startCycle + /* move to startCycle */ for (cycleNb = 0; cycleNb < startCycle; cycleNb++) { (void)FUZ_rand(&coreRandState); - if (0) // some problems related to dictionary re-use; in this case, enable this loop + if (0) /* some problems are related to dictionary re-use; in this case, enable this loop */ { int dictSize, blockSize, blockStart; char* dict; @@ -362,8 +363,8 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do } } - // Test loop - for (cycleNb = startCycle; cycleNb < nbCycles; cycleNb++) + /* Main test loop */ + for (cycleNb = startCycle; (cycleNb < nbCycles) || (FUZ_GetMilliSpan(startTime) < duration) ; cycleNb++) { U32 testNb = 0; char* dict; @@ -375,7 +376,7 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do (void)FUZ_rand(&coreRandState); randState = coreRandState ^ PRIME3; - // Select block to test + /* Select block to test */ blockSize = FUZ_rand(&randState) % FUZ_MAX_BLOCK_SIZE; blockStart = FUZ_rand(&randState) % (COMPRESSIBLE_NOISE_LENGTH - blockSize); dictSize = FUZ_rand(&randState) % FUZ_MAX_DICT_SIZE; @@ -385,7 +386,7 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do /* Compression tests */ - // Test compression HC + /* Test compression HC */ FUZ_DISPLAYTEST; ret = LZ4_compressHC(block, compressedBuffer, blockSize); FUZ_CHECKTEST(ret==0, "LZ4_compressHC() failed"); @@ -673,21 +674,22 @@ static int FUZ_test(U32 seed, const U32 nbCycles, const U32 startCycle, const do FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data"); - // ***** End of tests *** // - // Fill stats + /* ***** End of tests *** */ + /* Fill stats */ bytes += blockSize; cbytes += compressedSize; hcbytes += HCcompressedSize; ccbytes += blockContinueCompressedSize; } + if (nbCycles<=1) nbCycles = cycleNb; printf("\r%7u /%7u - ", cycleNb, nbCycles); printf("all tests completed successfully \n"); printf("compression ratio: %0.3f%%\n", (double)cbytes/bytes*100); printf("HC compression ratio: %0.3f%%\n", (double)hcbytes/bytes*100); printf("ratio with dict: %0.3f%%\n", (double)ccbytes/bytes*100); - // unalloc + /* release memory */ { _exit: free(CNBuffer); @@ -831,7 +833,7 @@ static void FUZ_unitTests(void) crcNew = XXH64(testVerify, testCompressedSize, 0); FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() simple dictionary decompression test : corruption"); - // multiple HC compression test with dictionary + /* multiple HC compression test with dictionary */ { int result1, result2; int segSize = testCompressedSize / 2; @@ -863,7 +865,7 @@ static void FUZ_unitTests(void) crcNew = XXH64(testVerify, testCompressedSize, 0); FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe_usingDict() decompression corruption"); - // multiple HC compression with ext. dictionary + /* multiple HC compression with ext. dictionary */ { XXH64_state_t crcOrigState; XXH64_state_t crcNewState; @@ -912,7 +914,7 @@ static void FUZ_unitTests(void) } } - // ring buffer test + /* ring buffer test */ { XXH64_state_t xxhOrig; XXH64_state_t xxhNew; @@ -956,7 +958,7 @@ static void FUZ_unitTests(void) } } - // small decoder-side ring buffer test + /* small decoder-side ring buffer test */ { XXH64_state_t xxhOrig; XXH64_state_t xxhNew; @@ -1013,6 +1015,7 @@ static int FUZ_usage(char* programName) DISPLAY( "\n"); DISPLAY( "Arguments :\n"); DISPLAY( " -i# : Nb of tests (default:%i) \n", NB_ATTEMPTS); + DISPLAY( " -T# : Duration of tests (default: use Nb of tests) \n"); DISPLAY( " -s# : Select seed (default:prompt user)\n"); DISPLAY( " -t# : Select starting test number (default:0)\n"); DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT); @@ -1033,8 +1036,9 @@ int main(int argc, char** argv) int proba = FUZ_COMPRESSIBILITY_DEFAULT; int pause = 0; char* programName = argv[0]; + U32 duration = 0; - // Check command line + /* Check command line */ for(argNb=1; argNb='0') && (*argument<='9')) { nbTests *= 10; @@ -1075,6 +1079,34 @@ int main(int argc, char** argv) } break; + case 'T': + argument++; + nbTests = 0; duration = 0; + + for (;;) + { + if (argument[0]=='m') + { + duration *= 60; + argument++; + continue; + } + if (argument[0]=='n') + { + argument++; + continue; + } + if ((*argument>='0') && (*argument<='9')) + { + duration *= 10; + duration += *argument - '0'; + argument++; + continue; + } + break; + } + break; + case 's': argument++; seed=0; seedset=1; @@ -1115,7 +1147,6 @@ int main(int argc, char** argv) } } - // Get Seed printf("Starting LZ4 fuzzer (%i-bits, %s)\n", (int)(sizeof(size_t)*8), LZ4_VERSION); if (!seedset) seed = FUZ_GetMilliStart() % 10000; @@ -1127,7 +1158,7 @@ int main(int argc, char** argv) if (nbTests<=0) nbTests=1; { - int result = FUZ_test(seed, nbTests, testNb, ((double)proba) / 100); + int result = FUZ_test(seed, nbTests, testNb, ((double)proba) / 100, duration); if (pause) { DISPLAY("press enter ... \n"); -- cgit v0.12 From 8b8e5efefe2dfdfbeb3ebc7591d2c345c34552f5 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 11 Apr 2015 10:25:08 +0100 Subject: fixed minor sanitize warning --- programs/Makefile | 3 +-- programs/lz4io.c | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 1c9e4b5..97be7d9 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -61,7 +61,6 @@ endif TRAVIS_TARGET:= $(LZ4_TRAVIS_CI_ENV) TEST_FILES := COPYING TEST_TARGETS := test-native -FUZZER_TIME ?= -T20mn default: lz4 @@ -103,7 +102,7 @@ datagen : datagen.c datagencli.c $(CC) $(FLAGS) $^ -o $@$(EXT) clean: - @rm -f core *.o *.test \ + @rm -f core *.o *.test tmp* \ lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) \ fullbench$(EXT) fullbench32$(EXT) \ fuzzer$(EXT) fuzzer32$(EXT) \ diff --git a/programs/lz4io.c b/programs/lz4io.c index 4071b1e..b6e678e 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -53,8 +53,8 @@ #include /* stat64 */ #include /* stat64 */ #include "lz4io.h" -#include "lz4.h" /* still required for legacy format */ -#include "lz4hc.h" /* still required for legacy format */ +#include "lz4.h" /* still required for legacy format */ +#include "lz4hc.h" /* still required for legacy format */ #include "lz4frame.h" @@ -823,7 +823,7 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file end = clock(); DISPLAYLEVEL(2, "\r%79s\r", ""); DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize); - if (filesize > 0) + if (end==start) end=start+1; { double seconds = (double)(end - start)/CLOCKS_PER_SEC; DISPLAYLEVEL(4, "Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024); -- cgit v0.12 From a07db74d24d8fb3f7a3dc64e4c7b1204f52226ad Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 11 Apr 2015 10:46:16 +0100 Subject: Clarified lz4frame.h inline doc --- lib/lz4frame.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 9d12c7d..e5435cd 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -45,7 +45,7 @@ extern "C" { #endif /************************************** - Includes +* Includes **************************************/ #include /* size_t */ @@ -142,15 +142,17 @@ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* prefsPtr); /* LZ4F_compressBound() : * Provides the minimum size of Dst buffer given srcSize to handle worst case situations. * prefsPtr is optional : you can provide NULL as argument, all preferences will then be set to default. - * Note that different preferences will produce in different results. + * Note that different preferences will produce different results. + * This function doesn't include frame termination cost (4 bytes, or 8 is frame checksum is enabled) */ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* cOptPtr); /* LZ4F_compressUpdate() * LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary. * The most important rule is that dstBuffer MUST be large enough (dstMaxSize) to ensure compression completion even in worst case. - * If this condition is not respected, LZ4F_compress() will fail (result is an errorCode) - * You can get the minimum value of dstMaxSize by using LZ4F_compressBound() + * You can get the minimum value of dstMaxSize by using LZ4F_compressBound(). + * If this condition is not respected, LZ4F_compress() will fail (result is an errorCode). + * LZ4F_compressUpdate() doesn't guarantee error recovery, so you have to reset compression context when an error occurs. * The LZ4F_compressOptions_t structure is optional : you can provide NULL as argument. * The result of the function is the number of bytes written into dstBuffer : it can be zero, meaning input data was just buffered. * The function outputs an error code if it fails (can be tested using LZ4F_isError()) @@ -172,10 +174,10 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t * When you want to properly finish the compressed frame, just call LZ4F_compressEnd(). * It will flush whatever data remained within compressionContext (like LZ4_flush()) * but also properly finalize the frame, with an endMark and a checksum. - * The result of the function is the number of bytes written into dstBuffer (necessarily >= 4 (endMark size)) + * The result of the function is the number of bytes written into dstBuffer (necessarily >= 4 (endMark), or 8 if optional frame checksum is enabled) * The function outputs an error code if it fails (can be tested using LZ4F_isError()) * The LZ4F_compressOptions_t structure is optional : you can provide NULL as argument. - * A successful call to LZ4F_compressEnd() makes cctx available again for future compression work. + * A successful call to LZ4F_compressEnd() makes cctx available again for future compression task. */ -- cgit v0.12 From be9d248851ecd712a8911526b009c5d0c948ee21 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 11 Apr 2015 12:28:09 +0100 Subject: Update lz4hc API : LZ4_compressHC_safe() --- NEWS | 2 ++ lib/lz4hc.c | 86 +++++++++++++++++++-------------------------------------- lib/lz4hc.h | 91 ++++++++++++++++++++++++++----------------------------------- 3 files changed, 68 insertions(+), 111 deletions(-) diff --git a/NEWS b/NEWS index a1d452a..0f33388 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ r129: Added : LZ4_compress_fast() +Changed: New compression functions LZ4_compress_safe() - Suggested by Evan Nemerson & Takayuki Matsuoka Added : AppVeyor CI environment, for Visual tests - Suggested by Takayuki Matsuoka +Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Evan Nemerson and Greg Slazinski Updated: Documentation converted to MarkDown r128: diff --git a/lib/lz4hc.c b/lib/lz4hc.c index c7a94a0..234e1af 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -536,55 +536,24 @@ _Search3: } -int LZ4_compressHC2(const char* source, char* dest, int inputSize, int compressionLevel) -{ - LZ4HC_Data_Structure ctx; - LZ4HC_init(&ctx, (const BYTE*)source); - return LZ4HC_compress_generic (&ctx, source, dest, inputSize, 0, compressionLevel, noLimit); -} - -int LZ4_compressHC(const char* source, char* dest, int inputSize) { return LZ4_compressHC2(source, dest, inputSize, 0); } - -int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) -{ - LZ4HC_Data_Structure ctx; - LZ4HC_init(&ctx, (const BYTE*)source); - return LZ4HC_compress_generic (&ctx, source, dest, inputSize, maxOutputSize, compressionLevel, limitedOutput); -} - -int LZ4_compressHC_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) -{ - return LZ4_compressHC2_limitedOutput(source, dest, inputSize, maxOutputSize, 0); -} - - -/***************************** - * Using external allocation - * ***************************/ int LZ4_sizeofStateHC(void) { return sizeof(LZ4HC_Data_Structure); } - -int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel) +int LZ4_compressHC_safe_extStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) { if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */ LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)source); - return LZ4HC_compress_generic (state, source, dest, inputSize, 0, compressionLevel, noLimit); + if (maxOutputSize < LZ4_compressBound(inputSize)) + return LZ4HC_compress_generic (state, source, dest, inputSize, maxOutputSize, compressionLevel, limitedOutput); + else + return LZ4HC_compress_generic (state, source, dest, inputSize, maxOutputSize, compressionLevel, noLimit); } -int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize) -{ return LZ4_compressHC2_withStateHC (state, source, dest, inputSize, 0); } - - -int LZ4_compressHC2_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) +int LZ4_compressHC_safe(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) { - if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */ - LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)source); - return LZ4HC_compress_generic (state, source, dest, inputSize, maxOutputSize, compressionLevel, limitedOutput); + LZ4HC_Data_Structure state; + return LZ4_compressHC_safe_extStateHC(&state, source, dest, inputSize, maxOutputSize, compressionLevel); } -int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize) -{ return LZ4_compressHC2_limitedOutput_withStateHC (state, source, dest, inputSize, maxOutputSize, 0); } - /************************************** @@ -592,7 +561,7 @@ int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, c * ************************************/ /* allocation */ LZ4_streamHC_t* LZ4_createStreamHC(void) { return (LZ4_streamHC_t*)malloc(sizeof(LZ4_streamHC_t)); } -int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) { free(LZ4_streamHCPtr); return 0; } +int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) { free(LZ4_streamHCPtr); return 0; } /* initialization */ @@ -669,14 +638,12 @@ static int LZ4_compressHC_continue_generic (LZ4HC_Data_Structure* ctxPtr, return LZ4HC_compress_generic (ctxPtr, source, dest, inputSize, maxOutputSize, ctxPtr->compressionLevel, limit); } -int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize) +int LZ4_compressHC_safe_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize) { - return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, 0, noLimit); -} - -int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize) -{ - return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, limitedOutput); + if (maxOutputSize < LZ4_compressBound(inputSize)) + return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, limitedOutput); + else + return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, noLimit); } @@ -705,6 +672,20 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS /*********************************** * Deprecated Functions ***********************************/ +/* Deprecated compression functions */ +int LZ4_compressHC(const char* source, char* dest, int inputSize) { return LZ4_compressHC2(source, dest, inputSize, 0); } +int LZ4_compressHC_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe(src, dst, srcSize, maxDstSize, 0); } +int LZ4_compressHC2(const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compressHC_safe (src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } +int LZ4_compressHC2_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compressHC_safe(src, dst, srcSize, maxDstSize, cLevel); } +int LZ4_compressHC_withStateHC (void* state, const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe_extStateHC (state, src, dst, srcSize, LZ4_compressBound(srcSize), 0); } +int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe_extStateHC (state, src, dst, srcSize, maxDstSize, 0); } +int LZ4_compressHC2_withStateHC (void* state, const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compressHC_safe_extStateHC(state, src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } +int LZ4_compressHC2_limitedOutput_withStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compressHC_safe_extStateHC(state, src, dst, srcSize, maxDstSize, cLevel); } +int LZ4_compressHC_continue (LZ4_streamHC_t* ctx, const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe_continue (ctx, src, dst, srcSize, LZ4_compressBound(srcSize)); } +int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* ctx, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe_continue (ctx, src, dst, srcSize, maxDstSize); } + + +/* Deprecated streaming functions */ int LZ4_sizeofStreamStateHC(void) { return LZ4_STREAMHCSIZE; } int LZ4_resetStreamStateHC(void* state, const char* inputBuffer) @@ -727,17 +708,6 @@ int LZ4_freeHC (void* LZ4HC_Data) return (0); } -/* -int LZ4_compressHC_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize) -{ -return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, 0, 0, noLimit); -} -int LZ4_compressHC_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize) -{ -return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, maxOutputSize, 0, limitedOutput); -} -*/ - int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel) { return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, 0, compressionLevel, noLimit); diff --git a/lib/lz4hc.h b/lib/lz4hc.h index 4a05845..c257dcc 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -38,78 +38,53 @@ extern "C" { #endif +/***************************** +* Includes +*****************************/ +#include /* size_t */ + -int LZ4_compressHC (const char* source, char* dest, int inputSize); +/************************************** +* Block Compression +**************************************/ +int LZ4_compressHC_safe (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); /* -LZ4_compressHC : +LZ4_compressHC_safe : return : the number of bytes in compressed buffer dest or 0 if compression fails. note : destination buffer must be already allocated. - To avoid any problem, size it to handle worst cases situations (input data not compressible) + To guarantee compression completion, size it to handle worst cases situations (data not compressible) Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h") + inputSize : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h") + compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work. + 0 means use default 'compressionLevel' value. + Values >16 behave the same as 16. */ -int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize); -/* -LZ4_compress_limitedOutput() : - Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'. - If it cannot achieve it, compression will stop, and result of the function will be zero. - This function never writes outside of provided output buffer. - - inputSize : Max supported value is 1 GB - maxOutputSize : is maximum allowed size into the destination buffer (which must be already allocated) - return : the number of output bytes written in buffer 'dest' - or 0 if compression fails. -*/ - - -int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel); -int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); -/* - Same functions as above, but with programmable 'compressionLevel'. - Recommended values are between 4 and 9, although any value between 0 and 16 will work. - 'compressionLevel'==0 means use default 'compressionLevel' value. - Values above 16 behave the same as 16. - Equivalent variants exist for all other compression functions below. -*/ /* Note : Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license) */ -/************************************** -* Using an external allocation -**************************************/ int LZ4_sizeofStateHC(void); -int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize); -int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); - -int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel); -int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); +int LZ4_compressHC_safe_extStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); /* -These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods. +This function is provided should you prefer to allocate memory for compression tables with your own allocation methods. To know how much memory must be allocated for the compression tables, use : int LZ4_sizeofStateHC(); Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0). The allocated memory can be provided to the compression functions using 'void* state' parameter. -LZ4_compress_withStateHC() and LZ4_compress_limitedOutput_withStateHC() are equivalent to previously described functions. -They just use the externally allocated memory for state instead of allocating their own (on stack, or on heap). +LZ4_compressHC_safe_extStateHC() is equivalent to previously described function. +It just uses externally allocated memory for stateHC instead of allocating their own (on stack, or on heap). */ - -/***************************** -* Includes -*****************************/ -#include /* size_t */ - - /************************************** -* Experimental Streaming Functions +* Streaming Compression **************************************/ #define LZ4_STREAMHCSIZE 262192 #define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t)) @@ -137,8 +112,7 @@ to avoid size mismatch between different versions. void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel); int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int dictSize); -int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize); -int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compressHC_safe_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int maxDictSize); @@ -149,8 +123,8 @@ One key assumption is that each previous block will remain read-accessible while Before starting compression, state must be properly initialized, using LZ4_resetStreamHC(). A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional). -Then, use LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue() to compress each successive block. -They work like usual LZ4_compressHC() or LZ4_compressHC_limitedOutput(), but use previous memory blocks to improve compression. +Then, use LZ4_compressHC_safe_continue() to compress each successive block. +It works like LZ4_compressHC_safe(), but use previous memory blocks to improve compression. Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression. If, for any reason, previous data block can't be preserved in memory during next compression block, @@ -161,16 +135,27 @@ using LZ4_saveDictHC(). /************************************** - * Deprecated Streaming Functions + * Deprecated Functions * ************************************/ -/* Note : these streaming functions follows the older model, and should no longer be used */ + +/* compression functions */ +int LZ4_compressHC (const char* source, char* dest, int inputSize); +int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel); +int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); +int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize); +int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel); +int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); +int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize); +int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); + +/* Streaming functions following the older model; should no longer be used */ void* LZ4_createHC (const char* inputBuffer); char* LZ4_slideInputBufferHC (void* LZ4HC_Data); int LZ4_freeHC (void* LZ4HC_Data); - int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); - int LZ4_sizeofStreamStateHC(void); int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); -- cgit v0.12 From 973e385fa332485f4617cf16406a8c8ef631a555 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 11 Apr 2015 18:59:22 +0100 Subject: Implemented obsolete warning message --- NEWS | 3 +- lib/lz4.c | 14 +++-- lib/lz4.h | 63 ++++++++++++++--------- programs/fullbench.c | 142 ++++++++++++++++++++++++--------------------------- programs/fuzzer.c | 17 +++--- 5 files changed, 124 insertions(+), 115 deletions(-) diff --git a/NEWS b/NEWS index 0f33388..462a23b 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,8 @@ r129: Added : LZ4_compress_fast() Changed: New compression functions LZ4_compress_safe() - Suggested by Evan Nemerson & Takayuki Matsuoka Added : AppVeyor CI environment, for Visual tests - Suggested by Takayuki Matsuoka -Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Evan Nemerson and Greg Slazinski +Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Greg Slazinski, Evan Nemerson & Takayuki Matsuoka +Modified:Obsolete functions generate warnings - Suggested by Evan Nemerson & Takayuki Matsuoka Updated: Documentation converted to MarkDown r128: diff --git a/lib/lz4.c b/lib/lz4.c index 6ed6ab3..d6fdcd9 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -63,6 +63,12 @@ /************************************** +* Includes +**************************************/ +#include "lz4.h" + + +/************************************** * Compiler Options **************************************/ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ @@ -88,8 +94,6 @@ # endif /* __STDC_VERSION__ */ #endif /* _MSC_VER */ -#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) - #if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__) # define expect(expr,value) (__builtin_expect ((expr),(value)) ) #else @@ -111,12 +115,6 @@ /************************************** -* Includes -**************************************/ -#include "lz4.h" - - -/************************************** * Basic Types **************************************/ #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ diff --git a/lib/lz4.h b/lib/lz4.h index 659866b..7bd4594 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -39,9 +39,9 @@ extern "C" { #endif /* - * lz4.h provides block compression functions, for optimal performance. + * lz4.h provides block compression functions, and gives full buffer control to programmer. * If you need to generate inter-operable compressed data (respecting LZ4 frame specification), - * please use lz4frame.h instead. + * and can let the library handle its own memory, please use lz4frame.h instead. */ /************************************** @@ -70,7 +70,7 @@ int LZ4_versionNumber (void); * Simple Functions **************************************/ -int LZ4_compress_safe (const char* source, char* dest, int sourceSize, int maxOutputSize); +int LZ4_compress_safe (const char* source, char* dest, int sourceSize, int maxDestSize); int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize); /* @@ -85,7 +85,7 @@ LZ4_compress_limitedOutput() : It greatly accelerates behavior on non-compressible input, but as a consequence, 'dest' content is not valid either. This function never writes outside 'dest' buffer, nor read outside 'source' buffer. sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE - maxOutputSize : full or partial size of buffer 'dest' (which must be already allocated) + maxDestSize : full or partial size of buffer 'dest' (which must be already allocated) return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize) or 0 if compression fails @@ -124,11 +124,12 @@ LZ4_compress_fast() : The larger the value, the faster the algorithm, but also the lesser the compression. So it's a trade-off, which can be fine tuned, selecting whichever value you want. An acceleration value of "0" means "use Default value", which is typically about 15 (see lz4.c source code). + Note : this function is "safe", even if its name does not say it. It's just faster and compress less. */ int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); /* -LZ4_compress_safe_withState() : +LZ4_compress_safe_extState() : Same compression function, just using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, and then, provide it as 'void* state' to compression functions. @@ -169,7 +170,6 @@ int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedS /*********************************************** * Streaming Compression Functions ***********************************************/ - #define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4) #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(long long)) /* @@ -280,35 +280,50 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS /************************************** * Obsolete Functions **************************************/ +/* Warning statements */ +#ifndef _WARNING_STATEMENT_BLOCK +# define _WARNING_STATEMENT_BLOCK +# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# if (GCC_VERSION >= 405) || defined(__clang__) +# define DEPRECATED(message) __attribute__((deprecated(message))) +# elif (GCC_VERSION >= 301) +# define DEPRECATED(message) __attribute__((deprecated)) +# elif defined(_MSC_VER) +# define DEPRECATED(message) __declspec(deprecated(message)) +# else +# pragma message("WARNING: You need to implement DEPRECATED for this compiler") +# define DEPRECATED +# endif +#endif // _WARNING_STATEMENT_BLOCK /* Obsolete compression functions */ -int LZ4_compress (const char* source, char* dest, int sourceSize); +/* These functions are planned to generate warnings by r131 approximately */ +int LZ4_compress (const char* source, char* dest, int sourceSize); int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); 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); -int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); -int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); - -/* -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 -These function prototypes are now disabled; uncomment them if you really need them. -It is highly recommended to stop using these functions and migrate to newer ones */ +int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); + +/* Obsolete decompression functions */ +/* These function names are completely deprecated and must no longer be used. + They are only provided here for compatibility with older programs. + - LZ4_uncompress is the same as LZ4_decompress_fast + - LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe + These function prototypes are now disabled; uncomment them only if you really need them. + It is highly recommended to stop using these prototypes and migrate to maintained ones */ /* int LZ4_uncompress (const char* source, char* dest, int outputSize); */ /* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */ /* Obsolete streaming functions; use new streaming interface whenever possible */ -void* LZ4_create (const char* inputBuffer); -int LZ4_sizeofStreamState(void); -int LZ4_resetStreamState(void* state, const char* inputBuffer); -char* LZ4_slideInputBuffer (void* state); +DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (const char* inputBuffer); +DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); +DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, const char* inputBuffer); +DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); /* Obsolete streaming decoding functions */ -int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize); -int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize); +DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize); +DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize); #if defined (__cplusplus) diff --git a/programs/fullbench.c b/programs/fullbench.c index 2f246a2..700655b 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -381,6 +381,23 @@ start: #endif // __SSSE3__ +static LZ4_stream_t LZ4_stream; +static void local_LZ4_resetDictT(void) +{ + LZ4_resetStream(&LZ4_stream); +} + +static void local_LZ4_createStream(void) +{ + LZ4_resetStream(&LZ4_stream); +} + +static int local_LZ4_saveDict(const char* in, char* out, int inSize) +{ + (void)in; + return LZ4_saveDict(&LZ4_stream, out, inSize); +} + static int local_LZ4_compress_limitedOutput(const char* in, char* out, int inSize) { return LZ4_compress_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)-1); @@ -391,53 +408,56 @@ static int local_LZ4_compress_fast(const char* in, char* out, int inSize) return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 0); } -static LZ4_stream_t* stateLZ4; static int local_LZ4_compress_withState(const char* in, char* out, int inSize) { - return LZ4_compress_withState(stateLZ4, in, out, inSize); + return LZ4_compress_withState(&LZ4_stream, in, out, inSize); } static int local_LZ4_compress_limitedOutput_withState(const char* in, char* out, int inSize) { - return LZ4_compress_limitedOutput_withState(stateLZ4, in, out, inSize, LZ4_compressBound(inSize)-1); + return LZ4_compress_limitedOutput_withState(&LZ4_stream, in, out, inSize, LZ4_compressBound(inSize)-1); } -static LZ4_stream_t* ctx; static int local_LZ4_compress_continue(const char* in, char* out, int inSize) { - return LZ4_compress_continue(ctx, in, out, inSize); + return LZ4_compress_continue(&LZ4_stream, in, out, inSize); } static int local_LZ4_compress_limitedOutput_continue(const char* in, char* out, int inSize) { - return LZ4_compress_limitedOutput_continue(ctx, in, out, inSize, LZ4_compressBound(inSize)-1); + return LZ4_compress_limitedOutput_continue(&LZ4_stream, in, out, inSize, LZ4_compressBound(inSize)-1); } +/* declare hidden function */ +int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize); -LZ4_stream_t LZ4_dict; -static void* local_LZ4_resetDictT(const char* fake) +static int local_LZ4_compress_forceDict(const char* in, char* out, int inSize) { - (void)fake; - memset(&LZ4_dict, 0, sizeof(LZ4_stream_t)); - return NULL; + return LZ4_compress_forceExtDict(&LZ4_stream, in, out, inSize); } -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) + +/* HC compression functions */ +LZ4_streamHC_t LZ4_streamHC; +static void local_LZ4_resetStreamHC(void) { - return LZ4_compress_forceExtDict(&LZ4_dict, in, out, inSize); + LZ4_resetStreamHC(&LZ4_streamHC, 0); } +static int local_LZ4_saveDictHC(const char* in, char* out, int inSize) +{ + (void)in; + return LZ4_saveDictHC(&LZ4_streamHC, out, inSize); +} -static LZ4_streamHC_t* stateLZ4HC; static int local_LZ4_compressHC_withStateHC(const char* in, char* out, int inSize) { - return LZ4_compressHC_withStateHC(stateLZ4HC, in, out, inSize); + return LZ4_compressHC_withStateHC(&LZ4_streamHC, in, out, inSize); } static int local_LZ4_compressHC_limitedOutput_withStateHC(const char* in, char* out, int inSize) { - return LZ4_compressHC_limitedOutput_withStateHC(stateLZ4HC, in, out, inSize, LZ4_compressBound(inSize)-1); + return LZ4_compressHC_limitedOutput_withStateHC(&LZ4_streamHC, in, out, inSize, LZ4_compressBound(inSize)-1); } static int local_LZ4_compressHC_limitedOutput(const char* in, char* out, int inSize) @@ -447,33 +467,16 @@ static int local_LZ4_compressHC_limitedOutput(const char* in, char* out, int inS static int local_LZ4_compressHC_continue(const char* in, char* out, int inSize) { - return LZ4_compressHC_continue((LZ4_streamHC_t*)ctx, in, out, inSize); + return LZ4_compressHC_continue(&LZ4_streamHC, in, out, inSize); } static int local_LZ4_compressHC_limitedOutput_continue(const char* in, char* out, int inSize) { - return LZ4_compressHC_limitedOutput_continue((LZ4_streamHC_t*)ctx, in, out, inSize, LZ4_compressBound(inSize)-1); -} - -static int local_LZ4F_compressFrame(const char* in, char* out, int inSize) -{ - return (int)LZ4F_compressFrame(out, 2*inSize + 16, in, inSize, NULL); -} - -static int local_LZ4_saveDict(const char* in, char* out, int inSize) -{ - (void)in; - return LZ4_saveDict(&LZ4_dict, out, inSize); -} - -LZ4_streamHC_t LZ4_dictHC; -static int local_LZ4_saveDictHC(const char* in, char* out, int inSize) -{ - (void)in; - return LZ4_saveDictHC(&LZ4_dictHC, out, inSize); + return LZ4_compressHC_limitedOutput_continue(&LZ4_streamHC, in, out, inSize, LZ4_compressBound(inSize)-1); } +/* decompression functions */ static int local_LZ4_decompress_fast(const char* in, char* out, int inSize, int outSize) { (void)inSize; @@ -481,13 +484,6 @@ static int local_LZ4_decompress_fast(const char* in, char* out, int inSize, int return outSize; } -static int local_LZ4_decompress_fast_withPrefix64k(const char* in, char* out, int inSize, int outSize) -{ - (void)inSize; - LZ4_decompress_fast_withPrefix64k(in, out, outSize); - return outSize; -} - static int local_LZ4_decompress_fast_usingDict(const char* in, char* out, int inSize, int outSize) { (void)inSize; @@ -516,6 +512,13 @@ static int local_LZ4_decompress_safe_partial(const char* in, char* out, int inSi return LZ4_decompress_safe_partial(in, out, inSize, outSize - 5, outSize); } + +/* frame functions */ +static int local_LZ4F_compressFrame(const char* in, char* out, int inSize) +{ + return (int)LZ4F_compressFrame(out, 2*inSize + 16, in, inSize, NULL); +} + static LZ4F_decompressionContext_t g_dCtx; static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outSize) @@ -534,11 +537,8 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) { int fileIdx=0; char* orig_buff; -# define NB_COMPRESSION_ALGORITHMS 17 - double totalCTime[NB_COMPRESSION_ALGORITHMS+1] = {0}; - double totalCSize[NB_COMPRESSION_ALGORITHMS+1] = {0}; -# define NB_DECOMPRESSION_ALGORITHMS 9 - double totalDTime[NB_DECOMPRESSION_ALGORITHMS+1] = {0}; +# define NB_COMPRESSION_ALGORITHMS 100 +# define NB_DECOMPRESSION_ALGORITHMS 100 size_t errorCode; @@ -576,8 +576,6 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); /* Allocation */ - stateLZ4 = LZ4_createStream(); - stateLZ4HC = LZ4_createStreamHC(); errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION); if (LZ4F_isError(errorCode)) { @@ -634,9 +632,12 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) { const char* compressorName; int (*compressionFunction)(const char*, char*, int); - void* (*initFunction)(const char*) = NULL; + void (*initFunction)(void) = NULL; double bestTime = 100000000.; + /* filter compressionAlgo only */ + if ((compressionAlgo != ALL_COMPRESSORS) && (compressionAlgo != cAlgNb)) continue; + /* Init data chunks */ { int i; @@ -654,34 +655,34 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) } } - if ((compressionAlgo != ALL_COMPRESSORS) && (compressionAlgo != cAlgNb)) continue; - switch(cAlgNb) { case 1 : compressionFunction = LZ4_compress; compressorName = "LZ4_compress"; break; case 2 : compressionFunction = local_LZ4_compress_limitedOutput; compressorName = "LZ4_compress_limitedOutput"; break; case 3 : compressionFunction = local_LZ4_compress_withState; compressorName = "LZ4_compress_withState"; break; case 4 : compressionFunction = local_LZ4_compress_limitedOutput_withState; compressorName = "LZ4_compress_limitedOutput_withState"; break; - case 5 : compressionFunction = local_LZ4_compress_continue; initFunction = LZ4_create; compressorName = "LZ4_compress_continue"; break; - case 6 : compressionFunction = local_LZ4_compress_limitedOutput_continue; initFunction = LZ4_create; compressorName = "LZ4_compress_limitedOutput_continue"; break; + case 5 : compressionFunction = local_LZ4_compress_continue; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_continue"; break; + case 6 : compressionFunction = local_LZ4_compress_limitedOutput_continue; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_limitedOutput_continue"; break; case 7 : compressionFunction = local_LZ4_compress_fast; compressorName = "LZ4_compress_fast"; break; case 8 : compressionFunction = LZ4_compressHC; compressorName = "LZ4_compressHC"; break; case 9 : compressionFunction = local_LZ4_compressHC_limitedOutput; compressorName = "LZ4_compressHC_limitedOutput"; break; case 10 : compressionFunction = local_LZ4_compressHC_withStateHC; compressorName = "LZ4_compressHC_withStateHC"; break; case 11: compressionFunction = local_LZ4_compressHC_limitedOutput_withStateHC; compressorName = "LZ4_compressHC_limitedOutput_withStateHC"; break; - case 12: compressionFunction = local_LZ4_compressHC_continue; initFunction = LZ4_createHC; compressorName = "LZ4_compressHC_continue"; break; - case 13: compressionFunction = local_LZ4_compressHC_limitedOutput_continue; initFunction = LZ4_createHC; compressorName = "LZ4_compressHC_limitedOutput_continue"; break; + case 12: compressionFunction = local_LZ4_compressHC_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compressHC_continue"; break; + case 13: compressionFunction = local_LZ4_compressHC_limitedOutput_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compressHC_limitedOutput_continue"; break; case 14: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break; case 15: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame"; chunkP[0].origSize = (int)benchedSize; nbChunks=1; break; case 16: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict"; - LZ4_loadDict(&LZ4_dict, chunkP[0].origBuffer, chunkP[0].origSize); + LZ4_loadDict(&LZ4_stream, chunkP[0].origBuffer, chunkP[0].origSize); break; case 17: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC"; - LZ4_loadDictHC(&LZ4_dictHC, chunkP[0].origBuffer, chunkP[0].origSize); + LZ4_loadDictHC(&LZ4_streamHC, chunkP[0].origBuffer, chunkP[0].origSize); break; - default : DISPLAY("ERROR ! Bad algorithm Id !! \n"); free(chunkP); return 1; + default : + continue; /* unknown ID : just skip */ + DISPLAY("ERROR ! Bad algorithm Id !! \n"); free(chunkP); return 1; } for (loopNb = 1; loopNb <= nbIterations; loopNb++) @@ -698,13 +699,12 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) milliTime = BMK_GetMilliStart(); while(BMK_GetMilliSpan(milliTime) < TIMELOOP) { - if (initFunction!=NULL) ctx = (LZ4_stream_t*)initFunction(chunkP[0].origBuffer); + if (initFunction!=NULL) initFunction(); for (chunkNb=0; chunkNb%9i (%5.2f%%),%7.1f MB/s\n", cAlgNb, compressorName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / bestTime / 1000.); else DISPLAY("%2i-%-28.28s :%9i ->%9i (%5.1f%%),%7.1f MB/s\n", cAlgNb, compressorName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / bestTime / 1000.); - - totalCTime[cAlgNb] += bestTime; - totalCSize[cAlgNb] += cSize; } /* Prepare layout for decompression */ @@ -732,7 +729,8 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) size_t remaining = benchedSize; char* in = orig_buff; char* out = compressed_buff; - nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); + + nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); for (i=0; i %7.1f MB/s\n", dAlgNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000.); - - totalDTime[dAlgNb] += bestTime; } } @@ -822,8 +818,6 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) free(orig_buff); free(compressed_buff); free(chunkP); - LZ4_freeStream(stateLZ4); - LZ4_freeStreamHC(stateLZ4HC); LZ4F_freeDecompressionContext(g_dCtx); } diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 9e2ce1e..d811eb2 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -316,7 +316,6 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c # define FUZ_DISPLAYTEST { testNb++; g_displayLevel<3 ? 0 : printf("%2u\b\b", testNb); if (g_displayLevel==4) fflush(stdout); } void* stateLZ4 = malloc(LZ4_sizeofState()); void* stateLZ4HC = malloc(LZ4_sizeofStateHC()); - void* LZ4continue; LZ4_stream_t LZ4dict; LZ4_streamHC_t LZ4dictHC; U32 crcOrig, crcCheck; @@ -546,16 +545,18 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c /* Compress using dictionary */ FUZ_DISPLAYTEST; - LZ4continue = LZ4_create (dict); - LZ4_compress_continue ((LZ4_stream_t*)LZ4continue, dict, compressedBuffer, dictSize); // Just to fill hash tables - blockContinueCompressedSize = LZ4_compress_continue ((LZ4_stream_t*)LZ4continue, block, compressedBuffer, blockSize); - FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_continue failed"); - free (LZ4continue); + { + LZ4_stream_t LZ4_stream; + LZ4_resetStream(&LZ4_stream); + LZ4_compress_continue (&LZ4_stream, dict, compressedBuffer, dictSize); /* Just to fill hash tables */ + blockContinueCompressedSize = LZ4_compress_continue (&LZ4_stream, block, compressedBuffer, blockSize); + FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_continue failed"); + } /* Decompress with dictionary as prefix */ FUZ_DISPLAYTEST; memcpy(decodedBuffer, dict, dictSize); - ret = LZ4_decompress_fast_withPrefix64k(compressedBuffer, decodedBuffer+dictSize, blockSize); + ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer+dictSize, blockSize, decodedBuffer, dictSize); FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_decompress_fast_withPrefix64k did not read all compressed block input"); crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0); if (crcCheck!=crcOrig) @@ -568,7 +569,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_fast_withPrefix64k corrupted decoded data (dict %i)", dictSize); FUZ_DISPLAYTEST; - ret = LZ4_decompress_safe_withPrefix64k(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize); + ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize, decodedBuffer, dictSize); FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_withPrefix64k did not regenerate original data"); crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0); FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_withPrefix64k corrupted decoded data"); -- cgit v0.12 From 9443f3d9244faedb08527bf684994a0495117833 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 11 Apr 2015 19:12:03 +0100 Subject: Extended obsolete warning messages to lz4hc --- lib/lz4.h | 13 +++++++++---- lib/lz4hc.h | 35 ++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/lz4.h b/lib/lz4.h index 7bd4594..0ee1a1e 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -280,9 +280,14 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS /************************************** * Obsolete Functions **************************************/ -/* Warning statements */ -#ifndef _WARNING_STATEMENT_BLOCK -# define _WARNING_STATEMENT_BLOCK +/* Deprecate Warnings */ +/* Should these warnings messages be a problem, + it is generally possible to disable them, + with -Wno-deprecated-declarations for gcc + or _CRT_SECURE_NO_WARNINGS in Visual for example. + You can also define _DEPRECATE_WARNING_DEFBLOCK. */ +#ifndef _DEPRECATE_WARNING_DEFBLOCK +# define _DEPRECATE_WARNING_DEFBLOCK # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) # if (GCC_VERSION >= 405) || defined(__clang__) # define DEPRECATED(message) __attribute__((deprecated(message))) @@ -294,7 +299,7 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS # pragma message("WARNING: You need to implement DEPRECATED for this compiler") # define DEPRECATED # endif -#endif // _WARNING_STATEMENT_BLOCK +#endif // _DEPRECATE_WARNING_DEFBLOCK /* Obsolete compression functions */ /* These functions are planned to generate warnings by r131 approximately */ diff --git a/lib/lz4hc.h b/lib/lz4hc.h index c257dcc..7a5bb02 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -137,8 +137,29 @@ using LZ4_saveDictHC(). /************************************** * Deprecated Functions * ************************************/ +/* Deprecate Warnings */ +/* Should these warnings messages be a problem, + it is generally possible to disable them, + with -Wno-deprecated-declarations for gcc + or _CRT_SECURE_NO_WARNINGS in Visual for example. + You can also define _DEPRECATE_WARNING_DEFBLOCK. */ +#ifndef _DEPRECATE_WARNING_DEFBLOCK +# define _DEPRECATE_WARNING_DEFBLOCK +# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# if (GCC_VERSION >= 405) || defined(__clang__) +# define DEPRECATED(message) __attribute__((deprecated(message))) +# elif (GCC_VERSION >= 301) +# define DEPRECATED(message) __attribute__((deprecated)) +# elif defined(_MSC_VER) +# define DEPRECATED(message) __declspec(deprecated(message)) +# else +# pragma message("WARNING: You need to implement DEPRECATED for this compiler") +# define DEPRECATED +# endif +#endif // _DEPRECATE_WARNING_DEFBLOCK /* compression functions */ +/* these functions are planned to trigger warning messages by r131 approximately */ int LZ4_compressHC (const char* source, char* dest, int inputSize); int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize); int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel); @@ -151,13 +172,13 @@ int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, cons int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); /* Streaming functions following the older model; should no longer be used */ -void* LZ4_createHC (const char* inputBuffer); -char* LZ4_slideInputBufferHC (void* LZ4HC_Data); -int LZ4_freeHC (void* LZ4HC_Data); -int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); -int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); -int LZ4_sizeofStreamStateHC(void); -int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); +DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (const char* inputBuffer); +DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data); +DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data); +DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); +DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); +DEPRECATED("use LZ4_createStreamHC() instead") int LZ4_sizeofStreamStateHC(void); +DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); #if defined (__cplusplus) -- cgit v0.12 From 62ed15319570d80690915f0d0dba0dc2e9478631 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 08:21:35 +0100 Subject: Fixed : a few minor coverity warnings --- lib/lz4frame.c | 18 ++++++++++++------ programs/bench.c | 12 ++++-------- programs/frametest.c | 18 +++++++++--------- programs/fullbench.c | 18 +++++++++++------- programs/fuzzer.c | 9 +++++---- programs/lz4cli.c | 2 +- programs/lz4io.c | 22 ++++++++++++++++------ 7 files changed, 58 insertions(+), 41 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index b6dbd20..7094364 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -372,9 +372,12 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_comp { LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)LZ4F_compressionContext; - FREEMEM(cctxPtr->lz4CtxPtr); - FREEMEM(cctxPtr->tmpBuff); - FREEMEM(LZ4F_compressionContext); + if (cctxPtr != NULL) /* null pointers can be safely provided to this function, like free() */ + { + FREEMEM(cctxPtr->lz4CtxPtr); + FREEMEM(cctxPtr->tmpBuff); + FREEMEM(LZ4F_compressionContext); + } return OK_NoError; } @@ -768,9 +771,12 @@ LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_decompressionContext_t* LZ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t LZ4F_decompressionContext) { LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)LZ4F_decompressionContext; - FREEMEM(dctxPtr->tmpIn); - FREEMEM(dctxPtr->tmpOutBuffer); - FREEMEM(dctxPtr); + if (dctxPtr != NULL) /* can accept NULL input, like free() */ + { + FREEMEM(dctxPtr->tmpIn); + FREEMEM(dctxPtr->tmpOutBuffer); + FREEMEM(dctxPtr); + } return OK_NoError; } diff --git a/programs/bench.c b/programs/bench.c index a5c72d6..8921f09 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -281,15 +281,11 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) /* Check file existence */ inFileName = fileNamesTable[fileIdx++]; inFile = fopen( inFileName, "rb" ); - if (inFile==NULL) - { - DISPLAY( "Pb opening %s\n", inFileName); - return 11; - } + if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; } /* Memory allocation & restrictions */ inFileSize = BMK_GetFileSize(inFileName); - if (inFileSize==0) { DISPLAY( "file is empty\n"); return 11; } + if (inFileSize==0) { DISPLAY( "file is empty\n"); fclose(inFile); return 11; } benchedSize = (size_t) BMK_findMaxMem(inFileSize * 2) / 2; if (benchedSize==0) { DISPLAY( "not enough memory\n"); return 11; } if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; @@ -306,7 +302,6 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) compressedBuffSize = nbChunks * maxCompressedChunkSize; compressedBuffer = (char*)malloc((size_t)compressedBuffSize); - if (!orig_buff || !compressedBuffer) { DISPLAY("\nError: not enough memory!\n"); @@ -402,6 +397,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) } milliTime = BMK_GetMilliSpan(milliTime); + nbLoops += !nbLoops; /* avoid division by zero */ if ((double)milliTime < fastestD*nbLoops) fastestD = (double)milliTime/nbLoops; DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \r", loopNb, inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / fastestC / 1000., (double)benchedSize / fastestD / 1000.); @@ -431,7 +427,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) if (nbFiles > 1) DISPLAY("%-16.16s :%10llu ->%10llu (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n", " TOTAL", (long long unsigned int)totals, (long long unsigned int)totalz, (double)totalz/(double)totals*100., (double)totals/totalc/1000., (double)totals/totald/1000.); - if (BMK_pause) { DISPLAY("\npress enter...\n"); getchar(); } + if (BMK_pause) { DISPLAY("\npress enter...\n"); (void)getchar(); } return 0; } diff --git a/programs/frametest.c b/programs/frametest.c index 5fccd08..6204d7a 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -238,10 +238,11 @@ int basicTests(U32 seed, double compressibility) U32 randState = seed; size_t cSize, testSize; LZ4F_preferences_t prefs; - LZ4F_decompressionContext_t dCtx; + LZ4F_decompressionContext_t dCtx = NULL; + LZ4F_compressionContext_t cctx = NULL; U64 crcOrig; - // Create compressible test buffer + /* Create compressible test buffer */ memset(&prefs, 0, sizeof(prefs)); CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH); compressedBuffer = malloc(LZ4F_compressFrameBound(COMPRESSIBLE_NOISE_LENGTH, NULL)); @@ -249,7 +250,7 @@ int basicTests(U32 seed, double compressibility) FUZ_fillCompressibleNoiseBuffer(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, compressibility, &randState); crcOrig = XXH64(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, 1); - // Trivial tests : one-step frame + /* Trivial tests : one-step frame */ testSize = COMPRESSIBLE_NOISE_LENGTH; DISPLAYLEVEL(3, "Using NULL preferences : \n"); cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, NULL), CNBuffer, testSize, NULL); @@ -385,7 +386,6 @@ int basicTests(U32 seed, double compressibility) size_t errorCode; BYTE* const ostart = (BYTE*)compressedBuffer; BYTE* op = ostart; - LZ4F_compressionContext_t cctx; errorCode = LZ4F_createCompressionContext(&cctx, LZ4F_VERSION); if (LZ4F_isError(errorCode)) goto _output_error; @@ -430,6 +430,7 @@ int basicTests(U32 seed, double compressibility) errorCode = LZ4F_freeCompressionContext(cctx); if (LZ4F_isError(errorCode)) goto _output_error; + cctx = NULL; } DISPLAYLEVEL(3, "Skippable frame test : \n"); @@ -500,10 +501,6 @@ int basicTests(U32 seed, double compressibility) ip += iSize; } DISPLAYLEVEL(3, "Skipped %i bytes \n", (int)(ip - (BYTE*)compressedBuffer - 8)); - - /* release memory */ - errorCode = LZ4F_freeDecompressionContext(dCtx); - if (LZ4F_isError(errorCode)) goto _output_error; } DISPLAY("Basic tests completed \n"); @@ -511,6 +508,8 @@ _end: free(CNBuffer); free(compressedBuffer); free(decodedBuffer); + LZ4F_freeDecompressionContext(dCtx); dCtx = NULL; + LZ4F_freeCompressionContext(cctx); cctx = NULL; return testResult; _output_error: @@ -667,6 +666,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi unsigned nonContiguousDst = (FUZ_rand(&randState) & 3) == 1; nonContiguousDst += FUZ_rand(&randState) & nonContiguousDst; /* 0=>0; 1=>1,2 */ XXH64_reset(&xxh64, 1); + if (maxBits < 3) maxBits = 3; while (ip < iend) { unsigned nbBitsI = (FUZ_rand(&randState) % (maxBits-1)) + 1; @@ -709,7 +709,7 @@ _end: if (pause) { DISPLAY("press enter to finish \n"); - getchar(); + (void)getchar(); } return testResult; diff --git a/programs/fullbench.c b/programs/fullbench.c index 700655b..8c95d29 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -533,14 +533,15 @@ static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outS } +#define NB_COMPRESSION_ALGORITHMS 100 +#define NB_DECOMPRESSION_ALGORITHMS 100 +#define CLEANEXIT(c) { benchStatus = c; goto _clean_up; } int fullSpeedBench(char** fileNamesTable, int nbFiles) { int fileIdx=0; char* orig_buff; -# define NB_COMPRESSION_ALGORITHMS 100 -# define NB_DECOMPRESSION_ALGORITHMS 100 size_t errorCode; - + int benchStatus = 0; /* Loop for each fileName */ while (fileIdx %.2f%%\n", (unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100); { @@ -538,6 +539,7 @@ static unsigned LZ4IO_readLE32 (const void* s) return value32; } +static unsigned g_magicRead = 0; static unsigned long long decodeLegacyStream(FILE* finput, FILE* foutput) { unsigned long long filesize = 0; @@ -562,7 +564,7 @@ static unsigned long long decodeLegacyStream(FILE* finput, FILE* foutput) blockSize = LZ4IO_readLE32(in_buff); /* Convert to Little Endian */ if (blockSize > LZ4_COMPRESSBOUND(LEGACY_BLOCKSIZE)) { /* Cannot read next block : maybe new stream ? */ - fseek(finput, -4, SEEK_CUR); + g_magicRead = blockSize; break; } @@ -761,10 +763,18 @@ static unsigned long long selectDecoder( FILE* finput, FILE* foutput) nbCalls++; /* Check Archive Header */ - nbReadBytes = fread(U32store, 1, MAGICNUMBER_SIZE, finput); - if (nbReadBytes==0) return ENDOFSTREAM; /* EOF */ - if (nbReadBytes != MAGICNUMBER_SIZE) EXM_THROW(40, "Unrecognized header : Magic Number unreadable"); - magicNumber = LZ4IO_readLE32(U32store); /* Little Endian format */ + if (g_magicRead) + { + magicNumber = g_magicRead; + g_magicRead = 0; + } + else + { + nbReadBytes = fread(U32store, 1, MAGICNUMBER_SIZE, finput); + if (nbReadBytes==0) return ENDOFSTREAM; /* EOF */ + if (nbReadBytes != MAGICNUMBER_SIZE) EXM_THROW(40, "Unrecognized header : Magic Number unreadable"); + magicNumber = LZ4IO_readLE32(U32store); /* Little Endian format */ + } if (LZ4IO_isSkippableMagicNumber(magicNumber)) magicNumber = LZ4IO_SKIPPABLE0; /* fold skippable magic numbers */ switch(magicNumber) @@ -809,7 +819,7 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file get_fileHandle(input_filename, output_filename, &finput, &foutput); /* sparse file */ - if (g_sparseFileSupport && foutput) { SET_SPARSE_FILE_MODE(foutput); } + if (g_sparseFileSupport) { SET_SPARSE_FILE_MODE(foutput); } /* Loop over multiple streams */ do -- cgit v0.12 From 66b8a4a8afe72ac37a26199249a78a5349201472 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 08:58:00 +0100 Subject: Fixed : minor Visual warnings --- programs/fullbench.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/programs/fullbench.c b/programs/fullbench.c index 8c95d29..4ffae59 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -684,7 +684,6 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) break; default : continue; /* unknown ID : just skip */ - DISPLAY("ERROR ! Bad algorithm Id !! \n"); free(chunkP); return 1; } for (loopNb = 1; loopNb <= nbIterations; loopNb++) @@ -774,7 +773,6 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) break; default : continue; /* skip if unknown ID */ - DISPLAY("ERROR ! Bad decompression algorithm Id !! \n"); CLEANEXIT(1); } { size_t i; for (i=0; i Date: Sun, 12 Apr 2015 17:28:53 +0900 Subject: Add LZ4 prefix to deprecation macros Replace the following macros: - "_DEPRECATE_WARNING_DEFBLOCK" to "LZ4_DEPRECATE_WARNING_DEFBLOCK" - "DEPRECATED" to "LZ4_DEPRECATED" --- lib/lz4.h | 30 +++++++++++++++--------------- lib/lz4hc.h | 32 ++++++++++++++++---------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/lz4.h b/lib/lz4.h index 0ee1a1e..20e3c01 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -285,21 +285,21 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS it is generally possible to disable them, with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual for example. - You can also define _DEPRECATE_WARNING_DEFBLOCK. */ -#ifndef _DEPRECATE_WARNING_DEFBLOCK -# define _DEPRECATE_WARNING_DEFBLOCK + You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */ +#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK +# define LZ4_DEPRECATE_WARNING_DEFBLOCK # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) # if (GCC_VERSION >= 405) || defined(__clang__) -# define DEPRECATED(message) __attribute__((deprecated(message))) +# define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) # elif (GCC_VERSION >= 301) -# define DEPRECATED(message) __attribute__((deprecated)) +# define LZ4_DEPRECATED(message) __attribute__((deprecated)) # elif defined(_MSC_VER) -# define DEPRECATED(message) __declspec(deprecated(message)) +# define LZ4_DEPRECATED(message) __declspec(deprecated(message)) # else -# pragma message("WARNING: You need to implement DEPRECATED for this compiler") -# define DEPRECATED +# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") +# define LZ4_DEPRECATED # endif -#endif // _DEPRECATE_WARNING_DEFBLOCK +#endif // LZ4_DEPRECATE_WARNING_DEFBLOCK /* Obsolete compression functions */ /* These functions are planned to generate warnings by r131 approximately */ @@ -321,14 +321,14 @@ int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const cha /* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */ /* Obsolete streaming functions; use new streaming interface whenever possible */ -DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (const char* inputBuffer); -DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); -DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, const char* inputBuffer); -DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); +LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); +LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); /* Obsolete streaming decoding functions */ -DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize); -DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize); +LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize); +LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize); #if defined (__cplusplus) diff --git a/lib/lz4hc.h b/lib/lz4hc.h index 7a5bb02..95bb6fe 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -142,21 +142,21 @@ using LZ4_saveDictHC(). it is generally possible to disable them, with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual for example. - You can also define _DEPRECATE_WARNING_DEFBLOCK. */ -#ifndef _DEPRECATE_WARNING_DEFBLOCK -# define _DEPRECATE_WARNING_DEFBLOCK + You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */ +#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK +# define LZ4_DEPRECATE_WARNING_DEFBLOCK # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) # if (GCC_VERSION >= 405) || defined(__clang__) -# define DEPRECATED(message) __attribute__((deprecated(message))) +# define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) # elif (GCC_VERSION >= 301) -# define DEPRECATED(message) __attribute__((deprecated)) +# define LZ4_DEPRECATED(message) __attribute__((deprecated)) # elif defined(_MSC_VER) -# define DEPRECATED(message) __declspec(deprecated(message)) +# define LZ4_DEPRECATED(message) __declspec(deprecated(message)) # else -# pragma message("WARNING: You need to implement DEPRECATED for this compiler") -# define DEPRECATED +# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") +# define LZ4_DEPRECATED # endif -#endif // _DEPRECATE_WARNING_DEFBLOCK +#endif // LZ4_DEPRECATE_WARNING_DEFBLOCK /* compression functions */ /* these functions are planned to trigger warning messages by r131 approximately */ @@ -172,13 +172,13 @@ int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, cons int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); /* Streaming functions following the older model; should no longer be used */ -DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (const char* inputBuffer); -DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data); -DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data); -DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); -DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); -DEPRECATED("use LZ4_createStreamHC() instead") int LZ4_sizeofStreamStateHC(void); -DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data); +LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data); +LZ4_DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); +LZ4_DEPRECATED("use LZ4_compressHC_safe_continue() instead") 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") int LZ4_sizeofStreamStateHC(void); +LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); #if defined (__cplusplus) -- cgit v0.12 From 81fdd9df23821d5db8331e66478e2617b470820c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 09:29:52 +0100 Subject: Fixed a few Valgrind warnings --- lib/lz4.c | 5 +++-- lib/lz4hc.c | 2 +- programs/fullbench.c | 52 +++++++++++++++++----------------------------------- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index d6fdcd9..e57d080 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -756,6 +756,7 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_stream) } +#define HASH_UNIT sizeof(size_t) int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) { LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict; @@ -765,7 +766,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) if (dict->initCheck) LZ4_resetStream(LZ4_dict); /* Uninitialized structure detected */ - if (dictSize < MINMATCH) + if (dictSize < HASH_UNIT) { dict->dictionary = NULL; dict->dictSize = 0; @@ -778,7 +779,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) dict->dictSize = (U32)(dictEnd - p); dict->currentOffset += dict->dictSize; - while (p <= dictEnd-MINMATCH) + while (p <= dictEnd-HASH_UNIT) { LZ4_putPosition(p, dict, byU32, base); p+=3; diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 234e1af..4f1272c 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -656,7 +656,7 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS if (dictSize > 64 KB) dictSize = 64 KB; if (dictSize < 4) dictSize = 0; if (dictSize > prefixSize) dictSize = prefixSize; - memcpy(safeBuffer, streamPtr->end - dictSize, dictSize); + memmove(safeBuffer, streamPtr->end - dictSize, dictSize); { U32 endIndex = (U32)(streamPtr->end - streamPtr->base); streamPtr->end = (const BYTE*)safeBuffer + dictSize; diff --git a/programs/fullbench.c b/programs/fullbench.c index 4ffae59..51e0e9a 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -539,10 +539,16 @@ static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outS int fullSpeedBench(char** fileNamesTable, int nbFiles) { int fileIdx=0; - char* orig_buff; + char* orig_buff = NULL; + struct chunkParameters* chunkP = NULL; + char* compressed_buff=NULL; size_t errorCode; int benchStatus = 0; + /* Init */ + errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION); + if (LZ4F_isError(errorCode)) { DISPLAY("dctx allocation issue \n"); CLEANEXIT(10); } + /* Loop for each fileName */ while (fileIdx inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); /* Allocation */ - errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION); - if (LZ4F_isError(errorCode)) - { - DISPLAY("dctx allocation issue \n"); - fclose(inFile); - return 10; - } chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters)); orig_buff = (char*) malloc((size_t)benchedSize); nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); maxCompressedChunkSize = LZ4_compressBound(chunkSize); compressedBuffSize = nbChunks * maxCompressedChunkSize; compressed_buff = (char*)malloc((size_t)compressedBuffSize); - - - if(!orig_buff || !compressed_buff) - { - DISPLAY("\nError: not enough memory!\n"); - free(orig_buff); - free(compressed_buff); - free(chunkP); - fclose(inFile); - return 12; - } + if(!orig_buff || !compressed_buff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); CLEANEXIT(12); } /* Fill in src buffer */ DISPLAY("Loading %s... \r", inFileName); @@ -813,15 +796,14 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) DISPLAY("%2i-%-29.29s :%10i -> %7.1f MB/s\n", dAlgNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000.); } - } + } _clean_up: - free(orig_buff); - free(compressed_buff); - free(chunkP); - LZ4F_freeDecompressionContext(g_dCtx); - } + free(orig_buff); + free(compressed_buff); + free(chunkP); + LZ4F_freeDecompressionContext(g_dCtx); if (BMK_pause) { printf("press enter...\n"); (void)getchar(); } -- cgit v0.12 From 138673df5e1f42d098a55d23fe84228726e9739d Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 09:37:34 +0100 Subject: fixed minor g++ warning --- lib/lz4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4.c b/lib/lz4.c index e57d080..4a6c550 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -766,7 +766,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) if (dict->initCheck) LZ4_resetStream(LZ4_dict); /* Uninitialized structure detected */ - if (dictSize < HASH_UNIT) + if (dictSize < (int)HASH_UNIT) { dict->dictionary = NULL; dict->dictSize = 0; -- cgit v0.12 From 8a610004f6ac5bf5966b8a16da5a240d289b538b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 09:42:58 +0100 Subject: Fixed a few coverity warnings --- programs/bench.c | 3 ++- programs/fullbench.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/programs/bench.c b/programs/bench.c index 8921f09..d3b060c 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -287,7 +287,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) inFileSize = BMK_GetFileSize(inFileName); if (inFileSize==0) { DISPLAY( "file is empty\n"); fclose(inFile); return 11; } benchedSize = (size_t) BMK_findMaxMem(inFileSize * 2) / 2; - if (benchedSize==0) { DISPLAY( "not enough memory\n"); return 11; } + if (benchedSize==0) { DISPLAY( "not enough memory\n"); fclose(inFile); return 11; } if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) { @@ -376,6 +376,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) } milliTime = BMK_GetMilliSpan(milliTime); + nbLoops += !nbLoops; /* avoid division by zero */ if ((double)milliTime < fastestC*nbLoops) fastestC = (double)milliTime/nbLoops; cSize=0; for (chunkNb=0; chunkNb Date: Sun, 12 Apr 2015 11:37:55 +0100 Subject: Fixed : minor coverity warning --- programs/fullbench.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/fullbench.c b/programs/fullbench.c index 40d95e5..658c365 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -569,9 +569,9 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) /* Memory size adjustments */ inFileSize = BMK_GetFileSize(inFileName); - if (inFileSize==0) { DISPLAY( "file is empty\n"); CLEANEXIT(11); } + if (inFileSize==0) { DISPLAY( "file is empty\n"); fclose(inFile); CLEANEXIT(11); } benchedSize = (size_t) BMK_findMaxMem(inFileSize*2) / 2; /* because 2 buffers */ - if (benchedSize==0) { DISPLAY( "not enough memory\n"); CLEANEXIT(11); } + if (benchedSize==0) { DISPLAY( "not enough memory\n"); fclose(inFile); CLEANEXIT(11); } if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); -- cgit v0.12 From 2852b9e439d7ad27c09641b1b5d108887a159a01 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 15:17:10 +0100 Subject: Fixed issue #84 --- Makefile | 4 ++-- lib/lz4.c | 13 +++++++------ lib/lz4frame.c | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 32f38aa..b4b1c6b 100644 --- a/Makefile +++ b/Makefile @@ -101,10 +101,10 @@ gpptest: clean $(MAKE) all CC=g++ CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror" clangtest: clean - $(MAKE) all CC=clang CFLAGS="-O3 -Werror" + $(MAKE) all CC=clang CPPFLAGS="-Werror -Wconversion -Wno-sign-conversion" sanitize: clean - $(MAKE) test CC=clang CFLAGS="-O3 -g -fsanitize=undefined" FUZZER_TIME="-T5mn" + $(MAKE) test CC=clang CPPFLAGS="-g -fsanitize=undefined" FUZZER_TIME="-T5mn" staticAnalyze: clean scan-build -v $(MAKE) all CFLAGS=-g diff --git a/lib/lz4.c b/lib/lz4.c index 4a6c550..d8e4977 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -94,6 +94,7 @@ # endif /* __STDC_VERSION__ */ #endif /* _MSC_VER */ +/* GCC_VERSION is defined into lz4.h */ #if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__) # define expect(expr,value) (__builtin_expect ((expr),(value)) ) #else @@ -260,7 +261,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r = 0; _BitScanForward64( &r, (U64)val ); return (int)(r>>3); -# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) +# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) return (__builtin_ctzll((U64)val) >> 3); # else static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 }; @@ -273,7 +274,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r; _BitScanForward( &r, (U32)val ); return (int)(r>>3); -# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) +# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) return (__builtin_ctz((U32)val) >> 3); # else static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 }; @@ -289,8 +290,8 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r = 0; _BitScanReverse64( &r, val ); return (unsigned)(r>>3); -# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) - return (__builtin_clzll(val) >> 3); +# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_clzll((U64)val) >> 3); # else unsigned r; if (!(val>>32)) { r=4; } else { r=0; val>>=32; } @@ -305,8 +306,8 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r = 0; _BitScanReverse( &r, (unsigned long)val ); return (unsigned)(r>>3); -# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) - return (__builtin_clz(val) >> 3); +# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_clz((U32)val) >> 3); # else unsigned r; if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 7094364..31cf9a5 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -447,10 +447,10 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds headerStart = dstPtr; /* FLG Byte */ - *dstPtr++ = ((1 & _2BITS) << 6) /* Version('01') */ + *dstPtr++ = (BYTE)(((1 & _2BITS) << 6) /* Version('01') */ + ((cctxPtr->prefs.frameInfo.blockMode & _1BIT ) << 5) /* Block mode */ - + (BYTE)((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2) /* Frame checksum */ - + (BYTE)((cctxPtr->prefs.frameInfo.contentSize > 0) << 3); /* Frame content size */ + + ((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2) /* Frame checksum */ + + ((cctxPtr->prefs.frameInfo.contentSize > 0) << 3)); /* Frame content size */ /* BD Byte */ *dstPtr++ = (BYTE)((cctxPtr->prefs.frameInfo.blockSizeID & _3BITS) << 4); /* Optional Frame content size field */ -- cgit v0.12 From 42e5bc4a9dab26a9d1fbc9899e107b3fb926233c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 16:06:12 +0100 Subject: Updated badges --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bcb8d7c..0945f85 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ It trades CPU time for compression ratio. |Branch |Status | |------------|---------| -|master | [![Build Status](https://travis-ci.org/Cyan4973/lz4.svg?branch=master)](https://travis-ci.org/Cyan4973/lz4) | -|dev | [![Build Status](https://travis-ci.org/Cyan4973/lz4.svg?branch=dev)](https://travis-ci.org/Cyan4973/lz4) | -|visual | [![Build status](https://ci.appveyor.com/api/projects/status/v6kxv9si529477cq?svg=true)](https://ci.appveyor.com/project/YannCollet/lz4) | +|master | [![Build Status](https://travis-ci.org/Cyan4973/lz4.svg?branch=master)](https://travis-ci.org/Cyan4973/lz4) [![Build status](https://ci.appveyor.com/api/projects/status/v6kxv9si529477cq/branch/master?svg=true)](https://ci.appveyor.com/project/YannCollet/lz4) | +|dev | [![Build Status](https://travis-ci.org/Cyan4973/lz4.svg?branch=dev)](https://travis-ci.org/Cyan4973/lz4) [![Build status](https://ci.appveyor.com/api/projects/status/v6kxv9si529477cq/branch/dev?svg=true)](https://ci.appveyor.com/project/YannCollet/lz4) | + -- cgit v0.12 From 2c7988761dcd7e5435c519eeffef32a90eed93ad Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 16:40:58 +0100 Subject: Shortened tests durations --- Makefile | 2 +- programs/Makefile | 1 + programs/frametest.c | 33 +++++++++++++++------------------ programs/fullbench.c | 51 +++++++++++++++++++++++++++++++-------------------- programs/fuzzer.c | 33 +++++++++++++++------------------ 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index b4b1c6b..b83d920 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ clangtest: clean $(MAKE) all CC=clang CPPFLAGS="-Werror -Wconversion -Wno-sign-conversion" sanitize: clean - $(MAKE) test CC=clang CPPFLAGS="-g -fsanitize=undefined" FUZZER_TIME="-T5mn" + $(MAKE) test CC=clang CPPFLAGS="-g -fsanitize=undefined" FUZZER_TIME="-T1mn" staticAnalyze: clean scan-build -v $(MAKE) all CFLAGS=-g diff --git a/programs/Makefile b/programs/Makefile index 97be7d9..5ea0593 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -61,6 +61,7 @@ endif TRAVIS_TARGET:= $(LZ4_TRAVIS_CI_ENV) TEST_FILES := COPYING TEST_TARGETS := test-native +FUZZER_TIME := -T9mn default: lz4 diff --git a/programs/frametest.c b/programs/frametest.c index 6204d7a..60cd765 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -726,7 +726,7 @@ int FUZ_usage(void) DISPLAY( "\n"); DISPLAY( "Arguments :\n"); DISPLAY( " -i# : Nb of tests (default:%u) \n", nbTestsDefault); - DISPLAY( " -T# : Duration of tests (default: use Nb of tests) \n"); + DISPLAY( " -T# : Duration of tests, in seconds (default: use Nb of tests) \n"); DISPLAY( " -s# : Select seed (default:prompt user)\n"); DISPLAY( " -t# : Select starting test number (default:0)\n"); DISPLAY( " -p# : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT); @@ -800,26 +800,23 @@ int main(int argc, char** argv) case 'T': argument++; nbTests = 0; duration = 0; - for (;;) { - if (argument[0]=='m') - { - duration *= 60; - argument++; - continue; - } - if (argument[0]=='n') - { - argument++; - continue; - } - if ((*argument>='0') && (*argument<='9')) + switch(*argument) { - duration *= 10; - duration += *argument - '0'; - argument++; - continue; + case 'm': duration *= 60; argument++; continue; + case 's': + case 'n': argument++; continue; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': duration *= 10; duration += *argument++ - '0'; continue; } break; } diff --git a/programs/fullbench.c b/programs/fullbench.c index 658c365..ed53819 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -535,24 +535,22 @@ static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outS #define NB_COMPRESSION_ALGORITHMS 100 #define NB_DECOMPRESSION_ALGORITHMS 100 -#define CLEANEXIT(c) { benchStatus = c; goto _clean_up; } int fullSpeedBench(char** fileNamesTable, int nbFiles) { int fileIdx=0; - char* orig_buff = NULL; - struct chunkParameters* chunkP = NULL; - char* compressed_buff=NULL; size_t errorCode; - int benchStatus = 0; /* Init */ errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION); - if (LZ4F_isError(errorCode)) { DISPLAY("dctx allocation issue \n"); CLEANEXIT(10); } + if (LZ4F_isError(errorCode)) { DISPLAY("dctx allocation issue \n"); return 10; } /* Loop for each fileName */ while (fileIdx inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); /* Allocation */ chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters)); - orig_buff = (char*) malloc((size_t)benchedSize); - nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); + orig_buff = (char*) malloc(benchedSize); + nbChunks = (int) ((benchedSize + (chunkSize-1)) / chunkSize); maxCompressedChunkSize = LZ4_compressBound(chunkSize); compressedBuffSize = nbChunks * maxCompressedChunkSize; compressed_buff = (char*)malloc((size_t)compressedBuffSize); - if(!orig_buff || !compressed_buff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); CLEANEXIT(12); } + if(!chunkP || !orig_buff || !compressed_buff) + { + DISPLAY("\nError: not enough memory!\n"); + fclose(inFile); + free(orig_buff); + free(compressed_buff); + free(chunkP); + return(12); + } /* Fill in src buffer */ DISPLAY("Loading %s... \r", inFileName); @@ -600,7 +606,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) } /* Calculating input Checksum */ - crcOriginal = XXH32(orig_buff, (unsigned int)benchedSize,0); + crcOriginal = XXH32(orig_buff, benchedSize,0); /* Bench */ @@ -750,7 +756,14 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) case 8: decompressionFunction = local_LZ4_decompress_safe_forceExtDict; dName = "LZ4_decompress_safe_forceExtDict"; break; case 9: decompressionFunction = local_LZ4F_decompress; dName = "LZ4F_decompress"; errorCode = LZ4F_compressFrame(compressed_buff, compressedBuffSize, orig_buff, benchedSize, NULL); - if (LZ4F_isError(errorCode)) { DISPLAY("Preparation error compressing frame\n"); CLEANEXIT(1); } + if (LZ4F_isError(errorCode)) + { + DISPLAY("Error while preparing compressed frame\n"); + free(orig_buff); + free(compressed_buff); + free(chunkP); + return 1; + } chunkP[0].origSize = (int)benchedSize; chunkP[0].compressedSize = (int)errorCode; nbChunks = 1; @@ -798,17 +811,15 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) DISPLAY("%2i-%-29.29s :%10i -> %7.1f MB/s\n", dAlgNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000.); } } + free(orig_buff); + free(compressed_buff); + free(chunkP); } -_clean_up: - free(orig_buff); - free(compressed_buff); - free(chunkP); LZ4F_freeDecompressionContext(g_dCtx); - if (BMK_pause) { printf("press enter...\n"); (void)getchar(); } - return benchStatus; + return 0; } diff --git a/programs/fuzzer.c b/programs/fuzzer.c index aa91ee8..1704b6e 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -1017,7 +1017,7 @@ static int FUZ_usage(char* programName) DISPLAY( "\n"); DISPLAY( "Arguments :\n"); DISPLAY( " -i# : Nb of tests (default:%i) \n", NB_ATTEMPTS); - DISPLAY( " -T# : Duration of tests (default: use Nb of tests) \n"); + DISPLAY( " -T# : Duration of tests, in seconds (default: use Nb of tests) \n"); DISPLAY( " -s# : Select seed (default:prompt user)\n"); DISPLAY( " -t# : Select starting test number (default:0)\n"); DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT); @@ -1084,26 +1084,23 @@ int main(int argc, char** argv) case 'T': argument++; nbTests = 0; duration = 0; - for (;;) { - if (argument[0]=='m') - { - duration *= 60; - argument++; - continue; - } - if (argument[0]=='n') - { - argument++; - continue; - } - if ((*argument>='0') && (*argument<='9')) + switch(*argument) { - duration *= 10; - duration += *argument - '0'; - argument++; - continue; + case 'm': duration *= 60; argument++; continue; + case 's': + case 'n': argument++; continue; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': duration *= 10; duration += *argument++ - '0'; continue; } break; } -- cgit v0.12 From da117257f5946295a379ca7ccf867c2854b0aed9 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 12 Apr 2015 16:49:37 +0100 Subject: new memory leak test for fullbench using multi-files --- programs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Makefile b/programs/Makefile index 5ea0593..2b0b8a9 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -251,7 +251,7 @@ test-mem: lz4 datagen fuzzer frametest fullbench valgrind --leak-check=yes ./lz4 -9 -B5D -f tmp tmp2 valgrind --leak-check=yes ./lz4 -t tmp2 valgrind --leak-check=yes ./lz4 -bi1 tmp - valgrind --leak-check=yes ./fullbench -i1 tmp + valgrind --leak-check=yes ./fullbench -i1 tmp tmp2 ./datagen -g256MB > tmp valgrind --leak-check=yes ./lz4 -B4D -f -vq tmp $(VOID) rm tmp* -- cgit v0.12 From 0169502b49dfa5eb8878f5c85be3270012266fc3 Mon Sep 17 00:00:00 2001 From: Kyle J Harper Date: Sun, 12 Apr 2015 17:28:13 -0500 Subject: Added new LZ4IO_decompressMultipleFilenames to allow decompression of multiple files with the -m switch added in r128 (ref: google code issue 151). Limitation: will only process files matching LZ4_EXTENSION macro, which for now seems reasonable. --- programs/lz4cli.c | 32 +++++++++++++++++++------------- programs/lz4io.c | 28 ++++++++++++++++++++++++++++ programs/lz4io.h | 3 ++- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index da5da71..f7cf27e 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -515,22 +515,28 @@ int main(int argc, char** argv) /* IO Stream/File */ LZ4IO_setNotificationLevel(displayLevel); - if (decode) DEFAULT_DECOMPRESSOR(input_filename, output_filename); + if (decode) + { + if (multiple_inputs) + LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); + else + DEFAULT_DECOMPRESSOR(input_filename, output_filename); + } else { - /* compression is default action */ - if (legacy_format) - { - DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n"); - LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel); - } + /* compression is default action */ + if (legacy_format) + { + DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n"); + LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel); + } + else + { + if (multiple_inputs) + LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); else - { - if (multiple_inputs) - LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); - else - DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); - } + DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); + } } if (main_pause) waitEnter(); diff --git a/programs/lz4io.c b/programs/lz4io.c index 02e03c8..16a588c 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -517,6 +517,34 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, return 0; } +int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) +{ + int i; + int skipped_files = 0; + char* outFileName = (char*)malloc(FNSPACE); + size_t ofnSize = FNSPACE; + size_t suffixSize = strlen(suffix); + char* ifnSuffix = (char*)malloc(suffixSize + 1); + + for (i=0; i Date: Sun, 12 Apr 2015 18:41:55 -0500 Subject: Added support for continuation of file compression and decompression if input files are missing. Should more closely match gzip/bzip2/xz and so forth. Also removed a debug print accidentally left in. --- programs/lz4cli.c | 8 +++++--- programs/lz4io.c | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index f7cf27e..f3524b3 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -265,7 +265,8 @@ int main(int argc, char** argv) forceStdout=0, forceCompress=0, main_pause=0, - multiple_inputs=0; + multiple_inputs=0, + multiple_rv=0; const char* input_filename=0; const char* output_filename=0; char* dynNameSpace=0; @@ -518,7 +519,7 @@ int main(int argc, char** argv) if (decode) { if (multiple_inputs) - LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); + multiple_rv = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); else DEFAULT_DECOMPRESSOR(input_filename, output_filename); } @@ -533,7 +534,7 @@ int main(int argc, char** argv) else { if (multiple_inputs) - LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); + multiple_rv = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); else DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); } @@ -542,5 +543,6 @@ int main(int argc, char** argv) if (main_pause) waitEnter(); free(dynNameSpace); free((void*)inFileNames); + if (multiple_rv != 0) return multiple_rv; return 0; } diff --git a/programs/lz4io.c b/programs/lz4io.c index 16a588c..d399c90 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -501,12 +501,21 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel) { int i; + int missing_files = 0; + FILE *ifp; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); for (i=0; i 0) return 1; return 0; } @@ -521,6 +531,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz { int i; int skipped_files = 0; + int missing_files = 0; + FILE *ifp; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; size_t suffixSize = strlen(suffix); @@ -528,13 +540,19 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz for (i=0; i 0) return 1; + if (missing_files > 0) return 1; return 0; } -- cgit v0.12 From b036eaade6bccc6a2358d22c874acff062762900 Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Mon, 13 Apr 2015 20:05:20 +0900 Subject: Add snprintf macro for MSVC --- examples/blockStreaming_doubleBuffer.c | 5 ++++- examples/blockStreaming_lineByLine.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/blockStreaming_doubleBuffer.c b/examples/blockStreaming_doubleBuffer.c index 0adf6ae..094f80d 100644 --- a/examples/blockStreaming_doubleBuffer.c +++ b/examples/blockStreaming_doubleBuffer.c @@ -2,7 +2,10 @@ // Copyright : Takayuki Matsuoka -#define _CRT_SECURE_NO_WARNINGS // for MSVC +#ifdef _MSC_VER /* Visual Studio */ +# define _CRT_SECURE_NO_WARNINGS +# define snprintf sprintf_s +#endif #include "lz4.h" #include diff --git a/examples/blockStreaming_lineByLine.c b/examples/blockStreaming_lineByLine.c index 6d14801..f0f7d46 100644 --- a/examples/blockStreaming_lineByLine.c +++ b/examples/blockStreaming_lineByLine.c @@ -2,7 +2,10 @@ // Copyright : Takayuki Matsuoka -#define _CRT_SECURE_NO_WARNINGS // for MSVC +#ifdef _MSC_VER /* Visual Studio */ +# define _CRT_SECURE_NO_WARNINGS +# define snprintf sprintf_s +#endif #include "lz4.h" #include -- cgit v0.12 From fd77bad52f39106dc1af40405076581426e86877 Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Mon, 13 Apr 2015 20:16:37 +0900 Subject: Replace obsolete functions --- examples/blockStreaming_doubleBuffer.c | 4 ++-- examples/blockStreaming_lineByLine.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/blockStreaming_doubleBuffer.c b/examples/blockStreaming_doubleBuffer.c index 094f80d..58f2bdb 100644 --- a/examples/blockStreaming_doubleBuffer.c +++ b/examples/blockStreaming_doubleBuffer.c @@ -53,8 +53,8 @@ void test_compress(FILE* outFp, FILE* inpFp) { char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)]; - const int cmpBytes = LZ4_compress_continue( - lz4Stream, inpPtr, cmpBuf, inpBytes); + const int cmpBytes = LZ4_compress_safe_continue( + lz4Stream, inpPtr, cmpBuf, inpBytes, sizeof(cmpBuf)); if(cmpBytes <= 0) { break; } diff --git a/examples/blockStreaming_lineByLine.c b/examples/blockStreaming_lineByLine.c index f0f7d46..8ae268f 100644 --- a/examples/blockStreaming_lineByLine.c +++ b/examples/blockStreaming_lineByLine.c @@ -41,7 +41,8 @@ static void test_compress( size_t ringBufferBytes) { LZ4_stream_t* const lz4Stream = LZ4_createStream(); - char* const cmpBuf = malloc(LZ4_COMPRESSBOUND(messageMaxBytes)); + const size_t cmpBufBytes = LZ4_COMPRESSBOUND(messageMaxBytes); + char* const cmpBuf = malloc(cmpBufBytes); char* const inpBuf = malloc(ringBufferBytes); int inpOffset = 0; @@ -63,8 +64,8 @@ static void test_compress( #endif { - const int cmpBytes = LZ4_compress_continue( - lz4Stream, inpPtr, cmpBuf, inpBytes); + const int cmpBytes = LZ4_compress_safe_continue( + lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes); if (cmpBytes <= 0) break; write_uint16(outFp, (uint16_t) cmpBytes); write_bin(outFp, cmpBuf, cmpBytes); -- cgit v0.12 From d535214e6101f5bb4697208d439306ca69399c7c Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Mon, 13 Apr 2015 10:57:31 -0700 Subject: Add more descriptive frame errors --- lib/lz4frame.c | 14 +++++++------- lib/lz4frame_static.h | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 474b196..2476464 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -854,16 +854,16 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo blockSizeID = (BD>>4) & _3BITS; /* validate */ - if (version != 1) return (size_t)-ERROR_GENERIC; /* Version Number, only supported value */ - if (blockChecksumFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */ - if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */ - if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bit */ - if (blockSizeID < 4) return (size_t)-ERROR_GENERIC; /* 4-7 only supported values for the time being */ - if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */ + if (version != 1) return (size_t)-ERROR_version_wrong; /* Version Number, only supported value */ + if (blockChecksumFlag != 0) return (size_t)-ERROR_unsupported_checksum; /* Only supported value for the time being */ + if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ + if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bit */ + if (blockSizeID < 4) return (size_t)-ERROR_unsupported_block_size; /* 4-7 only supported values for the time being */ + if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ /* check */ HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5); - if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_GENERIC; /* Bad header checksum error */ + if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_header_checksum_invalid; /* Bad header checksum error */ /* save */ dctxPtr->frameInfo.blockMode = (blockMode_t)blockMode; diff --git a/lib/lz4frame_static.h b/lib/lz4frame_static.h index 2e56400..b608d23 100644 --- a/lib/lz4frame_static.h +++ b/lib/lz4frame_static.h @@ -57,6 +57,11 @@ extern "C" { ITEM(ERROR_wrongSrcPtr) \ ITEM(ERROR_decompressionFailed) \ ITEM(ERROR_checksum_invalid) \ + ITEM(ERROR_version_wrong) \ + ITEM(ERROR_unsupported_checksum) \ + ITEM(ERROR_reserved_flag_set) \ + ITEM(ERROR_unsupported_block_size) \ + ITEM(ERROR_header_checksum_invalid) \ ITEM(ERROR_maxCode) #define LZ4F_GENERATE_ENUM(ENUM) ENUM, -- cgit v0.12 From cc2412401400fbacd7530b8dcc4af0b0d7c734ce Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 13 Apr 2015 20:43:54 +0100 Subject: minor compatibility fixes --- README.md | 7 +++---- programs/lz4.1 | 6 +++--- programs/lz4cli.c | 14 ++++++++------ programs/lz4io.c | 21 ++++++++++++--------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0945f85..5d506d4 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,11 @@ It trades CPU time for compression ratio. > **Branch Policy:** > - The "master" branch is considered stable, at all times. -> - The "dev" branch is the one where all contributions must be merged +> - The "dev" branch is the one where all contributions must be merged before being promoted to master. -> + If you plan to propose a patch, please commit into the "dev" branch. +> + If you plan to propose a patch, please commit into the "dev" branch, + or its own feature branch. Direct commit to "master" are not permitted. -> - Feature branches can also exist, - for dedicated tests of larger modifications before merge into "dev" branch. Benchmarks ------------------------- diff --git a/programs/lz4.1 b/programs/lz4.1 index 1225832..eea248f 100644 --- a/programs/lz4.1 +++ b/programs/lz4.1 @@ -158,13 +158,13 @@ for files that have not been compressed with force write to standard output, even if it is the console .TP -.BR \-m +.BR \-m ", " \--multiple Multiple file names. By default, the second filename is used as the output filename for the compressed file. With .B -m -, you can specify any number of input filenames, each of them will be compressed -with the resulting compressed file named +, you can specify any number of input filenames. Each of them will be compressed +independently, and the resulting name of the compressed file will be .B filename.lz4 . diff --git a/programs/lz4cli.c b/programs/lz4cli.c index ffc54c0..8d7d5ca 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -266,7 +266,7 @@ int main(int argc, char** argv) forceCompress=0, main_pause=0, multiple_inputs=0, - multiple_rv=0; + operationResult=0; const char* input_filename=0; const char* output_filename=0; char* dynNameSpace=0; @@ -295,12 +295,13 @@ int main(int argc, char** argv) /* long commands (--long-word) */ if (!strcmp(argument, "--compress")) { forceCompress = 1; continue; } if ((!strcmp(argument, "--decompress")) - || (!strcmp(argument, "--uncompress"))) { decode = 1; continue; } + || (!strcmp(argument, "--uncompress"))) { decode = 1; continue; } + if (!strcmp(argument, "--multiple")) { multiple_inputs = 1; if (inFileNames==NULL) inFileNames = (const char**)malloc(argc * sizeof(char*)); continue; } if (!strcmp(argument, "--test")) { decode = 1; LZ4IO_setOverwrite(1); output_filename=nulmark; continue; } if (!strcmp(argument, "--force")) { LZ4IO_setOverwrite(1); continue; } if (!strcmp(argument, "--no-force")) { LZ4IO_setOverwrite(0); continue; } if ((!strcmp(argument, "--stdout")) - || (!strcmp(argument, "--to-stdout"))) { forceStdout=1; output_filename=stdoutmark; displayLevel=1; continue; } + || (!strcmp(argument, "--to-stdout"))) { forceStdout=1; output_filename=stdoutmark; displayLevel=1; continue; } if (!strcmp(argument, "--frame-crc")) { LZ4IO_setStreamChecksumMode(1); continue; } if (!strcmp(argument, "--no-frame-crc")) { LZ4IO_setStreamChecksumMode(0); continue; } if (!strcmp(argument, "--content-size")) { LZ4IO_setContentSize(1); continue; } @@ -312,6 +313,7 @@ int main(int argc, char** argv) if (!strcmp(argument, "--version")) { DISPLAY(WELCOME_MESSAGE); return 0; } if (!strcmp(argument, "--keep")) { continue; } /* keep source file (default anyway; just for xz/lzma compatibility) */ + /* Short commands (note : aggregated short commands are allowed) */ if (argument[0]=='-') { @@ -528,7 +530,7 @@ int main(int argc, char** argv) if (decode) { if (multiple_inputs) - multiple_rv = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); + operationResult = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); else DEFAULT_DECOMPRESSOR(input_filename, output_filename); } @@ -543,7 +545,7 @@ int main(int argc, char** argv) else { if (multiple_inputs) - multiple_rv = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); + operationResult = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); else DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); } @@ -552,6 +554,6 @@ int main(int argc, char** argv) if (main_pause) waitEnter(); free(dynNameSpace); free((void*)inFileNames); - if (multiple_rv != 0) return multiple_rv; + if (operationResult != 0) return operationResult; return 0; } diff --git a/programs/lz4io.c b/programs/lz4io.c index c510f1d..7a3c10d 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -509,21 +509,21 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, { int i; int missing_files = 0; - FILE *ifp; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); for (i=0; i 0) return 1; if (missing_files > 0) return 1; return 0; -- cgit v0.12 From c64200dd85a85d9cc69a6fda682362d851be863b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 00:07:30 +0100 Subject: Improved performance when compressing a lot of small files --- programs/lz4io.c | 273 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 172 insertions(+), 101 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 7a3c10d..44c894c 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -46,7 +46,7 @@ /***************************** * Includes *****************************/ -#include /* fprintf, fopen, fread, stdin, stdout */ +#include /* fprintf, fopen, fread, stdin, stdout, fflush, getchar */ #include /* malloc, free */ #include /* strcmp, strlen */ #include /* clock */ @@ -253,7 +253,7 @@ static int LZ4IO_GetBlockSize_FromBlockId (int id) { return (1 << (8 + (2 * id)) static int LZ4IO_isSkippableMagicNumber(unsigned int magic) { return (magic & LZ4IO_SKIPPABLEMASK) == LZ4IO_SKIPPABLE0; } -static int get_fileHandle(const char* input_filename, const char* output_filename, FILE** pfinput, FILE** pfoutput) +static int LZ4IO_getFiles(const char* input_filename, const char* output_filename, FILE** pfinput, FILE** pfoutput) { if (!strcmp (input_filename, stdinmark)) @@ -267,6 +267,12 @@ static int get_fileHandle(const char* input_filename, const char* output_filenam *pfinput = fopen(input_filename, "rb"); } + if ( *pfinput==0 ) + { + DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", input_filename); + return 1; + } + if (!strcmp (output_filename, stdoutmark)) { DISPLAYLEVEL(4,"Using stdout for output\n"); @@ -285,16 +291,17 @@ static int get_fileHandle(const char* input_filename, const char* output_filenam { char ch; DISPLAYLEVEL(2, "Warning : %s already exists\n", output_filename); - DISPLAYLEVEL(2, "Overwrite ? (Y/N) : "); - if (g_displayLevel <= 1) EXM_THROW(11, "Operation aborted : %s already exists", output_filename); /* No interaction possible */ - ch = (char)getchar(); - if ((ch!='Y') && (ch!='y')) EXM_THROW(11, "Operation aborted : %s already exists", output_filename); + if ((g_displayLevel <= 1) || (*pfinput == stdin)) + EXM_THROW(11, "Operation aborted : %s already exists", output_filename); /* No interaction possible */ + DISPLAYLEVEL(2, "Overwrite ? (Y/n) : "); + ch = 'Y'; + while((ch = (char)getchar()) != '\n' && ch != EOF) /* flush integrated */ + if ((ch!='Y') && (ch!='y')) EXM_THROW(12, "No. Operation aborted : %s already exists", output_filename); } } *pfoutput = fopen( output_filename, "wb" ); } - if ( *pfinput==0 ) EXM_THROW(12, "Pb opening %s", input_filename); if ( *pfoutput==0) EXM_THROW(13, "Pb opening %s", output_filename); return 0; @@ -336,7 +343,8 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output start = clock(); if (compressionlevel < 3) compressionFunction = LZ4_compress; else compressionFunction = LZ4_compressHC; - get_fileHandle(input_filename, output_filename, &finput, &foutput); + if (LZ4IO_getFiles(input_filename, output_filename, &finput, &foutput)) + EXM_THROW(20, "File error"); if ((g_displayLevel==2) && (compressionlevel==1)) g_displayLevel=3; /* Allocate Memory */ @@ -394,59 +402,61 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output * Compression using Frame format *********************************************/ -int LZ4IO_compressFilename(const char* input_filename, const char* output_filename, int compressionLevel) +typedef struct { + const char* srcFileName; + FILE* sFile; + const char* dstFileName; + FILE* dFile; + void* srcBuffer; + size_t srcBufferSize; + void* dstBuffer; + size_t dstBufferSize; + LZ4F_compressionContext_t ctx; + unsigned compressionLevel; +} compressionJob_t; + + +static int LZ4IO_compressJob(compressionJob_t ress) { unsigned long long filesize = 0; unsigned long long compressedfilesize = 0; - char* in_buff; - char* out_buff; - FILE* finput; - FILE* foutput; - clock_t start, end; - int blockSize; - size_t sizeCheck, headerSize, readSize, outBuffSize; - LZ4F_compressionContext_t ctx; - LZ4F_errorCode_t errorCode; + FILE* finput = ress.sFile; + FILE* foutput = ress.dFile; + void* const srcBuffer = ress.srcBuffer; + void* const dstBuffer = ress.dstBuffer; + const size_t dstBufferSize = ress.dstBufferSize; + const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); + size_t sizeCheck, headerSize, readSize; + LZ4F_compressionContext_t ctx = ress.ctx; /* just a pointer */ LZ4F_preferences_t prefs; /* Init */ - start = clock(); memset(&prefs, 0, sizeof(prefs)); - errorCode = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); - get_fileHandle(input_filename, output_filename, &finput, &foutput); - blockSize = LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); /* Set compression parameters */ prefs.autoFlush = 1; - prefs.compressionLevel = compressionLevel; + prefs.compressionLevel = ress.compressionLevel; prefs.frameInfo.blockMode = (blockMode_t)g_blockIndependence; prefs.frameInfo.blockSizeID = (blockSizeID_t)g_blockSizeId; prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)g_streamChecksum; if (g_contentSizeFlag) { - unsigned long long fileSize = LZ4IO_GetFileSize(input_filename); + unsigned long long fileSize = LZ4IO_GetFileSize(ress.srcFileName); prefs.frameInfo.contentSize = fileSize; /* == 0 if input == stdin */ if (fileSize==0) DISPLAYLEVEL(3, "Warning : cannot determine uncompressed frame content size \n"); } - /* Allocate Memory */ - in_buff = (char*)malloc(blockSize); - outBuffSize = LZ4F_compressBound(blockSize, &prefs); - out_buff = (char*)malloc(outBuffSize); - if (!in_buff || !out_buff) EXM_THROW(31, "Allocation error : not enough memory"); - /* Write Archive Header */ - headerSize = LZ4F_compressBegin(ctx, out_buff, outBuffSize, &prefs); + headerSize = LZ4F_compressBegin(ctx, dstBuffer, dstBufferSize, &prefs); if (LZ4F_isError(headerSize)) EXM_THROW(32, "File header generation failed : %s", LZ4F_getErrorName(headerSize)); - sizeCheck = fwrite(out_buff, 1, headerSize, foutput); + sizeCheck = fwrite(dstBuffer, 1, headerSize, foutput); if (sizeCheck!=headerSize) EXM_THROW(33, "Write error : cannot write header"); compressedfilesize += headerSize; /* read first block */ - readSize = fread(in_buff, (size_t)1, (size_t)blockSize, finput); + readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, finput); filesize += readSize; /* Main Loop */ @@ -455,126 +465,145 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena size_t outSize; /* Compress Block */ - outSize = LZ4F_compressUpdate(ctx, out_buff, outBuffSize, in_buff, readSize, NULL); + outSize = LZ4F_compressUpdate(ctx, dstBuffer, dstBufferSize, srcBuffer, readSize, NULL); if (LZ4F_isError(outSize)) EXM_THROW(34, "Compression failed : %s", LZ4F_getErrorName(outSize)); compressedfilesize += outSize; - DISPLAYUPDATE(2, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100); + DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", (unsigned)(filesize>>20), (double)compressedfilesize/filesize*100); /* Write Block */ - sizeCheck = fwrite(out_buff, 1, outSize, foutput); + sizeCheck = fwrite(dstBuffer, 1, outSize, foutput); if (sizeCheck!=outSize) EXM_THROW(35, "Write error : cannot write compressed block"); /* Read next block */ - readSize = fread(in_buff, (size_t)1, (size_t)blockSize, finput); + readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, finput); filesize += readSize; } /* End of Stream mark */ - headerSize = LZ4F_compressEnd(ctx, out_buff, outBuffSize, NULL); + headerSize = LZ4F_compressEnd(ctx, dstBuffer, dstBufferSize, NULL); if (LZ4F_isError(headerSize)) EXM_THROW(36, "End of file generation failed : %s", LZ4F_getErrorName(headerSize)); - sizeCheck = fwrite(out_buff, 1, headerSize, foutput); + sizeCheck = fwrite(dstBuffer, 1, headerSize, foutput); if (sizeCheck!=headerSize) EXM_THROW(37, "Write error : cannot write end of stream"); compressedfilesize += headerSize; - /* Close & Free */ - free(in_buff); - free(out_buff); - fclose(finput); - fclose(foutput); - errorCode = LZ4F_freeCompressionContext(ctx); - if (LZ4F_isError(errorCode)) EXM_THROW(38, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); - /* Final Status */ - end = clock(); DISPLAYLEVEL(2, "\r%79s\r", ""); if (filesize == 0) { - DISPLAYLEVEL(2, "Null size input; converted into %u lz4 stream\n", (unsigned)compressedfilesize); + DISPLAYLEVEL(2, "Empty input\n"); } else { - double seconds = (double)(end - start)/CLOCKS_PER_SEC; DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", (unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100); - DISPLAYLEVEL(4, "Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024); } return 0; } -#define FNSPACE 30 -int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel) +int LZ4IO_compressFilename(const char* input_filename, const char* output_filename, int compressionLevel) { - int i; - int missing_files = 0; - char* outFileName = (char*)malloc(FNSPACE); - size_t ofnSize = FNSPACE; - const size_t suffixSize = strlen(suffix); + clock_t start, end; + const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); + compressionJob_t ress; + LZ4F_errorCode_t errorCode; - for (i=0; i 0) return 1; + return 0; } -int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) + +#define FNSPACE 30 +int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionLevel) { int i; - int skipped_files = 0; int missing_files = 0; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); - char* ifnSuffix = (char*)malloc(suffixSize + 1); + const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); + compressionJob_t ress; + LZ4F_errorCode_t errorCode; + + /* init */ + errorCode = LZ4F_createCompressionContext(&(ress.ctx), LZ4F_VERSION); + if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); + ress.compressionLevel = (unsigned)compressionLevel; + /* Allocate Memory */ + ress.srcBuffer = malloc(blockSize); + ress.srcBufferSize = blockSize; + ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ + ress.dstBuffer = malloc(ress.dstBufferSize); + if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); + + /* loop on each file */ for (i=0; i 0) return 1; + if (missing_files > 0) return 1; return 0; } + /* ********************************************************************* */ /* ********************** LZ4 file-stream Decompression **************** */ /* ********************************************************************* */ @@ -585,7 +614,7 @@ static unsigned LZ4IO_readLE32 (const void* s) unsigned value32 = srcPtr[0]; value32 += (srcPtr[1]<<8); value32 += (srcPtr[2]<<16); - value32 += (srcPtr[3]<<24); + value32 += ((unsigned)srcPtr[3])<<24; return value32; } @@ -866,7 +895,8 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file /* Init */ start = clock(); - get_fileHandle(input_filename, output_filename, &finput, &foutput); + if (LZ4IO_getFiles(input_filename, output_filename, &finput, &foutput)) + EXM_THROW(50, "File error"); /* sparse file */ if (g_sparseFileSupport) { SET_SPARSE_FILE_MODE(foutput); } @@ -897,3 +927,44 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file return 0; } + +int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) +{ + int i; + int skipped_files = 0; + int missing_files = 0; + char* outFileName = (char*)malloc(FNSPACE); + size_t ofnSize = FNSPACE; + const size_t suffixSize = strlen(suffix); + char* ifnSuffix = (char*)malloc(suffixSize + 1); + + for (i=0; i 0) return 1; + if (missing_files > 0) return 1; + return 0; +} -- cgit v0.12 From 113b150f0aeb3512b2850a65a824ad87f605187e Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 16:05:02 +0100 Subject: Fix leak issue with compression of multiple files --- programs/lz4io.c | 274 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 167 insertions(+), 107 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 44c894c..01375be 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -159,7 +159,7 @@ static const int maxBlockSizeID = 7; #define EXTENDED_ARGUMENTS #define EXTENDED_HELP #define EXTENDED_FORMAT -#define DEFAULT_DECOMPRESSOR decodeLZ4S +#define DEFAULT_DECOMPRESSOR LZ4IO_decompressFile /* ************************************************** */ @@ -240,7 +240,7 @@ static unsigned long long LZ4IO_GetFileSize(const char* infilename) struct stat statbuf; r = stat(infilename, &statbuf); #endif - if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */ + if (r || !S_ISREG(statbuf.st_mode)) return 0; /* failure, or is not a regular file */ return (unsigned long long)statbuf.st_size; } @@ -289,12 +289,11 @@ static int LZ4IO_getFiles(const char* input_filename, const char* output_filenam fclose(*pfoutput); if (!g_overwrite) { - char ch; + char ch = 'Y'; DISPLAYLEVEL(2, "Warning : %s already exists\n", output_filename); if ((g_displayLevel <= 1) || (*pfinput == stdin)) EXM_THROW(11, "Operation aborted : %s already exists", output_filename); /* No interaction possible */ DISPLAYLEVEL(2, "Overwrite ? (Y/n) : "); - ch = 'Y'; while((ch = (char)getchar()) != '\n' && ch != EOF) /* flush integrated */ if ((ch!='Y') && (ch!='y')) EXM_THROW(12, "No. Operation aborted : %s already exists", output_filename); } @@ -520,6 +519,7 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena ress.compressionLevel = (unsigned)compressionLevel; /* Allocate Memory */ + ress.srcFileName = input_filename; ress.srcBuffer = malloc(blockSize); ress.srcBufferSize = blockSize; ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ @@ -587,14 +587,17 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, issueWithSrcFile = LZ4IO_getFiles(inFileNamesTable[i], outFileName, &(ress.sFile), &(ress.dFile)); missing_files += issueWithSrcFile; - if (!issueWithSrcFile) LZ4IO_compressJob(ress); + if (!issueWithSrcFile) + { + LZ4IO_compressJob(ress); + fclose(ress.sFile); + fclose(ress.dFile); + } } /* Close & Free */ free(ress.srcBuffer); free(ress.dstBuffer); - fclose(ress.sFile); - fclose(ress.dFile); errorCode = LZ4F_freeCompressionContext(ress.ctx); if (LZ4F_isError(errorCode)) EXM_THROW(38, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); free(outFileName); @@ -618,12 +621,101 @@ static unsigned LZ4IO_readLE32 (const void* s) return value32; } +static unsigned LZ4IO_fwriteSparse(FILE* file, const void* buffer, size_t bufferSize, unsigned storedSkips) +{ + size_t* const bufferT = (size_t*)buffer; /* Buffer is supposed malloc'ed, hence aligned on size_t */ + size_t* ptrT = bufferT; + size_t bufferSizeT = bufferSize / sizeT; + size_t* const bufferTEnd = bufferT + bufferSizeT; + static const size_t segmentSizeT = (32 KB) / sizeT; + + if (!g_sparseFileSupport) /* normal write */ + { + size_t sizeCheck = fwrite(buffer, 1, bufferSize, file); + if (sizeCheck != bufferSize) EXM_THROW(68, "Write error : cannot write decoded block"); + return 0; + } + + /* avoid int overflow */ + if (storedSkips > 1 GB) + { + int seekResult = fseek(file, 1 GB, SEEK_CUR); + if (seekResult != 0) EXM_THROW(68, "1 GB skip error (sparse file support)"); + storedSkips -= 1 GB; + } + + while (ptrT < bufferTEnd) + { + size_t seg0SizeT = segmentSizeT; + size_t nb0T; + int seekResult; + + /* count leading zeros */ + if (seg0SizeT > bufferSizeT) seg0SizeT = bufferSizeT; + bufferSizeT -= seg0SizeT; + for (nb0T=0; (nb0T < seg0SizeT) && (ptrT[nb0T] == 0); nb0T++) ; + storedSkips += (unsigned)(nb0T * sizeT); + + if (nb0T != seg0SizeT) /* not all 0s */ + { + size_t sizeCheck; + seekResult = fseek(file, storedSkips, SEEK_CUR); + if (seekResult) EXM_THROW(68, "Skip error (sparse file)"); + storedSkips = 0; + seg0SizeT -= nb0T; + ptrT += nb0T; + sizeCheck = fwrite(ptrT, sizeT, seg0SizeT, file); + if (sizeCheck != seg0SizeT) EXM_THROW(68, "Write error : cannot write decoded block"); + } + ptrT += seg0SizeT; + } + + if (bufferSize & maskT) /* size not multiple of sizeT : implies end of block */ + { + const char* const restStart = (char*)bufferTEnd; + const char* restPtr = restStart; + size_t restSize = bufferSize & maskT; + const char* const restEnd = restStart + restSize; + for (; (restPtr < restEnd) && (*restPtr == 0); restPtr++) ; + storedSkips += (unsigned) (restPtr - restStart); + if (restPtr != restEnd) + { + size_t sizeCheck; + int seekResult = fseek(file, storedSkips, SEEK_CUR); + if (seekResult) EXM_THROW(68, "Skip error (end of block)"); + storedSkips = 0; + sizeCheck = fwrite(restPtr, 1, restEnd - restPtr, file); + if (sizeCheck != (size_t)(restEnd - restPtr)) EXM_THROW(68, "Write error : cannot write decoded end of block"); + } + } + + return storedSkips; +} + +static void LZ4IO_fwriteSparseEnd(FILE* file, unsigned storedSkips) +{ + char lastZeroByte[1] = { 0 }; + + if (storedSkips>0) /* implies g_sparseFileSupport */ + { + int seekResult; + size_t sizeCheck; + storedSkips --; + seekResult = fseek(file, storedSkips, SEEK_CUR); + if (seekResult != 0) EXM_THROW(69, "Final skip error (sparse file)\n"); + sizeCheck = fwrite(lastZeroByte, 1, 1, file); + if (sizeCheck != 1) EXM_THROW(69, "Write error : cannot write last zero\n"); + } +} + + static unsigned g_magicRead = 0; -static unsigned long long decodeLegacyStream(FILE* finput, FILE* foutput) +static unsigned long long LZ4IO_decodeLegacyStream(FILE* finput, FILE* foutput) { unsigned long long filesize = 0; char* in_buff; char* out_buff; + unsigned storedSkips = 0; /* Allocate Memory */ in_buff = (char*)malloc(LZ4_compressBound(LEGACY_BLOCKSIZE)); @@ -657,10 +749,11 @@ static unsigned long long decodeLegacyStream(FILE* finput, FILE* foutput) filesize += decodeSize; /* Write Block */ - sizeCheck = fwrite(out_buff, 1, decodeSize, foutput); - if (sizeCheck != (size_t)decodeSize) EXM_THROW(54, "Write error : cannot write decoded block into output\n"); + storedSkips = LZ4IO_fwriteSparse(foutput, out_buff, decodeSize, storedSkips); } + LZ4IO_fwriteSparseEnd(foutput, storedSkips); + /* Free */ free(in_buff); free(out_buff); @@ -669,37 +762,32 @@ static unsigned long long decodeLegacyStream(FILE* finput, FILE* foutput) } -static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) + +typedef struct { + FILE* sFile; + FILE* dFile; + void* srcBuffer; + size_t srcBufferSize; + void* dstBuffer; + size_t dstBufferSize; + LZ4F_decompressionContext_t dCtx; +} decompressionJob_t; + +static unsigned long long LZ4IO_decompressJob(decompressionJob_t ress) { unsigned long long filesize = 0; - void* inBuff; - void* outBuff; - size_t sizeCheck; - const size_t inBuffSize = 256 KB; - const size_t outBuffSize = 256 KB; - LZ4F_decompressionContext_t ctx; LZ4F_errorCode_t errorCode; unsigned storedSkips = 0; - /* init */ - errorCode = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create context : %s", LZ4F_getErrorName(errorCode)); - - /* Allocate Memory */ - inBuff = malloc(256 KB); - outBuff = malloc(256 KB); - if (!inBuff || !outBuff) EXM_THROW(61, "Allocation error : not enough memory"); - - /* Init feed with magic number (already consumed from FILE) */ + /* Init feed with magic number (already consumed from FILE* sFile) */ { - size_t inSize = 4; - size_t outSize=0; - LZ4IO_writeLE32(inBuff, LZ4IO_MAGICNUMBER); - errorCode = LZ4F_decompress(ctx, outBuff, &outSize, inBuff, &inSize, NULL); + size_t inSize = MAGICNUMBER_SIZE; + size_t outSize= 0; + LZ4IO_writeLE32(ress.srcBuffer, LZ4IO_MAGICNUMBER); + errorCode = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &outSize, ress.srcBuffer, &inSize, NULL); if (LZ4F_isError(errorCode)) EXM_THROW(62, "Header error : %s", LZ4F_getErrorName(errorCode)); } - /* Main Loop */ for (;;) { @@ -707,15 +795,15 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) size_t pos = 0; /* Read input */ - readSize = fread(inBuff, 1, inBuffSize, finput); + readSize = fread(ress.srcBuffer, 1, ress.srcBufferSize, ress.sFile); if (!readSize) break; /* empty file or stream */ while (pos < readSize) { /* Decode Input (at least partially) */ size_t remaining = readSize - pos; - size_t decodedBytes = outBuffSize; - errorCode = LZ4F_decompress(ctx, outBuff, &decodedBytes, (char*)inBuff+pos, &remaining, NULL); + size_t decodedBytes = ress.dstBufferSize; + errorCode = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &decodedBytes, (char*)(ress.srcBuffer)+pos, &remaining, NULL); if (LZ4F_isError(errorCode)) EXM_THROW(66, "Decompression error : %s", LZ4F_getErrorName(errorCode)); pos += remaining; @@ -724,83 +812,54 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) /* Write Block */ filesize += decodedBytes; DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20)); - if (g_sparseFileSupport) - { - size_t* const oBuffStartT = (size_t*)outBuff; /* since outBuff is malloc'ed, it's aligned on size_t */ - size_t* oBuffPosT = oBuffStartT; - size_t oBuffSizeT = decodedBytes / sizeT; - size_t* const oBuffEndT = oBuffStartT + oBuffSizeT; - static const size_t bs0T = (32 KB) / sizeT; - while (oBuffPosT < oBuffEndT) - { - size_t seg0SizeT = bs0T; - size_t nb0T; - int seekResult; - if (seg0SizeT > oBuffSizeT) seg0SizeT = oBuffSizeT; - oBuffSizeT -= seg0SizeT; - for (nb0T=0; (nb0T < seg0SizeT) && (oBuffPosT[nb0T] == 0); nb0T++) ; - storedSkips += (unsigned)(nb0T * sizeT); - if (storedSkips > 1 GB) /* avoid int overflow */ - { - seekResult = fseek(foutput, 1 GB, SEEK_CUR); - if (seekResult != 0) EXM_THROW(68, "1 GB skip error (sparse file)"); - storedSkips -= 1 GB; - } - if (nb0T != seg0SizeT) /* not all 0s */ - { - seekResult = fseek(foutput, storedSkips, SEEK_CUR); - if (seekResult) EXM_THROW(68, "Skip error (sparse file)"); - storedSkips = 0; - seg0SizeT -= nb0T; - oBuffPosT += nb0T; - sizeCheck = fwrite(oBuffPosT, sizeT, seg0SizeT, foutput); - if (sizeCheck != seg0SizeT) EXM_THROW(68, "Write error : cannot write decoded block"); - } - oBuffPosT += seg0SizeT; - } - if (decodedBytes & maskT) /* size not multiple of sizeT (necessarily end of block) */ - { - const char* const restStart = (char*)oBuffEndT; - const char* restPtr = restStart; - size_t restSize = decodedBytes & maskT; - const char* const restEnd = restStart + restSize; - for (; (restPtr < restEnd) && (*restPtr == 0); restPtr++) ; - storedSkips += (unsigned) (restPtr - restStart); - if (restPtr != restEnd) - { - int seekResult = fseek(foutput, storedSkips, SEEK_CUR); - if (seekResult) EXM_THROW(68, "Skip error (end of block)"); - storedSkips = 0; - sizeCheck = fwrite(restPtr, 1, restEnd - restPtr, foutput); - if (sizeCheck != (size_t)(restEnd - restPtr)) EXM_THROW(68, "Write error : cannot write decoded end of block"); - } - } - } - else - { - sizeCheck = fwrite(outBuff, 1, decodedBytes, foutput); - if (sizeCheck != decodedBytes) EXM_THROW(68, "Write error : cannot write decoded block"); - } + storedSkips = LZ4IO_fwriteSparse(ress.dFile, ress.dstBuffer, decodedBytes, storedSkips); } } - } - if ((g_sparseFileSupport) && (storedSkips>0)) - { - int seekResult; - storedSkips --; - seekResult = fseek(foutput, storedSkips, SEEK_CUR); - if (seekResult != 0) EXM_THROW(69, "Final skip error (sparse file)\n"); - memset(outBuff, 0, 1); - sizeCheck = fwrite(outBuff, 1, 1, foutput); - if (sizeCheck != 1) EXM_THROW(69, "Write error : cannot write last zero\n"); - } + LZ4IO_fwriteSparseEnd(ress.dFile, storedSkips); + + return filesize; +} + + +static const size_t LZ4IO_dBufferSize = 64 KB; + +static unsigned long long LZ4IO_decompressFile(FILE* finput, FILE* foutput) +{ + unsigned long long filesize = 0; + void* inBuff; + void* outBuff; + const size_t inBuffSize = LZ4IO_dBufferSize; + const size_t outBuffSize = LZ4IO_dBufferSize; + LZ4F_decompressionContext_t dCtx; + LZ4F_errorCode_t errorCode; + decompressionJob_t ress; + + /* init */ + errorCode = LZ4F_createDecompressionContext(&dCtx, LZ4F_VERSION); + if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create context : %s", LZ4F_getErrorName(errorCode)); + + /* Allocate Memory */ + inBuff = malloc(inBuffSize); + outBuff = malloc(outBuffSize); + if (!inBuff || !outBuff) EXM_THROW(61, "Allocation error : not enough memory"); + + /* Decompression Job */ + ress.dCtx = dCtx; + ress.dFile = foutput; + ress.dstBuffer = outBuff; + ress.dstBufferSize = outBuffSize; + ress.sFile = finput; + ress.srcBuffer = inBuff; + ress.srcBufferSize = inBuffSize; + + filesize = LZ4IO_decompressJob(ress); /* Free */ free(inBuff); free(outBuff); - errorCode = LZ4F_freeDecompressionContext(ctx); + errorCode = LZ4F_freeDecompressionContext(dCtx); if (LZ4F_isError(errorCode)) EXM_THROW(69, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); return filesize; @@ -812,6 +871,7 @@ static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigne void* buffer = malloc(64 KB); size_t read = 1, sizeCheck; unsigned long long total = MAGICNUMBER_SIZE; + unsigned storedSkips = 0; sizeCheck = fwrite(U32store, 1, MAGICNUMBER_SIZE, foutput); if (sizeCheck != MAGICNUMBER_SIZE) EXM_THROW(50, "Pass-through error at start"); @@ -820,10 +880,10 @@ static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigne { read = fread(buffer, 1, 64 KB, finput); total += read; - sizeCheck = fwrite(buffer, 1, read, foutput); - if (sizeCheck != read) EXM_THROW(50, "Pass-through error"); + storedSkips = LZ4IO_fwriteSparse(foutput, buffer, read, storedSkips); } + LZ4IO_fwriteSparseEnd(foutput, storedSkips); free(buffer); return total; } @@ -862,7 +922,7 @@ static unsigned long long selectDecoder( FILE* finput, FILE* foutput) return DEFAULT_DECOMPRESSOR(finput, foutput); case LEGACY_MAGICNUMBER: DISPLAYLEVEL(4, "Detected : Legacy format \n"); - return decodeLegacyStream(finput, foutput); + return LZ4IO_decodeLegacyStream(finput, foutput); case LZ4IO_SKIPPABLE0: DISPLAYLEVEL(4, "Skipping detected skippable area \n"); nbReadBytes = fread(U32store, 1, 4, finput); -- cgit v0.12 From eabc6d8d0054853274cd7839c252a0ae4bb8d929 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 16:34:37 +0100 Subject: New valgrind test with multiple files --- programs/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/programs/Makefile b/programs/Makefile index 2b0b8a9..1caaab4 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -247,6 +247,9 @@ test-mem: lz4 datagen fuzzer frametest fullbench valgrind --leak-check=yes ./datagen -g50M > $(VOID) ./datagen -g16KB > tmp valgrind --leak-check=yes ./lz4 -9 -BD -f tmp $(VOID) + ./datagen -g16KB -s2 > tmp2 + ./datagen -g16KB -s3 > tmp3 + valgrind --leak-check=yes ./lz4 --force --multiple tmp tmp2 tmp3 ./datagen -g16MB > tmp valgrind --leak-check=yes ./lz4 -9 -B5D -f tmp tmp2 valgrind --leak-check=yes ./lz4 -t tmp2 -- cgit v0.12 From 348f5099e42c23393ec9c8e6b403f4bca99bbb41 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 18:10:55 +0100 Subject: lz4io refactoring --- programs/lz4io.c | 145 +++++++++++++++++++++++++------------------------------ 1 file changed, 66 insertions(+), 79 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 01375be..9287979 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -402,25 +402,48 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output *********************************************/ typedef struct { - const char* srcFileName; - FILE* sFile; - const char* dstFileName; - FILE* dFile; - void* srcBuffer; + void* srcBuffer; size_t srcBufferSize; - void* dstBuffer; + void* dstBuffer; size_t dstBufferSize; LZ4F_compressionContext_t ctx; - unsigned compressionLevel; -} compressionJob_t; +} cRess_t; + +static cRess_t LZ4IO_createCResources(void) +{ + const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); + cRess_t ress; + LZ4F_errorCode_t errorCode; + + errorCode = LZ4F_createCompressionContext(&(ress.ctx), LZ4F_VERSION); + if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); + /* Allocate Memory */ + ress.srcBuffer = malloc(blockSize); + ress.srcBufferSize = blockSize; + ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ + ress.dstBuffer = malloc(ress.dstBufferSize); + if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); + + return ress; +} -static int LZ4IO_compressJob(compressionJob_t ress) +static void LZ4IO_freeCResources(cRess_t ress) +{ + LZ4F_errorCode_t errorCode; + free(ress.srcBuffer); + free(ress.dstBuffer); + errorCode = LZ4F_freeCompressionContext(ress.ctx); + if (LZ4F_isError(errorCode)) EXM_THROW(38, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); +} + + +static int LZ4IO_compressJob(cRess_t ress, const char* srcFileName, const char* dstFileName, int compressionLevel) { unsigned long long filesize = 0; unsigned long long compressedfilesize = 0; - FILE* finput = ress.sFile; - FILE* foutput = ress.dFile; + FILE* srcFile; + FILE* dstFile; void* const srcBuffer = ress.srcBuffer; void* const dstBuffer = ress.dstBuffer; const size_t dstBufferSize = ress.dstBufferSize; @@ -433,15 +456,21 @@ static int LZ4IO_compressJob(compressionJob_t ress) /* Init */ memset(&prefs, 0, sizeof(prefs)); + /* File check */ + { + int srcFileAbsent = LZ4IO_getFiles(srcFileName, dstFileName, &srcFile, &dstFile); + if (srcFileAbsent) return srcFileAbsent; + } + /* Set compression parameters */ prefs.autoFlush = 1; - prefs.compressionLevel = ress.compressionLevel; + prefs.compressionLevel = compressionLevel; prefs.frameInfo.blockMode = (blockMode_t)g_blockIndependence; prefs.frameInfo.blockSizeID = (blockSizeID_t)g_blockSizeId; prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)g_streamChecksum; if (g_contentSizeFlag) { - unsigned long long fileSize = LZ4IO_GetFileSize(ress.srcFileName); + unsigned long long fileSize = LZ4IO_GetFileSize(srcFileName); prefs.frameInfo.contentSize = fileSize; /* == 0 if input == stdin */ if (fileSize==0) DISPLAYLEVEL(3, "Warning : cannot determine uncompressed frame content size \n"); @@ -450,12 +479,12 @@ static int LZ4IO_compressJob(compressionJob_t ress) /* Write Archive Header */ headerSize = LZ4F_compressBegin(ctx, dstBuffer, dstBufferSize, &prefs); if (LZ4F_isError(headerSize)) EXM_THROW(32, "File header generation failed : %s", LZ4F_getErrorName(headerSize)); - sizeCheck = fwrite(dstBuffer, 1, headerSize, foutput); + sizeCheck = fwrite(dstBuffer, 1, headerSize, dstFile); if (sizeCheck!=headerSize) EXM_THROW(33, "Write error : cannot write header"); compressedfilesize += headerSize; /* read first block */ - readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, finput); + readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, srcFile); filesize += readSize; /* Main Loop */ @@ -470,11 +499,11 @@ static int LZ4IO_compressJob(compressionJob_t ress) DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", (unsigned)(filesize>>20), (double)compressedfilesize/filesize*100); /* Write Block */ - sizeCheck = fwrite(dstBuffer, 1, outSize, foutput); + sizeCheck = fwrite(dstBuffer, 1, outSize, dstFile); if (sizeCheck!=outSize) EXM_THROW(35, "Write error : cannot write compressed block"); /* Read next block */ - readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, finput); + readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, srcFile); filesize += readSize; } @@ -482,10 +511,14 @@ static int LZ4IO_compressJob(compressionJob_t ress) headerSize = LZ4F_compressEnd(ctx, dstBuffer, dstBufferSize, NULL); if (LZ4F_isError(headerSize)) EXM_THROW(36, "End of file generation failed : %s", LZ4F_getErrorName(headerSize)); - sizeCheck = fwrite(dstBuffer, 1, headerSize, foutput); + sizeCheck = fwrite(dstBuffer, 1, headerSize, dstFile); if (sizeCheck!=headerSize) EXM_THROW(37, "Write error : cannot write end of stream"); compressedfilesize += headerSize; + /* Release files */ + fclose (srcFile); + fclose (dstFile); + /* Final Status */ DISPLAYLEVEL(2, "\r%79s\r", ""); if (filesize == 0) @@ -502,40 +535,21 @@ static int LZ4IO_compressJob(compressionJob_t ress) } -int LZ4IO_compressFilename(const char* input_filename, const char* output_filename, int compressionLevel) +int LZ4IO_compressFilename(const char* srcFileName, const char* dstFileName, int compressionLevel) { clock_t start, end; - const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); - compressionJob_t ress; - LZ4F_errorCode_t errorCode; - + cRess_t ress; + int issueWithSrcFile = 0; /* Init */ start = clock(); - errorCode = LZ4F_createCompressionContext(&(ress.ctx), LZ4F_VERSION); - if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); - if (LZ4IO_getFiles(input_filename, output_filename, &(ress.sFile), &(ress.dFile))) - EXM_THROW(31, "File error"); - ress.compressionLevel = (unsigned)compressionLevel; + ress = LZ4IO_createCResources(); - /* Allocate Memory */ - ress.srcFileName = input_filename; - ress.srcBuffer = malloc(blockSize); - ress.srcBufferSize = blockSize; - ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ - ress.dstBuffer = malloc(ress.dstBufferSize); - if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); - - /* Compress */ - LZ4IO_compressJob(ress); + /* Compress File */ + issueWithSrcFile += LZ4IO_compressJob(ress, srcFileName, dstFileName, compressionLevel); - /* Close & Free */ - free(ress.srcBuffer); - free(ress.dstBuffer); - fclose(ress.sFile); - fclose(ress.dFile); - errorCode = LZ4F_freeCompressionContext(ress.ctx); - if (LZ4F_isError(errorCode)) EXM_THROW(38, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); + /* Free resources */ + LZ4IO_freeCResources(ress); /* Final Status */ end = clock(); @@ -544,7 +558,7 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena DISPLAYLEVEL(4, "Completed in %.2f sec \n", seconds); } - return 0; + return issueWithSrcFile; } @@ -556,54 +570,27 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); - const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId); - compressionJob_t ress; - LZ4F_errorCode_t errorCode; + cRess_t ress; /* init */ - errorCode = LZ4F_createCompressionContext(&(ress.ctx), LZ4F_VERSION); - if (LZ4F_isError(errorCode)) EXM_THROW(30, "Allocation error : can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); - ress.compressionLevel = (unsigned)compressionLevel; - - /* Allocate Memory */ - ress.srcBuffer = malloc(blockSize); - ress.srcBufferSize = blockSize; - ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ - ress.dstBuffer = malloc(ress.dstBufferSize); - if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); + ress = LZ4IO_createCResources(); /* loop on each file */ for (i=0; i 0) return 1; - return 0; + return missing_files; } -- cgit v0.12 From 05a46fc59ab0934389055f97b7be5b5a6da2824d Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 18:51:36 +0100 Subject: Changes LZ4F_compressBound() definition using NULL prefsPtr to cover worst case instead of default. --- lib/lz4frame.c | 3 ++- lib/lz4frame.h | 6 +++--- programs/lz4io.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 31cf9a5..8d4c029 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -472,12 +472,13 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds /* LZ4F_compressBound() : gives the size of Dst buffer given a srcSize to handle worst case situations. * The LZ4F_frameInfo_t structure is optional : -* you can provide NULL as argument, all preferences will then be set to default. +* you can provide NULL as argument, preferences will then be set to cover worst case situations. * */ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr) { LZ4F_preferences_t prefsNull; memset(&prefsNull, 0, sizeof(prefsNull)); + prefsNull.frameInfo.contentChecksumFlag = contentChecksumEnabled; /* worst case */ { const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr; blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID; diff --git a/lib/lz4frame.h b/lib/lz4frame.h index e5435cd..f22ef00 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -141,9 +141,9 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t cctx, void* dstBuffer, size_ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* prefsPtr); /* LZ4F_compressBound() : * Provides the minimum size of Dst buffer given srcSize to handle worst case situations. - * prefsPtr is optional : you can provide NULL as argument, all preferences will then be set to default. - * Note that different preferences will produce different results. - * This function doesn't include frame termination cost (4 bytes, or 8 is frame checksum is enabled) + * Different preferences can produce different results. + * prefsPtr is optional : you can provide NULL as argument, all preferences will then be set to cover worst case. + * This function includes frame termination cost (4 bytes, or 8 is frame checksum is enabled) */ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* cOptPtr); diff --git a/programs/lz4io.c b/programs/lz4io.c index 9287979..db34747 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -421,7 +421,7 @@ static cRess_t LZ4IO_createCResources(void) /* Allocate Memory */ ress.srcBuffer = malloc(blockSize); ress.srcBufferSize = blockSize; - ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ + ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* cover worst case */ ress.dstBuffer = malloc(ress.dstBufferSize); if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); -- cgit v0.12 From 5a6652708439800e30d21e0cd24ed15cfb745a8b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 20:21:50 +0200 Subject: Revert "Add more descriptive frame errors" --- lib/lz4frame.c | 14 +++++++------- lib/lz4frame_static.h | 5 ----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index df41f63..31cf9a5 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -861,16 +861,16 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo blockSizeID = (BD>>4) & _3BITS; /* validate */ - if (version != 1) return (size_t)-ERROR_version_wrong; /* Version Number, only supported value */ - if (blockChecksumFlag != 0) return (size_t)-ERROR_unsupported_checksum; /* Only supported value for the time being */ - if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ - if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bit */ - if (blockSizeID < 4) return (size_t)-ERROR_unsupported_block_size; /* 4-7 only supported values for the time being */ - if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ + if (version != 1) return (size_t)-ERROR_GENERIC; /* Version Number, only supported value */ + if (blockChecksumFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */ + if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */ + if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bit */ + if (blockSizeID < 4) return (size_t)-ERROR_GENERIC; /* 4-7 only supported values for the time being */ + if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */ /* check */ HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5); - if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_header_checksum_invalid; /* Bad header checksum error */ + if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_GENERIC; /* Bad header checksum error */ /* save */ dctxPtr->frameInfo.blockMode = (blockMode_t)blockMode; diff --git a/lib/lz4frame_static.h b/lib/lz4frame_static.h index b608d23..2e56400 100644 --- a/lib/lz4frame_static.h +++ b/lib/lz4frame_static.h @@ -57,11 +57,6 @@ extern "C" { ITEM(ERROR_wrongSrcPtr) \ ITEM(ERROR_decompressionFailed) \ ITEM(ERROR_checksum_invalid) \ - ITEM(ERROR_version_wrong) \ - ITEM(ERROR_unsupported_checksum) \ - ITEM(ERROR_reserved_flag_set) \ - ITEM(ERROR_unsupported_block_size) \ - ITEM(ERROR_header_checksum_invalid) \ ITEM(ERROR_maxCode) #define LZ4F_GENERATE_ENUM(ENUM) ENUM, -- cgit v0.12 From 3f4f623bc9d8635459ab45f978bd1fcfd52ddc75 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 14 Apr 2015 21:02:12 +0100 Subject: Valgrind tests generate errors --- programs/Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 1caaab4..6008c7b 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -244,22 +244,22 @@ test-frametest32: frametest32 ./frametest32 $(FUZZER_TIME) test-mem: lz4 datagen fuzzer frametest fullbench - valgrind --leak-check=yes ./datagen -g50M > $(VOID) + valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID) ./datagen -g16KB > tmp - valgrind --leak-check=yes ./lz4 -9 -BD -f tmp $(VOID) + valgrind --leak-check=yes --error-exitcode=1 ./lz4 -9 -BD -f tmp $(VOID) ./datagen -g16KB -s2 > tmp2 ./datagen -g16KB -s3 > tmp3 - valgrind --leak-check=yes ./lz4 --force --multiple tmp tmp2 tmp3 + valgrind --leak-check=yes --error-exitcode=1 ./lz4 --force --multiple tmp tmp2 tmp3 ./datagen -g16MB > tmp - valgrind --leak-check=yes ./lz4 -9 -B5D -f tmp tmp2 - valgrind --leak-check=yes ./lz4 -t tmp2 - valgrind --leak-check=yes ./lz4 -bi1 tmp - valgrind --leak-check=yes ./fullbench -i1 tmp tmp2 + valgrind --leak-check=yes --error-exitcode=1 ./lz4 -9 -B5D -f tmp tmp2 + valgrind --leak-check=yes --error-exitcode=1 ./lz4 -t tmp2 + valgrind --leak-check=yes --error-exitcode=1 ./lz4 -bi1 tmp + valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1 tmp tmp2 ./datagen -g256MB > tmp - valgrind --leak-check=yes ./lz4 -B4D -f -vq tmp $(VOID) + valgrind --leak-check=yes --error-exitcode=1 ./lz4 -B4D -f -vq tmp $(VOID) rm tmp* - valgrind --leak-check=yes ./fuzzer -i64 -t1 - valgrind --leak-check=yes ./frametest -i256 + valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i64 -t1 + valgrind --leak-check=yes --error-exitcode=1 ./frametest -i256 test-mem32: lz4c32 datagen # unfortunately, valgrind doesn't seem to work with non-native binary. If someone knows how to do a valgrind-test on a 32-bits exe with a 64-bits system... -- cgit v0.12 From b664a72145f5e48fbbb82b8efb52c72518b41aaf Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 14 Apr 2015 13:33:43 -0700 Subject: Revert "Revert "Add more descriptive frame errors"" This reverts commit 5a6652708439800e30d21e0cd24ed15cfb745a8b. --- lib/lz4frame.c | 14 +++++++------- lib/lz4frame_static.h | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 8d4c029..41f8b1e 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -862,16 +862,16 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo blockSizeID = (BD>>4) & _3BITS; /* validate */ - if (version != 1) return (size_t)-ERROR_GENERIC; /* Version Number, only supported value */ - if (blockChecksumFlag != 0) return (size_t)-ERROR_GENERIC; /* Only supported value for the time being */ - if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */ - if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bit */ - if (blockSizeID < 4) return (size_t)-ERROR_GENERIC; /* 4-7 only supported values for the time being */ - if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_GENERIC; /* Reserved bits */ + if (version != 1) return (size_t)-ERROR_version_wrong; /* Version Number, only supported value */ + if (blockChecksumFlag != 0) return (size_t)-ERROR_unsupported_checksum; /* Only supported value for the time being */ + if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ + if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bit */ + if (blockSizeID < 4) return (size_t)-ERROR_unsupported_block_size; /* 4-7 only supported values for the time being */ + if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ /* check */ HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5); - if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_GENERIC; /* Bad header checksum error */ + if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_header_checksum_invalid; /* Bad header checksum error */ /* save */ dctxPtr->frameInfo.blockMode = (blockMode_t)blockMode; diff --git a/lib/lz4frame_static.h b/lib/lz4frame_static.h index 2e56400..b608d23 100644 --- a/lib/lz4frame_static.h +++ b/lib/lz4frame_static.h @@ -57,6 +57,11 @@ extern "C" { ITEM(ERROR_wrongSrcPtr) \ ITEM(ERROR_decompressionFailed) \ ITEM(ERROR_checksum_invalid) \ + ITEM(ERROR_version_wrong) \ + ITEM(ERROR_unsupported_checksum) \ + ITEM(ERROR_reserved_flag_set) \ + ITEM(ERROR_unsupported_block_size) \ + ITEM(ERROR_header_checksum_invalid) \ ITEM(ERROR_maxCode) #define LZ4F_GENERATE_ENUM(ENUM) ENUM, -- cgit v0.12 From d7298d2059a4f2da7aa19122d3af2aacb931972b Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Wed, 15 Apr 2015 00:17:06 +0900 Subject: Replace GCC_VERSION with LZ4_GCC_VERSION --- lib/lz4.c | 12 ++++++------ lib/lz4.h | 6 +++--- lib/lz4hc.h | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index d8e4977..53cd4a9 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -94,8 +94,8 @@ # endif /* __STDC_VERSION__ */ #endif /* _MSC_VER */ -/* GCC_VERSION is defined into lz4.h */ -#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__) +/* LZ4_GCC_VERSION is defined into lz4.h */ +#if (LZ4_GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__) # define expect(expr,value) (__builtin_expect ((expr),(value)) ) #else # define expect(expr,value) (expr) @@ -261,7 +261,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r = 0; _BitScanForward64( &r, (U64)val ); return (int)(r>>3); -# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) +# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) return (__builtin_ctzll((U64)val) >> 3); # else static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 }; @@ -274,7 +274,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r; _BitScanForward( &r, (U32)val ); return (int)(r>>3); -# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) +# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) return (__builtin_ctz((U32)val) >> 3); # else static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 }; @@ -290,7 +290,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r = 0; _BitScanReverse64( &r, val ); return (unsigned)(r>>3); -# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) +# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) return (__builtin_clzll((U64)val) >> 3); # else unsigned r; @@ -306,7 +306,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val) unsigned long r = 0; _BitScanReverse( &r, (unsigned long)val ); return (unsigned)(r>>3); -# elif (defined(__clang__) || (GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) +# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT) return (__builtin_clz((U32)val) >> 3); # else unsigned r; diff --git a/lib/lz4.h b/lib/lz4.h index 20e3c01..e831055 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -288,10 +288,10 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */ #ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK # define LZ4_DEPRECATE_WARNING_DEFBLOCK -# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -# if (GCC_VERSION >= 405) || defined(__clang__) +# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# if (LZ4_GCC_VERSION >= 405) || defined(__clang__) # define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) -# elif (GCC_VERSION >= 301) +# elif (LZ4_GCC_VERSION >= 301) # define LZ4_DEPRECATED(message) __attribute__((deprecated)) # elif defined(_MSC_VER) # define LZ4_DEPRECATED(message) __declspec(deprecated(message)) diff --git a/lib/lz4hc.h b/lib/lz4hc.h index 95bb6fe..d7db3bd 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -145,10 +145,10 @@ using LZ4_saveDictHC(). You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */ #ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK # define LZ4_DEPRECATE_WARNING_DEFBLOCK -# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -# if (GCC_VERSION >= 405) || defined(__clang__) +# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# if (LZ4_GCC_VERSION >= 405) || defined(__clang__) # define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) -# elif (GCC_VERSION >= 301) +# elif (LZ4_GCC_VERSION >= 301) # define LZ4_DEPRECATED(message) __attribute__((deprecated)) # elif defined(_MSC_VER) # define LZ4_DEPRECATED(message) __declspec(deprecated(message)) -- cgit v0.12 From e1283c7991b9b55348480dd114af1aa47410811b Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Wed, 15 Apr 2015 00:19:13 +0900 Subject: Fix LZ4_DEPRECATED() for older/non-gcc/clang/MSVC compilers --- lib/lz4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4.h b/lib/lz4.h index e831055..98296e9 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -297,7 +297,7 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS # define LZ4_DEPRECATED(message) __declspec(deprecated(message)) # else # pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") -# define LZ4_DEPRECATED +# define LZ4_DEPRECATED(message) # endif #endif // LZ4_DEPRECATE_WARNING_DEFBLOCK -- cgit v0.12 From 081bcca33bba4f6ac3e913b3cf2bc2ba58b6b697 Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Wed, 15 Apr 2015 02:20:47 +0900 Subject: Issue#90 : Add LZ4F_ prefix - Add LZ4F_ prefix to LZ4 frame related enums. - Also add conditional macro LZ4F_DISABLE_OLD_ENUMS for testing and users who prefer strict prefixes. --- lib/lz4frame.c | 116 +++++++++++++++++++++++++------------------------- lib/lz4frame.h | 19 ++++++--- lib/lz4frame_static.h | 6 ++- programs/lz4io.c | 6 +-- 4 files changed, 79 insertions(+), 68 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 41f8b1e..619481d 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -101,7 +101,7 @@ typedef unsigned long long U64; #define LZ4F_MAGICNUMBER 0x184D2204U #define LZ4F_BLOCKUNCOMPRESSED_FLAG 0x80000000U #define LZ4F_MAXHEADERFRAME_SIZE 15 -#define LZ4F_BLOCKSIZEID_DEFAULT max64KB +#define LZ4F_BLOCKSIZEID_DEFAULT LZ4F_max64KB static const size_t minFHSize = 5; static const U32 minHClevel = 3; @@ -157,7 +157,7 @@ static const char* LZ4F_errorStrings[] = { LZ4F_LIST_ERRORS(LZ4F_GENERATE_STRING unsigned LZ4F_isError(LZ4F_errorCode_t code) { - return (code > (LZ4F_errorCode_t)(-ERROR_maxCode)); + return (code > (LZ4F_errorCode_t)(-LZ4F_ERROR_maxCode)); } const char* LZ4F_getErrorName(LZ4F_errorCode_t code) @@ -177,7 +177,7 @@ static size_t LZ4F_getBlockSize(unsigned blockSizeID) if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT; blockSizeID -= 4; - if (blockSizeID > 3) return (size_t)-ERROR_maxBlockSize_invalid; + if (blockSizeID > 3) return (size_t)-LZ4F_ERROR_maxBlockSize_invalid; return blockSizes[blockSizeID]; } @@ -236,15 +236,15 @@ static BYTE LZ4F_headerChecksum (const void* header, size_t length) /************************************** * Simple compression functions **************************************/ -static blockSizeID_t LZ4F_optimalBSID(const blockSizeID_t requestedBSID, const size_t srcSize) +static LZ4F_blockSizeID_t LZ4F_optimalBSID(const LZ4F_blockSizeID_t requestedBSID, const size_t srcSize) { - blockSizeID_t proposedBSID = max64KB; + LZ4F_blockSizeID_t proposedBSID = LZ4F_max64KB; size_t maxBlockSize = 64 KB; while (requestedBSID > proposedBSID) { if (srcSize <= maxBlockSize) return proposedBSID; - proposedBSID = (blockSizeID_t)((int)proposedBSID + 1); + proposedBSID = (LZ4F_blockSizeID_t)((int)proposedBSID + 1); maxBlockSize <<= 2; } return requestedBSID; @@ -314,12 +314,12 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf prefs.frameInfo.blockSizeID = LZ4F_optimalBSID(prefs.frameInfo.blockSizeID, srcSize); prefs.autoFlush = 1; if (srcSize <= LZ4F_getBlockSize(prefs.frameInfo.blockSizeID)) - prefs.frameInfo.blockMode = blockIndependent; /* no need for linked blocks */ + prefs.frameInfo.blockMode = LZ4F_blockIndependent; /* no need for linked blocks */ options.stableSrc = 1; if (dstMaxSize < LZ4F_compressFrameBound(srcSize, &prefs)) - return (size_t)-ERROR_dstMaxSize_tooSmall; + return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; errorCode = LZ4F_compressBegin(&cctxI, dstBuffer, dstMaxSize, &prefs); /* write header */ if (LZ4F_isError(errorCode)) return errorCode; @@ -357,14 +357,14 @@ LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_compressionContext_t* LZ4F_c LZ4F_cctx_internal_t* cctxPtr; cctxPtr = (LZ4F_cctx_internal_t*)ALLOCATOR(sizeof(LZ4F_cctx_internal_t)); - if (cctxPtr==NULL) return (LZ4F_errorCode_t)(-ERROR_allocation_failed); + if (cctxPtr==NULL) return (LZ4F_errorCode_t)(-LZ4F_ERROR_allocation_failed); cctxPtr->version = version; cctxPtr->cStage = 0; /* Next stage : write header */ *LZ4F_compressionContextPtr = (LZ4F_compressionContext_t)cctxPtr; - return OK_NoError; + return LZ4F_OK_NoError; } @@ -379,7 +379,7 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_comp FREEMEM(LZ4F_compressionContext); } - return OK_NoError; + return LZ4F_OK_NoError; } @@ -398,8 +398,8 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds BYTE* headerStart; size_t requiredBuffSize; - if (dstMaxSize < LZ4F_MAXHEADERFRAME_SIZE) return (size_t)-ERROR_dstMaxSize_tooSmall; - if (cctxPtr->cStage != 0) return (size_t)-ERROR_GENERIC; + if (dstMaxSize < LZ4F_MAXHEADERFRAME_SIZE) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; + if (cctxPtr->cStage != 0) return (size_t)-LZ4F_ERROR_GENERIC; memset(&prefNull, 0, sizeof(prefNull)); if (preferencesPtr == NULL) preferencesPtr = &prefNull; cctxPtr->prefs = *preferencesPtr; @@ -422,16 +422,16 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds if (cctxPtr->prefs.frameInfo.blockSizeID == 0) cctxPtr->prefs.frameInfo.blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT; cctxPtr->maxBlockSize = LZ4F_getBlockSize(cctxPtr->prefs.frameInfo.blockSizeID); - requiredBuffSize = cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == blockLinked) * 128 KB); + requiredBuffSize = cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 128 KB); if (preferencesPtr->autoFlush) - requiredBuffSize = (cctxPtr->prefs.frameInfo.blockMode == blockLinked) * 64 KB; /* just needs dict */ + requiredBuffSize = (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 64 KB; /* just needs dict */ if (cctxPtr->maxBufferSize < requiredBuffSize) { cctxPtr->maxBufferSize = requiredBuffSize; FREEMEM(cctxPtr->tmpBuff); cctxPtr->tmpBuff = (BYTE*)ALLOCATOR(requiredBuffSize); - if (cctxPtr->tmpBuff == NULL) return (size_t)-ERROR_allocation_failed; + if (cctxPtr->tmpBuff == NULL) return (size_t)-LZ4F_ERROR_allocation_failed; } cctxPtr->tmpIn = cctxPtr->tmpBuff; cctxPtr->tmpInSize = 0; @@ -481,7 +481,7 @@ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesP prefsNull.frameInfo.contentChecksumFlag = contentChecksumEnabled; /* worst case */ { const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr; - blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID; + LZ4F_blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID; size_t blockSize = LZ4F_getBlockSize(bid); unsigned nbBlocks = (unsigned)(srcSize / blockSize) + 1; size_t lastBlockSize = prefsPtr->autoFlush ? srcSize % blockSize : blockSize; @@ -530,14 +530,14 @@ static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char return LZ4_compressHC_limitedOutput_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize); } -static compressFunc_t LZ4F_selectCompression(blockMode_t blockMode, U32 level) +static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, U32 level) { if (level < minHClevel) { - if (blockMode == blockIndependent) return LZ4F_localLZ4_compress_limitedOutput_withState; + if (blockMode == LZ4F_blockIndependent) return LZ4F_localLZ4_compress_limitedOutput_withState; return LZ4F_localLZ4_compress_limitedOutput_continue; } - if (blockMode == blockIndependent) return LZ4_compressHC2_limitedOutput_withStateHC; + if (blockMode == LZ4F_blockIndependent) return LZ4_compressHC2_limitedOutput_withStateHC; return LZ4F_localLZ4_compressHC_limitedOutput_continue; } @@ -572,8 +572,8 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d compressFunc_t compress; - if (cctxPtr->cStage != 1) return (size_t)-ERROR_GENERIC; - if (dstMaxSize < LZ4F_compressBound(srcSize, &(cctxPtr->prefs))) return (size_t)-ERROR_dstMaxSize_tooSmall; + if (cctxPtr->cStage != 1) return (size_t)-LZ4F_ERROR_GENERIC; + if (dstMaxSize < LZ4F_compressBound(srcSize, &(cctxPtr->prefs))) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; memset(&cOptionsNull, 0, sizeof(cOptionsNull)); if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull; @@ -601,7 +601,7 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, blockSize, compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel); - if (cctxPtr->prefs.frameInfo.blockMode==blockLinked) cctxPtr->tmpIn += blockSize; + if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += blockSize; cctxPtr->tmpInSize = 0; } } @@ -623,7 +623,7 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d } /* preserve dictionary if necessary */ - if ((cctxPtr->prefs.frameInfo.blockMode==blockLinked) && (lastBlockCompressed==fromSrcBuffer)) + if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)) { if (compressOptionsPtr->stableSrc) { @@ -632,13 +632,13 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d else { int realDictSize = LZ4F_localSaveDict(cctxPtr); - if (realDictSize==0) return (size_t)-ERROR_GENERIC; + if (realDictSize==0) return (size_t)-LZ4F_ERROR_GENERIC; cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize; } } /* keep tmpIn within limits */ - if ((cctxPtr->tmpIn + blockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize) /* necessarily blockLinked && lastBlockCompressed==fromTmpBuffer */ + if ((cctxPtr->tmpIn + blockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize) /* necessarily LZ4F_blockLinked && lastBlockCompressed==fromTmpBuffer */ && !(cctxPtr->prefs.autoFlush)) { int realDictSize = LZ4F_localSaveDict(cctxPtr); @@ -654,7 +654,7 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d cctxPtr->tmpInSize = sizeToCopy; } - if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled) + if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled) XXH32_update(&(cctxPtr->xxh), srcBuffer, srcSize); cctxPtr->totalInSize += srcSize; @@ -679,8 +679,8 @@ size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer, if (cctxPtr->tmpInSize == 0) return 0; /* nothing to flush */ - if (cctxPtr->cStage != 1) return (size_t)-ERROR_GENERIC; - if (dstMaxSize < (cctxPtr->tmpInSize + 8)) return (size_t)-ERROR_dstMaxSize_tooSmall; /* +8 : block header(4) + block checksum(4) */ + if (cctxPtr->cStage != 1) return (size_t)-LZ4F_ERROR_GENERIC; + if (dstMaxSize < (cctxPtr->tmpInSize + 8)) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; /* +8 : block header(4) + block checksum(4) */ (void)compressOptionsPtr; /* not yet useful */ /* select compression function */ @@ -688,11 +688,11 @@ size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer, /* compress tmp buffer */ dstPtr += LZ4F_compressBlock(dstPtr, cctxPtr->tmpIn, cctxPtr->tmpInSize, compress, cctxPtr->lz4CtxPtr, cctxPtr->prefs.compressionLevel); - if (cctxPtr->prefs.frameInfo.blockMode==blockLinked) cctxPtr->tmpIn += cctxPtr->tmpInSize; + if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += cctxPtr->tmpInSize; cctxPtr->tmpInSize = 0; /* keep tmpIn within limits */ - if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize)) /* necessarily blockLinked */ + if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize)) /* necessarily LZ4F_blockLinked */ { int realDictSize = LZ4F_localSaveDict(cctxPtr); cctxPtr->tmpIn = cctxPtr->tmpBuff + realDictSize; @@ -725,7 +725,7 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t compressionContext, void* dstB LZ4F_writeLE32(dstPtr, 0); dstPtr+=4; /* endMark */ - if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled) + if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled) { U32 xxh = XXH32_digest(&(cctxPtr->xxh)); LZ4F_writeLE32(dstPtr, xxh); @@ -737,7 +737,7 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t compressionContext, void* dstB if (cctxPtr->prefs.frameInfo.contentSize) { if (cctxPtr->prefs.frameInfo.contentSize != cctxPtr->totalInSize) - return (size_t)-ERROR_frameSize_wrong; + return (size_t)-LZ4F_ERROR_frameSize_wrong; } return dstPtr - dstStart; @@ -762,11 +762,11 @@ LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_decompressionContext_t* LZ LZ4F_dctx_internal_t* dctxPtr; dctxPtr = (LZ4F_dctx_internal_t*)ALLOCATOR(sizeof(LZ4F_dctx_internal_t)); - if (dctxPtr==NULL) return (LZ4F_errorCode_t)-ERROR_GENERIC; + if (dctxPtr==NULL) return (LZ4F_errorCode_t)-LZ4F_ERROR_GENERIC; dctxPtr->version = versionNumber; *LZ4F_decompressionContextPtr = (LZ4F_compressionContext_t)dctxPtr; - return OK_NoError; + return LZ4F_OK_NoError; } LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t LZ4F_decompressionContext) @@ -778,7 +778,7 @@ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t LZ4F_ FREEMEM(dctxPtr->tmpOutBuffer); FREEMEM(dctxPtr); } - return OK_NoError; + return LZ4F_OK_NoError; } @@ -812,13 +812,13 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo const BYTE* srcPtr = (const BYTE*)srcVoidPtr; /* need to decode header to get frameInfo */ - if (srcSize < minFHSize) return (size_t)-ERROR_GENERIC; /* minimal header size */ + if (srcSize < minFHSize) return (size_t)-LZ4F_ERROR_GENERIC; /* minimal header size */ memset(&(dctxPtr->frameInfo), 0, sizeof(dctxPtr->frameInfo)); /* skippable frames */ if ((LZ4F_readLE32(srcPtr) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) { - dctxPtr->frameInfo.frameType = skippableFrame; + dctxPtr->frameInfo.frameType = LZ4F_skippableFrame; if (srcVoidPtr == (void*)(dctxPtr->header)) { dctxPtr->tmpInSize = srcSize; @@ -834,7 +834,7 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo } /* control magic number */ - if (LZ4F_readLE32(srcPtr) != LZ4F_MAGICNUMBER) return (size_t)-ERROR_frameType_unknown; + if (LZ4F_readLE32(srcPtr) != LZ4F_MAGICNUMBER) return (size_t)-LZ4F_ERROR_frameType_unknown; dctxPtr->frameInfo.frameType = LZ4F_frame; /* Flags */ @@ -874,9 +874,9 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_header_checksum_invalid; /* Bad header checksum error */ /* save */ - dctxPtr->frameInfo.blockMode = (blockMode_t)blockMode; - dctxPtr->frameInfo.contentChecksumFlag = (contentChecksum_t)contentChecksumFlag; - dctxPtr->frameInfo.blockSizeID = (blockSizeID_t)blockSizeID; + dctxPtr->frameInfo.blockMode = (LZ4F_blockMode_t)blockMode; + dctxPtr->frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)contentChecksumFlag; + dctxPtr->frameInfo.blockSizeID = (LZ4F_blockSizeID_t)blockSizeID; dctxPtr->maxBlockSize = LZ4F_getBlockSize(blockSizeID); if (contentSizeFlag) dctxPtr->frameRemainingSize = dctxPtr->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6); @@ -885,16 +885,16 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo if (contentChecksumFlag) XXH32_reset(&(dctxPtr->xxh), 0); /* alloc */ - bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==blockLinked) * 128 KB); + bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB); if (bufferNeeded > dctxPtr->maxBufferSize) /* tmp buffers too small */ { FREEMEM(dctxPtr->tmpIn); FREEMEM(dctxPtr->tmpOutBuffer); dctxPtr->maxBufferSize = bufferNeeded; dctxPtr->tmpIn = (BYTE*)ALLOCATOR(dctxPtr->maxBlockSize); - if (dctxPtr->tmpIn == NULL) return (size_t)-ERROR_GENERIC; + if (dctxPtr->tmpIn == NULL) return (size_t)-LZ4F_ERROR_GENERIC; dctxPtr->tmpOutBuffer= (BYTE*)ALLOCATOR(dctxPtr->maxBufferSize); - if (dctxPtr->tmpOutBuffer== NULL) return (size_t)-ERROR_GENERIC; + if (dctxPtr->tmpOutBuffer== NULL) return (size_t)-LZ4F_ERROR_GENERIC; } dctxPtr->tmpInSize = 0; dctxPtr->tmpInTarget = 0; @@ -1058,7 +1058,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, /* expect to continue decoding src buffer where it left previously */ if (dctxPtr->srcExpect != NULL) { - if (srcStart != dctxPtr->srcExpect) return (size_t)-ERROR_wrongSrcPtr; + if (srcStart != dctxPtr->srcExpect) return (size_t)-LZ4F_ERROR_wrongSrcPtr; } /* programmed as a state machine */ @@ -1143,7 +1143,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, dctxPtr->dStage = dstage_getSuffix; break; } - if (nextCBlockSize > dctxPtr->maxBlockSize) return (size_t)-ERROR_GENERIC; /* invalid cBlockSize */ + if (nextCBlockSize > dctxPtr->maxBlockSize) return (size_t)-LZ4F_ERROR_GENERIC; /* invalid cBlockSize */ dctxPtr->tmpInTarget = nextCBlockSize; if (LZ4F_readLE32(selectedIn) & LZ4F_BLOCKUNCOMPRESSED_FLAG) { @@ -1169,7 +1169,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= sizeToCopy; /* dictionary management */ - if (dctxPtr->frameInfo.blockMode==blockLinked) + if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 0); srcPtr += sizeToCopy; @@ -1231,18 +1231,18 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, int (*decoder)(const char*, char*, int, int, const char*, int); int decodedSize; - if (dctxPtr->frameInfo.blockMode == blockLinked) + if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked) decoder = LZ4_decompress_safe_usingDict; else decoder = LZ4F_decompress_safe; decodedSize = decoder((const char*)selectedIn, (char*)dstPtr, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize); - if (decodedSize < 0) return (size_t)-ERROR_GENERIC; /* decompression failed */ + if (decodedSize < 0) return (size_t)-LZ4F_ERROR_GENERIC; /* decompression failed */ if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dstPtr, decodedSize); if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= decodedSize; /* dictionary management */ - if (dctxPtr->frameInfo.blockMode==blockLinked) + if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) LZ4F_updateDict(dctxPtr, dstPtr, decodedSize, dstStart, 0); dstPtr += decodedSize; @@ -1256,13 +1256,13 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, int (*decoder)(const char*, char*, int, int, const char*, int); int decodedSize; - if (dctxPtr->frameInfo.blockMode == blockLinked) + if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked) decoder = LZ4_decompress_safe_usingDict; else decoder = LZ4F_decompress_safe; /* ensure enough place for tmpOut */ - if (dctxPtr->frameInfo.blockMode == blockLinked) + if (dctxPtr->frameInfo.blockMode == LZ4F_blockLinked) { if (dctxPtr->dict == dctxPtr->tmpOutBuffer) { @@ -1283,7 +1283,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, /* Decode */ decodedSize = decoder((const char*)selectedIn, (char*)dctxPtr->tmpOut, (int)dctxPtr->tmpInTarget, (int)dctxPtr->maxBlockSize, (const char*)dctxPtr->dict, (int)dctxPtr->dictSize); - if (decodedSize < 0) return (size_t)-ERROR_decompressionFailed; /* decompression failed */ + if (decodedSize < 0) return (size_t)-LZ4F_ERROR_decompressionFailed; /* decompression failed */ if (dctxPtr->frameInfo.contentChecksumFlag) XXH32_update(&(dctxPtr->xxh), dctxPtr->tmpOut, decodedSize); if (dctxPtr->frameInfo.contentSize) dctxPtr->frameRemainingSize -= decodedSize; dctxPtr->tmpOutSize = decodedSize; @@ -1299,7 +1299,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, memcpy(dstPtr, dctxPtr->tmpOut + dctxPtr->tmpOutStart, sizeToCopy); /* dictionary management */ - if (dctxPtr->frameInfo.blockMode==blockLinked) + if (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) LZ4F_updateDict(dctxPtr, dstPtr, sizeToCopy, dstStart, 1); dctxPtr->tmpOutStart += sizeToCopy; @@ -1319,7 +1319,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, case dstage_getSuffix: { size_t suffixSize = dctxPtr->frameInfo.contentChecksumFlag * 4; - if (dctxPtr->frameRemainingSize) return (size_t)-ERROR_frameSize_wrong; /* incorrect frame size decoded */ + if (dctxPtr->frameRemainingSize) return (size_t)-LZ4F_ERROR_frameSize_wrong; /* incorrect frame size decoded */ if (suffixSize == 0) /* frame completed */ { nextSrcSizeHint = 0; @@ -1360,7 +1360,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, { U32 readCRC = LZ4F_readLE32(selectedIn); U32 resultCRC = XXH32_digest(&(dctxPtr->xxh)); - if (readCRC != resultCRC) return (size_t)-ERROR_checksum_invalid; + if (readCRC != resultCRC) return (size_t)-LZ4F_ERROR_checksum_invalid; nextSrcSizeHint = 0; dctxPtr->dStage = dstage_getHeader; doAnotherStage = 0; @@ -1425,7 +1425,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, } /* preserve dictionary within tmp if necessary */ - if ( (dctxPtr->frameInfo.blockMode==blockLinked) + if ( (dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) &&(dctxPtr->dict != dctxPtr->tmpOutBuffer) &&(!decompressOptionsPtr->stableDst) &&((unsigned)(dctxPtr->dStage-1) < (unsigned)(dstage_getSuffix-1)) diff --git a/lib/lz4frame.h b/lib/lz4frame.h index f22ef00..1f13a07 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -62,16 +62,23 @@ const char* LZ4F_getErrorName(LZ4F_errorCode_t code); /* return error code str /************************************** * Frame compression types * ************************************/ -typedef enum { LZ4F_default=0, max64KB=4, max256KB=5, max1MB=6, max4MB=7 } blockSizeID_t; +typedef enum { LZ4F_default=0, LZ4F_max64KB=4, LZ4F_max256KB=5, LZ4F_max1MB=6, LZ4F_max4MB=7 } LZ4F_blockSizeID_t; +typedef enum { LZ4F_blockLinked=0, LZ4F_blockIndependent} LZ4F_blockMode_t; +typedef enum { LZ4F_noContentChecksum=0, LZ4F_contentChecksumEnabled } LZ4F_contentChecksum_t; +typedef enum { LZ4F_frame=0, LZ4F_skippableFrame } LZ4F_frameType_t; + +#ifndef LZ4F_DISABLE_OLD_ENUMS +typedef enum { /*LZ4F_default=0,*/ max64KB=4, max256KB=5, max1MB=6, max4MB=7 } blockSizeID_t; typedef enum { blockLinked=0, blockIndependent} blockMode_t; typedef enum { noContentChecksum=0, contentChecksumEnabled } contentChecksum_t; -typedef enum { LZ4F_frame=0, skippableFrame } frameType_t; +typedef enum { /*LZ4F_frame=0,*/ skippableFrame } frameType_t; +#endif typedef struct { - blockSizeID_t blockSizeID; /* max64KB, max256KB, max1MB, max4MB ; 0 == default */ - blockMode_t blockMode; /* blockLinked, blockIndependent ; 0 == default */ - contentChecksum_t contentChecksumFlag; /* noContentChecksum, contentChecksumEnabled ; 0 == default */ - frameType_t frameType; /* LZ4F_frame, skippableFrame ; 0 == default */ + LZ4F_blockSizeID_t blockSizeID; /* max64KB, max256KB, max1MB, max4MB ; 0 == default */ + LZ4F_blockMode_t blockMode; /* blockLinked, blockIndependent ; 0 == default */ + LZ4F_contentChecksum_t contentChecksumFlag; /* noContentChecksum, contentChecksumEnabled ; 0 == default */ + LZ4F_frameType_t frameType; /* LZ4F_frame, skippableFrame ; 0 == default */ unsigned long long contentSize; /* Size of uncompressed (original) content ; 0 == unknown */ unsigned reserved[2]; /* must be zero for forward compatibility */ } LZ4F_frameInfo_t; diff --git a/lib/lz4frame_static.h b/lib/lz4frame_static.h index b608d23..afcf7da 100644 --- a/lib/lz4frame_static.h +++ b/lib/lz4frame_static.h @@ -64,7 +64,11 @@ extern "C" { ITEM(ERROR_header_checksum_invalid) \ ITEM(ERROR_maxCode) -#define LZ4F_GENERATE_ENUM(ENUM) ENUM, +#ifndef LZ4F_DISABLE_OLD_ENUMS +#define LZ4F_GENERATE_ENUM(ENUM) LZ4F_##ENUM, ENUM = LZ4F_##ENUM, +#else +#define LZ4F_GENERATE_ENUM(ENUM) LZ4F_##ENUM, +#endif typedef enum { LZ4F_LIST_ERRORS(LZ4F_GENERATE_ENUM) } LZ4F_errorCodes; /* enum is exposed, to handle specific errors; compare function result to -enum value */ diff --git a/programs/lz4io.c b/programs/lz4io.c index db34747..6ca7ee7 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -465,9 +465,9 @@ static int LZ4IO_compressJob(cRess_t ress, const char* srcFileName, const char* /* Set compression parameters */ prefs.autoFlush = 1; prefs.compressionLevel = compressionLevel; - prefs.frameInfo.blockMode = (blockMode_t)g_blockIndependence; - prefs.frameInfo.blockSizeID = (blockSizeID_t)g_blockSizeId; - prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)g_streamChecksum; + prefs.frameInfo.blockMode = (LZ4F_blockMode_t)g_blockIndependence; + prefs.frameInfo.blockSizeID = (LZ4F_blockSizeID_t)g_blockSizeId; + prefs.frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)g_streamChecksum; if (g_contentSizeFlag) { unsigned long long fileSize = LZ4IO_GetFileSize(srcFileName); -- cgit v0.12 From 585bab81217ad2480803518140ed4956aad0459c Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Wed, 15 Apr 2015 02:59:51 +0900 Subject: Issue#90 : Change old enum to macro to maximize compatibility --- lib/lz4frame.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 1f13a07..d1501da 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -68,10 +68,19 @@ typedef enum { LZ4F_noContentChecksum=0, LZ4F_contentChecksumEnabled } LZ4F_cont typedef enum { LZ4F_frame=0, LZ4F_skippableFrame } LZ4F_frameType_t; #ifndef LZ4F_DISABLE_OLD_ENUMS -typedef enum { /*LZ4F_default=0,*/ max64KB=4, max256KB=5, max1MB=6, max4MB=7 } blockSizeID_t; -typedef enum { blockLinked=0, blockIndependent} blockMode_t; -typedef enum { noContentChecksum=0, contentChecksumEnabled } contentChecksum_t; -typedef enum { /*LZ4F_frame=0,*/ skippableFrame } frameType_t; +# define max64KB LZ4F_max64KB +# define max256KB LZ4F_max256KB +# define max1MB LZ4F_max1MB +# define max4MB LZ4F_max4MB +# define blockSizeID_t LZ4F_blockSizeID_t +# define blockLinked LZ4F_blockLinked +# define blockIndependent LZ4F_blockIndependent +# define blockMode_t LZ4F_blockMode_t +# define noContentChecksum LZ4F_noContentChecksum +# define contentChecksumEnabled LZ4F_contentChecksumEnabled +# define contentChecksum_t LZ4F_contentChecksum_t +# define skippableFrame LZ4F_skippableFrame +# define frameType_t LZ4F_frameType_t #endif typedef struct { -- cgit v0.12 From 175890fe9bcd5029ffb33e2328037e0251e89ecb Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Wed, 15 Apr 2015 03:00:36 +0900 Subject: Issue#90 : Change old enum names to new one --- programs/frametest.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/programs/frametest.c b/programs/frametest.c index 60cd765..8a51be8 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -297,21 +297,21 @@ int basicTests(U32 seed, double compressibility) } DISPLAYLEVEL(3, "Using 64 KB block : \n"); - prefs.frameInfo.blockSizeID = max64KB; - prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled; + prefs.frameInfo.blockSizeID = LZ4F_max64KB; + prefs.frameInfo.contentChecksumFlag = LZ4F_contentChecksumEnabled; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); DISPLAYLEVEL(3, "without checksum : \n"); - prefs.frameInfo.contentChecksumFlag = noContentChecksum; + prefs.frameInfo.contentChecksumFlag = LZ4F_noContentChecksum; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); DISPLAYLEVEL(3, "Using 256 KB block : \n"); - prefs.frameInfo.blockSizeID = max256KB; - prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled; + prefs.frameInfo.blockSizeID = LZ4F_max256KB; + prefs.frameInfo.contentChecksumFlag = LZ4F_contentChecksumEnabled; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); @@ -351,33 +351,33 @@ int basicTests(U32 seed, double compressibility) } DISPLAYLEVEL(3, "without checksum : \n"); - prefs.frameInfo.contentChecksumFlag = noContentChecksum; + prefs.frameInfo.contentChecksumFlag = LZ4F_noContentChecksum; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); DISPLAYLEVEL(3, "Using 1 MB block : \n"); - prefs.frameInfo.blockSizeID = max1MB; - prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled; + prefs.frameInfo.blockSizeID = LZ4F_max1MB; + prefs.frameInfo.contentChecksumFlag = LZ4F_contentChecksumEnabled; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); DISPLAYLEVEL(3, "without checksum : \n"); - prefs.frameInfo.contentChecksumFlag = noContentChecksum; + prefs.frameInfo.contentChecksumFlag = LZ4F_noContentChecksum; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); DISPLAYLEVEL(3, "Using 4 MB block : \n"); - prefs.frameInfo.blockSizeID = max4MB; - prefs.frameInfo.contentChecksumFlag = contentChecksumEnabled; + prefs.frameInfo.blockSizeID = LZ4F_max4MB; + prefs.frameInfo.contentChecksumFlag = LZ4F_contentChecksumEnabled; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); DISPLAYLEVEL(3, "without checksum : \n"); - prefs.frameInfo.contentChecksumFlag = noContentChecksum; + prefs.frameInfo.contentChecksumFlag = LZ4F_noContentChecksum; cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(testSize, &prefs), CNBuffer, testSize, &prefs); if (LZ4F_isError(cSize)) goto _output_error; DISPLAYLEVEL(3, "Compressed %i bytes into a %i bytes frame \n", (int)testSize, (int)cSize); @@ -595,9 +595,9 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi memset(&prefs, 0, sizeof(prefs)); memset(&cOptions, 0, sizeof(cOptions)); memset(&dOptions, 0, sizeof(dOptions)); - prefs.frameInfo.blockMode = (blockMode_t)BMId; - prefs.frameInfo.blockSizeID = (blockSizeID_t)BSId; - prefs.frameInfo.contentChecksumFlag = (contentChecksum_t)CCflag; + prefs.frameInfo.blockMode = (LZ4F_blockMode_t)BMId; + prefs.frameInfo.blockSizeID = (LZ4F_blockSizeID_t)BSId; + prefs.frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)CCflag; prefs.frameInfo.contentSize = frameContentSize; prefs.autoFlush = autoflush; prefs.compressionLevel = FUZ_rand(&randState) % 5; -- cgit v0.12 From 3d46d4b144223a69ab7e6ed327d426a7b5bdf10f Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Wed, 15 Apr 2015 14:19:17 +0900 Subject: Fix LZ4_DEPRECATED() in lz4hc.h --- lib/lz4hc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4hc.h b/lib/lz4hc.h index d7db3bd..2667044 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -154,7 +154,7 @@ using LZ4_saveDictHC(). # define LZ4_DEPRECATED(message) __declspec(deprecated(message)) # else # pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") -# define LZ4_DEPRECATED +# define LZ4_DEPRECATED(message) # endif #endif // LZ4_DEPRECATE_WARNING_DEFBLOCK -- cgit v0.12 From 4e574e7395323d7fe0edb4313d79d5ab3b2607ae Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 15 Apr 2015 10:34:08 +0100 Subject: Updated lz4frame error names --- lib/lz4frame.c | 20 ++++++++++---------- lib/lz4frame_static.h | 14 +++++--------- programs/Makefile | 4 ++-- programs/frametest.c | 3 ++- programs/lz4.1 | 6 +++--- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 619481d..6f53897 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -478,7 +478,7 @@ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesP { LZ4F_preferences_t prefsNull; memset(&prefsNull, 0, sizeof(prefsNull)); - prefsNull.frameInfo.contentChecksumFlag = contentChecksumEnabled; /* worst case */ + prefsNull.frameInfo.contentChecksumFlag = LZ4F_contentChecksumEnabled; /* worst case */ { const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr; LZ4F_blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID; @@ -862,16 +862,16 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo blockSizeID = (BD>>4) & _3BITS; /* validate */ - if (version != 1) return (size_t)-ERROR_version_wrong; /* Version Number, only supported value */ - if (blockChecksumFlag != 0) return (size_t)-ERROR_unsupported_checksum; /* Only supported value for the time being */ - if (((FLG>>0)&_2BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ - if (((BD>>7)&_1BIT) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bit */ - if (blockSizeID < 4) return (size_t)-ERROR_unsupported_block_size; /* 4-7 only supported values for the time being */ - if (((BD>>0)&_4BITS) != 0) return (size_t)-ERROR_reserved_flag_set; /* Reserved bits */ + if (version != 1) return (size_t)-LZ4F_ERROR_headerVersion_wrong; /* Version Number, only supported value */ + if (blockChecksumFlag != 0) return (size_t)-LZ4F_ERROR_blockChecksum_unsupported; /* Not supported for the time being */ + if (((FLG>>0)&_2BITS) != 0) return (size_t)-LZ4F_ERROR_reservedFlag_set; /* Reserved bits */ + if (((BD>>7)&_1BIT) != 0) return (size_t)-LZ4F_ERROR_reservedFlag_set; /* Reserved bit */ + if (blockSizeID < 4) return (size_t)-LZ4F_ERROR_maxBlockSize_invalid; /* 4-7 only supported values for the time being */ + if (((BD>>0)&_4BITS) != 0) return (size_t)-LZ4F_ERROR_reservedFlag_set; /* Reserved bits */ /* check */ HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5); - if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-ERROR_header_checksum_invalid; /* Bad header checksum error */ + if (HC != srcPtr[frameHeaderSize-1]) return (size_t)-LZ4F_ERROR_headerChecksum_invalid; /* Bad header checksum error */ /* save */ dctxPtr->frameInfo.blockMode = (LZ4F_blockMode_t)blockMode; @@ -1058,7 +1058,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, /* expect to continue decoding src buffer where it left previously */ if (dctxPtr->srcExpect != NULL) { - if (srcStart != dctxPtr->srcExpect) return (size_t)-LZ4F_ERROR_wrongSrcPtr; + if (srcStart != dctxPtr->srcExpect) return (size_t)-LZ4F_ERROR_srcPtr_wrong; } /* programmed as a state machine */ @@ -1360,7 +1360,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, { U32 readCRC = LZ4F_readLE32(selectedIn); U32 resultCRC = XXH32_digest(&(dctxPtr->xxh)); - if (readCRC != resultCRC) return (size_t)-LZ4F_ERROR_checksum_invalid; + if (readCRC != resultCRC) return (size_t)-LZ4F_ERROR_contentChecksum_invalid; nextSrcSizeHint = 0; dctxPtr->dStage = dstage_getHeader; doAnotherStage = 0; diff --git a/lib/lz4frame_static.h b/lib/lz4frame_static.h index afcf7da..25afed4 100644 --- a/lib/lz4frame_static.h +++ b/lib/lz4frame_static.h @@ -50,20 +50,16 @@ extern "C" { ITEM(OK_NoError) ITEM(ERROR_GENERIC) \ ITEM(ERROR_maxBlockSize_invalid) ITEM(ERROR_blockMode_invalid) ITEM(ERROR_contentChecksumFlag_invalid) \ ITEM(ERROR_compressionLevel_invalid) \ + ITEM(ERROR_headerVersion_wrong) ITEM(ERROR_blockChecksum_unsupported) ITEM(ERROR_reservedFlag_set) \ ITEM(ERROR_allocation_failed) \ ITEM(ERROR_srcSize_tooLarge) ITEM(ERROR_dstMaxSize_tooSmall) \ - ITEM(ERROR_frameSize_wrong) \ - ITEM(ERROR_frameType_unknown) \ - ITEM(ERROR_wrongSrcPtr) \ + ITEM(ERROR_frameType_unknown) ITEM(ERROR_frameSize_wrong) \ + ITEM(ERROR_srcPtr_wrong) \ ITEM(ERROR_decompressionFailed) \ - ITEM(ERROR_checksum_invalid) \ - ITEM(ERROR_version_wrong) \ - ITEM(ERROR_unsupported_checksum) \ - ITEM(ERROR_reserved_flag_set) \ - ITEM(ERROR_unsupported_block_size) \ - ITEM(ERROR_header_checksum_invalid) \ + ITEM(ERROR_headerChecksum_invalid) ITEM(ERROR_contentChecksum_invalid) \ ITEM(ERROR_maxCode) +//#define LZ4F_DISABLE_OLD_ENUMS #ifndef LZ4F_DISABLE_OLD_ENUMS #define LZ4F_GENERATE_ENUM(ENUM) LZ4F_##ENUM, ENUM = LZ4F_##ENUM, #else diff --git a/programs/Makefile b/programs/Makefile index 6008c7b..7bbe060 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -226,10 +226,10 @@ test-lz4c32: lz4 lz4c32 datagen ./datagen -g6GB | ./lz4c32 -vq9BD | ./lz4 -qt test-fullbench: fullbench - ./fullbench --no-prompt $(TEST_FILES) + ./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES) test-fullbench32: fullbench32 - ./fullbench32 --no-prompt $(TEST_FILES) + ./fullbench32 --no-prompt $(NB_LOOPS) $(TEST_FILES) test-fuzzer: fuzzer ./fuzzer $(FUZZER_TIME) diff --git a/programs/frametest.c b/programs/frametest.c index 8a51be8..6adf408 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -678,7 +678,8 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi dOptions.stableDst = FUZ_rand(&randState) & 1; if (nonContiguousDst==2) dOptions.stableDst = 0; result = LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, &dOptions); - if (result == (size_t)-ERROR_checksum_invalid) locateBuffDiff((BYTE*)srcBuffer+srcStart, decodedBuffer, srcSize, nonContiguousDst); + if (result == (size_t)-LZ4F_ERROR_contentChecksum_invalid) + locateBuffDiff((BYTE*)srcBuffer+srcStart, decodedBuffer, srcSize, nonContiguousDst); CHECK(LZ4F_isError(result), "Decompression failed (error %i:%s)", (int)result, LZ4F_getErrorName((LZ4F_errorCode_t)result)); XXH64_update(&xxh64, op, (U32)oSize); totalOut += oSize; diff --git a/programs/lz4.1 b/programs/lz4.1 index eea248f..a9b5195 100644 --- a/programs/lz4.1 +++ b/programs/lz4.1 @@ -177,12 +177,12 @@ independently, and the resulting name of the compressed file will be block dependency (improve compression ratio) .TP .B \--[no-]frame-crc - disable stream checksum (default:enabled) + select frame checksum (default:enabled) .TP .B \--[no-]content-size - compressed file includes original size (default:not present) + header includes original size (default:not present) Note : this option can only be activated when the original size can be determined, -hence for a file. It won't work with unknown source size, such as stdin pipe. +hence for a file. It won't work with unknown source size, such as stdin or pipe. .TP .B \--[no-]sparse enable sparse file (default:disabled)(experimental) -- cgit v0.12 From a430b859cf552aa43215fe082e15a95c8bda5d6f Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 15 Apr 2015 16:24:43 +0100 Subject: Multiple files decompression refactoring --- programs/Makefile | 21 ++++--- programs/lz4io.c | 179 ++++++++++++++++++++++++++---------------------------- 2 files changed, 99 insertions(+), 101 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 7bbe060..fa6b04d 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -191,7 +191,19 @@ test-lz4-frame-concatenation: lz4 datagen @rm *.test @echo frame concatenation test completed -test-lz4: lz4 datagen test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation +test-lz4-multiple: lz4 datagen + @echo ---- test multiple files ---- + @./datagen -s1 > tmp1 + @./datagen -s2 -g100K > tmp2 + @./datagen -s3 -g1M > tmp3 + ./lz4 -f -m tmp* + ls -ls tmp* + rm tmp1 tmp2 tmp3 + ./lz4 -df -m *.lz4 + ls -ls tmp* + @rm tmp* + +test-lz4: lz4 datagen test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation @echo ---- test lz4 basic compression/decompression ---- ./datagen -g0 | ./lz4 -v | ./lz4 -t ./datagen -g16KB | ./lz4 -9 | ./lz4 -t @@ -202,13 +214,6 @@ test-lz4: lz4 datagen test-lz4-sparse test-lz4-contentSize test-lz4-frame-concat ./datagen -g256MB | ./lz4 -vqB4D | ./lz4 -t ./datagen -g6GB | ./lz4 -vqB5D | ./lz4 -qt ./datagen -g6GB | ./lz4 -vq9BD | ./lz4 -qt - @echo ---- test multiple input files ---- - @./datagen -s1 > file1 - @./datagen -s2 > file2 - @./datagen -s3 > file3 - ./lz4 -f -m file1 file2 file3 - ls -l file* - @rm file1 file2 file3 file1.lz4 file2.lz4 file3.lz4 @echo ---- test pass-through ---- ./datagen | ./lz4 -tf diff --git a/programs/lz4io.c b/programs/lz4io.c index 6ca7ee7..130a1de 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -159,7 +159,7 @@ static const int maxBlockSizeID = 7; #define EXTENDED_ARGUMENTS #define EXTENDED_HELP #define EXTENDED_FORMAT -#define DEFAULT_DECOMPRESSOR LZ4IO_decompressFile +#define DEFAULT_DECOMPRESSOR LZ4IO_decompressLZ4F /* ************************************************** */ @@ -751,16 +751,44 @@ static unsigned long long LZ4IO_decodeLegacyStream(FILE* finput, FILE* foutput) typedef struct { - FILE* sFile; - FILE* dFile; void* srcBuffer; size_t srcBufferSize; void* dstBuffer; size_t dstBufferSize; LZ4F_decompressionContext_t dCtx; -} decompressionJob_t; +} dRess_t; -static unsigned long long LZ4IO_decompressJob(decompressionJob_t ress) +static const size_t LZ4IO_dBufferSize = 64 KB; + +static dRess_t LZ4IO_createDResources(void) +{ + dRess_t ress; + LZ4F_errorCode_t errorCode; + + /* init */ + errorCode = LZ4F_createDecompressionContext(&ress.dCtx, LZ4F_VERSION); + if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create LZ4F context : %s", LZ4F_getErrorName(errorCode)); + + /* Allocate Memory */ + ress.srcBufferSize = LZ4IO_dBufferSize; + ress.srcBuffer = malloc(ress.srcBufferSize); + ress.dstBufferSize = LZ4IO_dBufferSize; + ress.dstBuffer = malloc(ress.dstBufferSize); + if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(61, "Allocation error : not enough memory"); + + return ress; +} + +static void LZ4IO_freeDResources(dRess_t ress) +{ + LZ4F_errorCode_t errorCode = LZ4F_freeDecompressionContext(ress.dCtx); + if (LZ4F_isError(errorCode)) EXM_THROW(69, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); + free(ress.srcBuffer); + free(ress.dstBuffer); +} + + +static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE* dstFile) { unsigned long long filesize = 0; LZ4F_errorCode_t errorCode; @@ -782,7 +810,7 @@ static unsigned long long LZ4IO_decompressJob(decompressionJob_t ress) size_t pos = 0; /* Read input */ - readSize = fread(ress.srcBuffer, 1, ress.srcBufferSize, ress.sFile); + readSize = fread(ress.srcBuffer, 1, ress.srcBufferSize, srcFile); if (!readSize) break; /* empty file or stream */ while (pos < readSize) @@ -799,69 +827,26 @@ static unsigned long long LZ4IO_decompressJob(decompressionJob_t ress) /* Write Block */ filesize += decodedBytes; DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20)); - storedSkips = LZ4IO_fwriteSparse(ress.dFile, ress.dstBuffer, decodedBytes, storedSkips); + storedSkips = LZ4IO_fwriteSparse(dstFile, ress.dstBuffer, decodedBytes, storedSkips); } } } - LZ4IO_fwriteSparseEnd(ress.dFile, storedSkips); - - return filesize; -} - - -static const size_t LZ4IO_dBufferSize = 64 KB; - -static unsigned long long LZ4IO_decompressFile(FILE* finput, FILE* foutput) -{ - unsigned long long filesize = 0; - void* inBuff; - void* outBuff; - const size_t inBuffSize = LZ4IO_dBufferSize; - const size_t outBuffSize = LZ4IO_dBufferSize; - LZ4F_decompressionContext_t dCtx; - LZ4F_errorCode_t errorCode; - decompressionJob_t ress; - - /* init */ - errorCode = LZ4F_createDecompressionContext(&dCtx, LZ4F_VERSION); - if (LZ4F_isError(errorCode)) EXM_THROW(60, "Can't create context : %s", LZ4F_getErrorName(errorCode)); - - /* Allocate Memory */ - inBuff = malloc(inBuffSize); - outBuff = malloc(outBuffSize); - if (!inBuff || !outBuff) EXM_THROW(61, "Allocation error : not enough memory"); - - /* Decompression Job */ - ress.dCtx = dCtx; - ress.dFile = foutput; - ress.dstBuffer = outBuff; - ress.dstBufferSize = outBuffSize; - ress.sFile = finput; - ress.srcBuffer = inBuff; - ress.srcBufferSize = inBuffSize; - - filesize = LZ4IO_decompressJob(ress); - - /* Free */ - free(inBuff); - free(outBuff); - errorCode = LZ4F_freeDecompressionContext(dCtx); - if (LZ4F_isError(errorCode)) EXM_THROW(69, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); + LZ4IO_fwriteSparseEnd(dstFile, storedSkips); return filesize; } -static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigned char U32store[MAGICNUMBER_SIZE]) +static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigned char MNstore[MAGICNUMBER_SIZE]) { void* buffer = malloc(64 KB); size_t read = 1, sizeCheck; unsigned long long total = MAGICNUMBER_SIZE; unsigned storedSkips = 0; - sizeCheck = fwrite(U32store, 1, MAGICNUMBER_SIZE, foutput); - if (sizeCheck != MAGICNUMBER_SIZE) EXM_THROW(50, "Pass-through error at start"); + sizeCheck = fwrite(MNstore, 1, MAGICNUMBER_SIZE, foutput); + if (sizeCheck != MAGICNUMBER_SIZE) EXM_THROW(50, "Pass-through write error"); while (read) { @@ -877,9 +862,9 @@ static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigne #define ENDOFSTREAM ((unsigned long long)-1) -static unsigned long long selectDecoder( FILE* finput, FILE* foutput) +static unsigned long long selectDecoder(dRess_t ress, FILE* finput, FILE* foutput) { - unsigned char U32store[MAGICNUMBER_SIZE]; + unsigned char MNstore[MAGICNUMBER_SIZE]; unsigned magicNumber, size; int errorNb; size_t nbReadBytes; @@ -896,34 +881,34 @@ static unsigned long long selectDecoder( FILE* finput, FILE* foutput) } else { - nbReadBytes = fread(U32store, 1, MAGICNUMBER_SIZE, finput); + nbReadBytes = fread(MNstore, 1, MAGICNUMBER_SIZE, finput); if (nbReadBytes==0) return ENDOFSTREAM; /* EOF */ if (nbReadBytes != MAGICNUMBER_SIZE) EXM_THROW(40, "Unrecognized header : Magic Number unreadable"); - magicNumber = LZ4IO_readLE32(U32store); /* Little Endian format */ + magicNumber = LZ4IO_readLE32(MNstore); /* Little Endian format */ } if (LZ4IO_isSkippableMagicNumber(magicNumber)) magicNumber = LZ4IO_SKIPPABLE0; /* fold skippable magic numbers */ switch(magicNumber) { case LZ4IO_MAGICNUMBER: - return DEFAULT_DECOMPRESSOR(finput, foutput); + return LZ4IO_decompressLZ4F(ress, finput, foutput); case LEGACY_MAGICNUMBER: DISPLAYLEVEL(4, "Detected : Legacy format \n"); return LZ4IO_decodeLegacyStream(finput, foutput); case LZ4IO_SKIPPABLE0: DISPLAYLEVEL(4, "Skipping detected skippable area \n"); - nbReadBytes = fread(U32store, 1, 4, finput); + nbReadBytes = fread(MNstore, 1, 4, finput); if (nbReadBytes != 4) EXM_THROW(42, "Stream error : skippable size unreadable"); - size = LZ4IO_readLE32(U32store); /* Little Endian format */ + size = LZ4IO_readLE32(MNstore); /* Little Endian format */ errorNb = fseek(finput, size, SEEK_CUR); if (errorNb != 0) EXM_THROW(43, "Stream error : cannot skip skippable area"); - return selectDecoder(finput, foutput); + return selectDecoder(ress, finput, foutput); EXTENDED_FORMAT; default: if (nbCalls == 1) /* just started */ { if (g_overwrite) - return LZ4IO_passThrough(finput, foutput, U32store); + return LZ4IO_passThrough(finput, foutput, MNstore); EXM_THROW(44,"Unrecognized header : file cannot be decoded"); /* Wrong magic number at the beginning of 1st stream */ } DISPLAYLEVEL(2, "Stream followed by unrecognized data\n"); @@ -932,18 +917,16 @@ static unsigned long long selectDecoder( FILE* finput, FILE* foutput) } -int LZ4IO_decompressFilename(const char* input_filename, const char* output_filename) +static int LZ4IO_decompressFile_extRess(dRess_t ress, const char* input_filename, const char* output_filename) { unsigned long long filesize = 0, decodedSize=0; FILE* finput; FILE* foutput; - clock_t start, end; /* Init */ - start = clock(); if (LZ4IO_getFiles(input_filename, output_filename, &finput, &foutput)) - EXM_THROW(50, "File error"); + return 1; /* sparse file */ if (g_sparseFileSupport) { SET_SPARSE_FILE_MODE(foutput); } @@ -951,67 +934,77 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file /* Loop over multiple streams */ do { - decodedSize = selectDecoder(finput, foutput); + decodedSize = selectDecoder(ress, finput, foutput); if (decodedSize != ENDOFSTREAM) filesize += decodedSize; } while (decodedSize != ENDOFSTREAM); /* Final Status */ - end = clock(); DISPLAYLEVEL(2, "\r%79s\r", ""); DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize); - if (end==start) end=start+1; - { - double seconds = (double)(end - start)/CLOCKS_PER_SEC; - DISPLAYLEVEL(4, "Done in %.2f s ==> %.2f MB/s\n", seconds, (double)filesize / seconds / 1024 / 1024); - } /* Close */ fclose(finput); fclose(foutput); - /* Error status = OK */ return 0; } +int LZ4IO_decompressFilename(const char* input_filename, const char* output_filename) +{ + dRess_t ress; + clock_t start, end; + int missingFiles = 0; + + start = clock(); + + ress = LZ4IO_createDResources(); + missingFiles += LZ4IO_decompressFile_extRess(ress, input_filename, output_filename); + LZ4IO_freeDResources(ress); + + end = clock(); + if (end==start) end=start+1; + { + double seconds = (double)(end - start)/CLOCKS_PER_SEC; + DISPLAYLEVEL(4, "Done in %.2f sec \n", seconds); + } + + return missingFiles; +} + + int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) { int i; - int skipped_files = 0; - int missing_files = 0; + int skippedFiles = 0; + int missingFiles = 0; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); char* ifnSuffix = (char*)malloc(suffixSize + 1); + dRess_t ress; + + ress = LZ4IO_createDResources(); for (i=0; i 0) return 1; - if (missing_files > 0) return 1; - return 0; + return missingFiles + skippedFiles; } -- cgit v0.12 From d153aaa1c236ba464beec4171d76063b5109b18c Mon Sep 17 00:00:00 2001 From: Takayuki MATSUOKA Date: Thu, 16 Apr 2015 12:42:26 +0900 Subject: Add LZ4F_OBSOLETE_ENUM() to describe obsolete enums - Add LZ4F_OBSOLETE_ENUM() to describe obsolete enums - Add compatible typedefs for obsolete enum types - Remove constant macros --- lib/lz4frame.h | 64 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/lib/lz4frame.h b/lib/lz4frame.h index d1501da..428ad03 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -49,6 +49,14 @@ extern "C" { **************************************/ #include /* size_t */ +#ifndef LZ4F_OBSOLETE_ENUM +# ifndef LZ4F_DISABLE_OBSOLETE_ENUMS +# define LZ4F_OBSOLETE_ENUM(x) ,x +# else +# define LZ4F_OBSOLETE_ENUM(x) +# endif +#endif + /************************************** * Error management @@ -62,25 +70,43 @@ const char* LZ4F_getErrorName(LZ4F_errorCode_t code); /* return error code str /************************************** * Frame compression types * ************************************/ -typedef enum { LZ4F_default=0, LZ4F_max64KB=4, LZ4F_max256KB=5, LZ4F_max1MB=6, LZ4F_max4MB=7 } LZ4F_blockSizeID_t; -typedef enum { LZ4F_blockLinked=0, LZ4F_blockIndependent} LZ4F_blockMode_t; -typedef enum { LZ4F_noContentChecksum=0, LZ4F_contentChecksumEnabled } LZ4F_contentChecksum_t; -typedef enum { LZ4F_frame=0, LZ4F_skippableFrame } LZ4F_frameType_t; - -#ifndef LZ4F_DISABLE_OLD_ENUMS -# define max64KB LZ4F_max64KB -# define max256KB LZ4F_max256KB -# define max1MB LZ4F_max1MB -# define max4MB LZ4F_max4MB -# define blockSizeID_t LZ4F_blockSizeID_t -# define blockLinked LZ4F_blockLinked -# define blockIndependent LZ4F_blockIndependent -# define blockMode_t LZ4F_blockMode_t -# define noContentChecksum LZ4F_noContentChecksum -# define contentChecksumEnabled LZ4F_contentChecksumEnabled -# define contentChecksum_t LZ4F_contentChecksum_t -# define skippableFrame LZ4F_skippableFrame -# define frameType_t LZ4F_frameType_t +typedef enum { + LZ4F_default=0, + LZ4F_max64KB=4, + LZ4F_max256KB=5, + LZ4F_max1MB=6, + LZ4F_max4MB=7 + LZ4F_OBSOLETE_ENUM(max64KB = LZ4F_max64KB) + LZ4F_OBSOLETE_ENUM(max256KB = LZ4F_max256KB) + LZ4F_OBSOLETE_ENUM(max1MB = LZ4F_max1MB) + LZ4F_OBSOLETE_ENUM(max4MB = LZ4F_max4MB) +} LZ4F_blockSizeID_t; + +typedef enum { + LZ4F_blockLinked=0, + LZ4F_blockIndependent + LZ4F_OBSOLETE_ENUM(blockLinked = LZ4F_blockLinked) + LZ4F_OBSOLETE_ENUM(blockIndependent = LZ4F_blockIndependent) +} LZ4F_blockMode_t; + +typedef enum { + LZ4F_noContentChecksum=0, + LZ4F_contentChecksumEnabled + LZ4F_OBSOLETE_ENUM(noContentChecksum = LZ4F_noContentChecksum) + LZ4F_OBSOLETE_ENUM(contentChecksumEnabled = LZ4F_contentChecksumEnabled) +} LZ4F_contentChecksum_t; + +typedef enum { + LZ4F_frame=0, + LZ4F_skippableFrame + LZ4F_OBSOLETE_ENUM(skippableFrame = LZ4F_skippableFrame) +} LZ4F_frameType_t; + +#ifndef LZ4F_DISABLE_OBSOLETE_ENUMS +typedef LZ4F_blockSizeID_t blockSizeID_t; +typedef LZ4F_blockMode_t blockMode_t; +typedef LZ4F_frameType_t frameType_t; +typedef LZ4F_contentChecksum_t contentChecksum_t; #endif typedef struct { -- cgit v0.12 From 13c6e16333a63319ef0def9da6595a3bc7d2915d Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 07:16:48 +0100 Subject: Removed status notification in multiple-files mode --- programs/Makefile | 6 +++--- programs/lz4cli.c | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index fa6b04d..6eec96e 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -193,9 +193,9 @@ test-lz4-frame-concatenation: lz4 datagen test-lz4-multiple: lz4 datagen @echo ---- test multiple files ---- - @./datagen -s1 > tmp1 - @./datagen -s2 -g100K > tmp2 - @./datagen -s3 -g1M > tmp3 + @./datagen -s1 > tmp1 2> $(VOID) + @./datagen -s2 -g100K > tmp2 2> $(VOID) + @./datagen -s3 -g1M > tmp3 2> $(VOID) ./lz4 -f -m tmp* ls -ls tmp* rm tmp1 tmp2 tmp3 diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 8d7d5ca..d77ef5b 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -102,7 +102,7 @@ ***************************************/ #define DISPLAY(...) fprintf(stderr, __VA_ARGS__) #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); } -static unsigned displayLevel = 2; /* 0 : no display ; 1: errors ; 2 : + result + interaction + warnings ; 3 : + progression; 4 : + information */ +static unsigned displayLevel = 2; /* 0 : no display ; 1: errors only ; 2 : downgradable normal ; 3 : non-downgradable normal; 4 : + information */ /************************************** @@ -521,8 +521,9 @@ int main(int argc, char** argv) /* Check if output is defined as console; trigger an error in this case */ if (!strcmp(output_filename,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) badusage(); - /* No warning message in pure pipe mode (stdin + stdout) */ + /* Downgrade notification level in pure pipe mode (stdin + stdout) and multiple file mode */ if (!strcmp(input_filename, stdinmark) && !strcmp(output_filename,stdoutmark) && (displayLevel==2)) displayLevel=1; + if ((multiple_inputs) && (displayLevel==2)) displayLevel=1; /* IO Stream/File */ -- cgit v0.12 From e328d41ef4124870c31cba1fe1f4eed282b8e53e Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 08:51:31 +0100 Subject: minor optimization for small files --- programs/lz4io.c | 91 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 130a1de..ba2a6e8 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -421,7 +421,7 @@ static cRess_t LZ4IO_createCResources(void) /* Allocate Memory */ ress.srcBuffer = malloc(blockSize); ress.srcBufferSize = blockSize; - ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* cover worst case */ + ress.dstBufferSize = LZ4F_compressFrameBound(blockSize, NULL); /* cover worst case */ ress.dstBuffer = malloc(ress.dstBufferSize); if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); @@ -438,7 +438,7 @@ static void LZ4IO_freeCResources(cRess_t ress) } -static int LZ4IO_compressJob(cRess_t ress, const char* srcFileName, const char* dstFileName, int compressionLevel) +static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, const char* dstFileName, int compressionLevel) { unsigned long long filesize = 0; unsigned long long compressedfilesize = 0; @@ -476,44 +476,63 @@ static int LZ4IO_compressJob(cRess_t ress, const char* srcFileName, const char* DISPLAYLEVEL(3, "Warning : cannot determine uncompressed frame content size \n"); } - /* Write Archive Header */ - headerSize = LZ4F_compressBegin(ctx, dstBuffer, dstBufferSize, &prefs); - if (LZ4F_isError(headerSize)) EXM_THROW(32, "File header generation failed : %s", LZ4F_getErrorName(headerSize)); - sizeCheck = fwrite(dstBuffer, 1, headerSize, dstFile); - if (sizeCheck!=headerSize) EXM_THROW(33, "Write error : cannot write header"); - compressedfilesize += headerSize; - /* read first block */ - readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, srcFile); + readSize = fread(srcBuffer, (size_t)1, blockSize, srcFile); filesize += readSize; - /* Main Loop */ - while (readSize>0) + /* single-block file */ + if (readSize < blockSize) { - size_t outSize; - - /* Compress Block */ - outSize = LZ4F_compressUpdate(ctx, dstBuffer, dstBufferSize, srcBuffer, readSize, NULL); - if (LZ4F_isError(outSize)) EXM_THROW(34, "Compression failed : %s", LZ4F_getErrorName(outSize)); - compressedfilesize += outSize; + /* Compress in single pass */ + size_t cSize = LZ4F_compressFrame(dstBuffer, dstBufferSize, srcBuffer, readSize, &prefs); + if (LZ4F_isError(cSize)) EXM_THROW(34, "Compression failed : %s", LZ4F_getErrorName(cSize)); + compressedfilesize += cSize; DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", (unsigned)(filesize>>20), (double)compressedfilesize/filesize*100); /* Write Block */ - sizeCheck = fwrite(dstBuffer, 1, outSize, dstFile); - if (sizeCheck!=outSize) EXM_THROW(35, "Write error : cannot write compressed block"); - - /* Read next block */ - readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, srcFile); - filesize += readSize; + sizeCheck = fwrite(dstBuffer, 1, cSize, dstFile); + if (sizeCheck!=cSize) EXM_THROW(35, "Write error : cannot write compressed block"); } - /* End of Stream mark */ - headerSize = LZ4F_compressEnd(ctx, dstBuffer, dstBufferSize, NULL); - if (LZ4F_isError(headerSize)) EXM_THROW(36, "End of file generation failed : %s", LZ4F_getErrorName(headerSize)); + else + + /* multiple-blocks file */ + { + /* Write Archive Header */ + headerSize = LZ4F_compressBegin(ctx, dstBuffer, dstBufferSize, &prefs); + if (LZ4F_isError(headerSize)) EXM_THROW(32, "File header generation failed : %s", LZ4F_getErrorName(headerSize)); + sizeCheck = fwrite(dstBuffer, 1, headerSize, dstFile); + if (sizeCheck!=headerSize) EXM_THROW(33, "Write error : cannot write header"); + compressedfilesize += headerSize; + + /* Main Loop */ + while (readSize>0) + { + size_t outSize; + + /* Compress Block */ + outSize = LZ4F_compressUpdate(ctx, dstBuffer, dstBufferSize, srcBuffer, readSize, NULL); + if (LZ4F_isError(outSize)) EXM_THROW(34, "Compression failed : %s", LZ4F_getErrorName(outSize)); + compressedfilesize += outSize; + DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", (unsigned)(filesize>>20), (double)compressedfilesize/filesize*100); + + /* Write Block */ + sizeCheck = fwrite(dstBuffer, 1, outSize, dstFile); + if (sizeCheck!=outSize) EXM_THROW(35, "Write error : cannot write compressed block"); + + /* Read next block */ + readSize = fread(srcBuffer, (size_t)1, (size_t)blockSize, srcFile); + filesize += readSize; + } + + /* End of Stream mark */ + headerSize = LZ4F_compressEnd(ctx, dstBuffer, dstBufferSize, NULL); + if (LZ4F_isError(headerSize)) EXM_THROW(36, "End of file generation failed : %s", LZ4F_getErrorName(headerSize)); - sizeCheck = fwrite(dstBuffer, 1, headerSize, dstFile); - if (sizeCheck!=headerSize) EXM_THROW(37, "Write error : cannot write end of stream"); - compressedfilesize += headerSize; + sizeCheck = fwrite(dstBuffer, 1, headerSize, dstFile); + if (sizeCheck!=headerSize) EXM_THROW(37, "Write error : cannot write end of stream"); + compressedfilesize += headerSize; + } /* Release files */ fclose (srcFile); @@ -521,14 +540,10 @@ static int LZ4IO_compressJob(cRess_t ress, const char* srcFileName, const char* /* Final Status */ DISPLAYLEVEL(2, "\r%79s\r", ""); - if (filesize == 0) - { - DISPLAYLEVEL(2, "Empty input\n"); - } - else { DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", - (unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100); + (unsigned long long) filesize, (unsigned long long) compressedfilesize, + (double)compressedfilesize/(filesize + !filesize)*100); /* avoid division by zero */ } return 0; @@ -546,7 +561,7 @@ int LZ4IO_compressFilename(const char* srcFileName, const char* dstFileName, int ress = LZ4IO_createCResources(); /* Compress File */ - issueWithSrcFile += LZ4IO_compressJob(ress, srcFileName, dstFileName, compressionLevel); + issueWithSrcFile += LZ4IO_compressFilename_extRess(ress, srcFileName, dstFileName, compressionLevel); /* Free resources */ LZ4IO_freeCResources(ress); @@ -583,7 +598,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, strcpy(outFileName, inFileNamesTable[i]); strcat(outFileName, suffix); - missing_files += LZ4IO_compressJob(ress, inFileNamesTable[i], outFileName, compressionLevel); + missing_files += LZ4IO_compressFilename_extRess(ress, inFileNamesTable[i], outFileName, compressionLevel); } /* Close & Free */ -- cgit v0.12 From 2cf8a19e9d0b462d20b004e25e6dab79a997372a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 09:57:46 +0100 Subject: minor header refactoring --- lib/lz4frame.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 428ad03..9c5ff37 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -49,14 +49,6 @@ extern "C" { **************************************/ #include /* size_t */ -#ifndef LZ4F_OBSOLETE_ENUM -# ifndef LZ4F_DISABLE_OBSOLETE_ENUMS -# define LZ4F_OBSOLETE_ENUM(x) ,x -# else -# define LZ4F_OBSOLETE_ENUM(x) -# endif -#endif - /************************************** * Error management @@ -70,6 +62,13 @@ const char* LZ4F_getErrorName(LZ4F_errorCode_t code); /* return error code str /************************************** * Frame compression types * ************************************/ +//#define LZ4F_DISABLE_OBSOLETE_ENUMS +#ifndef LZ4F_DISABLE_OBSOLETE_ENUMS +# define LZ4F_OBSOLETE_ENUM(x) ,x +#else +# define LZ4F_OBSOLETE_ENUM(x) +#endif + typedef enum { LZ4F_default=0, LZ4F_max64KB=4, @@ -110,12 +109,12 @@ typedef LZ4F_contentChecksum_t contentChecksum_t; #endif typedef struct { - LZ4F_blockSizeID_t blockSizeID; /* max64KB, max256KB, max1MB, max4MB ; 0 == default */ - LZ4F_blockMode_t blockMode; /* blockLinked, blockIndependent ; 0 == default */ - LZ4F_contentChecksum_t contentChecksumFlag; /* noContentChecksum, contentChecksumEnabled ; 0 == default */ - LZ4F_frameType_t frameType; /* LZ4F_frame, skippableFrame ; 0 == default */ - unsigned long long contentSize; /* Size of uncompressed (original) content ; 0 == unknown */ - unsigned reserved[2]; /* must be zero for forward compatibility */ + LZ4F_blockSizeID_t blockSizeID; /* max64KB, max256KB, max1MB, max4MB ; 0 == default */ + LZ4F_blockMode_t blockMode; /* blockLinked, blockIndependent ; 0 == default */ + LZ4F_contentChecksum_t contentChecksumFlag; /* noContentChecksum, contentChecksumEnabled ; 0 == default */ + LZ4F_frameType_t frameType; /* LZ4F_frame, skippableFrame ; 0 == default */ + unsigned long long contentSize; /* Size of uncompressed (original) content ; 0 == unknown */ + unsigned reserved[2]; /* must be zero for forward compatibility */ } LZ4F_frameInfo_t; typedef struct { @@ -185,7 +184,7 @@ size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* prefsPtr); * Provides the minimum size of Dst buffer given srcSize to handle worst case situations. * Different preferences can produce different results. * prefsPtr is optional : you can provide NULL as argument, all preferences will then be set to cover worst case. - * This function includes frame termination cost (4 bytes, or 8 is frame checksum is enabled) + * This function includes frame termination cost (4 bytes, or 8 if frame checksum is enabled) */ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* cOptPtr); @@ -219,7 +218,7 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t * The result of the function is the number of bytes written into dstBuffer (necessarily >= 4 (endMark), or 8 if optional frame checksum is enabled) * The function outputs an error code if it fails (can be tested using LZ4F_isError()) * The LZ4F_compressOptions_t structure is optional : you can provide NULL as argument. - * A successful call to LZ4F_compressEnd() makes cctx available again for future compression task. + * A successful call to LZ4F_compressEnd() makes cctx available again for next compression task. */ -- cgit v0.12 From 0ed2e7111e944abc1b7dddffd2c2a859e4b07e58 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 12:48:50 +0100 Subject: Static analyzer generates error codes on bug suspicion --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b83d920..a9990df 100644 --- a/Makefile +++ b/Makefile @@ -104,10 +104,10 @@ clangtest: clean $(MAKE) all CC=clang CPPFLAGS="-Werror -Wconversion -Wno-sign-conversion" sanitize: clean - $(MAKE) test CC=clang CPPFLAGS="-g -fsanitize=undefined" FUZZER_TIME="-T1mn" + $(MAKE) test CC=clang CPPFLAGS="-g -fsanitize=undefined" FUZZER_TIME="-T1mn" NB_LOOPS=-i1 staticAnalyze: clean - scan-build -v $(MAKE) all CFLAGS=-g + scan-build --status-bugs -v $(MAKE) all CFLAGS=-g armtest: clean cd lib; $(MAKE) -e all CC=arm-linux-gnueabi-gcc CFLAGS="-O3 -Werror" -- cgit v0.12 From 633c1ca810cb18f9e61f9cd4d90ad104305a0505 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 13:09:34 +0100 Subject: fixed minor leak --- programs/lz4io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/lz4io.c b/programs/lz4io.c index ba2a6e8..258af5b 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -1021,5 +1021,6 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz LZ4IO_freeDResources(ress); free(outFileName); + free(ifnSuffix); return missingFiles + skippedFiles; } -- cgit v0.12 From 2ed9dcc900a8a662a52d11968baf27f61a9bedd3 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 13:18:15 +0100 Subject: fix minor "divide by zero" risk --- programs/lz4io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 258af5b..e2f2801 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -487,7 +487,8 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, size_t cSize = LZ4F_compressFrame(dstBuffer, dstBufferSize, srcBuffer, readSize, &prefs); if (LZ4F_isError(cSize)) EXM_THROW(34, "Compression failed : %s", LZ4F_getErrorName(cSize)); compressedfilesize += cSize; - DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", (unsigned)(filesize>>20), (double)compressedfilesize/filesize*100); + DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", + (unsigned)(filesize>>20), (double)compressedfilesize/(filesize+!filesize)*100); /* avoid division by zero */ /* Write Block */ sizeCheck = fwrite(dstBuffer, 1, cSize, dstFile); -- cgit v0.12 From 9e92bee0443b45efa3de6b71f51863e8d66ead20 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 13:34:03 +0100 Subject: stronger arm tests --- Makefile | 4 ++-- programs/lz4io.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a9990df..88c4016 100644 --- a/Makefile +++ b/Makefile @@ -110,8 +110,8 @@ staticAnalyze: clean scan-build --status-bugs -v $(MAKE) all CFLAGS=-g armtest: clean - cd lib; $(MAKE) -e all CC=arm-linux-gnueabi-gcc CFLAGS="-O3 -Werror" - cd programs; $(MAKE) -e bins CC=arm-linux-gnueabi-gcc CFLAGS="-O3 -Werror" + cd lib; $(MAKE) -e all CC=arm-linux-gnueabi-gcc CPPFLAGS="-Werror" + cd programs; $(MAKE) -e bins CC=arm-linux-gnueabi-gcc CPPFLAGS="-Werror" streaming-examples: cd examples; $(MAKE) -e test diff --git a/programs/lz4io.c b/programs/lz4io.c index e2f2801..e262304 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -289,12 +289,12 @@ static int LZ4IO_getFiles(const char* input_filename, const char* output_filenam fclose(*pfoutput); if (!g_overwrite) { - char ch = 'Y'; + int ch = 'Y'; DISPLAYLEVEL(2, "Warning : %s already exists\n", output_filename); if ((g_displayLevel <= 1) || (*pfinput == stdin)) EXM_THROW(11, "Operation aborted : %s already exists", output_filename); /* No interaction possible */ DISPLAYLEVEL(2, "Overwrite ? (Y/n) : "); - while((ch = (char)getchar()) != '\n' && ch != EOF) /* flush integrated */ + while((ch = getchar()) != '\n' && ch != EOF) /* flush integrated */ if ((ch!='Y') && (ch!='y')) EXM_THROW(12, "No. Operation aborted : %s already exists", output_filename); } } -- cgit v0.12 From bce2eeb9dfbca883003f21681e21df657fac90c4 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 16:27:16 +0100 Subject: Reclassified some notification messages as errors --- programs/lz4io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index e262304..7d4fc55 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -269,7 +269,7 @@ static int LZ4IO_getFiles(const char* input_filename, const char* output_filenam if ( *pfinput==0 ) { - DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", input_filename); + DISPLAYLEVEL(1, "Unable to access file for processing: %s\n", input_filename); return 1; } @@ -1010,7 +1010,7 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz if (ofnSize <= ifnSize-suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); } if (ifnSize <= suffixSize || strcmp(ifnSuffix, suffix) != 0) { - DISPLAYLEVEL(2, "File extension doesn't match expected LZ4_EXTENSION (%4s); will not process file: %s\n", suffix, inFileNamesTable[i]); + DISPLAYLEVEL(1, "File extension doesn't match expected LZ4_EXTENSION (%4s); will not process file: %s\n", suffix, inFileNamesTable[i]); skippedFiles++; continue; } -- cgit v0.12 From 7644bee6435f05e0954b3da5f457550614a199b7 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 16 Apr 2015 16:45:58 +0100 Subject: test error message in multiple files mode --- programs/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/Makefile b/programs/Makefile index 6eec96e..f61d708 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -201,6 +201,7 @@ test-lz4-multiple: lz4 datagen rm tmp1 tmp2 tmp3 ./lz4 -df -m *.lz4 ls -ls tmp* + ./lz4 -f -m tmp1 notHere tmp2; echo $$? @rm tmp* test-lz4: lz4 datagen test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation -- cgit v0.12 From 9fd4f1f9f780f1be38ad6695d62a9ba2ea426d6d Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 17 Apr 2015 19:42:07 +0100 Subject: Sparse file support is now enabled by default --- programs/lz4.1 | 2 +- programs/lz4cli.c | 2 +- programs/lz4io.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/lz4.1 b/programs/lz4.1 index a9b5195..a79fed3 100644 --- a/programs/lz4.1 +++ b/programs/lz4.1 @@ -185,7 +185,7 @@ independently, and the resulting name of the compressed file will be hence for a file. It won't work with unknown source size, such as stdin or pipe. .TP .B \--[no-]sparse - enable sparse file (default:disabled)(experimental) + sparse file support (default:enabled) .TP .B \-l use Legacy format (useful for Linux Kernel compression) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index d77ef5b..da18169 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -175,7 +175,7 @@ static int usage_advanced(void) /* DISPLAY( " -BX : enable block checksum (default:disabled)\n"); *//* Option currently inactive */ DISPLAY( "--no-frame-crc : disable stream checksum (default:enabled)\n"); DISPLAY( "--content-size : compressed frame includes original size (default:not present)\n"); - DISPLAY( "--sparse : enable sparse file (default:disabled)(experimental)\n"); + DISPLAY( "--[no-]sparse : sparse file support (default:enabled)\n"); DISPLAY( "Benchmark arguments :\n"); DISPLAY( " -b : benchmark file(s)\n"); DISPLAY( " -i# : iteration loops [1-9](default : 3), benchmark mode only\n"); diff --git a/programs/lz4io.c b/programs/lz4io.c index 7d4fc55..e0c69d8 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -131,7 +131,7 @@ static int g_blockSizeId = LZ4IO_BLOCKSIZEID_DEFAULT; static int g_blockChecksum = 0; static int g_streamChecksum = 1; static int g_blockIndependence = 1; -static int g_sparseFileSupport = 0; +static int g_sparseFileSupport = 1; static int g_contentSizeFlag = 0; static const int minBlockSizeID = 4; -- cgit v0.12 From 47c304039954d73cea018fbd6b4eebc05877d3fc Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 18 Apr 2015 12:44:38 +0100 Subject: added --no-sparse test --- programs/Makefile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index f61d708..910516f 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -151,15 +151,18 @@ test-travis: $(TRAVIS_TARGET) test-lz4-sparse: lz4 datagen @echo ---- test sparse file support ---- - ./datagen -g50M -P100 | ./lz4 -B4D | ./lz4 -dv --sparse > tmpB4 - ./datagen -g50M -P100 | ./lz4 -B5D | ./lz4 -dv --sparse > tmpB5 - ./datagen -g50M -P100 | ./lz4 -B6D | ./lz4 -dv --sparse > tmpB6 - ./datagen -g50M -P100 | ./lz4 -B7D | ./lz4 -dv --sparse > tmpB7 + ./datagen -g5M -P100 > tmpSrc + ./lz4 -B4D tmpSrc | ./lz4 -dv --sparse > tmpB4 + diff -s tmpSrc tmpB4 + ./lz4 -B5D tmpSrc | ./lz4 -dv --sparse > tmpB5 + diff -s tmpSrc tmpB5 + ./lz4 -B6D tmpSrc | ./lz4 -dv --sparse > tmpB6 + diff -s tmpSrc tmpB6 + ./lz4 -B7D tmpSrc | ./lz4 -dv --sparse > tmpB7 + diff -s tmpSrc tmpB7 + ./lz4 tmpSrc | ./lz4 -dv --no-sparse > tmpNoSparse + diff -s tmpSrc tmpNoSparse ls -ls tmp* - ./datagen -g50M -P100 | diff -s - tmpB4 - ./datagen -g50M -P100 | diff -s - tmpB5 - ./datagen -g50M -P100 | diff -s - tmpB6 - ./datagen -g50M -P100 | diff -s - tmpB7 ./datagen -s1 -g1200007 -P100 | ./lz4 | ./lz4 -dv --sparse > tmpOdd # Odd size file (to not finish on an exact nb of blocks) ./datagen -s1 -g1200007 -P100 | diff -s - tmpOdd ls -ls tmpOdd -- cgit v0.12 From 409f816267b00e2307fabc59cc6ddffcc605a1ec Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 19 Apr 2015 15:23:53 +0100 Subject: Updated LZ4F_getFrameInfo() behavior, related to uncomplete frame header decoding attempts --- lib/lz4frame.c | 82 ++++++++++++++++++++++++++++----------------------- lib/lz4frame.h | 20 ++++++------- lib/lz4frame_static.h | 16 +++++----- programs/frametest.c | 31 +++++++++++++++++++ 4 files changed, 94 insertions(+), 55 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 6f53897..7fc1314 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -100,10 +100,11 @@ typedef unsigned long long U64; #define LZ4F_MAGIC_SKIPPABLE_START 0x184D2A50U #define LZ4F_MAGICNUMBER 0x184D2204U #define LZ4F_BLOCKUNCOMPRESSED_FLAG 0x80000000U -#define LZ4F_MAXHEADERFRAME_SIZE 15 #define LZ4F_BLOCKSIZEID_DEFAULT LZ4F_max64KB -static const size_t minFHSize = 5; +static const size_t minFHSize = 7; +static const size_t maxFHSize = 15; +static const size_t BHSize = 4; static const U32 minHClevel = 3; /************************************** @@ -263,7 +264,7 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere prefs.frameInfo.blockSizeID = LZ4F_optimalBSID(prefs.frameInfo.blockSizeID, srcSize); prefs.autoFlush = 1; - headerSize = 15; /* header size, including magic number and frame content size*/ + headerSize = maxFHSize; /* header size, including magic number and frame content size*/ streamSize = LZ4F_compressBound(srcSize, &prefs); return headerSize + streamSize; @@ -398,7 +399,7 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds BYTE* headerStart; size_t requiredBuffSize; - if (dstMaxSize < LZ4F_MAXHEADERFRAME_SIZE) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; + if (dstMaxSize < maxFHSize) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; if (cctxPtr->cStage != 0) return (size_t)-LZ4F_ERROR_GENERIC; memset(&prefNull, 0, sizeof(prefNull)); if (preferencesPtr == NULL) preferencesPtr = &prefNull; @@ -789,8 +790,9 @@ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t LZ4F_ typedef enum { dstage_getHeader=0, dstage_storeHeader, dstage_getCBlockSize, dstage_storeCBlockSize, dstage_copyDirect, - dstage_getCBlock, dstage_storeCBlock, dstage_decodeCBlock, - dstage_decodeCBlock_intoDst, dstage_decodeCBlock_intoTmp, dstage_flushOut, + dstage_getCBlock, dstage_storeCBlock, + dstage_decodeCBlock, dstage_decodeCBlock_intoDst, + dstage_decodeCBlock_intoTmp, dstage_flushOut, dstage_getSuffix, dstage_storeSuffix, dstage_getSFrameSize, dstage_storeSFrameSize, dstage_skipSkippable @@ -802,6 +804,7 @@ typedef enum { dstage_getHeader=0, dstage_storeHeader, or an error code (testable with LZ4F_isError()) output : set internal values of dctx, such as dctxPtr->frameInfo and dctxPtr->dStage. + input : srcVoidPtr points at the **beginning of the frame** */ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVoidPtr, size_t srcSize) { @@ -812,10 +815,10 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo const BYTE* srcPtr = (const BYTE*)srcVoidPtr; /* need to decode header to get frameInfo */ - if (srcSize < minFHSize) return (size_t)-LZ4F_ERROR_GENERIC; /* minimal header size */ + if (srcSize < minFHSize) return (size_t)-LZ4F_ERROR_frameHeader_incomplete; /* minimal frame header size */ memset(&(dctxPtr->frameInfo), 0, sizeof(dctxPtr->frameInfo)); - /* skippable frames */ + /* special case : skippable frames */ if ((LZ4F_readLE32(srcPtr) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) { dctxPtr->frameInfo.frameType = LZ4F_skippableFrame; @@ -846,10 +849,11 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo contentChecksumFlag = (FLG>>2) & _1BIT; /* Frame Header Size */ - frameHeaderSize = contentSizeFlag ? 15 : 7; + frameHeaderSize = contentSizeFlag ? maxFHSize : minFHSize; if (srcSize < frameHeaderSize) { + /* not enough input to fully decode frame header */ if (srcPtr != dctxPtr->header) memcpy(dctxPtr->header, srcPtr, srcSize); dctxPtr->tmpInSize = srcSize; @@ -920,28 +924,32 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo * The function result is an hint of the better srcSize to use for next call to LZ4F_decompress, * or an error code which can be tested using LZ4F_isError(). */ -LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t decompressionContext, LZ4F_frameInfo_t* frameInfoPtr, const void* srcBuffer, size_t* srcSizePtr) +LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t dCtx, LZ4F_frameInfo_t* frameInfoPtr, + const void* srcBuffer, size_t* srcSizePtr) { - LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)decompressionContext; + LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)dCtx; - if (dctxPtr->dStage == dstage_getHeader) + if (dctxPtr->dStage > dstage_storeHeader) /* note : requires dstage_* header related to be at beginning of enum */ { - size_t frameHeaderSize = LZ4F_decodeHeader(dctxPtr, srcBuffer, *srcSizePtr); - if (LZ4F_isError(frameHeaderSize)) return frameHeaderSize; - *srcSizePtr = frameHeaderSize; /* nb Bytes consumed */ - *frameInfoPtr = dctxPtr->frameInfo; /* copy into */ - dctxPtr->srcExpect = NULL; - return 4; /* nextSrcSizeHint : 4 == block header size */ + size_t o=0, i=0; + /* frameInfo already decoded */ + *srcSizePtr = 0; + *frameInfoPtr = dctxPtr->frameInfo; + return LZ4F_decompress(dCtx, NULL, &o, NULL, &i, NULL); + } + else + { + size_t o=0; + size_t nextSrcSize = LZ4F_decompress(dCtx, NULL, &o, srcBuffer, srcSizePtr, NULL); + if (dctxPtr->dStage <= dstage_storeHeader) /* note : requires dstage_* header related to be at beginning of enum */ + return (size_t)-LZ4F_ERROR_frameHeader_incomplete; + *frameInfoPtr = dctxPtr->frameInfo; + return nextSrcSize; } - - /* frameInfo already decoded */ - *srcSizePtr = 0; - *frameInfoPtr = dctxPtr->frameInfo; - return 0; } -/* redirector, with common prototype */ +/* trivial redirector, for common prototype */ static int LZ4F_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize) { (void)dictStart; (void)dictSize; @@ -1071,7 +1079,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, case dstage_getHeader: { - if (srcEnd-srcPtr >= 7) + if ((size_t)(srcEnd-srcPtr) >= maxFHSize) /* enough to decode - shortcut */ { LZ4F_errorCode_t errorCode = LZ4F_decodeHeader(dctxPtr, srcPtr, srcEnd-srcPtr); if (LZ4F_isError(errorCode)) return errorCode; @@ -1079,7 +1087,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, break; } dctxPtr->tmpInSize = 0; - dctxPtr->tmpInTarget = 7; + dctxPtr->tmpInTarget = minFHSize; /* minimum to attempt decode */ dctxPtr->dStage = dstage_storeHeader; } @@ -1092,7 +1100,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, srcPtr += sizeToCopy; if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) { - nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + 4; + nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + BHSize; /* rest of header + nextBlockHeader */ doAnotherStage = 0; /* not enough src data, ask for some more */ break; } @@ -1105,10 +1113,10 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, case dstage_getCBlockSize: { - if ((srcEnd - srcPtr) >= 4) + if ((size_t)(srcEnd - srcPtr) >= BHSize) { selectedIn = srcPtr; - srcPtr += 4; + srcPtr += BHSize; } else { @@ -1121,15 +1129,15 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, if (dctxPtr->dStage == dstage_storeCBlockSize) case dstage_storeCBlockSize: { - size_t sizeToCopy = 4 - dctxPtr->tmpInSize; + size_t sizeToCopy = BHSize - dctxPtr->tmpInSize; if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr; memcpy(dctxPtr->tmpIn + dctxPtr->tmpInSize, srcPtr, sizeToCopy); srcPtr += sizeToCopy; dctxPtr->tmpInSize += sizeToCopy; - if (dctxPtr->tmpInSize < 4) /* not enough input to get full cBlockSize; wait for more */ + if (dctxPtr->tmpInSize < BHSize) /* not enough input to get full cBlockSize; wait for more */ { - nextSrcSizeHint = 4 - dctxPtr->tmpInSize; - doAnotherStage=0; + nextSrcSizeHint = BHSize - dctxPtr->tmpInSize; + doAnotherStage = 0; break; } selectedIn = dctxPtr->tmpIn; @@ -1153,7 +1161,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, dctxPtr->dStage = dstage_getCBlock; if (dstPtr==dstEnd) { - nextSrcSizeHint = nextCBlockSize + 4; + nextSrcSizeHint = nextCBlockSize + BHSize; doAnotherStage = 0; } break; @@ -1180,7 +1188,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, break; } dctxPtr->tmpInTarget -= sizeToCopy; /* still need to copy more */ - nextSrcSizeHint = dctxPtr->tmpInTarget + 4; + nextSrcSizeHint = dctxPtr->tmpInTarget + BHSize; doAnotherStage = 0; break; } @@ -1208,7 +1216,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, srcPtr += sizeToCopy; if (dctxPtr->tmpInSize < dctxPtr->tmpInTarget) /* need more input */ { - nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + 4; + nextSrcSizeHint = (dctxPtr->tmpInTarget - dctxPtr->tmpInSize) + BHSize; doAnotherStage=0; break; } @@ -1311,7 +1319,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, dctxPtr->dStage = dstage_getCBlockSize; break; } - nextSrcSizeHint = 4; + nextSrcSizeHint = BHSize; doAnotherStage = 0; /* still some data to flush */ break; } diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 9c5ff37..e871046 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -33,7 +33,7 @@ */ /* LZ4F is a stand-alone API to create LZ4-compressed frames - * fully conformant to specification v1.4.1. + * fully conformant to specification v1.5.1. * All related operations, including memory management, are handled by the library. * You don't need lz4.h when using lz4frame.h. * */ @@ -254,18 +254,16 @@ size_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t dctx, LZ4F_frameInfo_t* frameInfoPtr, const void* srcBuffer, size_t* srcSizePtr); /* LZ4F_getFrameInfo() - * This function decodes frame header information, such as blockSize. - * It is optional : you could start by calling directly LZ4F_decompress() instead. - * The objective is to extract header information without starting decompression, typically for allocation purposes. - * The function will work only if srcBuffer points at the beginning of the frame, - * and *srcSizePtr is large enough to decode the whole header (typically, between 7 & 15 bytes). - * The result is copied into an LZ4F_frameInfo_t structure, which is pointed by frameInfoPtr, and must be already allocated. - * LZ4F_getFrameInfo() can also be used *after* starting decompression, on a valid LZ4F_decompressionContext_t. + * This function decodes frame header information (such as max blockSize, frame checksum, etc.). + * Its usage is optional : you can start by calling directly LZ4F_decompress() instead. + * The objective is to extract frame header information, typically for allocation purposes. + * LZ4F_getFrameInfo() can also be used anytime *after* starting decompression, on any valid LZ4F_decompressionContext_t. + * The result is *copied* into an existing LZ4F_frameInfo_t structure which must be already allocated. * The number of bytes read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value). - * It is basically the frame header size. - * You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr) * The function result is an hint of how many srcSize bytes LZ4F_decompress() expects for next call, - * or an error code which can be tested using LZ4F_isError(). + * or an error code which can be tested using LZ4F_isError() + * (typically, when there is not enough src bytes to fully decode the frame header) + * You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr) */ size_t LZ4F_decompress(LZ4F_decompressionContext_t dctx, diff --git a/lib/lz4frame_static.h b/lib/lz4frame_static.h index 25afed4..0d90975 100644 --- a/lib/lz4frame_static.h +++ b/lib/lz4frame_static.h @@ -40,10 +40,18 @@ extern "C" { #endif /* lz4frame_static.h should be used solely in the context of static linking. + * It contains definitions which may still change overtime. + * Never use it in the context of DLL linking. * */ /************************************** +* Includes +**************************************/ +#include "lz4frame.h" + + +/************************************** * Error management * ************************************/ #define LZ4F_LIST_ERRORS(ITEM) \ @@ -53,7 +61,7 @@ extern "C" { ITEM(ERROR_headerVersion_wrong) ITEM(ERROR_blockChecksum_unsupported) ITEM(ERROR_reservedFlag_set) \ ITEM(ERROR_allocation_failed) \ ITEM(ERROR_srcSize_tooLarge) ITEM(ERROR_dstMaxSize_tooSmall) \ - ITEM(ERROR_frameType_unknown) ITEM(ERROR_frameSize_wrong) \ + ITEM(ERROR_frameHeader_incomplete) ITEM(ERROR_frameType_unknown) ITEM(ERROR_frameSize_wrong) \ ITEM(ERROR_srcPtr_wrong) \ ITEM(ERROR_decompressionFailed) \ ITEM(ERROR_headerChecksum_invalid) ITEM(ERROR_contentChecksum_invalid) \ @@ -68,12 +76,6 @@ extern "C" { typedef enum { LZ4F_LIST_ERRORS(LZ4F_GENERATE_ENUM) } LZ4F_errorCodes; /* enum is exposed, to handle specific errors; compare function result to -enum value */ -/************************************** - Includes -**************************************/ -#include "lz4frame.h" - - #if defined (__cplusplus) } #endif diff --git a/programs/frametest.c b/programs/frametest.c index 6adf408..ed131d2 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -277,6 +277,37 @@ int basicTests(U32 seed, double compressibility) if (crcDest != crcOrig) goto _output_error; DISPLAYLEVEL(3, "Regenerated %i bytes \n", (int)decodedBufferSize); + DISPLAYLEVEL(4, "Reusing decompression context \n"); + { + size_t oSize = 0; + size_t iSize = 0; + LZ4F_frameInfo_t fi; + + DISPLAYLEVEL(3, "Start by feeding 0 bytes, to get next input size : "); + errorCode = LZ4F_decompress(dCtx, NULL, &oSize, ip, &iSize, NULL); + if (LZ4F_isError(errorCode)) goto _output_error; + DISPLAYLEVEL(3, " %u \n", (unsigned)errorCode); + + DISPLAYLEVEL(3, "get FrameInfo on null input : "); + errorCode = LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize); + if (errorCode != (size_t)-LZ4F_ERROR_frameHeader_incomplete) goto _output_error; + DISPLAYLEVEL(3, " correctly failed : %s \n", LZ4F_getErrorName(errorCode)); + + DISPLAYLEVEL(3, "get FrameInfo on not enough input : "); + iSize = 6; + errorCode = LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize); + if (errorCode != (size_t)-LZ4F_ERROR_frameHeader_incomplete) goto _output_error; + DISPLAYLEVEL(3, " correctly failed : %s \n", LZ4F_getErrorName(errorCode)); + ip += iSize; + + DISPLAYLEVEL(3, "get FrameInfo on enough input : "); + iSize = 15 - iSize; + errorCode = LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize); + if (LZ4F_isError(errorCode)) goto _output_error; + DISPLAYLEVEL(3, " correctly decoded \n"); + ip += iSize; + } + DISPLAYLEVEL(3, "Byte after byte : \n"); while (ip < iend) { -- cgit v0.12 From 197982ec6cf449734f78d849ed4a845e075b2cf4 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 20 Apr 2015 09:24:25 +0100 Subject: Fixed unfinished frame (issue #75) --- NEWS | 8 ++++++-- programs/Makefile | 8 +++++++- programs/frametest.c | 14 ++++++++++++++ programs/lz4io.c | 21 +++++++++++++-------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 462a23b..e797ff7 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,13 @@ r129: +New : LZ4 CLI improved performance when compressing/decompressing multiple files (#86, kind contribution from Kyle J. Harper & Takayuki Matsuoka) Added : LZ4_compress_fast() -Changed: New compression functions LZ4_compress_safe() - Suggested by Evan Nemerson & Takayuki Matsuoka +Changed: Sparse file support enabled by default +Changed: New function names LZ4_compress_safe() - Suggested by Evan Nemerson & Takayuki Matsuoka +Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Greg Slazinski & Evan Nemerson +Changed: Enums converted to LZ4F_ namespace convention - by Takayuki Matsuoka Added : AppVeyor CI environment, for Visual tests - Suggested by Takayuki Matsuoka -Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Greg Slazinski, Evan Nemerson & Takayuki Matsuoka Modified:Obsolete functions generate warnings - Suggested by Evan Nemerson & Takayuki Matsuoka +Fixed : Bug #75 (unfinished stream), reported by Yongwoon Cho Updated: Documentation converted to MarkDown r128: diff --git a/programs/Makefile b/programs/Makefile index 910516f..b0e30d8 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -207,7 +207,13 @@ test-lz4-multiple: lz4 datagen ./lz4 -f -m tmp1 notHere tmp2; echo $$? @rm tmp* -test-lz4: lz4 datagen test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation +# test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation +test-lz4: lz4 datagen + @echo ---- test erroneous data ---- + ./datagen -s1 | ./lz4 -vf - tmp + tmpSize= $(stat -c%s "tmp") + echo "Size of tmp = $tmpSize bytes." + rm tmp* @echo ---- test lz4 basic compression/decompression ---- ./datagen -g0 | ./lz4 -v | ./lz4 -t ./datagen -g16KB | ./lz4 -9 | ./lz4 -t diff --git a/programs/frametest.c b/programs/frametest.c index ed131d2..237fd4a 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -279,6 +279,20 @@ int basicTests(U32 seed, double compressibility) DISPLAYLEVEL(4, "Reusing decompression context \n"); { + size_t iSize = compressedBufferSize - 4; + DISPLAYLEVEL(3, "Missing last 4 bytes : "); + errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, compressedBuffer, &iSize, NULL); + if (LZ4F_isError(errorCode)) goto _output_error; + if (!errorCode) goto _output_error; + DISPLAYLEVEL(3, "indeed, request %u bytes \n", (unsigned)errorCode); + iSize = errorCode; + errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, compressedBuffer, &iSize, NULL); + if (errorCode != 0) goto _output_error; + crcDest = XXH64(decodedBuffer, COMPRESSIBLE_NOISE_LENGTH, 1); + if (crcDest != crcOrig) goto _output_error; + } + + { size_t oSize = 0; size_t iSize = 0; LZ4F_frameInfo_t fi; diff --git a/programs/lz4io.c b/programs/lz4io.c index e0c69d8..cbf366b 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -807,7 +807,7 @@ static void LZ4IO_freeDResources(dRess_t ress) static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE* dstFile) { unsigned long long filesize = 0; - LZ4F_errorCode_t errorCode; + LZ4F_errorCode_t nextToLoad; unsigned storedSkips = 0; /* Init feed with magic number (already consumed from FILE* sFile) */ @@ -815,8 +815,8 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE size_t inSize = MAGICNUMBER_SIZE; size_t outSize= 0; LZ4IO_writeLE32(ress.srcBuffer, LZ4IO_MAGICNUMBER); - errorCode = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &outSize, ress.srcBuffer, &inSize, NULL); - if (LZ4F_isError(errorCode)) EXM_THROW(62, "Header error : %s", LZ4F_getErrorName(errorCode)); + nextToLoad = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &outSize, ress.srcBuffer, &inSize, NULL); + if (LZ4F_isError(nextToLoad)) EXM_THROW(62, "Header error : %s", LZ4F_getErrorName(nextToLoad)); } /* Main Loop */ @@ -824,18 +824,20 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE { size_t readSize; size_t pos = 0; + size_t decodedBytes = ress.dstBufferSize; /* Read input */ readSize = fread(ress.srcBuffer, 1, ress.srcBufferSize, srcFile); - if (!readSize) break; /* empty file or stream */ + if (!readSize) + break; /* empty file or stream */ - while (pos < readSize) + while (nextToLoad && ((pos < readSize) || (decodedBytes == ress.dstBufferSize))) /* still to read, or still to flush */ { /* Decode Input (at least partially) */ size_t remaining = readSize - pos; - size_t decodedBytes = ress.dstBufferSize; - errorCode = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &decodedBytes, (char*)(ress.srcBuffer)+pos, &remaining, NULL); - if (LZ4F_isError(errorCode)) EXM_THROW(66, "Decompression error : %s", LZ4F_getErrorName(errorCode)); + decodedBytes = ress.dstBufferSize; + nextToLoad = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &decodedBytes, (char*)(ress.srcBuffer)+pos, &remaining, NULL); + if (LZ4F_isError(nextToLoad)) EXM_THROW(66, "Decompression error : %s", LZ4F_getErrorName(nextToLoad)); pos += remaining; if (decodedBytes) @@ -850,6 +852,9 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE LZ4IO_fwriteSparseEnd(dstFile, storedSkips); + if (nextToLoad!=0) + EXM_THROW(67, "Unfinished stream"); + return filesize; } -- cgit v0.12 From c035b7a99a6057b249718e2f0d163f0f1dfe05dc Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 20 Apr 2015 09:26:16 +0100 Subject: Restored make-lz4 --- programs/Makefile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index b0e30d8..910516f 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -207,13 +207,7 @@ test-lz4-multiple: lz4 datagen ./lz4 -f -m tmp1 notHere tmp2; echo $$? @rm tmp* -# test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation -test-lz4: lz4 datagen - @echo ---- test erroneous data ---- - ./datagen -s1 | ./lz4 -vf - tmp - tmpSize= $(stat -c%s "tmp") - echo "Size of tmp = $tmpSize bytes." - rm tmp* +test-lz4: lz4 datagen test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation @echo ---- test lz4 basic compression/decompression ---- ./datagen -g0 | ./lz4 -v | ./lz4 -t ./datagen -g16KB | ./lz4 -9 | ./lz4 -t -- cgit v0.12 From e18aa907985da9ccbeb1684517d0f8e77e189984 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 20 Apr 2015 09:51:00 +0100 Subject: Fixed frametest --- programs/frametest.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/programs/frametest.c b/programs/frametest.c index 237fd4a..fedb78d 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -280,13 +280,15 @@ int basicTests(U32 seed, double compressibility) DISPLAYLEVEL(4, "Reusing decompression context \n"); { size_t iSize = compressedBufferSize - 4; + const BYTE* cBuff = (const BYTE*) compressedBuffer; DISPLAYLEVEL(3, "Missing last 4 bytes : "); - errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, compressedBuffer, &iSize, NULL); + errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, cBuff, &iSize, NULL); if (LZ4F_isError(errorCode)) goto _output_error; if (!errorCode) goto _output_error; DISPLAYLEVEL(3, "indeed, request %u bytes \n", (unsigned)errorCode); + cBuff += iSize; iSize = errorCode; - errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, compressedBuffer, &iSize, NULL); + errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, cBuff, &iSize, NULL); if (errorCode != 0) goto _output_error; crcDest = XXH64(decodedBuffer, COMPRESSIBLE_NOISE_LENGTH, 1); if (crcDest != crcOrig) goto _output_error; @@ -327,7 +329,6 @@ int basicTests(U32 seed, double compressibility) { size_t oSize = oend-op; size_t iSize = 1; - //DISPLAY("%7i \n", (int)(ip-(BYTE*)compressedBuffer)); errorCode = LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, NULL); if (LZ4F_isError(errorCode)) goto _output_error; op += oSize; @@ -335,7 +336,7 @@ int basicTests(U32 seed, double compressibility) } crcDest = XXH64(decodedBuffer, COMPRESSIBLE_NOISE_LENGTH, 1); if (crcDest != crcOrig) goto _output_error; - DISPLAYLEVEL(3, "Regenerated %i bytes \n", (int)decodedBufferSize); + DISPLAYLEVEL(3, "Regenerated %u/%u bytes \n", (unsigned)(op-(BYTE*)decodedBuffer), COMPRESSIBLE_NOISE_LENGTH); errorCode = LZ4F_freeDecompressionContext(dCtx); if (LZ4F_isError(errorCode)) goto _output_error; -- cgit v0.12 From cbcdd88ccb97632015cf3732b46f8800e62e337b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 20 Apr 2015 10:05:54 +0100 Subject: Fixed frame concatenation --- programs/lz4io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index cbf366b..40bdbb7 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -820,18 +820,19 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE } /* Main Loop */ - for (;;) + for (;nextToLoad;) { size_t readSize; size_t pos = 0; size_t decodedBytes = ress.dstBufferSize; /* Read input */ - readSize = fread(ress.srcBuffer, 1, ress.srcBufferSize, srcFile); + if (nextToLoad > ress.srcBufferSize) nextToLoad = ress.srcBufferSize; + readSize = fread(ress.srcBuffer, 1, nextToLoad, srcFile); if (!readSize) break; /* empty file or stream */ - while (nextToLoad && ((pos < readSize) || (decodedBytes == ress.dstBufferSize))) /* still to read, or still to flush */ + while ((pos < readSize) || (decodedBytes == ress.dstBufferSize)) /* still to read, or still to flush */ { /* Decode Input (at least partially) */ size_t remaining = readSize - pos; @@ -839,6 +840,7 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE nextToLoad = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &decodedBytes, (char*)(ress.srcBuffer)+pos, &remaining, NULL); if (LZ4F_isError(nextToLoad)) EXM_THROW(66, "Decompression error : %s", LZ4F_getErrorName(nextToLoad)); pos += remaining; + if (!nextToLoad) break; if (decodedBytes) { -- cgit v0.12 From a01e10dbdc58ae3bcef3348c6b196fc733b942b7 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 20 Apr 2015 12:12:02 +0100 Subject: Changed LZ4F compressionLevel from unsigned to signed, in anticipation for LZ4_compress_fast() integration. --- lib/lz4frame.c | 12 ++++++------ lib/lz4frame.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 7fc1314..eb38390 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -105,7 +105,7 @@ typedef unsigned long long U64; static const size_t minFHSize = 7; static const size_t maxFHSize = 15; static const size_t BHSize = 4; -static const U32 minHClevel = 3; +static const int minHClevel = 3; /************************************** * Structures and local types @@ -306,7 +306,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf if (prefs.frameInfo.contentSize != 0) prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ - if (prefs.compressionLevel < minHClevel) + if (prefs.compressionLevel < (int)minHClevel) { cctxI.lz4CtxPtr = &lz4ctx; cctxI.lz4CtxLevel = 1; @@ -334,7 +334,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; - if (prefs.compressionLevel >= minHClevel) /* no allocation necessary with lz4 fast */ + if (prefs.compressionLevel >= (int)minHClevel) /* no allocation necessary with lz4 fast */ FREEMEM(cctxI.lz4CtxPtr); return (dstPtr - dstStart); @@ -407,11 +407,11 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds /* ctx Management */ { - U32 tableID = cctxPtr->prefs.compressionLevelprefs.compressionLevel < minHClevel) ? 1 : 2; /* 0:nothing ; 1:LZ4 table ; 2:HC tables */ if (cctxPtr->lz4CtxLevel < tableID) { FREEMEM(cctxPtr->lz4CtxPtr); - if (cctxPtr->prefs.compressionLevelprefs.compressionLevel < minHClevel) cctxPtr->lz4CtxPtr = (void*)LZ4_createStream(); else cctxPtr->lz4CtxPtr = (void*)LZ4_createStreamHC(); @@ -531,7 +531,7 @@ static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char return LZ4_compressHC_limitedOutput_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize); } -static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, U32 level) +static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int level) { if (level < minHClevel) { diff --git a/lib/lz4frame.h b/lib/lz4frame.h index e871046..85ebce3 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -119,9 +119,9 @@ typedef struct { typedef struct { LZ4F_frameInfo_t frameInfo; - unsigned compressionLevel; /* 0 == default (fast mode); values above 16 count as 16 */ - unsigned autoFlush; /* 1 == always flush (reduce need for tmp buffer) */ - unsigned reserved[4]; /* must be zero for forward compatibility */ + int compressionLevel; /* 0 == default (fast mode); values above 16 count as 16; values below 0 count as 0 */ + unsigned autoFlush; /* 1 == always flush (reduce need for tmp buffer) */ + unsigned reserved[4]; /* must be zero for forward compatibility */ } LZ4F_preferences_t; -- cgit v0.12 From 72e679438f9ead31e671e0738b7730f846ebde70 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 20 Apr 2015 12:23:33 +0100 Subject: Updated LZ4F_freeDecompressionContext(), to provide stage hint as result --- lib/lz4frame.c | 4 +++- lib/lz4frame.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index eb38390..a70dbaf 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -772,14 +772,16 @@ LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_decompressionContext_t* LZ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t LZ4F_decompressionContext) { + LZ4F_errorCode_t result = LZ4F_OK_NoError; LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)LZ4F_decompressionContext; if (dctxPtr != NULL) /* can accept NULL input, like free() */ { + result = (LZ4F_errorCode_t)dctxPtr->dStage; FREEMEM(dctxPtr->tmpIn); FREEMEM(dctxPtr->tmpOutBuffer); FREEMEM(dctxPtr); } - return LZ4F_OK_NoError; + return result; } diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 85ebce3..b5ba2fb 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -245,6 +245,8 @@ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t dctx) * The function will provide a pointer to a fully allocated and initialized LZ4F_decompressionContext_t object. * The result is an errorCode, which can be tested using LZ4F_isError(). * dctx memory can be released using LZ4F_freeDecompressionContext(); + * The result of LZ4F_freeDecompressionContext() is indicative of the current state of decompressionContext when being released. + * That is, it should be == 0 if decompression has been completed fully and correctly. */ -- cgit v0.12 From f11afafe234ea45a6d80f8b21df1d603ace4e025 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 21 Apr 2015 18:31:35 +0100 Subject: Removed LZ4_compress() (obsolete) from lz4 --- lib/lz4.c | 2 +- lib/lz4.h | 2 +- programs/bench.c | 10 +++++----- programs/lz4io.c | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 53cd4a9..490f9ce 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -685,7 +685,7 @@ int LZ4_compress_safe(const char* source, char* dest, int inputSize, int maxOutp #if (HEAPMODE) void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* malloc-calloc aligned on 8-bytes boundaries */ #else - U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ + U64 ctx[LZ4_STREAMSIZE_U64]; /* Ensure data is aligned on 8-bytes boundaries */ #endif int result = LZ4_compress_safe_extState(ctx, source, dest, inputSize, maxOutputSize); diff --git a/lib/lz4.h b/lib/lz4.h index 98296e9..cf06a8e 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -302,7 +302,7 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS #endif // LZ4_DEPRECATE_WARNING_DEFBLOCK /* Obsolete compression functions */ -/* These functions are planned to generate warnings by r131 approximately */ +/* These functions are planned to start generate warnings by r131 approximately */ int LZ4_compress (const char* source, char* dest, int sourceSize); int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); diff --git a/programs/bench.c b/programs/bench.c index d3b060c..384a425 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -58,9 +58,9 @@ #include "lz4.h" #define COMPRESSOR0 LZ4_compress_local -static int LZ4_compress_local(const char* src, char* dst, int size, int clevel) { (void)clevel; return LZ4_compress(src, dst, size); } +static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { (void)clevel; return LZ4_compress_safe(src, dst, srcSize, dstSize); } #include "lz4hc.h" -#define COMPRESSOR1 LZ4_compressHC2 +#define COMPRESSOR1 LZ4_compressHC_safe #define DEFAULTCOMPRESSOR COMPRESSOR0 #include "xxhash.h" @@ -121,8 +121,8 @@ struct chunkParameters struct compressionParameters { - int (*compressionFunction)(const char*, char*, int, int); - int (*decompressionFunction)(const char*, char*, int); + int (*compressionFunction)(const char* src, char* dst, int srcSize, int dstSize, int cLevel); + int (*decompressionFunction)(const char* src, char* dst, int dstSize); }; @@ -371,7 +371,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel) while(BMK_GetMilliSpan(milliTime) < TIMELOOP) { for (chunkNb=0; chunkNb %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100); + DISPLAYUPDATE(2, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100); /* Write Block */ LZ4IO_writeLE32(out_buff, outSize); -- cgit v0.12 From b805d581b97be95fcc000134a54aa7c591b3ef09 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 21 Apr 2015 19:07:31 +0100 Subject: Removed obsolete functions from lz4 cli --- lib/lz4frame.c | 8 ++++---- lib/lz4hc.c | 3 ++- programs/lz4io.c | 12 +++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index a70dbaf..a2b6a22 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -516,19 +516,19 @@ static size_t LZ4F_compressBlock(void* dst, const void* src, size_t srcSize, com static int LZ4F_localLZ4_compress_limitedOutput_withState(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) { (void) level; - return LZ4_compress_limitedOutput_withState(ctx, src, dst, srcSize, dstSize); + return LZ4_compress_safe_extState(ctx, src, dst, srcSize, dstSize); } static int LZ4F_localLZ4_compress_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) { (void) level; - return LZ4_compress_limitedOutput_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstSize); + return LZ4_compress_safe_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstSize); } static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) { (void) level; - return LZ4_compressHC_limitedOutput_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize); + return LZ4_compressHC_safe_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize); } static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int level) @@ -538,7 +538,7 @@ static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int lev if (blockMode == LZ4F_blockIndependent) return LZ4F_localLZ4_compress_limitedOutput_withState; return LZ4F_localLZ4_compress_limitedOutput_continue; } - if (blockMode == LZ4F_blockIndependent) return LZ4_compressHC2_limitedOutput_withStateHC; + if (blockMode == LZ4F_blockIndependent) return LZ4_compressHC_safe_extStateHC; return LZ4F_localLZ4_compressHC_limitedOutput_continue; } diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 4f1272c..909481e 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -673,7 +673,8 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS * Deprecated Functions ***********************************/ /* Deprecated compression functions */ -int LZ4_compressHC(const char* source, char* dest, int inputSize) { return LZ4_compressHC2(source, dest, inputSize, 0); } +/* These functions are planned to start generate warnings by r131 approximately */ +int LZ4_compressHC(const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe (src, dst, srcSize, LZ4_compressBound(srcSize), 0); } int LZ4_compressHC_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe(src, dst, srcSize, maxDstSize, 0); } int LZ4_compressHC2(const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compressHC_safe (src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } int LZ4_compressHC2_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compressHC_safe(src, dst, srcSize, maxDstSize, cLevel); } diff --git a/programs/lz4io.c b/programs/lz4io.c index efe1fcd..88f94dd 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -322,12 +322,18 @@ static void LZ4IO_writeLE32 (void* p, unsigned value32) dstPtr[3] = (unsigned char)(value32 >> 24); } +static int LZ4IO_LZ4_compress(const char* src, char* dst, int srcSize, int dstSize, int cLevel) +{ + (void)cLevel; + return LZ4_compress_safe(src, dst, srcSize, dstSize); +} + /* LZ4IO_compressFilename_Legacy : * This function is intentionally "hidden" (not published in .h) * It generates compressed streams using the old 'legacy' format */ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output_filename, int compressionlevel) { - int (*compressionFunction)(const char* src, char* dst, int srcSize, int dstSize); + int (*compressionFunction)(const char* src, char* dst, int srcSize, int dstSize, int cLevel); unsigned long long filesize = 0; unsigned long long compressedfilesize = MAGICNUMBER_SIZE; char* in_buff; @@ -341,7 +347,7 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output /* Init */ start = clock(); - if (compressionlevel < 3) compressionFunction = LZ4_compress_safe; else compressionFunction = LZ4_compressHC_limitedOutput; + if (compressionlevel < 3) compressionFunction = LZ4IO_LZ4_compress; else compressionFunction = LZ4_compressHC_safe; if (LZ4IO_getFiles(input_filename, output_filename, &finput, &foutput)) EXM_THROW(20, "File error"); @@ -366,7 +372,7 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output filesize += inSize; /* Compress Block */ - outSize = compressionFunction(in_buff, out_buff+4, inSize, outBuffSize); + outSize = compressionFunction(in_buff, out_buff+4, inSize, outBuffSize, compressionlevel); compressedfilesize += outSize+4; DISPLAYUPDATE(2, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100); -- cgit v0.12 From b05d3d71a6ae2a0f711dfa0a046b8b0095978045 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 22 Apr 2015 00:57:39 +0100 Subject: Frame content size disabled by default when using LZ4F_compressFrame(), to be in better coherence with the advanced API LZ4F_compress_update() --- lib/lz4frame.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index a2b6a22..8f82f6c 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -301,7 +301,6 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf else { memset(&prefs, 0, sizeof(prefs)); - prefs.frameInfo.contentSize = (U64)srcSize; } if (prefs.frameInfo.contentSize != 0) prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ -- cgit v0.12 From 9c6fb8b160e72454cb50ca78ceca428cb246fd8a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 23 Apr 2015 07:46:35 +0100 Subject: Added LZ4_compress_fast_extState() --- lib/lz4.c | 34 ++++++++++++++++++---------------- lib/lz4.h | 22 ++++++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 490f9ce..e9fe467 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -697,29 +697,36 @@ int LZ4_compress_safe(const char* source, char* dest, int inputSize, int maxOutp } -int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) { -#if (HEAPMODE) - void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ -#else - U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ -#endif - int result; + MEM_INIT(state, 0, LZ4_STREAMSIZE); if (acceleration == 0) { if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); } else { if (inputSize < LZ4_64Klimit) - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); else - result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); } +} + + +int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +{ +#if (HEAPMODE) + void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ +#else + U64 ctx[LZ4_STREAMSIZE_U64]; /* Ensure data is aligned on 8-bytes boundaries */ +#endif + + int result = LZ4_compress_fast_extState(ctx, source, dest, inputSize, maxOutputSize, acceleration); #if (HEAPMODE) FREEMEM(ctx); @@ -740,11 +747,6 @@ LZ4_stream_t* LZ4_createStream(void) return lz4s; } -/* - * LZ4_initStream - * Use this function once, to init a newly allocated LZ4_stream_t structure - * Return : 1 if OK, 0 if error - */ void LZ4_resetStream (LZ4_stream_t* LZ4_stream) { MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t)); diff --git a/lib/lz4.h b/lib/lz4.h index cf06a8e..a2091fa 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -119,16 +119,6 @@ LZ4_compressBound() : int LZ4_compressBound(int inputSize); /* -LZ4_compress_fast() : - Same as LZ4_compress_limitedOutput, but allows to select an "acceleration" factor. - The larger the value, the faster the algorithm, but also the lesser the compression. - So it's a trade-off, which can be fine tuned, selecting whichever value you want. - An acceleration value of "0" means "use Default value", which is typically about 15 (see lz4.c source code). - Note : this function is "safe", even if its name does not say it. It's just faster and compress less. -*/ -int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); - -/* LZ4_compress_safe_extState() : Same compression function, just using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, @@ -138,6 +128,18 @@ LZ4_compress_safe_extState() : int LZ4_sizeofState(void); int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); +/* +LZ4_compress_fast() : + Same as LZ4_compress_safe(), but allows to select an "acceleration" factor. + The larger the acceleration value, the faster the algorithm, but also the lesser the compression. + It's a trade-off, which can be fine tuned, selecting whichever value you want. + An acceleration value of "0" means "use Default value", which is typically 17 (see lz4.c source code). + An acceleration value of "1" is the same as regular LZ4_compress_safe() + Note : this function is "safe", even if its name does not explicitly contain the word. It's just faster and compress less. +*/ +int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); +int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration); + /* LZ4_decompress_fast() : -- cgit v0.12 From a9a24e8b7f0fc17e8f667ed4e2cc8f8f9f9ee12f Mon Sep 17 00:00:00 2001 From: Eric Berge Date: Thu, 23 Apr 2015 15:59:09 -0500 Subject: cmake support for AIX, HPUX, Solaris and Windows The following changes allow for builds on AIX and HPUX with the native (non-gcc) compilers, as well as Visual Studio 2008 and Visual Studio 2012. Also work around a build error with gcc on Solaris which fails due to the system detecting an attempt to use C99 mode with an XPG mode less than XPG6. --- cmake_unofficial/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmake_unofficial/CMakeLists.txt b/cmake_unofficial/CMakeLists.txt index 1782ea0..77d9ca5 100644 --- a/cmake_unofficial/CMakeLists.txt +++ b/cmake_unofficial/CMakeLists.txt @@ -17,9 +17,11 @@ ENDIF() option(BUILD_TOOLS "Build the command line tools" ON) option(BUILD_LIBS "Build the libraries in addition to the tools" ON) +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) if(UNIX AND BUILD_LIBS) add_definitions(-fPIC) endif() +endif() set(LZ4_DIR ../lib/) set(PRG_DIR ../programs/) @@ -62,7 +64,12 @@ endif() #warnings +if(MSVC) +ADD_DEFINITIONS("-W4") +endif() +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) ADD_DEFINITIONS("-Wall") +endif() if(CMAKE_COMPILER_IS_GNUCXX) ADD_DEFINITIONS("-Wextra") ADD_DEFINITIONS("-Wundef") @@ -70,7 +77,10 @@ ADD_DEFINITIONS("-Wshadow") ADD_DEFINITIONS("-Wcast-align") ADD_DEFINITIONS("-Wstrict-prototypes") endif(CMAKE_COMPILER_IS_GNUCXX) +if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND + (NOT CMAKE_SYSTEM_NAME MATCHES "SunOS")) ADD_DEFINITIONS("-std=c99") +endif() ADD_DEFINITIONS("-DLZ4_VERSION=\"${CPACK_PACKAGE_VERSION_PATCH}\"") INCLUDE_DIRECTORIES (${LZ4_DIR}) -- cgit v0.12 From d6dc0a410d0be93551f247eeb871603d2db11c17 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 24 Apr 2015 10:15:12 +0100 Subject: streaming API : Improved ring buffer management --- lib/lz4.c | 3 +- lib/lz4.h | 39 +++++++++------- lib/lz4hc.c | 3 +- programs/fuzzer.c | 132 +++++++++++++++++++++++++++++++++--------------------- programs/lz4io.c | 34 +++++++------- 5 files changed, 124 insertions(+), 87 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index e9fe467..538aad4 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -1023,8 +1023,7 @@ FORCE_INLINE int LZ4_decompress_generic( { /* match can be copied as a single segment from external dictionary */ match = dictEnd - (lowPrefix-match); - memcpy(op, match, length); - op += length; + memmove(op, match, length); op += length; } else { diff --git a/lib/lz4.h b/lib/lz4.h index a2091fa..68f43a7 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -74,15 +74,14 @@ int LZ4_compress_safe (const char* source, char* dest, int sourceSize, int max int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize); /* -LZ4_compress_limitedOutput() : +LZ4_compress_safe() : Compresses 'sourceSize' bytes from buffer 'source' - into already allocated 'dest' of size 'maxOutputSize'. - Compression runs faster when 'maxOutputSize' >= LZ4_compressBound(sourceSize). - That's because in such case, it is guaranteed to compress within 'dest' budget, even in worst case scenario. - Compressing into a more limited space budget requires additional checks. - If the function cannot compress 'source' into a limited 'dest' budget, - compression stops *immediately*, and result of the function is zero. - It greatly accelerates behavior on non-compressible input, but as a consequence, 'dest' content is not valid either. + into already allocated 'dest' buffer of size 'maxDestSize'. + Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize). + It also runs faster, so it's a recommended setting. + If the function cannot compress 'source' into a more limited 'dest' budget, + compression stops *immediately*, and the function result is zero. + As a consequence, 'dest' content is not valid. This function never writes outside 'dest' buffer, nor read outside 'source' buffer. sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE maxDestSize : full or partial size of buffer 'dest' (which must be already allocated) @@ -132,13 +131,13 @@ int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int LZ4_compress_fast() : Same as LZ4_compress_safe(), but allows to select an "acceleration" factor. The larger the acceleration value, the faster the algorithm, but also the lesser the compression. - It's a trade-off, which can be fine tuned, selecting whichever value you want. + It's a trade-off. It can be fine tuned, with each successive value providing an additional +2/3% to speed. An acceleration value of "0" means "use Default value", which is typically 17 (see lz4.c source code). An acceleration value of "1" is the same as regular LZ4_compress_safe() Note : this function is "safe", even if its name does not explicitly contain the word. It's just faster and compress less. */ -int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxOutputSize, unsigned acceleration); -int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration); +int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, unsigned acceleration); +int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, unsigned acceleration); /* @@ -260,8 +259,18 @@ int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dicti *_continue() : These decoding functions allow decompression of multiple blocks in "streaming" mode. Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB) - If this condition is not possible, save the relevant part of decoded data into a safe buffer, - and indicate where is its new address using LZ4_setStreamDecode() + In the case of a ring buffers, decoding buffer must be either : + - Exactly same size as encoding buffer, with same update rule (block boundaries at same positions) + In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB). + - Larger than encoding buffer, by a minimum of maxBlockSize more bytes. + maxBlockSize is implementation dependent. It's the maximum size you intend to compress into a single block. + In which case, encoding and decoding buffers do not need to be synchronized, + and encoding ring buffer can have any size, including small ones ( < 64 KB). + - _At least_ 64 KB + 8 bytes + maxBlockSize. + In which case, encoding and decoding buffers do not need to be synchronized, + and encoding ring buffer can have any size, including larger than decoding buffer. + Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer, + and indicate where it is saved using LZ4_setStreamDecode() */ int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize); int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize); @@ -271,8 +280,8 @@ int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const ch Advanced decoding functions : *_usingDict() : These decoding functions work the same as - a combination of LZ4_setDictDecode() followed by LZ4_decompress_x_continue() - They are stand-alone and don't use nor update an LZ4_streamDecode_t structure. + a combination of LZ4_setStreamDecode() followed by LZ4_decompress_x_continue() + They are stand-alone. They don't need nor update an LZ4_streamDecode_t structure. */ int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize); int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize); diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 909481e..e154ca9 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -620,7 +620,8 @@ static int LZ4_compressHC_continue_generic (LZ4HC_Data_Structure* ctxPtr, } /* Check if blocks follow each other */ - if ((const BYTE*)source != ctxPtr->end) LZ4HC_setExternalDict(ctxPtr, (const BYTE*)source); + if ((const BYTE*)source != ctxPtr->end) + LZ4HC_setExternalDict(ctxPtr, (const BYTE*)source); /* Check overlapping input/dictionary space */ { diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 1704b6e..685553b 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -153,10 +153,10 @@ static U32 FUZ_rand(U32* src) { U32 rand32 = *src; rand32 *= PRIME1; - rand32 += PRIME2; + rand32 ^= PRIME2; rand32 = FUZ_rotl32(rand32, 13); *src = rand32; - return rand32 >> 3; + return rand32; } @@ -168,27 +168,28 @@ static void FUZ_fillCompressibleNoiseBuffer(void* buffer, size_t bufferSize, dou size_t pos = 0; U32 P32 = (U32)(32768 * proba); - // First Byte - BBuffer[pos++] = (BYTE)(FUZ_rand(seed)); + /* First Bytes */ + while (pos < 20) + BBuffer[pos++] = (BYTE)(FUZ_rand(seed)); while (pos < bufferSize) { - // Select : Literal (noise) or copy (within 64K) + /* Select : Literal (noise) or copy (within 64K) */ if (FUZ_RAND15BITS < P32) { - // Copy (within 64K) + /* Copy (within 64K) */ size_t match, d; size_t length = FUZ_RANDLENGTH + 4; size_t offset = FUZ_RAND15BITS + 1; - if (offset > pos) offset = pos; + while (offset > pos) offset >>= 1; d = pos + length; - if (d > bufferSize) d = bufferSize; + while (d > bufferSize) d = bufferSize; match = pos - offset; while (pos < d) BBuffer[pos++] = BBuffer[match++]; } else { - // Literal (noise) + /* Literal (noise) */ size_t d; size_t length = FUZ_RANDLENGTH; d = pos + length; @@ -299,6 +300,16 @@ static void FUZ_displayUpdate(unsigned testNb) } +static void FUZ_findDiff(const void* buff1, const void* buff2) +{ + const BYTE* b1 = (const BYTE*)buff1; + const BYTE* b2 = (const BYTE*)buff2; + size_t i=0; + while (b1[i]==b2[i]) i++; + DISPLAY("Wrong Byte at position %u\n", (unsigned)i); +} + + static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double compressibility, U32 duration) { unsigned long long bytes = 0; @@ -391,17 +402,17 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(ret==0, "LZ4_compressHC() failed"); HCcompressedSize = ret; - // Test compression HC using external state + /* Test compression HC using external state */ FUZ_DISPLAYTEST; ret = LZ4_compressHC_withStateHC(stateLZ4HC, block, compressedBuffer, blockSize); FUZ_CHECKTEST(ret==0, "LZ4_compressHC_withStateHC() failed"); - // Test compression using external state + /* Test compression using external state */ FUZ_DISPLAYTEST; ret = LZ4_compress_withState(stateLZ4, block, compressedBuffer, blockSize); FUZ_CHECKTEST(ret==0, "LZ4_compress_withState() failed"); - // Test compression + /* Test compression */ FUZ_DISPLAYTEST; ret = LZ4_compress(block, compressedBuffer, blockSize); FUZ_CHECKTEST(ret==0, "LZ4_compress() failed"); @@ -411,7 +422,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c crcOrig = XXH32(block, blockSize, 0); - // Test decoding with output size being exactly what's necessary => must work + /* Test decoding with output size being exactly what's necessary => must work */ FUZ_DISPLAYTEST; ret = LZ4_decompress_fast(compressedBuffer, decodedBuffer, blockSize); FUZ_CHECKTEST(ret<0, "LZ4_decompress_fast failed despite correct space"); @@ -419,19 +430,19 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c crcCheck = XXH32(decodedBuffer, blockSize, 0); FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_fast corrupted decoded data"); - // Test decoding with one byte missing => must fail + /* Test decoding with one byte missing => must fail */ FUZ_DISPLAYTEST; decodedBuffer[blockSize-1] = 0; ret = LZ4_decompress_fast(compressedBuffer, decodedBuffer, blockSize-1); FUZ_CHECKTEST(ret>=0, "LZ4_decompress_fast should have failed, due to Output Size being too small"); FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_fast overrun specified output buffer"); - // Test decoding with one byte too much => must fail + /* Test decoding with one byte too much => must fail */ FUZ_DISPLAYTEST; ret = LZ4_decompress_fast(compressedBuffer, decodedBuffer, blockSize+1); FUZ_CHECKTEST(ret>=0, "LZ4_decompress_fast should have failed, due to Output Size being too large"); - // Test decoding with output size exactly what's necessary => must work + /* Test decoding with output size exactly what's necessary => must work */ FUZ_DISPLAYTEST; decodedBuffer[blockSize] = 0; ret = LZ4_decompress_safe(compressedBuffer, decodedBuffer, compressedSize, blockSize); @@ -570,9 +581,9 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_DISPLAYTEST; ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize, decodedBuffer, dictSize); - FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_withPrefix64k did not regenerate original data"); + FUZ_CHECKTEST(ret!=blockSize, "LZ4_decompress_safe_usingDict did not regenerate original data"); crcCheck = XXH32(decodedBuffer+dictSize, blockSize, 0); - FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_withPrefix64k corrupted decoded data"); + FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data"); /* Compress using External dictionary */ FUZ_DISPLAYTEST; @@ -593,7 +604,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(ret!=blockContinueCompressedSize, "LZ4_compress_limitedOutput_compressed size is different (%i != %i)", ret, blockContinueCompressedSize); FUZ_CHECKTEST(ret<=0, "LZ4_compress_limitedOutput_continue should work : enough size available within output buffer"); - // Decompress with dictionary as external + /* Decompress with dictionary as external */ FUZ_DISPLAYTEST; decodedBuffer[blockSize] = 0; ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer, blockSize, dict, dictSize); @@ -601,11 +612,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_fast_usingDict overrun specified output buffer size") crcCheck = XXH32(decodedBuffer, blockSize, 0); if (crcCheck!=crcOrig) - { - int i=0; - while (block[i]==decodedBuffer[i]) i++; - printf("Wrong Byte at position %i/%i\n", i, blockSize); - } + FUZ_findDiff(block, decodedBuffer); FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize); FUZ_DISPLAYTEST; @@ -619,7 +626,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_DISPLAYTEST; decodedBuffer[blockSize-1] = 0; ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer, blockSize-1, dict, dictSize); - FUZ_CHECKTEST(ret>=0, "LZ4_decompress_fast_withDict should have failed : wrong original size (-1 byte)"); + FUZ_CHECKTEST(ret>=0, "LZ4_decompress_fast_usingDict should have failed : wrong original size (-1 byte)"); FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_fast_usingDict overrun specified output buffer size"); FUZ_DISPLAYTEST; @@ -640,9 +647,9 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c } } - // Compress HC using External dictionary + /* Compress HC using External dictionary */ FUZ_DISPLAYTEST; - dict -= (FUZ_rand(&randState) & 7); // even bigger separation + dict -= (FUZ_rand(&randState) & 7); /* even bigger separation */ if (dict < (char*)CNBuffer) dict = (char*)CNBuffer; LZ4_resetStreamHC (&LZ4dictHC, FUZ_rand(&randState) & 0x7); LZ4_loadDictHC(&LZ4dictHC, dict, dictSize); @@ -667,14 +674,9 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(decodedBuffer[blockSize], "LZ4_decompress_safe_usingDict overrun specified output buffer size") crcCheck = XXH32(decodedBuffer, blockSize, 0); if (crcCheck!=crcOrig) - { - int i=0; - while (block[i]==decodedBuffer[i]) i++; - printf("Wrong Byte at position %i/%i\n", i, blockSize); - } + FUZ_findDiff(block, decodedBuffer); FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe_usingDict corrupted decoded data"); - /* ***** End of tests *** */ /* Fill stats */ bytes += blockSize; @@ -723,13 +725,13 @@ static void FUZ_unitTests(void) char ringBuffer[ringBufferSize]; U32 randState = 1; - // Init + /* Init */ FUZ_fillCompressibleNoiseBuffer(testInput, testInputSize, 0.50, &randState); - // 32-bits address space overflow test + /* 32-bits address space overflow test */ FUZ_AddressOverflow(); - // LZ4 streaming tests + /* LZ4 streaming tests */ { LZ4_stream_t* statePtr; LZ4_stream_t streamingState; @@ -737,12 +739,12 @@ static void FUZ_unitTests(void) U64 crcNew; int result; - // Allocation test + /* Allocation test */ statePtr = LZ4_createStream(); FUZ_CHECKTEST(statePtr==NULL, "LZ4_createStream() allocation failed"); LZ4_freeStream(statePtr); - // simple compression test + /* simple compression test */ crcOrig = XXH64(testInput, testCompressedSize, 0); LZ4_resetStream(&streamingState); result = LZ4_compress_limitedOutput_continue(&streamingState, testInput, testCompressed, testCompressedSize, testCompressedSize-1); @@ -753,7 +755,7 @@ static void FUZ_unitTests(void) crcNew = XXH64(testVerify, testCompressedSize, 0); FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption"); - // ring buffer test + /* ring buffer test */ { XXH64_state_t xxhOrig; XXH64_state_t xxhNew; @@ -787,7 +789,7 @@ static void FUZ_unitTests(void) crcNew = XXH64_digest(&xxhNew); FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption"); - // prepare next message + /* prepare next message */ iNext += messageSize; rNext += messageSize; dNext += messageSize; @@ -798,21 +800,20 @@ static void FUZ_unitTests(void) } } - // LZ4 HC streaming tests + /* LZ4 HC streaming tests */ { LZ4_streamHC_t* sp; LZ4_streamHC_t sHC; - //XXH64_state_t xxh; U64 crcOrig; U64 crcNew; int result; - // Allocation test + /* Allocation test */ sp = LZ4_createStreamHC(); FUZ_CHECKTEST(sp==NULL, "LZ4_createStreamHC() allocation failed"); LZ4_freeStreamHC(sp); - // simple compression test + /* simple HC compression test */ crcOrig = XXH64(testInput, testCompressedSize, 0); LZ4_resetStreamHC(&sHC, 0); result = LZ4_compressHC_limitedOutput_continue(&sHC, testInput, testCompressed, testCompressedSize, testCompressedSize-1); @@ -823,7 +824,7 @@ static void FUZ_unitTests(void) crcNew = XXH64(testVerify, testCompressedSize, 0); FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption"); - // simple dictionary compression test + /* simple dictionary HC compression test */ crcOrig = XXH64(testInput + 64 KB, testCompressedSize, 0); LZ4_resetStreamHC(&sHC, 0); LZ4_loadDictHC(&sHC, testInput, 64 KB); @@ -855,7 +856,7 @@ static void FUZ_unitTests(void) FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() dictionary decompression corruption"); } - // remote dictionary HC compression test + /* remote dictionary HC compression test */ crcOrig = XXH64(testInput + 64 KB, testCompressedSize, 0); LZ4_resetStreamHC(&sHC, 0); LZ4_loadDictHC(&sHC, testInput, 32 KB); @@ -965,19 +966,46 @@ static void FUZ_unitTests(void) XXH64_state_t xxhOrig; XXH64_state_t xxhNew; LZ4_streamDecode_t decodeState; - const U32 maxMessageSizeLog = 10; + const U32 maxMessageSizeLog = 12; const U32 maxMessageSizeMask = (1< dBufferSize) dNext = 0; + while (totalMessageSize < 9 MB) { XXH64_update(&xxhOrig, testInput + iNext, messageSize); @@ -987,18 +1015,20 @@ static void FUZ_unitTests(void) FUZ_CHECKTEST(result==0, "LZ4_compressHC_limitedOutput_continue() compression failed"); result = LZ4_decompress_safe_continue(&decodeState, testCompressed, testVerify + dNext, result, messageSize); - FUZ_CHECKTEST(result!=(int)messageSize, "ringBuffer : LZ4_decompress_safe() test failed"); + FUZ_CHECKTEST(result!=(int)messageSize, "64K D.ringBuffer : LZ4_decompress_safe() test failed"); XXH64_update(&xxhNew, testVerify + dNext, messageSize); crcNew = XXH64_digest(&xxhNew); - FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption"); + if (crcOrig != crcNew) + FUZ_findDiff(testInput + iNext, testVerify + dNext); + FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption during small decoder-side ring buffer test"); /* prepare next message */ dNext += messageSize; totalMessageSize += messageSize; messageSize = (FUZ_rand(&randState) & maxMessageSizeMask) + 1; iNext = (FUZ_rand(&randState) & 65535); - if (dNext + messageSize > dBufferSize) dNext = 0; + if (dNext > dBufferSize) dNext = 0; } } } diff --git a/programs/lz4io.c b/programs/lz4io.c index 88f94dd..fb1f428 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -443,7 +443,11 @@ static void LZ4IO_freeCResources(cRess_t ress) if (LZ4F_isError(errorCode)) EXM_THROW(38, "Error : can't free LZ4F context resource : %s", LZ4F_getErrorName(errorCode)); } - +/* + * LZ4IO_compressFilename_extRess() + * result : 0 : compression completed correctly + * 1 : missing or pb opening srcFileName + */ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, const char* dstFileName, int compressionLevel) { unsigned long long filesize = 0; @@ -463,10 +467,7 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, memset(&prefs, 0, sizeof(prefs)); /* File check */ - { - int srcFileAbsent = LZ4IO_getFiles(srcFileName, dstFileName, &srcFile, &dstFile); - if (srcFileAbsent) return srcFileAbsent; - } + if (LZ4IO_getFiles(srcFileName, dstFileName, &srcFile, &dstFile)) return 1; /* Set compression parameters */ prefs.autoFlush = 1; @@ -547,11 +548,8 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName, /* Final Status */ DISPLAYLEVEL(2, "\r%79s\r", ""); - { - DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", - (unsigned long long) filesize, (unsigned long long) compressedfilesize, - (double)compressedfilesize/(filesize + !filesize)*100); /* avoid division by zero */ - } + DISPLAYLEVEL(2, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n", + filesize, compressedfilesize, (double)compressedfilesize/(filesize + !filesize)*100); /* avoid division by zero */ return 0; } @@ -588,8 +586,8 @@ int LZ4IO_compressFilename(const char* srcFileName, const char* dstFileName, int int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionLevel) { int i; - int missing_files = 0; - char* outFileName = (char*)malloc(FNSPACE); + int missed_files = 0; + char* dstFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); cRess_t ress; @@ -601,18 +599,18 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, for (i=0; i Date: Fri, 24 Apr 2015 11:04:21 +0100 Subject: Fixed minor static analyzer warning --- programs/fuzzer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 685553b..2bf3cfe 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -968,7 +968,7 @@ static void FUZ_unitTests(void) LZ4_streamDecode_t decodeState; const U32 maxMessageSizeLog = 12; const U32 maxMessageSizeMask = (1< Date: Fri, 24 Apr 2015 13:26:53 +0100 Subject: Modified lz4frame context typedef, to enforce stricter alignment condition --- lib/lz4frame.c | 7 ++++--- lib/lz4frame.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 8f82f6c..c6b9634 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -283,6 +283,7 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_preferences_t* preferencesPtr) { LZ4F_cctx_internal_t cctxI; + LZ4F_compressionContext_t cctx = (LZ4F_compressionContext_t)(&cctxI); LZ4_stream_t lz4ctx; LZ4F_preferences_t prefs; LZ4F_compressOptions_t options; @@ -321,15 +322,15 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf if (dstMaxSize < LZ4F_compressFrameBound(srcSize, &prefs)) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; - errorCode = LZ4F_compressBegin(&cctxI, dstBuffer, dstMaxSize, &prefs); /* write header */ + errorCode = LZ4F_compressBegin(cctx, dstBuffer, dstMaxSize, &prefs); /* write header */ if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; /* header size */ - errorCode = LZ4F_compressUpdate(&cctxI, dstPtr, dstEnd-dstPtr, srcBuffer, srcSize, &options); + errorCode = LZ4F_compressUpdate(cctx, dstPtr, dstEnd-dstPtr, srcBuffer, srcSize, &options); if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; - errorCode = LZ4F_compressEnd(&cctxI, dstPtr, dstEnd-dstPtr, &options); /* flush last block, and generate suffix */ + errorCode = LZ4F_compressEnd(cctx, dstPtr, dstEnd-dstPtr, &options); /* flush last block, and generate suffix */ if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; diff --git a/lib/lz4frame.h b/lib/lz4frame.h index b5ba2fb..4698c4b 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -146,7 +146,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf /********************************** * Advanced compression functions * ********************************/ -typedef void* LZ4F_compressionContext_t; +typedef size_t* LZ4F_compressionContext_t; typedef struct { unsigned stableSrc; /* 1 == src content will remain available on future calls to LZ4F_compress(); avoid saving src content within tmp buffer as future dictionary */ @@ -226,7 +226,7 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t * Decompression functions * *********************************/ -typedef void* LZ4F_decompressionContext_t; +typedef size_t* LZ4F_decompressionContext_t; typedef struct { unsigned stableDst; /* guarantee that decompressed data will still be there on next function calls (avoid storage into tmp buffers) */ -- cgit v0.12 From c9cbb8fc069f93708cbc6a053cf06f8c965f28e5 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 24 Apr 2015 14:28:06 +0100 Subject: Increased aligment requirement for lz4frame context pointer --- lib/lz4frame.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 4698c4b..6c4dbed 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -132,7 +132,7 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_preferences_t* preferencesPtr); /* LZ4F_compressFrame() - * Compress an entire srcBuffer into a valid LZ4 frame, as defined by specification v1.5 + * Compress an entire srcBuffer into a valid LZ4 frame, as defined by specification v1.5.1 * The most important rule is that dstBuffer MUST be large enough (dstMaxSize) to ensure compression completion even in worst case. * You can get the minimum value of dstMaxSize by using LZ4F_compressFrameBound() * If this condition is not respected, LZ4F_compressFrame() will fail (result is an errorCode) @@ -146,7 +146,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf /********************************** * Advanced compression functions * ********************************/ -typedef size_t* LZ4F_compressionContext_t; +typedef long long* LZ4F_compressionContext_t; /* must be aligned on 8-bytes */ typedef struct { unsigned stableSrc; /* 1 == src content will remain available on future calls to LZ4F_compress(); avoid saving src content within tmp buffer as future dictionary */ @@ -226,7 +226,7 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t * Decompression functions * *********************************/ -typedef size_t* LZ4F_decompressionContext_t; +typedef long long* LZ4F_decompressionContext_t; /* must be aligned on 8-bytes */ typedef struct { unsigned stableDst; /* guarantee that decompressed data will still be there on next function calls (avoid storage into tmp buffers) */ -- cgit v0.12 From ad2dd6df3f62340c6f4ad6d70e805ade7037afbd Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 27 Apr 2015 02:31:56 +0100 Subject: moved lz4frame context types to incomplete typedef --- lib/lz4frame.c | 61 +++++++++++++++++++++++++++++----------------------------- lib/lz4frame.h | 12 ++++++------ 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index c6b9634..5fad2e8 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -39,7 +39,7 @@ You can contact the author at : /************************************** -Compiler Options +* Compiler Options **************************************/ #ifdef _MSC_VER /* Visual Studio */ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ @@ -107,10 +107,11 @@ static const size_t maxFHSize = 15; static const size_t BHSize = 4; static const int minHClevel = 3; + /************************************** * Structures and local types **************************************/ -typedef struct +typedef struct LZ4F_cctx_s { LZ4F_preferences_t prefs; U32 version; @@ -124,9 +125,9 @@ typedef struct XXH32_state_t xxh; void* lz4CtxPtr; U32 lz4CtxLevel; /* 0: unallocated; 1: LZ4_stream_t; 3: LZ4_streamHC_t */ -} LZ4F_cctx_internal_t; +} LZ4F_cctx_t; -typedef struct +typedef struct LZ4F_dctx_s { LZ4F_frameInfo_t frameInfo; U32 version; @@ -146,7 +147,7 @@ typedef struct size_t tmpOutStart; XXH32_state_t xxh; BYTE header[16]; -} LZ4F_dctx_internal_t; +} LZ4F_dctx_t; /************************************** @@ -282,8 +283,7 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere */ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_preferences_t* preferencesPtr) { - LZ4F_cctx_internal_t cctxI; - LZ4F_compressionContext_t cctx = (LZ4F_compressionContext_t)(&cctxI); + LZ4F_cctx_t cctxI; LZ4_stream_t lz4ctx; LZ4F_preferences_t prefs; LZ4F_compressOptions_t options; @@ -298,11 +298,10 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf cctxI.version = LZ4F_VERSION; cctxI.maxBufferSize = 5 MB; /* mess with real buffer size to prevent allocation; works because autoflush==1 & stableSrc==1 */ - if (preferencesPtr!=NULL) prefs = *preferencesPtr; + if (preferencesPtr!=NULL) + prefs = *preferencesPtr; else - { memset(&prefs, 0, sizeof(prefs)); - } if (prefs.frameInfo.contentSize != 0) prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ @@ -322,15 +321,15 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf if (dstMaxSize < LZ4F_compressFrameBound(srcSize, &prefs)) return (size_t)-LZ4F_ERROR_dstMaxSize_tooSmall; - errorCode = LZ4F_compressBegin(cctx, dstBuffer, dstMaxSize, &prefs); /* write header */ + errorCode = LZ4F_compressBegin(&cctxI, dstBuffer, dstMaxSize, &prefs); /* write header */ if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; /* header size */ - errorCode = LZ4F_compressUpdate(cctx, dstPtr, dstEnd-dstPtr, srcBuffer, srcSize, &options); + errorCode = LZ4F_compressUpdate(&cctxI, dstPtr, dstEnd-dstPtr, srcBuffer, srcSize, &options); if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; - errorCode = LZ4F_compressEnd(cctx, dstPtr, dstEnd-dstPtr, &options); /* flush last block, and generate suffix */ + errorCode = LZ4F_compressEnd(&cctxI, dstPtr, dstEnd-dstPtr, &options); /* flush last block, and generate suffix */ if (LZ4F_isError(errorCode)) return errorCode; dstPtr += errorCode; @@ -342,8 +341,8 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf /*********************************** -* Advanced compression functions -* *********************************/ +* Advanced compression functions +***********************************/ /* LZ4F_createCompressionContext() : * The first thing to do is to create a compressionContext object, which will be used in all compression operations. @@ -355,9 +354,9 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf */ LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_compressionContext_t* LZ4F_compressionContextPtr, unsigned version) { - LZ4F_cctx_internal_t* cctxPtr; + LZ4F_cctx_t* cctxPtr; - cctxPtr = (LZ4F_cctx_internal_t*)ALLOCATOR(sizeof(LZ4F_cctx_internal_t)); + cctxPtr = (LZ4F_cctx_t*)ALLOCATOR(sizeof(LZ4F_cctx_t)); if (cctxPtr==NULL) return (LZ4F_errorCode_t)(-LZ4F_ERROR_allocation_failed); cctxPtr->version = version; @@ -371,7 +370,7 @@ LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_compressionContext_t* LZ4F_c LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_compressionContext) { - LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)LZ4F_compressionContext; + LZ4F_cctx_t* cctxPtr = (LZ4F_cctx_t*)LZ4F_compressionContext; if (cctxPtr != NULL) /* null pointers can be safely provided to this function, like free() */ { @@ -393,7 +392,7 @@ LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_compressionContext_t LZ4F_comp size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_preferences_t* preferencesPtr) { LZ4F_preferences_t prefNull; - LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext; + LZ4F_cctx_t* cctxPtr = (LZ4F_cctx_t*)compressionContext; BYTE* const dstStart = (BYTE*)dstBuffer; BYTE* dstPtr = dstStart; BYTE* headerStart; @@ -542,7 +541,7 @@ static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int lev return LZ4F_localLZ4_compressHC_limitedOutput_continue; } -static int LZ4F_localSaveDict(LZ4F_cctx_internal_t* cctxPtr) +static int LZ4F_localSaveDict(LZ4F_cctx_t* cctxPtr) { if (cctxPtr->prefs.compressionLevel < minHClevel) return LZ4_saveDict ((LZ4_stream_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB); @@ -563,7 +562,7 @@ typedef enum { notDone, fromTmpBuffer, fromSrcBuffer } LZ4F_lastBlockStatus; size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* compressOptionsPtr) { LZ4F_compressOptions_t cOptionsNull; - LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext; + LZ4F_cctx_t* cctxPtr = (LZ4F_cctx_t*)compressionContext; size_t blockSize = cctxPtr->maxBlockSize; const BYTE* srcPtr = (const BYTE*)srcBuffer; const BYTE* const srcEnd = srcPtr + srcSize; @@ -673,7 +672,7 @@ size_t LZ4F_compressUpdate(LZ4F_compressionContext_t compressionContext, void* d */ size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_compressOptions_t* compressOptionsPtr) { - LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext; + LZ4F_cctx_t* cctxPtr = (LZ4F_cctx_t*)compressionContext; BYTE* const dstStart = (BYTE*)dstBuffer; BYTE* dstPtr = dstStart; compressFunc_t compress; @@ -714,7 +713,7 @@ size_t LZ4F_flush(LZ4F_compressionContext_t compressionContext, void* dstBuffer, */ size_t LZ4F_compressEnd(LZ4F_compressionContext_t compressionContext, void* dstBuffer, size_t dstMaxSize, const LZ4F_compressOptions_t* compressOptionsPtr) { - LZ4F_cctx_internal_t* cctxPtr = (LZ4F_cctx_internal_t*)compressionContext; + LZ4F_cctx_t* cctxPtr = (LZ4F_cctx_t*)compressionContext; BYTE* const dstStart = (BYTE*)dstBuffer; BYTE* dstPtr = dstStart; size_t errorCode; @@ -760,20 +759,20 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t compressionContext, void* dstB */ LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_decompressionContext_t* LZ4F_decompressionContextPtr, unsigned versionNumber) { - LZ4F_dctx_internal_t* dctxPtr; + LZ4F_dctx_t* dctxPtr; - dctxPtr = (LZ4F_dctx_internal_t*)ALLOCATOR(sizeof(LZ4F_dctx_internal_t)); + dctxPtr = (LZ4F_dctx_t*)ALLOCATOR(sizeof(LZ4F_dctx_t)); if (dctxPtr==NULL) return (LZ4F_errorCode_t)-LZ4F_ERROR_GENERIC; dctxPtr->version = versionNumber; - *LZ4F_decompressionContextPtr = (LZ4F_compressionContext_t)dctxPtr; + *LZ4F_decompressionContextPtr = (LZ4F_decompressionContext_t)dctxPtr; return LZ4F_OK_NoError; } LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_decompressionContext_t LZ4F_decompressionContext) { LZ4F_errorCode_t result = LZ4F_OK_NoError; - LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)LZ4F_decompressionContext; + LZ4F_dctx_t* dctxPtr = (LZ4F_dctx_t*)LZ4F_decompressionContext; if (dctxPtr != NULL) /* can accept NULL input, like free() */ { result = (LZ4F_errorCode_t)dctxPtr->dStage; @@ -808,7 +807,7 @@ typedef enum { dstage_getHeader=0, dstage_storeHeader, dctxPtr->frameInfo and dctxPtr->dStage. input : srcVoidPtr points at the **beginning of the frame** */ -static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVoidPtr, size_t srcSize) +static size_t LZ4F_decodeHeader(LZ4F_dctx_t* dctxPtr, const void* srcVoidPtr, size_t srcSize) { BYTE FLG, BD, HC; unsigned version, blockMode, blockChecksumFlag, contentSizeFlag, contentChecksumFlag, blockSizeID; @@ -929,7 +928,7 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const void* srcVo LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t dCtx, LZ4F_frameInfo_t* frameInfoPtr, const void* srcBuffer, size_t* srcSizePtr) { - LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)dCtx; + LZ4F_dctx_t* dctxPtr = (LZ4F_dctx_t*)dCtx; if (dctxPtr->dStage > dstage_storeHeader) /* note : requires dstage_* header related to be at beginning of enum */ { @@ -959,7 +958,7 @@ static int LZ4F_decompress_safe (const char* source, char* dest, int compressedS } -static void LZ4F_updateDict(LZ4F_dctx_internal_t* dctxPtr, const BYTE* dstPtr, size_t dstSize, const BYTE* dstPtr0, unsigned withinTmp) +static void LZ4F_updateDict(LZ4F_dctx_t* dctxPtr, const BYTE* dstPtr, size_t dstSize, const BYTE* dstPtr0, unsigned withinTmp) { if (dctxPtr->dictSize==0) dctxPtr->dict = (BYTE*)dstPtr; /* priority to dictionary continuity */ @@ -1047,7 +1046,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, const void* srcBuffer, size_t* srcSizePtr, const LZ4F_decompressOptions_t* decompressOptionsPtr) { - LZ4F_dctx_internal_t* dctxPtr = (LZ4F_dctx_internal_t*)decompressionContext; + LZ4F_dctx_t* dctxPtr = (LZ4F_dctx_t*)decompressionContext; LZ4F_decompressOptions_t optionsNull; const BYTE* const srcStart = (const BYTE*)srcBuffer; const BYTE* const srcEnd = srcStart + *srcSizePtr; diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 6c4dbed..05fbc5f 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -144,9 +144,9 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf /********************************** - * Advanced compression functions - * ********************************/ -typedef long long* LZ4F_compressionContext_t; /* must be aligned on 8-bytes */ +* Advanced compression functions +**********************************/ +typedef struct LZ4F_cctx_s* LZ4F_compressionContext_t; /* must be aligned on 8-bytes */ typedef struct { unsigned stableSrc; /* 1 == src content will remain available on future calls to LZ4F_compress(); avoid saving src content within tmp buffer as future dictionary */ @@ -223,10 +223,10 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t /*********************************** - * Decompression functions - * *********************************/ +* Decompression functions +***********************************/ -typedef long long* LZ4F_decompressionContext_t; /* must be aligned on 8-bytes */ +typedef struct LZ4F_dctx_s* LZ4F_decompressionContext_t; /* must be aligned on 8-bytes */ typedef struct { unsigned stableDst; /* guarantee that decompressed data will still be there on next function calls (avoid storage into tmp buffers) */ -- cgit v0.12 From 1e751a74f4caf2265b52a03577df3631f1a777a6 Mon Sep 17 00:00:00 2001 From: Eric Berge Date: Tue, 28 Apr 2015 09:00:23 -0500 Subject: Install the lz4frame.h header in the cmake build --- cmake_unofficial/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake_unofficial/CMakeLists.txt b/cmake_unofficial/CMakeLists.txt index 77d9ca5..4c3eb65 100644 --- a/cmake_unofficial/CMakeLists.txt +++ b/cmake_unofficial/CMakeLists.txt @@ -25,7 +25,7 @@ endif() set(LZ4_DIR ../lib/) set(PRG_DIR ../programs/) -set(LZ4_SRCS_LIB ${LZ4_DIR}lz4.c ${LZ4_DIR}lz4hc.c ${LZ4_DIR}lz4.h ${LZ4_DIR}lz4hc.h ${LZ4_DIR}lz4frame.c ${LZ4_DIR}xxhash.c) +set(LZ4_SRCS_LIB ${LZ4_DIR}lz4.c ${LZ4_DIR}lz4hc.c ${LZ4_DIR}lz4.h ${LZ4_DIR}lz4hc.h ${LZ4_DIR}lz4frame.c ${LZ4_DIR}lz4frame.h ${LZ4_DIR}xxhash.c) set(LZ4_SRCS ${LZ4_DIR}lz4frame.c ${LZ4_DIR}xxhash.c ${PRG_DIR}bench.c ${PRG_DIR}lz4cli.c ${PRG_DIR}lz4io.c) if(BUILD_TOOLS AND NOT BUILD_LIBS) @@ -53,6 +53,7 @@ if(BUILD_LIBS) install(FILES ${LZ4_DIR}/lz4.h ${LZ4_DIR}/lz4hc.h + ${LZ4_DIR}/lz4frame.h DESTINATION include ) -- cgit v0.12 From 2a974d73c35476eb66275dd0d9448a6efa51bf56 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 2 May 2015 15:44:43 +0100 Subject: refactored lz4hc --- lib/lz4hc.c | 102 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index e154ca9..1db3d98 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -1,53 +1,53 @@ /* -LZ4 HC - High Compression Mode of LZ4 -Copyright (C) 2011-2015, Yann Collet. - -BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -You can contact the author at : - - LZ4 source repository : https://github.com/Cyan4973/lz4 - - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c + LZ4 HC - High Compression Mode of LZ4 + Copyright (C) 2011-2015, Yann Collet. + + BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + You can contact the author at : + - LZ4 source repository : https://github.com/Cyan4973/lz4 + - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c */ /************************************** - Tuning Parameter +* Tuning Parameter **************************************/ static const int LZ4HC_compressionLevel_default = 9; /************************************** - Includes +* Includes **************************************/ #include "lz4hc.h" /************************************** - Local Compiler Options +* Local Compiler Options **************************************/ #if defined(__GNUC__) # pragma GCC diagnostic ignored "-Wunused-function" @@ -59,18 +59,18 @@ static const int LZ4HC_compressionLevel_default = 9; /************************************** - Common LZ4 definition +* Common LZ4 definition **************************************/ #define LZ4_COMMONDEFS_ONLY #include "lz4.c" /************************************** - Local Constants +* Local Constants **************************************/ #define DICTIONARY_LOGSIZE 16 #define MAXD (1<> ((MINMATCH*8)-HASH_LOG)) -#define DELTANEXT(p) chainTable[(size_t)(p) & MAXD_MASK] -#define GETNEXT(p) ((p) - (size_t)DELTANEXT(p)) +//#define DELTANEXTU16(p) chainTable[(p) & MAXD_MASK] /* flexible, MAXD dependent */ +#define DELTANEXTU16(p) chainTable[(U16)(p)] /* faster */ static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); } /************************************** - HC Compression +* HC Compression **************************************/ static void LZ4HC_init (LZ4HC_Data_Structure* hc4, const BYTE* start) { @@ -141,7 +141,7 @@ FORCE_INLINE void LZ4HC_Insert (LZ4HC_Data_Structure* hc4, const BYTE* ip) U32 h = LZ4HC_hashPtr(base+idx); size_t delta = idx - HashTable[h]; if (delta>MAX_DISTANCE) delta = MAX_DISTANCE; - chainTable[idx & 0xFFFF] = (U16)delta; + DELTANEXTU16(idx) = (U16)delta; HashTable[h] = idx; idx++; } @@ -197,7 +197,7 @@ FORCE_INLINE int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure* hc4, /* I if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; } /* virtual matchpos */ } } - matchIndex -= chainTable[matchIndex & 0xFFFF]; + matchIndex -= DELTANEXTU16(matchIndex); } return (int)ml; @@ -274,7 +274,7 @@ FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch ( if ((int)mlt > longest) { longest = (int)mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; } } } - matchIndex -= chainTable[matchIndex & 0xFFFF]; + matchIndex -= DELTANEXTU16(matchIndex); } return longest; @@ -557,8 +557,8 @@ int LZ4_compressHC_safe(const char* source, char* dest, int inputSize, int maxOu /************************************** - * Streaming Functions - * ************************************/ +* Streaming Functions +**************************************/ /* allocation */ LZ4_streamHC_t* LZ4_createStreamHC(void) { return (LZ4_streamHC_t*)malloc(sizeof(LZ4_streamHC_t)); } int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) { free(LZ4_streamHCPtr); return 0; } @@ -671,8 +671,8 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS /*********************************** - * Deprecated Functions - ***********************************/ +* Deprecated Functions +***********************************/ /* Deprecated compression functions */ /* These functions are planned to start generate warnings by r131 approximately */ int LZ4_compressHC(const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe (src, dst, srcSize, LZ4_compressBound(srcSize), 0); } -- cgit v0.12 From 791512cfddac1dd789ebfdbf1880553a17b57ccb Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 2 May 2015 19:10:28 +0100 Subject: Fixed bug 9318 --- lib/lz4.c | 10 ++++++---- programs/fuzzer.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 538aad4..6fed55a 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -767,7 +767,8 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) const BYTE* const dictEnd = p + dictSize; const BYTE* base; - if (dict->initCheck) LZ4_resetStream(LZ4_dict); /* Uninitialized structure detected */ + if (dict->initCheck) /* Uninitialized structure detected */ + LZ4_resetStream(LZ4_dict); if (dictSize < (int)HASH_UNIT) { @@ -776,7 +777,8 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) return 0; } - if (p <= dictEnd - 64 KB) p = dictEnd - 64 KB; + if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB; + dict->currentOffset += 64 KB; base = p - dict->currentOffset; dict->dictionary = p; dict->dictSize = (U32)(dictEnd - p); @@ -784,7 +786,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) while (p <= dictEnd-HASH_UNIT) { - LZ4_putPosition(p, dict, byU32, base); + LZ4_putPosition(p, dict->hashTable, byU32, base); p+=3; } @@ -1260,7 +1262,7 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_safe(source, dest, inputSize, LZ4_compressBound(inputSize)); } int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_safe_extState(state, src, dst, srcSize, dstSize); } int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_safe_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize)); } -int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_safe_continue(LZ4_stream, source, dest, inputSize, maxOutputSize); } +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_safe_continue(LZ4_stream, src, dst, srcSize, maxDstSize); } int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_safe_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize)); } /* diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 2bf3cfe..9fd4648 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -596,7 +596,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_DISPLAYTEST; LZ4_loadDict(&LZ4dict, dict, dictSize); ret = LZ4_compress_limitedOutput_continue(&LZ4dict, block, compressedBuffer, blockSize, blockContinueCompressedSize-1); - FUZ_CHECKTEST(ret>0, "LZ4_compress_limitedOutput_continue using ExtDict should fail : one missing byte for output buffer"); + FUZ_CHECKTEST(ret>0, "LZ4_compress_limitedOutput_continue using ExtDict should fail : one missing byte for output buffer : %i written, %i buffer", ret, blockContinueCompressedSize); FUZ_DISPLAYTEST; LZ4_loadDict(&LZ4dict, dict, dictSize); -- cgit v0.12 From 1b17bf2ab8cf66dd2b740eca376e2d46f7ad7041 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 3 May 2015 17:57:46 +0100 Subject: New lz4 API, using LZ4_compress_fast() --- lib/lz4.c | 101 ++++++++++--------------- lib/lz4.h | 77 ++++++++++--------- lib/lz4frame.c | 4 +- programs/bench.c | 2 +- programs/fullbench.c | 207 ++++++++++++++++++++++++++++++--------------------- programs/lz4io.c | 2 +- 6 files changed, 207 insertions(+), 186 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 6fed55a..3c182aa 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -47,7 +47,7 @@ * ACCELERATION_DEFAULT : * Select the value of "acceleration" for LZ4_compress_fast() when parameter == 0 */ -#define ACCELERATION_DEFAULT 17 +#define ACCELERATION_DEFAULT 1 /************************************** @@ -71,12 +71,6 @@ /************************************** * Compiler Options **************************************/ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ -/* "restrict" is a known keyword */ -#else -# define restrict /* Disable restrict */ -#endif - #ifdef _MSC_VER /* Visual Studio */ # define FORCE_INLINE static __forceinline # include @@ -220,7 +214,7 @@ static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) /************************************** - Common Constants +* Common Constants **************************************/ #define MINMATCH 4 @@ -660,78 +654,64 @@ _last_literals: } -int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize) +int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, volatile int acceleration) { - MEM_INIT(state, 0, LZ4_STREAMSIZE); + LZ4_resetStream((LZ4_stream_t*)state); + if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; if (maxOutputSize >= LZ4_compressBound(inputSize)) { if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, 1); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration); else - return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); + return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); } else { if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, 1); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, 1); + return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); } } -int LZ4_compress_safe(const char* source, char* dest, int inputSize, int maxOutputSize) + +int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) { #if (HEAPMODE) - void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* malloc-calloc aligned on 8-bytes boundaries */ + void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t_internal)); /* malloc-calloc always properly aligned */ #else - U64 ctx[LZ4_STREAMSIZE_U64]; /* Ensure data is aligned on 8-bytes boundaries */ + LZ4_stream_t ctx; + void* ctxPtr = &ctx; #endif - int result = LZ4_compress_safe_extState(ctx, source, dest, inputSize, maxOutputSize); + int result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); #if (HEAPMODE) - FREEMEM(ctx); + FREEMEM(ctxPtr); #endif return result; } -int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +int LZ4_compress_default(const char* source, char* dest, int inputSize, int maxOutputSize) { - MEM_INIT(state, 0, LZ4_STREAMSIZE); - - if (acceleration == 0) - { - if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, ACCELERATION_DEFAULT); - else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, ACCELERATION_DEFAULT); - } - else - { - if (inputSize < LZ4_64Klimit) - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); - else - return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); - } + return LZ4_compress_fast(source, dest, inputSize, maxOutputSize, 1); } -int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, unsigned acceleration) +/* hidden debug function */ +/* strangely enough, gcc generates faster code when this function is uncommented, even if unused */ +int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) { -#if (HEAPMODE) - void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ -#else - U64 ctx[LZ4_STREAMSIZE_U64]; /* Ensure data is aligned on 8-bytes boundaries */ -#endif + LZ4_stream_t ctx; - int result = LZ4_compress_fast_extState(ctx, source, dest, inputSize, maxOutputSize, acceleration); + LZ4_resetStream(&ctx); -#if (HEAPMODE) - FREEMEM(ctx); -#endif - return result; + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration); } @@ -767,7 +747,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) const BYTE* const dictEnd = p + dictSize; const BYTE* base; - if (dict->initCheck) /* Uninitialized structure detected */ + if ((dict->initCheck) || (dict->currentOffset > 1 GB)) /* Uninitialized structure, or reuse overflow */ LZ4_resetStream(LZ4_dict); if (dictSize < (int)HASH_UNIT) @@ -815,7 +795,7 @@ static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src) } -int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize) +int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) { LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_stream; const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; @@ -824,6 +804,7 @@ int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_stream, const char* source, ch if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */ if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd; LZ4_renormDictT(streamPtr, smallest); + if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; /* Check overlapping input/dictionary space */ { @@ -842,9 +823,9 @@ int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_stream, const char* source, ch { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, acceleration); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, acceleration); streamPtr->dictSize += (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; return result; @@ -854,9 +835,9 @@ int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_stream, const char* source, ch { int result; if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration); else - result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, 1); + result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration); streamPtr->dictionary = (const BYTE*)source; streamPtr->dictSize = (U32)inputSize; streamPtr->currentOffset += (U32)inputSize; @@ -929,7 +910,7 @@ FORCE_INLINE int LZ4_decompress_generic( ) { /* Local Variables */ - const BYTE* restrict ip = (const BYTE*) source; + const BYTE* ip = (const BYTE*) source; const BYTE* const iend = ip + inputSize; BYTE* op = (BYTE*) dest; @@ -1258,12 +1239,12 @@ int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compres * Obsolete Functions ***************************************************/ /* obsolete compression functions */ -int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_safe(source, dest, inputSize, maxOutputSize); } -int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_safe(source, dest, inputSize, LZ4_compressBound(inputSize)); } -int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_safe_extState(state, src, dst, srcSize, dstSize); } -int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_safe_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize)); } -int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_safe_continue(LZ4_stream, src, dst, srcSize, maxDstSize); } -int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_safe_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize)); } +int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_default(source, dest, inputSize, maxOutputSize); } +int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_default(source, dest, inputSize, LZ4_compressBound(inputSize)); } +int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, dstSize, 1); } +int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize), 1); } +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_fast_continue(LZ4_stream, src, dst, srcSize, maxDstSize, 1); } +int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_fast_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize), 1); } /* These function names are deprecated and should no longer be used. diff --git a/lib/lz4.h b/lib/lz4.h index 68f43a7..b597064 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -70,11 +70,11 @@ int LZ4_versionNumber (void); * Simple Functions **************************************/ -int LZ4_compress_safe (const char* source, char* dest, int sourceSize, int maxDestSize); +int LZ4_compress_default(const char* source, char* dest, int sourceSize, int maxDestSize); int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize); /* -LZ4_compress_safe() : +LZ4_compress_default() : Compresses 'sourceSize' bytes from buffer 'source' into already allocated 'dest' buffer of size 'maxDestSize'. Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize). @@ -86,7 +86,7 @@ LZ4_compress_safe() : sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE maxDestSize : full or partial size of buffer 'dest' (which must be already allocated) return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize) - or 0 if compression fails + or 0 if compression fails LZ4_decompress_safe() : compressedSize : is obviously the source size @@ -95,7 +95,7 @@ LZ4_decompress_safe() : If the destination buffer is not large enough, decoding will stop and output an error code (<0). If the source stream is detected malformed, the function will stop decoding and return a negative result. This function is protected against buffer overflow exploits, including malicious data packets. - It never writes outside of output buffer, nor reads outside of input buffer. + It never writes outside output buffer, nor reads outside input buffer. */ @@ -108,36 +108,35 @@ LZ4_decompress_safe() : /* LZ4_compressBound() : Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible) - This function is primarily useful for memory allocation purposes (output buffer size). + This function is primarily useful for memory allocation purposes (destination buffer size). Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example). - - inputSize : max supported value is LZ4_MAX_INPUT_SIZE - return : maximum output size in a "worst case" scenario - or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) + Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize) + inputSize : max supported value is LZ4_MAX_INPUT_SIZE + return : maximum output size in a "worst case" scenario + or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) */ int LZ4_compressBound(int inputSize); /* -LZ4_compress_safe_extState() : - Same compression function, just using an externally allocated memory space to store compression state. - Use LZ4_sizeofState() to know how much memory must be allocated, - and then, provide it as 'void* state' to compression functions. - Note that 'state' ptr must be aligned on 4-bytes boundaries. +LZ4_compress_fast() : + Same as LZ4_compress_default(), but allows to select an "acceleration" factor. + The larger the acceleration value, the faster the algorithm, but also the lesser the compression. + It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed. + An acceleration value of "0" means "use Default value" (see lz4.c) + An acceleration value of "1" is the same as regular LZ4_compress_default() */ -int LZ4_sizeofState(void); -int LZ4_compress_safe_extState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, int acceleration); + /* -LZ4_compress_fast() : - Same as LZ4_compress_safe(), but allows to select an "acceleration" factor. - The larger the acceleration value, the faster the algorithm, but also the lesser the compression. - It's a trade-off. It can be fine tuned, with each successive value providing an additional +2/3% to speed. - An acceleration value of "0" means "use Default value", which is typically 17 (see lz4.c source code). - An acceleration value of "1" is the same as regular LZ4_compress_safe() - Note : this function is "safe", even if its name does not explicitly contain the word. It's just faster and compress less. +LZ4_compress_fast_extState() : + Same compression function, just using an externally allocated memory space to store compression state. + Use LZ4_sizeofState() to know how much memory must be allocated, + and allocate it on 8-bytes boundaries (using malloc() typically). + Then, provide it as 'void* state' to compression function. */ -int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, unsigned acceleration); -int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, unsigned acceleration); +int LZ4_sizeofState(void); +int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, int acceleration); /* @@ -186,7 +185,7 @@ typedef struct { long long table[LZ4_STREAMSIZE_U64]; } LZ4_stream_t; * LZ4_resetStream * Use this function to init an allocated LZ4_stream_t structure */ -void LZ4_resetStream (LZ4_stream_t* LZ4_streamPtr); +void LZ4_resetStream (LZ4_stream_t* streamPtr); /* * LZ4_createStream will allocate and initialize an LZ4_stream_t structure @@ -195,7 +194,7 @@ void LZ4_resetStream (LZ4_stream_t* LZ4_streamPtr); * They are more future proof, in case of a change of LZ4_stream_t size. */ LZ4_stream_t* LZ4_createStream(void); -int LZ4_freeStream (LZ4_stream_t* LZ4_streamPtr); +int LZ4_freeStream (LZ4_stream_t* streamPtr); /* * LZ4_loadDict @@ -204,27 +203,27 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_streamPtr); * Loading a size of 0 is allowed. * Return : dictionary size, in bytes (necessarily <= 64 KB) */ -int LZ4_loadDict (LZ4_stream_t* LZ4_streamPtr, const char* dictionary, int dictSize); +int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize); /* - * LZ4_compress_safe_continue - * Compress data block 'source', using data from previous blocks to improve compression ratio. + * LZ4_compress_fast_continue + * Compress buffer content 'src', using data from previously compressed blocks as dictionary to improve compression ratio. * Important : Previous data blocks are assumed to still be present and unmodified ! - * dest buffer must be already allocated. - * if maxOutpuSize >= (inputSize), compression is guaranteed to succeed. - * if not, and if target size objective cannot be met, compression stops, and function returns a zero. + * 'dst' buffer must be already allocated. + * If maxDstSize >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster. + * If not, and if compressed data cannot fit into 'dst' buffer size, compression stops, and function returns a zero. */ -int LZ4_compress_safe_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int maxDstSize, int acceleration); /* * LZ4_saveDict * If previously compressed data block is not guaranteed to remain available at its memory location * save it into a safer place (char* safeBuffer) * Note : you don't need to call LZ4_loadDict() afterwards, - * dictionary is immediately usable, you can therefore call again LZ4_compress_continue() + * dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue() * Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error */ -int LZ4_saveDict (LZ4_stream_t* LZ4_streamPtr, char* safeBuffer, int dictSize); +int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize); /************************************************ @@ -310,7 +309,7 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS # pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") # define LZ4_DEPRECATED(message) # endif -#endif // LZ4_DEPRECATE_WARNING_DEFBLOCK +#endif /* LZ4_DEPRECATE_WARNING_DEFBLOCK */ /* Obsolete compression functions */ /* These functions are planned to start generate warnings by r131 approximately */ @@ -338,8 +337,8 @@ LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); /* Obsolete streaming decoding functions */ -LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize); -LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize); +LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize); +LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize); #if defined (__cplusplus) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 5fad2e8..408e871 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -515,13 +515,13 @@ static size_t LZ4F_compressBlock(void* dst, const void* src, size_t srcSize, com static int LZ4F_localLZ4_compress_limitedOutput_withState(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) { (void) level; - return LZ4_compress_safe_extState(ctx, src, dst, srcSize, dstSize); + return LZ4_compress_limitedOutput_withState(ctx, src, dst, srcSize, dstSize); } static int LZ4F_localLZ4_compress_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) { (void) level; - return LZ4_compress_safe_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstSize); + return LZ4_compress_limitedOutput_continue((LZ4_stream_t*)ctx, src, dst, srcSize, dstSize); } static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) diff --git a/programs/bench.c b/programs/bench.c index 384a425..3a93cf9 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -58,7 +58,7 @@ #include "lz4.h" #define COMPRESSOR0 LZ4_compress_local -static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { (void)clevel; return LZ4_compress_safe(src, dst, srcSize, dstSize); } +static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { (void)clevel; return LZ4_compress_default(src, dst, srcSize, dstSize); } #include "lz4hc.h" #define COMPRESSOR1 LZ4_compressHC_safe #define DEFAULTCOMPRESSOR COMPRESSOR0 diff --git a/programs/fullbench.c b/programs/fullbench.c index ed53819..0d08a40 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -30,7 +30,7 @@ #define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_DEPRECATE /* VS2005 */ -// Unix Large Files support (>4GB) +/* Unix Large Files support (>4GB) */ #if (defined(__sun__) && (!defined(__LP64__))) // Sun Solaris 32-bits requires specific definitions # define _LARGEFILE_SOURCE # define _FILE_OFFSET_BITS 64 @@ -47,17 +47,17 @@ /************************************** * Includes **************************************/ -#include // malloc -#include // fprintf, fopen, ftello64 -#include // stat64 -#include // stat64 -#include // strcmp +#include /* malloc, free */ +#include /* fprintf, fopen, ftello64 */ +#include /* stat64 */ +#include /* stat64 */ +#include /* strcmp */ -// Use ftime() if gettimeofday() is not available on your target +/* Use ftime() if gettimeofday() is not available on your target */ #if defined(BMK_LEGACY_TIMER) -# include // timeb, ftime +# include /* timeb, ftime */ #else -# include // gettimeofday +# include /* gettimeofday */ #endif #include "lz4.h" @@ -75,16 +75,11 @@ # define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) #endif -// GCC does not support _rotl outside of Windows -#if !defined(_WIN32) -# define _rotl(x,r) ((x << r) | (x >> (32 - r))) -#endif - /************************************** * Basic Types **************************************/ -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L // C99 +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ # include typedef uint8_t BYTE; typedef uint16_t U16; @@ -118,7 +113,7 @@ #define GB *(1U<<30) #define KNUTH 2654435761U -#define MAX_MEM (1984 MB) +#define MAX_MEM (1920 MB) #define DEFAULT_CHUNKSIZE (4 MB) #define ALL_COMPRESSORS 0 @@ -139,42 +134,42 @@ struct chunkParameters /************************************** -* MACRO +* Macros **************************************/ #define DISPLAY(...) fprintf(stderr, __VA_ARGS__) -#define PROGRESS(...) no_prompt ? 0 : DISPLAY(__VA_ARGS__) - +#define PROGRESS(...) g_noPrompt ? 0 : DISPLAY(__VA_ARGS__) /************************************** * Benchmark Parameters **************************************/ -static int chunkSize = DEFAULT_CHUNKSIZE; -static int nbIterations = NBLOOPS; -static int BMK_pause = 0; -static int compressionTest = 1; -static int decompressionTest = 1; -static int compressionAlgo = ALL_COMPRESSORS; -static int decompressionAlgo = ALL_DECOMPRESSORS; -static int no_prompt = 0; +static int g_chunkSize = DEFAULT_CHUNKSIZE; +static int g_nbIterations = NBLOOPS; +static int g_pause = 0; +static int g_compressionTest = 1; +static int g_compressionAlgo = ALL_COMPRESSORS; +static int g_decompressionTest = 1; +static int g_decompressionAlgo = ALL_DECOMPRESSORS; +static int g_noPrompt = 0; -void BMK_SetBlocksize(int bsize) +static void BMK_setBlocksize(int bsize) { - chunkSize = bsize; - DISPLAY("-Using Block Size of %i KB-\n", chunkSize>>10); + g_chunkSize = bsize; + DISPLAY("-Using Block Size of %i KB-\n", g_chunkSize>>10); } -void BMK_SetNbIterations(int nbLoops) +static void BMK_setNbIterations(int nbLoops) { - nbIterations = nbLoops; - DISPLAY("- %i iterations -\n", nbIterations); + g_nbIterations = nbLoops; + DISPLAY("- %i iterations -\n", g_nbIterations); } -void BMK_SetPause(void) +static void BMK_setPause(void) { - BMK_pause = 1; + g_pause = 1; } + /********************************************************* * Private functions *********************************************************/ @@ -253,7 +248,7 @@ static U64 BMK_GetFileSize(char* infilename) struct stat statbuf; r = stat(infilename, &statbuf); #endif - if (r || !S_ISREG(statbuf.st_mode)) return 0; // No good... + if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */ return (U64)statbuf.st_size; } @@ -403,11 +398,46 @@ static int local_LZ4_compress_limitedOutput(const char* in, char* out, int inSiz return LZ4_compress_limitedOutput(in, out, inSize, LZ4_compressBound(inSize)-1); } -static int local_LZ4_compress_fast(const char* in, char* out, int inSize) +static int local_LZ4_compress_default_large(const char* in, char* out, int inSize) +{ + return LZ4_compress_default(in, out, inSize, LZ4_compressBound(inSize)); +} + +static int local_LZ4_compress_default_small(const char* in, char* out, int inSize) +{ + return LZ4_compress_default(in, out, inSize, LZ4_compressBound(inSize)-1); +} + +static int local_LZ4_compress_fast0(const char* in, char* out, int inSize) { return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 0); } +static int local_LZ4_compress_fast1(const char* in, char* out, int inSize) +{ + return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 1); +} + +static int local_LZ4_compress_fast2(const char* in, char* out, int inSize) +{ + return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 2); +} + +static int local_LZ4_compress_fast17(const char* in, char* out, int inSize) +{ + return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 17); +} + +static int local_LZ4_compress_fast_extState0(const char* in, char* out, int inSize) +{ + return LZ4_compress_fast_extState(&LZ4_stream, in, out, inSize, LZ4_compressBound(inSize), 0); +} + +static int local_LZ4_compress_fast_continue0(const char* in, char* out, int inSize) +{ + return LZ4_compress_fast_continue(&LZ4_stream, in, out, inSize, LZ4_compressBound(inSize), 0); +} + static int local_LZ4_compress_withState(const char* in, char* out, int inSize) { return LZ4_compress_withState(&LZ4_stream, in, out, inSize); @@ -575,10 +605,10 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); /* Allocation */ - chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters)); + chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)g_chunkSize)+1) * sizeof(struct chunkParameters)); orig_buff = (char*) malloc(benchedSize); - nbChunks = (int) ((benchedSize + (chunkSize-1)) / chunkSize); - maxCompressedChunkSize = LZ4_compressBound(chunkSize); + nbChunks = (int) ((benchedSize + (g_chunkSize-1)) / g_chunkSize); + maxCompressedChunkSize = LZ4_compressBound(g_chunkSize); compressedBuffSize = nbChunks * maxCompressedChunkSize; compressed_buff = (char*)malloc((size_t)compressedBuffSize); if(!chunkP || !orig_buff || !compressed_buff) @@ -619,7 +649,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) DISPLAY(" %s : \n", inFileName); /* Bench Compression Algorithms */ - for (cAlgNb=1; (cAlgNb <= NB_COMPRESSION_ALGORITHMS) && (compressionTest); cAlgNb++) + for (cAlgNb=0; (cAlgNb <= NB_COMPRESSION_ALGORITHMS) && (g_compressionTest); cAlgNb++) { const char* compressorName; int (*compressionFunction)(const char*, char*, int); @@ -627,7 +657,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) double bestTime = 100000000.; /* filter compressionAlgo only */ - if ((compressionAlgo != ALL_COMPRESSORS) && (compressionAlgo != cAlgNb)) continue; + if ((g_compressionAlgo != ALL_COMPRESSORS) && (g_compressionAlgo != cAlgNb)) continue; /* Init data chunks */ { @@ -635,12 +665,12 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) size_t remaining = benchedSize; char* in = orig_buff; char* out = compressed_buff; - nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); + nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize); for (i=0; i chunkSize) { chunkP[i].origSize = chunkSize; remaining -= chunkSize; } else { chunkP[i].origSize = (int)remaining; remaining = 0; } + 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; } chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize; chunkP[i].compressedSize = 0; } @@ -648,34 +678,44 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) switch(cAlgNb) { - case 1 : compressionFunction = LZ4_compress; compressorName = "LZ4_compress"; break; - case 2 : compressionFunction = local_LZ4_compress_limitedOutput; compressorName = "LZ4_compress_limitedOutput"; break; - case 3 : compressionFunction = local_LZ4_compress_withState; compressorName = "LZ4_compress_withState"; break; - case 4 : compressionFunction = local_LZ4_compress_limitedOutput_withState; compressorName = "LZ4_compress_limitedOutput_withState"; break; - case 5 : compressionFunction = local_LZ4_compress_continue; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_continue"; break; - case 6 : compressionFunction = local_LZ4_compress_limitedOutput_continue; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_limitedOutput_continue"; break; - case 7 : compressionFunction = local_LZ4_compress_fast; compressorName = "LZ4_compress_fast"; break; - case 8 : compressionFunction = LZ4_compressHC; compressorName = "LZ4_compressHC"; break; - case 9 : compressionFunction = local_LZ4_compressHC_limitedOutput; compressorName = "LZ4_compressHC_limitedOutput"; break; - case 10 : compressionFunction = local_LZ4_compressHC_withStateHC; compressorName = "LZ4_compressHC_withStateHC"; break; - case 11: compressionFunction = local_LZ4_compressHC_limitedOutput_withStateHC; compressorName = "LZ4_compressHC_limitedOutput_withStateHC"; break; - case 12: compressionFunction = local_LZ4_compressHC_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compressHC_continue"; break; - case 13: compressionFunction = local_LZ4_compressHC_limitedOutput_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compressHC_limitedOutput_continue"; break; - case 14: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break; - case 15: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame"; + case 0 : DISPLAY("Compression functions : \n"); continue; + case 1 : compressionFunction = local_LZ4_compress_default_large; compressorName = "LZ4_compress_default"; break; + case 2 : compressionFunction = local_LZ4_compress_default_small; compressorName = "LZ4_compress_default(small dst)"; break; + case 3 : compressionFunction = local_LZ4_compress_fast0; compressorName = "LZ4_compress_fast(0)"; break; + case 4 : compressionFunction = local_LZ4_compress_fast1; compressorName = "LZ4_compress_fast(1)"; break; + case 5 : compressionFunction = local_LZ4_compress_fast2; compressorName = "LZ4_compress_fast(2)"; break; + case 6 : compressionFunction = local_LZ4_compress_fast17; compressorName = "LZ4_compress_fast(17)"; break; + case 7 : compressionFunction = local_LZ4_compress_fast_extState0; compressorName = "LZ4_compress_fast_extState(0)"; break; + case 8 : compressionFunction = local_LZ4_compress_fast_continue0; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_fast_continue(0)"; break; + + case 10: compressionFunction = LZ4_compressHC; compressorName = "LZ4_compressHC"; break; + case 11: compressionFunction = local_LZ4_compressHC_limitedOutput; compressorName = "LZ4_compressHC_limitedOutput"; break; + case 12 : compressionFunction = local_LZ4_compressHC_withStateHC; compressorName = "LZ4_compressHC_withStateHC"; break; + case 13: compressionFunction = local_LZ4_compressHC_limitedOutput_withStateHC; compressorName = "LZ4_compressHC_limitedOutput_withStateHC"; break; + case 14: compressionFunction = local_LZ4_compressHC_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compressHC_continue"; break; + case 15: compressionFunction = local_LZ4_compressHC_limitedOutput_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compressHC_limitedOutput_continue"; break; + case 20: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break; + case 30: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame"; chunkP[0].origSize = (int)benchedSize; nbChunks=1; break; - case 16: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict"; + case 40: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict"; LZ4_loadDict(&LZ4_stream, chunkP[0].origBuffer, chunkP[0].origSize); break; - case 17: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC"; + case 41: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC"; LZ4_loadDictHC(&LZ4_streamHC, chunkP[0].origBuffer, chunkP[0].origSize); break; + case 60: DISPLAY("Obsolete compression functions : \n"); continue; + case 61: compressionFunction = LZ4_compress; compressorName = "LZ4_compress"; break; + case 62: compressionFunction = local_LZ4_compress_limitedOutput; compressorName = "LZ4_compress_limitedOutput"; break; + case 63: compressionFunction = local_LZ4_compress_withState; compressorName = "LZ4_compress_withState"; break; + case 64: compressionFunction = local_LZ4_compress_limitedOutput_withState; compressorName = "LZ4_compress_limitedOutput_withState"; break; + case 65: compressionFunction = local_LZ4_compress_continue; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_continue"; break; + case 66: compressionFunction = local_LZ4_compress_limitedOutput_continue; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_limitedOutput_continue"; break; default : continue; /* unknown ID : just skip */ } - for (loopNb = 1; loopNb <= nbIterations; loopNb++) + for (loopNb = 1; loopNb <= g_nbIterations; loopNb++) { double averageTime; int milliTime; @@ -721,12 +761,12 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) char* in = orig_buff; char* out = compressed_buff; - nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize); + nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize); for (i=0; i chunkSize) { chunkP[i].origSize = chunkSize; remaining -= chunkSize; } else { chunkP[i].origSize = (int)remaining; remaining = 0; } + 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; } chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize; chunkP[i].compressedSize = 0; } @@ -738,16 +778,17 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) } /* Decompression Algorithms */ - for (dAlgNb=1; (dAlgNb <= NB_DECOMPRESSION_ALGORITHMS) && (decompressionTest); dAlgNb++) + for (dAlgNb=0; (dAlgNb <= NB_DECOMPRESSION_ALGORITHMS) && (g_decompressionTest); dAlgNb++) { const char* dName; int (*decompressionFunction)(const char*, char*, int, int); double bestTime = 100000000.; - if ((decompressionAlgo != ALL_DECOMPRESSORS) && (decompressionAlgo != dAlgNb)) continue; + if ((g_decompressionAlgo != ALL_DECOMPRESSORS) && (g_decompressionAlgo != dAlgNb)) continue; switch(dAlgNb) { + case 0: DISPLAY("Decompression functions : \n"); continue; case 1: decompressionFunction = local_LZ4_decompress_fast; dName = "LZ4_decompress_fast"; break; case 3: decompressionFunction = local_LZ4_decompress_fast_usingDict; dName = "LZ4_decompress_fast_usingDict"; break; case 4: decompressionFunction = LZ4_decompress_safe; dName = "LZ4_decompress_safe"; break; @@ -774,7 +815,7 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles) { size_t i; for (i=0; i= '0') && (argument[1]<= '9')) { - compressionAlgo *= 10; - compressionAlgo += argument[1] - '0'; + g_compressionAlgo *= 10; + g_compressionAlgo += argument[1] - '0'; argument++; } break; // Select decompression algorithm only case 'd': - compressionTest = 0; + g_compressionTest = 0; while ((argument[1]>= '0') && (argument[1]<= '9')) { - decompressionAlgo *= 10; - decompressionAlgo += argument[1] - '0'; + g_decompressionAlgo *= 10; + g_decompressionAlgo += argument[1] - '0'; argument++; } break; @@ -921,7 +962,7 @@ int main(int argc, char** argv) { int B = argument[1] - '0'; int S = 1 << (8 + 2*B); - BMK_SetBlocksize(S); + BMK_setBlocksize(S); argument++; break; } @@ -936,13 +977,13 @@ _exit_blockProperties: if ((argument[1] >='0') && (argument[1] <='9')) { int iters = argument[1] - '0'; - BMK_SetNbIterations(iters); + BMK_setNbIterations(iters); argument++; } break; // Pause at the end (hidden option) - case 'p': BMK_SetPause(); break; + case 'p': BMK_setPause(); break; // Unknown command default : badusage(exename); return 1; diff --git a/programs/lz4io.c b/programs/lz4io.c index fb1f428..16fc879 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -325,7 +325,7 @@ static void LZ4IO_writeLE32 (void* p, unsigned value32) static int LZ4IO_LZ4_compress(const char* src, char* dst, int srcSize, int dstSize, int cLevel) { (void)cLevel; - return LZ4_compress_safe(src, dst, srcSize, dstSize); + return LZ4_compress_fast(src, dst, srcSize, dstSize, 1); } /* LZ4IO_compressFilename_Legacy : -- cgit v0.12 From 1171303a4ff6566f7f9d4b1f91d4d73f0bf00584 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 3 May 2015 18:02:48 +0100 Subject: Updated streaming examples --- examples/blockStreaming_doubleBuffer.c | 4 ++-- examples/blockStreaming_lineByLine.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/blockStreaming_doubleBuffer.c b/examples/blockStreaming_doubleBuffer.c index 58f2bdb..59355da 100644 --- a/examples/blockStreaming_doubleBuffer.c +++ b/examples/blockStreaming_doubleBuffer.c @@ -53,8 +53,8 @@ void test_compress(FILE* outFp, FILE* inpFp) { char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)]; - const int cmpBytes = LZ4_compress_safe_continue( - lz4Stream, inpPtr, cmpBuf, inpBytes, sizeof(cmpBuf)); + const int cmpBytes = LZ4_compress_fast_continue( + lz4Stream, inpPtr, cmpBuf, inpBytes, sizeof(cmpBuf), 1); if(cmpBytes <= 0) { break; } diff --git a/examples/blockStreaming_lineByLine.c b/examples/blockStreaming_lineByLine.c index 8ae268f..c4fd2e3 100644 --- a/examples/blockStreaming_lineByLine.c +++ b/examples/blockStreaming_lineByLine.c @@ -64,8 +64,8 @@ static void test_compress( #endif { - const int cmpBytes = LZ4_compress_safe_continue( - lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes); + const int cmpBytes = LZ4_compress_fast_continue( + lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes, 1); if (cmpBytes <= 0) break; write_uint16(outFp, (uint16_t) cmpBytes); write_bin(outFp, cmpBuf, cmpBytes); -- cgit v0.12 From b4348a47189f7bce93537a85906d26b09be7e802 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 3 May 2015 18:06:01 +0100 Subject: Fixed minor Visual warning --- lib/lz4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4.c b/lib/lz4.c index 3c182aa..bb40f76 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -654,7 +654,7 @@ _last_literals: } -int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, volatile int acceleration) +int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) { LZ4_resetStream((LZ4_stream_t*)state); if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; -- cgit v0.12 From e05088d0eb500d8d673e081929620e538df3d718 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 3 May 2015 20:57:21 +0100 Subject: Updated lz4hc API --- examples/Makefile | 25 +++----- examples/blockStreaming_doubleBuffer.c | 8 ++- examples/blockStreaming_lineByLine.c | 12 ++-- lib/lz4frame.c | 4 +- lib/lz4hc.c | 37 ++++++------ lib/lz4hc.h | 107 +++++++++++++++++---------------- programs/bench.c | 2 +- programs/lz4io.c | 2 +- 8 files changed, 97 insertions(+), 100 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index 0c4cf13..808b511 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,6 +1,7 @@ # ########################################################################## # LZ4 examples - Makefile # Copyright (C) Yann Collet 2011-2014 +# # GPL v2 License # # This program is free software; you can redistribute it and/or modify @@ -21,29 +22,17 @@ # - LZ4 source repository : http://code.google.com/p/lz4/ # - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c # ########################################################################## -# lz4 : Command Line Utility, supporting gzip-like arguments -# lz4c : CLU, supporting also legacy lz4demo arguments -# lz4c32: Same as lz4c, but forced to compile in 32-bits mode -# fuzzer : Test tool, to check lz4 integrity on target platform -# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode -# fullbench : Precisely measure speed for each LZ4 function variant -# fullbench32: Same as fullbench, but forced to compile in 32-bits mode +# This makefile compile and test +# example programs, using (mostly) LZ4 streaming library, +# kindly provided by Takayuki Matsuoka # ########################################################################## -CC := $(CC) CFLAGS ?= -O3 -CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -Wno-missing-braces # Wno-missing-braces required due to GCC <4.8.3 bug -FLAGS = -I../lib $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) +CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes +FLAGS := -I../lib $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) TESTFILE= Makefile -LZ4DIR = ../lib - - -# Minimize test target for Travis CI's Build Matrix -ifeq ($(LZ4_TRAVIS_CI_ENV),-m32) -CFLAGS += -m32 -else ifeq ($(LZ4_TRAVIS_CI_ENV),-m64) -endif +LZ4DIR := ../lib # Define *.exe as extension for Windows systems diff --git a/examples/blockStreaming_doubleBuffer.c b/examples/blockStreaming_doubleBuffer.c index 59355da..efe6fc6 100644 --- a/examples/blockStreaming_doubleBuffer.c +++ b/examples/blockStreaming_doubleBuffer.c @@ -38,11 +38,13 @@ size_t read_bin(FILE* fp, void* array, size_t arrayBytes) { void test_compress(FILE* outFp, FILE* inpFp) { - LZ4_stream_t lz4Stream_body = { 0 }; + LZ4_stream_t lz4Stream_body; LZ4_stream_t* lz4Stream = &lz4Stream_body; char inpBuf[2][BLOCK_BYTES]; int inpBufIndex = 0; + + LZ4_resetStream(lz4Stream); for(;;) { char* const inpPtr = inpBuf[inpBufIndex]; @@ -71,12 +73,14 @@ void test_compress(FILE* outFp, FILE* inpFp) void test_decompress(FILE* outFp, FILE* inpFp) { - LZ4_streamDecode_t lz4StreamDecode_body = { 0 }; + LZ4_streamDecode_t lz4StreamDecode_body; LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body; char decBuf[2][BLOCK_BYTES]; int decBufIndex = 0; + LZ4_setStreamDecode(lz4StreamDecode, NULL, 0); + for(;;) { char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)]; int cmpBytes = 0; diff --git a/examples/blockStreaming_lineByLine.c b/examples/blockStreaming_lineByLine.c index c4fd2e3..f449aa3 100644 --- a/examples/blockStreaming_lineByLine.c +++ b/examples/blockStreaming_lineByLine.c @@ -42,8 +42,8 @@ static void test_compress( { LZ4_stream_t* const lz4Stream = LZ4_createStream(); const size_t cmpBufBytes = LZ4_COMPRESSBOUND(messageMaxBytes); - char* const cmpBuf = malloc(cmpBufBytes); - char* const inpBuf = malloc(ringBufferBytes); + char* const cmpBuf = (char*) malloc(cmpBufBytes); + char* const inpBuf = (char*) malloc(ringBufferBytes); int inpOffset = 0; for ( ; ; ) @@ -90,8 +90,8 @@ static void test_decompress( size_t ringBufferBytes) { LZ4_streamDecode_t* const lz4StreamDecode = LZ4_createStreamDecode(); - char* const cmpBuf = malloc(LZ4_COMPRESSBOUND(messageMaxBytes)); - char* const decBuf = malloc(ringBufferBytes); + char* const cmpBuf = (char*) malloc(LZ4_COMPRESSBOUND(messageMaxBytes)); + char* const decBuf = (char*) malloc(ringBufferBytes); int decOffset = 0; for ( ; ; ) @@ -125,8 +125,8 @@ static int compare(FILE* f0, FILE* f1) { int result = 0; const size_t tempBufferBytes = 65536; - char* const b0 = malloc(tempBufferBytes); - char* const b1 = malloc(tempBufferBytes); + char* const b0 = (char*) malloc(tempBufferBytes); + char* const b1 = (char*) malloc(tempBufferBytes); while(0 == result) { diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 408e871..d73436c 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -527,7 +527,7 @@ static int LZ4F_localLZ4_compress_limitedOutput_continue(void* ctx, const char* static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char* src, char* dst, int srcSize, int dstSize, int level) { (void) level; - return LZ4_compressHC_safe_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize); + return LZ4_compress_HC_continue((LZ4_streamHC_t*)ctx, src, dst, srcSize, dstSize); } static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int level) @@ -537,7 +537,7 @@ static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int lev if (blockMode == LZ4F_blockIndependent) return LZ4F_localLZ4_compress_limitedOutput_withState; return LZ4F_localLZ4_compress_limitedOutput_continue; } - if (blockMode == LZ4F_blockIndependent) return LZ4_compressHC_safe_extStateHC; + if (blockMode == LZ4F_blockIndependent) return LZ4_compress_HC_extStateHC; return LZ4F_localLZ4_compressHC_limitedOutput_continue; } diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 1db3d98..fa05ee3 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -538,20 +538,20 @@ _Search3: int LZ4_sizeofStateHC(void) { return sizeof(LZ4HC_Data_Structure); } -int LZ4_compressHC_safe_extStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) +int LZ4_compress_HC_extStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel) { if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */ - LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)source); - if (maxOutputSize < LZ4_compressBound(inputSize)) - return LZ4HC_compress_generic (state, source, dest, inputSize, maxOutputSize, compressionLevel, limitedOutput); + LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)src); + if (maxDstSize < LZ4_compressBound(srcSize)) + return LZ4HC_compress_generic (state, src, dst, srcSize, maxDstSize, compressionLevel, limitedOutput); else - return LZ4HC_compress_generic (state, source, dest, inputSize, maxOutputSize, compressionLevel, noLimit); + return LZ4HC_compress_generic (state, src, dst, srcSize, maxDstSize, compressionLevel, noLimit); } -int LZ4_compressHC_safe(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) +int LZ4_compress_HC(const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel) { LZ4HC_Data_Structure state; - return LZ4_compressHC_safe_extStateHC(&state, source, dest, inputSize, maxOutputSize, compressionLevel); + return LZ4_compress_HC_extStateHC(&state, src, dst, srcSize, maxDstSize, compressionLevel); } @@ -639,7 +639,7 @@ static int LZ4_compressHC_continue_generic (LZ4HC_Data_Structure* ctxPtr, return LZ4HC_compress_generic (ctxPtr, source, dest, inputSize, maxOutputSize, ctxPtr->compressionLevel, limit); } -int LZ4_compressHC_safe_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize) +int LZ4_compress_HC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize) { if (maxOutputSize < LZ4_compressBound(inputSize)) return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, limitedOutput); @@ -675,19 +675,20 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS ***********************************/ /* Deprecated compression functions */ /* These functions are planned to start generate warnings by r131 approximately */ -int LZ4_compressHC(const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe (src, dst, srcSize, LZ4_compressBound(srcSize), 0); } -int LZ4_compressHC_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe(src, dst, srcSize, maxDstSize, 0); } -int LZ4_compressHC2(const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compressHC_safe (src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } -int LZ4_compressHC2_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compressHC_safe(src, dst, srcSize, maxDstSize, cLevel); } -int LZ4_compressHC_withStateHC (void* state, const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe_extStateHC (state, src, dst, srcSize, LZ4_compressBound(srcSize), 0); } -int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe_extStateHC (state, src, dst, srcSize, maxDstSize, 0); } -int LZ4_compressHC2_withStateHC (void* state, const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compressHC_safe_extStateHC(state, src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } -int LZ4_compressHC2_limitedOutput_withStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compressHC_safe_extStateHC(state, src, dst, srcSize, maxDstSize, cLevel); } -int LZ4_compressHC_continue (LZ4_streamHC_t* ctx, const char* src, char* dst, int srcSize) { return LZ4_compressHC_safe_continue (ctx, src, dst, srcSize, LZ4_compressBound(srcSize)); } -int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* ctx, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compressHC_safe_continue (ctx, src, dst, srcSize, maxDstSize); } +int LZ4_compressHC(const char* src, char* dst, int srcSize) { return LZ4_compress_HC (src, dst, srcSize, LZ4_compressBound(srcSize), 0); } +int LZ4_compressHC_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_HC(src, dst, srcSize, maxDstSize, 0); } +int LZ4_compressHC2(const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compress_HC (src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } +int LZ4_compressHC2_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compress_HC(src, dst, srcSize, maxDstSize, cLevel); } +int LZ4_compressHC_withStateHC (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_HC_extStateHC (state, src, dst, srcSize, LZ4_compressBound(srcSize), 0); } +int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_HC_extStateHC (state, src, dst, srcSize, maxDstSize, 0); } +int LZ4_compressHC2_withStateHC (void* state, const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compress_HC_extStateHC(state, src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); } +int LZ4_compressHC2_limitedOutput_withStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compress_HC_extStateHC(state, src, dst, srcSize, maxDstSize, cLevel); } +int LZ4_compressHC_continue (LZ4_streamHC_t* ctx, const char* src, char* dst, int srcSize) { return LZ4_compress_HC_continue (ctx, src, dst, srcSize, LZ4_compressBound(srcSize)); } +int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* ctx, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_HC_continue (ctx, src, dst, srcSize, maxDstSize); } /* Deprecated streaming functions */ +/* These functions currently generate deprecation warnings */ int LZ4_sizeofStreamStateHC(void) { return LZ4_STREAMHCSIZE; } int LZ4_resetStreamStateHC(void* state, const char* inputBuffer) diff --git a/lib/lz4hc.h b/lib/lz4hc.h index 2667044..f8461b4 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -47,18 +47,18 @@ extern "C" { /************************************** * Block Compression **************************************/ -int LZ4_compressHC_safe (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); +int LZ4_compress_HC (const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel); /* -LZ4_compressHC_safe : - return : the number of bytes in compressed buffer dest - or 0 if compression fails. - note : destination buffer must be already allocated. - To guarantee compression completion, size it to handle worst cases situations (data not compressible) - Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h") - inputSize : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h") - compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work. - 0 means use default 'compressionLevel' value. - Values >16 behave the same as 16. +LZ4_compress_HC : + Destination buffer 'dst' must be already allocated. + Compression completion is guaranteed if 'dst' buffer is sized to handle worst circumstances (data not compressible) + Worst size evaluation is provided by function LZ4_compressBound() (see "lz4.h") + srcSize : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h") + compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work. + 0 means "use default value" (see lz4hc.c). + Values >16 behave the same as 16. + return : the number of bytes written into buffer 'dst' + or 0 if compression fails. */ @@ -68,18 +68,18 @@ LZ4_compressHC_safe : int LZ4_sizeofStateHC(void); -int LZ4_compressHC_safe_extStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); - +int LZ4_compress_HC_extStateHC(void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel); /* -This function is provided should you prefer to allocate memory for compression tables with your own allocation methods. -To know how much memory must be allocated for the compression tables, use : -int LZ4_sizeofStateHC(); +LZ4_compress_HC_extStateHC() : + Use this function if you prefer to manually allocate memory for compression tables. + To know how much memory must be allocated for the compression tables, use : + int LZ4_sizeofStateHC(); -Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0). + Allocated memory must be aligned on 8-bytes boundaries (which a normal malloc() will do properly). -The allocated memory can be provided to the compression functions using 'void* state' parameter. -LZ4_compressHC_safe_extStateHC() is equivalent to previously described function. -It just uses externally allocated memory for stateHC instead of allocating their own (on stack, or on heap). + The allocated memory can then be provided to the compression functions using 'void* state' parameter. + LZ4_compress_HC_extStateHC() is equivalent to previously described function. + It just uses externally allocated memory for stateHC. */ @@ -90,53 +90,56 @@ It just uses externally allocated memory for stateHC instead of allocating their #define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t)) typedef struct { size_t table[LZ4_STREAMHCSIZE_SIZET]; } LZ4_streamHC_t; /* -LZ4_streamHC_t -This structure allows static allocation of LZ4 HC streaming state. -State must then be initialized using LZ4_resetStreamHC() before first use. + LZ4_streamHC_t + This structure allows static allocation of LZ4 HC streaming state. + State must then be initialized using LZ4_resetStreamHC() before first use. -Static allocation should only be used with statically linked library. -If you want to use LZ4 as a DLL, please use construction functions below, which are more future-proof. + Static allocation should only be used in combination with static linking. + If you want to use LZ4 as a DLL, please use construction functions below, which are future-proof. */ LZ4_streamHC_t* LZ4_createStreamHC(void); -int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr); +int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr); /* -These functions create and release memory for LZ4 HC streaming state. -Newly created states are already initialized. -Existing state space can be re-used anytime using LZ4_resetStreamHC(). -If you use LZ4 as a DLL, please use these functions instead of direct struct allocation, -to avoid size mismatch between different versions. + These functions create and release memory for LZ4 HC streaming state. + Newly created states are already initialized. + Existing state space can be re-used anytime using LZ4_resetStreamHC(). + If you use LZ4 as a DLL, use these functions instead of static structure allocation, + to avoid size mismatch between different versions. */ -void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel); -int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int dictSize); +void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel); +int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize); -int LZ4_compressHC_safe_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); +int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr, const char* src, char* dst, int srcSize, int maxDstSize); -int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int maxDictSize); +int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize); /* -These functions compress data in successive blocks of any size, using previous blocks as dictionary. -One key assumption is that each previous block will remain read-accessible while compressing next block. - -Before starting compression, state must be properly initialized, using LZ4_resetStreamHC(). -A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional). - -Then, use LZ4_compressHC_safe_continue() to compress each successive block. -It works like LZ4_compressHC_safe(), but use previous memory blocks to improve compression. -Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression. - -If, for any reason, previous data block can't be preserved in memory during next compression block, -you must save it to a safer memory space, -using LZ4_saveDictHC(). + These functions compress data in successive blocks of any size, using previous blocks as dictionary. + One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks. + There is an exception for ring buffers, which can be smaller 64 KB. + Such case is automatically detected and correctly handled by LZ4_compress_HC_continue(). + + Before starting compression, state must be properly initialized, using LZ4_resetStreamHC(). + A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional). + + Then, use LZ4_compress_HC_continue() to compress each successive block. + It works like LZ4_compress_HC(), but use previous memory blocks as dictionary to improve compression. + Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression. + As a reminder, size 'dst' buffer to handle worst cases, using LZ4_compressBound(), to ensure success of compression operation. + + If, for any reason, previous data blocks can't be preserved unmodified in memory during next compression block, + you must save it to a safer memory space, using LZ4_saveDictHC(). + Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer'. */ /************************************** - * Deprecated Functions - * ************************************/ +* Deprecated Functions +**************************************/ /* Deprecate Warnings */ /* Should these warnings messages be a problem, it is generally possible to disable them, @@ -175,8 +178,8 @@ int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, cons LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (const char* inputBuffer); LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data); LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data); -LZ4_DEPRECATED("use LZ4_compressHC_safe_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); -LZ4_DEPRECATED("use LZ4_compressHC_safe_continue() instead") 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") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); +LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") 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") int LZ4_sizeofStreamStateHC(void); LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); diff --git a/programs/bench.c b/programs/bench.c index 3a93cf9..9f949c4 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -60,7 +60,7 @@ #define COMPRESSOR0 LZ4_compress_local static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { (void)clevel; return LZ4_compress_default(src, dst, srcSize, dstSize); } #include "lz4hc.h" -#define COMPRESSOR1 LZ4_compressHC_safe +#define COMPRESSOR1 LZ4_compress_HC #define DEFAULTCOMPRESSOR COMPRESSOR0 #include "xxhash.h" diff --git a/programs/lz4io.c b/programs/lz4io.c index 16fc879..15c93f4 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -347,7 +347,7 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output /* Init */ start = clock(); - if (compressionlevel < 3) compressionFunction = LZ4IO_LZ4_compress; else compressionFunction = LZ4_compressHC_safe; + if (compressionlevel < 3) compressionFunction = LZ4IO_LZ4_compress; else compressionFunction = LZ4_compress_HC; if (LZ4IO_getFiles(input_filename, output_filename, &finput, &foutput)) EXM_THROW(20, "File error"); -- cgit v0.12 From 05b0aa62a785bbf17b2452a0e7cda04bc630cc27 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 4 May 2015 14:43:37 +0100 Subject: Updated readme --- NEWS | 8 ++++---- README.md | 48 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index e797ff7..08622f2 100644 --- a/NEWS +++ b/NEWS @@ -1,14 +1,14 @@ r129: -New : LZ4 CLI improved performance when compressing/decompressing multiple files (#86, kind contribution from Kyle J. Harper & Takayuki Matsuoka) Added : LZ4_compress_fast() +Changed: New lz4 and lz4hc compression API. Previous function prototypes still supported. Changed: Sparse file support enabled by default -Changed: New function names LZ4_compress_safe() - Suggested by Evan Nemerson & Takayuki Matsuoka +New : LZ4 CLI improved performance compressing/decompressing multiple files (#86, kind contribution from Kyle J. Harper & Takayuki Matsuoka) Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Greg Slazinski & Evan Nemerson Changed: Enums converted to LZ4F_ namespace convention - by Takayuki Matsuoka Added : AppVeyor CI environment, for Visual tests - Suggested by Takayuki Matsuoka -Modified:Obsolete functions generate warnings - Suggested by Evan Nemerson & Takayuki Matsuoka +Modified:Obsolete functions generate warnings - Suggested by Evan Nemerson, contributed by Takayuki Matsuoka Fixed : Bug #75 (unfinished stream), reported by Yongwoon Cho -Updated: Documentation converted to MarkDown +Updated: Documentation converted to MarkDown format r128: New : lz4cli sparse file support (Requested by Neil Wilson, and contributed by Takayuki Matsuoka) diff --git a/README.md b/README.md index 5d506d4..d050029 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,12 @@ It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems. -A high compression derivative, called LZ4_HC, is also provided. -It trades CPU time for compression ratio. +Speed can be tuned dynamically, selecting an "acceleration" factor +which trades compression ratio for more speed up. +On the other end, a high compression derivative, LZ4_HC, is also provided, +trading CPU time for improved compression ratio. +All versions feature the same excellent decompression speed. + |Branch |Status | |------------|---------| @@ -37,26 +41,40 @@ The reference system uses a Core i5-4300U @1.9GHz. Benchmark evaluates the compression of reference [Silesia Corpus] in single-thread mode. -| Compressor | Ratio | Compression | Decompression | -| ---------- | ----- | ----------- | ------------- | -| memcpy | 1.000 | 4200 MB/s | 4200 MB/s | -|**LZ4 fast (r129)**| 1.607 |**680 MB/s** | **2220 MB/s** | -|**LZ4 (r129)** |**2.101**|**385 MB/s** | **1850 MB/s** | -| LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | -| QuickLZ 1.5.1.b6 | 2.238 | 320 MB/s | 380 MB/s | -| Snappy 1.1.0 | 2.091 | 250 MB/s | 960 MB/s | -| zlib 1.2.8 -1 | 2.730 | 59 MB/s | 250 MB/s | -|**LZ4 HC (r129)** |**2.720**| 22 MB/s | **1830 MB/s** | -| zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | +| Compressor | Ratio | Compression | Decompression | +| ---------- | ----- | ----------- | ------------- | +| memcpy | 1.000 | 4200 MB/s | 4200 MB/s | +|**LZ4 fast 17 (r129)**| 1.607 |**690 MB/s** | **2220 MB/s** | +|**LZ4 default (r129)**|**2.101**|**385 MB/s** | **1850 MB/s** | +| LZO 2.06 | 2.108 | 350 MB/s | 510 MB/s | +| QuickLZ 1.5.1.b6 | 2.238 | 320 MB/s | 380 MB/s | +| Snappy 1.1.0 | 2.091 | 250 MB/s | 960 MB/s | +| zlib 1.2.8 -1 | 2.730 | 59 MB/s | 250 MB/s | +|**LZ4 HC (r129)** |**2.720**| 22 MB/s | **1830 MB/s** | +| zlib 1.2.8 -6 | 3.099 | 18 MB/s | 270 MB/s | + + +Documentation +------------------------- The raw LZ4 block compression format is detailed within [lz4_Block_format]. -Compressing an arbitrarily long file or data stream requires multiple blocks. +To compress an arbitrarily long file or data stream, multiple blocks are required. Organizing these blocks and providing a common header format to handle their content is the purpose of the Frame format, defined into [lz4_Frame_format]. -Interoperable versions of LZ4 must respect this frame format too. +Interoperable versions of LZ4 must respect this frame format. + + +Other source versions +------------------------- + +Beyond the C reference source, +many contributors have created versions of lz4 in multiple languages. +A list of these sources is maintained on the [LZ4 Homepage]. + [Open-Source Benchmark program by m^2 (v0.14.3)]: http://encode.ru/threads/1371-Filesystem-benchmark?p=34029&viewfull=1#post34029 [Silesia Corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia [lz4_Block_format]: lz4_Block_format.md [lz4_Frame_format]: lz4_Frame_format.md +[LZ4 Homepage]: http://www.lz4.info -- cgit v0.12 From 1c3e633c48766c58df949887297dc5838170a33f Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 6 May 2015 01:58:24 +0100 Subject: Added compilation flag -Wcast-qual --- lib/lz4.c | 26 +++++++------- lib/lz4.h | 4 +-- lib/lz4frame.c | 20 +++++------ lib/lz4hc.c | 11 +++--- lib/lz4hc.h | 4 +-- lib/xxhash.c | 100 +++++++++++++++++++++++++-------------------------- lib/xxhash.h | 6 ++-- programs/Makefile | 2 +- programs/frametest.c | 4 +-- programs/lz4cli.c | 2 +- programs/lz4io.c | 8 ++--- 11 files changed, 92 insertions(+), 95 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index bb40f76..c511456 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -351,7 +351,7 @@ typedef struct { U32 currentOffset; U32 initCheck; const BYTE* dictionary; - const BYTE* bufferStart; + BYTE* bufferStart; /* obsolete, used for slideInputBuffer */ U32 dictSize; } LZ4_stream_t_internal; @@ -1064,11 +1064,11 @@ FORCE_INLINE int LZ4_decompress_generic( if (endOnInput) return (int) (((char*)op)-dest); /* Nb of output bytes decoded */ else - return (int) (((char*)ip)-source); /* Nb of input bytes read */ + return (int) (((const char*)ip)-source); /* Nb of input bytes read */ /* Overflow error detected */ _output_error: - return (int) (-(((char*)ip)-source))-1; + return (int) (-(((const char*)ip)-source))-1; } @@ -1092,9 +1092,9 @@ int LZ4_decompress_fast(const char* source, char* dest, int originalSize) typedef struct { - BYTE* externalDict; + const BYTE* externalDict; size_t extDictSize; - BYTE* prefixEnd; + const BYTE* prefixEnd; size_t prefixSize; } LZ4_streamDecode_t_internal; @@ -1126,7 +1126,7 @@ int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dicti { LZ4_streamDecode_t_internal* lz4sd = (LZ4_streamDecode_t_internal*) LZ4_streamDecode; lz4sd->prefixSize = (size_t) dictSize; - lz4sd->prefixEnd = (BYTE*) dictionary + dictSize; + lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize; lz4sd->externalDict = NULL; lz4sd->extDictSize = 0; return 1; @@ -1215,7 +1215,7 @@ FORCE_INLINE int LZ4_decompress_usingDict_generic(const char* source, char* dest return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0); return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0); } - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (BYTE*)dictStart, dictSize); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); } int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) @@ -1231,7 +1231,7 @@ int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSi /* debug function */ int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) { - return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (BYTE*)dictStart, dictSize); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); } @@ -1260,23 +1260,23 @@ int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; } -static void LZ4_init(LZ4_stream_t_internal* lz4ds, const BYTE* base) +static void LZ4_init(LZ4_stream_t_internal* lz4ds, BYTE* base) { MEM_INIT(lz4ds, 0, LZ4_STREAMSIZE); lz4ds->bufferStart = base; } -int LZ4_resetStreamState(void* state, const char* inputBuffer) +int LZ4_resetStreamState(void* state, char* inputBuffer) { if ((((size_t)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */ - LZ4_init((LZ4_stream_t_internal*)state, (const BYTE*)inputBuffer); + LZ4_init((LZ4_stream_t_internal*)state, (BYTE*)inputBuffer); return 0; } -void* LZ4_create (const char* inputBuffer) +void* LZ4_create (char* inputBuffer) { void* lz4ds = ALLOCATOR(8, LZ4_STREAMSIZE_U64); - LZ4_init ((LZ4_stream_t_internal*)lz4ds, (const BYTE*)inputBuffer); + LZ4_init ((LZ4_stream_t_internal*)lz4ds, (BYTE*)inputBuffer); return lz4ds; } diff --git a/lib/lz4.h b/lib/lz4.h index b597064..00304d8 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -331,9 +331,9 @@ int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const cha /* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */ /* Obsolete streaming functions; use new streaming interface whenever possible */ -LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer); LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); -LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer); LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); /* Obsolete streaming decoding functions */ diff --git a/lib/lz4frame.c b/lib/lz4frame.c index d73436c..d1733d0 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -140,7 +140,7 @@ typedef struct LZ4F_dctx_s size_t tmpInSize; size_t tmpInTarget; BYTE* tmpOutBuffer; - BYTE* dict; + const BYTE* dict; size_t dictSize; BYTE* tmpOut; size_t tmpOutSize; @@ -961,7 +961,7 @@ static int LZ4F_decompress_safe (const char* source, char* dest, int compressedS static void LZ4F_updateDict(LZ4F_dctx_t* dctxPtr, const BYTE* dstPtr, size_t dstSize, const BYTE* dstPtr0, unsigned withinTmp) { if (dctxPtr->dictSize==0) - dctxPtr->dict = (BYTE*)dstPtr; /* priority to dictionary continuity */ + dctxPtr->dict = (const BYTE*)dstPtr; /* priority to dictionary continuity */ if (dctxPtr->dict + dctxPtr->dictSize == dstPtr) /* dictionary continuity */ { @@ -971,7 +971,7 @@ static void LZ4F_updateDict(LZ4F_dctx_t* dctxPtr, const BYTE* dstPtr, size_t dst if (dstPtr - dstPtr0 + dstSize >= 64 KB) /* dstBuffer large enough to become dictionary */ { - dctxPtr->dict = (BYTE*)dstPtr0; + dctxPtr->dict = (const BYTE*)dstPtr0; dctxPtr->dictSize = dstPtr - dstPtr0 + dstSize; return; } @@ -987,7 +987,7 @@ static void LZ4F_updateDict(LZ4F_dctx_t* dctxPtr, const BYTE* dstPtr, size_t dst { size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer; size_t copySize = 64 KB - dctxPtr->tmpOutSize; - BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart; + const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart; if (dctxPtr->tmpOutSize > 64 KB) copySize = 0; if (copySize > preserveSize) copySize = preserveSize; @@ -1003,10 +1003,10 @@ static void LZ4F_updateDict(LZ4F_dctx_t* dctxPtr, const BYTE* dstPtr, size_t dst if (dctxPtr->dictSize + dstSize > dctxPtr->maxBufferSize) /* tmp buffer not large enough */ { size_t preserveSize = 64 KB - dstSize; /* note : dstSize < 64 KB */ - memcpy(dctxPtr->dict, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize); + memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize); dctxPtr->dictSize = preserveSize; } - memcpy(dctxPtr->dict + dctxPtr->dictSize, dstPtr, dstSize); + memcpy(dctxPtr->tmpOutBuffer + dctxPtr->dictSize, dstPtr, dstSize); dctxPtr->dictSize += dstSize; return; } @@ -1277,10 +1277,10 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, { if (dctxPtr->dictSize > 128 KB) { - memcpy(dctxPtr->dict, dctxPtr->dict + dctxPtr->dictSize - 64 KB, 64 KB); + memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - 64 KB, 64 KB); dctxPtr->dictSize = 64 KB; } - dctxPtr->tmpOut = dctxPtr->dict + dctxPtr->dictSize; + dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + dctxPtr->dictSize; } else /* dict not within tmp */ { @@ -1444,7 +1444,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, { size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer; size_t copySize = 64 KB - dctxPtr->tmpOutSize; - BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart; + const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart; if (dctxPtr->tmpOutSize > 64 KB) copySize = 0; if (copySize > preserveSize) copySize = preserveSize; @@ -1456,7 +1456,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, else { size_t newDictSize = dctxPtr->dictSize; - BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize; + const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize; if ((newDictSize) > 64 KB) newDictSize = 64 KB; memcpy(dctxPtr->tmpOutBuffer, oldDictEnd - newDictSize, newDictSize); diff --git a/lib/lz4hc.c b/lib/lz4hc.c index fa05ee3..a22ab2b 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -91,7 +91,7 @@ typedef struct const BYTE* end; /* next block here to continue on current prefix */ const BYTE* base; /* All index relative to this position */ const BYTE* dictBase; /* alternate base for extDict */ - const BYTE* inputBuffer;/* deprecated */ + BYTE* inputBuffer; /* deprecated */ U32 dictLimit; /* below that point, need extDict */ U32 lowLimit; /* below that point, no more dict */ U32 nextToUpdate; /* index from which to continue dictionary update */ @@ -119,7 +119,6 @@ static void LZ4HC_init (LZ4HC_Data_Structure* hc4, const BYTE* start) MEM_INIT(hc4->chainTable, 0xFF, sizeof(hc4->chainTable)); hc4->nextToUpdate = 64 KB; hc4->base = start - 64 KB; - hc4->inputBuffer = start; hc4->end = start; hc4->dictBase = start - 64 KB; hc4->dictLimit = 64 KB; @@ -628,7 +627,7 @@ static int LZ4_compressHC_continue_generic (LZ4HC_Data_Structure* ctxPtr, const BYTE* sourceEnd = (const BYTE*) source + inputSize; const BYTE* dictBegin = ctxPtr->dictBase + ctxPtr->lowLimit; const BYTE* dictEnd = ctxPtr->dictBase + ctxPtr->dictLimit; - if ((sourceEnd > dictBegin) && ((BYTE*)source < dictEnd)) + if ((sourceEnd > dictBegin) && ((const BYTE*)source < dictEnd)) { if (sourceEnd > dictEnd) sourceEnd = dictEnd; ctxPtr->lowLimit = (U32)(sourceEnd - ctxPtr->dictBase); @@ -691,17 +690,19 @@ int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* ctx, const char* src, /* These functions currently generate deprecation warnings */ int LZ4_sizeofStreamStateHC(void) { return LZ4_STREAMHCSIZE; } -int LZ4_resetStreamStateHC(void* state, const char* inputBuffer) +int LZ4_resetStreamStateHC(void* state, char* inputBuffer) { if ((((size_t)state) & (sizeof(void*)-1)) != 0) return 1; /* Error : pointer is not aligned for pointer (32 or 64 bits) */ LZ4HC_init((LZ4HC_Data_Structure*)state, (const BYTE*)inputBuffer); + ((LZ4HC_Data_Structure*)state)->inputBuffer = (BYTE*)inputBuffer; return 0; } -void* LZ4_createHC (const char* inputBuffer) +void* LZ4_createHC (char* inputBuffer) { void* hc4 = ALLOCATOR(1, sizeof(LZ4HC_Data_Structure)); LZ4HC_init ((LZ4HC_Data_Structure*)hc4, (const BYTE*)inputBuffer); + ((LZ4HC_Data_Structure*)hc4)->inputBuffer = (BYTE*)inputBuffer; return hc4; } diff --git a/lib/lz4hc.h b/lib/lz4hc.h index f8461b4..431f7c8 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -175,13 +175,13 @@ int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, cons int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize); /* Streaming functions following the older model; should no longer be used */ -LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (char* inputBuffer); LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data); LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data); LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") 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") int LZ4_sizeofStreamStateHC(void); -LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); +LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, char* inputBuffer); #if defined (__cplusplus) diff --git a/lib/xxhash.c b/lib/xxhash.c index a4a3fbe..e6fb8f1 100644 --- a/lib/xxhash.c +++ b/lib/xxhash.c @@ -29,13 +29,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. You can contact the author at : - xxHash source repository : https://github.com/Cyan4973/xxHash -- public discussion board : https://groups.google.com/forum/#!forum/lz4c */ /************************************** * Tuning parameters -***************************************/ +**************************************/ /* Unaligned memory access is automatically enabled for "common" CPU, such as x86. * For others CPU, the compiler will be more cautious, and insert extra code to ensure aligned access is respected. * If you know your target CPU supports unaligned memory access, you want to force this option manually to improve performance. @@ -93,10 +92,7 @@ static void* XXH_malloc(size_t s) { return malloc(s); } static void XXH_free (void* p) { free(p); } /* for memcpy() */ #include -static void* XXH_memcpy(void* dest, const void* src, size_t size) -{ - return memcpy(dest,src,size); -} +static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); } /************************************** @@ -104,17 +100,17 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) ***************************************/ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ # include -typedef uint8_t BYTE; -typedef uint16_t U16; -typedef uint32_t U32; -typedef int32_t S32; -typedef uint64_t U64; + typedef uint8_t BYTE; + typedef uint16_t U16; + typedef uint32_t U32; + typedef int32_t S32; + typedef uint64_t U64; #else -typedef unsigned char BYTE; -typedef unsigned short U16; -typedef unsigned int U32; -typedef signed int S32; -typedef unsigned long long U64; + typedef unsigned char BYTE; + typedef unsigned short U16; + typedef unsigned int U32; + typedef signed int S32; + typedef unsigned long long U64; #endif static U32 XXH_read32(const void* memPtr) @@ -133,7 +129,7 @@ static U64 XXH_read64(const void* memPtr) -/***************************************** +/****************************************** * Compiler-specific Functions and Macros ******************************************/ #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) @@ -175,39 +171,17 @@ static U64 XXH_swap64 (U64 x) #endif -/************************************** -* Constants -***************************************/ -#define PRIME32_1 2654435761U -#define PRIME32_2 2246822519U -#define PRIME32_3 3266489917U -#define PRIME32_4 668265263U -#define PRIME32_5 374761393U - -#define PRIME64_1 11400714785074694791ULL -#define PRIME64_2 14029467366897019727ULL -#define PRIME64_3 1609587929392839161ULL -#define PRIME64_4 9650029242287828579ULL -#define PRIME64_5 2870177450012600261ULL - - /*************************************** * Architecture Macros -****************************************/ +***************************************/ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess; #ifndef XXH_CPU_LITTLE_ENDIAN /* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example using a compiler switch */ static const int one = 1; -# define XXH_CPU_LITTLE_ENDIAN (*(char*)(&one)) +# define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&one)) #endif -/************************************** -* Macros -***************************************/ -#define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(!!(c)) }; } /* use only *after* variable declarations */ - - -/**************************** +/***************************** * Memory reads *****************************/ typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment; @@ -217,7 +191,7 @@ FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_a if (align==XXH_unaligned) return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr)); else - return endian==XXH_littleEndian ? *(U32*)ptr : XXH_swap32(*(U32*)ptr); + return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr); } FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian) @@ -230,7 +204,7 @@ FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_a if (align==XXH_unaligned) return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr)); else - return endian==XXH_littleEndian ? *(U64*)ptr : XXH_swap64(*(U64*)ptr); + return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr); } FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian) @@ -239,7 +213,29 @@ FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian) } -/**************************** +/*************************************** +* Macros +***************************************/ +#define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(!!(c)) }; } /* use only *after* variable declarations */ + + +/*************************************** +* Constants +***************************************/ +#define PRIME32_1 2654435761U +#define PRIME32_2 2246822519U +#define PRIME32_3 3266489917U +#define PRIME32_4 668265263U +#define PRIME32_5 374761393U + +#define PRIME64_1 11400714785074694791ULL +#define PRIME64_2 14029467366897019727ULL +#define PRIME64_3 1609587929392839161ULL +#define PRIME64_4 9650029242287828579ULL +#define PRIME64_5 2870177450012600261ULL + + +/***************************** * Simple Hash Functions *****************************/ FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align) @@ -319,7 +315,7 @@ FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH } -unsigned int XXH32 (const void* input, size_t len, unsigned seed) +unsigned XXH32 (const void* input, size_t len, unsigned seed) { #if 0 /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ @@ -331,7 +327,7 @@ unsigned int XXH32 (const void* input, size_t len, unsigned seed) XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; # if !defined(XXH_USE_UNALIGNED_ACCESS) - if ((((size_t)input) & 3) == 0) /* Input is aligned, let's leverage the speed advantage */ + if ((((size_t)input) & 3) == 0) /* Input is 4-bytes aligned, leverage the speed benefit */ { if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned); @@ -488,7 +484,7 @@ unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed } /**************************************************** - * Advanced Hash Functions +* Advanced Hash Functions ****************************************************/ /*** Allocation ***/ @@ -672,9 +668,9 @@ XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t l FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state_in, XXH_endianess endian) { - XXH_istate32_t* state = (XXH_istate32_t*) state_in; + const XXH_istate32_t* state = (const XXH_istate32_t*) state_in; const BYTE * p = (const BYTE*)state->mem32; - BYTE* bEnd = (BYTE*)(state->mem32) + state->memsize; + const BYTE* bEnd = (const BYTE*)(state->mem32) + state->memsize; U32 h32; if (state->total_len >= 16) @@ -826,9 +822,9 @@ XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t l FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state_in, XXH_endianess endian) { - XXH_istate64_t * state = (XXH_istate64_t *) state_in; + const XXH_istate64_t * state = (const XXH_istate64_t *) state_in; const BYTE * p = (const BYTE*)state->mem64; - BYTE* bEnd = (BYTE*)state->mem64 + state->memsize; + const BYTE* bEnd = (const BYTE*)state->mem64 + state->memsize; U64 h64; if (state->total_len >= 32) diff --git a/lib/xxhash.h b/lib/xxhash.h index 34eea73..0df5ac1 100644 --- a/lib/xxhash.h +++ b/lib/xxhash.h @@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. You can contact the author at : - - xxHash source repository : http://code.google.com/p/xxhash/ + - xxHash source repository : https://github.com/Cyan4973/xxHash */ /* Notice extracted from xxHash homepage : @@ -57,8 +57,8 @@ Q.Score is a measure of quality of the hash function. It depends on successfully passing SMHasher test set. 10 is a perfect score. -A new 64-bits version, named XXH64, is available since r35. -It offers better speed for 64-bits applications. +A 64-bits version, named XXH64, is available since r35. +It offers much better speed, but for 64-bits applications only. Name Speed on 64 bits Speed on 32 bits XXH64 13.8 GB/s 1.9 GB/s XXH32 6.8 GB/s 6.0 GB/s diff --git a/programs/Makefile b/programs/Makefile index 910516f..39335db 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -39,7 +39,7 @@ RELEASE?= r129 DESTDIR?= PREFIX ?= /usr/local CFLAGS ?= -O3 -CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\" +CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\" FLAGS := -I../lib $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) BINDIR := $(PREFIX)/bin diff --git a/programs/frametest.c b/programs/frametest.c index fedb78d..46ec030 100644 --- a/programs/frametest.c +++ b/programs/frametest.c @@ -568,8 +568,8 @@ _output_error: static void locateBuffDiff(const void* buff1, const void* buff2, size_t size, unsigned nonContiguous) { int p=0; - BYTE* b1=(BYTE*)buff1; - BYTE* b2=(BYTE*)buff2; + const BYTE* b1=(const BYTE*)buff1; + const BYTE* b2=(const BYTE*)buff2; if (nonContiguous) { DISPLAY("Non-contiguous output test (%i bytes)\n", (int)size); diff --git a/programs/lz4cli.c b/programs/lz4cli.c index da18169..970856d 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -470,7 +470,7 @@ int main(int argc, char** argv) if (!decode) DISPLAYLEVEL(4, "Blocks size : %i KB\n", blockSize>>10); /* No input filename ==> use stdin */ - if (multiple_inputs) input_filename = inFileNames[0], output_filename = (char*)(inFileNames[0]); + if (multiple_inputs) input_filename = inFileNames[0], output_filename = (const char*)(inFileNames[0]); if(!input_filename) { input_filename=stdinmark; } /* Check if input or output are defined as console; trigger an error in this case */ diff --git a/programs/lz4io.c b/programs/lz4io.c index 15c93f4..209f5ed 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -630,10 +630,10 @@ static unsigned LZ4IO_readLE32 (const void* s) static unsigned LZ4IO_fwriteSparse(FILE* file, const void* buffer, size_t bufferSize, unsigned storedSkips) { - size_t* const bufferT = (size_t*)buffer; /* Buffer is supposed malloc'ed, hence aligned on size_t */ - size_t* ptrT = bufferT; + const size_t* const bufferT = (const size_t*)buffer; /* Buffer is supposed malloc'ed, hence aligned on size_t */ + const size_t* ptrT = bufferT; size_t bufferSizeT = bufferSize / sizeT; - size_t* const bufferTEnd = bufferT + bufferSizeT; + const size_t* const bufferTEnd = bufferT + bufferSizeT; static const size_t segmentSizeT = (32 KB) / sizeT; if (!g_sparseFileSupport) /* normal write */ @@ -679,7 +679,7 @@ static unsigned LZ4IO_fwriteSparse(FILE* file, const void* buffer, size_t buffer if (bufferSize & maskT) /* size not multiple of sizeT : implies end of block */ { - const char* const restStart = (char*)bufferTEnd; + const char* const restStart = (const char*)bufferTEnd; const char* restPtr = restStart; size_t restSize = bufferSize & maskT; const char* const restEnd = restStart + restSize; -- cgit v0.12 From efbebd2a9955c6a6eabc558f00643abb4690edac Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 6 May 2015 02:29:04 +0100 Subject: Added : LZ4_compress_destSize() --- lib/Makefile | 4 +- lib/lz4.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/lz4.h | 15 ++++ programs/fuzzer.c | 35 +++++++++ 4 files changed, 269 insertions(+), 6 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 8aa15de..ef671d3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -31,7 +31,7 @@ # ################################################################ # Version numbers -VERSION ?= 128 +VERSION ?= 129 LIBVER_MAJOR=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h` LIBVER_MINOR=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h` LIBVER_PATCH=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h` @@ -40,7 +40,7 @@ LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH) DESTDIR?= PREFIX ?= /usr/local CFLAGS ?= -O3 -CFLAGS += -I. -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -pedantic +CFLAGS += -I. -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wcast-qual Wstrict-prototypes -pedantic LIBDIR?= $(PREFIX)/lib INCLUDEDIR=$(PREFIX)/include diff --git a/lib/lz4.c b/lib/lz4.c index c511456..55f2359 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -679,7 +679,7 @@ int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) { #if (HEAPMODE) - void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t_internal)); /* malloc-calloc always properly aligned */ + void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ #else LZ4_stream_t ctx; void* ctxPtr = &ctx; @@ -715,9 +715,222 @@ int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int m } -/***************************************** -* Experimental : Streaming functions -*****************************************/ +/******************************** +* destSize variant +********************************/ + +static int LZ4_compress_destSize_generic( + void* const ctx, + const char* const src, + char* const dst, + int* const srcSizePtr, + const int targetDstSize, + const tableType_t tableType) +{ + const BYTE* ip = (const BYTE*) src; + const BYTE* base = (const BYTE*) src; + const BYTE* lowLimit = (const BYTE*) src; + const BYTE* anchor = ip; + const BYTE* const iend = ip + *srcSizePtr; + const BYTE* const mflimit = iend - MFLIMIT; + const BYTE* const matchlimit = iend - LASTLITERALS; + + BYTE* op = (BYTE*) dst; + BYTE* const oend = op + targetDstSize; + BYTE* const oMaxLit = op + targetDstSize - 2 /* offset */ - 8 /* because 8+MINMATCH==MFLIMIT */ - 1 /* token */; + BYTE* const oMaxMatch = op + targetDstSize - (LASTLITERALS + 1 /* token */); + BYTE* const oMaxSeq = oMaxLit - 1 /* token */; + + U32 forwardH; + + + /* Init conditions */ + if (targetDstSize < 1) return 0; /* Impossible to store anything */ + if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ + if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if (*srcSizePtr> LZ4_skipTrigger); + + if (unlikely(forwardIp > mflimit)) + goto _last_literals; + + match = LZ4_getPositionOnHash(h, ctx, tableType, base); + forwardH = LZ4_hashPosition(forwardIp, tableType); + LZ4_putPositionOnHash(ip, h, ctx, tableType, base); + + } while ( ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) + || (LZ4_read32(match) != LZ4_read32(ip)) ); + } + + /* Catch up */ + while ((ip>anchor) && (match > lowLimit) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; } + + { + /* Encode Literal length */ + unsigned litLength = (unsigned)(ip - anchor); + token = op++; + if (op + ((litLength+240)/255) + litLength > oMaxLit) + { + /* Not enough space for a last match */ + op--; + goto _last_literals; + } + if (litLength>=RUN_MASK) + { + unsigned len = litLength - RUN_MASK; + *token=(RUN_MASK<= 255 ; len-=255) *op++ = 255; + *op++ = (BYTE)len; + } + else *token = (BYTE)(litLength< oMaxMatch) + { + /* Match description too long : reduce it */ + matchLength = (15-1) + (oMaxMatch-op) * 255; + } + //printf("offset %5i, matchLength%5i \n", (int)(ip-match), matchLength + MINMATCH); + ip += MINMATCH + matchLength; + + if (matchLength>=ML_MASK) + { + *token += ML_MASK; + matchLength -= ML_MASK; + while (matchLength >= 255) { matchLength-=255; *op++ = 255; } + *op++ = (BYTE)matchLength; + } + else *token += (BYTE)(matchLength); + } + + anchor = ip; + + /* Test end of block */ + if (ip > mflimit) break; + if (op > oMaxSeq) break; + + /* Fill table */ + LZ4_putPosition(ip-2, ctx, tableType, base); + + /* Test next position */ + match = LZ4_getPosition(ip, ctx, tableType, base); + LZ4_putPosition(ip, ctx, tableType, base); + if ( (match+MAX_DISTANCE>=ip) + && (LZ4_read32(match)==LZ4_read32(ip)) ) + { token=op++; *token=0; goto _next_match; } + + /* Prepare next loop */ + forwardH = LZ4_hashPosition(++ip, tableType); + } + +_last_literals: + /* Encode Last Literals */ + { + size_t lastRunSize = (size_t)(iend - anchor); + if (op + 1 /* token */ + ((lastRunSize+240)/255) /* litLength */ + lastRunSize /* literals */ > oend) + { + /* adapt lastRunSize to fill 'dst' */ + lastRunSize = (oend-op) - 1; + lastRunSize -= (lastRunSize+240)/255; + } + ip = anchor + lastRunSize; + + if (lastRunSize >= RUN_MASK) + { + size_t accumulator = lastRunSize - RUN_MASK; + *op++ = RUN_MASK << ML_BITS; + for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; + *op++ = (BYTE) accumulator; + } + else + { + *op++ = (BYTE)(lastRunSize<= LZ4_compressBound(*srcSizePtr)) /* compression success is guaranteed */ + { + return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr, targetDstSize, 1); + } + else + { + if (*srcSizePtr < LZ4_64Klimit) + return LZ4_compress_destSize_generic(state, src, dst, srcSizePtr, targetDstSize, byU16); + else + return LZ4_compress_destSize_generic(state, src, dst, srcSizePtr, targetDstSize, LZ4_64bits() ? byU32 : byPtr); + } +} + + +int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize) +{ +#if (HEAPMODE) + void* ctx = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ +#else + LZ4_stream_t ctxBody; + void* ctx = &ctxBody; +#endif + + int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); + +#if (HEAPMODE) + FREEMEM(ctx); +#endif + return result; +} + + + +/******************************** +* Streaming functions +********************************/ LZ4_stream_t* LZ4_createStream(void) { diff --git a/lib/lz4.h b/lib/lz4.h index 00304d8..93388c2 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -140,6 +140,21 @@ int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int /* +LZ4_compress_destSize() : + Reverse the logic, by compressing as much data as possible from 'source' buffer + into already allocated buffer 'dest' of size 'targetDestSize'. + This function either compresses the entire 'source' content into 'dest' if it's large enough, + or fill 'dest' buffer completely with as much data as possible from 'source'. + Original idea by WiredTiger team. + *sourceSizePtr : will be modified to indicate how many bytes where read from 'source' to fill 'dest'. + New value is necessarily <= old value. + return : Nb bytes written into 'dest' (necessarily <= targetDestSize) + or 0 if compression fails +*/ +int LZ4_compress_destSize (const char* source, char* dest, int* sourceSizePtr, int targetDestSize); + + +/* LZ4_decompress_fast() : originalSize : is the original and therefore uncompressed size return : the number of bytes read from the source buffer (in other words, the compressed size) diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 9fd4648..6588290 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -396,6 +396,41 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c /* Compression tests */ + /* Test compression destSize */ + FUZ_DISPLAYTEST; + { + int srcSize = blockSize; + int targetSize = srcSize * ((FUZ_rand(&randState) & 127)+1) >> 7; + char endCheck = FUZ_rand(&randState) & 255; + compressedBuffer[targetSize] = endCheck; + ret = LZ4_compress_destSize(block, compressedBuffer, &srcSize, targetSize); + FUZ_CHECKTEST(ret > targetSize, "LZ4_compress_destSize() result larger than dst buffer !"); + FUZ_CHECKTEST(compressedBuffer[targetSize] != endCheck, "LZ4_compress_destSize() overwrite dst buffer !"); + FUZ_CHECKTEST(srcSize > blockSize, "LZ4_compress_destSize() fed more than src buffer !"); + DISPLAY("destSize : %7i/%7i; content%7i/%7i ", ret, targetSize, srcSize, blockSize); + if (targetSize>0) + { + FUZ_CHECKTEST((ret==0), "LZ4_compress_destSize() compression failed"); + /* check correctness */ + FUZ_DISPLAYTEST; + + crcOrig = XXH32(block, srcSize, 0); + compressedSize = ret; + endCheck = FUZ_rand(&randState) & 255; + decodedBuffer[srcSize] = endCheck; + ret = LZ4_decompress_safe(compressedBuffer, decodedBuffer, compressedSize, srcSize); + FUZ_CHECKTEST(ret<0, "LZ4_decompress_safe() failed on data compressed by LZ4_compress_destSize"); + FUZ_CHECKTEST(ret!=srcSize, "LZ4_decompress_safe() failed : did not fully decompressed data"); + FUZ_CHECKTEST(decodedBuffer[srcSize] != endCheck, "LZ4_decompress_safe() overwrite dst buffer !"); + crcCheck = XXH32(decodedBuffer, srcSize, 0); + FUZ_CHECKTEST(crcCheck!=crcOrig, "LZ4_decompress_safe() corrupted decoded data"); + + DISPLAY(" OK \n"); + } + else + DISPLAY(" \n"); + } + /* Test compression HC */ FUZ_DISPLAYTEST; ret = LZ4_compressHC(block, compressedBuffer, blockSize); -- cgit v0.12 From b4ef93a83707614b66e3f44706d9992048119768 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 6 May 2015 10:26:59 +0100 Subject: Fixed typo --- lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile b/lib/Makefile index ef671d3..4be1499 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -40,7 +40,7 @@ LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH) DESTDIR?= PREFIX ?= /usr/local CFLAGS ?= -O3 -CFLAGS += -I. -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wcast-qual Wstrict-prototypes -pedantic +CFLAGS += -I. -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wcast-qual -Wstrict-prototypes -pedantic LIBDIR?= $(PREFIX)/lib INCLUDEDIR=$(PREFIX)/include -- cgit v0.12 From 672bfdebd0975289dbbdecabeeda9fabb499475a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 6 May 2015 20:23:06 +0100 Subject: Updated comments --- lib/lz4.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/lz4.h b/lib/lz4.h index 93388c2..20e3d48 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -89,10 +89,10 @@ LZ4_compress_default() : or 0 if compression fails LZ4_decompress_safe() : - compressedSize : is obviously the source size - maxDecompressedSize : is the size of the destination buffer, which must be already allocated. - return : the number of bytes decompressed into the destination buffer (necessarily <= maxDecompressedSize) - If the destination buffer is not large enough, decoding will stop and output an error code (<0). + compressedSize : is the precise full size of the compressed block. + maxDecompressedSize : is the size of destination buffer, which must be already allocated. + return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize) + If destination buffer is not large enough, decoding will stop and output an error code (<0). If the source stream is detected malformed, the function will stop decoding and return a negative result. This function is protected against buffer overflow exploits, including malicious data packets. It never writes outside output buffer, nor reads outside input buffer. -- cgit v0.12 From fdd0029c3778768d0e8a80ce238d981f946c8b78 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 6 May 2015 20:57:35 +0100 Subject: minor parsing update --- lz4_Block_format.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lz4_Block_format.md b/lz4_Block_format.md index b933a6a..a120a0b 100644 --- a/lz4_Block_format.md +++ b/lz4_Block_format.md @@ -45,17 +45,20 @@ There can be any number of bytes following the token. There is no "size limit". (Side note : this is why a not-compressible input block is expanded by 0.4%). Example 1 : A length of 48 will be represented as : -- 15 : value for the 4-bits High field -- 33 : (=48-15) remaining length to reach 48 + + - 15 : value for the 4-bits High field + - 33 : (=48-15) remaining length to reach 48 Example 2 : A length of 280 will be represented as : -- 15 : value for the 4-bits High field -- 255 : following byte is maxed, since 280-15 >= 255 -- 10 : (=280 - 15 - 255) ) remaining length to reach 280 + + - 15 : value for the 4-bits High field + - 255 : following byte is maxed, since 280-15 >= 255 + - 10 : (=280 - 15 - 255) ) remaining length to reach 280 Example 3 : A length of 15 will be represented as : -- 15 : value for the 4-bits High field -- 0 : (=15-15) yes, the zero must be output + + - 15 : value for the 4-bits High field + - 0 : (=15-15) yes, the zero must be output Following the token and optional length bytes, are the literals themselves. They are exactly as numerous as previously decoded (length of literals). @@ -84,7 +87,7 @@ we output additional bytes, one at a time, with values ranging from 0 to 255. They are added to total to provide the final match length. A 255 value means there is another byte to read and add. There is no limit to the number of optional bytes that can be output this way. -(This points towards a maximum achievable compression ratio of ~250). +(This points towards a maximum achievable compression ratio of about 250). With the offset and the matchlength, the decoder can now proceed to copy the data from the already decoded buffer. @@ -98,8 +101,7 @@ There are specific parsing rules to respect in order to remain compatible with assumptions made by the decoder : 1. The last 5 bytes are always literals -2. The last match must start at least 12 bytes before end of block. - +2. The last match must start at least 12 bytes before end of block. Consequently, a block with less than 13 bytes cannot be compressed. These rules are in place to ensure that the decoder -- cgit v0.12