summaryrefslogtreecommitdiff
path: root/src/static_libs/lz4
diff options
context:
space:
mode:
authorStefan Schmidt <stefan@osg.samsung.com>2015-12-16 11:53:11 +0100
committerStefan Schmidt <stefan@osg.samsung.com>2015-12-16 11:53:11 +0100
commit1872c06ff0a091190186615f3b4074fcac7385ee (patch)
treeddf4050e02fa0fddde6803d2ebbaf7a5db130916 /src/static_libs/lz4
parent1243b24f9b2967433e0a00d36c58117afe21d56b (diff)
lz4: Update our internal copy to release r131
Clang and GCC optimizations and bug fixes. Have a look at the NEWS file for more details.
Diffstat (limited to 'src/static_libs/lz4')
-rw-r--r--src/static_libs/lz4/NEWS55
-rw-r--r--src/static_libs/lz4/README.md12
-rw-r--r--src/static_libs/lz4/lz4.c641
-rw-r--r--src/static_libs/lz4/lz4.h208
-rw-r--r--src/static_libs/lz4/lz4hc.c209
-rw-r--r--src/static_libs/lz4/lz4hc.h197
6 files changed, 763 insertions, 559 deletions
diff --git a/src/static_libs/lz4/NEWS b/src/static_libs/lz4/NEWS
index 2eeb948ab9..781687d443 100644
--- a/src/static_libs/lz4/NEWS
+++ b/src/static_libs/lz4/NEWS
@@ -1,19 +1,44 @@
1r131
2New : Dos/DJGPP target, thanks to Louis Santillan (#114)
3Added : Example using lz4frame library, by Zbigniew Jędrzejewski-Szmek (#118)
4Changed: xxhash symbols are modified (namespace emulation) within liblz4
5
6r130:
7Fixed : incompatibility sparse mode vs console, reported by Yongwoon Cho (#105)
8Fixed : LZ4IO exits too early when frame crc not present, reported by Yongwoon Cho (#106)
9Fixed : incompatibility sparse mode vs append mode, reported by Takayuki Matsuoka (#110)
10Performance fix : big compression speed boost for clang (+30%)
11New : cross-version test, by Takayuki Matsuoka
12
13r129:
14Added : LZ4_compress_fast(), LZ4_compress_fast_continue()
15Added : LZ4_compress_destSize()
16Changed: New lz4 and lz4hc compression API. Previous function prototypes still supported.
17Changed: Sparse file support enabled by default
18New : LZ4 CLI improved performance compressing/decompressing multiple files (#86, kind contribution from Kyle J. Harper & Takayuki Matsuoka)
19Fixed : GCC 4.9+ optimization bug - Reported by Markus Trippelsdorf, Greg Slazinski & Evan Nemerson
20Changed: Enums converted to LZ4F_ namespace convention - by Takayuki Matsuoka
21Added : AppVeyor CI environment, for Visual tests - Suggested by Takayuki Matsuoka
22Modified:Obsolete functions generate warnings - Suggested by Evan Nemerson, contributed by Takayuki Matsuoka
23Fixed : Bug #75 (unfinished stream), reported by Yongwoon Cho
24Updated: Documentation converted to MarkDown format
25
1r128: 26r128:
2New : lz4cli sparse file support 27New : lz4cli sparse file support (Requested by Neil Wilson, and contributed by Takayuki Matsuoka)
3New : command -m, to compress multiple files in a single command 28New : command -m, to compress multiple files in a single command (suggested by Kyle J. Harper)
4Fixed : Restored lz4hc compression ratio (was slightly lower since r124) 29Fixed : Restored lz4hc compression ratio (slightly lower since r124)
5New : lz4 cli supports long commands 30New : lz4 cli supports long commands (suggested by Takayuki Matsuoka)
6New : lz4frame & lz4cli frame content size support 31New : lz4frame & lz4cli frame content size support
7New : lz4frame supports skippable frames 32New : lz4frame supports skippable frames, as requested by Sergey Cherepanov
8Changed:Default "make install" directory is /usr/local 33Changed: Default "make install" directory is /usr/local, as notified by Ron Johnson
9New : lz4 cli supports "pass-through" mode 34New : lz4 cli supports "pass-through" mode, requested by Neil Wilson
10New : datagen can generate sparse files 35New : datagen can generate sparse files
11New : scan-build tests 36New : scan-build tests, thanks to kind help by Takayuki Matsuoka
12New : g++ compatibility tests 37New : g++ compatibility tests
13New : arm cross-compilation test 38New : arm cross-compilation test, thanks to kind help by Takayuki Matsuoka
14Fixed : Fuzzer + frametest compatibility with NetBSD (issue #48) 39Fixed : Fuzzer + frametest compatibility with NetBSD (issue #48, reported by Thomas Klausner)
15Added : Visual project directory 40Added : Visual project directory
16Updated:Man page & Specification 41Updated: Man page & Specification
17 42
18r127: 43r127:
19N/A : added a file on SVN 44N/A : added a file on SVN
diff --git a/src/static_libs/lz4/README.md b/src/static_libs/lz4/README.md
index 636c8be0bc..f6ebf5e10b 100644
--- a/src/static_libs/lz4/README.md
+++ b/src/static_libs/lz4/README.md
@@ -1,15 +1,16 @@
1LZ4 - Library Files 1LZ4 - Library Files
2================================ 2================================
3 3
4This directory contains many files, but you don't necessarily need them all. 4The __lib__ directory contains several files, but you don't necessarily need them all.
5 5
6If you want to integrate LZ4 compression/decompression into your program, you basically need to include "**lz4.c**" and "**lz4.h**" only. 6To integrate fast LZ4 compression/decompression into your program, you basically just need "**lz4.c**" and "**lz4.h**".
7 7
8If you want more compression, at the cost of compression speed (but preserving decompression speed), you will also have to include "**lz4hc.c**" and "**lz4hc.h**". Note that lz4hc needs lz4 to work properly. 8For more compression at the cost of compression speed (while preserving decompression speed), use **lz4hc** on top of regular lz4. `lz4hc` only provides compression functions. It also needs `lz4` to compile properly.
9 9
10Next level, if you want to produce files or data streams compatible with lz4 utility, you will have to use and include "**lz4frame.c**" and **lz4frame.h**". This library encapsulate lz4-compressed blocks into the official interoperable frame format. In order to work properly, lz4frame needs lz4 and lz4hc, and also "**xxhash.c**" and "**xxhash.h**", which provide the error detection algorithm. 10If you want to produce files or data streams compatible with `lz4` command line utility, use **lz4frame**. This library encapsulates lz4-compressed blocks into the [official interoperable frame format]. In order to work properly, lz4frame needs lz4 and lz4hc, and also **xxhash**, which provides error detection algorithm.
11(_Advanced stuff_ : It's possible to hide xxhash symbols into a local namespace. This is what `liblz4` does, to avoid symbol duplication in case a user program would link to several libraries containing xxhash symbols.)
11 12
12A more complex "lz4frame_static.h" is also provided, although its usage is not recommended. It contains definitions which are not guaranteed to remain stable within future versions. Use only if you don't plan to update your lz4 version. 13A more complex "lz4frame_static.h" is also provided, although its usage is not recommended. It contains definitions which are not guaranteed to remain stable within future versions. Use for static linking ***only***.
13 14
14The other files are not source code. There are : 15The other files are not source code. There are :
15 16
@@ -17,3 +18,4 @@ The other files are not source code. There are :
17 - Makefile : script to compile or install lz4 library (static or dynamic) 18 - Makefile : script to compile or install lz4 library (static or dynamic)
18 - liblz4.pc.in : for pkg-config (make install) 19 - liblz4.pc.in : for pkg-config (make install)
19 20
21[official interoperable frame format]: ../lz4_Frame_format.md
diff --git a/src/static_libs/lz4/lz4.c b/src/static_libs/lz4/lz4.c
index 881d1af020..08cf6b5cd7 100644
--- a/src/static_libs/lz4/lz4.c
+++ b/src/static_libs/lz4/lz4.c
@@ -34,7 +34,7 @@
34 34
35 35
36/************************************** 36/**************************************
37 Tuning parameters 37* Tuning parameters
38**************************************/ 38**************************************/
39/* 39/*
40 * HEAPMODE : 40 * HEAPMODE :
@@ -44,51 +44,16 @@
44#define HEAPMODE 0 44#define HEAPMODE 0
45 45
46/* 46/*
47 * CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS : 47 * ACCELERATION_DEFAULT :
48 * By default, the source code expects the compiler to correctly optimize 48 * Select "acceleration" for LZ4_compress_fast() when parameter value <= 0
49 * 4-bytes and 8-bytes read on architectures able to handle it efficiently.
50 * This is not always the case. In some circumstances (ARM notably),
51 * the compiler will issue cautious code even when target is able to correctly handle unaligned memory accesses.
52 *
53 * You can force the compiler to use unaligned memory access by uncommenting the line below.
54 * One of the below scenarios will happen :
55 * 1 - Your target CPU correctly handle unaligned access, and was not well optimized by compiler (good case).
56 * You will witness large performance improvements (+50% and up).
57 * Keep the line uncommented and send a word to upstream (https://groups.google.com/forum/#!forum/lz4c)
58 * The goal is to automatically detect such situations by adding your target CPU within an exception list.
59 * 2 - Your target CPU correctly handle unaligned access, and was already already optimized by compiler
60 * No change will be experienced.
61 * 3 - Your target CPU inefficiently handle unaligned access.
62 * You will experience a performance loss. Comment back the line.
63 * 4 - Your target CPU does not handle unaligned access.
64 * Program will crash.
65 * If uncommenting results in better performance (case 1)
66 * please report your configuration to upstream (https://groups.google.com/forum/#!forum/lz4c)
67 * This way, an automatic detection macro can be added to match your case within later versions of the library.
68 */ 49 */
69/* #define CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS 1 */ 50#define ACCELERATION_DEFAULT 1
70 51
71 52
72/************************************** 53/**************************************
73 CPU Feature Detection 54* CPU Feature Detection
74**************************************/ 55**************************************/
75/* 56/*
76 * Automated efficient unaligned memory access detection
77 * Based on known hardware architectures
78 * This list will be updated thanks to feedbacks
79 */
80#if defined(CPU_HAS_EFFICIENT_UNALIGNED_MEMORY_ACCESS) \
81 || defined(__ARM_FEATURE_UNALIGNED) \
82 || defined(__i386__) || defined(__x86_64__) \
83 || defined(_M_IX86) || defined(_M_X64) \
84 || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_8__) \
85 || (defined(_M_ARM) && (_M_ARM >= 7))
86# define LZ4_UNALIGNED_ACCESS 1
87#else
88# define LZ4_UNALIGNED_ACCESS 0
89#endif
90
91/*
92 * LZ4_FORCE_SW_BITCOUNT 57 * LZ4_FORCE_SW_BITCOUNT
93 * Define this parameter if your target system or compiler does not support hardware bit count 58 * Define this parameter if your target system or compiler does not support hardware bit count
94 */ 59 */
@@ -98,14 +63,14 @@
98 63
99 64
100/************************************** 65/**************************************
101* Compiler Options 66* Includes
102**************************************/ 67**************************************/
103#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ 68#include "lz4.h"
104/* "restrict" is a known keyword */
105#else
106# define restrict /* Disable restrict */
107#endif
108 69
70
71/**************************************
72* Compiler Options
73**************************************/
109#ifdef _MSC_VER /* Visual Studio */ 74#ifdef _MSC_VER /* Visual Studio */
110# define FORCE_INLINE static __forceinline 75# define FORCE_INLINE static __forceinline
111# include <intrin.h> 76# include <intrin.h>
@@ -113,7 +78,7 @@
113# pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ 78# pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */
114#else 79#else
115# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ 80# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
116# ifdef __GNUC__ 81# if defined(__GNUC__) || defined(__clang__)
117# define FORCE_INLINE static inline __attribute__((always_inline)) 82# define FORCE_INLINE static inline __attribute__((always_inline))
118# else 83# else
119# define FORCE_INLINE static inline 84# define FORCE_INLINE static inline
@@ -123,9 +88,8 @@
123# endif /* __STDC_VERSION__ */ 88# endif /* __STDC_VERSION__ */
124#endif /* _MSC_VER */ 89#endif /* _MSC_VER */
125 90
126#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 91/* LZ4_GCC_VERSION is defined into lz4.h */
127 92#if (LZ4_GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)
128#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)
129# define expect(expr,value) (__builtin_expect ((expr),(value)) ) 93# define expect(expr,value) (__builtin_expect ((expr),(value)) )
130#else 94#else
131# define expect(expr,value) (expr) 95# define expect(expr,value) (expr)
@@ -136,7 +100,7 @@
136 100
137 101
138/************************************** 102/**************************************
139 Memory routines 103* Memory routines
140**************************************/ 104**************************************/
141#include <stdlib.h> /* malloc, calloc, free */ 105#include <stdlib.h> /* malloc, calloc, free */
142#define ALLOCATOR(n,s) calloc(n,s) 106#define ALLOCATOR(n,s) calloc(n,s)
@@ -146,13 +110,7 @@
146 110
147 111
148/************************************** 112/**************************************
149 Includes 113* Basic Types
150**************************************/
151#include "lz4.h"
152
153
154/**************************************
155 Basic Types
156**************************************/ 114**************************************/
157#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */ 115#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
158# include <stdint.h> 116# include <stdint.h>
@@ -171,7 +129,7 @@
171 129
172 130
173/************************************** 131/**************************************
174 Reading and writing into memory 132* Reading and writing into memory
175**************************************/ 133**************************************/
176#define STEPSIZE sizeof(size_t) 134#define STEPSIZE sizeof(size_t)
177 135
@@ -184,10 +142,19 @@ static unsigned LZ4_isLittleEndian(void)
184} 142}
185 143
186 144
145static U16 LZ4_read16(const void* memPtr)
146{
147 U16 val16;
148 memcpy(&val16, memPtr, 2);
149 return val16;
150}
151
187static U16 LZ4_readLE16(const void* memPtr) 152static U16 LZ4_readLE16(const void* memPtr)
188{ 153{
189 if ((LZ4_UNALIGNED_ACCESS) && (LZ4_isLittleEndian())) 154 if (LZ4_isLittleEndian())
190 return *(U16*)memPtr; 155 {
156 return LZ4_read16(memPtr);
157 }
191 else 158 else
192 { 159 {
193 const BYTE* p = (const BYTE*)memPtr; 160 const BYTE* p = (const BYTE*)memPtr;
@@ -197,10 +164,9 @@ static U16 LZ4_readLE16(const void* memPtr)
197 164
198static void LZ4_writeLE16(void* memPtr, U16 value) 165static void LZ4_writeLE16(void* memPtr, U16 value)
199{ 166{
200 if ((LZ4_UNALIGNED_ACCESS) && (LZ4_isLittleEndian())) 167 if (LZ4_isLittleEndian())
201 { 168 {
202 *(U16*)memPtr = value; 169 memcpy(memPtr, &value, 2);
203 return;
204 } 170 }
205 else 171 else
206 { 172 {
@@ -210,41 +176,18 @@ static void LZ4_writeLE16(void* memPtr, U16 value)
210 } 176 }
211} 177}
212 178
213
214static U16 LZ4_read16(const void* memPtr)
215{
216 if (LZ4_UNALIGNED_ACCESS)
217 return *(U16*)memPtr;
218 else
219 {
220 U16 val16;
221 memcpy(&val16, memPtr, 2);
222 return val16;
223 }
224}
225
226static U32 LZ4_read32(const void* memPtr) 179static U32 LZ4_read32(const void* memPtr)
227{ 180{
228 if (LZ4_UNALIGNED_ACCESS) 181 U32 val32;
229 return *(U32*)memPtr; 182 memcpy(&val32, memPtr, 4);
230 else 183 return val32;
231 {
232 U32 val32;
233 memcpy(&val32, memPtr, 4);
234 return val32;
235 }
236} 184}
237 185
238static U64 LZ4_read64(const void* memPtr) 186static U64 LZ4_read64(const void* memPtr)
239{ 187{
240 if (LZ4_UNALIGNED_ACCESS) 188 U64 val64;
241 return *(U64*)memPtr; 189 memcpy(&val64, memPtr, 8);
242 else 190 return val64;
243 {
244 U64 val64;
245 memcpy(&val64, memPtr, 8);
246 return val64;
247 }
248} 191}
249 192
250static size_t LZ4_read_ARCH(const void* p) 193static size_t LZ4_read_ARCH(const void* p)
@@ -256,31 +199,9 @@ static size_t LZ4_read_ARCH(const void* p)
256} 199}
257 200
258 201
259static void LZ4_copy4(void* dstPtr, const void* srcPtr) 202static void LZ4_copy4(void* dstPtr, const void* srcPtr) { memcpy(dstPtr, srcPtr, 4); }
260{
261 if (LZ4_UNALIGNED_ACCESS)
262 {
263 *(U32*)dstPtr = *(U32*)srcPtr;
264 return;
265 }
266 memcpy(dstPtr, srcPtr, 4);
267}
268 203
269static void LZ4_copy8(void* dstPtr, const void* srcPtr) 204static void LZ4_copy8(void* dstPtr, const void* srcPtr) { memcpy(dstPtr, srcPtr, 8); }
270{
271#if GCC_VERSION!=409 /* disabled on GCC 4.9, as it generates invalid opcode (crash) */
272 if (LZ4_UNALIGNED_ACCESS)
273 {
274 if (LZ4_64bits())
275 *(U64*)dstPtr = *(U64*)srcPtr;
276 else
277 ((U32*)dstPtr)[0] = ((U32*)srcPtr)[0],
278 ((U32*)dstPtr)[1] = ((U32*)srcPtr)[1];
279 return;
280 }
281#endif
282 memcpy(dstPtr, srcPtr, 8);
283}
284 205
285/* customized version of memcpy, which may overwrite up to 7 bytes beyond dstEnd */ 206/* customized version of memcpy, which may overwrite up to 7 bytes beyond dstEnd */
286static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) 207static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd)
@@ -293,7 +214,7 @@ static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd)
293 214
294 215
295/************************************** 216/**************************************
296 Common Constants 217* Common Constants
297**************************************/ 218**************************************/
298#define MINMATCH 4 219#define MINMATCH 4
299 220
@@ -334,7 +255,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val)
334 unsigned long r = 0; 255 unsigned long r = 0;
335 _BitScanForward64( &r, (U64)val ); 256 _BitScanForward64( &r, (U64)val );
336 return (int)(r>>3); 257 return (int)(r>>3);
337# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) 258# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT)
338 return (__builtin_ctzll((U64)val) >> 3); 259 return (__builtin_ctzll((U64)val) >> 3);
339# else 260# else
340 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 }; 261 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 };
@@ -347,7 +268,7 @@ static unsigned LZ4_NbCommonBytes (register size_t val)
347 unsigned long r; 268 unsigned long r;
348 _BitScanForward( &r, (U32)val ); 269 _BitScanForward( &r, (U32)val );
349 return (int)(r>>3); 270 return (int)(r>>3);
350# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) 271# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT)
351 return (__builtin_ctz((U32)val) >> 3); 272 return (__builtin_ctz((U32)val) >> 3);
352# else 273# else
353 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 }; 274 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 };
@@ -363,8 +284,8 @@ static unsigned LZ4_NbCommonBytes (register size_t val)
363 unsigned long r = 0; 284 unsigned long r = 0;
364 _BitScanReverse64( &r, val ); 285 _BitScanReverse64( &r, val );
365 return (unsigned)(r>>3); 286 return (unsigned)(r>>3);
366# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) 287# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT)
367 return (__builtin_clzll(val) >> 3); 288 return (__builtin_clzll((U64)val) >> 3);
368# else 289# else
369 unsigned r; 290 unsigned r;
370 if (!(val>>32)) { r=4; } else { r=0; val>>=32; } 291 if (!(val>>32)) { r=4; } else { r=0; val>>=32; }
@@ -379,8 +300,8 @@ static unsigned LZ4_NbCommonBytes (register size_t val)
379 unsigned long r = 0; 300 unsigned long r = 0;
380 _BitScanReverse( &r, (unsigned long)val ); 301 _BitScanReverse( &r, (unsigned long)val );
381 return (unsigned)(r>>3); 302 return (unsigned)(r>>3);
382# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT) 303# elif (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && !defined(LZ4_FORCE_SW_BITCOUNT)
383 return (__builtin_clz(val) >> 3); 304 return (__builtin_clz((U32)val) >> 3);
384# else 305# else
385 unsigned r; 306 unsigned r;
386 if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } 307 if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
@@ -423,13 +344,6 @@ static const U32 LZ4_skipTrigger = 6; /* Increase this value ==> compression ru
423 344
424 345
425/************************************** 346/**************************************
426* Local Utils
427**************************************/
428int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; }
429int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
430
431
432/**************************************
433* Local Structures and types 347* Local Structures and types
434**************************************/ 348**************************************/
435typedef struct { 349typedef struct {
@@ -437,7 +351,7 @@ typedef struct {
437 U32 currentOffset; 351 U32 currentOffset;
438 U32 initCheck; 352 U32 initCheck;
439 const BYTE* dictionary; 353 const BYTE* dictionary;
440 const BYTE* bufferStart; 354 BYTE* bufferStart; /* obsolete, used for slideInputBuffer */
441 U32 dictSize; 355 U32 dictSize;
442} LZ4_stream_t_internal; 356} LZ4_stream_t_internal;
443 357
@@ -451,6 +365,14 @@ typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive;
451typedef enum { full = 0, partial = 1 } earlyEnd_directive; 365typedef enum { full = 0, partial = 1 } earlyEnd_directive;
452 366
453 367
368/**************************************
369* Local Utils
370**************************************/
371int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; }
372int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
373int LZ4_sizeofState() { return LZ4_STREAMSIZE; }
374
375
454 376
455/******************************** 377/********************************
456* Compression functions 378* Compression functions
@@ -464,7 +386,22 @@ static U32 LZ4_hashSequence(U32 sequence, tableType_t const tableType)
464 return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG)); 386 return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG));
465} 387}
466 388
467static U32 LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(LZ4_read32(p), tableType); } 389static const U64 prime5bytes = 889523592379ULL;
390static U32 LZ4_hashSequence64(size_t sequence, tableType_t const tableType)
391{
392 const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG;
393 const U32 hashMask = (1<<hashLog) - 1;
394 return ((sequence * prime5bytes) >> (40 - hashLog)) & hashMask;
395}
396
397static U32 LZ4_hashSequenceT(size_t sequence, tableType_t const tableType)
398{
399 if (LZ4_64bits())
400 return LZ4_hashSequence64(sequence, tableType);
401 return LZ4_hashSequence((U32)sequence, tableType);
402}
403
404static U32 LZ4_hashPosition(const void* p, tableType_t tableType) { return LZ4_hashSequenceT(LZ4_read_ARCH(p), tableType); }
468 405
469static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase) 406static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase)
470{ 407{
@@ -495,16 +432,17 @@ static const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t t
495 return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase); 432 return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
496} 433}
497 434
498static int LZ4_compress_generic( 435FORCE_INLINE int LZ4_compress_generic(
499 void* ctx, 436 void* const ctx,
500 const char* source, 437 const char* const source,
501 char* dest, 438 char* const dest,
502 int inputSize, 439 const int inputSize,
503 int maxOutputSize, 440 const int maxOutputSize,
504 limitedOutput_directive outputLimited, 441 const limitedOutput_directive outputLimited,
505 tableType_t const tableType, 442 const tableType_t tableType,
506 dict_directive dict, 443 const dict_directive dict,
507 dictIssue_directive dictIssue) 444 const dictIssue_directive dictIssue,
445 const U32 acceleration)
508{ 446{
509 LZ4_stream_t_internal* const dictPtr = (LZ4_stream_t_internal*)ctx; 447 LZ4_stream_t_internal* const dictPtr = (LZ4_stream_t_internal*)ctx;
510 448
@@ -527,7 +465,7 @@ static int LZ4_compress_generic(
527 size_t refDelta=0; 465 size_t refDelta=0;
528 466
529 /* Init conditions */ 467 /* Init conditions */
530 if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ 468 if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */
531 switch(dict) 469 switch(dict)
532 { 470 {
533 case noDict: 471 case noDict:
@@ -558,15 +496,15 @@ static int LZ4_compress_generic(
558 BYTE* token; 496 BYTE* token;
559 { 497 {
560 const BYTE* forwardIp = ip; 498 const BYTE* forwardIp = ip;
561 unsigned step=1; 499 unsigned step = 1;
562 unsigned searchMatchNb = (1U << LZ4_skipTrigger); 500 unsigned searchMatchNb = acceleration << LZ4_skipTrigger;
563 501
564 /* Find a match */ 502 /* Find a match */
565 do { 503 do {
566 U32 h = forwardH; 504 U32 h = forwardH;
567 ip = forwardIp; 505 ip = forwardIp;
568 forwardIp += step; 506 forwardIp += step;
569 step = searchMatchNb++ >> LZ4_skipTrigger; 507 step = (searchMatchNb++ >> LZ4_skipTrigger);
570 508
571 if (unlikely(forwardIp > mflimit)) goto _last_literals; 509 if (unlikely(forwardIp > mflimit)) goto _last_literals;
572 510
@@ -693,13 +631,22 @@ _next_match:
693_last_literals: 631_last_literals:
694 /* Encode Last Literals */ 632 /* Encode Last Literals */
695 { 633 {
696 int lastRun = (int)(iend - anchor); 634 const size_t lastRun = (size_t)(iend - anchor);
697 if ((outputLimited) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) 635 if ((outputLimited) && ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize))
698 return 0; /* Check output limit */ 636 return 0; /* Check output limit */
699 if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun >= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } 637 if (lastRun >= RUN_MASK)
700 else *op++ = (BYTE)(lastRun<<ML_BITS); 638 {
701 memcpy(op, anchor, iend - anchor); 639 size_t accumulator = lastRun - RUN_MASK;
702 op += iend-anchor; 640 *op++ = RUN_MASK << ML_BITS;
641 for(; accumulator >= 255 ; accumulator-=255) *op++ = 255;
642 *op++ = (BYTE) accumulator;
643 }
644 else
645 {
646 *op++ = (BYTE)(lastRun<<ML_BITS);
647 }
648 memcpy(op, anchor, lastRun);
649 op += lastRun;
703 } 650 }
704 651
705 /* End */ 652 /* End */
@@ -707,39 +654,271 @@ _last_literals:
707} 654}
708 655
709 656
710int LZ4_compress(const char* source, char* dest, int inputSize) 657int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
658{
659 LZ4_resetStream((LZ4_stream_t*)state);
660 if (acceleration < 1) acceleration = ACCELERATION_DEFAULT;
661
662 if (maxOutputSize >= LZ4_compressBound(inputSize))
663 {
664 if (inputSize < LZ4_64Klimit)
665 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration);
666 else
667 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration);
668 }
669 else
670 {
671 if (inputSize < LZ4_64Klimit)
672 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration);
673 else
674 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration);
675 }
676}
677
678
679int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
711{ 680{
712#if (HEAPMODE) 681#if (HEAPMODE)
713 void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ 682 void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
714#else 683#else
715 U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ 684 LZ4_stream_t ctx;
685 void* ctxPtr = &ctx;
716#endif 686#endif
717 int result;
718 687
719 if (inputSize < LZ4_64Klimit) 688 int result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration);
720 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue);
721 else
722 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue);
723 689
724#if (HEAPMODE) 690#if (HEAPMODE)
725 FREEMEM(ctx); 691 FREEMEM(ctxPtr);
726#endif 692#endif
727 return result; 693 return result;
728} 694}
729 695
730int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) 696
697int LZ4_compress_default(const char* source, char* dest, int inputSize, int maxOutputSize)
698{
699 return LZ4_compress_fast(source, dest, inputSize, maxOutputSize, 1);
700}
701
702
703/* hidden debug function */
704/* strangely enough, gcc generates faster code when this function is uncommented, even if unused */
705int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
706{
707 LZ4_stream_t ctx;
708
709 LZ4_resetStream(&ctx);
710
711 if (inputSize < LZ4_64Klimit)
712 return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration);
713 else
714 return LZ4_compress_generic(&ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue, acceleration);
715}
716
717
718/********************************
719* destSize variant
720********************************/
721
722static int LZ4_compress_destSize_generic(
723 void* const ctx,
724 const char* const src,
725 char* const dst,
726 int* const srcSizePtr,
727 const int targetDstSize,
728 const tableType_t tableType)
729{
730 const BYTE* ip = (const BYTE*) src;
731 const BYTE* base = (const BYTE*) src;
732 const BYTE* lowLimit = (const BYTE*) src;
733 const BYTE* anchor = ip;
734 const BYTE* const iend = ip + *srcSizePtr;
735 const BYTE* const mflimit = iend - MFLIMIT;
736 const BYTE* const matchlimit = iend - LASTLITERALS;
737
738 BYTE* op = (BYTE*) dst;
739 BYTE* const oend = op + targetDstSize;
740 BYTE* const oMaxLit = op + targetDstSize - 2 /* offset */ - 8 /* because 8+MINMATCH==MFLIMIT */ - 1 /* token */;
741 BYTE* const oMaxMatch = op + targetDstSize - (LASTLITERALS + 1 /* token */);
742 BYTE* const oMaxSeq = oMaxLit - 1 /* token */;
743
744 U32 forwardH;
745
746
747 /* Init conditions */
748 if (targetDstSize < 1) return 0; /* Impossible to store anything */
749 if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */
750 if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */
751 if (*srcSizePtr<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */
752
753 /* First Byte */
754 *srcSizePtr = 0;
755 LZ4_putPosition(ip, ctx, tableType, base);
756 ip++; forwardH = LZ4_hashPosition(ip, tableType);
757
758 /* Main Loop */
759 for ( ; ; )
760 {
761 const BYTE* match;
762 BYTE* token;
763 {
764 const BYTE* forwardIp = ip;
765 unsigned step = 1;
766 unsigned searchMatchNb = 1 << LZ4_skipTrigger;
767
768 /* Find a match */
769 do {
770 U32 h = forwardH;
771 ip = forwardIp;
772 forwardIp += step;
773 step = (searchMatchNb++ >> LZ4_skipTrigger);
774
775 if (unlikely(forwardIp > mflimit))
776 goto _last_literals;
777
778 match = LZ4_getPositionOnHash(h, ctx, tableType, base);
779 forwardH = LZ4_hashPosition(forwardIp, tableType);
780 LZ4_putPositionOnHash(ip, h, ctx, tableType, base);
781
782 } while ( ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip))
783 || (LZ4_read32(match) != LZ4_read32(ip)) );
784 }
785
786 /* Catch up */
787 while ((ip>anchor) && (match > lowLimit) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; }
788
789 {
790 /* Encode Literal length */
791 unsigned litLength = (unsigned)(ip - anchor);
792 token = op++;
793 if (op + ((litLength+240)/255) + litLength > oMaxLit)
794 {
795 /* Not enough space for a last match */
796 op--;
797 goto _last_literals;
798 }
799 if (litLength>=RUN_MASK)
800 {
801 unsigned len = litLength - RUN_MASK;
802 *token=(RUN_MASK<<ML_BITS);
803 for(; len >= 255 ; len-=255) *op++ = 255;
804 *op++ = (BYTE)len;
805 }
806 else *token = (BYTE)(litLength<<ML_BITS);
807
808 /* Copy Literals */
809 LZ4_wildCopy(op, anchor, op+litLength);
810 op += litLength;
811 }
812
813_next_match:
814 /* Encode Offset */
815 LZ4_writeLE16(op, (U16)(ip-match)); op+=2;
816
817 /* Encode MatchLength */
818 {
819 size_t matchLength;
820
821 matchLength = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit);
822
823 if (op + ((matchLength+240)/255) > oMaxMatch)
824 {
825 /* Match description too long : reduce it */
826 matchLength = (15-1) + (oMaxMatch-op) * 255;
827 }
828 //printf("offset %5i, matchLength%5i \n", (int)(ip-match), matchLength + MINMATCH);
829 ip += MINMATCH + matchLength;
830
831 if (matchLength>=ML_MASK)
832 {
833 *token += ML_MASK;
834 matchLength -= ML_MASK;
835 while (matchLength >= 255) { matchLength-=255; *op++ = 255; }
836 *op++ = (BYTE)matchLength;
837 }
838 else *token += (BYTE)(matchLength);
839 }
840
841 anchor = ip;
842
843 /* Test end of block */
844 if (ip > mflimit) break;
845 if (op > oMaxSeq) break;
846
847 /* Fill table */
848 LZ4_putPosition(ip-2, ctx, tableType, base);
849
850 /* Test next position */
851 match = LZ4_getPosition(ip, ctx, tableType, base);
852 LZ4_putPosition(ip, ctx, tableType, base);
853 if ( (match+MAX_DISTANCE>=ip)
854 && (LZ4_read32(match)==LZ4_read32(ip)) )
855 { token=op++; *token=0; goto _next_match; }
856
857 /* Prepare next loop */
858 forwardH = LZ4_hashPosition(++ip, tableType);
859 }
860
861_last_literals:
862 /* Encode Last Literals */
863 {
864 size_t lastRunSize = (size_t)(iend - anchor);
865 if (op + 1 /* token */ + ((lastRunSize+240)/255) /* litLength */ + lastRunSize /* literals */ > oend)
866 {
867 /* adapt lastRunSize to fill 'dst' */
868 lastRunSize = (oend-op) - 1;
869 lastRunSize -= (lastRunSize+240)/255;
870 }
871 ip = anchor + lastRunSize;
872
873 if (lastRunSize >= RUN_MASK)
874 {
875 size_t accumulator = lastRunSize - RUN_MASK;
876 *op++ = RUN_MASK << ML_BITS;
877 for(; accumulator >= 255 ; accumulator-=255) *op++ = 255;
878 *op++ = (BYTE) accumulator;
879 }
880 else
881 {
882 *op++ = (BYTE)(lastRunSize<<ML_BITS);
883 }
884 memcpy(op, anchor, lastRunSize);
885 op += lastRunSize;
886 }
887
888 /* End */
889 *srcSizePtr = (int) (((const char*)ip)-src);
890 return (int) (((char*)op)-dst);
891}
892
893
894static int LZ4_compress_destSize_extState (void* state, const char* src, char* dst, int* srcSizePtr, int targetDstSize)
895{
896 LZ4_resetStream((LZ4_stream_t*)state);
897
898 if (targetDstSize >= LZ4_compressBound(*srcSizePtr)) /* compression success is guaranteed */
899 {
900 return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr, targetDstSize, 1);
901 }
902 else
903 {
904 if (*srcSizePtr < LZ4_64Klimit)
905 return LZ4_compress_destSize_generic(state, src, dst, srcSizePtr, targetDstSize, byU16);
906 else
907 return LZ4_compress_destSize_generic(state, src, dst, srcSizePtr, targetDstSize, LZ4_64bits() ? byU32 : byPtr);
908 }
909}
910
911
912int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize)
731{ 913{
732#if (HEAPMODE) 914#if (HEAPMODE)
733 void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U64, 8); /* Aligned on 8-bytes boundaries */ 915 void* ctx = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
734#else 916#else
735 U64 ctx[LZ4_STREAMSIZE_U64] = {0}; /* Ensure data is aligned on 8-bytes boundaries */ 917 LZ4_stream_t ctxBody;
918 void* ctx = &ctxBody;
736#endif 919#endif
737 int result;
738 920
739 if (inputSize < LZ4_64Klimit) 921 int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize);
740 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue);
741 else
742 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue);
743 922
744#if (HEAPMODE) 923#if (HEAPMODE)
745 FREEMEM(ctx); 924 FREEMEM(ctx);
@@ -748,19 +927,10 @@ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, in
748} 927}
749 928
750 929
751/*****************************************
752* Experimental : Streaming functions
753*****************************************/
754 930
755/* 931/********************************
756 * LZ4_initStream 932* Streaming functions
757 * Use this function once, to init a newly allocated LZ4_stream_t structure 933********************************/
758 * Return : 1 if OK, 0 if error
759 */
760void LZ4_resetStream (LZ4_stream_t* LZ4_stream)
761{
762 MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t));
763}
764 934
765LZ4_stream_t* LZ4_createStream(void) 935LZ4_stream_t* LZ4_createStream(void)
766{ 936{
@@ -770,6 +940,11 @@ LZ4_stream_t* LZ4_createStream(void)
770 return lz4s; 940 return lz4s;
771} 941}
772 942
943void LZ4_resetStream (LZ4_stream_t* LZ4_stream)
944{
945 MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t));
946}
947
773int LZ4_freeStream (LZ4_stream_t* LZ4_stream) 948int LZ4_freeStream (LZ4_stream_t* LZ4_stream)
774{ 949{
775 FREEMEM(LZ4_stream); 950 FREEMEM(LZ4_stream);
@@ -777,6 +952,7 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_stream)
777} 952}
778 953
779 954
955#define HASH_UNIT sizeof(size_t)
780int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) 956int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
781{ 957{
782 LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict; 958 LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict;
@@ -784,24 +960,26 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
784 const BYTE* const dictEnd = p + dictSize; 960 const BYTE* const dictEnd = p + dictSize;
785 const BYTE* base; 961 const BYTE* base;
786 962
787 if (dict->initCheck) LZ4_resetStream(LZ4_dict); /* Uninitialized structure detected */ 963 if ((dict->initCheck) || (dict->currentOffset > 1 GB)) /* Uninitialized structure, or reuse overflow */
964 LZ4_resetStream(LZ4_dict);
788 965
789 if (dictSize < MINMATCH) 966 if (dictSize < (int)HASH_UNIT)
790 { 967 {
791 dict->dictionary = NULL; 968 dict->dictionary = NULL;
792 dict->dictSize = 0; 969 dict->dictSize = 0;
793 return 0; 970 return 0;
794 } 971 }
795 972
796 if (p <= dictEnd - 64 KB) p = dictEnd - 64 KB; 973 if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB;
974 dict->currentOffset += 64 KB;
797 base = p - dict->currentOffset; 975 base = p - dict->currentOffset;
798 dict->dictionary = p; 976 dict->dictionary = p;
799 dict->dictSize = (U32)(dictEnd - p); 977 dict->dictSize = (U32)(dictEnd - p);
800 dict->currentOffset += dict->dictSize; 978 dict->currentOffset += dict->dictSize;
801 979
802 while (p <= dictEnd-MINMATCH) 980 while (p <= dictEnd-HASH_UNIT)
803 { 981 {
804 LZ4_putPosition(p, dict, byU32, base); 982 LZ4_putPosition(p, dict->hashTable, byU32, base);
805 p+=3; 983 p+=3;
806 } 984 }
807 985
@@ -830,8 +1008,7 @@ static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src)
830} 1008}
831 1009
832 1010
833FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* source, char* dest, int inputSize, 1011int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
834 int maxOutputSize, limitedOutput_directive limit)
835{ 1012{
836 LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_stream; 1013 LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_stream;
837 const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; 1014 const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
@@ -840,6 +1017,7 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so
840 if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */ 1017 if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */
841 if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd; 1018 if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd;
842 LZ4_renormDictT(streamPtr, smallest); 1019 LZ4_renormDictT(streamPtr, smallest);
1020 if (acceleration < 1) acceleration = ACCELERATION_DEFAULT;
843 1021
844 /* Check overlapping input/dictionary space */ 1022 /* Check overlapping input/dictionary space */
845 { 1023 {
@@ -858,9 +1036,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so
858 { 1036 {
859 int result; 1037 int result;
860 if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) 1038 if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
861 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall); 1039 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, acceleration);
862 else 1040 else
863 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue); 1041 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, acceleration);
864 streamPtr->dictSize += (U32)inputSize; 1042 streamPtr->dictSize += (U32)inputSize;
865 streamPtr->currentOffset += (U32)inputSize; 1043 streamPtr->currentOffset += (U32)inputSize;
866 return result; 1044 return result;
@@ -870,9 +1048,9 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so
870 { 1048 {
871 int result; 1049 int result;
872 if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) 1050 if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
873 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall); 1051 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration);
874 else 1052 else
875 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue); 1053 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration);
876 streamPtr->dictionary = (const BYTE*)source; 1054 streamPtr->dictionary = (const BYTE*)source;
877 streamPtr->dictSize = (U32)inputSize; 1055 streamPtr->dictSize = (U32)inputSize;
878 streamPtr->currentOffset += (U32)inputSize; 1056 streamPtr->currentOffset += (U32)inputSize;
@@ -880,18 +1058,8 @@ FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* so
880 } 1058 }
881} 1059}
882 1060
883int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize)
884{
885 return LZ4_compress_continue_generic(LZ4_stream, source, dest, inputSize, 0, notLimited);
886}
887
888int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize)
889{
890 return LZ4_compress_continue_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput);
891}
892
893 1061
894/* Hidden debug function, to force separate dictionary mode */ 1062/* Hidden debug function, to force external dictionary mode */
895int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize) 1063int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize)
896{ 1064{
897 LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_dict; 1065 LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_dict;
@@ -902,7 +1070,7 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char*
902 if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; 1070 if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
903 LZ4_renormDictT((LZ4_stream_t_internal*)LZ4_dict, smallest); 1071 LZ4_renormDictT((LZ4_stream_t_internal*)LZ4_dict, smallest);
904 1072
905 result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue); 1073 result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 1);
906 1074
907 streamPtr->dictionary = (const BYTE*)source; 1075 streamPtr->dictionary = (const BYTE*)source;
908 streamPtr->dictSize = (U32)inputSize; 1076 streamPtr->dictSize = (U32)inputSize;
@@ -955,7 +1123,7 @@ FORCE_INLINE int LZ4_decompress_generic(
955 ) 1123 )
956{ 1124{
957 /* Local Variables */ 1125 /* Local Variables */
958 const BYTE* restrict ip = (const BYTE*) source; 1126 const BYTE* ip = (const BYTE*) source;
959 const BYTE* const iend = ip + inputSize; 1127 const BYTE* const iend = ip + inputSize;
960 1128
961 BYTE* op = (BYTE*) dest; 1129 BYTE* op = (BYTE*) dest;
@@ -1051,8 +1219,7 @@ FORCE_INLINE int LZ4_decompress_generic(
1051 { 1219 {
1052 /* match can be copied as a single segment from external dictionary */ 1220 /* match can be copied as a single segment from external dictionary */
1053 match = dictEnd - (lowPrefix-match); 1221 match = dictEnd - (lowPrefix-match);
1054 memcpy(op, match, length); 1222 memmove(op, match, length); op += length;
1055 op += length;
1056 } 1223 }
1057 else 1224 else
1058 { 1225 {
@@ -1110,11 +1277,11 @@ FORCE_INLINE int LZ4_decompress_generic(
1110 if (endOnInput) 1277 if (endOnInput)
1111 return (int) (((char*)op)-dest); /* Nb of output bytes decoded */ 1278 return (int) (((char*)op)-dest); /* Nb of output bytes decoded */
1112 else 1279 else
1113 return (int) (((char*)ip)-source); /* Nb of input bytes read */ 1280 return (int) (((const char*)ip)-source); /* Nb of input bytes read */
1114 1281
1115 /* Overflow error detected */ 1282 /* Overflow error detected */
1116_output_error: 1283_output_error:
1117 return (int) (-(((char*)ip)-source))-1; 1284 return (int) (-(((const char*)ip)-source))-1;
1118} 1285}
1119 1286
1120 1287
@@ -1138,9 +1305,9 @@ int LZ4_decompress_fast(const char* source, char* dest, int originalSize)
1138 1305
1139typedef struct 1306typedef struct
1140{ 1307{
1141 BYTE* externalDict; 1308 const BYTE* externalDict;
1142 size_t extDictSize; 1309 size_t extDictSize;
1143 BYTE* prefixEnd; 1310 const BYTE* prefixEnd;
1144 size_t prefixSize; 1311 size_t prefixSize;
1145} LZ4_streamDecode_t_internal; 1312} LZ4_streamDecode_t_internal;
1146 1313
@@ -1172,7 +1339,7 @@ int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dicti
1172{ 1339{
1173 LZ4_streamDecode_t_internal* lz4sd = (LZ4_streamDecode_t_internal*) LZ4_streamDecode; 1340 LZ4_streamDecode_t_internal* lz4sd = (LZ4_streamDecode_t_internal*) LZ4_streamDecode;
1174 lz4sd->prefixSize = (size_t) dictSize; 1341 lz4sd->prefixSize = (size_t) dictSize;
1175 lz4sd->prefixEnd = (BYTE*) dictionary + dictSize; 1342 lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize;
1176 lz4sd->externalDict = NULL; 1343 lz4sd->externalDict = NULL;
1177 lz4sd->extDictSize = 0; 1344 lz4sd->extDictSize = 0;
1178 return 1; 1345 return 1;
@@ -1261,7 +1428,7 @@ FORCE_INLINE int LZ4_decompress_usingDict_generic(const char* source, char* dest
1261 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0); 1428 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0);
1262 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0); 1429 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0);
1263 } 1430 }
1264 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (BYTE*)dictStart, dictSize); 1431 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize);
1265} 1432}
1266 1433
1267int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) 1434int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize)
@@ -1277,13 +1444,21 @@ int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSi
1277/* debug function */ 1444/* debug function */
1278int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) 1445int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize)
1279{ 1446{
1280 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (BYTE*)dictStart, dictSize); 1447 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize);
1281} 1448}
1282 1449
1283 1450
1284/*************************************************** 1451/***************************************************
1285* Obsolete Functions 1452* Obsolete Functions
1286***************************************************/ 1453***************************************************/
1454/* obsolete compression functions */
1455int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_default(source, dest, inputSize, maxOutputSize); }
1456int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_default(source, dest, inputSize, LZ4_compressBound(inputSize)); }
1457int 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); }
1458int 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); }
1459int 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); }
1460int 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); }
1461
1287/* 1462/*
1288These function names are deprecated and should no longer be used. 1463These function names are deprecated and should no longer be used.
1289They are only provided here for compatibility with older user programs. 1464They are only provided here for compatibility with older user programs.
@@ -1298,23 +1473,23 @@ int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize,
1298 1473
1299int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; } 1474int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; }
1300 1475
1301static void LZ4_init(LZ4_stream_t_internal* lz4ds, const BYTE* base) 1476static void LZ4_init(LZ4_stream_t_internal* lz4ds, BYTE* base)
1302{ 1477{
1303 MEM_INIT(lz4ds, 0, LZ4_STREAMSIZE); 1478 MEM_INIT(lz4ds, 0, LZ4_STREAMSIZE);
1304 lz4ds->bufferStart = base; 1479 lz4ds->bufferStart = base;
1305} 1480}
1306 1481
1307int LZ4_resetStreamState(void* state, const char* inputBuffer) 1482int LZ4_resetStreamState(void* state, char* inputBuffer)
1308{ 1483{
1309 if ((((size_t)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */ 1484 if ((((size_t)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */
1310 LZ4_init((LZ4_stream_t_internal*)state, (const BYTE*)inputBuffer); 1485 LZ4_init((LZ4_stream_t_internal*)state, (BYTE*)inputBuffer);
1311 return 0; 1486 return 0;
1312} 1487}
1313 1488
1314void* LZ4_create (const char* inputBuffer) 1489void* LZ4_create (char* inputBuffer)
1315{ 1490{
1316 void* lz4ds = ALLOCATOR(8, LZ4_STREAMSIZE_U64); 1491 void* lz4ds = ALLOCATOR(8, LZ4_STREAMSIZE_U64);
1317 LZ4_init ((LZ4_stream_t_internal*)lz4ds, (const BYTE*)inputBuffer); 1492 LZ4_init ((LZ4_stream_t_internal*)lz4ds, (BYTE*)inputBuffer);
1318 return lz4ds; 1493 return lz4ds;
1319} 1494}
1320 1495
@@ -1325,32 +1500,6 @@ char* LZ4_slideInputBuffer (void* LZ4_Data)
1325 return (char*)(ctx->bufferStart + dictSize); 1500 return (char*)(ctx->bufferStart + dictSize);
1326} 1501}
1327 1502
1328/* Obsolete compresson functions using User-allocated state */
1329
1330int LZ4_sizeofState() { return LZ4_STREAMSIZE; }
1331
1332int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize)
1333{
1334 if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
1335 MEM_INIT(state, 0, LZ4_STREAMSIZE);
1336
1337 if (inputSize < LZ4_64Klimit)
1338 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue);
1339 else
1340 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue);
1341}
1342
1343int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
1344{
1345 if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
1346 MEM_INIT(state, 0, LZ4_STREAMSIZE);
1347
1348 if (inputSize < LZ4_64Klimit)
1349 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue);
1350 else
1351 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, LZ4_64bits() ? byU32 : byPtr, noDict, noDictIssue);
1352}
1353
1354/* Obsolete streaming decompression functions */ 1503/* Obsolete streaming decompression functions */
1355 1504
1356int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize) 1505int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize)
diff --git a/src/static_libs/lz4/lz4.h b/src/static_libs/lz4/lz4.h
index de43fc0a20..3e74002256 100644
--- a/src/static_libs/lz4/lz4.h
+++ b/src/static_libs/lz4/lz4.h
@@ -39,17 +39,17 @@ extern "C" {
39#endif 39#endif
40 40
41/* 41/*
42 * lz4.h provides block compression functions, for optimal performance. 42 * lz4.h provides block compression functions, and gives full buffer control to programmer.
43 * If you need to generate inter-operable compressed data (respecting LZ4 frame specification), 43 * If you need to generate inter-operable compressed data (respecting LZ4 frame specification),
44 * please use lz4frame.h instead. 44 * and can let the library handle its own memory, please use lz4frame.h instead.
45*/ 45*/
46 46
47/************************************** 47/**************************************
48* Version 48* Version
49**************************************/ 49**************************************/
50#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */ 50#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
51#define LZ4_VERSION_MINOR 6 /* for new (non-breaking) interface capabilities */ 51#define LZ4_VERSION_MINOR 7 /* for new (non-breaking) interface capabilities */
52#define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */ 52#define LZ4_VERSION_RELEASE 1 /* for tweaks, bug-fixes, or development */
53#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE) 53#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
54int LZ4_versionNumber (void); 54int LZ4_versionNumber (void);
55 55
@@ -70,28 +70,32 @@ int LZ4_versionNumber (void);
70* Simple Functions 70* Simple Functions
71**************************************/ 71**************************************/
72 72
73int LZ4_compress (const char* source, char* dest, int sourceSize); 73int LZ4_compress_default(const char* source, char* dest, int sourceSize, int maxDestSize);
74int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize); 74int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize);
75 75
76/* 76/*
77LZ4_compress() : 77LZ4_compress_default() :
78 Compresses 'sourceSize' bytes from 'source' into 'dest'. 78 Compresses 'sourceSize' bytes from buffer 'source'
79 Destination buffer must be already allocated, 79 into already allocated 'dest' buffer of size 'maxDestSize'.
80 and must be sized to handle worst cases situations (input data not compressible) 80 Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize).
81 Worst case size evaluation is provided by function LZ4_compressBound() 81 It also runs faster, so it's a recommended setting.
82 inputSize : Max supported value is LZ4_MAX_INPUT_SIZE 82 If the function cannot compress 'source' into a more limited 'dest' budget,
83 return : the number of bytes written in buffer dest 83 compression stops *immediately*, and the function result is zero.
84 or 0 if the compression fails 84 As a consequence, 'dest' content is not valid.
85 This function never writes outside 'dest' buffer, nor read outside 'source' buffer.
86 sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE
87 maxDestSize : full or partial size of buffer 'dest' (which must be already allocated)
88 return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize)
89 or 0 if compression fails
85 90
86LZ4_decompress_safe() : 91LZ4_decompress_safe() :
87 compressedSize : is obviously the source size 92 compressedSize : is the precise full size of the compressed block.
88 maxDecompressedSize : is the size of the destination buffer, which must be already allocated. 93 maxDecompressedSize : is the size of destination buffer, which must be already allocated.
89 return : the number of bytes decompressed into the destination buffer (necessarily <= maxDecompressedSize) 94 return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize)
90 If the destination buffer is not large enough, decoding will stop and output an error code (<0). 95 If destination buffer is not large enough, decoding will stop and output an error code (<0).
91 If the source stream is detected malformed, the function will stop decoding and return a negative result. 96 If the source stream is detected malformed, the function will stop decoding and return a negative result.
92 This function is protected against buffer overflow exploits, 97 This function is protected against buffer overflow exploits, including malicious data packets.
93 and never writes outside of output buffer, nor reads outside of input buffer. 98 It never writes outside output buffer, nor reads outside input buffer.
94 It is also protected against malicious data packets.
95*/ 99*/
96 100
97 101
@@ -99,45 +103,54 @@ LZ4_decompress_safe() :
99* Advanced Functions 103* Advanced Functions
100**************************************/ 104**************************************/
101#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */ 105#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
102#define LZ4_COMPRESSBOUND(isize) ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16) 106#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
103 107
104/* 108/*
105LZ4_compressBound() : 109LZ4_compressBound() :
106 Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible) 110 Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
107 This function is primarily useful for memory allocation purposes (output buffer size). 111 This function is primarily useful for memory allocation purposes (destination buffer size).
108 Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example). 112 Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
109 113 Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize)
110 isize : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE 114 inputSize : max supported value is LZ4_MAX_INPUT_SIZE
111 return : maximum output size in a "worst case" scenario 115 return : maximum output size in a "worst case" scenario
112 or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) 116 or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
113*/ 117*/
114int LZ4_compressBound(int isize); 118int LZ4_compressBound(int inputSize);
115
116 119
117/* 120/*
118LZ4_compress_limitedOutput() : 121LZ4_compress_fast() :
119 Compress 'sourceSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'. 122 Same as LZ4_compress_default(), but allows to select an "acceleration" factor.
120 If it cannot achieve it, compression will stop, and result of the function will be zero. 123 The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
121 This saves time and memory on detecting non-compressible (or barely compressible) data. 124 It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
122 This function never writes outside of provided output buffer. 125 An acceleration value of "1" is the same as regular LZ4_compress_default()
123 126 Values <= 0 will be replaced by ACCELERATION_DEFAULT (see lz4.c), which is 1.
124 sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE
125 maxOutputSize : is the size of the destination buffer (which must be already allocated)
126 return : the number of bytes written in buffer 'dest'
127 or 0 if compression fails
128*/ 127*/
129int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); 128int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, int acceleration);
130 129
131 130
132/* 131/*
133LZ4_compress_withState() : 132LZ4_compress_fast_extState() :
134 Same compression functions, but using an externally allocated memory space to store compression state. 133 Same compression function, just using an externally allocated memory space to store compression state.
135 Use LZ4_sizeofState() to know how much memory must be allocated, 134 Use LZ4_sizeofState() to know how much memory must be allocated,
136 and then, provide it as 'void* state' to compression functions. 135 and allocate it on 8-bytes boundaries (using malloc() typically).
136 Then, provide it as 'void* state' to compression function.
137*/ 137*/
138int LZ4_sizeofState(void); 138int LZ4_sizeofState(void);
139int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); 139int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, int acceleration);
140int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); 140
141
142/*
143LZ4_compress_destSize() :
144 Reverse the logic, by compressing as much data as possible from 'source' buffer
145 into already allocated buffer 'dest' of size 'targetDestSize'.
146 This function either compresses the entire 'source' content into 'dest' if it's large enough,
147 or fill 'dest' buffer completely with as much data as possible from 'source'.
148 *sourceSizePtr : will be modified to indicate how many bytes where read from 'source' to fill 'dest'.
149 New value is necessarily <= old value.
150 return : Nb bytes written into 'dest' (necessarily <= targetDestSize)
151 or 0 if compression fails
152*/
153int LZ4_compress_destSize (const char* source, char* dest, int* sourceSizePtr, int targetDestSize);
141 154
142 155
143/* 156/*
@@ -153,7 +166,6 @@ LZ4_decompress_fast() :
153*/ 166*/
154int LZ4_decompress_fast (const char* source, char* dest, int originalSize); 167int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
155 168
156
157/* 169/*
158LZ4_decompress_safe_partial() : 170LZ4_decompress_safe_partial() :
159 This function decompress a compressed block of size 'compressedSize' at position 'source' 171 This function decompress a compressed block of size 'compressedSize' at position 'source'
@@ -172,7 +184,6 @@ int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedS
172/*********************************************** 184/***********************************************
173* Streaming Compression Functions 185* Streaming Compression Functions
174***********************************************/ 186***********************************************/
175
176#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4) 187#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
177#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(long long)) 188#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(long long))
178/* 189/*
@@ -188,7 +199,7 @@ typedef struct { long long table[LZ4_STREAMSIZE_U64]; } LZ4_stream_t;
188 * LZ4_resetStream 199 * LZ4_resetStream
189 * Use this function to init an allocated LZ4_stream_t structure 200 * Use this function to init an allocated LZ4_stream_t structure
190 */ 201 */
191void LZ4_resetStream (LZ4_stream_t* LZ4_streamPtr); 202void LZ4_resetStream (LZ4_stream_t* streamPtr);
192 203
193/* 204/*
194 * LZ4_createStream will allocate and initialize an LZ4_stream_t structure 205 * LZ4_createStream will allocate and initialize an LZ4_stream_t structure
@@ -197,7 +208,7 @@ void LZ4_resetStream (LZ4_stream_t* LZ4_streamPtr);
197 * They are more future proof, in case of a change of LZ4_stream_t size. 208 * They are more future proof, in case of a change of LZ4_stream_t size.
198 */ 209 */
199LZ4_stream_t* LZ4_createStream(void); 210LZ4_stream_t* LZ4_createStream(void);
200int LZ4_freeStream (LZ4_stream_t* LZ4_streamPtr); 211int LZ4_freeStream (LZ4_stream_t* streamPtr);
201 212
202/* 213/*
203 * LZ4_loadDict 214 * LZ4_loadDict
@@ -206,32 +217,27 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_streamPtr);
206 * Loading a size of 0 is allowed. 217 * Loading a size of 0 is allowed.
207 * Return : dictionary size, in bytes (necessarily <= 64 KB) 218 * Return : dictionary size, in bytes (necessarily <= 64 KB)
208 */ 219 */
209int LZ4_loadDict (LZ4_stream_t* LZ4_streamPtr, const char* dictionary, int dictSize); 220int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
210 221
211/* 222/*
212 * LZ4_compress_continue 223 * LZ4_compress_fast_continue
213 * Compress data block 'source', using blocks compressed before as dictionary to improve compression ratio 224 * Compress buffer content 'src', using data from previously compressed blocks as dictionary to improve compression ratio.
214 * Previous data blocks are assumed to still be present at their previous location. 225 * Important : Previous data blocks are assumed to still be present and unmodified !
215 * dest buffer must be already allocated, and sized to at least LZ4_compressBound(inputSize) 226 * 'dst' buffer must be already allocated.
227 * If maxDstSize >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
228 * If not, and if compressed data cannot fit into 'dst' buffer size, compression stops, and function returns a zero.
216 */ 229 */
217int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); 230int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int maxDstSize, int acceleration);
218
219/*
220 * LZ4_compress_limitedOutput_continue
221 * Same as before, but also specify a maximum target compressed size (maxOutputSize)
222 * If objective cannot be met, compression exits, and returns a zero.
223 */
224int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
225 231
226/* 232/*
227 * LZ4_saveDict 233 * LZ4_saveDict
228 * If previously compressed data block is not guaranteed to remain available at its memory location 234 * If previously compressed data block is not guaranteed to remain available at its memory location
229 * save it into a safer place (char* safeBuffer) 235 * save it into a safer place (char* safeBuffer)
230 * Note : you don't need to call LZ4_loadDict() afterwards, 236 * Note : you don't need to call LZ4_loadDict() afterwards,
231 * dictionary is immediately usable, you can therefore call again LZ4_compress_continue() 237 * dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue()
232 * Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error 238 * Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error
233 */ 239 */
234int LZ4_saveDict (LZ4_stream_t* LZ4_streamPtr, char* safeBuffer, int dictSize); 240int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize);
235 241
236 242
237/************************************************ 243/************************************************
@@ -266,8 +272,18 @@ int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dicti
266*_continue() : 272*_continue() :
267 These decoding functions allow decompression of multiple blocks in "streaming" mode. 273 These decoding functions allow decompression of multiple blocks in "streaming" mode.
268 Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB) 274 Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB)
269 If this condition is not possible, save the relevant part of decoded data into a safe buffer, 275 In the case of a ring buffers, decoding buffer must be either :
270 and indicate where is its new address using LZ4_setStreamDecode() 276 - Exactly same size as encoding buffer, with same update rule (block boundaries at same positions)
277 In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB).
278 - Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
279 maxBlockSize is implementation dependent. It's the maximum size you intend to compress into a single block.
280 In which case, encoding and decoding buffers do not need to be synchronized,
281 and encoding ring buffer can have any size, including small ones ( < 64 KB).
282 - _At least_ 64 KB + 8 bytes + maxBlockSize.
283 In which case, encoding and decoding buffers do not need to be synchronized,
284 and encoding ring buffer can have any size, including larger than decoding buffer.
285 Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer,
286 and indicate where it is saved using LZ4_setStreamDecode()
271*/ 287*/
272int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize); 288int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize);
273int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize); 289int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize);
@@ -277,8 +293,8 @@ int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const ch
277Advanced decoding functions : 293Advanced decoding functions :
278*_usingDict() : 294*_usingDict() :
279 These decoding functions work the same as 295 These decoding functions work the same as
280 a combination of LZ4_setDictDecode() followed by LZ4_decompress_x_continue() 296 a combination of LZ4_setStreamDecode() followed by LZ4_decompress_x_continue()
281 They are stand-alone and don't use nor update an LZ4_streamDecode_t structure. 297 They are stand-alone. They don't need nor update an LZ4_streamDecode_t structure.
282*/ 298*/
283int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize); 299int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize);
284int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize); 300int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize);
@@ -288,27 +304,55 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS
288/************************************** 304/**************************************
289* Obsolete Functions 305* Obsolete Functions
290**************************************/ 306**************************************/
291/* 307/* Deprecate Warnings */
292Obsolete decompression functions 308/* Should these warnings messages be a problem,
293These function names are deprecated and should no longer be used. 309 it is generally possible to disable them,
294They are only provided here for compatibility with older user programs. 310 with -Wno-deprecated-declarations for gcc
295- LZ4_uncompress is the same as LZ4_decompress_fast 311 or _CRT_SECURE_NO_WARNINGS in Visual for example.
296- LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe 312 You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */
297These function prototypes are now disabled; uncomment them if you really need them. 313#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK
298It is highly recommended to stop using these functions and migrate to newer ones */ 314# define LZ4_DEPRECATE_WARNING_DEFBLOCK
315# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
316# if (LZ4_GCC_VERSION >= 405) || defined(__clang__)
317# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
318# elif (LZ4_GCC_VERSION >= 301)
319# define LZ4_DEPRECATED(message) __attribute__((deprecated))
320# elif defined(_MSC_VER)
321# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
322# else
323# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
324# define LZ4_DEPRECATED(message)
325# endif
326#endif /* LZ4_DEPRECATE_WARNING_DEFBLOCK */
327
328/* Obsolete compression functions */
329/* These functions are planned to start generate warnings by r131 approximately */
330int LZ4_compress (const char* source, char* dest, int sourceSize);
331int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize);
332int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
333int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
334int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
335int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
336
337/* Obsolete decompression functions */
338/* These function names are completely deprecated and must no longer be used.
339 They are only provided here for compatibility with older programs.
340 - LZ4_uncompress is the same as LZ4_decompress_fast
341 - LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe
342 These function prototypes are now disabled; uncomment them only if you really need them.
343 It is highly recommended to stop using these prototypes and migrate to maintained ones */
299/* int LZ4_uncompress (const char* source, char* dest, int outputSize); */ 344/* int LZ4_uncompress (const char* source, char* dest, int outputSize); */
300/* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */ 345/* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */
301 346
302
303/* Obsolete streaming functions; use new streaming interface whenever possible */ 347/* Obsolete streaming functions; use new streaming interface whenever possible */
304void* LZ4_create (const char* inputBuffer); 348LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer);
305int LZ4_sizeofStreamState(void); 349LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void);
306int LZ4_resetStreamState(void* state, const char* inputBuffer); 350LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer);
307char* LZ4_slideInputBuffer (void* state); 351LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state);
308 352
309/* Obsolete streaming decoding functions */ 353/* Obsolete streaming decoding functions */
310int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize); 354LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
311int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize); 355LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
312 356
313 357
314#if defined (__cplusplus) 358#if defined (__cplusplus)
diff --git a/src/static_libs/lz4/lz4hc.c b/src/static_libs/lz4/lz4hc.c
index c7a94a0678..bbe7a9d2d7 100644
--- a/src/static_libs/lz4/lz4hc.c
+++ b/src/static_libs/lz4/lz4hc.c
@@ -1,53 +1,53 @@
1/* 1/*
2LZ4 HC - High Compression Mode of LZ4 2 LZ4 HC - High Compression Mode of LZ4
3Copyright (C) 2011-2015, Yann Collet. 3 Copyright (C) 2011-2015, Yann Collet.
4 4
5BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) 5 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6 6
7Redistribution and use in source and binary forms, with or without 7 Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are 8 modification, are permitted provided that the following conditions are
9met: 9 met:
10 10
11* Redistributions of source code must retain the above copyright 11 * Redistributions of source code must retain the above copyright
12notice, this list of conditions and the following disclaimer. 12 notice, this list of conditions and the following disclaimer.
13* Redistributions in binary form must reproduce the above 13 * Redistributions in binary form must reproduce the above
14copyright notice, this list of conditions and the following disclaimer 14 copyright notice, this list of conditions and the following disclaimer
15in the documentation and/or other materials provided with the 15 in the documentation and/or other materials provided with the
16distribution. 16 distribution.
17 17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30You can contact the author at : 30 You can contact the author at :
31 - LZ4 source repository : https://github.com/Cyan4973/lz4 31 - LZ4 source repository : https://github.com/Cyan4973/lz4
32 - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c 32 - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
33*/ 33*/
34 34
35 35
36 36
37/************************************** 37/**************************************
38 Tuning Parameter 38* Tuning Parameter
39**************************************/ 39**************************************/
40static const int LZ4HC_compressionLevel_default = 9; 40static const int LZ4HC_compressionLevel_default = 9;
41 41
42 42
43/************************************** 43/**************************************
44 Includes 44* Includes
45**************************************/ 45**************************************/
46#include "lz4hc.h" 46#include "lz4hc.h"
47 47
48 48
49/************************************** 49/**************************************
50 Local Compiler Options 50* Local Compiler Options
51**************************************/ 51**************************************/
52#if defined(__GNUC__) 52#if defined(__GNUC__)
53# pragma GCC diagnostic ignored "-Wunused-function" 53# pragma GCC diagnostic ignored "-Wunused-function"
@@ -59,18 +59,18 @@ static const int LZ4HC_compressionLevel_default = 9;
59 59
60 60
61/************************************** 61/**************************************
62 Common LZ4 definition 62* Common LZ4 definition
63**************************************/ 63**************************************/
64#define LZ4_COMMONDEFS_ONLY 64#define LZ4_COMMONDEFS_ONLY
65#include "lz4.c" 65#include "lz4.c"
66 66
67 67
68/************************************** 68/**************************************
69 Local Constants 69* Local Constants
70**************************************/ 70**************************************/
71#define DICTIONARY_LOGSIZE 16 71#define DICTIONARY_LOGSIZE 16
72#define MAXD (1<<DICTIONARY_LOGSIZE) 72#define MAXD (1<<DICTIONARY_LOGSIZE)
73#define MAXD_MASK ((U32)(MAXD - 1)) 73#define MAXD_MASK (MAXD - 1)
74 74
75#define HASH_LOG (DICTIONARY_LOGSIZE-1) 75#define HASH_LOG (DICTIONARY_LOGSIZE-1)
76#define HASHTABLESIZE (1 << HASH_LOG) 76#define HASHTABLESIZE (1 << HASH_LOG)
@@ -82,36 +82,36 @@ static const int g_maxCompressionLevel = 16;
82 82
83 83
84/************************************** 84/**************************************
85 Local Types 85* Local Types
86**************************************/ 86**************************************/
87typedef struct 87typedef struct
88{ 88{
89 U32 hashTable[HASHTABLESIZE]; 89 U32 hashTable[HASHTABLESIZE];
90 U16 chainTable[MAXD]; 90 U16 chainTable[MAXD];
91 const BYTE* end; /* next block here to continue on current prefix */ 91 const BYTE* end; /* next block here to continue on current prefix */
92 const BYTE* base; /* All index relative to this position */ 92 const BYTE* base; /* All index relative to this position */
93 const BYTE* dictBase; /* alternate base for extDict */ 93 const BYTE* dictBase; /* alternate base for extDict */
94 const BYTE* inputBuffer;/* deprecated */ 94 BYTE* inputBuffer; /* deprecated */
95 U32 dictLimit; /* below that point, need extDict */ 95 U32 dictLimit; /* below that point, need extDict */
96 U32 lowLimit; /* below that point, no more dict */ 96 U32 lowLimit; /* below that point, no more dict */
97 U32 nextToUpdate; 97 U32 nextToUpdate; /* index from which to continue dictionary update */
98 U32 compressionLevel; 98 U32 compressionLevel;
99} LZ4HC_Data_Structure; 99} LZ4HC_Data_Structure;
100 100
101 101
102/************************************** 102/**************************************
103 Local Macros 103* Local Macros
104**************************************/ 104**************************************/
105#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG)) 105#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG))
106#define DELTANEXT(p) chainTable[(size_t)(p) & MAXD_MASK] 106//#define DELTANEXTU16(p) chainTable[(p) & MAXD_MASK] /* flexible, MAXD dependent */
107#define GETNEXT(p) ((p) - (size_t)DELTANEXT(p)) 107#define DELTANEXTU16(p) chainTable[(U16)(p)] /* faster */
108 108
109static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); } 109static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); }
110 110
111 111
112 112
113/************************************** 113/**************************************
114 HC Compression 114* HC Compression
115**************************************/ 115**************************************/
116static void LZ4HC_init (LZ4HC_Data_Structure* hc4, const BYTE* start) 116static void LZ4HC_init (LZ4HC_Data_Structure* hc4, const BYTE* start)
117{ 117{
@@ -119,7 +119,6 @@ static void LZ4HC_init (LZ4HC_Data_Structure* hc4, const BYTE* start)
119 MEM_INIT(hc4->chainTable, 0xFF, sizeof(hc4->chainTable)); 119 MEM_INIT(hc4->chainTable, 0xFF, sizeof(hc4->chainTable));
120 hc4->nextToUpdate = 64 KB; 120 hc4->nextToUpdate = 64 KB;
121 hc4->base = start - 64 KB; 121 hc4->base = start - 64 KB;
122 hc4->inputBuffer = start;
123 hc4->end = start; 122 hc4->end = start;
124 hc4->dictBase = start - 64 KB; 123 hc4->dictBase = start - 64 KB;
125 hc4->dictLimit = 64 KB; 124 hc4->dictLimit = 64 KB;
@@ -141,7 +140,7 @@ FORCE_INLINE void LZ4HC_Insert (LZ4HC_Data_Structure* hc4, const BYTE* ip)
141 U32 h = LZ4HC_hashPtr(base+idx); 140 U32 h = LZ4HC_hashPtr(base+idx);
142 size_t delta = idx - HashTable[h]; 141 size_t delta = idx - HashTable[h];
143 if (delta>MAX_DISTANCE) delta = MAX_DISTANCE; 142 if (delta>MAX_DISTANCE) delta = MAX_DISTANCE;
144 chainTable[idx & 0xFFFF] = (U16)delta; 143 DELTANEXTU16(idx) = (U16)delta;
145 HashTable[h] = idx; 144 HashTable[h] = idx;
146 idx++; 145 idx++;
147 } 146 }
@@ -197,7 +196,7 @@ FORCE_INLINE int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure* hc4, /* I
197 if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; } /* virtual matchpos */ 196 if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; } /* virtual matchpos */
198 } 197 }
199 } 198 }
200 matchIndex -= chainTable[matchIndex & 0xFFFF]; 199 matchIndex -= DELTANEXTU16(matchIndex);
201 } 200 }
202 201
203 return (int)ml; 202 return (int)ml;
@@ -274,7 +273,7 @@ FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch (
274 if ((int)mlt > longest) { longest = (int)mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; } 273 if ((int)mlt > longest) { longest = (int)mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; }
275 } 274 }
276 } 275 }
277 matchIndex -= chainTable[matchIndex & 0xFFFF]; 276 matchIndex -= DELTANEXTU16(matchIndex);
278 } 277 }
279 278
280 return longest; 279 return longest;
@@ -536,63 +535,32 @@ _Search3:
536} 535}
537 536
538 537
539int LZ4_compressHC2(const char* source, char* dest, int inputSize, int compressionLevel)
540{
541 LZ4HC_Data_Structure ctx;
542 LZ4HC_init(&ctx, (const BYTE*)source);
543 return LZ4HC_compress_generic (&ctx, source, dest, inputSize, 0, compressionLevel, noLimit);
544}
545
546int LZ4_compressHC(const char* source, char* dest, int inputSize) { return LZ4_compressHC2(source, dest, inputSize, 0); }
547
548int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel)
549{
550 LZ4HC_Data_Structure ctx;
551 LZ4HC_init(&ctx, (const BYTE*)source);
552 return LZ4HC_compress_generic (&ctx, source, dest, inputSize, maxOutputSize, compressionLevel, limitedOutput);
553}
554
555int LZ4_compressHC_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize)
556{
557 return LZ4_compressHC2_limitedOutput(source, dest, inputSize, maxOutputSize, 0);
558}
559
560
561/*****************************
562 * Using external allocation
563 * ***************************/
564int LZ4_sizeofStateHC(void) { return sizeof(LZ4HC_Data_Structure); } 538int LZ4_sizeofStateHC(void) { return sizeof(LZ4HC_Data_Structure); }
565 539
566 540int LZ4_compress_HC_extStateHC (void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel)
567int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel)
568{ 541{
569 if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */ 542 if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */
570 LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)source); 543 LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)src);
571 return LZ4HC_compress_generic (state, source, dest, inputSize, 0, compressionLevel, noLimit); 544 if (maxDstSize < LZ4_compressBound(srcSize))
545 return LZ4HC_compress_generic (state, src, dst, srcSize, maxDstSize, compressionLevel, limitedOutput);
546 else
547 return LZ4HC_compress_generic (state, src, dst, srcSize, maxDstSize, compressionLevel, noLimit);
572} 548}
573 549
574int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize) 550int LZ4_compress_HC(const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel)
575{ return LZ4_compressHC2_withStateHC (state, source, dest, inputSize, 0); }
576
577
578int LZ4_compressHC2_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel)
579{ 551{
580 if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */ 552 LZ4HC_Data_Structure state;
581 LZ4HC_init ((LZ4HC_Data_Structure*)state, (const BYTE*)source); 553 return LZ4_compress_HC_extStateHC(&state, src, dst, srcSize, maxDstSize, compressionLevel);
582 return LZ4HC_compress_generic (state, source, dest, inputSize, maxOutputSize, compressionLevel, limitedOutput);
583} 554}
584 555
585int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
586{ return LZ4_compressHC2_limitedOutput_withStateHC (state, source, dest, inputSize, maxOutputSize, 0); }
587
588 556
589 557
590/************************************** 558/**************************************
591 * Streaming Functions 559* Streaming Functions
592 * ************************************/ 560**************************************/
593/* allocation */ 561/* allocation */
594LZ4_streamHC_t* LZ4_createStreamHC(void) { return (LZ4_streamHC_t*)malloc(sizeof(LZ4_streamHC_t)); } 562LZ4_streamHC_t* LZ4_createStreamHC(void) { return (LZ4_streamHC_t*)malloc(sizeof(LZ4_streamHC_t)); }
595int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) { free(LZ4_streamHCPtr); return 0; } 563int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr) { free(LZ4_streamHCPtr); return 0; }
596 564
597 565
598/* initialization */ 566/* initialization */
@@ -651,14 +619,15 @@ static int LZ4_compressHC_continue_generic (LZ4HC_Data_Structure* ctxPtr,
651 } 619 }
652 620
653 /* Check if blocks follow each other */ 621 /* Check if blocks follow each other */
654 if ((const BYTE*)source != ctxPtr->end) LZ4HC_setExternalDict(ctxPtr, (const BYTE*)source); 622 if ((const BYTE*)source != ctxPtr->end)
623 LZ4HC_setExternalDict(ctxPtr, (const BYTE*)source);
655 624
656 /* Check overlapping input/dictionary space */ 625 /* Check overlapping input/dictionary space */
657 { 626 {
658 const BYTE* sourceEnd = (const BYTE*) source + inputSize; 627 const BYTE* sourceEnd = (const BYTE*) source + inputSize;
659 const BYTE* dictBegin = ctxPtr->dictBase + ctxPtr->lowLimit; 628 const BYTE* dictBegin = ctxPtr->dictBase + ctxPtr->lowLimit;
660 const BYTE* dictEnd = ctxPtr->dictBase + ctxPtr->dictLimit; 629 const BYTE* dictEnd = ctxPtr->dictBase + ctxPtr->dictLimit;
661 if ((sourceEnd > dictBegin) && ((BYTE*)source < dictEnd)) 630 if ((sourceEnd > dictBegin) && ((const BYTE*)source < dictEnd))
662 { 631 {
663 if (sourceEnd > dictEnd) sourceEnd = dictEnd; 632 if (sourceEnd > dictEnd) sourceEnd = dictEnd;
664 ctxPtr->lowLimit = (U32)(sourceEnd - ctxPtr->dictBase); 633 ctxPtr->lowLimit = (U32)(sourceEnd - ctxPtr->dictBase);
@@ -669,14 +638,12 @@ static int LZ4_compressHC_continue_generic (LZ4HC_Data_Structure* ctxPtr,
669 return LZ4HC_compress_generic (ctxPtr, source, dest, inputSize, maxOutputSize, ctxPtr->compressionLevel, limit); 638 return LZ4HC_compress_generic (ctxPtr, source, dest, inputSize, maxOutputSize, ctxPtr->compressionLevel, limit);
670} 639}
671 640
672int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize) 641int LZ4_compress_HC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize)
673{ 642{
674 return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, 0, noLimit); 643 if (maxOutputSize < LZ4_compressBound(inputSize))
675} 644 return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, limitedOutput);
676 645 else
677int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize) 646 return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, noLimit);
678{
679 return LZ4_compressHC_continue_generic ((LZ4HC_Data_Structure*)LZ4_streamHCPtr, source, dest, inputSize, maxOutputSize, limitedOutput);
680} 647}
681 648
682 649
@@ -689,7 +656,7 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS
689 if (dictSize > 64 KB) dictSize = 64 KB; 656 if (dictSize > 64 KB) dictSize = 64 KB;
690 if (dictSize < 4) dictSize = 0; 657 if (dictSize < 4) dictSize = 0;
691 if (dictSize > prefixSize) dictSize = prefixSize; 658 if (dictSize > prefixSize) dictSize = prefixSize;
692 memcpy(safeBuffer, streamPtr->end - dictSize, dictSize); 659 memmove(safeBuffer, streamPtr->end - dictSize, dictSize);
693 { 660 {
694 U32 endIndex = (U32)(streamPtr->end - streamPtr->base); 661 U32 endIndex = (U32)(streamPtr->end - streamPtr->base);
695 streamPtr->end = (const BYTE*)safeBuffer + dictSize; 662 streamPtr->end = (const BYTE*)safeBuffer + dictSize;
@@ -703,21 +670,40 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS
703 670
704 671
705/*********************************** 672/***********************************
706 * Deprecated Functions 673* Deprecated Functions
707 ***********************************/ 674***********************************/
675/* Deprecated compression functions */
676/* These functions are planned to start generate warnings by r131 approximately */
677int LZ4_compressHC(const char* src, char* dst, int srcSize) { return LZ4_compress_HC (src, dst, srcSize, LZ4_compressBound(srcSize), 0); }
678int LZ4_compressHC_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_HC(src, dst, srcSize, maxDstSize, 0); }
679int LZ4_compressHC2(const char* src, char* dst, int srcSize, int cLevel) { return LZ4_compress_HC (src, dst, srcSize, LZ4_compressBound(srcSize), cLevel); }
680int LZ4_compressHC2_limitedOutput(const char* src, char* dst, int srcSize, int maxDstSize, int cLevel) { return LZ4_compress_HC(src, dst, srcSize, maxDstSize, cLevel); }
681int 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); }
682int 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); }
683int 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); }
684int 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); }
685int 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)); }
686int 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); }
687
688
689/* Deprecated streaming functions */
690/* These functions currently generate deprecation warnings */
708int LZ4_sizeofStreamStateHC(void) { return LZ4_STREAMHCSIZE; } 691int LZ4_sizeofStreamStateHC(void) { return LZ4_STREAMHCSIZE; }
709 692
710int LZ4_resetStreamStateHC(void* state, const char* inputBuffer) 693int LZ4_resetStreamStateHC(void* state, char* inputBuffer)
711{ 694{
712 if ((((size_t)state) & (sizeof(void*)-1)) != 0) return 1; /* Error : pointer is not aligned for pointer (32 or 64 bits) */ 695 if ((((size_t)state) & (sizeof(void*)-1)) != 0) return 1; /* Error : pointer is not aligned for pointer (32 or 64 bits) */
713 LZ4HC_init((LZ4HC_Data_Structure*)state, (const BYTE*)inputBuffer); 696 LZ4HC_init((LZ4HC_Data_Structure*)state, (const BYTE*)inputBuffer);
697 ((LZ4HC_Data_Structure*)state)->inputBuffer = (BYTE*)inputBuffer;
714 return 0; 698 return 0;
715} 699}
716 700
717void* LZ4_createHC (const char* inputBuffer) 701void* LZ4_createHC (char* inputBuffer)
718{ 702{
719 void* hc4 = ALLOCATOR(1, sizeof(LZ4HC_Data_Structure)); 703 void* hc4 = ALLOCATOR(1, sizeof(LZ4HC_Data_Structure));
704 if (hc4 == NULL) return NULL; /* not enough memory */
720 LZ4HC_init ((LZ4HC_Data_Structure*)hc4, (const BYTE*)inputBuffer); 705 LZ4HC_init ((LZ4HC_Data_Structure*)hc4, (const BYTE*)inputBuffer);
706 ((LZ4HC_Data_Structure*)hc4)->inputBuffer = (BYTE*)inputBuffer;
721 return hc4; 707 return hc4;
722} 708}
723 709
@@ -727,17 +713,6 @@ int LZ4_freeHC (void* LZ4HC_Data)
727 return (0); 713 return (0);
728} 714}
729 715
730/*
731int LZ4_compressHC_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize)
732{
733return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, 0, 0, noLimit);
734}
735int LZ4_compressHC_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize)
736{
737return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, maxOutputSize, 0, limitedOutput);
738}
739*/
740
741int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel) 716int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel)
742{ 717{
743 return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, 0, compressionLevel, noLimit); 718 return LZ4HC_compress_generic (LZ4HC_Data, source, dest, inputSize, 0, compressionLevel, noLimit);
diff --git a/src/static_libs/lz4/lz4hc.h b/src/static_libs/lz4/lz4hc.h
index 4a05845423..431f7c87c8 100644
--- a/src/static_libs/lz4/lz4hc.h
+++ b/src/static_libs/lz4/lz4hc.h
@@ -38,141 +38,150 @@
38extern "C" { 38extern "C" {
39#endif 39#endif
40 40
41/*****************************
42* Includes
43*****************************/
44#include <stddef.h> /* size_t */
41 45
42int LZ4_compressHC (const char* source, char* dest, int inputSize);
43/*
44LZ4_compressHC :
45 return : the number of bytes in compressed buffer dest
46 or 0 if compression fails.
47 note : destination buffer must be already allocated.
48 To avoid any problem, size it to handle worst cases situations (input data not compressible)
49 Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
50*/
51 46
52int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize); 47/**************************************
48* Block Compression
49**************************************/
50int LZ4_compress_HC (const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
53/* 51/*
54LZ4_compress_limitedOutput() : 52LZ4_compress_HC :
55 Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'. 53 Destination buffer 'dst' must be already allocated.
56 If it cannot achieve it, compression will stop, and result of the function will be zero. 54 Compression completion is guaranteed if 'dst' buffer is sized to handle worst circumstances (data not compressible)
57 This function never writes outside of provided output buffer. 55 Worst size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
58 56 srcSize : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h")
59 inputSize : Max supported value is 1 GB 57 compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work.
60 maxOutputSize : is maximum allowed size into the destination buffer (which must be already allocated) 58 0 means "use default value" (see lz4hc.c).
61 return : the number of output bytes written in buffer 'dest' 59 Values >16 behave the same as 16.
62 or 0 if compression fails. 60 return : the number of bytes written into buffer 'dst'
61 or 0 if compression fails.
63*/ 62*/
64 63
65 64
66int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
67int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
68/*
69 Same functions as above, but with programmable 'compressionLevel'.
70 Recommended values are between 4 and 9, although any value between 0 and 16 will work.
71 'compressionLevel'==0 means use default 'compressionLevel' value.
72 Values above 16 behave the same as 16.
73 Equivalent variants exist for all other compression functions below.
74*/
75
76/* Note : 65/* Note :
77 Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license) 66 Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
78*/ 67*/
79 68
80 69
81/**************************************
82* Using an external allocation
83**************************************/
84int LZ4_sizeofStateHC(void); 70int LZ4_sizeofStateHC(void);
85int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize); 71int LZ4_compress_HC_extStateHC(void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
86int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
87
88int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
89int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
90
91/* 72/*
92These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods. 73LZ4_compress_HC_extStateHC() :
93To know how much memory must be allocated for the compression tables, use : 74 Use this function if you prefer to manually allocate memory for compression tables.
94int LZ4_sizeofStateHC(); 75 To know how much memory must be allocated for the compression tables, use :
76 int LZ4_sizeofStateHC();
95 77
96Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0). 78 Allocated memory must be aligned on 8-bytes boundaries (which a normal malloc() will do properly).
97 79
98The allocated memory can be provided to the compression functions using 'void* state' parameter. 80 The allocated memory can then be provided to the compression functions using 'void* state' parameter.
99LZ4_compress_withStateHC() and LZ4_compress_limitedOutput_withStateHC() are equivalent to previously described functions. 81 LZ4_compress_HC_extStateHC() is equivalent to previously described function.
100They just use the externally allocated memory for state instead of allocating their own (on stack, or on heap). 82 It just uses externally allocated memory for stateHC.
101*/ 83*/
102 84
103 85
104
105/*****************************
106* Includes
107*****************************/
108#include <stddef.h> /* size_t */
109
110
111/************************************** 86/**************************************
112* Experimental Streaming Functions 87* Streaming Compression
113**************************************/ 88**************************************/
114#define LZ4_STREAMHCSIZE 262192 89#define LZ4_STREAMHCSIZE 262192
115#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t)) 90#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
116typedef struct { size_t table[LZ4_STREAMHCSIZE_SIZET]; } LZ4_streamHC_t; 91typedef struct { size_t table[LZ4_STREAMHCSIZE_SIZET]; } LZ4_streamHC_t;
117/* 92/*
118LZ4_streamHC_t 93 LZ4_streamHC_t
119This structure allows static allocation of LZ4 HC streaming state. 94 This structure allows static allocation of LZ4 HC streaming state.
120State must then be initialized using LZ4_resetStreamHC() before first use. 95 State must then be initialized using LZ4_resetStreamHC() before first use.
121 96
122Static allocation should only be used with statically linked library. 97 Static allocation should only be used in combination with static linking.
123If you want to use LZ4 as a DLL, please use construction functions below, which are more future-proof. 98 If you want to use LZ4 as a DLL, please use construction functions below, which are future-proof.
124*/ 99*/
125 100
126 101
127LZ4_streamHC_t* LZ4_createStreamHC(void); 102LZ4_streamHC_t* LZ4_createStreamHC(void);
128int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr); 103int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
129/* 104/*
130These functions create and release memory for LZ4 HC streaming state. 105 These functions create and release memory for LZ4 HC streaming state.
131Newly created states are already initialized. 106 Newly created states are already initialized.
132Existing state space can be re-used anytime using LZ4_resetStreamHC(). 107 Existing state space can be re-used anytime using LZ4_resetStreamHC().
133If you use LZ4 as a DLL, please use these functions instead of direct struct allocation, 108 If you use LZ4 as a DLL, use these functions instead of static structure allocation,
134to avoid size mismatch between different versions. 109 to avoid size mismatch between different versions.
135*/ 110*/
136 111
137void LZ4_resetStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel); 112void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
138int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int dictSize); 113int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
139 114
140int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize); 115int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr, const char* src, char* dst, int srcSize, int maxDstSize);
141int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
142 116
143int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int maxDictSize); 117int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
144 118
145/* 119/*
146These functions compress data in successive blocks of any size, using previous blocks as dictionary. 120 These functions compress data in successive blocks of any size, using previous blocks as dictionary.
147One key assumption is that each previous block will remain read-accessible while compressing next block. 121 One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
148 122 There is an exception for ring buffers, which can be smaller 64 KB.
149Before starting compression, state must be properly initialized, using LZ4_resetStreamHC(). 123 Such case is automatically detected and correctly handled by LZ4_compress_HC_continue().
150A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional). 124
151 125 Before starting compression, state must be properly initialized, using LZ4_resetStreamHC().
152Then, use LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue() to compress each successive block. 126 A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional).
153They work like usual LZ4_compressHC() or LZ4_compressHC_limitedOutput(), but use previous memory blocks to improve compression. 127
154Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression. 128 Then, use LZ4_compress_HC_continue() to compress each successive block.
155 129 It works like LZ4_compress_HC(), but use previous memory blocks as dictionary to improve compression.
156If, for any reason, previous data block can't be preserved in memory during next compression block, 130 Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
157you must save it to a safer memory space, 131 As a reminder, size 'dst' buffer to handle worst cases, using LZ4_compressBound(), to ensure success of compression operation.
158using LZ4_saveDictHC(). 132
133 If, for any reason, previous data blocks can't be preserved unmodified in memory during next compression block,
134 you must save it to a safer memory space, using LZ4_saveDictHC().
135 Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer'.
159*/ 136*/
160 137
161 138
162 139
163/************************************** 140/**************************************
164 * Deprecated Streaming Functions 141* Deprecated Functions
165 * ************************************/ 142**************************************/
166/* Note : these streaming functions follows the older model, and should no longer be used */ 143/* Deprecate Warnings */
167void* LZ4_createHC (const char* inputBuffer); 144/* Should these warnings messages be a problem,
168char* LZ4_slideInputBufferHC (void* LZ4HC_Data); 145 it is generally possible to disable them,
169int LZ4_freeHC (void* LZ4HC_Data); 146 with -Wno-deprecated-declarations for gcc
170 147 or _CRT_SECURE_NO_WARNINGS in Visual for example.
171int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel); 148 You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */
172int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel); 149#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK
173 150# define LZ4_DEPRECATE_WARNING_DEFBLOCK
174int LZ4_sizeofStreamStateHC(void); 151# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
175int LZ4_resetStreamStateHC(void* state, const char* inputBuffer); 152# if (LZ4_GCC_VERSION >= 405) || defined(__clang__)
153# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
154# elif (LZ4_GCC_VERSION >= 301)
155# define LZ4_DEPRECATED(message) __attribute__((deprecated))
156# elif defined(_MSC_VER)
157# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
158# else
159# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
160# define LZ4_DEPRECATED(message)
161# endif
162#endif // LZ4_DEPRECATE_WARNING_DEFBLOCK
163
164/* compression functions */
165/* these functions are planned to trigger warning messages by r131 approximately */
166int LZ4_compressHC (const char* source, char* dest, int inputSize);
167int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
168int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
169int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
170int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
171int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
172int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
173int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
174int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
175int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
176
177/* Streaming functions following the older model; should no longer be used */
178LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (char* inputBuffer);
179LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
180LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data);
181LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
182LZ4_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);
183LZ4_DEPRECATED("use LZ4_createStreamHC() instead") int LZ4_sizeofStreamStateHC(void);
184LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
176 185
177 186
178#if defined (__cplusplus) 187#if defined (__cplusplus)