extzstd 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/contrib/zstd/CHANGELOG +188 -1
  4. data/contrib/zstd/CONTRIBUTING.md +157 -74
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +81 -58
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +59 -35
  9. data/contrib/zstd/TESTING.md +2 -3
  10. data/contrib/zstd/appveyor.yml +49 -136
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +87 -181
  13. data/contrib/zstd/lib/README.md +23 -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 +33 -59
  17. data/contrib/zstd/lib/common/compiler.h +115 -45
  18. data/contrib/zstd/lib/common/cpu.h +1 -1
  19. data/contrib/zstd/lib/common/debug.c +1 -1
  20. data/contrib/zstd/lib/common/debug.h +1 -1
  21. data/contrib/zstd/lib/common/entropy_common.c +15 -37
  22. data/contrib/zstd/lib/common/error_private.c +9 -2
  23. data/contrib/zstd/lib/common/error_private.h +82 -3
  24. data/contrib/zstd/lib/common/fse.h +9 -85
  25. data/contrib/zstd/lib/common/fse_decompress.c +29 -111
  26. data/contrib/zstd/lib/common/huf.h +84 -172
  27. data/contrib/zstd/lib/common/mem.h +58 -49
  28. data/contrib/zstd/lib/common/pool.c +37 -16
  29. data/contrib/zstd/lib/common/pool.h +9 -3
  30. data/contrib/zstd/lib/common/portability_macros.h +156 -0
  31. data/contrib/zstd/lib/common/threading.c +68 -14
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +7 -809
  34. data/contrib/zstd/lib/common/xxhash.h +5568 -167
  35. data/contrib/zstd/lib/common/zstd_common.c +1 -36
  36. data/contrib/zstd/lib/common/zstd_deps.h +1 -1
  37. data/contrib/zstd/lib/common/zstd_internal.h +64 -150
  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 +69 -150
  41. data/contrib/zstd/lib/compress/hist.c +1 -1
  42. data/contrib/zstd/lib/compress/hist.h +1 -1
  43. data/contrib/zstd/lib/compress/huf_compress.c +773 -251
  44. data/contrib/zstd/lib/compress/zstd_compress.c +2650 -826
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +509 -180
  46. data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
  47. data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
  48. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
  49. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
  50. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +33 -305
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +266 -85
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +369 -132
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +722 -258
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1105 -360
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +41 -1
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +272 -208
  60. data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
  61. data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  62. data/contrib/zstd/lib/compress/zstd_opt.c +324 -197
  63. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +109 -53
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1071 -539
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -0
  68. data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
  69. data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
  70. data/contrib/zstd/lib/decompress/zstd_decompress.c +507 -82
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +962 -310
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +54 -6
  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 +44 -32
  79. data/contrib/zstd/lib/dictBuilder/cover.h +6 -5
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +24 -16
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +88 -95
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +16 -53
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +24 -69
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +25 -72
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +23 -69
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +35 -85
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +42 -87
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +35 -82
  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 +4 -3
  100. data/contrib/zstd/lib/module.modulemap +35 -0
  101. data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
  102. data/contrib/zstd/lib/zstd.h +922 -293
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
  104. data/ext/extconf.rb +7 -6
  105. data/ext/extzstd.c +13 -10
  106. data/ext/libzstd_conf.h +0 -1
  107. data/ext/zstd_decompress_asm.S +1 -0
  108. metadata +16 -5
@@ -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
@@ -268,27 +268,6 @@ extern "C" {
268
268
  /*-**************************************************************
269
269
  * Memory I/O
270
270
  *****************************************************************/
271
- /* MEM_FORCE_MEMORY_ACCESS :
272
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
273
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
274
- * The below switch allow to select different access method for improved performance.
275
- * Method 0 (default) : use `memcpy()`. Safe and portable.
276
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
277
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
278
- * Method 2 : direct access. This method is portable but violate C standard.
279
- * It can generate buggy code on targets depending on alignment.
280
- * In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
281
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
282
- * Prefer these methods in priority order (0 > 1 > 2)
283
- */
284
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
285
- # 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__) )
286
- # define MEM_FORCE_MEMORY_ACCESS 2
287
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
288
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
289
- # define MEM_FORCE_MEMORY_ACCESS 1
290
- # endif
291
- #endif
292
271
 
293
272
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
294
273
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
@@ -299,33 +278,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
299
278
  return one.c[0];
300
279
  }
301
280
 
