From 24de7b0346c0bf867482af0c4d987164453d1970 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 22 May 2017 13:05:45 -0700 Subject: [PATCH] Implemented ZSTD_CCtx_refCDict() --- lib/compress/zstd_compress.c | 14 ++++++-------- lib/zstd.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 94f00625..ae49938f 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -228,9 +228,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v return ERROR(compressionParameter_unsupported); \ } } - if (cctx->streamStage != zcss_init) { - return ERROR(stage_wrong); - } + if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); switch(param) { @@ -326,14 +324,14 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize) { + if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); cctx->frameContentSize = pledgedSrcSize; return 0; } ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize) { - DEBUGLOG(5, "ZSTD_CCtx_loadDictionary : dictSize = %u", - (unsigned)dictSize); + if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); ZSTD_freeCDict(cctx->cdictLocal); /* in case one already exists */ if (dict==NULL || dictSize==0) { /* no dictionary mode */ cctx->cdictLocal = NULL; @@ -358,13 +356,14 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, s ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize) { (void)cctx; (void)prefix; (void)prefixSize; /* to be done later */ + if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); return ERROR(compressionParameter_unsupported); } -/* Not ready yet ! */ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) { - (void)cctx; (void)cdict; /* to be done later */ + if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); + cctx->cdict = cdict; return ERROR(compressionParameter_unsupported); } @@ -384,7 +383,6 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams) return 0; } - /** ZSTD_cycleLog() : * condition for correct operation : hashLog > 1 */ static U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat) diff --git a/lib/zstd.h b/lib/zstd.h index 5a0206a0..83fe9d30 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -746,7 +746,7 @@ ZSTDLIB_API size_t ZSTD_CDict_loadDictionary(ZSTD_CDict* cdict, const void* dict * Adding a new dictionary effectively "discards" any previous one. * Note 2 : CDict is just referenced, its lifetime must outlive CCtx. */ -ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /* Not ready yet ! */ +ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);