extlz4 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +43 -3
  4. data/contrib/lz4/CODING_STYLE +57 -0
  5. data/contrib/lz4/LICENSE +3 -2
  6. data/contrib/lz4/Makefile.inc +56 -30
  7. data/contrib/lz4/NEWS +46 -0
  8. data/contrib/lz4/README.md +17 -6
  9. data/contrib/lz4/SECURITY.md +17 -0
  10. data/contrib/lz4/build/README.md +4 -15
  11. data/contrib/lz4/build/VS2022/_build.bat +39 -0
  12. data/contrib/lz4/build/VS2022/_setup.bat +35 -0
  13. data/contrib/lz4/build/VS2022/_test.bat +38 -0
  14. data/contrib/lz4/build/VS2022/build-and-test-win32-debug.bat +26 -0
  15. data/contrib/lz4/build/VS2022/build-and-test-win32-release.bat +26 -0
  16. data/contrib/lz4/build/VS2022/build-and-test-x64-debug.bat +26 -0
  17. data/contrib/lz4/build/VS2022/build-and-test-x64-release.bat +26 -0
  18. data/contrib/lz4/build/{VS2017 → VS2022}/datagen/datagen.vcxproj +11 -7
  19. data/contrib/lz4/build/{VS2017 → VS2022}/frametest/frametest.vcxproj +4 -4
  20. data/contrib/lz4/build/{VS2017 → VS2022}/fullbench/fullbench.vcxproj +4 -4
  21. data/contrib/lz4/build/{VS2017 → VS2022}/fullbench-dll/fullbench-dll.vcxproj +4 -4
  22. data/contrib/lz4/build/{VS2017 → VS2022}/fuzzer/fuzzer.vcxproj +4 -4
  23. data/contrib/lz4/build/{VS2017 → VS2022}/liblz4/liblz4.vcxproj +4 -4
  24. data/contrib/lz4/build/{VS2010 → VS2022}/liblz4-dll/liblz4-dll.rc +1 -1
  25. data/contrib/lz4/build/{VS2017 → VS2022}/liblz4-dll/liblz4-dll.vcxproj +4 -4
  26. data/contrib/lz4/build/{VS2010 → VS2022}/lz4/lz4.rc +1 -1
  27. data/contrib/lz4/build/{VS2017 → VS2022}/lz4/lz4.vcxproj +33 -8
  28. data/contrib/lz4/build/{VS2017 → VS2022}/lz4.sln +5 -2
  29. data/contrib/lz4/build/cmake/CMakeLists.txt +133 -100
  30. data/contrib/lz4/build/cmake/lz4Config.cmake.in +2 -0
  31. data/contrib/lz4/build/meson/GetLz4LibraryVersion.py +39 -0
  32. data/contrib/lz4/build/meson/README.md +34 -0
  33. data/contrib/lz4/build/meson/meson/contrib/gen_manual/meson.build +42 -0
  34. data/contrib/lz4/build/meson/meson/contrib/meson.build +11 -0
  35. data/contrib/lz4/build/meson/meson/examples/meson.build +32 -0
  36. data/contrib/lz4/build/meson/meson/lib/meson.build +87 -0
  37. data/contrib/lz4/build/meson/meson/meson.build +135 -0
  38. data/contrib/lz4/build/meson/meson/ossfuzz/meson.build +35 -0
  39. data/contrib/lz4/build/meson/meson/programs/meson.build +91 -0
  40. data/contrib/lz4/build/meson/meson/tests/meson.build +162 -0
  41. data/contrib/lz4/build/meson/meson.build +31 -0
  42. data/contrib/lz4/build/meson/meson_options.txt +44 -0
  43. data/contrib/lz4/build/visual/README.md +5 -0
  44. data/contrib/lz4/build/visual/generate_solution.cmd +55 -0
  45. data/contrib/lz4/build/visual/generate_vs2015.cmd +3 -0
  46. data/contrib/lz4/build/visual/generate_vs2017.cmd +3 -0
  47. data/contrib/lz4/build/visual/generate_vs2019.cmd +3 -0
  48. data/contrib/lz4/build/visual/generate_vs2022.cmd +3 -0
  49. data/contrib/lz4/lib/LICENSE +1 -1
  50. data/contrib/lz4/lib/README.md +69 -13
  51. data/contrib/lz4/lib/liblz4-dll.rc.in +1 -1
  52. data/contrib/lz4/lib/liblz4.pc.in +3 -3
  53. data/contrib/lz4/lib/lz4.c +608 -274
  54. data/contrib/lz4/lib/lz4.h +212 -102
  55. data/contrib/lz4/lib/lz4file.c +341 -0
  56. data/contrib/lz4/lib/lz4file.h +93 -0
  57. data/contrib/lz4/lib/lz4frame.c +545 -308
  58. data/contrib/lz4/lib/lz4frame.h +252 -124
  59. data/contrib/lz4/lib/lz4frame_static.h +1 -1
  60. data/contrib/lz4/lib/lz4hc.c +1038 -461
  61. data/contrib/lz4/lib/lz4hc.h +57 -56
  62. data/contrib/lz4/lib/xxhash.c +21 -21
  63. data/contrib/lz4/ossfuzz/Makefile +1 -0
  64. data/contrib/lz4/ossfuzz/decompress_fuzzer.c +18 -2
  65. data/contrib/lz4/ossfuzz/fuzz_helpers.h +4 -3
  66. data/contrib/lz4/ossfuzz/round_trip_frame_uncompressed_fuzzer.c +134 -0
  67. data/contrib/lz4/ossfuzz/round_trip_fuzzer.c +66 -6
  68. data/ext/blockapi.c +19 -19
  69. data/ext/extlz4.h +12 -0
  70. data/ext/frameapi.c +26 -26
  71. data/ext/hashargs.c +7 -1
  72. metadata +47 -30
  73. data/contrib/lz4/build/VS2010/datagen/datagen.vcxproj +0 -169
  74. data/contrib/lz4/build/VS2010/frametest/frametest.vcxproj +0 -176
  75. data/contrib/lz4/build/VS2010/fullbench/fullbench.vcxproj +0 -176
  76. data/contrib/lz4/build/VS2010/fullbench-dll/fullbench-dll.vcxproj +0 -180
  77. data/contrib/lz4/build/VS2010/fuzzer/fuzzer.vcxproj +0 -173
  78. data/contrib/lz4/build/VS2010/liblz4/liblz4.vcxproj +0 -175
  79. data/contrib/lz4/build/VS2010/liblz4-dll/liblz4-dll.vcxproj +0 -179
  80. data/contrib/lz4/build/VS2010/lz4/lz4.vcxproj +0 -189
  81. data/contrib/lz4/build/VS2010/lz4.sln +0 -98
  82. data/contrib/lz4/build/VS2017/liblz4-dll/liblz4-dll.rc +0 -51
  83. data/contrib/lz4/build/VS2017/lz4/lz4.rc +0 -51
  84. data/contrib/lz4/tmp +0 -0
  85. data/contrib/lz4/tmpsparse +0 -0
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * LZ4 - Fast LZ compression algorithm
3
3
  * Header File
