size_t maxBlockSize)
{
size_t const windowSize = (size_t) BOUNDED(1ULL, 1ULL << cParams->windowLog, pledgedSrcSize);
- size_t const blockSize = MIN(maxBlockSize, windowSize);
+ size_t const blockSize = MIN(ZSTD_resolveMaxBlockSize(maxBlockSize), windowSize);
size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, cParams->minMatch, useExternalMatchFinder);
size_t const tokenSpace = ZSTD_cwksp_alloc_size(WILDCOPY_OVERLENGTH + blockSize)
+ ZSTD_cwksp_aligned_alloc_size(maxNbSeq * sizeof(seqDef))
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
{ ZSTD_compressionParameters const cParams =
ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
- size_t const blockSize = MIN(params->maxBlockSize, (size_t)1 << cParams.windowLog);
+ size_t const blockSize = MIN(ZSTD_resolveMaxBlockSize(params->maxBlockSize), (size_t)1 << cParams.windowLog);
size_t const inBuffSize = (params->inBufferMode == ZSTD_bm_buffered)
? ((size_t)1 << cParams.windowLog) + blockSize
: 0;
assert(params->useRowMatchFinder != ZSTD_ps_auto);
assert(params->useBlockSplitter != ZSTD_ps_auto);
assert(params->ldmParams.enableLdm != ZSTD_ps_auto);
+ assert(params->maxBlockSize != 0);
if (params->ldmParams.enableLdm == ZSTD_ps_enable) {
/* Adjust long distance matching parameters */
ZSTD_ldm_adjustParameters(&zc->appliedParams.ldmParams, ¶ms->cParams);
if (!ZSTD_isError(r)) goto _output_error;
}
DISPLAYLEVEL(3, "OK \n");
+
+ DISPLAYLEVEL(3, "test%3i : test estimation functions with default cctx params : ", testNb++);
+ {
+ // Test ZSTD_estimateCCtxSize_usingCCtxParams
+ {
+ ZSTD_CCtx_params* params = ZSTD_createCCtxParams();
+ size_t const cctxSizeDefault = ZSTD_estimateCCtxSize_usingCCtxParams(params);
+ staticCCtx = ZSTD_initStaticCCtx(staticCCtxBuffer, cctxSizeDefault);
+ CHECK_VAR(cSize, ZSTD_compressCCtx(staticCCtx,
+ compressedBuffer, compressedBufferSize,
+ CNBuffer, CNBuffSize, 3));
+
+ {
+ size_t const r = ZSTD_decompressDCtx(staticDCtx,
+ decodedBuffer, CNBuffSize,
+ compressedBuffer, cSize);
+ if (r != CNBuffSize) goto _output_error;
+ if (memcmp(decodedBuffer, CNBuffer, CNBuffSize)) goto _output_error;
+ }
+ ZSTD_freeCCtxParams(params);
+ }
+
+ // Test ZSTD_estimateCStreamSize_usingCCtxParams
+ {
+ ZSTD_CCtx_params* params = ZSTD_createCCtxParams();
+ size_t const cctxSizeDefault = ZSTD_estimateCStreamSize_usingCCtxParams(params);
+ staticCCtx = ZSTD_initStaticCCtx(staticCCtxBuffer, cctxSizeDefault);
+ CHECK_VAR(cSize, ZSTD_compressCCtx(staticCCtx,
+ compressedBuffer, compressedBufferSize,
+ CNBuffer, CNBuffSize, 3) );
+
+ {
+ size_t const r = ZSTD_decompressDCtx(staticDCtx,
+ decodedBuffer, CNBuffSize,
+ compressedBuffer, cSize);
+ if (r != CNBuffSize) goto _output_error;
+ if (memcmp(decodedBuffer, CNBuffer, CNBuffSize)) goto _output_error;
+ }
+ ZSTD_freeCCtxParams(params);
+ }
+ }
+ DISPLAYLEVEL(3, "OK \n");
+
+ DISPLAYLEVEL(3, "test%3i : test estimation functions with maxBlockSize = 0 : ", testNb++);
+ {
+ // Test ZSTD_estimateCCtxSize_usingCCtxParams
+ {
+ ZSTD_CCtx_params* params = ZSTD_createCCtxParams();
+ size_t cctxSizeDefault;
+ CHECK_Z(ZSTD_CCtxParams_setParameter(params, ZSTD_c_maxBlockSize, 0));
+ cctxSizeDefault = ZSTD_estimateCCtxSize_usingCCtxParams(params);
+ staticCCtx = ZSTD_initStaticCCtx(staticCCtxBuffer, cctxSizeDefault);
+ CHECK_VAR(cSize, ZSTD_compressCCtx(staticCCtx,
+ compressedBuffer, compressedBufferSize,
+ CNBuffer, CNBuffSize, 3) );
+
+ {
+ size_t const r = ZSTD_decompressDCtx(staticDCtx,
+ decodedBuffer, CNBuffSize,
+ compressedBuffer, cSize);
+ if (r != CNBuffSize) goto _output_error;
+ if (memcmp(decodedBuffer, CNBuffer, CNBuffSize)) goto _output_error;
+ }
+ ZSTD_freeCCtxParams(params);
+ }
+
+ // Test ZSTD_estimateCStreamSize_usingCCtxParams
+ {
+ ZSTD_CCtx_params* params = ZSTD_createCCtxParams();
+ size_t cctxSizeDefault;
+ CHECK_Z(ZSTD_CCtxParams_setParameter(params, ZSTD_c_maxBlockSize, 0));
+ cctxSizeDefault = ZSTD_estimateCStreamSize_usingCCtxParams(params);
+ staticCCtx = ZSTD_initStaticCCtx(staticCCtxBuffer, cctxSizeDefault);
+ CHECK_VAR(cSize, ZSTD_compressCCtx(staticCCtx,
+ compressedBuffer, compressedBufferSize,
+ CNBuffer, CNBuffSize, 3) );
+
+ {
+ size_t const r = ZSTD_decompressDCtx(staticDCtx,
+ decodedBuffer, CNBuffSize,
+ compressedBuffer, cSize);
+ if (r != CNBuffSize) goto _output_error;
+ if (memcmp(decodedBuffer, CNBuffer, CNBuffSize)) goto _output_error;
+ }
+ ZSTD_freeCCtxParams(params);
+ }
+ }
+ DISPLAYLEVEL(3, "OK \n");
}
free(staticCCtxBuffer);
free(staticDCtxBuffer);