zstd-ruby 1.4.4.0 → 1.5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +8 -0
  3. data/.github/workflows/ruby.yml +35 -0
  4. data/README.md +2 -2
  5. data/ext/zstdruby/extconf.rb +1 -0
  6. data/ext/zstdruby/libzstd/BUCK +5 -7
  7. data/ext/zstdruby/libzstd/Makefile +241 -173
  8. data/ext/zstdruby/libzstd/README.md +76 -18
  9. data/ext/zstdruby/libzstd/common/bitstream.h +75 -57
  10. data/ext/zstdruby/libzstd/common/compiler.h +196 -20
  11. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  12. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  13. data/ext/zstdruby/libzstd/common/debug.h +22 -49
  14. data/ext/zstdruby/libzstd/common/entropy_common.c +208 -76
  15. data/ext/zstdruby/libzstd/common/error_private.c +3 -1
  16. data/ext/zstdruby/libzstd/common/error_private.h +87 -4
  17. data/ext/zstdruby/libzstd/common/fse.h +51 -42
  18. data/ext/zstdruby/libzstd/common/fse_decompress.c +149 -57
  19. data/ext/zstdruby/libzstd/common/huf.h +60 -54
  20. data/ext/zstdruby/libzstd/common/mem.h +87 -98
  21. data/ext/zstdruby/libzstd/common/pool.c +23 -17
  22. data/ext/zstdruby/libzstd/common/pool.h +3 -3
  23. data/ext/zstdruby/libzstd/common/portability_macros.h +131 -0
  24. data/ext/zstdruby/libzstd/common/threading.c +10 -8
  25. data/ext/zstdruby/libzstd/common/threading.h +4 -3
  26. data/ext/zstdruby/libzstd/common/xxhash.c +15 -873
  27. data/ext/zstdruby/libzstd/common/xxhash.h +5572 -191
  28. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  29. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  30. data/ext/zstdruby/libzstd/common/zstd_internal.h +252 -108
  31. data/ext/zstdruby/libzstd/common/zstd_trace.h +163 -0
  32. data/ext/zstdruby/libzstd/compress/clevels.h +134 -0
  33. data/ext/zstdruby/libzstd/compress/fse_compress.c +105 -85
  34. data/ext/zstdruby/libzstd/compress/hist.c +41 -63
  35. data/ext/zstdruby/libzstd/compress/hist.h +13 -33
  36. data/ext/zstdruby/libzstd/compress/huf_compress.c +831 -259
  37. data/ext/zstdruby/libzstd/compress/zstd_compress.c +3213 -1007
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +493 -71
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +21 -16
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +4 -2
  41. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +51 -24
  42. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +10 -3
  43. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +573 -0
  44. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  45. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +208 -81
  46. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +315 -137
  47. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  48. data/ext/zstdruby/libzstd/compress/zstd_fast.c +319 -128
  49. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  50. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +1156 -171
  51. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +59 -1
  52. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +331 -206
  53. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +15 -3
  54. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +106 -0
  55. data/ext/zstdruby/libzstd/compress/zstd_opt.c +403 -226
  56. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  57. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +188 -453
  58. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +32 -114
  59. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +1065 -410
  60. data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +571 -0
  61. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +20 -16
  62. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +3 -3
  63. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +691 -230
  64. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +1072 -323
  65. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +16 -7
  66. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +71 -10
  67. data/ext/zstdruby/libzstd/deprecated/zbuff.h +3 -3
  68. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
  69. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +24 -4
  70. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  71. data/ext/zstdruby/libzstd/dictBuilder/cover.c +57 -40
  72. data/ext/zstdruby/libzstd/dictBuilder/cover.h +20 -9
  73. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  74. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +54 -35
  75. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +151 -57
  76. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  77. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  78. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +4 -4
  79. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +25 -19
  80. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  81. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +18 -14
  82. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  83. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +18 -14
  84. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  85. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +22 -16
  86. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  87. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +29 -25
  88. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
  89. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +29 -25
  90. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  91. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +34 -26
  92. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  93. data/ext/zstdruby/libzstd/libzstd.mk +185 -0
  94. data/ext/zstdruby/libzstd/libzstd.pc.in +4 -3
  95. data/ext/zstdruby/libzstd/modulemap/module.modulemap +4 -0
  96. data/ext/zstdruby/libzstd/{dictBuilder/zdict.h → zdict.h} +201 -31
  97. data/ext/zstdruby/libzstd/zstd.h +760 -234
  98. data/ext/zstdruby/libzstd/{common/zstd_errors.h → zstd_errors.h} +3 -1
  99. data/ext/zstdruby/zstdruby.c +2 -2
  100. data/lib/zstd-ruby/version.rb +1 -1
  101. metadata +20 -9
  102. data/.travis.yml +0 -14
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 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
@@ -11,7 +11,7 @@
11
11
 
