From 2b7f19dd9defae9c363279b966cbdc1c6edd9a1b Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 15:33:25 -0800 Subject: [PATCH 01/14] deprecate advanced streaming functions --- lib/zstd.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/zstd.h b/lib/zstd.h index 480d65f675e..91b21074eb9 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -2465,8 +2465,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx); * ZSTD_DCtx_loadDictionary(zds, dict, dictSize); * * note: no dictionary will be used if dict == NULL or dictSize < 8 - * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ +ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions") ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /*! @@ -2476,8 +2476,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const vo * ZSTD_DCtx_refDDict(zds, ddict); * * note : ddict is referenced, it must outlive decompression session - * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ +ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_refDDict, see zstd.h for detailed instructions") ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /*! @@ -2486,8 +2486,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const Z * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); * * re-use decompression parameters from previous init; saves dictionary loading - * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ +ZSTD_DEPRECATED("use ZSTD_DCtx_reset, see zstd.h for detailed instructions") ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); From 03f28cbc4a0a17e321d62fb00b8084d86fd08e59 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 15:42:42 -0800 Subject: [PATCH 02/14] remove internal usage of the deprecated functions --- lib/decompress/zstd_decompress.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index f00ef3a67ae..16f5ff2350b 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -1656,7 +1656,8 @@ size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t di size_t ZSTD_initDStream(ZSTD_DStream* zds) { DEBUGLOG(4, "ZSTD_initDStream"); - return ZSTD_initDStream_usingDDict(zds, NULL); + FORWARD_IF_ERROR(ZSTD_DCtx_reset(zds, ZSTD_reset_session_only)); + return ZSTD_DCtx_refDDict(zds, NULL); } /* ZSTD_initDStream_usingDDict() : @@ -1664,6 +1665,7 @@ size_t ZSTD_initDStream(ZSTD_DStream* zds) * this function cannot fail */ size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* dctx, const ZSTD_DDict* ddict) { + DEBUGLOG(4, "ZSTD_initDStream_usingDDict"); FORWARD_IF_ERROR( ZSTD_DCtx_reset(dctx, ZSTD_reset_session_only) , ""); FORWARD_IF_ERROR( ZSTD_DCtx_refDDict(dctx, ddict) , ""); return ZSTD_startingInputLength(dctx->format); @@ -1674,6 +1676,7 @@ size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* dctx, const ZSTD_DDict* ddict) * this function cannot fail */ size_t ZSTD_resetDStream(ZSTD_DStream* dctx) { + DEBUGLOG(4, "ZSTD_resetDStream"); FORWARD_IF_ERROR(ZSTD_DCtx_reset(dctx, ZSTD_reset_session_only), ""); return ZSTD_startingInputLength(dctx->format); } From a503ee8e32b25697343fe1f8da9552cfc007d2fd Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 15:48:21 -0800 Subject: [PATCH 03/14] nit --- lib/decompress/zstd_decompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 16f5ff2350b..2a13e54135a 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -1656,7 +1656,7 @@ size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t di size_t ZSTD_initDStream(ZSTD_DStream* zds) { DEBUGLOG(4, "ZSTD_initDStream"); - FORWARD_IF_ERROR(ZSTD_DCtx_reset(zds, ZSTD_reset_session_only)); + FORWARD_IF_ERROR(ZSTD_DCtx_reset(zds, ZSTD_reset_session_only), ""); return ZSTD_DCtx_refDDict(zds, NULL); } From c453ab68b17b5c62b583f4ad8558844b7746970f Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 17:15:37 -0800 Subject: [PATCH 04/14] suppress warnings in tests/zstreamtest.c --- tests/zstreamtest.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 664ff632ac1..3ab8bd30c44 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -126,6 +126,28 @@ static U32 FUZ_rand(U32* seedPtr) #f, ZSTD_getErrorName(err)); \ } +/* These functions are deprecated, but heavily used in zstreamtest.c. + * For now, let's use macros to suppress the compiler warning. + * At some point, we should go through and actually migrate each callsite. */ +static size_t ZSTD_initDStream_usingDict_helper(ZSTD_DStream* zds, const void* dict, size_t dictSize) { + DEBUGLOG(4, "ZSTD_initDStream_usingDict"); + FORWARD_IF_ERROR( ZSTD_DCtx_reset(zds, ZSTD_reset_session_only) , ""); + FORWARD_IF_ERROR( ZSTD_DCtx_loadDictionary(zds, dict, dictSize) , ""); + return ZSTD_startingInputLength(zds->format); +} +static size_t ZSTD_initDStream_usingDDict_helper(ZSTD_DStream* zds, const ZSTD_DDict* ddict) { + DEBUGLOG(4, "ZSTD_initDStream_usingDDict"); + FORWARD_IF_ERROR( ZSTD_DCtx_reset(dctx, ZSTD_reset_session_only) , ""); + FORWARD_IF_ERROR( ZSTD_DCtx_refDDict(dctx, ddict) , ""); + return ZSTD_startingInputLength(dctx->format); +} +#define ZSTD_initDStream_usingDict(zds, dict, dictSize) ( + ZSTD_initDStream_usingDict_helper(zds, dict, dictSize) +) +#define ZSTD_initDStream_usingDDict(zds, dict, dictSize) ( + ZSTD_initDStream_usingDDict_helper(zds, ddict) +) + /*====================================================== * Basic Unit tests From 88911ec882f5f69eca2381cf9889b19f688e2e9f Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 17:38:37 -0800 Subject: [PATCH 05/14] purge ZSTD_initDStream_usingDict --- lib/deprecated/zbuff.h | 11 +++++++---- lib/deprecated/zbuff_decompress.c | 5 ++++- programs/fileio.c | 3 ++- tests/zstreamtest.c | 2 +- zlibWrapper/examples/zwrapbench.c | 6 ++++-- zlibWrapper/zstd_zlibwrapper.c | 6 ++++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/deprecated/zbuff.h b/lib/deprecated/zbuff.h index a968245b36a..695ebbedb1f 100644 --- a/lib/deprecated/zbuff.h +++ b/lib/deprecated/zbuff.h @@ -125,7 +125,9 @@ ZBUFF_DEPRECATED("use ZSTD_createDStream") ZBUFF_DCtx* ZBUFF_createDCtx(void); ZBUFF_DEPRECATED("use ZSTD_freeDStream") size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx); ZBUFF_DEPRECATED("use ZSTD_initDStream") size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx); -ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize); + +ZBUFF_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions") +size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize); ZBUFF_DEPRECATED("use ZSTD_decompressStream") size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx, void* dst, size_t* dstCapacityPtr, @@ -200,9 +202,10 @@ ZBUFF_DEPRECATED("use ZSTD_createDStream_advanced") ZBUFF_DCtx* ZBUFF_createDCtx /*--- Advanced Streaming Initialization ---*/ -ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc, - const void* dict, size_t dictSize, - ZSTD_parameters params, unsigned long long pledgedSrcSize); +ZBUFF_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions") +size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc, + const void* dict, size_t dictSize, + ZSTD_parameters params, unsigned long long pledgedSrcSize); #endif /* ZBUFF_STATIC_H_30298098432 */ diff --git a/lib/deprecated/zbuff_decompress.c b/lib/deprecated/zbuff_decompress.c index 51159ef5318..535e0259efc 100644 --- a/lib/deprecated/zbuff_decompress.c +++ b/lib/deprecated/zbuff_decompress.c @@ -15,6 +15,7 @@ ***************************************/ #define ZBUFF_STATIC_LINKING_ONLY #include "zbuff.h" +#include "../zstd_errors.h" /* FORWARD_IF_ERROR */ ZBUFF_DCtx* ZBUFF_createDCtx(void) @@ -37,7 +38,9 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd) size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize) { - return ZSTD_initDStream_usingDict(zbd, dict, dictSize); + FORWARD_IF_ERROR( ZSTD_DCtx_reset(zbd, ZSTD_reset_session_only) , ""); + FORWARD_IF_ERROR( ZSTD_DCtx_loadDictionary(zbd, dict, dictSize) , ""); + return ZSTD_startingInputLength(zbd->format); } size_t ZBUFF_decompressInit(ZBUFF_DCtx* zbd) diff --git a/programs/fileio.c b/programs/fileio.c index 6bfa559e924..6a731b7cc23 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1994,7 +1994,8 @@ static dRess_t FIO_createDResources(FIO_prefs_t* const prefs, const char* dictFi /* dictionary */ { void* dictBuffer; size_t const dictBufferSize = FIO_createDictBuffer(&dictBuffer, dictFileName, prefs); - CHECK( ZSTD_initDStream_usingDict(ress.dctx, dictBuffer, dictBufferSize) ); + CHECK( ZSTD_DCtx_reset(ress.dctx, ZSTD_reset_session_only) ); + CHECK( ZSTD_DCtx_loadDictionary(ress.dctx, dictBuffer, dictBufferSize) ); free(dictBuffer); } diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 3ab8bd30c44..c687a085901 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -127,7 +127,7 @@ static U32 FUZ_rand(U32* seedPtr) } /* These functions are deprecated, but heavily used in zstreamtest.c. - * For now, let's use macros to suppress the compiler warning. + * For now, let's use macros to suppress the compiler warnings. * At some point, we should go through and actually migrate each callsite. */ static size_t ZSTD_initDStream_usingDict_helper(ZSTD_DStream* zds, const void* dict, size_t dictSize) { DEBUGLOG(4, "ZSTD_initDStream_usingDict"); diff --git a/zlibWrapper/examples/zwrapbench.c b/zlibWrapper/examples/zwrapbench.c index aef29be0ba8..057618ea9c3 100644 --- a/zlibWrapper/examples/zwrapbench.c +++ b/zlibWrapper/examples/zwrapbench.c @@ -428,8 +428,10 @@ static int BMK_benchMem(z_const void* srcBuffer, size_t srcSize, ZSTD_DStream* zbd = ZSTD_createDStream(); size_t rSize; if (zbd == NULL) EXM_THROW(1, "ZSTD_createDStream() allocation failure"); - rSize = ZSTD_initDStream_usingDict(zbd, dictBuffer, dictBufferSize); - if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_initDStream() failed : %s", ZSTD_getErrorName(rSize)); + rSize = ZSTD_DCtx_reset(zbd, ZSTD_reset_session_only); + if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_DCtx_reset() failed : %s", ZSTD_getErrorName(rSize)); + rsize = ZSTD_DCtx_loadDictionary(zbd, dictBuffer, dictBufferSize); + if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_DCtx_loadDictionary() failed : %s", ZSTD_getErrorName(rSize)); do { U32 blockNb; for (blockNb=0; blockNbstate; if (zwd == NULL || zwd->zbd == NULL) return Z_STREAM_ERROR; - { size_t const initErr = ZSTD_initDStream_usingDict(zwd->zbd, dictionary, dictLength); - if (ZSTD_isError(initErr)) return ZWRAPD_finishWithError(zwd, strm, 0); } + { size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only); + if (ZSTD_isError(resetErr)) return ZWRAPD_finishWithError(zwd, strm, 0); } + { size_t const loadErr = ZSTD_DCtx_loadDictionary(zwd->zbd, dictionary, dictLength); + if (ZSTD_isError(loadErr)) return ZWRAPD_finishWithError(zwd, strm, 0); } zwd->decompState = ZWRAP_useReset; if (zwd->totalInBytes == ZSTD_HEADERSIZE) { From 6d8b69ade14eb7fe56f9563ac1b58ed549633292 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 17:47:45 -0800 Subject: [PATCH 06/14] nits --- tests/zstreamtest.c | 21 ++++++++++++++++----- zlibWrapper/examples/zwrapbench.c | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index c687a085901..af767c75929 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -126,19 +126,30 @@ static U32 FUZ_rand(U32* seedPtr) #f, ZSTD_getErrorName(err)); \ } -/* These functions are deprecated, but heavily used in zstreamtest.c. +/* The initDStream_using* functions are deprecated, but heavily used in zstreamtest.c. * For now, let's use macros to suppress the compiler warnings. * At some point, we should go through and actually migrate each callsite. */ +static size_t ZSTD_startingInputLength(ZSTD_format_e format) +{ + size_t const startingInputLength = ZSTD_FRAMEHEADERSIZE_PREFIX(format); + /* only supports formats ZSTD_f_zstd1 and ZSTD_f_zstd1_magicless */ + assert( (format == ZSTD_f_zstd1) || (format == ZSTD_f_zstd1_magicless) ); + return startingInputLength; +} static size_t ZSTD_initDStream_usingDict_helper(ZSTD_DStream* zds, const void* dict, size_t dictSize) { DEBUGLOG(4, "ZSTD_initDStream_usingDict"); - FORWARD_IF_ERROR( ZSTD_DCtx_reset(zds, ZSTD_reset_session_only) , ""); - FORWARD_IF_ERROR( ZSTD_DCtx_loadDictionary(zds, dict, dictSize) , ""); + const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); + if (ZSTD_isError(resetRes)) return resetRes; + const size_t loadRes = ZSTD_DCtx_loadDictionary(zds, dict, dictSize); + if (ZSTD_isError(loadRes)) return loadRes; return ZSTD_startingInputLength(zds->format); } static size_t ZSTD_initDStream_usingDDict_helper(ZSTD_DStream* zds, const ZSTD_DDict* ddict) { DEBUGLOG(4, "ZSTD_initDStream_usingDDict"); - FORWARD_IF_ERROR( ZSTD_DCtx_reset(dctx, ZSTD_reset_session_only) , ""); - FORWARD_IF_ERROR( ZSTD_DCtx_refDDict(dctx, ddict) , ""); + const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); + if (ZSTD_isError(resetRes)) return resetRes; + const size_t refRes = ZSTD_DCtx_refDDict(zds, ddict); + if (ZSTD_isError(refRes)) return refRes; return ZSTD_startingInputLength(dctx->format); } #define ZSTD_initDStream_usingDict(zds, dict, dictSize) ( diff --git a/zlibWrapper/examples/zwrapbench.c b/zlibWrapper/examples/zwrapbench.c index 057618ea9c3..3bc9a1ab0b8 100644 --- a/zlibWrapper/examples/zwrapbench.c +++ b/zlibWrapper/examples/zwrapbench.c @@ -430,7 +430,7 @@ static int BMK_benchMem(z_const void* srcBuffer, size_t srcSize, if (zbd == NULL) EXM_THROW(1, "ZSTD_createDStream() allocation failure"); rSize = ZSTD_DCtx_reset(zbd, ZSTD_reset_session_only); if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_DCtx_reset() failed : %s", ZSTD_getErrorName(rSize)); - rsize = ZSTD_DCtx_loadDictionary(zbd, dictBuffer, dictBufferSize); + rSize = ZSTD_DCtx_loadDictionary(zbd, dictBuffer, dictBufferSize); if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_DCtx_loadDictionary() failed : %s", ZSTD_getErrorName(rSize)); do { U32 blockNb; From 1e4331dca6606e8234fe26e0b505110fc726afc8 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 4 Jan 2023 17:50:00 -0800 Subject: [PATCH 07/14] c90 compat --- tests/zstreamtest.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index af767c75929..16b264774c7 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -138,18 +138,18 @@ static size_t ZSTD_startingInputLength(ZSTD_format_e format) } static size_t ZSTD_initDStream_usingDict_helper(ZSTD_DStream* zds, const void* dict, size_t dictSize) { DEBUGLOG(4, "ZSTD_initDStream_usingDict"); - const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); - if (ZSTD_isError(resetRes)) return resetRes; - const size_t loadRes = ZSTD_DCtx_loadDictionary(zds, dict, dictSize); - if (ZSTD_isError(loadRes)) return loadRes; + { const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); + if (ZSTD_isError(resetRes)) return resetRes; } + { const size_t loadRes = ZSTD_DCtx_loadDictionary(zds, dict, dictSize); + if (ZSTD_isError(loadRes)) return loadRes; } return ZSTD_startingInputLength(zds->format); } static size_t ZSTD_initDStream_usingDDict_helper(ZSTD_DStream* zds, const ZSTD_DDict* ddict) { DEBUGLOG(4, "ZSTD_initDStream_usingDDict"); - const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); - if (ZSTD_isError(resetRes)) return resetRes; - const size_t refRes = ZSTD_DCtx_refDDict(zds, ddict); - if (ZSTD_isError(refRes)) return refRes; + { const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); + if (ZSTD_isError(resetRes)) return resetRes; } + { const size_t refRes = ZSTD_DCtx_refDDict(zds, ddict); + if (ZSTD_isError(refRes)) return refRes; } return ZSTD_startingInputLength(dctx->format); } #define ZSTD_initDStream_usingDict(zds, dict, dictSize) ( From d0783375b079c0244cd0499de25273ef9636239f Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Thu, 5 Jan 2023 12:24:32 -0800 Subject: [PATCH 08/14] zstreamtest.c already disables deprecation warnings! --- tests/zstreamtest.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 16b264774c7..664ff632ac1 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -126,39 +126,6 @@ static U32 FUZ_rand(U32* seedPtr) #f, ZSTD_getErrorName(err)); \ } -/* The initDStream_using* functions are deprecated, but heavily used in zstreamtest.c. - * For now, let's use macros to suppress the compiler warnings. - * At some point, we should go through and actually migrate each callsite. */ -static size_t ZSTD_startingInputLength(ZSTD_format_e format) -{ - size_t const startingInputLength = ZSTD_FRAMEHEADERSIZE_PREFIX(format); - /* only supports formats ZSTD_f_zstd1 and ZSTD_f_zstd1_magicless */ - assert( (format == ZSTD_f_zstd1) || (format == ZSTD_f_zstd1_magicless) ); - return startingInputLength; -} -static size_t ZSTD_initDStream_usingDict_helper(ZSTD_DStream* zds, const void* dict, size_t dictSize) { - DEBUGLOG(4, "ZSTD_initDStream_usingDict"); - { const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); - if (ZSTD_isError(resetRes)) return resetRes; } - { const size_t loadRes = ZSTD_DCtx_loadDictionary(zds, dict, dictSize); - if (ZSTD_isError(loadRes)) return loadRes; } - return ZSTD_startingInputLength(zds->format); -} -static size_t ZSTD_initDStream_usingDDict_helper(ZSTD_DStream* zds, const ZSTD_DDict* ddict) { - DEBUGLOG(4, "ZSTD_initDStream_usingDDict"); - { const size_t resetRes = ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); - if (ZSTD_isError(resetRes)) return resetRes; } - { const size_t refRes = ZSTD_DCtx_refDDict(zds, ddict); - if (ZSTD_isError(refRes)) return refRes; } - return ZSTD_startingInputLength(dctx->format); -} -#define ZSTD_initDStream_usingDict(zds, dict, dictSize) ( - ZSTD_initDStream_usingDict_helper(zds, dict, dictSize) -) -#define ZSTD_initDStream_usingDDict(zds, dict, dictSize) ( - ZSTD_initDStream_usingDDict_helper(zds, ddict) -) - /*====================================================== * Basic Unit tests From aca0ab62483bed74010195a74a7232d328551599 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Thu, 5 Jan 2023 12:26:20 -0800 Subject: [PATCH 09/14] fix initDStream() return value --- lib/decompress/zstd_decompress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 2a13e54135a..6cf7e5df533 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -1657,7 +1657,8 @@ size_t ZSTD_initDStream(ZSTD_DStream* zds) { DEBUGLOG(4, "ZSTD_initDStream"); FORWARD_IF_ERROR(ZSTD_DCtx_reset(zds, ZSTD_reset_session_only), ""); - return ZSTD_DCtx_refDDict(zds, NULL); + FORWARD_IF_ERROR(ZSTD_DCtx_refDDict(zds, NULL, ""); + return ZSTD_startingInputLength(zds->format); } /* ZSTD_initDStream_usingDDict() : From 6362261613624e2fdfe4711c2fad22d85e8b2a4b Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Thu, 5 Jan 2023 13:52:40 -0800 Subject: [PATCH 10/14] fix typo --- lib/decompress/zstd_decompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 6cf7e5df533..c04bf42f49b 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -1657,7 +1657,7 @@ size_t ZSTD_initDStream(ZSTD_DStream* zds) { DEBUGLOG(4, "ZSTD_initDStream"); FORWARD_IF_ERROR(ZSTD_DCtx_reset(zds, ZSTD_reset_session_only), ""); - FORWARD_IF_ERROR(ZSTD_DCtx_refDDict(zds, NULL, ""); + FORWARD_IF_ERROR(ZSTD_DCtx_refDDict(zds, NULL), ""); return ZSTD_startingInputLength(zds->format); } From 6d33be966d68fe9e7b85f740137efbd925489261 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Thu, 5 Jan 2023 14:04:44 -0800 Subject: [PATCH 11/14] wasn't able to import private symbol properly, this commit works around that --- lib/deprecated/zbuff_decompress.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/deprecated/zbuff_decompress.c b/lib/deprecated/zbuff_decompress.c index 535e0259efc..a5c988382ae 100644 --- a/lib/deprecated/zbuff_decompress.c +++ b/lib/deprecated/zbuff_decompress.c @@ -15,7 +15,6 @@ ***************************************/ #define ZBUFF_STATIC_LINKING_ONLY #include "zbuff.h" -#include "../zstd_errors.h" /* FORWARD_IF_ERROR */ ZBUFF_DCtx* ZBUFF_createDCtx(void) @@ -38,8 +37,10 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd) size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize) { - FORWARD_IF_ERROR( ZSTD_DCtx_reset(zbd, ZSTD_reset_session_only) , ""); - FORWARD_IF_ERROR( ZSTD_DCtx_loadDictionary(zbd, dict, dictSize) , ""); + { const size_t resetRet = ZSTD_DCtx_reset(zbd, ZSTD_reset_session_only); + if (ZSTD_isError(resetRet)) return resetRet; } + { const size_t loadRet = ZSTD_DCtx_loadDictionary(zbd, dict, dictSize); + if (ZSTD_isError(loadRet)) return loadRet; } return ZSTD_startingInputLength(zbd->format); } From d12f695004a441845a815df151e062ef344fe7aa Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 11 Jan 2023 13:17:31 -0800 Subject: [PATCH 12/14] new strategy for zbuff --- lib/deprecated/zbuff.h | 1 + lib/deprecated/zbuff_decompress.c | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/deprecated/zbuff.h b/lib/deprecated/zbuff.h index 695ebbedb1f..0cafd905d25 100644 --- a/lib/deprecated/zbuff.h +++ b/lib/deprecated/zbuff.h @@ -28,6 +28,7 @@ extern "C" { * Dependencies ***************************************/ #include /* size_t */ +#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* zbuff_decompress.c depends on deprecated zstd functions */ #include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */ diff --git a/lib/deprecated/zbuff_decompress.c b/lib/deprecated/zbuff_decompress.c index a5c988382ae..51159ef5318 100644 --- a/lib/deprecated/zbuff_decompress.c +++ b/lib/deprecated/zbuff_decompress.c @@ -37,11 +37,7 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd) size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize) { - { const size_t resetRet = ZSTD_DCtx_reset(zbd, ZSTD_reset_session_only); - if (ZSTD_isError(resetRet)) return resetRet; } - { const size_t loadRet = ZSTD_DCtx_loadDictionary(zbd, dict, dictSize); - if (ZSTD_isError(loadRet)) return loadRet; } - return ZSTD_startingInputLength(zbd->format); + return ZSTD_initDStream_usingDict(zbd, dict, dictSize); } size_t ZBUFF_decompressInit(ZBUFF_DCtx* zbd) From b103bd7cb1c89bde3aca314a0eb495990265c833 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Wed, 11 Jan 2023 14:32:57 -0800 Subject: [PATCH 13/14] undo zbuff deprecation warning changes --- lib/deprecated/zbuff.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/deprecated/zbuff.h b/lib/deprecated/zbuff.h index 0cafd905d25..d0b397d2663 100644 --- a/lib/deprecated/zbuff.h +++ b/lib/deprecated/zbuff.h @@ -126,9 +126,7 @@ ZBUFF_DEPRECATED("use ZSTD_createDStream") ZBUFF_DCtx* ZBUFF_createDCtx(void); ZBUFF_DEPRECATED("use ZSTD_freeDStream") size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx); ZBUFF_DEPRECATED("use ZSTD_initDStream") size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx); - -ZBUFF_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions") -size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize); +ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize); ZBUFF_DEPRECATED("use ZSTD_decompressStream") size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx, void* dst, size_t* dstCapacityPtr, @@ -203,10 +201,9 @@ ZBUFF_DEPRECATED("use ZSTD_createDStream_advanced") ZBUFF_DCtx* ZBUFF_createDCtx /*--- Advanced Streaming Initialization ---*/ -ZBUFF_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions") -size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc, - const void* dict, size_t dictSize, - ZSTD_parameters params, unsigned long long pledgedSrcSize); +ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc, + const void* dict, size_t dictSize, + ZSTD_parameters params, unsigned long long pledgedSrcSize); #endif /* ZBUFF_STATIC_H_30298098432 */ From 870e52de9afa0b429229dea5f4f2e5d338a76906 Mon Sep 17 00:00:00 2001 From: Elliot Gorokhovsky Date: Thu, 12 Jan 2023 07:13:18 -0800 Subject: [PATCH 14/14] move ZSTD_DISABLE_DEPRECATE_WARNINGS from .h to .c --- lib/deprecated/zbuff.h | 1 - lib/deprecated/zbuff_decompress.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/deprecated/zbuff.h b/lib/deprecated/zbuff.h index d0b397d2663..a968245b36a 100644 --- a/lib/deprecated/zbuff.h +++ b/lib/deprecated/zbuff.h @@ -28,7 +28,6 @@ extern "C" { * Dependencies ***************************************/ #include /* size_t */ -#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* zbuff_decompress.c depends on deprecated zstd functions */ #include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */ diff --git a/lib/deprecated/zbuff_decompress.c b/lib/deprecated/zbuff_decompress.c index 51159ef5318..12a66af7412 100644 --- a/lib/deprecated/zbuff_decompress.c +++ b/lib/deprecated/zbuff_decompress.c @@ -13,6 +13,8 @@ /* ************************************* * Dependencies ***************************************/ +#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* suppress warning on ZSTD_initDStream_usingDict */ +#include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */ #define ZBUFF_STATIC_LINKING_ONLY #include "zbuff.h"