4
- * Copyright (C) 2011-present, Yann Collet.
4
+ * Copyright (C) 2011-2023, Yann Collet.
5
5
 
6
6
  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
7
 
@@ -97,36 +97,79 @@ extern "C" {
97
97
  # define LZ4LIB_API LZ4LIB_VISIBILITY
98
98
  #endif
99
99
 
100
+ /*! LZ4_FREESTANDING :
101
+ * When this macro is set to 1, it enables "freestanding mode" that is
102
+ * suitable for typical freestanding environment which doesn't support
103
+ * standard C library.
104
+ *
105
+ * - LZ4_FREESTANDING is a compile-time switch.
106
+ * - It requires the following macros to be defined:
107
+ * LZ4_memcpy, LZ4_memmove, LZ4_memset.
108
+ * - It only enables LZ4/HC functions which don't use heap.
109
+ * All LZ4F_* functions are not supported.
110
+ * - See tests/freestanding.c to check its basic setup.
111
+ */
112
+ #if defined(LZ4_FREESTANDING) && (LZ4_FREESTANDING == 1)
113
+ # define LZ4_HEAPMODE 0
114
+ # define LZ4HC_HEAPMODE 0
115
+ # define LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 1
116
+ # if !defined(LZ4_memcpy)
117
+ # error "LZ4_FREESTANDING requires macro 'LZ4_memcpy'."
118
+ # endif
119
+ # if !defined(LZ4_memset)
120
+ # error "LZ4_FREESTANDING requires macro 'LZ4_memset'."
121
+ # endif
122
+ # if !defined(LZ4_memmove)
123
+ # error "LZ4_FREESTANDING requires macro 'LZ4_memmove'."
124
+ # endif
125
+ #elif ! defined(LZ4_FREESTANDING)
126
+ # define LZ4_FREESTANDING 0
127
+ #endif
128
+
129
+
100
130
  /*------ Version ------*/
101
131
  #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
102
- #define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
103
- #define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
132
+ #define LZ4_VERSION_MINOR 10 /* for new (non-breaking) interface capabilities */
133
+ #define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */
104
134
 
105
135
  #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
106
136
 
107
137
  #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
108
138
  #define LZ4_QUOTE(str) #str
109
139
  #define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
110
- #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
140
+ #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) /* requires v1.7.3+ */
111
141
 
112
- LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version */
113
- LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; useful to check dll version */
142
+ LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version; requires v1.3.0+ */
143
+ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; useful to check dll version; requires v1.7.5+ */
114
144
 
115
145
 
116
146
  /*-************************************
117
- * Tuning parameter
147
+ * Tuning memory usage
118
148
  **************************************/
119
149
  /*!
120
150
  * LZ4_MEMORY_USAGE :
121
- * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
122
- * Increasing memory usage improves compression ratio.
123
- * Reduced memory usage may improve speed, thanks to better cache locality.
124
- * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
151
+ * Can be selected at compile time, by setting LZ4_MEMORY_USAGE.
152
+ * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB)
153
+ * Increasing memory usage improves compression ratio, generally at the cost of speed.
154
+ * Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality.
155
+ * Default value is 14, for 16KB, which nicely fits into most L1 caches.
125
156
  */
126
157
  #ifndef LZ4_MEMORY_USAGE
127
- # define LZ4_MEMORY_USAGE 14
158
+ # define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
128
159
  #endif
129
160
 
161
+ /* These are absolute limits, they should not be changed by users */
162
+ #define LZ4_MEMORY_USAGE_MIN 10
163
+ #define LZ4_MEMORY_USAGE_DEFAULT 14
164
+ #define LZ4_MEMORY_USAGE_MAX 20
165
+
166
+ #if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
167
+ # error "LZ4_MEMORY_USAGE is too small !"
168
+ #endif
169
+
170
+ #if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
171
+ # error "LZ4_MEMORY_USAGE is too large !"
172
+ #endif
130
173
 
131
174
  /*-************************************
132
175
  * Simple Functions
@@ -148,8 +191,9 @@ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string;
148
191
  LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
149
192
 
150
193
  /*! LZ4_decompress_safe() :
151
- * compressedSize : is the exact complete size of the compressed block.
152
- * dstCapacity : is the size of destination buffer (which must be already allocated), presumed an upper bound of decompressed size.
194
+ * @compressedSize : is the exact complete size of the compressed block.
195
+ * @dstCapacity : is the size of destination buffer (which must be already allocated),
196
+ * presumed an upper bound of decompressed size.
153
197
  * @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
154
198
  * If destination buffer is not large enough, decoding will stop and output an error code (negative value).
155
199
  * If the source stream is detected malformed, the function will stop decoding and return a negative result.
@@ -201,20 +245,20 @@ LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int d
201
245
  LZ4LIB_API int LZ4_sizeofState(void);
202
246
  LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
203
247
 
204
-
205
248
  /*! LZ4_compress_destSize() :
206
249
  * Reverse the logic : compresses as much data as possible from 'src' buffer
207
- * into already allocated buffer 'dst', of size >= 'targetDestSize'.
250
+ * into already allocated buffer 'dst', of size >= 'dstCapacity'.
208
251
  * This function either compresses the entire 'src' content into 'dst' if it's large enough,
209
252
  * or fill 'dst' buffer completely with as much data as possible from 'src'.
210
253
  * note: acceleration parameter is fixed to "default".
211
254
  *
212
- * *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
255
+ * *srcSizePtr : in+out parameter. Initially contains size of input.
256
+ * Will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
213
257
  * New value is necessarily <= input value.
214
- * @return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
258
+ * @return : Nb bytes written into 'dst' (necessarily <= dstCapacity)
215
259
  * or 0 if compression fails.
216
260
  *
217
- * Note : from v1.8.2 to v1.9.1, this function had a bug (fixed un v1.9.2+):
261
+ * Note : from v1.8.2 to v1.9.1, this function had a bug (fixed in v1.9.2+):
218
262
  * the produced compressed content could, in specific circumstances,
219
263
  * require to be decompressed into a destination buffer larger
220
264
  * by at least 1 byte than the content to decompress.
@@ -225,8 +269,7 @@ LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* d
225
269
  * a dstCapacity which is > decompressedSize, by at least 1 byte.
226
270
  * See https://github.com/lz4/lz4/issues/859 for details
227
271
  */
228
- LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
229
-
272
+ LZ4LIB_API int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize);
230
273
 
