]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
better consistency in accessing @input
authorYann Collet <cyan@fb.com>
Mon, 24 Jan 2022 22:45:22 +0000 (14:45 -0800)
committerYann Collet <cyan@fb.com>
Wed, 26 Jan 2022 18:31:24 +0000 (10:31 -0800)
as suggested by @terrelln.

Also : commented zstreamtest more
to ensure ZSTD_stableInBuffer is tested/

lib/compress/zstd_compress.c
tests/zstreamtest.c

index 553a0765de17f8cec9cffa01f9d8fd505b323816..7be5d87a7515f2a3568971fc1a786e1c3ca1b79c 100644 (file)
@@ -5660,7 +5660,7 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
             if (cctx->savedInPosPlusOne == 0) cctx->savedInPosPlusOne = input->pos + 1;
             cctx->expectedInBuffer = *input;
             /* pretend input was consumed, to give a sense forward progress */
-            input[0].pos = input[0].size;
+            input->pos = input->size;
             /* but actually input wasn't consumed, so keep track of position from where compression shall resume */
             cctx->expectedInBuffer.pos = cctx->savedInPosPlusOne - 1;
             /* don't initialize yet, wait for the first block of flush() order, for better parameters adaptation */
index 15a5cdb7c2ebfb07b971cd155cfcbeac37ce256b..1444d27df9a9f63e14a1139dbefb12ecc842f342 100644 (file)
@@ -769,11 +769,12 @@ static int basicUnitTests(U32 seed, double compressibility)
     }
 
     /* Compression with ZSTD_c_stable{In,Out}Buffer */
-    {   ZSTD_CCtx* cctx = ZSTD_createCCtx();
+    {   ZSTD_CCtx* const cctx = ZSTD_createCCtx();
         ZSTD_inBuffer in;
         ZSTD_outBuffer out;
         size_t cctxSize1;
         size_t cctxSize2;
+        assert(cctx != NULL);
         in.src = CNBuffer;
         in.size = CNBufferSize;
         out.dst = compressedBuffer;
@@ -784,6 +785,7 @@ static int basicUnitTests(U32 seed, double compressibility)
         CHECK(!(cSize < ZSTD_compressBound(CNBufferSize)), "cSize too large for test");
         CHECK_Z(cSize = ZSTD_compress2(cctx, compressedBuffer, cSize + 4, CNBuffer, CNBufferSize));
         CHECK_Z(cctxSize1 = ZSTD_sizeof_CCtx(cctx));
+        /* @cctxSize2 : sizeof_CCtx when doing full streaming (no stable in/out) */
         {   ZSTD_CCtx* const cctx2 = ZSTD_createCCtx();
             assert(cctx2 != NULL);
             in.pos = out.pos = 0;
@@ -792,16 +794,17 @@ static int basicUnitTests(U32 seed, double compressibility)
             CHECK_Z(cctxSize2 = ZSTD_sizeof_CCtx(cctx2));
             ZSTD_freeCCtx(cctx2);
         }
-        {   ZSTD_CCtx* const cctx3 = ZSTD_createCCtx();
+        /* @cctxSize1 : sizeof_CCtx when doing single-shot compression (no streaming) */
+        {   ZSTD_CCtx* const cctx1 = ZSTD_createCCtx();
             ZSTD_parameters params = ZSTD_getParams(0, CNBufferSize, 0);
             size_t cSize3;
-            assert(cctx3 != NULL);
+            assert(cctx1 != NULL);
             params.fParams.checksumFlag = 1;
-            cSize3 = ZSTD_compress_advanced(cctx3, compressedBuffer, compressedBufferSize, CNBuffer, CNBufferSize, NULL, 0, params);
+            cSize3 = ZSTD_compress_advanced(cctx1, compressedBuffer, compressedBufferSize, CNBuffer, CNBufferSize, NULL, 0, params);
             CHECK_Z(cSize3);
             CHECK(!(cSize == cSize3), "Must be same compressed size");
-            CHECK(!(cctxSize1 == ZSTD_sizeof_CCtx(cctx3)), "Must be same CCtx size");
-            ZSTD_freeCCtx(cctx3);
+            CHECK(!(cctxSize1 == ZSTD_sizeof_CCtx(cctx1)), "Must be same CCtx size");
+            ZSTD_freeCCtx(cctx1);
         }
         CHECK(!(cctxSize1 < cctxSize2), "Stable buffers means less allocated size");
         CHECK_Z(ZSTD_decompress(decodedBuffer, CNBufferSize, compressedBuffer, cSize));
@@ -891,8 +894,9 @@ static int basicUnitTests(U32 seed, double compressibility)
         }
         DISPLAYLEVEL(3, "OK \n");
 
-        DISPLAYLEVEL(3, "test%3i : ZSTD_compressStream2() ZSTD_c_stableInBuffer allocated size : ", testNb++);
+        DISPLAYLEVEL(3, "test%3i : ZSTD_compressStream2() with ZSTD_c_stableInBuffer: context size : ", testNb++);
         {   size_t const cctxSize = ZSTD_sizeof_CCtx(cctx);
+            DISPLAYLEVEL(4, "cctxSize1=%zu; cctxSize=%zu; cctxSize2=%zu : ", cctxSize1, cctxSize, cctxSize2);
             CHECK(!(cctxSize1 < cctxSize), "Must be bigger than single-pass");
             CHECK(!(cctxSize < cctxSize2), "Must be smaller than streaming");
             cctxSize1 = cctxSize;
@@ -925,8 +929,9 @@ static int basicUnitTests(U32 seed, double compressibility)
         }
         DISPLAYLEVEL(3, "OK \n");
 
-        DISPLAYLEVEL(3, "test%3i : ZSTD_compressStream2() ZSTD_c_stableOutBuffer allocated size : ", testNb++);
+        DISPLAYLEVEL(3, "test%3i : ZSTD_compressStream2() with ZSTD_c_stableOutBuffer: context size : ", testNb++);
         {   size_t const cctxSize = ZSTD_sizeof_CCtx(cctx);
+            DISPLAYLEVEL(4, "cctxSize1=%zu; cctxSize=%zu; cctxSize2=%zu : ", cctxSize1, cctxSize, cctxSize2);
             CHECK(!(cctxSize1 < cctxSize), "Must be bigger than single-pass and stableInBuffer");
             CHECK(!(cctxSize < cctxSize2), "Must be smaller than streaming");
         }