Skip to content

Commit de1f9ab

Browse files
Update bundled libraries to lz4 1.9.4
1 parent 81112d2 commit de1f9ab

File tree

7 files changed

+1221
-662
lines changed

7 files changed

+1221
-662
lines changed

lz4libs/lz4.c

Lines changed: 422 additions & 195 deletions
Large diffs are not rendered by default.

lz4libs/lz4.h

Lines changed: 114 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* LZ4 - Fast LZ compression algorithm
33
* Header File
4-
* Copyright (C) 2011-present, Yann Collet.
4+
* Copyright (C) 2011-2020, Yann Collet.
55
66
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
77
@@ -97,36 +97,77 @@ extern "C" {
9797
# define LZ4LIB_API LZ4LIB_VISIBILITY
9898
#endif
9999

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+
100130
/*------ Version ------*/
101131
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
102132
#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
103-
#define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
133+
#define LZ4_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */
104134

105135
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
106136

107137
#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
108138
#define LZ4_QUOTE(str) #str
109139
#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+ */
111141

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+ */
114144

115145

116146
/*-************************************
117147
* Tuning parameter
118148
**************************************/
149+
#define LZ4_MEMORY_USAGE_MIN 10
150+
#define LZ4_MEMORY_USAGE_DEFAULT 14
151+
#define LZ4_MEMORY_USAGE_MAX 20
152+
119153
/*!
120154
* 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.
155+
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; )
156+
* Increasing memory usage improves compression ratio, at the cost of speed.
157+
* Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality.
124158
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
125159
*/
126160
#ifndef LZ4_MEMORY_USAGE
127-
# define LZ4_MEMORY_USAGE 14
161+
# define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
128162
#endif
129163

164+
#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
165+
# error "LZ4_MEMORY_USAGE is too small !"
166+
#endif
167+
168+
#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
169+
# error "LZ4_MEMORY_USAGE is too large !"
170+
#endif
130171

131172
/*-************************************
132173
* Simple Functions
@@ -270,8 +311,25 @@ LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcS
270311
***********************************************/
271312
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
272313

314+
/**
315+
Note about RC_INVOKED
316+
317+
- RC_INVOKED is predefined symbol of rc.exe (the resource compiler which is part of MSVC/Visual Studio).
318+
https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros
319+
320+
- Since rc.exe is a legacy compiler, it truncates long symbol (> 30 chars)
321+
and reports warning "RC4011: identifier truncated".
322+
323+
- To eliminate the warning, we surround long preprocessor symbol with
324+
"#if !defined(RC_INVOKED) ... #endif" block that means
325+
"skip this block when rc.exe is trying to read it".
326+
*/
327+
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
328+
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
273329
LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
274330
LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
331+
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
332+
#endif
275333

276334
/*! LZ4_resetStream_fast() : v1.9.0+
277335
* Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
@@ -355,8 +413,12 @@ typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
355413
* creation / destruction of streaming decompression tracking context.
356414
* A tracking context can be re-used multiple times.
357415
*/
416+
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
417+
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
358418
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
359419
LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
420+
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
421+
#endif
360422

361423
/*! LZ4_setStreamDecode() :
362424
* An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
@@ -406,7 +468,10 @@ LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
406468
* save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
407469
* then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
408470
*/
409-
LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
471+
LZ4LIB_API int
472+
LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode,
473+
const char* src, char* dst,
474+
int srcSize, int dstCapacity);
410475

411476

412477
/*! LZ4_decompress_*_usingDict() :
@@ -417,7 +482,16 @@ LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecod
417482
* Performance tip : Decompression speed can be substantially increased
418483
* when dst == dictStart + dictSize.
419484
*/
420-
LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
485+
LZ4LIB_API int
486+
LZ4_decompress_safe_usingDict(const char* src, char* dst,
487+
int srcSize, int dstCapacity,
488+
const char* dictStart, int dictSize);
489+
490+
LZ4LIB_API int
491+
LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
492+
int compressedSize,
493+
int targetOutputSize, int maxOutputSize,
494+
const char* dictStart, int dictSize);
421495

422496
#endif /* LZ4_H_2983827168210 */
423497

@@ -496,13 +570,15 @@ LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const c
496570
* stream (and source buffer) must remain in-place / accessible / unchanged
497571
* through the completion of the first compression call on the stream.
498572
*/
499-
LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream);
573+
LZ4LIB_STATIC_API void
574+
LZ4_attach_dictionary(LZ4_stream_t* workingStream,
575+
const LZ4_stream_t* dictionaryStream);
500576

501577

502578
/*! In-place compression and decompression
503579
*
504580
* It's possible to have input and output sharing the same buffer,
505-
* for highly contrained memory environments.
581+
* for highly constrained memory environments.
506582
* In both cases, it requires input to lay at the end of the buffer,
507583
* and decompression to start at beginning of the buffer.
508584
* Buffer size must feature some margin, hence be larger than final size.
@@ -592,38 +668,26 @@ LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const
592668
typedef unsigned int LZ4_u32;
593669
#endif
594670

671+
/*! LZ4_stream_t :
672+
* Never ever use below internal definitions directly !
673+
* These definitions are not API/ABI safe, and may change in future versions.
674+
* If you need static allocation, declare or allocate an LZ4_stream_t object.
675+
**/
676+
595677
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
596678
struct LZ4_stream_t_internal {
597679
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
598-
LZ4_u32 currentOffset;
599-
LZ4_u32 tableType;
600680
const LZ4_byte* dictionary;
601681
const LZ4_stream_t_internal* dictCtx;
682+
LZ4_u32 currentOffset;
683+
LZ4_u32 tableType;
602684
LZ4_u32 dictSize;
685+
/* Implicit padding to ensure structure is aligned */
603686
};
604687

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*))
688+
#define LZ4_STREAM_MINSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */
625689
union LZ4_stream_u {
626-
void* table[LZ4_STREAMSIZE_VOIDP];
690+
char minStateSize[LZ4_STREAM_MINSIZE];
627691
LZ4_stream_t_internal internal_donotuse;
628692
}; /* previously typedef'd to LZ4_stream_t */
629693

@@ -641,21 +705,25 @@ union LZ4_stream_u {
641705
* In which case, the function will @return NULL.
642706
* Note2: An LZ4_stream_t structure guarantees correct alignment and size.
643707
* Note3: Before v1.9.0, use LZ4_resetStream() instead
644-
*/
708+
**/
645709
LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
646710

647711

648712
/*! 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))
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_streamDecode_t object.
716+
**/
717+
typedef struct {
718+
const LZ4_byte* externalDict;
719+
const LZ4_byte* prefixEnd;
720+
size_t extDictSize;
721+
size_t prefixSize;
722+
} LZ4_streamDecode_t_internal;
723+
724+
#define LZ4_STREAMDECODE_MINSIZE 32
657725
union LZ4_streamDecode_u {
658-
unsigned long long table[LZ4_STREAMDECODESIZE_U64];
726+
char minStateSize[LZ4_STREAMDECODE_MINSIZE];
659727
LZ4_streamDecode_t_internal internal_donotuse;
660728
} ; /* previously typedef'd to LZ4_streamDecode_t */
661729

0 commit comments

Comments
 (0)