231
274
  /*! LZ4_decompress_safe_partial() :
232
275
  * Decompress an LZ4 compressed block, of size 'srcSize' at position 'src',
@@ -270,8 +313,25 @@ LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcS
270
313
  ***********************************************/
271
314
  typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
272
315
 
316
+ /*!
317
+ Note about RC_INVOKED
318
+
319
+ - RC_INVOKED is predefined symbol of rc.exe (the resource compiler which is part of MSVC/Visual Studio).
320
+ https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros
321
+
322
+ - Since rc.exe is a legacy compiler, it truncates long symbol (> 30 chars)
323
+ and reports warning "RC4011: identifier truncated".
324
+
325
+ - To eliminate the warning, we surround long preprocessor symbol with
326
+ "#if !defined(RC_INVOKED) ... #endif" block that means
327
+ "skip this block when rc.exe is trying to read it".
328
+ */
329
+ #if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
330
+ #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
273
331
  LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
274
332
  LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
333
+ #endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
334
+ #endif
275
335
 
276
336
  /*! LZ4_resetStream_fast() : v1.9.0+
277
337
  * Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
@@ -303,13 +363,58 @@ LZ4LIB_API void LZ4_resetStream_fast (LZ4_stream_t* streamPtr);
303
363
  * LZ4_loadDict() triggers a reset, so any previous data will be forgotten.
304
364
  * The same dictionary will have to be loaded on decompression side for successful decoding.
305
365
  * Dictionary are useful for better compression of small data (KB range).
306
- * While LZ4 accept any input as dictionary,
307
- * results are generally better when using Zstandard's Dictionary Builder.
366
+ * While LZ4 itself accepts any input as dictionary, dictionary efficiency is also a topic.
367
+ * When in doubt, employ the Zstandard's Dictionary Builder.
308
368
  * Loading a size of 0 is allowed, and is the same as reset.
309
- * @return : loaded dictionary size, in bytes (necessarily <= 64 KB)
369
+ * @return : loaded dictionary size, in bytes (note: only the last 64 KB are loaded)
310
370
  */
