From: Stella Lau Date: Fri, 18 Aug 2017 01:45:04 +0000 (-0700) Subject: Add initialization/allocation functions for opaque params X-Git-Tag: fuzz-corpora2~29^2^2~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4169f49171a6fa98baf5e62c5ff6aeb74d675fd9;p=thirdparty%2Fzstd.git Add initialization/allocation functions for opaque params --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index b5bdf680e..509f8bedc 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -230,6 +230,44 @@ static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams( return cctxParams; } +ZSTD_CCtx_params* ZSTD_createCCtxParams(void) +{ + ZSTD_CCtx_params* params = + (ZSTD_CCtx_params*)ZSTD_calloc(sizeof(ZSTD_CCtx_params), + ZSTD_defaultCMem); + if (!params) { return NULL; } + // TODO +// params->compressionLevel = ZSTD_CLEVEL_DEFAULT; + return params; +} + +size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* params, + ZSTD_compressionParameters cParams) +{ + CHECK_F( params == NULL ); + memset(params, 0, sizeof(ZSTD_CCtx_params)); + params->cParams = cParams; + return 0; +} + +ZSTD_CCtx_params* ZSTD_createAndInitCCtxParams( + int compressionLevel, unsigned long long estimatedSrcSize, + size_t dictSize) +{ + ZSTD_CCtx_params* params = ZSTD_createCCtxParams(); + if (params == NULL) { return NULL; } + ZSTD_initCCtxParams(params, ZSTD_getCParams( + compressionLevel, estimatedSrcSize, dictSize)); + return params; +} + +size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params) +{ + ZSTD_free(params, ZSTD_defaultCMem); + return 0; +} + + static ZSTD_parameters ZSTD_getParamsFromCCtx(const ZSTD_CCtx* cctx) { return ZSTD_getParamsFromCCtxParams(cctx->appliedParams); diff --git a/lib/zstd.h b/lib/zstd.h index 2111c9de0..b847d01f2 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -611,6 +611,12 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_initStaticCDict_advanced_opaque( unsigned byReference, ZSTD_dictMode_e dictMode, ZSTD_CCtx_params* params); +ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void); +ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createAndInitCCtxParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); +ZSTDLIB_API size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* params, ZSTD_compressionParameters cParams); +ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); + + /*! ZSTD_getCParams() : * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. * `estimatedSrcSize` value is optional, select 0 if not known */