]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
ZSTD_decompressDCtx() is compatible with sticky parameters
authorYann Collet <cyan@fb.com>
Wed, 5 Dec 2018 01:30:58 +0000 (17:30 -0800)
committerYann Collet <cyan@fb.com>
Wed, 5 Dec 2018 01:30:58 +0000 (17:30 -0800)
lib/zstd.h
tests/fuzzer.c
tests/zstreamtest.c

index 4c4a7cd09d80dc4e719fdd4ee26bdf517735a0b2..ed97603fa837c9ccc5244e4eb1e6c936102b5265 100644 (file)
@@ -168,7 +168,7 @@ ZSTDLIB_API size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
 
 /*! ZSTD_compressCCtx() :
  *  Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */
-ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx,
+ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
                                      void* dst, size_t dstCapacity,
                                const void* src, size_t srcSize,
                                      int compressionLevel);
@@ -184,8 +184,11 @@ ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
 ZSTDLIB_API size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
 
 /*! ZSTD_decompressDCtx() :
- *  Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) */
-ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx,
+ *  Same as ZSTD_decompress(),
+ *  requires an allocated ZSTD_DCtx.
+ *  Compatible with sticky parameters.
+ */
+ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
                                        void* dst, size_t dstCapacity,
                                  const void* src, size_t srcSize);
 
@@ -799,11 +802,11 @@ ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
 /* ============================== */
 
 /* The advanced API pushes parameters one by one into an existing DCtx context.
- * Parameters are "sticky, and remain valid for all futures decompression jobs
- * started with the same DCtx context.
+ * Parameters are sticky, and remain valid for all following decompression jobs
+ * using the same DCtx context.
  * It's possible to reset parameters to default values using ZSTD_DCtx_reset().
- * Note : No new decompression function is provided,
- * use existing ZSTD_decompressDCtx() and ZSTD_decompressStream().
+ * Note : This API is compatible with existing ZSTD_decompressDCtx() and ZSTD_decompressStream().
+ *        Therefore, no new decompression function is necessary.
  */
 
 
index d3eef32adf30019ef2f3de861f1003a129bb82ef..5a2c4a09c250e4b8300515ce4392e3ebb14d0e0e 100644 (file)
@@ -1398,13 +1398,19 @@ static int basicUnitTests(U32 seed, double compressibility)
             size_t const zfhrt = ZSTD_getFrameHeader_advanced(&zfh, compressedBuffer, cSize, ZSTD_f_zstd1_magicless);
             if (zfhrt != 0) goto _output_error;
         }
+        /* one shot */
+        {   size_t const result = ZSTD_decompressDCtx(dctx, decodedBuffer, CNBuffSize, compressedBuffer, cSize);
+            if (result != inputSize) goto _output_error;
+            DISPLAYLEVEL(3, "one-shot OK, ");
+        }
+        /* streaming */
         {   ZSTD_inBuffer in = { compressedBuffer, cSize, 0 };
             ZSTD_outBuffer out = { decodedBuffer, CNBuffSize, 0 };
             size_t const result = ZSTD_decompressStream(dctx, &out, &in);
             if (result != 0) goto _output_error;
             if (in.pos != in.size) goto _output_error;
             if (out.pos != inputSize) goto _output_error;
-            DISPLAYLEVEL(3, "OK : regenerated %u bytes \n", (U32)out.pos);
+            DISPLAYLEVEL(3, "streaming OK : regenerated %u bytes \n", (U32)out.pos);
         }
 
         ZSTD_freeCCtx(cctx);
index 19cf7cd7fed451717d53b5f13d98c97b2386d92e..7b640524b8bbf655a0a2deb5a1a39363889d1ea0 100644 (file)
@@ -379,7 +379,7 @@ static int basicUnitTests(U32 seed, double compressibility)
     inBuff2 = inBuff;
     DISPLAYLEVEL(3, "test%3i : decompress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
     ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
-    CHECK_Z( ZSTD_DCtx_setMaxWindowSize(zd, 1000000000) );  /* large limit */
+    CHECK_Z( ZSTD_DCtx_setParameter(zd, ZSTD_d_windowLogMax, ZSTD_WINDOWLOG_LIMIT_DEFAULT+1) );  /* large limit */
     { size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inBuff);
       if (remaining != 0) goto _output_error; }  /* should reach end of frame == 0; otherwise, some data left, or an error */
     if (outBuff.pos != CNBufferSize) goto _output_error;   /* should regenerate the same amount */
@@ -652,7 +652,7 @@ static int basicUnitTests(U32 seed, double compressibility)
     /* Memory restriction */
     DISPLAYLEVEL(3, "test%3i : maxWindowSize < frame requirement : ", testNb++);
     ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
-    CHECK_Z( ZSTD_DCtx_setMaxWindowSize(zd, 1000) );  /* too small limit */
+    CHECK_Z( ZSTD_DCtx_setParameter(zd, ZSTD_d_windowLogMax, 10) );  /* too small limit */
     outBuff.dst = decodedBuffer;
     outBuff.size = CNBufferSize;
     outBuff.pos = 0;
@@ -934,7 +934,7 @@ static int basicUnitTests(U32 seed, double compressibility)
         ZSTD_resetDStream(zd);
         CHECK_Z(ZSTD_CCtx_refCDict(zc, cdict));
         CHECK_Z(ZSTD_initDStream_usingDDict(zd, ddict));
-        CHECK_Z(ZSTD_DCtx_setMaxWindowSize(zd, 1U << kMaxWindowLog));
+        CHECK_Z(ZSTD_DCtx_setParameter(zd, ZSTD_d_windowLogMax, kMaxWindowLog));
         /* Test all values < 300 */
         for (value = 0; value < 300; ++value) {
             for (type = (SEQ_gen_type)0; type < SEQ_gen_max; ++type) {