Fix ZSTD_estimateCStreamSize_usingCCtxParams()
It wasn't using the ZSTD_CCtx_params correctly. It must actualize the compression parameters by calling ZSTD_getCParamsFromCCtxParams() to get the real window log. Tested by updating the streaming memory usage example in the next commit. The CHECK() failed before this patch, and passes after. I also added a unit test to zstreamtest.c that failed before this patch, and passes after.
This commit is contained in:
@@ -1106,9 +1106,11 @@ size_t ZSTD_estimateCCtxSize(int compressionLevel)
|
|||||||
size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
||||||
{
|
{
|
||||||
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
|
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
|
||||||
{ size_t const CCtxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params);
|
{ ZSTD_compressionParameters const cParams =
|
||||||
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params->cParams.windowLog);
|
ZSTD_getCParamsFromCCtxParams(params, 0, 0);
|
||||||
size_t const inBuffSize = ((size_t)1 << params->cParams.windowLog) + blockSize;
|
size_t const CCtxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params);
|
||||||
|
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog);
|
||||||
|
size_t const inBuffSize = ((size_t)1 << cParams.windowLog) + blockSize;
|
||||||
size_t const outBuffSize = ZSTD_compressBound(blockSize) + 1;
|
size_t const outBuffSize = ZSTD_compressBound(blockSize) + 1;
|
||||||
size_t const streamingSize = inBuffSize + outBuffSize;
|
size_t const streamingSize = inBuffSize + outBuffSize;
|
||||||
|
|
||||||
|
|||||||
@@ -344,6 +344,20 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
DISPLAYLEVEL(3, "OK (%u bytes) \n", (unsigned)(cstreamSize + cdictSize));
|
DISPLAYLEVEL(3, "OK (%u bytes) \n", (unsigned)(cstreamSize + cdictSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* context size functions */
|
||||||
|
DISPLAYLEVEL(3, "test%3i : estimate CStream size using CCtxParams : ", testNb++);
|
||||||
|
{ ZSTD_CCtx_params* const params = ZSTD_createCCtxParams();
|
||||||
|
size_t cstreamSize, cctxSize;
|
||||||
|
CHECK_Z( ZSTD_CCtxParams_setParameter(params, ZSTD_c_compressionLevel, 19) );
|
||||||
|
cstreamSize = ZSTD_estimateCStreamSize_usingCCtxParams(params);
|
||||||
|
CHECK_Z(cstreamSize);
|
||||||
|
cctxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params);
|
||||||
|
CHECK_Z(cctxSize);
|
||||||
|
if (cstreamSize <= cctxSize + 2 * ZSTD_BLOCKSIZE_MAX) goto _output_error;
|
||||||
|
ZSTD_freeCCtxParams(params);
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
}
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : check actual CStream size : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : check actual CStream size : ", testNb++);
|
||||||
{ size_t const s = ZSTD_sizeof_CStream(zc);
|
{ size_t const s = ZSTD_sizeof_CStream(zc);
|
||||||
if (ZSTD_isError(s)) goto _output_error;
|
if (ZSTD_isError(s)) goto _output_error;
|
||||||
|
|||||||
Reference in New Issue
Block a user