extzstd 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja.md +8 -0
  3. data/README.md +1 -1
  4. data/contrib/zstd/CHANGELOG +94 -0
  5. data/contrib/zstd/CONTRIBUTING.md +351 -1
  6. data/contrib/zstd/Makefile +32 -10
  7. data/contrib/zstd/README.md +33 -10
  8. data/contrib/zstd/TESTING.md +2 -2
  9. data/contrib/zstd/appveyor.yml +42 -4
  10. data/contrib/zstd/lib/Makefile +128 -60
  11. data/contrib/zstd/lib/README.md +47 -16
  12. data/contrib/zstd/lib/common/bitstream.h +38 -39
  13. data/contrib/zstd/lib/common/compiler.h +40 -5
  14. data/contrib/zstd/lib/common/cpu.h +1 -1
  15. data/contrib/zstd/lib/common/debug.c +11 -31
  16. data/contrib/zstd/lib/common/debug.h +11 -31
  17. data/contrib/zstd/lib/common/entropy_common.c +13 -33
  18. data/contrib/zstd/lib/common/error_private.c +2 -1
  19. data/contrib/zstd/lib/common/error_private.h +6 -2
  20. data/contrib/zstd/lib/common/fse.h +12 -32
  21. data/contrib/zstd/lib/common/fse_decompress.c +12 -35
  22. data/contrib/zstd/lib/common/huf.h +15 -33
  23. data/contrib/zstd/lib/common/mem.h +75 -2
  24. data/contrib/zstd/lib/common/pool.c +8 -4
  25. data/contrib/zstd/lib/common/pool.h +2 -2
  26. data/contrib/zstd/lib/common/threading.c +50 -4
  27. data/contrib/zstd/lib/common/threading.h +36 -4
  28. data/contrib/zstd/lib/common/xxhash.c +23 -35
  29. data/contrib/zstd/lib/common/xxhash.h +11 -31
  30. data/contrib/zstd/lib/common/zstd_common.c +1 -1
  31. data/contrib/zstd/lib/common/zstd_errors.h +2 -1
  32. data/contrib/zstd/lib/common/zstd_internal.h +154 -26
  33. data/contrib/zstd/lib/compress/fse_compress.c +17 -40
  34. data/contrib/zstd/lib/compress/hist.c +15 -35
  35. data/contrib/zstd/lib/compress/hist.h +12 -32
  36. data/contrib/zstd/lib/compress/huf_compress.c +92 -92
  37. data/contrib/zstd/lib/compress/zstd_compress.c +1191 -1330
  38. data/contrib/zstd/lib/compress/zstd_compress_internal.h +317 -55
  39. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  40. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  41. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  45. data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
  46. data/contrib/zstd/lib/compress/zstd_double_fast.c +65 -43
  47. data/contrib/zstd/lib/compress/zstd_double_fast.h +2 -2
  48. data/contrib/zstd/lib/compress/zstd_fast.c +92 -66
  49. data/contrib/zstd/lib/compress/zstd_fast.h +2 -2
  50. data/contrib/zstd/lib/compress/zstd_lazy.c +74 -42
  51. data/contrib/zstd/lib/compress/zstd_lazy.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_ldm.c +32 -10
  53. data/contrib/zstd/lib/compress/zstd_ldm.h +7 -2
  54. data/contrib/zstd/lib/compress/zstd_opt.c +81 -114
  55. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  56. data/contrib/zstd/lib/compress/zstdmt_compress.c +95 -51
  57. data/contrib/zstd/lib/compress/zstdmt_compress.h +3 -2
  58. data/contrib/zstd/lib/decompress/huf_decompress.c +76 -60
  59. data/contrib/zstd/lib/decompress/zstd_ddict.c +12 -8
  60. data/contrib/zstd/lib/decompress/zstd_ddict.h +2 -2
  61. data/contrib/zstd/lib/decompress/zstd_decompress.c +292 -172
  62. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +459 -338
  63. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +3 -3
  64. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +18 -4
  65. data/contrib/zstd/lib/deprecated/zbuff.h +9 -8
  66. data/contrib/zstd/lib/deprecated/zbuff_common.c +2 -2
  67. data/contrib/zstd/lib/deprecated/zbuff_compress.c +1 -1
  68. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +1 -1
  69. data/contrib/zstd/lib/dictBuilder/cover.c +164 -54
  70. data/contrib/zstd/lib/dictBuilder/cover.h +52 -7
  71. data/contrib/zstd/lib/dictBuilder/fastcover.c +60 -43
  72. data/contrib/zstd/lib/dictBuilder/zdict.c +43 -19
  73. data/contrib/zstd/lib/dictBuilder/zdict.h +56 -28
  74. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -4
  75. data/contrib/zstd/lib/legacy/zstd_v01.c +110 -110
  76. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  77. data/contrib/zstd/lib/legacy/zstd_v02.c +23 -13
  78. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  79. data/contrib/zstd/lib/legacy/zstd_v03.c +23 -13
  80. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  81. data/contrib/zstd/lib/legacy/zstd_v04.c +30 -17
  82. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  83. data/contrib/zstd/lib/legacy/zstd_v05.c +113 -102
  84. data/contrib/zstd/lib/legacy/zstd_v05.h +2 -2
  85. data/contrib/zstd/lib/legacy/zstd_v06.c +20 -18
  86. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  87. data/contrib/zstd/lib/legacy/zstd_v07.c +25 -19
  88. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  89. data/contrib/zstd/lib/libzstd.pc.in +3 -2
  90. data/contrib/zstd/lib/zstd.h +265 -88
  91. data/ext/extzstd.h +1 -1
  92. data/ext/libzstd_conf.h +8 -0
  93. data/ext/zstd_common.c +1 -3
  94. data/ext/zstd_compress.c +3 -3
  95. data/ext/zstd_decompress.c +1 -5
  96. data/ext/zstd_dictbuilder.c +2 -3
  97. data/ext/zstd_dictbuilder_fastcover.c +1 -3
  98. data/ext/zstd_legacy_v01.c +2 -0
  99. data/ext/zstd_legacy_v02.c +2 -0
  100. data/ext/zstd_legacy_v03.c +2 -0
  101. data/ext/zstd_legacy_v04.c +2 -0
  102. data/ext/zstd_legacy_v05.c +2 -0
  103. data/ext/zstd_legacy_v06.c +2 -0
  104. data/ext/zstd_legacy_v07.c +2 -0
  105. data/lib/extzstd.rb +18 -10
  106. data/lib/extzstd/version.rb +1 -1
  107. metadata +15 -6
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -19,7 +19,7 @@ extern "C" {
19
19
  * Dependencies
20
20
  ***************************************/
21
21
  #include <stddef.h> /* size_t */
22
- #include "mem.h" /* U64, U32 */
22
+ #include "../common/mem.h" /* U64, U32 */
23
23
 
24
24
 
25
25
  /* *************************************
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -14,7 +14,7 @@
14
14
  #include <stddef.h> /* size_t, ptrdiff_t */
15
15
  #include <string.h> /* memcpy */
16
16
  #include <stdlib.h> /* malloc, free, qsort */
17
- #include "error_private.h"
17
+ #include "../common/error_private.h"
18
18
 
19
19
 
20
20
 
@@ -860,7 +860,7 @@ MEM_STATIC unsigned BITv06_highbit32 ( U32 val)
860
860
  _BitScanReverse ( &r, val );
861
861
  return (unsigned) r;
862
862
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
863
- return 31 - __builtin_clz (val);
863
+ return __builtin_clz (val) ^ 31;
864
864
  # else /* Software version */
865
865
  static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
866
866
  U32 v = val;
@@ -1862,7 +1862,7 @@ MEM_STATIC size_t HUFv06_readStats(BYTE* huffWeight, size_t hwSize, U32* rankSta
1862
1862
 
1863
1863
  if (!srcSize) return ERROR(srcSize_wrong);
1864
1864
  iSize = ip[0];
1865
- //memset(huffWeight, 0, hwSize); /* is not necessary, even though some analyzer complain ... */
1865
+ /* memset(huffWeight, 0, hwSize); */ /* is not necessary, even though some analyzer complain ... */
1866
1866
 
1867
1867
  if (iSize >= 128) { /* special header */
1868
1868
  if (iSize >= (242)) { /* RLE */
@@ -2014,7 +2014,7 @@ size_t HUFv06_readDTableX2 (U16* DTable, const void* src, size_t srcSize)
2014
2014
  HUFv06_DEltX2* const dt = (HUFv06_DEltX2*)dtPtr;
2015
2015
 
2016
2016
  HUFv06_STATIC_ASSERT(sizeof(HUFv06_DEltX2) == sizeof(U16)); /* if compilation fails here, assertion is false */
2017
- //memset(huffWeight, 0, sizeof(huffWeight)); /* is not necessary, even though some analyzer complain ... */
2017
+ /* memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */
2018
2018
 
2019
2019
  iSize = HUFv06_readStats(huffWeight, HUFv06_MAX_SYMBOL_VALUE + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
2020
2020
  if (HUFv06_isError(iSize)) return iSize;
@@ -2340,7 +2340,7 @@ size_t HUFv06_readDTableX4 (U32* DTable, const void* src, size_t srcSize)
2340
2340
 
2341
2341
  HUFv06_STATIC_ASSERT(sizeof(HUFv06_DEltX4) == sizeof(U32)); /* if compilation fails here, assertion is false */
2342
2342
  if (memLog > HUFv06_ABSOLUTEMAX_TABLELOG) return ERROR(tableLog_tooLarge);
2343
- //memset(weightList, 0, sizeof(weightList)); /* is not necessary, even though some analyzer complain ... */
2343
+ /* memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
2344
2344
 
2345
2345
  iSize = HUFv06_readStats(weightList, HUFv06_MAX_SYMBOL_VALUE + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
2346
2346
  if (HUFv06_isError(iSize)) return iSize;
@@ -2664,13 +2664,13 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2664
2664
 
2665
2665
  { U32 algoNb = 0;
2666
2666
  if (Dtime[1] < Dtime[0]) algoNb = 1;
2667
- // if (Dtime[2] < Dtime[algoNb]) algoNb = 2; /* current speed of HUFv06_decompress4X6 is not good */
2667
+ /* if (Dtime[2] < Dtime[algoNb]) algoNb = 2; */ /* current speed of HUFv06_decompress4X6 is not good */
2668
2668
  return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
2669
2669
  }
2670
2670
 
2671
- //return HUFv06_decompress4X2(dst, dstSize, cSrc, cSrcSize); /* multi-streams single-symbol decoding */
2672
- //return HUFv06_decompress4X4(dst, dstSize, cSrc, cSrcSize); /* multi-streams double-symbols decoding */
2673
- //return HUFv06_decompress4X6(dst, dstSize, cSrc, cSrcSize); /* multi-streams quad-symbols decoding */
2671
+ /* return HUFv06_decompress4X2(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams single-symbol decoding */
2672
+ /* return HUFv06_decompress4X4(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams double-symbols decoding */
2673
+ /* return HUFv06_decompress4X6(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams quad-symbols decoding */
2674
2674
  }
2675
2675
  /*
2676
2676
  Common functions of Zstd compression library
@@ -3242,14 +3242,12 @@ static size_t ZSTDv06_decodeSeqHeaders(int* nbSeqPtr,
3242
3242
  }
3243
3243
 
3244
3244
  /* FSE table descriptors */
3245
+ if (ip + 4 > iend) return ERROR(srcSize_wrong); /* min : header byte + all 3 are "raw", hence no header, but at least xxLog bits per type */
3245
3246
  { U32 const LLtype = *ip >> 6;
3246
3247
  U32 const Offtype = (*ip >> 4) & 3;
3247
3248
  U32 const MLtype = (*ip >> 2) & 3;
3248
3249
  ip++;
3249
3250
 
3250
- /* check */
3251
- if (ip > iend-3) return ERROR(srcSize_wrong); /* min : all 3 are "raw", hence no header, but at least xxLog bits per type */
3252
-
3253
3251
  /* Build DTables */
3254
3252
  { size_t const bhSize = ZSTDv06_buildSeqTable(DTableLL, LLtype, MaxLL, LLFSELog, ip, iend-ip, LL_defaultNorm, LL_defaultNormLog, flagRepeatTable);
3255
3253
  if (ZSTDv06_isError(bhSize)) return ERROR(corruption_detected);
@@ -3503,8 +3501,10 @@ static size_t ZSTDv06_decompressSequences(
3503
3501
  { size_t const lastLLSize = litEnd - litPtr;
3504
3502
  if (litPtr > litEnd) return ERROR(corruption_detected); /* too many literals already used */
3505
3503
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
3506
- memcpy(op, litPtr, lastLLSize);
3507
- op += lastLLSize;
3504
+ if (lastLLSize > 0) {
3505
+ memcpy(op, litPtr, lastLLSize);
3506
+ op += lastLLSize;
3507
+ }
3508
3508
  }
3509
3509
 
3510
3510
  return op-ostart;
@@ -3672,7 +3672,7 @@ void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cS
3672
3672
  blockProperties_t blockProperties = { bt_compressed, 0 };
3673
3673
 
3674
3674
  /* Frame Header */
3675
- { size_t const frameHeaderSize = ZSTDv06_frameHeaderSize(src, ZSTDv06_frameHeaderSize_min);
3675
+ { size_t const frameHeaderSize = ZSTDv06_frameHeaderSize(src, srcSize);
3676
3676
  if (ZSTDv06_isError(frameHeaderSize)) {
3677
3677
  ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, frameHeaderSize);
3678
3678
  return;
@@ -4002,7 +4002,9 @@ size_t ZBUFFv06_decompressInit(ZBUFFv06_DCtx* zbd)
4002
4002
  MEM_STATIC size_t ZBUFFv06_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
4003
4003
  {
4004
4004
  size_t length = MIN(dstCapacity, srcSize);
4005
- memcpy(dst, src, length);
4005
+ if (length > 0) {
4006
+ memcpy(dst, src, length);
4007
+ }
4006
4008
  return length;
4007
4009
  }
4008
4010
 
@@ -4111,7 +4113,7 @@ size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* zbd,
4111
4113
  if (!decodedSize) { zbd->stage = ZBUFFds_read; break; } /* this was just a header */
4112
4114
  zbd->outEnd = zbd->outStart + decodedSize;
4113
4115
  zbd->stage = ZBUFFds_flush;
4114
- // break; /* ZBUFFds_flush follows */
4116
+ /* break; */ /* ZBUFFds_flush follows */
4115
4117
  }
4116
4118
  }
4117
4119
  /* fall-through */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -17,14 +17,14 @@
17
17
  #ifndef XXH_STATIC_LINKING_ONLY
18
18
  # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
19
19
  #endif
20
- #include "xxhash.h" /* XXH64_* */
20
+ #include "../common/xxhash.h" /* XXH64_* */
21
21
  #include "zstd_v07.h"
22
22
 
23
23
  #define FSEv07_STATIC_LINKING_ONLY /* FSEv07_MIN_TABLELOG */
24
24
  #define HUFv07_STATIC_LINKING_ONLY /* HUFv07_TABLELOG_ABSOLUTEMAX */
25
25
  #define ZSTDv07_STATIC_LINKING_ONLY
26
26
 
27
- #include "error_private.h"
27
+ #include "../common/error_private.h"
28
28
 
29
29
 
30
30
  #ifdef ZSTDv07_STATIC_LINKING_ONLY
@@ -530,7 +530,7 @@ MEM_STATIC unsigned BITv07_highbit32 (U32 val)
530
530
  _BitScanReverse ( &r, val );
531
531
  return (unsigned) r;
532
532
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
533
- return 31 - __builtin_clz (val);
533
+ return __builtin_clz (val) ^ 31;
534
534
  # else /* Software version */
535
535
  static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
536
536
  U32 v = val;
@@ -1314,7 +1314,7 @@ size_t HUFv07_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
1314
1314
 
1315
1315
  if (!srcSize) return ERROR(srcSize_wrong);
1316
1316
  iSize = ip[0];
1317
- //memset(huffWeight, 0, hwSize); /* is not necessary, even though some analyzer complain ... */
1317
+ /* memset(huffWeight, 0, hwSize); */ /* is not necessary, even though some analyzer complain ... */
1318
1318
 
1319
1319
  if (iSize >= 128) { /* special header */
1320
1320
  if (iSize >= (242)) { /* RLE */
@@ -1784,7 +1784,7 @@ size_t HUFv07_readDTableX2 (HUFv07_DTable* DTable, const void* src, size_t srcSi
1784
1784
  HUFv07_DEltX2* const dt = (HUFv07_DEltX2*)dtPtr;
1785
1785
 
1786
1786
  HUFv07_STATIC_ASSERT(sizeof(DTableDesc) == sizeof(HUFv07_DTable));
1787
- //memset(huffWeight, 0, sizeof(huffWeight)); /* is not necessary, even though some analyzer complain ... */
1787
+ /* memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */
1788
1788
 
1789
1789
  iSize = HUFv07_readStats(huffWeight, HUFv07_SYMBOLVALUE_MAX + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
1790
1790
  if (HUFv07_isError(iSize)) return iSize;
@@ -2148,7 +2148,7 @@ size_t HUFv07_readDTableX4 (HUFv07_DTable* DTable, const void* src, size_t srcSi
2148
2148
 
2149
2149
  HUFv07_STATIC_ASSERT(sizeof(HUFv07_DEltX4) == sizeof(HUFv07_DTable)); /* if compilation fails here, assertion is false */
2150
2150
  if (maxTableLog > HUFv07_TABLELOG_ABSOLUTEMAX) return ERROR(tableLog_tooLarge);
2151
- //memset(weightList, 0, sizeof(weightList)); /* is not necessary, even though some analyzer complain ... */
2151
+ /* memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
2152
2152
 
2153
2153
  iSize = HUFv07_readStats(weightList, HUFv07_SYMBOLVALUE_MAX + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
2154
2154
  if (HUFv07_isError(iSize)) return iSize;
@@ -2530,8 +2530,8 @@ size_t HUFv07_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2530
2530
  return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
2531
2531
  }
2532
2532
 
2533
- //return HUFv07_decompress4X2(dst, dstSize, cSrc, cSrcSize); /* multi-streams single-symbol decoding */
2534
- //return HUFv07_decompress4X4(dst, dstSize, cSrc, cSrcSize); /* multi-streams double-symbols decoding */
2533
+ /* return HUFv07_decompress4X2(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams single-symbol decoding */
2534
+ /* return HUFv07_decompress4X4(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams double-symbols decoding */
2535
2535
  }
2536
2536
 
2537
2537
  size_t HUFv07_decompress4X_DCtx (HUFv07_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
@@ -3272,7 +3272,9 @@ static size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProper
3272
3272
  static size_t ZSTDv07_copyRawBlock(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
3273
3273
  {
3274
3274
  if (srcSize > dstCapacity) return ERROR(dstSize_tooSmall);
3275
- memcpy(dst, src, srcSize);
3275
+ if (srcSize > 0) {
3276
+ memcpy(dst, src, srcSize);
3277
+ }
3276
3278
  return srcSize;
3277
3279
  }
3278
3280
 
@@ -3470,14 +3472,12 @@ static size_t ZSTDv07_decodeSeqHeaders(int* nbSeqPtr,
3470
3472
  }
3471
3473
 
3472
3474
  /* FSE table descriptors */
3475
+ if (ip + 4 > iend) return ERROR(srcSize_wrong); /* min : header byte + all 3 are "raw", hence no header, but at least xxLog bits per type */
3473
3476
  { U32 const LLtype = *ip >> 6;
3474
3477
  U32 const OFtype = (*ip >> 4) & 3;
3475
3478
  U32 const MLtype = (*ip >> 2) & 3;
3476
3479
  ip++;
3477
3480
 
3478
- /* check */
3479
- if (ip > iend-3) return ERROR(srcSize_wrong); /* min : all 3 are "raw", hence no header, but at least xxLog bits per type */
3480
-
3481
3481
  /* Build DTables */
3482
3482
  { size_t const llhSize = ZSTDv07_buildSeqTable(DTableLL, LLtype, MaxLL, LLFSELog, ip, iend-ip, LL_defaultNorm, LL_defaultNormLog, flagRepeatTable);
3483
3483
  if (ZSTDv07_isError(llhSize)) return ERROR(corruption_detected);
@@ -3714,10 +3714,12 @@ static size_t ZSTDv07_decompressSequences(
3714
3714
 
3715
3715
  /* last literal segment */
3716
3716
  { size_t const lastLLSize = litEnd - litPtr;
3717
- //if (litPtr > litEnd) return ERROR(corruption_detected); /* too many literals already used */
3717
+ /* if (litPtr > litEnd) return ERROR(corruption_detected); */ /* too many literals already used */
3718
3718
  if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall);
3719
- memcpy(op, litPtr, lastLLSize);
3720
- op += lastLLSize;
3719
+ if (lastLLSize > 0) {
3720
+ memcpy(op, litPtr, lastLLSize);
3721
+ op += lastLLSize;
3722
+ }
3721
3723
  }
3722
3724
 
3723
3725
  return op-ostart;
@@ -3778,7 +3780,9 @@ ZSTDLIBv07_API size_t ZSTDv07_insertBlock(ZSTDv07_DCtx* dctx, const void* blockS
3778
3780
  static size_t ZSTDv07_generateNxBytes(void* dst, size_t dstCapacity, BYTE byte, size_t length)
3779
3781
  {
3780
3782
  if (length > dstCapacity) return ERROR(dstSize_tooSmall);
3781
- memset(dst, byte, length);
3783
+ if (length > 0) {
3784
+ memset(dst, byte, length);
3785
+ }
3782
3786
  return length;
3783
3787
  }
3784
3788
 
@@ -3918,7 +3922,7 @@ void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cS
3918
3922
  }
3919
3923
 
3920
3924
  /* Frame Header */
3921
- { size_t const frameHeaderSize = ZSTDv07_frameHeaderSize(src, ZSTDv07_frameHeaderSize_min);
3925
+ { size_t const frameHeaderSize = ZSTDv07_frameHeaderSize(src, srcSize);
3922
3926
  if (ZSTDv07_isError(frameHeaderSize)) {
3923
3927
  ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, frameHeaderSize);
3924
3928
  return;
@@ -4380,7 +4384,9 @@ size_t ZBUFFv07_decompressInit(ZBUFFv07_DCtx* zbd)
4380
4384
  MEM_STATIC size_t ZBUFFv07_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
4381
4385
  {
4382
4386
  size_t const length = MIN(dstCapacity, srcSize);
4383
- memcpy(dst, src, length);
4387
+ if (length > 0) {
4388
+ memcpy(dst, src, length);
4389
+ }
4384
4390
  return length;
4385
4391
  }
4386
4392
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -3,8 +3,9 @@
3
3
  # BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4
4
 
5
5
  prefix=@PREFIX@
6
- libdir=@LIBDIR@
7
- includedir=@INCLUDEDIR@
6
+ exec_prefix=${prefix}
7
+ includedir=${prefix}/@INCLUDEDIR@
8
+ libdir=${exec_prefix}/@LIBDIR@
8
9
 
9
10
  Name: zstd
10
11
  Description: fast lossless compression algorithm library
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -15,6 +15,7 @@ extern "C" {
15
15
  #define ZSTD_H_235446
16
16
 
17
17
  /* ====== Dependency ======*/
18
+ #include <limits.h> /* INT_MAX */
18
19
  #include <stddef.h> /* size_t */
19
20
 
20
21
 
@@ -71,7 +72,7 @@ extern "C" {
71
72
  /*------ Version ------*/
72
73
  #define ZSTD_VERSION_MAJOR 1
73
74
  #define ZSTD_VERSION_MINOR 4
74
- #define ZSTD_VERSION_RELEASE 0
75
+ #define ZSTD_VERSION_RELEASE 5
75
76
 
76
77
  #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
77
78
  ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library version */
@@ -82,16 +83,16 @@ ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library v
82
83
  #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
83
84
  ZSTDLIB_API const char* ZSTD_versionString(void); /* requires v1.3.0+ */
84
85
 
85
- /***************************************
86
- * Default constant
87
- ***************************************/
86
+ /* *************************************
87
+ * Default constant
88
+ ***************************************/
88
89
  #ifndef ZSTD_CLEVEL_DEFAULT
89
90
  # define ZSTD_CLEVEL_DEFAULT 3
90
91
  #endif
91
92
 
92
- /***************************************
93
- * Constants
94
- ***************************************/
93
+ /* *************************************
94
+ * Constants
95
+ ***************************************/
95
96
 
96
97
  /* All magic numbers are supposed read/written to/from files/memory using little-endian convention */
97
98
  #define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */
@@ -183,17 +184,26 @@ ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compres
183
184
  ***************************************/
184
185
  /*= Compression context
185
186
  * When compressing many times,
186
- * it is recommended to allocate a context just once, and re-use it for each successive compression operation.
187
+ * it is recommended to allocate a context just once,
188
+ * and re-use it for each successive compression operation.
187
189
  * This will make workload friendlier for system's memory.
188
- * Use one context per thread for parallel execution in multi-threaded environments. */
190
+ * Note : re-using context is just a speed / resource optimization.
191
+ * It doesn't change the compression ratio, which remains identical.
192
+ * Note 2 : In multi-threaded environments,
193
+ * use one different context per thread for parallel execution.
194
+ */
189
195
  typedef struct ZSTD_CCtx_s ZSTD_CCtx;
190
196
  ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
191
197
  ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
192
198
 
193
199
  /*! ZSTD_compressCCtx() :
194
- * Same as ZSTD_compress(), using an explicit ZSTD_CCtx
195
- * The function will compress at requested compression level,
196
- * ignoring any other parameter */
200
+ * Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
201
+ * Important : in order to behave similarly to `ZSTD_compress()`,
202
+ * this function compresses at requested compression level,
203
+ * __ignoring any other parameter__ .
204
+ * If any advanced parameter was set using the advanced API,
205
+ * they will all be reset. Only `compressionLevel` remains.
206
+ */
197
207
  ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
198
208
  void* dst, size_t dstCapacity,
199
209
  const void* src, size_t srcSize,
@@ -228,7 +238,7 @@ ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
228
238
  * using ZSTD_CCtx_set*() functions.
229
239
  * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
230
240
  * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
231
- * They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()
241
+ * __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ .
232
242
  *
233
243
  * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
234
244
  *
@@ -256,18 +266,29 @@ typedef enum {
256
266
 
257
267
  /* compression parameters
258
268
  * Note: When compressing with a ZSTD_CDict these parameters are superseded
259
- * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
260
- * for more info (superseded-by-cdict). */
261
- ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
269
+ * by the parameters used to construct the ZSTD_CDict.
270
+ * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
271
+ ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
272
+ * Note that exact compression parameters are dynamically determined,
273
+ * depending on both compression level and srcSize (when known).
262
274
  * Default level is ZSTD_CLEVEL_DEFAULT==3.
263
275
  * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
264
276
  * Note 1 : it's possible to pass a negative compression level.
265
- * Note 2 : setting a level sets all default values of other compression parameters */
277
+ * Note 2 : setting a level does not automatically set all other compression parameters
278
+ * to default. Setting this will however eventually dynamically impact the compression
279
+ * parameters which have not been manually set. The manually set
280
+ * ones will 'stick'. */
281
+ /* Advanced compression parameters :
282
+ * It's possible to pin down compression parameters to some specific values.
283
+ * In which case, these values are no longer dynamically selected by the compressor */
266
284
  ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
285
+ * This will set a memory budget for streaming decompression,
286
+ * with larger values requiring more memory
287
+ * and typically compressing more.
267
288
  * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
268
289
  * Special: value 0 means "use default windowLog".
269
290
  * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
270
- * requires explicitly allowing such window size at decompression stage if using streaming. */
291
+ * requires explicitly allowing such size at streaming decompression stage. */
271
292
  ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
272
293
  * Resulting memory usage is (1 << (hashLog+2)).
273
294
  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
@@ -278,13 +299,13 @@ typedef enum {
278
299
  * Resulting memory usage is (1 << (chainLog+2)).
279
300
  * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
280
301
  * Larger tables result in better and slower compression.
281
- * This parameter is useless when using "fast" strategy.
302
+ * This parameter is useless for "fast" strategy.
282
303
  * It's still useful when using "dfast" strategy,
283
304
  * in which case it defines a secondary probe table.
284
305
  * Special: value 0 means "use default chainLog". */
285
306
  ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
286
307
  * More attempts result in better and slower compression.
287
- * This parameter is useless when using "fast" and "dFast" strategies.
308
+ * This parameter is useless for "fast" and "dFast" strategies.
288
309
  * Special: value 0 means "use default searchLog". */
289
310
  ZSTD_c_minMatch=105, /* Minimum size of searched matches.
290
311
  * Note that Zstandard can still find matches of smaller size,
@@ -339,7 +360,7 @@ typedef enum {
339
360
  ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
340
361
  * Content size must be known at the beginning of compression.
341
362
  * This is automatically the case when using ZSTD_compress2(),
342
- * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
363
+ * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
343
364
  ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
344
365
  ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
345
366
 
@@ -358,7 +379,7 @@ typedef enum {
358
379
  * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
359
380
  * 0 means default, which is dynamically determined based on compression parameters.
360
381
  * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
361
- * The minimum size is automatically and transparently enforced */
382
+ * The minimum size is automatically and transparently enforced. */
362
383
  ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
363
384
  * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
364
385
  * It helps preserve compression ratio, while each job is compressed in parallel.
@@ -380,6 +401,8 @@ typedef enum {
380
401
  * ZSTD_c_forceMaxWindow
381
402
  * ZSTD_c_forceAttachDict
382
403
  * ZSTD_c_literalCompressionMode
404
+ * ZSTD_c_targetCBlockSize
405
+ * ZSTD_c_srcSizeHint
383
406
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
384
407
  * note : never ever use experimentalParam? names directly;
385
408
  * also, the enums values themselves are unstable and can still change.
@@ -389,6 +412,8 @@ typedef enum {
389
412
  ZSTD_c_experimentalParam3=1000,
390
413
  ZSTD_c_experimentalParam4=1001,
391
414
  ZSTD_c_experimentalParam5=1002,
415
+ ZSTD_c_experimentalParam6=1003,
416
+ ZSTD_c_experimentalParam7=1004
392
417
  } ZSTD_cParameter;
393
418
 
394
419
  typedef struct {
@@ -497,11 +522,13 @@ typedef enum {
497
522
  /* note : additional experimental parameters are also available
498
523
  * within the experimental section of the API.
499
524
  * At the time of this writing, they include :
500
- * ZSTD_c_format
525
+ * ZSTD_d_format
526
+ * ZSTD_d_stableOutBuffer
501
527
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
502
528
  * note : never ever use experimentalParam? names directly
503
529
  */
504
- ZSTD_d_experimentalParam1=1000
530
+ ZSTD_d_experimentalParam1=1000,
531
+ ZSTD_d_experimentalParam2=1001
505
532
 
506
533
  } ZSTD_dParameter;
507
534
 
@@ -657,17 +684,33 @@ ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
657
684
  ZSTD_inBuffer* input,
658
685
  ZSTD_EndDirective endOp);
659
686
 
687
+
688
+ /* These buffer sizes are softly recommended.
689
+ * They are not required : ZSTD_compressStream*() happily accepts any buffer size, for both input and output.
690
+ * Respecting the recommended size just makes it a bit easier for ZSTD_compressStream*(),
691
+ * reducing the amount of memory shuffling and buffering, resulting in minor performance savings.
692
+ *
693
+ * However, note that these recommendations are from the perspective of a C caller program.
694
+ * If the streaming interface is invoked from some other language,
695
+ * especially managed ones such as Java or Go, through a foreign function interface such as jni or cgo,
696
+ * a major performance rule is to reduce crossing such interface to an absolute minimum.
697
+ * It's not rare that performance ends being spent more into the interface, rather than compression itself.
698
+ * In which cases, prefer using large buffers, as large as practical,
699
+ * for both input and output, to reduce the nb of roundtrips.
700
+ */
660
701
  ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */
661
- ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */
702
+ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block. */
662
703
 
663
- /*******************************************************************************
664
- * This is a legacy streaming API, and can be replaced by ZSTD_CCtx_reset() and
665
- * ZSTD_compressStream2(). It is redundant, but is still fully supported.
704
+
705
+ /* *****************************************************************************
706
+ * This following is a legacy streaming API.
707
+ * It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
708
+ * It is redundant, but remains fully supported.
666
709
  * Advanced parameters and dictionary compression can only be used through the
667
710
  * new API.
668
711
  ******************************************************************************/
669
712
 
670
- /**
713
+ /*!
671
714
  * Equivalent to:
672
715
  *
673
716
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
@@ -675,16 +718,16 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
675
718
  * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
676
719
  */
677
720
  ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
678
- /**
721
+ /*!
679
722
  * Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue).
680
723
  * NOTE: The return value is different. ZSTD_compressStream() returns a hint for
681
724
  * the next read size (if non-zero and not an error). ZSTD_compressStream2()
682
- * returns the number of bytes left to flush (if non-zero and not an error).
725
+ * returns the minimum nb of bytes left to flush (if non-zero and not an error).
683
726
  */
684
727
  ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
685
- /** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
728
+ /*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
686
729
  ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
687
- /** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
730
+ /*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
688
731
  ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
689
732
 
690
733
 
@@ -725,7 +768,7 @@ ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds);
725
768
 
726
769
  /* This function is redundant with the advanced API and equivalent to:
727
770
  *
728
- * ZSTD_DCtx_reset(zds);
771
+ * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
729
772
  * ZSTD_DCtx_refDDict(zds, NULL);
730
773
  */
731
774
  ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
@@ -770,12 +813,17 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
770
813
  typedef struct ZSTD_CDict_s ZSTD_CDict;
771
814
 
772
815
  /*! ZSTD_createCDict() :
773
- * When compressing multiple messages / blocks using the same dictionary, it's recommended to load it only once.
774
- * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup cost.
816
+ * When compressing multiple messages or blocks using the same dictionary,
817
+ * it's recommended to digest the dictionary only once, since it's a costly operation.
818
+ * ZSTD_createCDict() will create a state from digesting a dictionary.
819
+ * The resulting state can be used for future compression operations with very limited startup cost.
775
820
  * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
776
- * `dictBuffer` can be released after ZSTD_CDict creation, because its content is copied within CDict.
777
- * Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate `dictBuffer` content.
778
- * Note : A ZSTD_CDict can be created from an empty dictBuffer, but it is inefficient when used to compress small data. */
821
+ * @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict.
822
+ * Note 1 : Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate @dictBuffer content.
823
+ * Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer,
824
+ * in which case the only thing that it transports is the @compressionLevel.
825
+ * This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively,
826
+ * expecting a ZSTD_CDict parameter with any data, including those without a known dictionary. */
779
827
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
780
828
  int compressionLevel);
781
829
 
@@ -902,7 +950,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
902
950
  * Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
903
951
  * It's a CPU consuming operation, with non-negligible impact on latency.
904
952
  * If there is a need to use the same prefix multiple times, consider loadDictionary instead.
905
- * Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dm_rawContent).
953
+ * Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent).
906
954
  * Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation. */
907
955
  ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
908
956
  const void* prefix, size_t prefixSize);
@@ -946,7 +994,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
946
994
  * Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
947
995
  * Prefix buffer must remain unmodified up to the end of frame,
948
996
  * reached when ZSTD_decompressStream() returns 0.
949
- * Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
997
+ * Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent).
950
998
  * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
951
999
  * Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
952
1000
  * A full dictionary is more costly, as it requires building tables.
@@ -969,7 +1017,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
969
1017
  #endif /* ZSTD_H_235446 */
970
1018
 
971
1019
 
972
- /****************************************************************************************
1020
+ /* **************************************************************************************
973
1021
  * ADVANCED AND EXPERIMENTAL FUNCTIONS
974
1022
  ****************************************************************************************
975
1023
  * The definitions in the following section are considered experimental.
@@ -991,8 +1039,8 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
991
1039
  * Some of them might be removed in the future (especially when redundant with existing stable functions)
992
1040
  * ***************************************************************************************/
993
1041
 
994
- #define ZSTD_FRAMEHEADERSIZE_PREFIX 5 /* minimum input size required to query frame header size */
995
- #define ZSTD_FRAMEHEADERSIZE_MIN 6
1042
+ #define ZSTD_FRAMEHEADERSIZE_PREFIX(format) ((format) == ZSTD_f_zstd1 ? 5 : 1) /* minimum input size required to query frame header size */
1043
+ #define ZSTD_FRAMEHEADERSIZE_MIN(format) ((format) == ZSTD_f_zstd1 ? 6 : 2)
996
1044
  #define ZSTD_FRAMEHEADERSIZE_MAX 18 /* can be useful for static allocation */
997
1045
  #define ZSTD_SKIPPABLEHEADERSIZE 8
998
1046
 
@@ -1037,6 +1085,12 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1037
1085
  #define ZSTD_LDM_HASHRATELOG_MIN 0
1038
1086
  #define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
1039
1087
 
1088
+ /* Advanced parameter bounds */
1089
+ #define ZSTD_TARGETCBLOCKSIZE_MIN 64
1090
+ #define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
1091
+ #define ZSTD_SRCSIZEHINT_MIN 0
1092
+ #define ZSTD_SRCSIZEHINT_MAX INT_MAX
1093
+
1040
1094
  /* internal */
1041
1095
  #define ZSTD_HASHLOG3_MAX 17
1042
1096
 
@@ -1045,6 +1099,24 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1045
1099
 
1046
1100
  typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
1047
1101
 
1102
+ typedef struct {
1103
+ unsigned int matchPos; /* Match pos in dst */
1104
+ /* If seqDef.offset > 3, then this is seqDef.offset - 3
1105
+ * If seqDef.offset < 3, then this is the corresponding repeat offset
1106
+ * But if seqDef.offset < 3 and litLength == 0, this is the
1107
+ * repeat offset before the corresponding repeat offset
1108
+ * And if seqDef.offset == 3 and litLength == 0, this is the
1109
+ * most recent repeat offset - 1
1110
+ */
1111
+ unsigned int offset;
1112
+ unsigned int litLength; /* Literal length */
1113
+ unsigned int matchLength; /* Match length */
1114
+ /* 0 when seq not rep and seqDef.offset otherwise
1115
+ * when litLength == 0 this will be <= 4, otherwise <= 3 like normal
1116
+ */
1117
+ unsigned int rep;
1118
+ } ZSTD_Sequence;
1119
+
1048
1120
  typedef struct {
1049
1121
  unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */
1050
1122
  unsigned chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
@@ -1074,21 +1146,12 @@ typedef enum {
1074
1146
 
1075
1147
  typedef enum {
1076
1148
  ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */
1077
- ZSTD_dlm_byRef = 1, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
1149
+ ZSTD_dlm_byRef = 1 /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
1078
1150
  } ZSTD_dictLoadMethod_e;
1079
1151
 
1080
1152
  typedef enum {
1081
- /* Opened question : should we have a format ZSTD_f_auto ?
1082
- * Today, it would mean exactly the same as ZSTD_f_zstd1.
1083
- * But, in the future, should several formats become supported,
1084
- * on the compression side, it would mean "default format".
1085
- * On the decompression side, it would mean "automatic format detection",
1086
- * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
1087
- * Since meaning is a little different, another option could be to define different enums for compression and decompression.
1088
- * This question could be kept for later, when there are actually multiple formats to support,
1089
- * but there is also the question of pinning enum values, and pinning value `0` is especially important */
1090
1153
  ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */
1091
- ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
1154
+ ZSTD_f_zstd1_magicless = 1 /* Variant of zstd frame format, without initial 4-bytes magic number.
1092
1155
  * Useful to save 4 bytes per generated frame.
1093
1156
  * Decoder cannot recognise automatically this format, requiring this instruction. */
1094
1157
  } ZSTD_format_e;
@@ -1099,7 +1162,7 @@ typedef enum {
1099
1162
  * to evolve and should be considered only in the context of extremely
1100
1163
  * advanced performance tuning.
1101
1164
  *
1102
- * Zstd currently supports the use of a CDict in two ways:
1165
+ * Zstd currently supports the use of a CDict in three ways:
1103
1166
  *
1104
1167
  * - The contents of the CDict can be copied into the working context. This
1105
1168
  * means that the compression can search both the dictionary and input
@@ -1115,6 +1178,12 @@ typedef enum {
1115
1178
  * working context's tables can be reused). For small inputs, this can be
1116
1179
  * faster than copying the CDict's tables.
1117
1180
  *
1181
+ * - The CDict's tables are not used at all, and instead we use the working
1182
+ * context alone to reload the dictionary and use params based on the source
1183
+ * size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
1184
+ * This method is effective when the dictionary sizes are very small relative
1185
+ * to the input size, and the input size is fairly large to begin with.
1186
+ *
1118
1187
  * Zstd has a simple internal heuristic that selects which strategy to use
1119
1188
  * at the beginning of a compression. However, if experimentation shows that
1120
1189
  * Zstd is making poor choices, it is possible to override that choice with
@@ -1123,6 +1192,7 @@ typedef enum {
1123
1192
  ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
1124
1193
  ZSTD_dictForceAttach = 1, /* Never copy the dictionary. */
1125
1194
  ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */
1195
+ ZSTD_dictForceLoad = 3 /* Always reload the dictionary */
1126
1196
  } ZSTD_dictAttachPref_e;
1127
1197
 
1128
1198
  typedef enum {
@@ -1131,7 +1201,7 @@ typedef enum {
1131
1201
  * levels will be compressed. */
1132
1202
  ZSTD_lcm_huffman = 1, /**< Always attempt Huffman compression. Uncompressed literals will still be
1133
1203
  * emitted if Huffman compression is not profitable. */
1134
- ZSTD_lcm_uncompressed = 2, /**< Always emit uncompressed literals. */
1204
+ ZSTD_lcm_uncompressed = 2 /**< Always emit uncompressed literals. */
1135
1205
  } ZSTD_literalCompressionMode_e;
1136
1206
 
1137
1207
 
@@ -1162,7 +1232,7 @@ typedef enum {
1162
1232
  * however it does mean that all frame data must be present and valid. */
1163
1233
  ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1164
1234
 
1165
- /** ZSTD_decompressBound() :
1235
+ /*! ZSTD_decompressBound() :
1166
1236
  * `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1167
1237
  * `srcSize` must be the _exact_ size of this series
1168
1238
  * (i.e. there should be a frame boundary at `src + srcSize`)
@@ -1183,6 +1253,15 @@ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcS
1183
1253
  * or an error code (if srcSize is too small) */
1184
1254
  ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1185
1255
 
1256
+ /*! ZSTD_getSequences() :
1257
+ * Extract sequences from the sequence store
1258
+ * zc can be used to insert custom compression params.
1259
+ * This function invokes ZSTD_compress2
1260
+ * @return : number of sequences extracted
1261
+ */
1262
+ ZSTDLIB_API size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
1263
+ size_t outSeqsSize, const void* src, size_t srcSize);
1264
+
1186
1265
 
1187
1266
  /***************************************
1188
1267
  * Memory management
@@ -1191,12 +1270,26 @@ ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1191
1270
  /*! ZSTD_estimate*() :
1192
1271
  * These functions make it possible to estimate memory usage
1193
1272
  * of a future {D,C}Ctx, before its creation.
1194
- * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
1195
- * It will also consider src size to be arbitrarily "large", which is worst case.
1196
- * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
1197
- * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1198
- * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
1199
- * Note : CCtx size estimation is only correct for single-threaded compression. */
1273
+ *
1274
+ * ZSTD_estimateCCtxSize() will provide a memory budget large enough
1275
+ * for any compression level up to selected one.
1276
+ * Note : Unlike ZSTD_estimateCStreamSize*(), this estimate
1277
+ * does not include space for a window buffer.
1278
+ * Therefore, the estimation is only guaranteed for single-shot compressions, not streaming.
1279
+ * The estimate will assume the input may be arbitrarily large,
1280
+ * which is the worst case.
1281
+ *
1282
+ * When srcSize can be bound by a known and rather "small" value,
1283
+ * this fact can be used to provide a tighter estimation
1284
+ * because the CCtx compression context will need less memory.
1285
+ * This tighter estimation can be provided by more advanced functions
1286
+ * ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
1287
+ * and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
1288
+ * Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
1289
+ *
1290
+ * Note 2 : only single-threaded compression is supported.
1291
+ * ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1292
+ */
1200
1293
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
1201
1294
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1202
1295
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
@@ -1307,7 +1400,8 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
1307
1400
  * Create a digested dictionary for compression
1308
1401
  * Dictionary content is just referenced, not duplicated.
1309
1402
  * As a consequence, `dictBuffer` **must** outlive CDict,
1310
- * and its content must remain unmodified throughout the lifetime of CDict. */
1403
+ * and its content must remain unmodified throughout the lifetime of CDict.
1404
+ * note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */
1311
1405
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1312
1406
 
1313
1407
  /*! ZSTD_getCParams() :
@@ -1334,7 +1428,9 @@ ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1334
1428
  ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1335
1429
 
1336
1430
  /*! ZSTD_compress_advanced() :
1337
- * Same as ZSTD_compress_usingDict(), with fine-tune control over compression parameters (by structure) */
1431
+ * Note : this function is now DEPRECATED.
1432
+ * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
1433
+ * This prototype will be marked as deprecated and generate compilation warning on reaching v1.5.x */
1338
1434
  ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1339
1435
  void* dst, size_t dstCapacity,
1340
1436
  const void* src, size_t srcSize,
@@ -1342,7 +1438,9 @@ ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1342
1438
  ZSTD_parameters params);
1343
1439
 
1344
1440
  /*! ZSTD_compress_usingCDict_advanced() :
1345
- * Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */
1441
+ * Note : this function is now REDUNDANT.
1442
+ * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
1443
+ * This prototype will be marked as deprecated and generate compilation warning in some future version */
1346
1444
  ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
1347
1445
  void* dst, size_t dstCapacity,
1348
1446
  const void* src, size_t srcSize,
@@ -1409,6 +1507,17 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
1409
1507
  */
1410
1508
  #define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
1411
1509
 
1510
+ /* Tries to fit compressed block size to be around targetCBlockSize.
1511
+ * No target when targetCBlockSize == 0.
1512
+ * There is no guarantee on compressed block size (default:0) */
1513
+ #define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
1514
+
1515
+ /* User's best guess of source size.
1516
+ * Hint is not valid when srcSizeHint == 0.
1517
+ * There is no guarantee that hint is close to actual source size,
1518
+ * but compression ratio may regress significantly if guess considerably underestimates */
1519
+ #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
1520
+
1412
1521
  /*! ZSTD_CCtx_getParameter() :
1413
1522
  * Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1414
1523
  * and store it into int* value.
@@ -1543,6 +1652,37 @@ ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowS
1543
1652
  * allowing selection between ZSTD_format_e input compression formats
1544
1653
  */
1545
1654
  #define ZSTD_d_format ZSTD_d_experimentalParam1
1655
+ /* ZSTD_d_stableOutBuffer
1656
+ * Experimental parameter.
1657
+ * Default is 0 == disabled. Set to 1 to enable.
1658
+ *
1659
+ * Tells the decompressor that the ZSTD_outBuffer will ALWAYS be the same
1660
+ * between calls, except for the modifications that zstd makes to pos (the
1661
+ * caller must not modify pos). This is checked by the decompressor, and
1662
+ * decompression will fail if it ever changes. Therefore the ZSTD_outBuffer
1663
+ * MUST be large enough to fit the entire decompressed frame. This will be
1664
+ * checked when the frame content size is known. The data in the ZSTD_outBuffer
1665
+ * in the range [dst, dst + pos) MUST not be modified during decompression
1666
+ * or you will get data corruption.
1667
+ *
1668
+ * When this flags is enabled zstd won't allocate an output buffer, because
1669
+ * it can write directly to the ZSTD_outBuffer, but it will still allocate
1670
+ * an input buffer large enough to fit any compressed block. This will also
1671
+ * avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
1672
+ * If you need to avoid the input buffer allocation use the buffer-less
1673
+ * streaming API.
1674
+ *
1675
+ * NOTE: So long as the ZSTD_outBuffer always points to valid memory, using
1676
+ * this flag is ALWAYS memory safe, and will never access out-of-bounds
1677
+ * memory. However, decompression WILL fail if you violate the preconditions.
1678
+ *
1679
+ * WARNING: The data in the ZSTD_outBuffer in the range [dst, dst + pos) MUST
1680
+ * not be modified during decompression or you will get data corruption. This
1681
+ * is because zstd needs to reference data in the ZSTD_outBuffer to regenerate
1682
+ * matches. Normally zstd maintains its own buffer for this purpose, but passing
1683
+ * this flag tells zstd to use the user provided buffer.
1684
+ */
1685
+ #define ZSTD_d_stableOutBuffer ZSTD_d_experimentalParam2
1546
1686
 
1547
1687
  /*! ZSTD_DCtx_setFormat() :
1548
1688
  * Instruct the decoder context about what kind of data to decode next.
@@ -1581,8 +1721,13 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs (
1581
1721
  * pledgedSrcSize must be correct. If it is not known at init time, use
1582
1722
  * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
1583
1723
  * "0" also disables frame content size field. It may be enabled in the future.
1724
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1584
1725
  */
1585
- ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);
1726
+ ZSTDLIB_API size_t
1727
+ ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
1728
+ int compressionLevel,
1729
+ unsigned long long pledgedSrcSize);
1730
+
1586
1731
  /**! ZSTD_initCStream_usingDict() :
1587
1732
  * This function is deprecated, and is equivalent to:
1588
1733
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
@@ -1591,42 +1736,66 @@ ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLe
1591
1736
  *
1592
1737
  * Creates of an internal CDict (incompatible with static CCtx), except if
1593
1738
  * dict == NULL or dictSize < 8, in which case no dict is used.
1594
- * Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if
1739
+ * Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
1595
1740
  * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
1741
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1596
1742
  */
1597
- ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
1743
+ ZSTDLIB_API size_t
1744
+ ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
1745
+ const void* dict, size_t dictSize,
1746
+ int compressionLevel);
1747
+
1598
1748
  /**! ZSTD_initCStream_advanced() :
1599
1749
  * This function is deprecated, and is approximately equivalent to:
1600
1750
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1601
- * ZSTD_CCtx_setZstdParams(zcs, params); // Set the zstd params and leave the rest as-is
1751
+ * // Pseudocode: Set each zstd parameter and leave the rest as-is.
1752
+ * for ((param, value) : params) {
1753
+ * ZSTD_CCtx_setParameter(zcs, param, value);
1754
+ * }
1602
1755
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1603
1756
  * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1604
1757
  *
1605
- * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1606
- * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy.
1758
+ * dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
1759
+ * pledgedSrcSize must be correct.
1760
+ * If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
1761
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1607
1762
  */
1608
- ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
1609
- ZSTD_parameters params, unsigned long long pledgedSrcSize);
1763
+ ZSTDLIB_API size_t
1764
+ ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
1765
+ const void* dict, size_t dictSize,
1766
+ ZSTD_parameters params,
1767
+ unsigned long long pledgedSrcSize);
1768
+
1610
1769
  /**! ZSTD_initCStream_usingCDict() :
1611
1770
  * This function is deprecated, and equivalent to:
1612
1771
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1613
1772
  * ZSTD_CCtx_refCDict(zcs, cdict);
1614
1773
  *
1615
1774
  * note : cdict will just be referenced, and must outlive compression session
1775
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1616
1776
  */
1617
1777
  ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
1778
+
1618
1779
  /**! ZSTD_initCStream_usingCDict_advanced() :
1619
- * This function is deprecated, and is approximately equivalent to:
1780
+ * This function is DEPRECATED, and is approximately equivalent to:
1620
1781
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1621
- * ZSTD_CCtx_setZstdFrameParams(zcs, fParams); // Set the zstd frame params and leave the rest as-is
1782
+ * // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
1783
+ * for ((fParam, value) : fParams) {
1784
+ * ZSTD_CCtx_setParameter(zcs, fParam, value);
1785
+ * }
1622
1786
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1623
1787
  * ZSTD_CCtx_refCDict(zcs, cdict);
1624
1788
  *
1625
1789
  * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
1626
1790
  * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1627
1791
  * value ZSTD_CONTENTSIZE_UNKNOWN.
1792
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1628
1793
  */
1629
- ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);
1794
+ ZSTDLIB_API size_t
1795
+ ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
1796
+ const ZSTD_CDict* cdict,
1797
+ ZSTD_frameParameters fParams,
1798
+ unsigned long long pledgedSrcSize);
1630
1799
 
1631
1800
  /*! ZSTD_resetCStream() :
1632
1801
  * This function is deprecated, and is equivalent to:
@@ -1641,6 +1810,7 @@ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const
1641
1810
  * For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
1642
1811
  * but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
1643
1812
  * @return : 0, or an error code (which can be tested using ZSTD_isError())
1813
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1644
1814
  */
1645
1815
  ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
1646
1816
 
@@ -1686,8 +1856,10 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1686
1856
  * ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
1687
1857
  *
1688
1858
  * note: no dictionary will be used if dict == NULL or dictSize < 8
1859
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1689
1860
  */
1690
1861
  ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1862
+
1691
1863
  /**
1692
1864
  * This function is deprecated, and is equivalent to:
1693
1865
  *
@@ -1695,14 +1867,17 @@ ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dic
1695
1867
  * ZSTD_DCtx_refDDict(zds, ddict);
1696
1868
  *
1697
1869
  * note : ddict is referenced, it must outlive decompression session
1870
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1698
1871
  */
1699
1872
  ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
1873
+
1700
1874
  /**
1701
1875
  * This function is deprecated, and is equivalent to:
1702
1876
  *
1703
1877
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1704
1878
  *
1705
1879
  * re-use decompression parameters from previous init; saves dictionary loading
1880
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1706
1881
  */
1707
1882
  ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
1708
1883
 
@@ -1843,7 +2018,7 @@ typedef struct {
1843
2018
  unsigned checksumFlag;
1844
2019
  } ZSTD_frameHeader;
1845
2020
 
1846
- /** ZSTD_getFrameHeader() :
2021
+ /*! ZSTD_getFrameHeader() :
1847
2022
  * decode Frame Header, or requires larger `srcSize`.
1848
2023
  * @return : 0, `zfhPtr` is correctly filled,
1849
2024
  * >0, `srcSize` is too small, value is wanted `srcSize` amount,
@@ -1876,8 +2051,8 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
1876
2051
 
1877
2052
  /*!
1878
2053
  Block functions produce and decode raw zstd blocks, without frame metadata.
1879
- Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
1880
- User will have to take in charge required information to regenerate data, such as compressed and content sizes.
2054
+ Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
2055
+ But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
1881
2056
 
1882
2057
  A few rules to respect :
1883
2058
  - Compressing and decompressing require a context structure
@@ -1888,12 +2063,14 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
1888
2063
  + copyCCtx() and copyDCtx() can be used too
1889
2064
  - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
1890
2065
  + If input is larger than a block size, it's necessary to split input data into multiple blocks
1891
- + For inputs larger than a single block, really consider using regular ZSTD_compress() instead.
1892
- Frame metadata is not that costly, and quickly becomes negligible as source size grows larger.
1893
- - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
1894
- In which case, nothing is produced into `dst` !
1895
- + User must test for such outcome and deal directly with uncompressed data
1896
- + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
2066
+ + For inputs larger than a single block, consider using regular ZSTD_compress() instead.
2067
+ Frame metadata is not that costly, and quickly becomes negligible as source size grows larger than a block.
2068
+ - When a block is considered not compressible enough, ZSTD_compressBlock() result will be 0 (zero) !
2069
+ ===> In which case, nothing is produced into `dst` !
2070
+ + User __must__ test for such outcome and deal directly with uncompressed data
2071
+ + A block cannot be declared incompressible if ZSTD_compressBlock() return value was != 0.
2072
+ Doing so would mess up with statistics history, leading to potential data corruption.
2073
+ + ZSTD_decompressBlock() _doesn't accept uncompressed data as input_ !!
1897
2074
  + In case of multiple successive blocks, should some of them be uncompressed,
1898
2075
  decoder must be informed of their existence in order to follow proper history.
1899
2076
  Use ZSTD_insertBlock() for such a case.