]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Implemented ZSTD_CCtx_refCDict()
authorYann Collet <cyan@fb.com>
Mon, 22 May 2017 20:05:45 +0000 (13:05 -0700)
committerYann Collet <cyan@fb.com>
Mon, 22 May 2017 20:05:45 +0000 (13:05 -0700)
lib/compress/zstd_compress.c
lib/zstd.h

index 94f006257443be8870a17d1ee43e97b3f705ed35..ae49938f756b9d9a6c3f40bc32c6220b0c755247 100644 (file)
@@ -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)
index 5a0206a01c1f786497fb7eea161ed9eb63286eef..83fe9d30f66c091f4b6e67032a85f65e0258dbc8 100644 (file)
@@ -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);