311
371
  LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
312
372
 
373
+ /*! LZ4_loadDictSlow() : v1.10.0+
374
+ * Same as LZ4_loadDict(),
375
+ * but uses a bit more cpu to reference the dictionary content more thoroughly.
376
+ * This is expected to slightly improve compression ratio.
377
+ * The extra-cpu cost is likely worth it if the dictionary is re-used across multiple sessions.
378
+ * @return : loaded dictionary size, in bytes (note: only the last 64 KB are loaded)
379
+ */
380
+ LZ4LIB_API int LZ4_loadDictSlow(LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
381
+
382
+ /*! LZ4_attach_dictionary() : stable since v1.10.0
383
+ *
384
+ * This allows efficient re-use of a static dictionary multiple times.
385
+ *
386
+ * Rather than re-loading the dictionary buffer into a working context before
387
+ * each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
388
+ * working LZ4_stream_t, this function introduces a no-copy setup mechanism,
389
+ * in which the working stream references @dictionaryStream in-place.
390
+ *
391
+ * Several assumptions are made about the state of @dictionaryStream.
392
+ * Currently, only states which have been prepared by LZ4_loadDict() or
393
+ * LZ4_loadDictSlow() should be expected to work.
394
+ *
395
+ * Alternatively, the provided @dictionaryStream may be NULL,
396
+ * in which case any existing dictionary stream is unset.
397
+ *
398
+ * If a dictionary is provided, it replaces any pre-existing stream history.
399
+ * The dictionary contents are the only history that can be referenced and
400
+ * logically immediately precede the data compressed in the first subsequent
401
+ * compression call.
402
+ *
403
+ * The dictionary will only remain attached to the working stream through the
404
+ * first compression call, at the end of which it is cleared.
405
+ * @dictionaryStream stream (and source buffer) must remain in-place / accessible / unchanged
406
+ * through the completion of the compression session.
407
+ *
408
+ * Note: there is no equivalent LZ4_attach_*() method on the decompression side
409
+ * because there is no initialization cost, hence no need to share the cost across multiple sessions.
410
+ * To decompress LZ4 blocks using dictionary, attached or not,
411
+ * just employ the regular LZ4_setStreamDecode() for streaming,
412
+ * or the stateless LZ4_decompress_safe_usingDict() for one-shot decompression.
413
+ */
414
+ LZ4LIB_API void
415
+ LZ4_attach_dictionary(LZ4_stream_t* workingStream,
416
+ const LZ4_stream_t* dictionaryStream);
417
+
313
418
  /*! LZ4_compress_fast_continue() :
314
419
  * Compress 'src' content using data from previously compressed blocks, for better compression ratio.
315
420
  * 'dst' buffer must be already allocated.
@@ -355,8 +460,12 @@ typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
355
460
  * creation / destruction of streaming decompression tracking context.
356
461
  * A tracking context can be re-used multiple times.
357
462
  */
463
+ #if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
464
+ #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
358
465
  LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
359
466
  LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
467
+ #endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
468
+ #endif
360
469
 
361
470
  /*! LZ4_setStreamDecode() :
362
471
  * An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
@@ -381,11 +490,24 @@ LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const
381
490
  LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
382
491
  #define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
383
492
 
384
- /*! LZ4_decompress_*_continue() :
385
- * These decoding functions allow decompression of consecutive blocks in "streaming" mode.
386
- * A block is an unsplittable entity, it must be presented entirely to a decompression function.
387
- * Decompression functions only accepts one block at a time.
388
- * The last 64KB of previously decoded data *must* remain available and unmodified at the memory position where they were decoded.
493
+ /*! LZ4_decompress_safe_continue() :
494
+ * This decoding function allows decompression of consecutive blocks in "streaming" mode.
495
+ * The difference with the usual independent blocks is that
496
+ * new blocks are allowed to find references into former blocks.
497
+ * A block is an unsplittable entity, and must be presented entirely to the decompression function.
498
+ * LZ4_decompress_safe_continue() only accepts one block at a time.
499
+ * It's modeled after `LZ4_decompress_safe()` and behaves similarly.
500
+ *
501
+ * @LZ4_streamDecode : decompression state, tracking the position in memory of past data
502
+ * @compressedSize : exact complete size of one compressed block.
503
+ * @dstCapacity : size of destination buffer (which must be already allocated),
504
+ * must be an upper bound of decompressed size.
505
+ * @return : number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
506
+ * If destination buffer is not large enough, decoding will stop and output an error code (negative value).
507
+ * If the source stream is detected malformed, the function will stop decoding and return a negative result.
508
+ *
509
+ * The last 64KB of previously decoded data *must* remain available and unmodified
510
+ * at the memory position where they were previously decoded.
389
511
  * If less than 64KB of data has been decoded, all the data must be present.
390
512
  *
391
513
  * Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
@@ -406,18 +528,36 @@ LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
406
528
  * save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
407
529
  * then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
408
530
  */
409
- LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
531
+ LZ4LIB_API int
532
+ LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode,
533
+ const char* src, char* dst,
534
+ int srcSize, int dstCapacity);
410
535
 