302
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
303
-
304
- /* violates C standard, by lying on structure alignment.
305
- Only use if no other choice to achieve best performance on target platform */
306
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
307
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
308
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
309
-
310
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
311
-
312
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
313
-
314
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
315
- /* currently only defined for gcc and icc */
316
- typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
317
-
318
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
319
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
320
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
321
-
322
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
323
-
324
- #else
325
-
326
- /* default method, safe and standard.
327
- can sometimes prove slower */
328
-
329
281
  MEM_STATIC U16 MEM_read16(const void* memPtr)
330
282
  {
331
283
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -346,8 +298,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
346
298
  memcpy(memPtr, &value, sizeof(value));
347
299
  }
348
300
 
349
- #endif /* MEM_FORCE_MEMORY_ACCESS */
350
-
351
301
  MEM_STATIC U32 MEM_swap32(U32 in)
352
302
  {
353
303
  #if defined(_MSC_VER) /* Visual Studio */
@@ -442,7 +392,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
442
392
  header file (to include)
443
393
  Copyright (C) 2013-2016, Yann Collet.
444
394
 
445
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
395
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
446
396
 
447
397
  Redistribution and use in source and binary forms, with or without
448
398
  modification, are permitted provided that the following conditions are
@@ -530,9 +480,8 @@ MEM_STATIC size_t BITv07_readBitsFast(BITv07_DStream_t* bitD, unsigned nbBits);
530
480
  MEM_STATIC unsigned BITv07_highbit32 (U32 val)
531
481
  {
532
482
  # if defined(_MSC_VER) /* Visual */
533
- unsigned long r=0;
534
- _BitScanReverse ( &r, val );
535
- return (unsigned) r;
483
+ unsigned long r;
484
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
536
485
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
537
486
  return __builtin_clz (val) ^ 31;
538
487
  # else /* Software version */
@@ -600,7 +549,7 @@ MEM_STATIC size_t BITv07_initDStream(BITv07_DStream_t* bitD, const void* srcBuff
600
549
  }
601
550
 
602
551
  /*! BITv07_lookBitsFast() :
603
- * unsafe version; only works only if nbBits >= 1 */
552
+ * unsafe version; only works if nbBits >= 1 */
604
553
  MEM_STATIC size_t BITv07_lookBitsFast(const BITv07_DStream_t* bitD, U32 nbBits)
605
554
  {
606
555
  U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -620,7 +569,7 @@ MEM_STATIC size_t BITv07_readBits(BITv07_DStream_t* bitD, U32 nbBits)
620
569
  }
621
570
 
622
571
  /*! BITv07_readBitsFast() :
623
- * unsafe version; only works only if nbBits >= 1 */
572
+ * unsafe version; only works if nbBits >= 1 */
624
573
  MEM_STATIC size_t BITv07_readBitsFast(BITv07_DStream_t* bitD, U32 nbBits)
625
574
  {
626
575
  size_t const value = BITv07_lookBitsFast(bitD, nbBits);
@@ -674,7 +623,7 @@ MEM_STATIC unsigned BITv07_endOfDStream(const BITv07_DStream_t* DStream)
674
623
  Public Prototypes declaration
675
624
  Copyright (C) 2013-2016, Yann Collet.
676
625
 
677
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
626
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
678
627
 
679
628
  Redistribution and use in source and binary forms, with or without
680
629
  modification, are permitted provided that the following conditions are
@@ -982,7 +931,7 @@ MEM_STATIC BYTE FSEv07_decodeSymbolFast(FSEv07_DState_t* DStatePtr, BITv07_DStre
982
931
  header file
983
932
  Copyright (C) 2013-2016, Yann Collet.
984
933
 
985
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
934
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
986
935
 
987
936
  Redistribution and use in source and binary forms, with or without
988
937
  modification, are permitted provided that the following conditions are
@@ -1155,7 +1104,7 @@ size_t HUFv07_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void
1155
1104
  Common functions of New Generation Entropy library
1156
1105
  Copyright (C) 2016, Yann Collet.
1157
1106
 
1158
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1107
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1159
1108
 
1160
1109
  Redistribution and use in source and binary forms, with or without
1161
1110
  modification, are permitted provided that the following conditions are
@@ -1379,7 +1328,7 @@ size_t HUFv07_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
1379
1328
  FSE : Finite State Entropy decoder
1380
1329
  Copyright (C) 2013-2015, Yann Collet.
1381
1330
 
1382
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1331
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1383
1332
 
1384
1333
  Redistribution and use in source and binary forms, with or without
1385
1334
  modification, are permitted provided that the following conditions are
@@ -1703,7 +1652,7 @@ size_t FSEv07_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t
1703
1652
  Huffman decoder, part of New Generation Entropy library
1704
1653
  Copyright (C) 2013-2016, Yann Collet.
1705
1654
 
1706
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1655
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1707
1656
 
1708
1657
  Redistribution and use in source and binary forms, with or without
1709
1658
  modification, are permitted provided that the following conditions are
@@ -2581,7 +2530,7 @@ size_t HUFv07_decompress1X_DCtx (HUFv07_DTable* dctx, void* dst, size_t dstSize,
2581
2530
  Common functions of Zstd compression library
2582
2531
  Copyright (C) 2015-2016, Yann Collet.
2583
2532
 
2584
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2533
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2585
2534
 
2586
2535
  Redistribution and use in source and binary forms, with or without
2587
2536
  modification, are permitted provided that the following conditions are
@@ -2605,7 +2554,7 @@ size_t HUFv07_decompress1X_DCtx (HUFv07_DTable* dctx, void* dst, size_t dstSize,
2605
2554
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2606
2555
 
2607
2556
  You can contact the author at :
2608
- - zstd homepage : http://www.zstd.net/
2557
+ - zstd homepage : https://facebook.github.io/zstd/
2609
2558
  */
2610
2559
 
2611
2560
 
@@ -2651,7 +2600,7 @@ static void ZSTDv07_defaultFreeFunction(void* opaque, void* address)
2651
2600
  Header File for include
2652
2601
  Copyright (C) 2014-2016, Yann Collet.
2653
2602
 
2654
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2603
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2655
2604
 
2656
2605
  Redistribution and use in source and binary forms, with or without
2657
2606
  modification, are permitted provided that the following conditions are
@@ -2721,7 +2670,7 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
2721
2670
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
2722
2671
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
2723
2672
 
2724
- #define HufLog 12
2673
+ #define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
2725
2674
  typedef enum { lbt_huffman, lbt_repeat, lbt_raw, lbt_rle } litBlockType_t;
2726
2675
 
2727
2676
  #define LONGNBSEQ 0x7F00
@@ -2858,7 +2807,7 @@ static const ZSTDv07_customMem defaultCustomMem = { ZSTDv07_defaultAllocFunction
2858
2807
  zstd - standard compression library
2859
2808
  Copyright (C) 2014-2016, Yann Collet.
2860
2809
 
2861
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2810
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2862
2811
 
2863
2812
  Redistribution and use in source and binary forms, with or without
2864
2813
  modification, are permitted provided that the following conditions are
@@ -2882,7 +2831,7 @@ static const ZSTDv07_customMem defaultCustomMem = { ZSTDv07_defaultAllocFunction
2882
2831
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2883
2832
 
2884
2833
  You can contact the author at :
2885
- - zstd homepage : http://www.zstd.net
2834
+ - zstd homepage : https://facebook.github.io/zstd
2886
2835
  */
2887
2836
 
2888
2837
  /* ***************************************************************
@@ -2935,7 +2884,7 @@ struct ZSTDv07_DCtx_s
2935
2884
  FSEv07_DTable LLTable[FSEv07_DTABLE_SIZE_U32(LLFSELog)];
2936
2885
  FSEv07_DTable OffTable[FSEv07_DTABLE_SIZE_U32(OffFSELog)];
2937
2886
  FSEv07_DTable MLTable[FSEv07_DTABLE_SIZE_U32(MLFSELog)];
2938
- 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 */
2939
2888
  const void* previousDstEnd;
2940
2889
  const void* base;
2941
2890
  const void* vBase;
@@ -2971,7 +2920,7 @@ size_t ZSTDv07_decompressBegin(ZSTDv07_DCtx* dctx)
2971
2920
  dctx->base = NULL;
2972
2921
  dctx->vBase = NULL;
2973
2922
  dctx->dictEnd = NULL;
2974
- dctx->hufTable[0] = (HUFv07_DTable)((HufLog)*0x1000001);
2923
+ dctx->hufTable[0] = (HUFv07_DTable)((ZSTD_HUFFDTABLE_CAPACITY_LOG)*0x1000001);
2975
2924
  dctx->litEntropy = dctx->fseEntropy = 0;
2976
2925
  dctx->dictID = 0;
2977
2926
  { int i; for (i=0; i<ZSTDv07_REP_NUM; i++) dctx->rep[i] = repStartValue[i]; }
@@ -3258,7 +3207,7 @@ typedef struct
3258
3207
  * Provides the size of compressed block from block header `src` */
3259
3208
  static size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
3260
3209
  {
3261
- const BYTE* const in = (const BYTE* const)src;
3210
+ const BYTE* const in = (const BYTE*)src;
3262
3211
  U32 cSize;
3263
3212
 
3264
3213
  if (srcSize < ZSTDv07_blockHeaderSize) return ERROR(srcSize_wrong);
@@ -3453,7 +3402,7 @@ static size_t ZSTDv07_decodeSeqHeaders(int* nbSeqPtr,
3453
3402
  FSEv07_DTable* DTableLL, FSEv07_DTable* DTableML, FSEv07_DTable* DTableOffb, U32 flagRepeatTable,
3454
3403
  const void* src, size_t srcSize)
3455
3404
  {
3456
- const BYTE* const istart = (const BYTE* const)src;
3405
+ const BYTE* const istart = (const BYTE*)src;
3457
3406
  const BYTE* const iend = istart + srcSize;
3458
3407
  const BYTE* ip = istart;
3459
3408
 
@@ -3603,11 +3552,14 @@ size_t ZSTDv07_execSequence(BYTE* op,
3603
3552
  const BYTE* match = oLitEnd - sequence.offset;
3604
3553
 
3605
3554
  /* check */
3606
- if ((oLitEnd>oend_w) | (oMatchEnd>oend)) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */
3607
- 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);;
3608
3560
 
3609
3561
  /* copy Literals */
3610
- 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 */
3611
3563
  op = oLitEnd;
3612
3564
  *litPtr = iLitEnd; /* update for next sequence */
3613
3565
 
@@ -3621,7 +3573,7 @@ size_t ZSTDv07_execSequence(BYTE* op,
3621
3573
  return sequenceLength;
3622
3574
  }
3623
3575
  /* span extDict & currentPrefixSegment */
3624
- { size_t const length1 = dictEnd - match;
3576
+ { size_t const length1 = (size_t)(dictEnd - match);
3625
3577
  memmove(oLitEnd, match, length1);
3626
3578
  op = oLitEnd + length1;
3627
3579
  sequence.matchLength -= length1;
@@ -3672,7 +3624,7 @@ static size_t ZSTDv07_decompressSequences(
3672
3624
  {
3673
3625
  const BYTE* ip = (const BYTE*)seqStart;
3674
3626
  const BYTE* const iend = ip + seqSize;
3675
- BYTE* const ostart = (BYTE* const)dst;
3627
+ BYTE* const ostart = (BYTE*)dst;
3676
3628
  BYTE* const oend = ostart + maxDstSize;
3677
3629
  BYTE* op = ostart;
3678
3630
  const BYTE* litPtr = dctx->litPtr;
@@ -3799,7 +3751,7 @@ static size_t ZSTDv07_decompressFrame(ZSTDv07_DCtx* dctx,
3799
3751
  {
3800
3752
  const BYTE* ip = (const BYTE*)src;
3801
3753
  const BYTE* const iend = ip + srcSize;
3802
- BYTE* const ostart = (BYTE* const)dst;
3754
+ BYTE* const ostart = (BYTE*)dst;
3803
3755
  BYTE* const oend = ostart + dstCapacity;
3804
3756
  BYTE* op = ostart;
3805
3757
  size_t remainingSize = srcSize;
@@ -4257,7 +4209,7 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress_usingDDict(ZSTDv07_DCtx* dctx,
4257
4209
  Buffered version of Zstd compression library
4258
4210
  Copyright (C) 2015-2016, Yann Collet.
4259
4211
 
4260
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4212
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
4261
4213
 
4262
4214
  Redistribution and use in source and binary forms, with or without
4263
4215
  modification, are permitted provided that the following conditions are
@@ -4281,7 +4233,7 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress_usingDDict(ZSTDv07_DCtx* dctx,
4281
4233
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4282
4234
 
4283
4235
  You can contact the author at :
4284
- - zstd homepage : http://www.zstd.net/
4236
+ - zstd homepage : https://facebook.github.io/zstd/
4285
4237
  */
4286
4238
 
4287
4239
 
@@ -4421,7 +4373,8 @@ size_t ZBUFFv07_decompressContinue(ZBUFFv07_DCtx* zbd,
4421
4373
  if (hSize != 0) {
4422
4374
  size_t const toLoad = hSize - zbd->lhSize; /* if hSize!=0, hSize > zbd->lhSize */
4423
4375
  if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */
4424
- memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4376
+ if (ip != NULL)
4377
+ memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4425
4378
  zbd->lhSize += iend-ip;
4426
4379
  *dstCapacityPtr = 0;
4427
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,6 +1,6 @@
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
6
  exec_prefix=@EXEC_PREFIX@
@@ -9,7 +9,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
+ }