diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2022-07-13 16:40:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-13 16:40:27 (GMT) |
commit | 6adf4282c24422c5e4d30687610cec4c4cbc3d74 (patch) | |
tree | bfe9f76eddf29139db6a26d5d79af292a232db69 | |
parent | 16ac87590124d474fd8fc0c27eb0941c46a55b62 (diff) | |
parent | 832b444266053ab86d32b8a2f8b25a3f8abff703 (diff) | |
download | lz4-6adf4282c24422c5e4d30687610cec4c4cbc3d74.zip lz4-6adf4282c24422c5e4d30687610cec4c4cbc3d74.tar.gz lz4-6adf4282c24422c5e4d30687610cec4c4cbc3d74.tar.bz2 |
Merge pull request #1114 from lz4/blockSize
minor : proper interface for LZ4F_getBlockSize()
-rw-r--r-- | doc/lz4_manual.html | 51 | ||||
-rw-r--r-- | doc/lz4frame_manual.html | 16 | ||||
-rw-r--r-- | lib/lz4frame.c | 10 | ||||
-rw-r--r-- | lib/lz4frame.h | 6 | ||||
-rw-r--r-- | tests/frametest.c | 6 |
5 files changed, 39 insertions, 50 deletions
diff --git a/doc/lz4_manual.html b/doc/lz4_manual.html index 037cfc0..5461ab9 100644 --- a/doc/lz4_manual.html +++ b/doc/lz4_manual.html @@ -50,9 +50,9 @@ <a name="Chapter2"></a><h2>Version</h2><pre></pre> -<pre><b>int LZ4_versionNumber (void); </b>/**< library version number; useful to check dll version */<b> +<pre><b>int LZ4_versionNumber (void); </b>/**< library version number; useful to check dll version; requires v1.3.0+ */<b> </b></pre><BR> -<pre><b>const char* LZ4_versionString (void); </b>/**< library version string; useful to check dll version */<b> +<pre><b>const char* LZ4_versionString (void); </b>/**< library version string; useful to check dll version; requires v1.7.5+ */<b> </b></pre><BR> <a name="Chapter3"></a><h2>Tuning parameter</h2><pre></pre> @@ -452,28 +452,9 @@ int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream); Accessing members will expose user code to API and/or ABI break in future versions of the library. <BR></pre> -<pre><b>typedef struct { - const LZ4_byte* externalDict; - size_t extDictSize; - const LZ4_byte* prefixEnd; - size_t prefixSize; -} LZ4_streamDecode_t_internal; -</b></pre><BR> -<pre><b>#define LZ4_STREAMSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) </b>/* static size, for inter-version compatibility */<b> -#define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void*)) -union LZ4_stream_u { - void* table[LZ4_STREAMSIZE_VOIDP]; - LZ4_stream_t_internal internal_donotuse; -}; </b>/* previously typedef'd to LZ4_stream_t */<b> -</b><p> Do not use below internal definitions directly ! - Declare or allocate an LZ4_stream_t instead. - LZ4_stream_t can also be created using LZ4_createStream(), which is recommended. - The structure definition can be convenient for static allocation - (on stack, or as part of larger structure). - Init this structure with LZ4_initStream() before first use. - note : only use this definition in association with static linking ! - this definition is not API/ABI safe, and may change in future versions. - +<pre><b></b><p> Never ever use below internal definitions directly ! + These definitions are not API/ABI safe, and may change in future versions. + If you need static allocation, declare or allocate an LZ4_stream_t object. </p></pre><BR> <pre><b>LZ4_stream_t* LZ4_initStream (void* buffer, size_t size); @@ -489,21 +470,17 @@ union LZ4_stream_u { In which case, the function will @return NULL. Note2: An LZ4_stream_t structure guarantees correct alignment and size. Note3: Before v1.9.0, use LZ4_resetStream() instead - </p></pre><BR> -<pre><b>#define LZ4_STREAMDECODESIZE_U64 (4 + ((sizeof(void*)==16) ? 2 : 0) </b>/*AS-400*/ )<b> -#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long)) -union LZ4_streamDecode_u { - unsigned long long table[LZ4_STREAMDECODESIZE_U64]; - LZ4_streamDecode_t_internal internal_donotuse; -} ; </b>/* previously typedef'd to LZ4_streamDecode_t */<b> -</b><p> information structure to track an LZ4 stream during decompression. - init this structure using LZ4_setStreamDecode() before first use. - note : only use in association with static linking ! - this definition is not API/ABI safe, - and may change in a future version ! - +<pre><b>typedef struct { + const LZ4_byte* externalDict; + const LZ4_byte* prefixEnd; + size_t extDictSize; + size_t prefixSize; +} LZ4_streamDecode_t_internal; +</b><p> Never ever use below internal definitions directly ! + These definitions are not API/ABI safe, and may change in future versions. + If you need static allocation, declare or allocate an LZ4_streamDecode_t object. </p></pre><BR> <a name="Chapter10"></a><h2>Obsolete Functions</h2><pre></pre> diff --git a/doc/lz4frame_manual.html b/doc/lz4frame_manual.html index 0ae5150..196881e 100644 --- a/doc/lz4frame_manual.html +++ b/doc/lz4frame_manual.html @@ -135,13 +135,16 @@ <pre><b>LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_cctx** cctxPtr, unsigned version); LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_cctx* cctx); -</b><p> The first thing to do is to create a compressionContext object, which will be used in all compression operations. +</b><p> The first thing to do is to create a compressionContext object, + which will keep track of operation state during streaming compression. This is achieved using LZ4F_createCompressionContext(), which takes as argument a version. The version provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL. The function will provide a pointer to a fully allocated LZ4F_cctx object. - If @return != zero, there was an error during context creation. - Object can be released using LZ4F_freeCompressionContext(); - Note: LZ4F_freeCompressionContext() works with NULL pointers (do nothing). + If @return != zero, there context creation failed. + Once all streaming compression jobs are completed, + the state object can be released using LZ4F_freeCompressionContext(). + Note1 : LZ4F_freeCompressionContext() is always successful. Its return value can be ignored. + Note2 : LZ4F_freeCompressionContext() works fine with NULL input pointers (do nothing). </p></pre><BR> @@ -344,6 +347,11 @@ LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx* dctx); <pre><b>typedef enum { LZ4F_LIST_ERRORS(LZ4F_GENERATE_ENUM) _LZ4F_dummy_error_enum_for_c89_never_used } LZ4F_errorCodes; </b></pre><BR> +<pre><b>LZ4FLIB_STATIC_API size_t LZ4F_getBlockSize(LZ4F_blockSizeID_t blockSizeID); +</b><p> Return, in scalar format (size_t), + the maximum block size associated with blockSizeID. +</p></pre><BR> + <pre><b>LZ4FLIB_STATIC_API size_t LZ4F_uncompressedUpdate(LZ4F_cctx* cctx, void* dstBuffer, size_t dstCapacity, const void* srcBuffer, size_t srcSize, diff --git a/lib/lz4frame.c b/lib/lz4frame.c index aec2728..5373083 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -285,16 +285,16 @@ unsigned LZ4F_getVersion(void) { return LZ4F_VERSION; } int LZ4F_compressionLevel_max(void) { return LZ4HC_CLEVEL_MAX; } -size_t LZ4F_getBlockSize(unsigned blockSizeID) +size_t LZ4F_getBlockSize(LZ4F_blockSizeID_t blockSizeID) { static const size_t blockSizes[4] = { 64 KB, 256 KB, 1 MB, 4 MB }; if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT; if (blockSizeID < LZ4F_max64KB || blockSizeID > LZ4F_max4MB) RETURN_ERROR(maxBlockSize_invalid); - blockSizeID -= LZ4F_max64KB; - return blockSizes[blockSizeID]; -} + { int const blockSizeIdx = (int)blockSizeID - (int)LZ4F_max64KB; + return blockSizes[blockSizeIdx]; +} } /*-************************************ * Private functions @@ -1291,7 +1291,7 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx* dctx, const void* src, size_t srcSize dctx->frameInfo.blockChecksumFlag = (LZ4F_blockChecksum_t)blockChecksumFlag; dctx->frameInfo.contentChecksumFlag = (LZ4F_contentChecksum_t)contentChecksumFlag; dctx->frameInfo.blockSizeID = (LZ4F_blockSizeID_t)blockSizeID; - dctx->maxBlockSize = LZ4F_getBlockSize(blockSizeID); + dctx->maxBlockSize = LZ4F_getBlockSize((LZ4F_blockSizeID_t)blockSizeID); if (contentSizeFlag) dctx->frameRemainingSize = dctx->frameInfo.contentSize = LZ4F_readLE64(srcPtr+6); diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 2c5a559..1de09d8 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -545,7 +545,11 @@ typedef enum { LZ4F_LIST_ERRORS(LZ4F_GENERATE_ENUM) LZ4FLIB_STATIC_API LZ4F_errorCodes LZ4F_getErrorCode(size_t functionResult); -LZ4FLIB_STATIC_API size_t LZ4F_getBlockSize(unsigned); +/*! LZ4F_getBlockSize() : + * Return, in scalar format (size_t), + * the maximum block size associated with blockSizeID. +**/ +LZ4FLIB_STATIC_API size_t LZ4F_getBlockSize(LZ4F_blockSizeID_t blockSizeID); /*! LZ4F_uncompressedUpdate() : * LZ4F_uncompressedUpdate() can be called repetitively to add as much data uncompressed data as necessary. diff --git a/tests/frametest.c b/tests/frametest.c index a496c3c..58eac38 100644 --- a/tests/frametest.c +++ b/tests/frametest.c @@ -686,20 +686,20 @@ int basicTests(U32 seed, double compressibility) { size_t result; unsigned blockSizeID; for (blockSizeID = 4; blockSizeID < 8; ++blockSizeID) { - result = LZ4F_getBlockSize(blockSizeID); + result = LZ4F_getBlockSize((LZ4F_blockSizeID_t)blockSizeID); CHECK(result); DISPLAYLEVEL(3, "Returned block size of %u bytes for blockID %u \n", (unsigned)result, blockSizeID); } /* Test an invalid input that's too large */ - result = LZ4F_getBlockSize(8); + result = LZ4F_getBlockSize((LZ4F_blockSizeID_t)8); if(!LZ4F_isError(result) || LZ4F_getErrorCode(result) != LZ4F_ERROR_maxBlockSize_invalid) goto _output_error; /* Test an invalid input that's too small */ - result = LZ4F_getBlockSize(3); + result = LZ4F_getBlockSize((LZ4F_blockSizeID_t)3); if(!LZ4F_isError(result) || LZ4F_getErrorCode(result) != LZ4F_ERROR_maxBlockSize_invalid) goto _output_error; |