411
536
 
412
- /*! LZ4_decompress_*_usingDict() :
413
- * These decoding functions work the same as
414
- * a combination of LZ4_setStreamDecode() followed by LZ4_decompress_*_continue()
415
- * They are stand-alone, and don't need an LZ4_streamDecode_t structure.
537
+ /*! LZ4_decompress_safe_usingDict() :
538
+ * Works the same as
539
+ * a combination of LZ4_setStreamDecode() followed by LZ4_decompress_safe_continue()
540
+ * However, it's stateless: it doesn't need any LZ4_streamDecode_t state.
416
541
  * Dictionary is presumed stable : it must remain accessible and unmodified during decompression.
417
542
  * Performance tip : Decompression speed can be substantially increased
418
543
  * when dst == dictStart + dictSize.
419
544
  */
420
- LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
545
+ LZ4LIB_API int
546
+ LZ4_decompress_safe_usingDict(const char* src, char* dst,
547
+ int srcSize, int dstCapacity,
548
+ const char* dictStart, int dictSize);
549
+
550
+ /*! LZ4_decompress_safe_partial_usingDict() :
551
+ * Behaves the same as LZ4_decompress_safe_partial()
552
+ * with the added ability to specify a memory segment for past data.
553
+ * Performance tip : Decompression speed can be substantially increased
554
+ * when dst == dictStart + dictSize.
555
+ */
556
+ LZ4LIB_API int
557
+ LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
558
+ int compressedSize,
559
+ int targetOutputSize, int maxOutputSize,
560
+ const char* dictStart, int dictSize);
421
561
 
