diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2021-08-02 15:03:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 15:03:38 (GMT) |
commit | 163db1675c0cb5c4e35266e1c1f73e119227ad30 (patch) | |
tree | a760c5af59566ee3728fa199bd01f2c0cfd42582 /lib | |
parent | 27fd77e6cd7ea81cba18c2593f08084415cf5d06 (diff) | |
parent | 0a0922067fdb684c2c79169cc9b02118b905a6b9 (diff) | |
download | lz4-163db1675c0cb5c4e35266e1c1f73e119227ad30.zip lz4-163db1675c0cb5c4e35266e1c1f73e119227ad30.tar.gz lz4-163db1675c0cb5c4e35266e1c1f73e119227ad30.tar.bz2 |
Merge pull request #1013 from eloj/relax-lz4-memory-usage-tunable
Define LZ4_STREAMSIZE in terms of LZ4_MEMORY_USAGE.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4.h | 2 | ||||
-rw-r--r-- | lib/lz4frame.c | 14 |
2 files changed, 14 insertions, 2 deletions
@@ -620,7 +620,7 @@ typedef struct { * note : only use this definition in association with static linking ! * this definition is not API/ABI safe, and may change in future versions. */ -#define LZ4_STREAMSIZE 16416 /* static size, for inter-version compatibility */ +#define LZ4_STREAMSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */ #define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void*)) union LZ4_stream_u { void* table[LZ4_STREAMSIZE_VOIDP]; diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 21dc47f..9069717 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -588,6 +588,16 @@ static void LZ4F_initStream(void* ctx, } } +static int ctxTypeID_to_size(int ctxTypeID) { + switch(ctxTypeID) { + case 1: + return LZ4_sizeofState(); + case 2: + return LZ4_sizeofStateHC(); + default: + return 0; + } +} /*! LZ4F_compressBegin_usingCDict() : * init streaming compression AND writes frame header into @dstBuffer. @@ -610,7 +620,9 @@ size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx* cctxPtr, /* cctx Management */ { U16 const ctxTypeID = (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) ? 1 : 2; - if (cctxPtr->lz4CtxAlloc < ctxTypeID) { + int requiredSize = ctxTypeID_to_size(ctxTypeID); + int allocatedSize = ctxTypeID_to_size(cctxPtr->lz4CtxAlloc); + if (allocatedSize < requiredSize) { /* not enough space allocated */ FREEMEM(cctxPtr->lz4CtxPtr); if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) { |