Also Convert zstd_compress.c
This commit is contained in:
+153
-153
@@ -117,7 +117,8 @@ static void ZSTD_freeCCtxContent(ZSTD_CCtx* cctx)
|
|||||||
size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx)
|
size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx)
|
||||||
{
|
{
|
||||||
if (cctx==NULL) return 0; /* support free on NULL */
|
if (cctx==NULL) return 0; /* support free on NULL */
|
||||||
if (cctx->staticSize) return ERROR(memory_allocation); /* not compatible with static CCtx */
|
RETURN_ERROR_IF(cctx->staticSize, memory_allocation,
|
||||||
|
"not compatible with static CCtx");
|
||||||
ZSTD_freeCCtxContent(cctx);
|
ZSTD_freeCCtxContent(cctx);
|
||||||
ZSTD_free(cctx, cctx->customMem);
|
ZSTD_free(cctx, cctx->customMem);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -195,7 +196,7 @@ size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel) {
|
size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel) {
|
||||||
if (!cctxParams) { return ERROR(GENERIC); }
|
RETURN_ERROR_IF(!cctxParams, GENERIC);
|
||||||
memset(cctxParams, 0, sizeof(*cctxParams));
|
memset(cctxParams, 0, sizeof(*cctxParams));
|
||||||
cctxParams->compressionLevel = compressionLevel;
|
cctxParams->compressionLevel = compressionLevel;
|
||||||
cctxParams->fParams.contentSizeFlag = 1;
|
cctxParams->fParams.contentSizeFlag = 1;
|
||||||
@@ -204,8 +205,8 @@ size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel)
|
|||||||
|
|
||||||
size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params)
|
size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params)
|
||||||
{
|
{
|
||||||
if (!cctxParams) { return ERROR(GENERIC); }
|
RETURN_ERROR_IF(!cctxParams, GENERIC);
|
||||||
CHECK_F( ZSTD_checkCParams(params.cParams) );
|
FORWARD_ERROR( ZSTD_checkCParams(params.cParams) );
|
||||||
memset(cctxParams, 0, sizeof(*cctxParams));
|
memset(cctxParams, 0, sizeof(*cctxParams));
|
||||||
cctxParams->cParams = params.cParams;
|
cctxParams->cParams = params.cParams;
|
||||||
cctxParams->fParams = params.fParams;
|
cctxParams->fParams = params.fParams;
|
||||||
@@ -378,10 +379,10 @@ static int ZSTD_cParam_withinBounds(ZSTD_cParameter cParam, int value)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOUNDCHECK(cParam, val) { \
|
#define BOUNDCHECK(cParam, val) { \
|
||||||
if (!ZSTD_cParam_withinBounds(cParam,val)) { \
|
RETURN_ERROR_IF(!ZSTD_cParam_withinBounds(cParam,val), \
|
||||||
return ERROR(parameter_outOfBound); \
|
parameter_outOfBound); \
|
||||||
} }
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
|
static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
|
||||||
@@ -425,7 +426,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
if (ZSTD_isUpdateAuthorized(param)) {
|
if (ZSTD_isUpdateAuthorized(param)) {
|
||||||
cctx->cParamsChanged = 1;
|
cctx->cParamsChanged = 1;
|
||||||
} else {
|
} else {
|
||||||
return ERROR(stage_wrong);
|
RETURN_ERROR(stage_wrong);
|
||||||
} }
|
} }
|
||||||
|
|
||||||
switch(param)
|
switch(param)
|
||||||
@@ -434,7 +435,8 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||||
|
|
||||||
case ZSTD_c_compressionLevel:
|
case ZSTD_c_compressionLevel:
|
||||||
if (cctx->cdict) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->cdict, stage_wrong,
|
||||||
|
"compression level is configured in cdict");
|
||||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||||
|
|
||||||
case ZSTD_c_windowLog:
|
case ZSTD_c_windowLog:
|
||||||
@@ -444,7 +446,8 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
case ZSTD_c_minMatch:
|
case ZSTD_c_minMatch:
|
||||||
case ZSTD_c_targetLength:
|
case ZSTD_c_targetLength:
|
||||||
case ZSTD_c_strategy:
|
case ZSTD_c_strategy:
|
||||||
if (cctx->cdict) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->cdict, stage_wrong,
|
||||||
|
"cparams are configured in cdict");
|
||||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||||
|
|
||||||
case ZSTD_c_contentSizeFlag:
|
case ZSTD_c_contentSizeFlag:
|
||||||
@@ -461,9 +464,8 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||||
|
|
||||||
case ZSTD_c_nbWorkers:
|
case ZSTD_c_nbWorkers:
|
||||||
if ((value!=0) && cctx->staticSize) {
|
RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported,
|
||||||
return ERROR(parameter_unsupported); /* MT not compatible with static alloc */
|
"MT not compatible with static alloc");
|
||||||
}
|
|
||||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||||
|
|
||||||
case ZSTD_c_jobSize:
|
case ZSTD_c_jobSize:
|
||||||
@@ -476,10 +478,10 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
|||||||
case ZSTD_c_ldmMinMatch:
|
case ZSTD_c_ldmMinMatch:
|
||||||
case ZSTD_c_ldmBucketSizeLog:
|
case ZSTD_c_ldmBucketSizeLog:
|
||||||
case ZSTD_c_ldmHashRateLog:
|
case ZSTD_c_ldmHashRateLog:
|
||||||
if (cctx->cdict) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->cdict, stage_wrong);
|
||||||
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
||||||
|
|
||||||
default: return ERROR(parameter_unsupported);
|
default: RETURN_ERROR(parameter_unsupported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,7 +577,7 @@ size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* CCtxParams,
|
|||||||
|
|
||||||
case ZSTD_c_nbWorkers :
|
case ZSTD_c_nbWorkers :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
if (value!=0) return ERROR(parameter_unsupported);
|
RETURN_ERROR_IF(value!=0, parameter_unsupported, "not compiled with multithreading");
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
return ZSTDMT_CCtxParam_setNbWorkers(CCtxParams, value);
|
return ZSTDMT_CCtxParam_setNbWorkers(CCtxParams, value);
|
||||||
@@ -583,21 +585,21 @@ size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* CCtxParams,
|
|||||||
|
|
||||||
case ZSTD_c_jobSize :
|
case ZSTD_c_jobSize :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
return ERROR(parameter_unsupported);
|
RETURN_ERROR(parameter_unsupported, "not compiled with multithreading");
|
||||||
#else
|
#else
|
||||||
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_jobSize, value);
|
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_jobSize, value);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case ZSTD_c_overlapLog :
|
case ZSTD_c_overlapLog :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
return ERROR(parameter_unsupported);
|
RETURN_ERROR(parameter_unsupported, "not compiled with multithreading");
|
||||||
#else
|
#else
|
||||||
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_overlapLog, value);
|
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_overlapLog, value);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case ZSTD_c_rsyncable :
|
case ZSTD_c_rsyncable :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
return ERROR(parameter_unsupported);
|
RETURN_ERROR(parameter_unsupported, "not compiled with multithreading");
|
||||||
#else
|
#else
|
||||||
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_rsyncable, value);
|
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_rsyncable, value);
|
||||||
#endif
|
#endif
|
||||||
@@ -625,12 +627,12 @@ size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* CCtxParams,
|
|||||||
return CCtxParams->ldmParams.bucketSizeLog;
|
return CCtxParams->ldmParams.bucketSizeLog;
|
||||||
|
|
||||||
case ZSTD_c_ldmHashRateLog :
|
case ZSTD_c_ldmHashRateLog :
|
||||||
if (value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
|
RETURN_ERROR_IF(value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN,
|
||||||
return ERROR(parameter_outOfBound);
|
parameter_outOfBound);
|
||||||
CCtxParams->ldmParams.hashRateLog = value;
|
CCtxParams->ldmParams.hashRateLog = value;
|
||||||
return CCtxParams->ldmParams.hashRateLog;
|
return CCtxParams->ldmParams.hashRateLog;
|
||||||
|
|
||||||
default: return ERROR(parameter_unsupported);
|
default: RETURN_ERROR(parameter_unsupported, "unknown parameter");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,7 +696,7 @@ size_t ZSTD_CCtxParam_getParameter(
|
|||||||
break;
|
break;
|
||||||
case ZSTD_c_jobSize :
|
case ZSTD_c_jobSize :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
return ERROR(parameter_unsupported);
|
RETURN_ERROR(parameter_unsupported, "not compiled with multithreading");
|
||||||
#else
|
#else
|
||||||
assert(CCtxParams->jobSize <= INT_MAX);
|
assert(CCtxParams->jobSize <= INT_MAX);
|
||||||
*value = (int)CCtxParams->jobSize;
|
*value = (int)CCtxParams->jobSize;
|
||||||
@@ -702,14 +704,14 @@ size_t ZSTD_CCtxParam_getParameter(
|
|||||||
#endif
|
#endif
|
||||||
case ZSTD_c_overlapLog :
|
case ZSTD_c_overlapLog :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
return ERROR(parameter_unsupported);
|
RETURN_ERROR(parameter_unsupported, "not compiled with multithreading");
|
||||||
#else
|
#else
|
||||||
*value = CCtxParams->overlapLog;
|
*value = CCtxParams->overlapLog;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case ZSTD_c_rsyncable :
|
case ZSTD_c_rsyncable :
|
||||||
#ifndef ZSTD_MULTITHREAD
|
#ifndef ZSTD_MULTITHREAD
|
||||||
return ERROR(parameter_unsupported);
|
RETURN_ERROR(parameter_unsupported, "not compiled with multithreading");
|
||||||
#else
|
#else
|
||||||
*value = CCtxParams->rsyncable;
|
*value = CCtxParams->rsyncable;
|
||||||
break;
|
break;
|
||||||
@@ -729,7 +731,7 @@ size_t ZSTD_CCtxParam_getParameter(
|
|||||||
case ZSTD_c_ldmHashRateLog :
|
case ZSTD_c_ldmHashRateLog :
|
||||||
*value = CCtxParams->ldmParams.hashRateLog;
|
*value = CCtxParams->ldmParams.hashRateLog;
|
||||||
break;
|
break;
|
||||||
default: return ERROR(parameter_unsupported);
|
default: RETURN_ERROR(parameter_unsupported, "unknown parameter");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -745,8 +747,8 @@ size_t ZSTD_CCtx_setParametersUsingCCtxParams(
|
|||||||
ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params)
|
ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_CCtx_setParametersUsingCCtxParams");
|
DEBUGLOG(4, "ZSTD_CCtx_setParametersUsingCCtxParams");
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
|
||||||
if (cctx->cdict) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->cdict, stage_wrong);
|
||||||
|
|
||||||
cctx->requestedParams = *params;
|
cctx->requestedParams = *params;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -755,7 +757,7 @@ size_t ZSTD_CCtx_setParametersUsingCCtxParams(
|
|||||||
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize)
|
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_CCtx_setPledgedSrcSize to %u bytes", (U32)pledgedSrcSize);
|
DEBUGLOG(4, "ZSTD_CCtx_setPledgedSrcSize to %u bytes", (U32)pledgedSrcSize);
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
|
||||||
cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
|
cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -764,8 +766,9 @@ size_t ZSTD_CCtx_loadDictionary_advanced(
|
|||||||
ZSTD_CCtx* cctx, const void* dict, size_t dictSize,
|
ZSTD_CCtx* cctx, const void* dict, size_t dictSize,
|
||||||
ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
|
ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
|
||||||
{
|
{
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
|
||||||
if (cctx->staticSize) return ERROR(memory_allocation); /* no malloc for static CCtx */
|
RETURN_ERROR_IF(cctx->staticSize, memory_allocation,
|
||||||
|
"no malloc for static CCtx");
|
||||||
DEBUGLOG(4, "ZSTD_CCtx_loadDictionary_advanced (size: %u)", (U32)dictSize);
|
DEBUGLOG(4, "ZSTD_CCtx_loadDictionary_advanced (size: %u)", (U32)dictSize);
|
||||||
ZSTD_freeCDict(cctx->cdictLocal); /* in case one already exists */
|
ZSTD_freeCDict(cctx->cdictLocal); /* in case one already exists */
|
||||||
if (dict==NULL || dictSize==0) { /* no dictionary mode */
|
if (dict==NULL || dictSize==0) { /* no dictionary mode */
|
||||||
@@ -779,8 +782,7 @@ size_t ZSTD_CCtx_loadDictionary_advanced(
|
|||||||
dictLoadMethod, dictContentType,
|
dictLoadMethod, dictContentType,
|
||||||
cParams, cctx->customMem);
|
cParams, cctx->customMem);
|
||||||
cctx->cdict = cctx->cdictLocal;
|
cctx->cdict = cctx->cdictLocal;
|
||||||
if (cctx->cdictLocal == NULL)
|
RETURN_ERROR_IF(cctx->cdictLocal == NULL, memory_allocation);
|
||||||
return ERROR(memory_allocation);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -801,7 +803,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, s
|
|||||||
|
|
||||||
size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
|
size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
|
||||||
{
|
{
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
|
||||||
cctx->cdict = cdict;
|
cctx->cdict = cdict;
|
||||||
memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* exclusive */
|
memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* exclusive */
|
||||||
return 0;
|
return 0;
|
||||||
@@ -815,7 +817,7 @@ size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSiz
|
|||||||
size_t ZSTD_CCtx_refPrefix_advanced(
|
size_t ZSTD_CCtx_refPrefix_advanced(
|
||||||
ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
|
ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
|
||||||
{
|
{
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
|
||||||
cctx->cdict = NULL; /* prefix discards any prior cdict */
|
cctx->cdict = NULL; /* prefix discards any prior cdict */
|
||||||
cctx->prefixDict.dict = prefix;
|
cctx->prefixDict.dict = prefix;
|
||||||
cctx->prefixDict.dictSize = prefixSize;
|
cctx->prefixDict.dictSize = prefixSize;
|
||||||
@@ -834,7 +836,7 @@ size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset)
|
|||||||
}
|
}
|
||||||
if ( (reset == ZSTD_reset_parameters)
|
if ( (reset == ZSTD_reset_parameters)
|
||||||
|| (reset == ZSTD_reset_session_and_parameters) ) {
|
|| (reset == ZSTD_reset_session_and_parameters) ) {
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
|
||||||
cctx->cdict = NULL;
|
cctx->cdict = NULL;
|
||||||
return ZSTD_CCtxParams_reset(&cctx->requestedParams);
|
return ZSTD_CCtxParams_reset(&cctx->requestedParams);
|
||||||
}
|
}
|
||||||
@@ -974,8 +976,7 @@ ZSTD_sizeof_matchState(const ZSTD_compressionParameters* const cParams,
|
|||||||
|
|
||||||
size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
||||||
{
|
{
|
||||||
/* 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.");
|
||||||
if (params->nbWorkers > 0) { return ERROR(GENERIC); }
|
|
||||||
{ ZSTD_compressionParameters const cParams =
|
{ ZSTD_compressionParameters const cParams =
|
||||||
ZSTD_getCParamsFromCCtxParams(params, 0, 0);
|
ZSTD_getCParamsFromCCtxParams(params, 0, 0);
|
||||||
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog);
|
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog);
|
||||||
@@ -1023,7 +1024,7 @@ 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)
|
||||||
{
|
{
|
||||||
if (params->nbWorkers > 0) { return ERROR(GENERIC); }
|
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);
|
{ size_t const CCtxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params);
|
||||||
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params->cParams.windowLog);
|
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params->cParams.windowLog);
|
||||||
size_t const inBuffSize = ((size_t)1 << params->cParams.windowLog) + blockSize;
|
size_t const inBuffSize = ((size_t)1 << params->cParams.windowLog) + blockSize;
|
||||||
@@ -1368,13 +1369,13 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
|
|||||||
DEBUGLOG(4, "Need to resize workSpaceSize from %zuKB to %zuKB",
|
DEBUGLOG(4, "Need to resize workSpaceSize from %zuKB to %zuKB",
|
||||||
zc->workSpaceSize >> 10,
|
zc->workSpaceSize >> 10,
|
||||||
neededSpace >> 10);
|
neededSpace >> 10);
|
||||||
/* static cctx : no resize, error out */
|
|
||||||
if (zc->staticSize) return ERROR(memory_allocation);
|
RETURN_ERROR_IF(zc->staticSize, memory_allocation, "static cctx : no resize");
|
||||||
|
|
||||||
zc->workSpaceSize = 0;
|
zc->workSpaceSize = 0;
|
||||||
ZSTD_free(zc->workSpace, zc->customMem);
|
ZSTD_free(zc->workSpace, zc->customMem);
|
||||||
zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem);
|
zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem);
|
||||||
if (zc->workSpace == NULL) return ERROR(memory_allocation);
|
RETURN_ERROR_IF(zc->workSpace == NULL, memory_allocation);
|
||||||
zc->workSpaceSize = neededSpace;
|
zc->workSpaceSize = neededSpace;
|
||||||
zc->workSpaceOversizedDuration = 0;
|
zc->workSpaceOversizedDuration = 0;
|
||||||
|
|
||||||
@@ -1645,7 +1646,7 @@ static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx* dstCCtx,
|
|||||||
ZSTD_buffered_policy_e zbuff)
|
ZSTD_buffered_policy_e zbuff)
|
||||||
{
|
{
|
||||||
DEBUGLOG(5, "ZSTD_copyCCtx_internal");
|
DEBUGLOG(5, "ZSTD_copyCCtx_internal");
|
||||||
if (srcCCtx->stage!=ZSTDcs_init) return ERROR(stage_wrong);
|
RETURN_ERROR_IF(srcCCtx->stage!=ZSTDcs_init, stage_wrong);
|
||||||
|
|
||||||
memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem));
|
memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem));
|
||||||
{ ZSTD_CCtx_params params = dstCCtx->requestedParams;
|
{ ZSTD_CCtx_params params = dstCCtx->requestedParams;
|
||||||
@@ -1778,7 +1779,8 @@ static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue)
|
|||||||
static size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastBlock)
|
static size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastBlock)
|
||||||
{
|
{
|
||||||
U32 const cBlockHeader24 = lastBlock + (((U32)bt_raw)<<1) + (U32)(srcSize << 3);
|
U32 const cBlockHeader24 = lastBlock + (((U32)bt_raw)<<1) + (U32)(srcSize << 3);
|
||||||
if (srcSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(srcSize + ZSTD_blockHeaderSize > dstCapacity,
|
||||||
|
dstSize_tooSmall);
|
||||||
MEM_writeLE24(dst, cBlockHeader24);
|
MEM_writeLE24(dst, cBlockHeader24);
|
||||||
memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize);
|
memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize);
|
||||||
return ZSTD_blockHeaderSize + srcSize;
|
return ZSTD_blockHeaderSize + srcSize;
|
||||||
@@ -1789,7 +1791,7 @@ static size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void
|
|||||||
BYTE* const ostart = (BYTE* const)dst;
|
BYTE* const ostart = (BYTE* const)dst;
|
||||||
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
||||||
|
|
||||||
if (srcSize + flSize > dstCapacity) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(srcSize + flSize > dstCapacity, dstSize_tooSmall);
|
||||||
|
|
||||||
switch(flSize)
|
switch(flSize)
|
||||||
{
|
{
|
||||||
@@ -1879,7 +1881,7 @@ static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|||||||
if (srcSize <= minLitSize) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
if (srcSize <= minLitSize) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dstCapacity < lhSize+1) return ERROR(dstSize_tooSmall); /* not enough space for compression */
|
RETURN_ERROR_IF(dstCapacity < lhSize+1, dstSize_tooSmall, "not enough space for compression");
|
||||||
{ HUF_repeat repeat = prevHuf->repeatMode;
|
{ HUF_repeat repeat = prevHuf->repeatMode;
|
||||||
int const preferRepeat = strategy < ZSTD_lazy ? srcSize <= 1024 : 0;
|
int const preferRepeat = strategy < ZSTD_lazy ? srcSize <= 1024 : 0;
|
||||||
if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
|
if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
|
||||||
@@ -2051,21 +2053,17 @@ static size_t ZSTD_fseBitCost(
|
|||||||
unsigned s;
|
unsigned s;
|
||||||
FSE_CState_t cstate;
|
FSE_CState_t cstate;
|
||||||
FSE_initCState(&cstate, ctable);
|
FSE_initCState(&cstate, ctable);
|
||||||
if (ZSTD_getFSEMaxSymbolValue(ctable) < max) {
|
RETURN_ERROR_IF(ZSTD_getFSEMaxSymbolValue(ctable) < max, GENERIC,
|
||||||
DEBUGLOG(5, "Repeat FSE_CTable has maxSymbolValue %u < %u",
|
"Repeat FSE_CTable has maxSymbolValue %u < %u",
|
||||||
ZSTD_getFSEMaxSymbolValue(ctable), max);
|
ZSTD_getFSEMaxSymbolValue(ctable), max);
|
||||||
return ERROR(GENERIC);
|
|
||||||
}
|
|
||||||
for (s = 0; s <= max; ++s) {
|
for (s = 0; s <= max; ++s) {
|
||||||
unsigned const tableLog = cstate.stateLog;
|
unsigned const tableLog = cstate.stateLog;
|
||||||
unsigned const badCost = (tableLog + 1) << kAccuracyLog;
|
unsigned const badCost = (tableLog + 1) << kAccuracyLog;
|
||||||
unsigned const bitCost = FSE_bitCost(cstate.symbolTT, tableLog, s, kAccuracyLog);
|
unsigned const bitCost = FSE_bitCost(cstate.symbolTT, tableLog, s, kAccuracyLog);
|
||||||
if (count[s] == 0)
|
if (count[s] == 0)
|
||||||
continue;
|
continue;
|
||||||
if (bitCost >= badCost) {
|
RETURN_ERROR_IF(bitCost >= badCost, GENERIC,
|
||||||
DEBUGLOG(5, "Repeat FSE_CTable has Prob[%u] == 0", s);
|
"Repeat FSE_CTable has Prob[%u] == 0", s);
|
||||||
return ERROR(GENERIC);
|
|
||||||
}
|
|
||||||
cost += count[s] * bitCost;
|
cost += count[s] * bitCost;
|
||||||
}
|
}
|
||||||
return cost >> kAccuracyLog;
|
return cost >> kAccuracyLog;
|
||||||
@@ -2081,7 +2079,7 @@ static size_t ZSTD_NCountCost(unsigned const* count, unsigned const max,
|
|||||||
BYTE wksp[FSE_NCOUNTBOUND];
|
BYTE wksp[FSE_NCOUNTBOUND];
|
||||||
S16 norm[MaxSeq + 1];
|
S16 norm[MaxSeq + 1];
|
||||||
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
|
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
|
||||||
CHECK_F(FSE_normalizeCount(norm, tableLog, count, nbSeq, max));
|
FORWARD_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq, max));
|
||||||
return FSE_writeNCount(wksp, sizeof(wksp), norm, max, tableLog);
|
return FSE_writeNCount(wksp, sizeof(wksp), norm, max, tableLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2187,15 +2185,15 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case set_rle:
|
case set_rle:
|
||||||
CHECK_F(FSE_buildCTable_rle(nextCTable, (BYTE)max));
|
FORWARD_ERROR(FSE_buildCTable_rle(nextCTable, (BYTE)max));
|
||||||
if (dstCapacity==0) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(dstCapacity==0, dstSize_tooSmall);
|
||||||
*op = codeTable[0];
|
*op = codeTable[0];
|
||||||
return 1;
|
return 1;
|
||||||
case set_repeat:
|
case set_repeat:
|
||||||
memcpy(nextCTable, prevCTable, prevCTableSize);
|
memcpy(nextCTable, prevCTable, prevCTableSize);
|
||||||
return 0;
|
return 0;
|
||||||
case set_basic:
|
case set_basic:
|
||||||
CHECK_F(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, workspace, workspaceSize)); /* note : could be pre-calculated */
|
FORWARD_ERROR(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, workspace, workspaceSize)); /* note : could be pre-calculated */
|
||||||
return 0;
|
return 0;
|
||||||
case set_compressed: {
|
case set_compressed: {
|
||||||
S16 norm[MaxSeq + 1];
|
S16 norm[MaxSeq + 1];
|
||||||
@@ -2206,14 +2204,14 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
|||||||
nbSeq_1--;
|
nbSeq_1--;
|
||||||
}
|
}
|
||||||
assert(nbSeq_1 > 1);
|
assert(nbSeq_1 > 1);
|
||||||
CHECK_F(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max));
|
FORWARD_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max));
|
||||||
{ size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */
|
{ size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */
|
||||||
if (FSE_isError(NCountSize)) return NCountSize;
|
FORWARD_ERROR(NCountSize);
|
||||||
CHECK_F(FSE_buildCTable_wksp(nextCTable, norm, max, tableLog, workspace, workspaceSize));
|
FORWARD_ERROR(FSE_buildCTable_wksp(nextCTable, norm, max, tableLog, workspace, workspaceSize));
|
||||||
return NCountSize;
|
return NCountSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: return assert(0), ERROR(GENERIC);
|
default: assert(0); RETURN_ERROR(GENERIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2304,7 +2302,7 @@ ZSTD_encodeSequences_body(
|
|||||||
FSE_flushCState(&blockStream, &stateLitLength);
|
FSE_flushCState(&blockStream, &stateLitLength);
|
||||||
|
|
||||||
{ size_t const streamSize = BIT_closeCStream(&blockStream);
|
{ size_t const streamSize = BIT_closeCStream(&blockStream);
|
||||||
if (streamSize==0) return ERROR(dstSize_tooSmall); /* not enough space */
|
RETURN_ERROR_IF(streamSize==0, dstSize_tooSmall, "not enough space");
|
||||||
return streamSize;
|
return streamSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2412,14 +2410,14 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|||||||
literals, litSize,
|
literals, litSize,
|
||||||
workspace, wkspSize,
|
workspace, wkspSize,
|
||||||
bmi2);
|
bmi2);
|
||||||
if (ZSTD_isError(cSize))
|
FORWARD_ERROR(cSize);
|
||||||
return cSize;
|
|
||||||
assert(cSize <= dstCapacity);
|
assert(cSize <= dstCapacity);
|
||||||
op += cSize;
|
op += cSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sequences Header */
|
/* Sequences Header */
|
||||||
if ((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/,
|
||||||
|
dstSize_tooSmall);
|
||||||
if (nbSeq < 0x7F)
|
if (nbSeq < 0x7F)
|
||||||
*op++ = (BYTE)nbSeq;
|
*op++ = (BYTE)nbSeq;
|
||||||
else if (nbSeq < LONGNBSEQ)
|
else if (nbSeq < LONGNBSEQ)
|
||||||
@@ -2453,7 +2451,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|||||||
count, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL,
|
count, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL,
|
||||||
prevEntropy->fse.litlengthCTable, sizeof(prevEntropy->fse.litlengthCTable),
|
prevEntropy->fse.litlengthCTable, sizeof(prevEntropy->fse.litlengthCTable),
|
||||||
workspace, wkspSize);
|
workspace, wkspSize);
|
||||||
if (ZSTD_isError(countSize)) return countSize;
|
FORWARD_ERROR(countSize);
|
||||||
if (LLtype == set_compressed)
|
if (LLtype == set_compressed)
|
||||||
lastNCount = op;
|
lastNCount = op;
|
||||||
op += countSize;
|
op += countSize;
|
||||||
@@ -2475,7 +2473,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|||||||
count, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
|
count, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
|
||||||
prevEntropy->fse.offcodeCTable, sizeof(prevEntropy->fse.offcodeCTable),
|
prevEntropy->fse.offcodeCTable, sizeof(prevEntropy->fse.offcodeCTable),
|
||||||
workspace, wkspSize);
|
workspace, wkspSize);
|
||||||
if (ZSTD_isError(countSize)) return countSize;
|
FORWARD_ERROR(countSize);
|
||||||
if (Offtype == set_compressed)
|
if (Offtype == set_compressed)
|
||||||
lastNCount = op;
|
lastNCount = op;
|
||||||
op += countSize;
|
op += countSize;
|
||||||
@@ -2495,7 +2493,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|||||||
count, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML,
|
count, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML,
|
||||||
prevEntropy->fse.matchlengthCTable, sizeof(prevEntropy->fse.matchlengthCTable),
|
prevEntropy->fse.matchlengthCTable, sizeof(prevEntropy->fse.matchlengthCTable),
|
||||||
workspace, wkspSize);
|
workspace, wkspSize);
|
||||||
if (ZSTD_isError(countSize)) return countSize;
|
FORWARD_ERROR(countSize);
|
||||||
if (MLtype == set_compressed)
|
if (MLtype == set_compressed)
|
||||||
lastNCount = op;
|
lastNCount = op;
|
||||||
op += countSize;
|
op += countSize;
|
||||||
@@ -2510,7 +2508,7 @@ ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|||||||
CTable_LitLength, llCodeTable,
|
CTable_LitLength, llCodeTable,
|
||||||
sequences, nbSeq,
|
sequences, nbSeq,
|
||||||
longOffsets, bmi2);
|
longOffsets, bmi2);
|
||||||
if (ZSTD_isError(bitstreamSize)) return bitstreamSize;
|
FORWARD_ERROR(bitstreamSize);
|
||||||
op += bitstreamSize;
|
op += bitstreamSize;
|
||||||
/* zstd versions <= 1.3.4 mistakenly report corruption when
|
/* zstd versions <= 1.3.4 mistakenly report corruption when
|
||||||
* FSE_readNCount() recieves a buffer < 4 bytes.
|
* FSE_readNCount() recieves a buffer < 4 bytes.
|
||||||
@@ -2553,7 +2551,7 @@ ZSTD_compressSequences(seqStore_t* seqStorePtr,
|
|||||||
*/
|
*/
|
||||||
if ((cSize == ERROR(dstSize_tooSmall)) & (srcSize <= dstCapacity))
|
if ((cSize == ERROR(dstSize_tooSmall)) & (srcSize <= dstCapacity))
|
||||||
return 0; /* block not compressed */
|
return 0; /* block not compressed */
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
|
|
||||||
/* Check compressibility */
|
/* Check compressibility */
|
||||||
{ size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, cctxParams->cParams.strategy);
|
{ size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, cctxParams->cParams.strategy);
|
||||||
@@ -2680,7 +2678,7 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
|
|||||||
ldmSeqStore.seq = zc->ldmSequences;
|
ldmSeqStore.seq = zc->ldmSequences;
|
||||||
ldmSeqStore.capacity = zc->maxNbLdmSequences;
|
ldmSeqStore.capacity = zc->maxNbLdmSequences;
|
||||||
/* Updates ldmSeqStore.size */
|
/* Updates ldmSeqStore.size */
|
||||||
CHECK_F(ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore,
|
FORWARD_ERROR(ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore,
|
||||||
&zc->appliedParams.ldmParams,
|
&zc->appliedParams.ldmParams,
|
||||||
src, srcSize));
|
src, srcSize));
|
||||||
/* Updates ldmSeqStore.pos */
|
/* Updates ldmSeqStore.pos */
|
||||||
@@ -2753,8 +2751,9 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
|
|||||||
ZSTD_matchState_t* const ms = &cctx->blockState.matchState;
|
ZSTD_matchState_t* const ms = &cctx->blockState.matchState;
|
||||||
U32 const lastBlock = lastFrameChunk & (blockSize >= remaining);
|
U32 const lastBlock = lastFrameChunk & (blockSize >= remaining);
|
||||||
|
|
||||||
if (dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE)
|
RETURN_ERROR_IF(dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE,
|
||||||
return ERROR(dstSize_tooSmall); /* not enough space to store compressed block */
|
dstSize_tooSmall,
|
||||||
|
"not enough space to store compressed block");
|
||||||
if (remaining < blockSize) blockSize = remaining;
|
if (remaining < blockSize) blockSize = remaining;
|
||||||
|
|
||||||
if (ZSTD_window_needOverflowCorrection(ms->window, ip + blockSize)) {
|
if (ZSTD_window_needOverflowCorrection(ms->window, ip + blockSize)) {
|
||||||
@@ -2775,11 +2774,11 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
|
|||||||
{ size_t cSize = ZSTD_compressBlock_internal(cctx,
|
{ size_t cSize = ZSTD_compressBlock_internal(cctx,
|
||||||
op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize,
|
op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize,
|
||||||
ip, blockSize);
|
ip, blockSize);
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
|
|
||||||
if (cSize == 0) { /* block is not compressible */
|
if (cSize == 0) { /* block is not compressible */
|
||||||
cSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
|
cSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
} else {
|
} else {
|
||||||
U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3);
|
U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3);
|
||||||
MEM_writeLE24(op, cBlockHeader24);
|
MEM_writeLE24(op, cBlockHeader24);
|
||||||
@@ -2816,7 +2815,7 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
|
|||||||
size_t pos=0;
|
size_t pos=0;
|
||||||
|
|
||||||
assert(!(params.fParams.contentSizeFlag && pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN));
|
assert(!(params.fParams.contentSizeFlag && pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN));
|
||||||
if (dstCapacity < ZSTD_FRAMEHEADERSIZE_MAX) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(dstCapacity < ZSTD_FRAMEHEADERSIZE_MAX, dstSize_tooSmall);
|
||||||
DEBUGLOG(4, "ZSTD_writeFrameHeader : dictIDFlag : %u ; dictID : %u ; dictIDSizeCode : %u",
|
DEBUGLOG(4, "ZSTD_writeFrameHeader : dictIDFlag : %u ; dictID : %u ; dictIDSizeCode : %u",
|
||||||
!params.fParams.noDictIDFlag, (unsigned)dictID, (unsigned)dictIDSizeCode);
|
!params.fParams.noDictIDFlag, (unsigned)dictID, (unsigned)dictIDSizeCode);
|
||||||
|
|
||||||
@@ -2852,7 +2851,7 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
|
|||||||
*/
|
*/
|
||||||
size_t ZSTD_writeLastEmptyBlock(void* dst, size_t dstCapacity)
|
size_t ZSTD_writeLastEmptyBlock(void* dst, size_t dstCapacity)
|
||||||
{
|
{
|
||||||
if (dstCapacity < ZSTD_blockHeaderSize) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(dstCapacity < ZSTD_blockHeaderSize, dstSize_tooSmall);
|
||||||
{ U32 const cBlockHeader24 = 1 /*lastBlock*/ + (((U32)bt_raw)<<1); /* 0 size */
|
{ U32 const cBlockHeader24 = 1 /*lastBlock*/ + (((U32)bt_raw)<<1); /* 0 size */
|
||||||
MEM_writeLE24(dst, cBlockHeader24);
|
MEM_writeLE24(dst, cBlockHeader24);
|
||||||
return ZSTD_blockHeaderSize;
|
return ZSTD_blockHeaderSize;
|
||||||
@@ -2861,10 +2860,9 @@ size_t ZSTD_writeLastEmptyBlock(void* dst, size_t dstCapacity)
|
|||||||
|
|
||||||
size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSeq)
|
size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSeq)
|
||||||
{
|
{
|
||||||
if (cctx->stage != ZSTDcs_init)
|
RETURN_ERROR_IF(cctx->stage != ZSTDcs_init, stage_wrong);
|
||||||
return ERROR(stage_wrong);
|
RETURN_ERROR_IF(cctx->appliedParams.ldmParams.enableLdm,
|
||||||
if (cctx->appliedParams.ldmParams.enableLdm)
|
parameter_unsupported);
|
||||||
return ERROR(parameter_unsupported);
|
|
||||||
cctx->externSeqStore.seq = seq;
|
cctx->externSeqStore.seq = seq;
|
||||||
cctx->externSeqStore.size = nbSeq;
|
cctx->externSeqStore.size = nbSeq;
|
||||||
cctx->externSeqStore.capacity = nbSeq;
|
cctx->externSeqStore.capacity = nbSeq;
|
||||||
@@ -2883,12 +2881,13 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
|
|||||||
|
|
||||||
DEBUGLOG(5, "ZSTD_compressContinue_internal, stage: %u, srcSize: %u",
|
DEBUGLOG(5, "ZSTD_compressContinue_internal, stage: %u, srcSize: %u",
|
||||||
cctx->stage, (unsigned)srcSize);
|
cctx->stage, (unsigned)srcSize);
|
||||||
if (cctx->stage==ZSTDcs_created) return ERROR(stage_wrong); /* missing init (ZSTD_compressBegin) */
|
RETURN_ERROR_IF(cctx->stage==ZSTDcs_created, stage_wrong,
|
||||||
|
"missing init (ZSTD_compressBegin)");
|
||||||
|
|
||||||
if (frame && (cctx->stage==ZSTDcs_init)) {
|
if (frame && (cctx->stage==ZSTDcs_init)) {
|
||||||
fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams,
|
fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams,
|
||||||
cctx->pledgedSrcSizePlusOne-1, cctx->dictID);
|
cctx->pledgedSrcSizePlusOne-1, cctx->dictID);
|
||||||
if (ZSTD_isError(fhSize)) return fhSize;
|
FORWARD_ERROR(fhSize);
|
||||||
dstCapacity -= fhSize;
|
dstCapacity -= fhSize;
|
||||||
dst = (char*)dst + fhSize;
|
dst = (char*)dst + fhSize;
|
||||||
cctx->stage = ZSTDcs_ongoing;
|
cctx->stage = ZSTDcs_ongoing;
|
||||||
@@ -2923,17 +2922,18 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
|
|||||||
{ size_t const cSize = frame ?
|
{ size_t const cSize = frame ?
|
||||||
ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) :
|
ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) :
|
||||||
ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize);
|
ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize);
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
cctx->consumedSrcSize += srcSize;
|
cctx->consumedSrcSize += srcSize;
|
||||||
cctx->producedCSize += (cSize + fhSize);
|
cctx->producedCSize += (cSize + fhSize);
|
||||||
assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0));
|
assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0));
|
||||||
if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */
|
if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */
|
||||||
ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
|
ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
|
||||||
if (cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne) {
|
RETURN_ERROR_IF(
|
||||||
DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize >= %u",
|
cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne,
|
||||||
(unsigned)cctx->pledgedSrcSizePlusOne-1, (unsigned)cctx->consumedSrcSize);
|
srcSize_wrong,
|
||||||
return ERROR(srcSize_wrong);
|
"error : pledgedSrcSize = %u, while realSrcSize >= %u",
|
||||||
}
|
(unsigned)cctx->pledgedSrcSizePlusOne-1,
|
||||||
|
(unsigned)cctx->consumedSrcSize);
|
||||||
}
|
}
|
||||||
return cSize + fhSize;
|
return cSize + fhSize;
|
||||||
}
|
}
|
||||||
@@ -2958,7 +2958,7 @@ size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx)
|
|||||||
size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
size_t const blockSizeMax = ZSTD_getBlockSize(cctx);
|
size_t const blockSizeMax = ZSTD_getBlockSize(cctx);
|
||||||
if (srcSize > blockSizeMax) return ERROR(srcSize_wrong);
|
RETURN_ERROR_IF(srcSize > blockSizeMax, srcSize_wrong);
|
||||||
|
|
||||||
return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 /* last chunk */);
|
return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 /* last chunk */);
|
||||||
}
|
}
|
||||||
@@ -3021,9 +3021,9 @@ static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t* ms,
|
|||||||
NOTE: This behavior is not standard and could be improved in the future. */
|
NOTE: This behavior is not standard and could be improved in the future. */
|
||||||
static size_t ZSTD_checkDictNCount(short* normalizedCounter, unsigned dictMaxSymbolValue, unsigned maxSymbolValue) {
|
static size_t ZSTD_checkDictNCount(short* normalizedCounter, unsigned dictMaxSymbolValue, unsigned maxSymbolValue) {
|
||||||
U32 s;
|
U32 s;
|
||||||
if (dictMaxSymbolValue < maxSymbolValue) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(dictMaxSymbolValue < maxSymbolValue, dictionary_corrupted);
|
||||||
for (s = 0; s <= maxSymbolValue; ++s) {
|
for (s = 0; s <= maxSymbolValue; ++s) {
|
||||||
if (normalizedCounter[s] == 0) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(normalizedCounter[s] == 0, dictionary_corrupted);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3061,15 +3061,15 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
|
|
||||||
{ unsigned maxSymbolValue = 255;
|
{ unsigned maxSymbolValue = 255;
|
||||||
size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr);
|
size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr);
|
||||||
if (HUF_isError(hufHeaderSize)) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(HUF_isError(hufHeaderSize), dictionary_corrupted);
|
||||||
if (maxSymbolValue < 255) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(maxSymbolValue < 255, dictionary_corrupted);
|
||||||
dictPtr += hufHeaderSize;
|
dictPtr += hufHeaderSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ unsigned offcodeLog;
|
{ unsigned offcodeLog;
|
||||||
size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
|
size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
|
||||||
if (FSE_isError(offcodeHeaderSize)) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(FSE_isError(offcodeHeaderSize), dictionary_corrupted);
|
||||||
if (offcodeLog > OffFSELog) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(offcodeLog > OffFSELog, dictionary_corrupted);
|
||||||
/* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */
|
/* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */
|
||||||
/* fill all offset symbols to avoid garbage at end of table */
|
/* fill all offset symbols to avoid garbage at end of table */
|
||||||
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.offcodeCTable,
|
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.offcodeCTable,
|
||||||
@@ -3082,10 +3082,10 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
{ short matchlengthNCount[MaxML+1];
|
{ short matchlengthNCount[MaxML+1];
|
||||||
unsigned matchlengthMaxValue = MaxML, matchlengthLog;
|
unsigned matchlengthMaxValue = MaxML, matchlengthLog;
|
||||||
size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr);
|
size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr);
|
||||||
if (FSE_isError(matchlengthHeaderSize)) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(FSE_isError(matchlengthHeaderSize), dictionary_corrupted);
|
||||||
if (matchlengthLog > MLFSELog) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(matchlengthLog > MLFSELog, dictionary_corrupted);
|
||||||
/* Every match length code must have non-zero probability */
|
/* Every match length code must have non-zero probability */
|
||||||
CHECK_F( ZSTD_checkDictNCount(matchlengthNCount, matchlengthMaxValue, MaxML));
|
FORWARD_ERROR( ZSTD_checkDictNCount(matchlengthNCount, matchlengthMaxValue, MaxML));
|
||||||
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.matchlengthCTable,
|
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.matchlengthCTable,
|
||||||
matchlengthNCount, matchlengthMaxValue, matchlengthLog,
|
matchlengthNCount, matchlengthMaxValue, matchlengthLog,
|
||||||
workspace, HUF_WORKSPACE_SIZE),
|
workspace, HUF_WORKSPACE_SIZE),
|
||||||
@@ -3096,10 +3096,10 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
{ short litlengthNCount[MaxLL+1];
|
{ short litlengthNCount[MaxLL+1];
|
||||||
unsigned litlengthMaxValue = MaxLL, litlengthLog;
|
unsigned litlengthMaxValue = MaxLL, litlengthLog;
|
||||||
size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr);
|
size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr);
|
||||||
if (FSE_isError(litlengthHeaderSize)) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(FSE_isError(litlengthHeaderSize), dictionary_corrupted);
|
||||||
if (litlengthLog > LLFSELog) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(litlengthLog > LLFSELog, dictionary_corrupted);
|
||||||
/* Every literal length code must have non-zero probability */
|
/* Every literal length code must have non-zero probability */
|
||||||
CHECK_F( ZSTD_checkDictNCount(litlengthNCount, litlengthMaxValue, MaxLL));
|
FORWARD_ERROR( ZSTD_checkDictNCount(litlengthNCount, litlengthMaxValue, MaxLL));
|
||||||
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.litlengthCTable,
|
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.litlengthCTable,
|
||||||
litlengthNCount, litlengthMaxValue, litlengthLog,
|
litlengthNCount, litlengthMaxValue, litlengthLog,
|
||||||
workspace, HUF_WORKSPACE_SIZE),
|
workspace, HUF_WORKSPACE_SIZE),
|
||||||
@@ -3107,7 +3107,7 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
dictPtr += litlengthHeaderSize;
|
dictPtr += litlengthHeaderSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dictPtr+12 > dictEnd) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(dictPtr+12 > dictEnd, dictionary_corrupted);
|
||||||
bs->rep[0] = MEM_readLE32(dictPtr+0);
|
bs->rep[0] = MEM_readLE32(dictPtr+0);
|
||||||
bs->rep[1] = MEM_readLE32(dictPtr+4);
|
bs->rep[1] = MEM_readLE32(dictPtr+4);
|
||||||
bs->rep[2] = MEM_readLE32(dictPtr+8);
|
bs->rep[2] = MEM_readLE32(dictPtr+8);
|
||||||
@@ -3120,19 +3120,19 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
offcodeMax = ZSTD_highbit32(maxOffset); /* Calculate minimum offset code required to represent maxOffset */
|
offcodeMax = ZSTD_highbit32(maxOffset); /* Calculate minimum offset code required to represent maxOffset */
|
||||||
}
|
}
|
||||||
/* All offset values <= dictContentSize + 128 KB must be representable */
|
/* All offset values <= dictContentSize + 128 KB must be representable */
|
||||||
CHECK_F (ZSTD_checkDictNCount(offcodeNCount, offcodeMaxValue, MIN(offcodeMax, MaxOff)));
|
FORWARD_ERROR(ZSTD_checkDictNCount(offcodeNCount, offcodeMaxValue, MIN(offcodeMax, MaxOff)));
|
||||||
/* All repCodes must be <= dictContentSize and != 0*/
|
/* All repCodes must be <= dictContentSize and != 0*/
|
||||||
{ U32 u;
|
{ U32 u;
|
||||||
for (u=0; u<3; u++) {
|
for (u=0; u<3; u++) {
|
||||||
if (bs->rep[u] == 0) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(bs->rep[u] == 0, dictionary_corrupted);
|
||||||
if (bs->rep[u] > dictContentSize) return ERROR(dictionary_corrupted);
|
RETURN_ERROR_IF(bs->rep[u] > dictContentSize, dictionary_corrupted);
|
||||||
} }
|
} }
|
||||||
|
|
||||||
bs->entropy.huf.repeatMode = HUF_repeat_valid;
|
bs->entropy.huf.repeatMode = HUF_repeat_valid;
|
||||||
bs->entropy.fse.offcode_repeatMode = FSE_repeat_valid;
|
bs->entropy.fse.offcode_repeatMode = FSE_repeat_valid;
|
||||||
bs->entropy.fse.matchlength_repeatMode = FSE_repeat_valid;
|
bs->entropy.fse.matchlength_repeatMode = FSE_repeat_valid;
|
||||||
bs->entropy.fse.litlength_repeatMode = FSE_repeat_valid;
|
bs->entropy.fse.litlength_repeatMode = FSE_repeat_valid;
|
||||||
CHECK_F(ZSTD_loadDictionaryContent(ms, params, dictPtr, dictContentSize, dtlm));
|
FORWARD_ERROR(ZSTD_loadDictionaryContent(ms, params, dictPtr, dictContentSize, dtlm));
|
||||||
return dictID;
|
return dictID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3162,8 +3162,7 @@ ZSTD_compress_insertDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
DEBUGLOG(4, "raw content dictionary detected");
|
DEBUGLOG(4, "raw content dictionary detected");
|
||||||
return ZSTD_loadDictionaryContent(ms, params, dict, dictSize, dtlm);
|
return ZSTD_loadDictionaryContent(ms, params, dict, dictSize, dtlm);
|
||||||
}
|
}
|
||||||
if (dictContentType == ZSTD_dct_fullDict)
|
RETURN_ERROR_IF(dictContentType == ZSTD_dct_fullDict, dictionary_wrong);
|
||||||
return ERROR(dictionary_wrong);
|
|
||||||
assert(0); /* impossible */
|
assert(0); /* impossible */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3190,13 +3189,13 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
|
|||||||
return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff);
|
return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_F( ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
|
FORWARD_ERROR( ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
|
||||||
ZSTDcrp_continue, zbuff) );
|
ZSTDcrp_continue, zbuff) );
|
||||||
{
|
{
|
||||||
size_t const dictID = ZSTD_compress_insertDictionary(
|
size_t const dictID = ZSTD_compress_insertDictionary(
|
||||||
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
|
cctx->blockState.prevCBlock, &cctx->blockState.matchState,
|
||||||
¶ms, dict, dictSize, dictContentType, dtlm, cctx->entropyWorkspace);
|
¶ms, dict, dictSize, dictContentType, dtlm, cctx->entropyWorkspace);
|
||||||
if (ZSTD_isError(dictID)) return dictID;
|
FORWARD_ERROR(dictID);
|
||||||
assert(dictID <= (size_t)(U32)-1);
|
assert(dictID <= (size_t)(U32)-1);
|
||||||
cctx->dictID = (U32)dictID;
|
cctx->dictID = (U32)dictID;
|
||||||
}
|
}
|
||||||
@@ -3213,7 +3212,7 @@ size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx* cctx,
|
|||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_compressBegin_advanced_internal: wlog=%u", params.cParams.windowLog);
|
DEBUGLOG(4, "ZSTD_compressBegin_advanced_internal: wlog=%u", params.cParams.windowLog);
|
||||||
/* compression parameters verification and optimization */
|
/* compression parameters verification and optimization */
|
||||||
CHECK_F( ZSTD_checkCParams(params.cParams) );
|
FORWARD_ERROR( ZSTD_checkCParams(params.cParams) );
|
||||||
return ZSTD_compressBegin_internal(cctx,
|
return ZSTD_compressBegin_internal(cctx,
|
||||||
dict, dictSize, dictContentType, dtlm,
|
dict, dictSize, dictContentType, dtlm,
|
||||||
cdict,
|
cdict,
|
||||||
@@ -3261,12 +3260,12 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
|
|||||||
size_t fhSize = 0;
|
size_t fhSize = 0;
|
||||||
|
|
||||||
DEBUGLOG(4, "ZSTD_writeEpilogue");
|
DEBUGLOG(4, "ZSTD_writeEpilogue");
|
||||||
if (cctx->stage == ZSTDcs_created) return ERROR(stage_wrong); /* init missing */
|
RETURN_ERROR_IF(cctx->stage == ZSTDcs_created, stage_wrong, "init missing");
|
||||||
|
|
||||||
/* special case : empty frame */
|
/* special case : empty frame */
|
||||||
if (cctx->stage == ZSTDcs_init) {
|
if (cctx->stage == ZSTDcs_init) {
|
||||||
fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams, 0, 0);
|
fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams, 0, 0);
|
||||||
if (ZSTD_isError(fhSize)) return fhSize;
|
FORWARD_ERROR(fhSize);
|
||||||
dstCapacity -= fhSize;
|
dstCapacity -= fhSize;
|
||||||
op += fhSize;
|
op += fhSize;
|
||||||
cctx->stage = ZSTDcs_ongoing;
|
cctx->stage = ZSTDcs_ongoing;
|
||||||
@@ -3275,7 +3274,7 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
|
|||||||
if (cctx->stage != ZSTDcs_ending) {
|
if (cctx->stage != ZSTDcs_ending) {
|
||||||
/* write one last empty block, make it the "last" block */
|
/* write one last empty block, make it the "last" block */
|
||||||
U32 const cBlockHeader24 = 1 /* last block */ + (((U32)bt_raw)<<1) + 0;
|
U32 const cBlockHeader24 = 1 /* last block */ + (((U32)bt_raw)<<1) + 0;
|
||||||
if (dstCapacity<4) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall);
|
||||||
MEM_writeLE32(op, cBlockHeader24);
|
MEM_writeLE32(op, cBlockHeader24);
|
||||||
op += ZSTD_blockHeaderSize;
|
op += ZSTD_blockHeaderSize;
|
||||||
dstCapacity -= ZSTD_blockHeaderSize;
|
dstCapacity -= ZSTD_blockHeaderSize;
|
||||||
@@ -3283,7 +3282,7 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
|
|||||||
|
|
||||||
if (cctx->appliedParams.fParams.checksumFlag) {
|
if (cctx->appliedParams.fParams.checksumFlag) {
|
||||||
U32 const checksum = (U32) XXH64_digest(&cctx->xxhState);
|
U32 const checksum = (U32) XXH64_digest(&cctx->xxhState);
|
||||||
if (dstCapacity<4) return ERROR(dstSize_tooSmall);
|
RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall);
|
||||||
DEBUGLOG(4, "ZSTD_writeEpilogue: write checksum : %08X", (unsigned)checksum);
|
DEBUGLOG(4, "ZSTD_writeEpilogue: write checksum : %08X", (unsigned)checksum);
|
||||||
MEM_writeLE32(op, checksum);
|
MEM_writeLE32(op, checksum);
|
||||||
op += 4;
|
op += 4;
|
||||||
@@ -3301,18 +3300,20 @@ size_t ZSTD_compressEnd (ZSTD_CCtx* cctx,
|
|||||||
size_t const cSize = ZSTD_compressContinue_internal(cctx,
|
size_t const cSize = ZSTD_compressContinue_internal(cctx,
|
||||||
dst, dstCapacity, src, srcSize,
|
dst, dstCapacity, src, srcSize,
|
||||||
1 /* frame mode */, 1 /* last chunk */);
|
1 /* frame mode */, 1 /* last chunk */);
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize);
|
endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize);
|
||||||
if (ZSTD_isError(endResult)) return endResult;
|
FORWARD_ERROR(endResult);
|
||||||
assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0));
|
assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0));
|
||||||
if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */
|
if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */
|
||||||
ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
|
ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
|
||||||
DEBUGLOG(4, "end of frame : controlling src size");
|
DEBUGLOG(4, "end of frame : controlling src size");
|
||||||
if (cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1) {
|
RETURN_ERROR_IF(
|
||||||
DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize = %u",
|
cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1,
|
||||||
(unsigned)cctx->pledgedSrcSizePlusOne-1, (unsigned)cctx->consumedSrcSize);
|
srcSize_wrong,
|
||||||
return ERROR(srcSize_wrong);
|
"error : pledgedSrcSize = %u, while realSrcSize = %u",
|
||||||
} }
|
(unsigned)cctx->pledgedSrcSizePlusOne-1,
|
||||||
|
(unsigned)cctx->consumedSrcSize);
|
||||||
|
}
|
||||||
return cSize + endResult;
|
return cSize + endResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3340,7 +3341,7 @@ size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx,
|
|||||||
ZSTD_parameters params)
|
ZSTD_parameters params)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_compress_advanced");
|
DEBUGLOG(4, "ZSTD_compress_advanced");
|
||||||
CHECK_F(ZSTD_checkCParams(params.cParams));
|
FORWARD_ERROR(ZSTD_checkCParams(params.cParams));
|
||||||
return ZSTD_compress_internal(cctx,
|
return ZSTD_compress_internal(cctx,
|
||||||
dst, dstCapacity,
|
dst, dstCapacity,
|
||||||
src, srcSize,
|
src, srcSize,
|
||||||
@@ -3357,7 +3358,7 @@ size_t ZSTD_compress_advanced_internal(
|
|||||||
ZSTD_CCtx_params params)
|
ZSTD_CCtx_params params)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_compress_advanced_internal (srcSize:%u)", (unsigned)srcSize);
|
DEBUGLOG(4, "ZSTD_compress_advanced_internal (srcSize:%u)", (unsigned)srcSize);
|
||||||
CHECK_F( ZSTD_compressBegin_internal(cctx,
|
FORWARD_ERROR( ZSTD_compressBegin_internal(cctx,
|
||||||
dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL,
|
dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL,
|
||||||
params, srcSize, ZSTDb_not_buffered) );
|
params, srcSize, ZSTDb_not_buffered) );
|
||||||
return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
|
return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
|
||||||
@@ -3441,7 +3442,7 @@ static size_t ZSTD_initCDict_internal(
|
|||||||
void* const internalBuffer = ZSTD_malloc(dictSize, cdict->customMem);
|
void* const internalBuffer = ZSTD_malloc(dictSize, cdict->customMem);
|
||||||
cdict->dictBuffer = internalBuffer;
|
cdict->dictBuffer = internalBuffer;
|
||||||
cdict->dictContent = internalBuffer;
|
cdict->dictContent = internalBuffer;
|
||||||
if (!internalBuffer) return ERROR(memory_allocation);
|
RETURN_ERROR_IF(!internalBuffer, memory_allocation);
|
||||||
memcpy(internalBuffer, dictBuffer, dictSize);
|
memcpy(internalBuffer, dictBuffer, dictSize);
|
||||||
}
|
}
|
||||||
cdict->dictContentSize = dictSize;
|
cdict->dictContentSize = dictSize;
|
||||||
@@ -3467,7 +3468,7 @@ static size_t ZSTD_initCDict_internal(
|
|||||||
&cdict->cBlockState, &cdict->matchState, ¶ms,
|
&cdict->cBlockState, &cdict->matchState, ¶ms,
|
||||||
cdict->dictContent, cdict->dictContentSize,
|
cdict->dictContent, cdict->dictContentSize,
|
||||||
dictContentType, ZSTD_dtlm_full, cdict->workspace);
|
dictContentType, ZSTD_dtlm_full, cdict->workspace);
|
||||||
if (ZSTD_isError(dictID)) return dictID;
|
FORWARD_ERROR(dictID);
|
||||||
assert(dictID <= (size_t)(U32)-1);
|
assert(dictID <= (size_t)(U32)-1);
|
||||||
cdict->dictID = (U32)dictID;
|
cdict->dictID = (U32)dictID;
|
||||||
}
|
}
|
||||||
@@ -3597,7 +3598,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(
|
|||||||
ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize)
|
ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_compressBegin_usingCDict_advanced");
|
DEBUGLOG(4, "ZSTD_compressBegin_usingCDict_advanced");
|
||||||
if (cdict==NULL) return ERROR(dictionary_wrong);
|
RETURN_ERROR_IF(cdict==NULL, dictionary_wrong);
|
||||||
{ ZSTD_CCtx_params params = cctx->requestedParams;
|
{ ZSTD_CCtx_params params = cctx->requestedParams;
|
||||||
params.cParams = ZSTD_getCParamsFromCDict(cdict);
|
params.cParams = ZSTD_getCParamsFromCDict(cdict);
|
||||||
/* Increase window log to fit the entire dictionary and source if the
|
/* Increase window log to fit the entire dictionary and source if the
|
||||||
@@ -3633,7 +3634,7 @@ size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
|
|||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
const ZSTD_CDict* cdict, ZSTD_frameParameters fParams)
|
const ZSTD_CDict* cdict, ZSTD_frameParameters fParams)
|
||||||
{
|
{
|
||||||
CHECK_F (ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, srcSize)); /* will check if cdict != NULL */
|
FORWARD_ERROR(ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, srcSize)); /* will check if cdict != NULL */
|
||||||
return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
|
return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3701,7 +3702,7 @@ static size_t ZSTD_resetCStream_internal(ZSTD_CStream* cctx,
|
|||||||
assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams)));
|
assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams)));
|
||||||
assert(!((dict) && (cdict))); /* either dict or cdict, not both */
|
assert(!((dict) && (cdict))); /* either dict or cdict, not both */
|
||||||
|
|
||||||
CHECK_F( ZSTD_compressBegin_internal(cctx,
|
FORWARD_ERROR( ZSTD_compressBegin_internal(cctx,
|
||||||
dict, dictSize, dictContentType, ZSTD_dtlm_fast,
|
dict, dictSize, dictContentType, ZSTD_dtlm_fast,
|
||||||
cdict,
|
cdict,
|
||||||
params, pledgedSrcSize,
|
params, pledgedSrcSize,
|
||||||
@@ -3743,16 +3744,15 @@ size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs,
|
|||||||
|
|
||||||
if (dict && dictSize >= 8) {
|
if (dict && dictSize >= 8) {
|
||||||
DEBUGLOG(4, "loading dictionary of size %u", (unsigned)dictSize);
|
DEBUGLOG(4, "loading dictionary of size %u", (unsigned)dictSize);
|
||||||
if (zcs->staticSize) { /* static CCtx : never uses malloc */
|
RETURN_ERROR_IF(
|
||||||
/* incompatible with internal cdict creation */
|
zcs->staticSize, memory_allocation,
|
||||||
return ERROR(memory_allocation);
|
"static CCtx: incompatible with internal cdict creation");
|
||||||
}
|
|
||||||
ZSTD_freeCDict(zcs->cdictLocal);
|
ZSTD_freeCDict(zcs->cdictLocal);
|
||||||
zcs->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize,
|
zcs->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize,
|
||||||
ZSTD_dlm_byCopy, ZSTD_dct_auto,
|
ZSTD_dlm_byCopy, ZSTD_dct_auto,
|
||||||
params.cParams, zcs->customMem);
|
params.cParams, zcs->customMem);
|
||||||
zcs->cdict = zcs->cdictLocal;
|
zcs->cdict = zcs->cdictLocal;
|
||||||
if (zcs->cdictLocal == NULL) return ERROR(memory_allocation);
|
RETURN_ERROR_IF(zcs->cdictLocal == NULL, memory_allocation);
|
||||||
} else {
|
} else {
|
||||||
if (cdict) {
|
if (cdict) {
|
||||||
params.cParams = ZSTD_getCParamsFromCDict(cdict); /* cParams are enforced from cdict; it includes windowLog */
|
params.cParams = ZSTD_getCParamsFromCDict(cdict); /* cParams are enforced from cdict; it includes windowLog */
|
||||||
@@ -3773,7 +3773,8 @@ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
|
|||||||
unsigned long long pledgedSrcSize)
|
unsigned long long pledgedSrcSize)
|
||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_initCStream_usingCDict_advanced");
|
DEBUGLOG(4, "ZSTD_initCStream_usingCDict_advanced");
|
||||||
if (!cdict) return ERROR(dictionary_wrong); /* cannot handle NULL cdict (does not know what to do) */
|
RETURN_ERROR_IF(!cdict, dictionary_wrong,
|
||||||
|
"cannot handle NULL cdict (does not know what to do)");
|
||||||
{ ZSTD_CCtx_params params = zcs->requestedParams;
|
{ ZSTD_CCtx_params params = zcs->requestedParams;
|
||||||
params.cParams = ZSTD_getCParamsFromCDict(cdict);
|
params.cParams = ZSTD_getCParamsFromCDict(cdict);
|
||||||
params.fParams = fParams;
|
params.fParams = fParams;
|
||||||
@@ -3802,7 +3803,7 @@ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|||||||
{
|
{
|
||||||
DEBUGLOG(4, "ZSTD_initCStream_advanced: pledgedSrcSize=%u, flag=%u",
|
DEBUGLOG(4, "ZSTD_initCStream_advanced: pledgedSrcSize=%u, flag=%u",
|
||||||
(unsigned)pledgedSrcSize, params.fParams.contentSizeFlag);
|
(unsigned)pledgedSrcSize, params.fParams.contentSizeFlag);
|
||||||
CHECK_F( ZSTD_checkCParams(params.cParams) );
|
FORWARD_ERROR( ZSTD_checkCParams(params.cParams) );
|
||||||
if ((pledgedSrcSize==0) && (params.fParams.contentSizeFlag==0)) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* for compatibility with older programs relying on this behavior. Users should now specify ZSTD_CONTENTSIZE_UNKNOWN. This line will be removed in the future. */
|
if ((pledgedSrcSize==0) && (params.fParams.contentSizeFlag==0)) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* for compatibility with older programs relying on this behavior. Users should now specify ZSTD_CONTENTSIZE_UNKNOWN. This line will be removed in the future. */
|
||||||
zcs->requestedParams = ZSTD_assignParamsToCCtxParams(zcs->requestedParams, params);
|
zcs->requestedParams = ZSTD_assignParamsToCCtxParams(zcs->requestedParams, params);
|
||||||
return ZSTD_initCStream_internal(zcs, dict, dictSize, NULL /*cdict*/, zcs->requestedParams, pledgedSrcSize);
|
return ZSTD_initCStream_internal(zcs, dict, dictSize, NULL /*cdict*/, zcs->requestedParams, pledgedSrcSize);
|
||||||
@@ -3874,8 +3875,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|||||||
switch(zcs->streamStage)
|
switch(zcs->streamStage)
|
||||||
{
|
{
|
||||||
case zcss_init:
|
case zcss_init:
|
||||||
/* call ZSTD_initCStream() first ! */
|
RETURN_ERROR(init_missing, "call ZSTD_initCStream() first!");
|
||||||
return ERROR(init_missing);
|
|
||||||
|
|
||||||
case zcss_load:
|
case zcss_load:
|
||||||
if ( (flushMode == ZSTD_e_end)
|
if ( (flushMode == ZSTD_e_end)
|
||||||
@@ -3885,7 +3885,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|||||||
size_t const cSize = ZSTD_compressEnd(zcs,
|
size_t const cSize = ZSTD_compressEnd(zcs,
|
||||||
op, oend-op, ip, iend-ip);
|
op, oend-op, ip, iend-ip);
|
||||||
DEBUGLOG(4, "ZSTD_compressEnd : cSize=%u", (unsigned)cSize);
|
DEBUGLOG(4, "ZSTD_compressEnd : cSize=%u", (unsigned)cSize);
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
ip = iend;
|
ip = iend;
|
||||||
op += cSize;
|
op += cSize;
|
||||||
zcs->frameEnded = 1;
|
zcs->frameEnded = 1;
|
||||||
@@ -3926,7 +3926,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|||||||
zcs->inBuff + zcs->inToCompress, iSize) :
|
zcs->inBuff + zcs->inToCompress, iSize) :
|
||||||
ZSTD_compressContinue(zcs, cDst, oSize,
|
ZSTD_compressContinue(zcs, cDst, oSize,
|
||||||
zcs->inBuff + zcs->inToCompress, iSize);
|
zcs->inBuff + zcs->inToCompress, iSize);
|
||||||
if (ZSTD_isError(cSize)) return cSize;
|
FORWARD_ERROR(cSize);
|
||||||
zcs->frameEnded = lastBlock;
|
zcs->frameEnded = lastBlock;
|
||||||
/* prepare next block */
|
/* prepare next block */
|
||||||
zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize;
|
zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize;
|
||||||
@@ -4002,7 +4002,7 @@ static size_t ZSTD_nextInputSizeHint_MTorST(const ZSTD_CCtx* cctx)
|
|||||||
|
|
||||||
size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input)
|
size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input)
|
||||||
{
|
{
|
||||||
CHECK_F( ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue) );
|
FORWARD_ERROR( ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue) );
|
||||||
return ZSTD_nextInputSizeHint_MTorST(zcs);
|
return ZSTD_nextInputSizeHint_MTorST(zcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4014,8 +4014,8 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
{
|
{
|
||||||
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
||||||
/* check conditions */
|
/* check conditions */
|
||||||
if (output->pos > output->size) return ERROR(GENERIC);
|
RETURN_ERROR_IF(output->pos > output->size, GENERIC);
|
||||||
if (input->pos > input->size) return ERROR(GENERIC);
|
RETURN_ERROR_IF(input->pos > input->size, GENERIC);
|
||||||
assert(cctx!=NULL);
|
assert(cctx!=NULL);
|
||||||
|
|
||||||
/* transparent initialization stage */
|
/* transparent initialization stage */
|
||||||
@@ -4040,11 +4040,11 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
DEBUGLOG(4, "ZSTD_compressStream2: creating new mtctx for nbWorkers=%u",
|
DEBUGLOG(4, "ZSTD_compressStream2: creating new mtctx for nbWorkers=%u",
|
||||||
params.nbWorkers);
|
params.nbWorkers);
|
||||||
cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbWorkers, cctx->customMem);
|
cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbWorkers, cctx->customMem);
|
||||||
if (cctx->mtctx == NULL) return ERROR(memory_allocation);
|
RETURN_ERROR_IF(cctx->mtctx == NULL, memory_allocation);
|
||||||
}
|
}
|
||||||
/* mt compression */
|
/* mt compression */
|
||||||
DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbWorkers=%u", params.nbWorkers);
|
DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbWorkers=%u", params.nbWorkers);
|
||||||
CHECK_F( ZSTDMT_initCStream_internal(
|
FORWARD_ERROR( ZSTDMT_initCStream_internal(
|
||||||
cctx->mtctx,
|
cctx->mtctx,
|
||||||
prefixDict.dict, prefixDict.dictSize, ZSTD_dct_rawContent,
|
prefixDict.dict, prefixDict.dictSize, ZSTD_dct_rawContent,
|
||||||
cctx->cdict, params, cctx->pledgedSrcSizePlusOne-1) );
|
cctx->cdict, params, cctx->pledgedSrcSizePlusOne-1) );
|
||||||
@@ -4052,7 +4052,7 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
cctx->appliedParams.nbWorkers = params.nbWorkers;
|
cctx->appliedParams.nbWorkers = params.nbWorkers;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{ CHECK_F( ZSTD_resetCStream_internal(cctx,
|
{ FORWARD_ERROR( ZSTD_resetCStream_internal(cctx,
|
||||||
prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType,
|
prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType,
|
||||||
cctx->cdict,
|
cctx->cdict,
|
||||||
params, cctx->pledgedSrcSizePlusOne-1) );
|
params, cctx->pledgedSrcSizePlusOne-1) );
|
||||||
@@ -4077,7 +4077,7 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
return flushMin;
|
return flushMin;
|
||||||
} }
|
} }
|
||||||
#endif
|
#endif
|
||||||
CHECK_F( ZSTD_compressStream_generic(cctx, output, input, endOp) );
|
FORWARD_ERROR( ZSTD_compressStream_generic(cctx, output, input, endOp) );
|
||||||
DEBUGLOG(5, "completed ZSTD_compressStream2");
|
DEBUGLOG(5, "completed ZSTD_compressStream2");
|
||||||
return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */
|
return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */
|
||||||
}
|
}
|
||||||
@@ -4108,10 +4108,10 @@ size_t ZSTD_compress2(ZSTD_CCtx* cctx,
|
|||||||
dst, dstCapacity, &oPos,
|
dst, dstCapacity, &oPos,
|
||||||
src, srcSize, &iPos,
|
src, srcSize, &iPos,
|
||||||
ZSTD_e_end);
|
ZSTD_e_end);
|
||||||
if (ZSTD_isError(result)) return result;
|
FORWARD_ERROR(result);
|
||||||
if (result != 0) { /* compression not completed, due to lack of output space */
|
if (result != 0) { /* compression not completed, due to lack of output space */
|
||||||
assert(oPos == dstCapacity);
|
assert(oPos == dstCapacity);
|
||||||
return ERROR(dstSize_tooSmall);
|
RETURN_ERROR(dstSize_tooSmall);
|
||||||
}
|
}
|
||||||
assert(iPos == srcSize); /* all input is expected consumed */
|
assert(iPos == srcSize); /* all input is expected consumed */
|
||||||
return oPos;
|
return oPos;
|
||||||
@@ -4133,7 +4133,7 @@ size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output)
|
|||||||
{
|
{
|
||||||
ZSTD_inBuffer input = { NULL, 0, 0 };
|
ZSTD_inBuffer input = { NULL, 0, 0 };
|
||||||
size_t const remainingToFlush = ZSTD_compressStream2(zcs, output, &input, ZSTD_e_end);
|
size_t const remainingToFlush = ZSTD_compressStream2(zcs, output, &input, ZSTD_e_end);
|
||||||
CHECK_F( remainingToFlush );
|
FORWARD_ERROR( remainingToFlush );
|
||||||
if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */
|
if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */
|
||||||
/* single thread mode : attempt to calculate remaining to flush more precisely */
|
/* single thread mode : attempt to calculate remaining to flush more precisely */
|
||||||
{ size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE;
|
{ size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE;
|
||||||
|
|||||||
Reference in New Issue
Block a user