422
562
  #endif /* LZ4_H_2983827168210 */
423
563
 
@@ -452,9 +592,9 @@ LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int sr
452
592
  #define LZ4_STATIC_3504398509
453
593
 
454
594
  #ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
455
- #define LZ4LIB_STATIC_API LZ4LIB_API
595
+ # define LZ4LIB_STATIC_API LZ4LIB_API
456
596
  #else
457
- #define LZ4LIB_STATIC_API
597
+ # define LZ4LIB_STATIC_API
458
598
  #endif
459
599
 
460
600
 
@@ -470,39 +610,16 @@ LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int sr
470
610
  */
471
611
  LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
472
612
 
473
- /*! LZ4_attach_dictionary() :
474
- * This is an experimental API that allows
475
- * efficient use of a static dictionary many times.
476
- *
477
- * Rather than re-loading the dictionary buffer into a working context before
478
- * each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
479
- * working LZ4_stream_t, this function introduces a no-copy setup mechanism,
480
- * in which the working stream references the dictionary stream in-place.
481
- *
482
- * Several assumptions are made about the state of the dictionary stream.
483
- * Currently, only streams which have been prepared by LZ4_loadDict() should
484
- * be expected to work.
485
- *
486
- * Alternatively, the provided dictionaryStream may be NULL,
487
- * in which case any existing dictionary stream is unset.
488
- *
489
- * If a dictionary is provided, it replaces any pre-existing stream history.
490
- * The dictionary contents are the only history that can be referenced and
491
- * logically immediately precede the data compressed in the first subsequent
492
- * compression call.
493
- *
494
- * The dictionary will only remain attached to the working stream through the
495
- * first compression call, at the end of which it is cleared. The dictionary
496
- * stream (and source buffer) must remain in-place / accessible / unchanged
497
- * through the completion of the first compression call on the stream.
613
+ /*! LZ4_compress_destSize_extState() : introduced in v1.10.0
614
+ * Same as LZ4_compress_destSize(), but using an externally allocated state.
615
+ * Also: exposes @acceleration
498
616
  */
499
- LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream);
500
-
617
+ int LZ4_compress_destSize_extState(void* state, const char* src, char* dst, int* srcSizePtr, int targetDstSize, int acceleration);
501
618
 
502
619
  /*! In-place compression and decompression
503
620
  *
504
621
  * It's possible to have input and output sharing the same buffer,
505
- * for highly contrained memory environments.
622
+ * for highly constrained memory environments.
506
623
  * In both cases, it requires input to lay at the end of the buffer,
507
624
  * and decompression to start at beginning of the buffer.
508
625
  * Buffer size must feature some margin, hence be larger than final size.
@@ -592,38 +709,26 @@ LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const
592
709
  typedef unsigned int LZ4_u32;
593
710
  #endif
594
711
 
712
+ /*! LZ4_stream_t :
713
+ * Never ever use below internal definitions directly !
714
+ * These definitions are not API/ABI safe, and may change in future versions.
715
+ * If you need static allocation, declare or allocate an LZ4_stream_t object.
716
+ **/
717
+
595
718
  typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