12
12
  /*- Dependencies -*/
13
13
  #include "zstd_v05.h"
14
- #include "error_private.h"
14
+ #include "../common/error_private.h"
15
15
 
16
16
 
17
17
  /* ******************************************************************
@@ -80,7 +80,11 @@ extern "C" {
80
80
  * Basic Types
81
81
  *****************************************************************/
82
82
  #if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
83
- # include <stdint.h>
83
+ # if defined(_AIX)
84
+ # include <inttypes.h>
85
+ # else
86
+ # include <stdint.h> /* intptr_t */
87
+ # endif
84
88
  typedef uint8_t BYTE;
85
89
  typedef uint16_t U16;
86
90
  typedef int16_t S16;
@@ -116,10 +120,7 @@ extern "C" {
116
120
  * Prefer these methods in priority order (0 > 1 > 2)
117
121
  */
118
122
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
119
- # 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__) )
120
- # define MEM_FORCE_MEMORY_ACCESS 2
121
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
122
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
123
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
123
124
  # define MEM_FORCE_MEMORY_ACCESS 1
124
125
  # endif
125
126
  #endif
@@ -752,9 +753,8 @@ MEM_STATIC size_t BITv05_readBitsFast(BITv05_DStream_t* bitD, unsigned nbBits);
752
753
  MEM_STATIC unsigned BITv05_highbit32 (U32 val)
753
754
  {
754
755
  # if defined(_MSC_VER) /* Visual */
755
- unsigned long r=0;
756
- _BitScanReverse ( &r, val );
757
- return (unsigned) r;
756
+ unsigned long r;
757
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
758
758
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
759
759
  return __builtin_clz (val) ^ 31;
760
760
  # else /* Software version */
@@ -1804,7 +1804,7 @@ static size_t HUFv05_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
1804
1804
 
1805
1805
  if (!srcSize) return ERROR(srcSize_wrong);
1806
1806
  iSize = ip[0];
1807
- //memset(huffWeight, 0, hwSize); /* is not necessary, even though some analyzer complain ... */
1807
+ /* memset(huffWeight, 0, hwSize); */ /* is not necessary, even though some analyzer complain ... */
1808
1808
 
1809
1809
  if (iSize >= 128) { /* special header */
1810
1810
  if (iSize >= (242)) { /* RLE */
@@ -1879,7 +1879,7 @@ size_t HUFv05_readDTableX2 (U16* DTable, const void* src, size_t srcSize)
1879
1879
  HUFv05_DEltX2* const dt = (HUFv05_DEltX2*)dtPtr;
1880
1880
 
1881
1881
  HUFv05_STATIC_ASSERT(sizeof(HUFv05_DEltX2) == sizeof(U16)); /* if compilation fails here, assertion is false */
1882
- //memset(huffWeight, 0, sizeof(huffWeight)); /* is not necessary, even though some analyzer complain ... */
1882
+ /* memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */
1883
1883
 
1884
1884
  iSize = HUFv05_readStats(huffWeight, HUFv05_MAX_SYMBOL_VALUE + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
1885
1885
  if (HUFv05_isError(iSize)) return iSize;
@@ -2210,7 +2210,7 @@ size_t HUFv05_readDTableX4 (unsigned* DTable, const void* src, size_t srcSize)
2210
2210
 
2211
2211
  HUFv05_STATIC_ASSERT(sizeof(HUFv05_DEltX4) == sizeof(unsigned)); /* if compilation fails here, assertion is false */
2212
2212
  if (memLog > HUFv05_ABSOLUTEMAX_TABLELOG) return ERROR(tableLog_tooLarge);
2213
- //memset(weightList, 0, sizeof(weightList)); /* is not necessary, even though some analyzer complain ... */
2213
+ /* memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
2214
2214
 
2215
2215
  iSize = HUFv05_readStats(weightList, HUFv05_MAX_SYMBOL_VALUE + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
2216
2216
  if (HUFv05_isError(iSize)) return iSize;
@@ -2539,9 +2539,9 @@ size_t HUFv05_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2539
2539
 
2540
2540
  return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
2541
2541
 
2542
- //return HUFv05_decompress4X2(dst, dstSize, cSrc, cSrcSize); /* multi-streams single-symbol decoding */
2543
- //return HUFv05_decompress4X4(dst, dstSize, cSrc, cSrcSize); /* multi-streams double-symbols decoding */
2544
- //return HUFv05_decompress4X6(dst, dstSize, cSrc, cSrcSize); /* multi-streams quad-symbols decoding */
2542
+ /* return HUFv05_decompress4X2(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams single-symbol decoding */
2543
+ /* return HUFv05_decompress4X4(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams double-symbols decoding */
2544
+ /* return HUFv05_decompress4X6(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams quad-symbols decoding */
2545
2545
  }
2546
2546
  /*
2547
2547
  zstd - standard compression library
@@ -2829,7 +2829,7 @@ static size_t ZSTDv05_decodeFrameHeader_Part2(ZSTDv05_DCtx* zc, const void* src,
2829
2829
 
2830
2830
  static size_t ZSTDv05_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
2831
2831
  {
2832
- const BYTE* const in = (const BYTE* const)src;
2832
+ const BYTE* const in = (const BYTE*)src;
2833
2833
  BYTE headerFlags;
2834
2834
  U32 cSize;
2835
2835
 
@@ -2998,7 +2998,7 @@ static size_t ZSTDv05_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t
2998
2998
  FSEv05_DTable* DTableLL, FSEv05_DTable* DTableML, FSEv05_DTable* DTableOffb,
2999
2999
  const void* src, size_t srcSize, U32 flagStaticTable)
3000
3000
  {
3001
- const BYTE* const istart = (const BYTE* const)src;
3001
+ const BYTE* const istart = (const BYTE*)src;
3002
3002
  const BYTE* ip = istart;
3003
3003
  const BYTE* const iend = istart + srcSize;
3004
3004
  U32 LLtype, Offtype, MLtype;
@@ -3306,7 +3306,7 @@ static size_t ZSTDv05_decompressSequences(
3306
3306
  {
3307
3307
  const BYTE* ip = (const BYTE*)seqStart;
3308
3308
  const BYTE* const iend = ip + seqSize;
3309
- BYTE* const ostart = (BYTE* const)dst;
3309
+ BYTE* const ostart = (BYTE*)dst;
3310
3310
  BYTE* op = ostart;
3311
3311
  BYTE* const oend = ostart + maxDstSize;
3312
3312
  size_t errorCode, dumpsLength=0;
@@ -3362,8 +3362,10 @@ static size_t ZSTDv05_decompressSequences(
3362
3362
  size_t lastLLSize = litEnd - litPtr;
3363
3363
  if (litPtr > litEnd) return ERROR(corruption_detected); /* too many literals already used */
3364
3364
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
3365
- memcpy(op, litPtr, lastLLSize);
3366
- op += lastLLSize;
3365
+ if (lastLLSize > 0) {
3366
+ memcpy(op, litPtr, lastLLSize);
3367
+ op += lastLLSize;
3368
+ }
3367
3369
  }
3368
3370
 
3369
3371
  return op-ostart;
@@ -3417,7 +3419,7 @@ static size_t ZSTDv05_decompress_continueDCtx(ZSTDv05_DCtx* dctx,
3417
3419
  {
3418
3420
  const BYTE* ip = (const BYTE*)src;
3419
3421
  const BYTE* iend = ip + srcSize;
3420
- BYTE* const ostart = (BYTE* const)dst;
3422
+ BYTE* const ostart = (BYTE*)dst;
3421
3423
  BYTE* op = ostart;
3422
3424
  BYTE* const oend = ostart + maxDstSize;
3423
3425
  size_t remainingSize = srcSize;
@@ -3791,7 +3793,9 @@ static size_t ZBUFFv05_blockHeaderSize = 3;
3791
3793
  static size_t ZBUFFv05_limitCopy(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
3792
3794
  {
3793
3795
  size_t length = MIN(maxDstSize, srcSize);
3794
- memcpy(dst, src, length);
3796
+ if (length > 0) {
3797
+ memcpy(dst, src, length);
3798
+ }
3795
3799
  return length;
3796
3800
  }
3797
3801
 
@@ -3928,7 +3932,7 @@ size_t ZBUFFv05_decompressContinue(ZBUFFv05_DCtx* zbc, void* dst, size_t* maxDst
3928
3932
  *maxDstSizePtr = 0;
3929
3933
  return headerSize - zbc->hPos;
3930
3934
  }
3931
- // zbc->stage = ZBUFFv05ds_decodeHeader; break; /* useless : stage follows */
3935
+ /* zbc->stage = ZBUFFv05ds_decodeHeader; break; */ /* useless : stage follows */
3932
3936
  }
3933
3937
  /* fall-through */
3934
3938
  case ZBUFFv05ds_decodeHeader:
@@ -4001,7 +4005,7 @@ size_t ZBUFFv05_decompressContinue(ZBUFFv05_DCtx* zbc, void* dst, size_t* maxDst
4001
4005
  if (!decodedSize) { zbc->stage = ZBUFFv05ds_read; break; } /* this was just a header */
4002
4006
  zbc->outEnd = zbc->outStart + decodedSize;
4003
4007
  zbc->stage = ZBUFFv05ds_flush;
4004
- // break; /* ZBUFFv05ds_flush follows */
4008
+ /* break; */ /* ZBUFFv05ds_flush follows */
4005
4009
  }
4006
4010
  }
4007
4011
  /* fall-through */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 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) 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
 
@@ -82,7 +82,11 @@ extern "C" {
82
82
  * Basic Types
83
83
  *****************************************************************/
84
84
  #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
85
- # include <stdint.h>
85
+ # if defined(_AIX)
86
+ # include <inttypes.h>
87
+ # else
88
+ # include <stdint.h> /* intptr_t */
89
+ # endif
86
90
  typedef uint8_t BYTE;
87
91
  typedef uint16_t U16;
88
92
  typedef int16_t S16;
@@ -118,10 +122,7 @@ extern "C" {
118
122
  * Prefer these methods in priority order (0 > 1 > 2)
119
123
  */
120
124
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
121
- # 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__) )
122
- # define MEM_FORCE_MEMORY_ACCESS 2
123
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
124
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
125
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
125
126
  # define MEM_FORCE_MEMORY_ACCESS 1
126
127
  # endif
127
128
  #endif
@@ -856,9 +857,8 @@ MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, unsigned nbBits);
856
857
  MEM_STATIC unsigned BITv06_highbit32 ( U32 val)
857
858
  {
858
859
  # if defined(_MSC_VER) /* Visual */
859
- unsigned long r=0;
860
- _BitScanReverse ( &r, val );
861
- return (unsigned) r;
860
+ unsigned long r;
861
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
862
862
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
863
863
  return __builtin_clz (val) ^ 31;
864
864
  # else /* Software version */
@@ -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
@@ -3025,7 +3025,7 @@ typedef struct
3025
3025
  * Provides the size of compressed block from block header `src` */
3026
3026
  static size_t ZSTDv06_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
3027
3027
  {
3028
- const BYTE* const in = (const BYTE* const)src;
3028
+ const BYTE* const in = (const BYTE*)src;
3029
3029
  U32 cSize;
3030
3030
 
3031
3031
  if (srcSize < ZSTDv06_blockHeaderSize) return ERROR(srcSize_wrong);
@@ -3219,7 +3219,7 @@ static size_t ZSTDv06_decodeSeqHeaders(int* nbSeqPtr,
3219
3219
  FSEv06_DTable* DTableLL, FSEv06_DTable* DTableML, FSEv06_DTable* DTableOffb, U32 flagRepeatTable,
3220
3220
  const void* src, size_t srcSize)
3221
3221
  {
3222
- const BYTE* const istart = (const BYTE* const)src;
3222
+ const BYTE* const istart = (const BYTE*)src;
3223
3223
  const BYTE* const iend = istart + srcSize;
3224
3224
  const BYTE* ip = istart;
3225
3225
 
@@ -3441,7 +3441,7 @@ static size_t ZSTDv06_decompressSequences(
3441
3441
  {
3442
3442
  const BYTE* ip = (const BYTE*)seqStart;
3443
3443
  const BYTE* const iend = ip + seqSize;
3444
- BYTE* const ostart = (BYTE* const)dst;
3444
+ BYTE* const ostart = (BYTE*)dst;
3445
3445
  BYTE* const oend = ostart + maxDstSize;
3446
3446
  BYTE* op = ostart;
3447
3447
  const BYTE* litPtr = dctx->litPtr;
@@ -3501,8 +3501,10 @@ static size_t ZSTDv06_decompressSequences(
3501
3501
  { size_t const lastLLSize = litEnd - litPtr;
3502
3502
  if (litPtr > litEnd) return ERROR(corruption_detected); /* too many literals already used */
3503
3503
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
3504
- memcpy(op, litPtr, lastLLSize);
3505
- op += lastLLSize;
3504
+ if (lastLLSize > 0) {
3505
+ memcpy(op, litPtr, lastLLSize);
3506
+ op += lastLLSize;
3507
+ }
3506
3508
  }
3507
3509
 
3508
3510
  return op-ostart;
@@ -3555,7 +3557,7 @@ static size_t ZSTDv06_decompressFrame(ZSTDv06_DCtx* dctx,
3555
3557
  {
3556
3558
  const BYTE* ip = (const BYTE*)src;
3557
3559
  const BYTE* const iend = ip + srcSize;
3558
- BYTE* const ostart = (BYTE* const)dst;
3560
+ BYTE* const ostart = (BYTE*)dst;
3559
3561
  BYTE* op = ostart;
3560
3562
  BYTE* const oend = ostart + dstCapacity;
3561
3563
  size_t remainingSize = srcSize;
@@ -4000,7 +4002,9 @@ size_t ZBUFFv06_decompressInit(ZBUFFv06_DCtx* zbd)
4000
4002
  MEM_STATIC size_t ZBUFFv06_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
4001
4003
  {
4002
4004
  size_t length = MIN(dstCapacity, srcSize);
4003
- memcpy(dst, src, length);
4005
+ if (length > 0) {
4006
+ memcpy(dst, src, length);
4007
+ }
4004
4008
  return length;
4005
4009
  }
4006
4010
 
@@ -4109,7 +4113,7 @@ size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* zbd,
4109
4113
  if (!decodedSize) { zbd->stage = ZBUFFds_read; break; } /* this was just a header */
4110
4114
  zbd->outEnd = zbd->outStart + decodedSize;
4111
4115
  zbd->stage = ZBUFFds_flush;
4112
- // break; /* ZBUFFds_flush follows */
4116
+ /* break; */ /* ZBUFFds_flush follows */
4113
4117
  }
4114
4118
  }
4115
4119
  /* fall-through */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 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) 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
@@ -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;
@@ -278,10 +282,7 @@ extern "C" {
278
282
  * Prefer these methods in priority order (0 > 1 > 2)
279
283
  */
280
284
  #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
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
285
286
  # define MEM_FORCE_MEMORY_ACCESS 1
286
287
  # endif
287
288
  #endif
@@ -526,9 +527,8 @@ MEM_STATIC size_t BITv07_readBitsFast(BITv07_DStream_t* bitD, unsigned nbBits);
526
527
  MEM_STATIC unsigned BITv07_highbit32 (U32 val)
527
528
  {
528
529
  # if defined(_MSC_VER) /* Visual */
529
- unsigned long r=0;
530
- _BitScanReverse ( &r, val );
531
- return (unsigned) r;
530
+ unsigned long r;
531
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
532
532
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
533
533
  return __builtin_clz (val) ^ 31;
534
534
  # else /* Software version */
@@ -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)
@@ -3254,7 +3254,7 @@ typedef struct
3254
3254
  * Provides the size of compressed block from block header `src` */
3255
3255
  static size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
3256
3256
  {
3257
- const BYTE* const in = (const BYTE* const)src;
3257
+ const BYTE* const in = (const BYTE*)src;
3258
3258
  U32 cSize;
3259
3259
 
3260
3260
  if (srcSize < ZSTDv07_blockHeaderSize) return ERROR(srcSize_wrong);
@@ -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
 
@@ -3447,7 +3449,7 @@ static size_t ZSTDv07_decodeSeqHeaders(int* nbSeqPtr,
3447
3449
  FSEv07_DTable* DTableLL, FSEv07_DTable* DTableML, FSEv07_DTable* DTableOffb, U32 flagRepeatTable,
3448
3450
  const void* src, size_t srcSize)
3449
3451
  {
3450
- const BYTE* const istart = (const BYTE* const)src;
3452
+ const BYTE* const istart = (const BYTE*)src;
3451
3453
  const BYTE* const iend = istart + srcSize;
3452
3454
  const BYTE* ip = istart;
3453
3455
 
@@ -3666,7 +3668,7 @@ static size_t ZSTDv07_decompressSequences(
3666
3668
  {
3667
3669
  const BYTE* ip = (const BYTE*)seqStart;
3668
3670
  const BYTE* const iend = ip + seqSize;
3669
- BYTE* const ostart = (BYTE* const)dst;
3671
+ BYTE* const ostart = (BYTE*)dst;
3670
3672
  BYTE* const oend = ostart + maxDstSize;
3671
3673
  BYTE* op = ostart;
3672
3674
  const BYTE* litPtr = dctx->litPtr;
@@ -3712,10 +3714,12 @@ static size_t ZSTDv07_decompressSequences(
3712
3714
 
3713
3715
  /* last literal segment */
3714
3716
  { size_t const lastLLSize = litEnd - litPtr;
3715
- //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 */
3716
3718
  if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall);
3717
- memcpy(op, litPtr, lastLLSize);
3718
- op += lastLLSize;
3719
+ if (lastLLSize > 0) {
3720
+ memcpy(op, litPtr, lastLLSize);
3721
+ op += lastLLSize;
3722
+ }
3719
3723
  }
3720
3724
 
3721
3725
  return op-ostart;
@@ -3776,7 +3780,9 @@ ZSTDLIBv07_API size_t ZSTDv07_insertBlock(ZSTDv07_DCtx* dctx, const void* blockS
3776
3780
  static size_t ZSTDv07_generateNxBytes(void* dst, size_t dstCapacity, BYTE byte, size_t length)
3777
3781
  {
3778
3782
  if (length > dstCapacity) return ERROR(dstSize_tooSmall);
3779
- memset(dst, byte, length);
3783
+ if (length > 0) {
3784
+ memset(dst, byte, length);
3785
+ }
3780
3786
  return length;
3781
3787
  }
3782
3788
 
@@ -3789,7 +3795,7 @@ static size_t ZSTDv07_decompressFrame(ZSTDv07_DCtx* dctx,
3789
3795
  {
3790
3796
  const BYTE* ip = (const BYTE*)src;
3791
3797
  const BYTE* const iend = ip + srcSize;
3792
- BYTE* const ostart = (BYTE* const)dst;
3798
+ BYTE* const ostart = (BYTE*)dst;
3793
3799
  BYTE* const oend = ostart + dstCapacity;
3794
3800
  BYTE* op = ostart;
3795
3801
  size_t remainingSize = srcSize;
@@ -4378,7 +4384,9 @@ size_t ZBUFFv07_decompressInit(ZBUFFv07_DCtx* zbd)
4378
4384
  MEM_STATIC size_t ZBUFFv07_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
4379
4385
  {
4380
4386
  size_t const length = MIN(dstCapacity, srcSize);
4381
- memcpy(dst, src, length);
4387
+ if (length > 0) {
4388
+ memcpy(dst, src, length);
4389
+ }
4382
4390
  return length;
4383
4391
  }
4384
4392
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 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