extzstd 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -14
  3. data/contrib/zstd/CHANGELOG +301 -56
  4. data/contrib/zstd/CONTRIBUTING.md +169 -72
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +116 -87
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +62 -32
  9. data/contrib/zstd/TESTING.md +2 -3
  10. data/contrib/zstd/appveyor.yml +52 -136
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +225 -222
  13. data/contrib/zstd/lib/README.md +51 -6
  14. data/contrib/zstd/lib/common/allocations.h +55 -0
  15. data/contrib/zstd/lib/common/bits.h +200 -0
  16. data/contrib/zstd/lib/common/bitstream.h +45 -62
  17. data/contrib/zstd/lib/common/compiler.h +205 -22
  18. data/contrib/zstd/lib/common/cpu.h +1 -3
  19. data/contrib/zstd/lib/common/debug.c +1 -1
  20. data/contrib/zstd/lib/common/debug.h +12 -19
  21. data/contrib/zstd/lib/common/entropy_common.c +172 -48
  22. data/contrib/zstd/lib/common/error_private.c +10 -2
  23. data/contrib/zstd/lib/common/error_private.h +82 -3
  24. data/contrib/zstd/lib/common/fse.h +37 -86
  25. data/contrib/zstd/lib/common/fse_decompress.c +117 -92
  26. data/contrib/zstd/lib/common/huf.h +99 -166
  27. data/contrib/zstd/lib/common/mem.h +124 -142
  28. data/contrib/zstd/lib/common/pool.c +54 -27
  29. data/contrib/zstd/lib/common/pool.h +10 -4
  30. data/contrib/zstd/lib/common/portability_macros.h +156 -0
  31. data/contrib/zstd/lib/common/threading.c +74 -19
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +7 -847
  34. data/contrib/zstd/lib/common/xxhash.h +5568 -167
  35. data/contrib/zstd/lib/common/zstd_common.c +2 -37
  36. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  37. data/contrib/zstd/lib/common/zstd_internal.h +132 -187
  38. data/contrib/zstd/lib/common/zstd_trace.h +163 -0
  39. data/contrib/zstd/lib/compress/clevels.h +134 -0
  40. data/contrib/zstd/lib/compress/fse_compress.c +83 -157
  41. data/contrib/zstd/lib/compress/hist.c +27 -29
  42. data/contrib/zstd/lib/compress/hist.h +2 -2
  43. data/contrib/zstd/lib/compress/huf_compress.c +916 -279
  44. data/contrib/zstd/lib/compress/zstd_compress.c +3773 -1019
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +610 -203
  46. data/contrib/zstd/lib/compress/zstd_compress_literals.c +119 -42
  47. data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
  48. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +42 -19
  49. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
  50. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +49 -317
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +320 -103
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +388 -151
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +729 -265
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1270 -251
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +61 -1
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +324 -219
  60. data/contrib/zstd/lib/compress/zstd_ldm.h +9 -2
  61. data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  62. data/contrib/zstd/lib/compress/zstd_opt.c +481 -209
  63. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +181 -457
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +34 -113
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1199 -565
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -0
  68. data/contrib/zstd/lib/decompress/zstd_ddict.c +12 -12
  69. data/contrib/zstd/lib/decompress/zstd_ddict.h +2 -2
  70. data/contrib/zstd/lib/decompress/zstd_decompress.c +627 -157
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1086 -326
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +19 -5
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +62 -13
  74. data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
  75. data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
  76. data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
  77. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  78. data/contrib/zstd/lib/dictBuilder/cover.c +73 -52
  79. data/contrib/zstd/lib/dictBuilder/cover.h +7 -6
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +44 -35
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +103 -111
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +21 -54
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +29 -70
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +30 -73
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +29 -71
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +40 -86
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +47 -88
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +40 -83
  97. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  98. data/contrib/zstd/lib/libzstd.mk +214 -0
  99. data/contrib/zstd/lib/libzstd.pc.in +7 -6
  100. data/contrib/zstd/lib/module.modulemap +35 -0
  101. data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +203 -34
  102. data/contrib/zstd/lib/zstd.h +1217 -287
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +28 -8
  104. data/ext/extconf.rb +7 -6
  105. data/ext/extzstd.c +19 -10
  106. data/ext/extzstd.h +6 -0
  107. data/ext/libzstd_conf.h +0 -1
  108. data/ext/zstd_decompress_asm.S +1 -0
  109. data/gemstub.rb +3 -21
  110. data/lib/extzstd/version.rb +6 -1
  111. data/lib/extzstd.rb +0 -2
  112. data/test/test_basic.rb +0 -5
  113. metadata +18 -6
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -184,7 +184,7 @@ ZSTDLIBv07_API size_t ZSTDv07_insertBlock(ZSTDv07_DCtx* dctx, const void* blockS
184
184
  low-level memory access routines
185
185
  Copyright (C) 2013-2015, Yann Collet.
186
186
 
187
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
187
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
188
188
 
189
189
  Redistribution and use in source and binary forms, with or without
190
190
  modification, are permitted provided that the following conditions are
@@ -242,7 +242,11 @@ extern "C" {
242
242
  * Basic Types
243
243
  *****************************************************************/
244
244
  #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
245
- # include <stdint.h>
245
+ # if defined(_AIX)
246
+ # include <inttypes.h>
247
+ # else
248
+ # include <stdint.h> /* intptr_t */
249
+ # endif
246
250
  typedef uint8_t BYTE;
247
251
  typedef uint16_t U16;
248
252
  typedef int16_t S16;
@@ -264,27 +268,6 @@ extern "C" {
264
268
  /*-**************************************************************
265
269
  * Memory I/O
266
270
  *****************************************************************/
267
- /* MEM_FORCE_MEMORY_ACCESS :
268
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
269
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
270
- * The below switch allow to select different access method for improved performance.
271
- * Method 0 (default) : use `memcpy()`. Safe and portable.
272
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
273
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
274
- * Method 2 : direct access. This method is portable but violate C standard.
275
- * It can generate buggy code on targets depending on alignment.
276
- * In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
277
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
278
- * Prefer these methods in priority order (0 > 1 > 2)
279
- */
280
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
281
- # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
282
- # define MEM_FORCE_MEMORY_ACCESS 2
283
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
284
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
285
- # define MEM_FORCE_MEMORY_ACCESS 1
286
- # endif
287
- #endif
288
271
 
289
272
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
290
273
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
@@ -295,33 +278,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
295
278
  return one.c[0];
296
279
  }
297
280
 
298
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
299
-
300
- /* violates C standard, by lying on structure alignment.
301
- Only use if no other choice to achieve best performance on target platform */
302
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
303
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
304
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
305
-
306
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
307
-
308
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
309
-
310
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
311
- /* currently only defined for gcc and icc */
312
- typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
313
-
314
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
315
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
316
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
317
-
318
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
319
-
320
- #else
321
-
322
- /* default method, safe and standard.
323
- can sometimes prove slower */
324
-
325
281
  MEM_STATIC U16 MEM_read16(const void* memPtr)
326
282
  {
327
283
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -342,8 +298,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
342
298
  memcpy(memPtr, &value, sizeof(value));
343
299
  }
344
300
 
345
- #endif /* MEM_FORCE_MEMORY_ACCESS */
346
-
347
301
  MEM_STATIC U32 MEM_swap32(U32 in)
348
302
  {
349
303
  #if defined(_MSC_VER) /* Visual Studio */
@@ -438,7 +392,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
438
392
  header file (to include)
439
393
  Copyright (C) 2013-2016, Yann Collet.
440
394
 
441
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
395
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
442
396
 
443
397
  Redistribution and use in source and binary forms, with or without
444
398
  modification, are permitted provided that the following conditions are
@@ -526,9 +480,8 @@ MEM_STATIC size_t BITv07_readBitsFast(BITv07_DStream_t* bitD, unsigned nbBits);
526
480
  MEM_STATIC unsigned BITv07_highbit32 (U32 val)
527
481
  {
528
482
  # if defined(_MSC_VER) /* Visual */
529
- unsigned long r=0;
530
- _BitScanReverse ( &r, val );
531
- return (unsigned) r;
483
+ unsigned long r;
484
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
532
485
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
533
486
  return __builtin_clz (val) ^ 31;
534
487
  # else /* Software version */
@@ -596,7 +549,7 @@ MEM_STATIC size_t BITv07_initDStream(BITv07_DStream_t* bitD, const void* srcBuff
596
549
  }
597
550
 
598
551
  /*! BITv07_lookBitsFast() :
599
- * unsafe version; only works only if nbBits >= 1 */
552
+ * unsafe version; only works if nbBits >= 1 */
600
553
  MEM_STATIC size_t BITv07_lookBitsFast(const BITv07_DStream_t* bitD, U32 nbBits)
601
554
  {
602
555
  U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -616,7 +569,7 @@ MEM_STATIC size_t BITv07_readBits(BITv07_DStream_t* bitD, U32 nbBits)
616
569
  }
617
570
 
618
571
  /*! BITv07_readBitsFast() :
619
- * unsafe version; only works only if nbBits >= 1 */
572
+ * unsafe version; only works if nbBits >= 1 */
620
573
  MEM_STATIC size_t BITv07_readBitsFast(BITv07_DStream_t* bitD, U32 nbBits)
621
574
  {
622
575
  size_t const value = BITv07_lookBitsFast(bitD, nbBits);
@@ -670,7 +623,7 @@ MEM_STATIC unsigned BITv07_endOfDStream(const BITv07_DStream_t* DStream)
670
623
  Public Prototypes declaration
671
624
  Copyright (C) 2013-2016, Yann Collet.
672
625
 
673
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
626
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
674
627
 
675
628
  Redistribution and use in source and binary forms, with or without
676
629
  modification, are permitted provided that the following conditions are
@@ -978,7 +931,7 @@ MEM_STATIC BYTE FSEv07_decodeSymbolFast(FSEv07_DState_t* DStatePtr, BITv07_DStre
978
931
  header file
979
932
  Copyright (C) 2013-2016, Yann Collet.
980
933
 
981
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
934
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
982
935
 
983
936
  Redistribution and use in source and binary forms, with or without
984
937
  modification, are permitted provided that the following conditions are
@@ -1151,7 +1104,7 @@ size_t HUFv07_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void
1151
1104
  Common functions of New Generation Entropy library
1152
1105
  Copyright (C) 2016, Yann Collet.
1153
1106
 
1154
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1107
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1155
1108
 
1156
1109
  Redistribution and use in source and binary forms, with or without
1157
1110
  modification, are permitted provided that the following conditions are
@@ -1375,7 +1328,7 @@ size_t HUFv07_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
1375
1328
  FSE : Finite State Entropy decoder
1376
1329
  Copyright (C) 2013-2015, Yann Collet.
1377
1330
 
1378
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1331
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1379
1332
 
1380
1333
  Redistribution and use in source and binary forms, with or without
1381
1334
  modification, are permitted provided that the following conditions are
@@ -1699,7 +1652,7 @@ size_t FSEv07_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t
1699
1652
  Huffman decoder, part of New Generation Entropy library
1700
1653
  Copyright (C) 2013-2016, Yann Collet.
1701
1654
 
1702
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1655
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1703
1656
 
1704
1657
  Redistribution and use in source and binary forms, with or without
1705
1658
  modification, are permitted provided that the following conditions are
@@ -2577,7 +2530,7 @@ size_t HUFv07_decompress1X_DCtx (HUFv07_DTable* dctx, void* dst, size_t dstSize,
2577
2530
  Common functions of Zstd compression library
2578
2531
  Copyright (C) 2015-2016, Yann Collet.
2579
2532
 
2580
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2533
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2581
2534
 
2582
2535
  Redistribution and use in source and binary forms, with or without
2583
2536
  modification, are permitted provided that the following conditions are
@@ -2601,7 +2554,7 @@ size_t HUFv07_decompress1X_DCtx (HUFv07_DTable* dctx, void* dst, size_t dstSize,
2601
2554
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2602
2555
 
2603
2556
  You can contact the author at :
2604
- - zstd homepage : http://www.zstd.net/
2557
+ - zstd homepage : https://facebook.github.io/zstd/
2605
2558
  */
2606
2559
 
2607
2560
 
@@ -2647,7 +2600,7 @@ static void ZSTDv07_defaultFreeFunction(void* opaque, void* address)
2647
2600
  Header File for include
2648
2601
  Copyright (C) 2014-2016, Yann Collet.
2649
2602
 
2650
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2603
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2651
2604
 
2652
2605
  Redistribution and use in source and binary forms, with or without
2653
2606
  modification, are permitted provided that the following conditions are
@@ -2717,7 +2670,7 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
2717
2670
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
2718
2671
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
2719
2672
 
2720
- #define HufLog 12
2673
+ #define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
2721
2674
  typedef enum { lbt_huffman, lbt_repeat, lbt_raw, lbt_rle } litBlockType_t;
2722
2675
 
2723
2676
  #define LONGNBSEQ 0x7F00
@@ -2854,7 +2807,7 @@ static const ZSTDv07_customMem defaultCustomMem = { ZSTDv07_defaultAllocFunction
2854
2807
  zstd - standard compression library
2855
2808
  Copyright (C) 2014-2016, Yann Collet.
2856
2809
 
2857
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2810
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2858
2811
 
2859
2812
  Redistribution and use in source and binary forms, with or without
2860
2813
  modification, are permitted provided that the following conditions are
@@ -2878,7 +2831,7 @@ static const ZSTDv07_customMem defaultCustomMem = { ZSTDv07_defaultAllocFunction
2878
2831
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2879
2832
 
2880
2833
  You can contact the author at :
2881
- - zstd homepage : http://www.zstd.net
2834
+ - zstd homepage : https://facebook.github.io/zstd
2882
2835
  */
2883
2836
 
2884
2837
  /* ***************************************************************
@@ -2931,7 +2884,7 @@ struct ZSTDv07_DCtx_s
2931
2884
  FSEv07_DTable LLTable[FSEv07_DTABLE_SIZE_U32(LLFSELog)];
2932
2885
  FSEv07_DTable OffTable[FSEv07_DTABLE_SIZE_U32(OffFSELog)];
2933
2886
  FSEv07_DTable MLTable[FSEv07_DTABLE_SIZE_U32(MLFSELog)];
2934
- HUFv07_DTable hufTable[HUFv07_DTABLE_SIZE(HufLog)]; /* can accommodate HUFv07_decompress4X */
2887
+ HUFv07_DTable hufTable[HUFv07_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)]; /* can accommodate HUFv07_decompress4X */
2935
2888
  const void* previousDstEnd;
2936
2889
  const void* base;
2937
2890
  const void* vBase;
@@ -2967,7 +2920,7 @@ size_t ZSTDv07_decompressBegin(ZSTDv07_DCtx* dctx)
2967
2920
  dctx->base = NULL;
2968
2921
  dctx->vBase = NULL;
2969
2922
  dctx->dictEnd = NULL;
2970
- dctx->hufTable[0] = (HUFv07_DTable)((HufLog)*0x1000001);
2923
+ dctx->hufTable[0] = (HUFv07_DTable)((ZSTD_HUFFDTABLE_CAPACITY_LOG)*0x1000001);
2971
2924
  dctx->litEntropy = dctx->fseEntropy = 0;
2972
2925
  dctx->dictID = 0;
2973
2926
  { int i; for (i=0; i<ZSTDv07_REP_NUM; i++) dctx->rep[i] = repStartValue[i]; }
@@ -3254,7 +3207,7 @@ typedef struct
3254
3207
  * Provides the size of compressed block from block header `src` */
3255
3208
  static size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
3256
3209
  {
3257
- const BYTE* const in = (const BYTE* const)src;
3210
+ const BYTE* const in = (const BYTE*)src;
3258
3211
  U32 cSize;
3259
3212
 
3260
3213
  if (srcSize < ZSTDv07_blockHeaderSize) return ERROR(srcSize_wrong);
@@ -3449,7 +3402,7 @@ static size_t ZSTDv07_decodeSeqHeaders(int* nbSeqPtr,
3449
3402
  FSEv07_DTable* DTableLL, FSEv07_DTable* DTableML, FSEv07_DTable* DTableOffb, U32 flagRepeatTable,
3450
3403
  const void* src, size_t srcSize)
3451
3404
  {
3452
- const BYTE* const istart = (const BYTE* const)src;
3405
+ const BYTE* const istart = (const BYTE*)src;
3453
3406
  const BYTE* const iend = istart + srcSize;
3454
3407
  const BYTE* ip = istart;
3455
3408
 
@@ -3599,11 +3552,14 @@ size_t ZSTDv07_execSequence(BYTE* op,
3599
3552
  const BYTE* match = oLitEnd - sequence.offset;
3600
3553
 
3601
3554
  /* check */
3602
- if ((oLitEnd>oend_w) | (oMatchEnd>oend)) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
3603
- if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
3555
+ assert(oend >= op);
3556
+ if (sequence.litLength + WILDCOPY_OVERLENGTH > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
3557
+ if (sequenceLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
3558
+ assert(litLimit >= *litPtr);
3559
+ if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);;
3604
3560
 
3605
3561
  /* copy Literals */
3606
- ZSTDv07_wildcopy(op, *litPtr, sequence.litLength); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
3562
+ ZSTDv07_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */
3607
3563
  op = oLitEnd;
3608
3564
  *litPtr = iLitEnd; /* update for next sequence */
3609
3565
 
@@ -3617,7 +3573,7 @@ size_t ZSTDv07_execSequence(BYTE* op,
3617
3573
  return sequenceLength;
3618
3574
  }
3619
3575
  /* span extDict & currentPrefixSegment */
3620
- { size_t const length1 = dictEnd - match;
3576
+ { size_t const length1 = (size_t)(dictEnd - match);
3621
3577
  memmove(oLitEnd, match, length1);
3622
3578
  op = oLitEnd + length1;
3623
3579
  sequence.matchLength -= length1;
@@ -3668,7 +3624,7 @@ static size_t ZSTDv07_decompressSequences(
3668
3624
  {
3669
3625
  const BYTE* ip = (const BYTE*)seqStart;
3670
3626
  const BYTE* const iend = ip + seqSize;
3671
- BYTE* const ostart = (BYTE* const)dst;
3627
+ BYTE* const ostart = (BYTE*)dst;
3672
3628
  BYTE* const oend = ostart + maxDstSize;
3673
3629
  BYTE* op = ostart;
3674
3630
  const BYTE* litPtr = dctx->litPtr;
@@ -3795,7 +3751,7 @@ static size_t ZSTDv07_decompressFrame(ZSTDv07_DCtx* dctx,
3795
3751
  {
3796
3752
  const BYTE* ip = (const BYTE*)src;
3797
3753
  const BYTE* const iend = ip + srcSize;
3798
- BYTE* const ostart = (BYTE* const)dst;
3754
+ BYTE* const ostart = (BYTE*)dst;
3799
3755
  BYTE* const oend = ostart + dstCapacity;
3800
3756
  BYTE* op = ostart;
3801
3757
  size_t remainingSize = srcSize;
@@ -4253,7 +4209,7 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress_usingDDict(ZSTDv07_DCtx* dctx,
4253
4209
  Buffered version of Zstd compression library
4254
4210
  Copyright (C) 2015-2016, Yann Collet.
4255
4211
 
4256
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4212
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
4257
4213
 
4258
4214
  Redistribution and use in source and binary forms, with or without
4259
4215
  modification, are permitted provided that the following conditions are
@@ -4277,7 +4233,7 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress_usingDDict(ZSTDv07_DCtx* dctx,
4277
4233
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4278
4234
 
4279
4235
  You can contact the author at :
4280
- - zstd homepage : http://www.zstd.net/
4236
+ - zstd homepage : https://facebook.github.io/zstd/
4281
4237
  */
4282
4238
 
4283
4239
 
@@ -4417,7 +4373,8 @@ size_t ZBUFFv07_decompressContinue(ZBUFFv07_DCtx* zbd,
4417
4373
  if (hSize != 0) {
4418
4374
  size_t const toLoad = hSize - zbd->lhSize; /* if hSize!=0, hSize > zbd->lhSize */
4419
4375
  if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */
4420
- memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4376
+ if (ip != NULL)
4377
+ memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4421
4378
  zbd->lhSize += iend-ip;
4422
4379
  *dstCapacityPtr = 0;
4423
4380
  return (hSize - zbd->lhSize) + ZSTDv07_blockHeaderSize; /* remaining header bytes + next block header */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -0,0 +1,214 @@
1
+ # ################################################################
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ # All rights reserved.
4
+ #
5
+ # This source code is licensed under both the BSD-style license (found in the
6
+ # LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ # in the COPYING file in the root directory of this source tree).
8
+ # You may select, at your option, one of the above-listed licenses.
9
+ # ################################################################
10
+
11
+ ##################################################################
12
+ # Input Variables
13
+ ##################################################################
14
+
15
+ # Zstd lib directory
16
+ LIBZSTD ?= ./
17
+
18
+ # ZSTD_LIB_MINIFY is a helper variable that
19
+ # configures a bunch of other variables to space-optimized defaults.
20
+ ZSTD_LIB_MINIFY ?= 0
21
+
22
+ # Legacy support
23
+ ifneq ($(ZSTD_LIB_MINIFY), 0)
24
+ ZSTD_LEGACY_SUPPORT ?= 0
25
+ else
26
+ ZSTD_LEGACY_SUPPORT ?= 5
27
+ endif
28
+ ZSTD_LEGACY_MULTITHREADED_API ?= 0
29
+
30
+ # Build size optimizations
31
+ ifneq ($(ZSTD_LIB_MINIFY), 0)
32
+ HUF_FORCE_DECOMPRESS_X1 ?= 1
33
+ HUF_FORCE_DECOMPRESS_X2 ?= 0
34
+ ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ?= 1
35
+ ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG ?= 0
36
+ ZSTD_NO_INLINE ?= 1
37
+ ZSTD_STRIP_ERROR_STRINGS ?= 1
38
+ else
39
+ HUF_FORCE_DECOMPRESS_X1 ?= 0
40
+ HUF_FORCE_DECOMPRESS_X2 ?= 0
41
+ ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ?= 0
42
+ ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG ?= 0
43
+ ZSTD_NO_INLINE ?= 0
44
+ ZSTD_STRIP_ERROR_STRINGS ?= 0
45
+ endif
46
+
47
+ # Assembly support
48
+ ZSTD_NO_ASM ?= 0
49
+
50
+ ##################################################################
51
+ # libzstd helpers
52
+ ##################################################################
53
+
54
+ VOID ?= /dev/null
55
+
56
+ # Make 4.3 doesn't support '\#' anymore (https://lwn.net/Articles/810071/)
57
+ NUM_SYMBOL := \#
58
+
59
+ # define silent mode as default (verbose mode with V=1 or VERBOSE=1)
60
+ $(V)$(VERBOSE).SILENT:
61
+
62
+ # When cross-compiling from linux to windows,
63
+ # one might need to specify TARGET_SYSTEM as "Windows."
64
+ # Building from Fedora fails without it.
65
+ # (but Ubuntu and Debian don't need to set anything)
66
+ TARGET_SYSTEM ?= $(OS)
67
+
68
+ # Version numbers
69
+ LIBVER_SRC := $(LIBZSTD)/zstd.h
70
+ LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
71
+ LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
72
+ LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
73
+ LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
74
+ LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
75
+ LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
76
+ LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
77
+ LIBVER := $(shell echo $(LIBVER_SCRIPT))
78
+ CCVER := $(shell $(CC) --version)
79
+ ZSTD_VERSION?= $(LIBVER)
80
+
81
+ ifneq ($(ZSTD_LIB_MINIFY), 0)
82
+ HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
83
+ ifneq ($(HAVE_CC_OZ), 0)
84
+ # Some compilers (clang) support an even more space-optimized setting.
85
+ CFLAGS += -Oz
86
+ else
87
+ CFLAGS += -Os
88
+ endif
89
+ CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
90
+ -DDYNAMIC_BMI2=0 -DNDEBUG
91
+ else
92
+ CFLAGS ?= -O3
93
+ endif
94
+
95
+ DEBUGLEVEL ?= 0
96
+ CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
97
+ ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
98
+ CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
99
+ endif
100
+ DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
101
+ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
102
+ -Wstrict-prototypes -Wundef -Wpointer-arith \
103
+ -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
104
+ -Wredundant-decls -Wmissing-prototypes -Wc++-compat
105
+ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
106
+ ASFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) $(CFLAGS)
107
+ LDFLAGS += $(MOREFLAGS)
108
+ FLAGS = $(CPPFLAGS) $(CFLAGS) $(ASFLAGS) $(LDFLAGS)
109
+
110
+ ifndef ALREADY_APPENDED_NOEXECSTACK
111
+ export ALREADY_APPENDED_NOEXECSTACK := 1
112
+ ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) $(FLAGS) -z noexecstack -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
113
+ LDFLAGS += -z noexecstack
114
+ endif
115
+ ifeq ($(shell echo | $(CC) $(FLAGS) -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
116
+ CFLAGS += -Wa,--noexecstack
117
+ # CFLAGS are also added to ASFLAGS
118
+ else ifeq ($(shell echo | $(CC) $(FLAGS) -Qunused-arguments -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
119
+ # See e.g.: https://github.com/android/ndk/issues/171
120
+ CFLAGS += -Qunused-arguments -Wa,--noexecstack
121
+ # CFLAGS are also added to ASFLAGS
122
+ endif
123
+ endif
124
+
125
+ ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) $(FLAGS) -z cet-report=error -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
126
+ LDFLAGS += -z cet-report=error
127
+ endif
128
+
129
+ HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
130
+ GREP_OPTIONS ?=
131
+ ifeq ($(HAVE_COLORNEVER), 1)
132
+ GREP_OPTIONS += --color=never
133
+ endif
134
+ GREP = grep $(GREP_OPTIONS)
135
+
136
+ ZSTD_COMMON_FILES := $(sort $(wildcard $(LIBZSTD)/common/*.c))
137
+ ZSTD_COMPRESS_FILES := $(sort $(wildcard $(LIBZSTD)/compress/*.c))
138
+ ZSTD_DECOMPRESS_FILES := $(sort $(wildcard $(LIBZSTD)/decompress/*.c))
139
+ ZSTD_DICTBUILDER_FILES := $(sort $(wildcard $(LIBZSTD)/dictBuilder/*.c))
140
+ ZSTD_DEPRECATED_FILES := $(sort $(wildcard $(LIBZSTD)/deprecated/*.c))
141
+ ZSTD_LEGACY_FILES :=
142
+
143
+ ZSTD_DECOMPRESS_AMD64_ASM_FILES := $(sort $(wildcard $(LIBZSTD)/decompress/*_amd64.S))
144
+
145
+ ifneq ($(ZSTD_NO_ASM), 0)
146
+ CPPFLAGS += -DZSTD_DISABLE_ASM
147
+ else
148
+ # Unconditionally add the ASM files they are disabled by
149
+ # macros in the .S file.
150
+ ZSTD_DECOMPRESS_FILES += $(ZSTD_DECOMPRESS_AMD64_ASM_FILES)
151
+ endif
152
+
153
+ ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
154
+ CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
155
+ endif
156
+
157
+ ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
158
+ CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
159
+ endif
160
+
161
+ ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT), 0)
162
+ CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT
163
+ endif
164
+
165
+ ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG), 0)
166
+ CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
167
+ endif
168
+
169
+ ifneq ($(ZSTD_NO_INLINE), 0)
170
+ CFLAGS += -DZSTD_NO_INLINE
171
+ endif
172
+
173
+ ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
174
+ CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
175
+ endif
176
+
177
+ ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
178
+ CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
179
+ endif
180
+
181
+ ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
182
+ ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
183
+ ZSTD_LEGACY_FILES += $(shell ls $(LIBZSTD)/legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
184
+ endif
185
+ endif
186
+ CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
187
+
188
+ UNAME := $(shell uname)
189
+
190
+ ifndef BUILD_DIR
191
+ ifeq ($(UNAME), Darwin)
192
+ ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
193
+ HASH ?= md5
194
+ endif
195
+ else ifeq ($(UNAME), FreeBSD)
196
+ HASH ?= gmd5sum
197
+ else ifeq ($(UNAME), NetBSD)
198
+ HASH ?= md5 -n
199
+ else ifeq ($(UNAME), OpenBSD)
200
+ HASH ?= md5
201
+ endif
202
+ HASH ?= md5sum
203
+
204
+ HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
205
+ HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
206
+ ifeq ($(HAVE_HASH),0)
207
+ $(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
208
+ BUILD_DIR := obj/generic_noconf
209
+ endif
210
+ endif # BUILD_DIR
211
+
212
+ ZSTD_SUBDIR := $(LIBZSTD)/common $(LIBZSTD)/compress $(LIBZSTD)/decompress $(LIBZSTD)/dictBuilder $(LIBZSTD)/legacy $(LIBZSTD)/deprecated
213
+ vpath %.c $(ZSTD_SUBDIR)
214
+ vpath %.S $(ZSTD_SUBDIR)
@@ -1,15 +1,16 @@
1
1
  # ZSTD - standard compression algorithm
2
- # Copyright (C) 2014-2016, Yann Collet, Facebook
3
- # BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ # BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
4
4
 
5
5
  prefix=@PREFIX@
6
- exec_prefix=${prefix}
7
- includedir=${prefix}/@INCLUDEDIR@
8
- libdir=${exec_prefix}/@LIBDIR@
6
+ exec_prefix=@EXEC_PREFIX@
7
+ includedir=@INCLUDEDIR@
8
+ libdir=@LIBDIR@
9
9
 
10
10
  Name: zstd
11
11
  Description: fast lossless compression algorithm library
12
- URL: http://www.zstd.net/
12
+ URL: https://facebook.github.io/zstd/
13
13
  Version: @VERSION@
14
14
  Libs: -L${libdir} -lzstd
15
+ Libs.private: @LIBS_PRIVATE@
15
16
  Cflags: -I${includedir}
@@ -0,0 +1,35 @@
1
+ module libzstd [extern_c] {
2
+ header "zstd.h"
3
+ export *
4
+ config_macros [exhaustive] \
5
+ /* zstd.h */ \
6
+ ZSTD_STATIC_LINKING_ONLY, \
7
+ ZSTDLIB_VISIBILITY, \
8
+ ZSTDLIB_VISIBLE, \
9
+ ZSTDLIB_HIDDEN, \
10
+ ZSTD_DLL_EXPORT, \
11
+ ZSTDLIB_STATIC_API, \
12
+ ZSTD_DISABLE_DEPRECATE_WARNINGS, \
13
+ ZSTD_CLEVEL_DEFAULT, \
14
+ /* zdict.h */ \
15
+ ZDICT_STATIC_LINKING_ONLY, \
16
+ ZDICTLIB_VISIBLE, \
17
+ ZDICTLIB_HIDDEN, \
18
+ ZDICTLIB_VISIBILITY, \
19
+ ZDICTLIB_STATIC_API, \
20
+ ZDICT_DISABLE_DEPRECATE_WARNINGS, \
21
+ /* zstd_errors.h */ \
22
+ ZSTDERRORLIB_VISIBLE, \
23
+ ZSTDERRORLIB_HIDDEN, \
24
+ ZSTDERRORLIB_VISIBILITY
25
+
26
+ module dictbuilder [extern_c] {
27
+ header "zdict.h"
28
+ export *
29
+ }
30
+
31
+ module errors [extern_c] {
32
+ header "zstd_errors.h"
33
+ export *
34
+ }
35
+ }