596
719
  struct LZ4_stream_t_internal {
597
720
  LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
598
- LZ4_u32 currentOffset;
599
- LZ4_u32 tableType;
600
721
  const LZ4_byte* dictionary;
601
722
  const LZ4_stream_t_internal* dictCtx;
723
+ LZ4_u32 currentOffset;
724
+ LZ4_u32 tableType;
602
725
  LZ4_u32 dictSize;
726
+ /* Implicit padding to ensure structure is aligned */
603
727
  };
604
728
 
605
- typedef struct {
606
- const LZ4_byte* externalDict;
607
- size_t extDictSize;
608
- const LZ4_byte* prefixEnd;
609
- size_t prefixSize;
610
- } LZ4_streamDecode_t_internal;
611
-
612
-
613
- /*! LZ4_stream_t :
614
- * Do not use below internal definitions directly !
615
- * Declare or allocate an LZ4_stream_t instead.
616
- * LZ4_stream_t can also be created using LZ4_createStream(), which is recommended.
617
- * The structure definition can be convenient for static allocation
618
- * (on stack, or as part of larger structure).
619
- * Init this structure with LZ4_initStream() before first use.
620
- * note : only use this definition in association with static linking !
621
- * this definition is not API/ABI safe, and may change in future versions.
622
- */
623
- #define LZ4_STREAMSIZE 16416 /* static size, for inter-version compatibility */
624
- #define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void*))
729
+ #define LZ4_STREAM_MINSIZE ((1UL << (LZ4_MEMORY_USAGE)) + 32) /* static size, for inter-version compatibility */
625
730
  union LZ4_stream_u {
626
- void* table[LZ4_STREAMSIZE_VOIDP];
731
+ char minStateSize[LZ4_STREAM_MINSIZE];
627
732
  LZ4_stream_t_internal internal_donotuse;
628
733
  }; /* previously typedef'd to LZ4_stream_t */
629
734
 
@@ -641,21 +746,25 @@ union LZ4_stream_u {
641
746
  * In which case, the function will @return NULL.
642
747
  * Note2: An LZ4_stream_t structure guarantees correct alignment and size.
643
748
  * Note3: Before v1.9.0, use LZ4_resetStream() instead
644
- */
645
- LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
749
+ **/
750
+ LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* stateBuffer, size_t size);
646
751
 
647
752
 
648
753
  /*! LZ4_streamDecode_t :
649
- * information structure to track an LZ4 stream during decompression.
650
- * init this structure using LZ4_setStreamDecode() before first use.
651
- * note : only use in association with static linking !
652
- * this definition is not API/ABI safe,
653
- * and may change in a future version !
654
- */
655
- #define LZ4_STREAMDECODESIZE_U64 (4 + ((sizeof(void*)==16) ? 2 : 0) /*AS-400*/ )
656
- #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
754
+ * Never ever use below internal definitions directly !
755
+ * These definitions are not API/ABI safe, and may change in future versions.
756
+ * If you need static allocation, declare or allocate an LZ4_streamDecode_t object.
757
+ **/
758
+ typedef struct {
759
+ const LZ4_byte* externalDict;
760
+ const LZ4_byte* prefixEnd;
761
+ size_t extDictSize;
762
+ size_t prefixSize;
763
+ } LZ4_streamDecode_t_internal;
764
+
765
+ #define LZ4_STREAMDECODE_MINSIZE 32
657
766
  union LZ4_streamDecode_u {
658
- unsigned long long table[LZ4_STREAMDECODESIZE_U64];
767
+ char minStateSize[LZ4_STREAMDECODE_MINSIZE];
659
768
  LZ4_streamDecode_t_internal internal_donotuse;
660
769
  } ; /* previously typedef'd to LZ4_streamDecode_t */
661
770
 
@@ -750,11 +859,12 @@ LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4
750
859
  * But they may happen if input data is invalid (error or intentional tampering).
751
860
  * As a consequence, use these functions in trusted environments with trusted data **only**.
752
861
  */
753
- LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
862
+ LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_partial() instead")
754
863
  LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
755
- LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
864
+ LZ4_DEPRECATED("This function is deprecated and unsafe. Consider migrating towards LZ4_decompress_safe_continue() instead. "
865
+ "Note that the contract will change (requires block's compressed size, instead of decompressed size)")
756
866
  LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
757
- LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
867
+ LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_partial_usingDict() instead")
758
868
  LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
759
869
 
760
870
  /*! LZ4_resetStream() :