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,23 +1,21 @@
1
- ZSTD Windows binary package
2
- ====================================
1
+ # ZSTD Windows binary package
3
2
 
4
- #### The package contents
3
+ ## The package contents
5
4
 
6
- - `zstd.exe` : Command Line Utility, supporting gzip-like arguments
7
- - `dll\libzstd.dll` : The ZSTD dynamic library (DLL)
8
- - `dll\libzstd.lib` : The import library of the ZSTD dynamic library (DLL) for Visual C++
9
- - `example\` : The example of usage of the ZSTD library
10
- - `include\` : Header files required by the ZSTD library
5
+ - `zstd.exe` : Command Line Utility, supporting gzip-like arguments
6
+ - `dll\libzstd.dll` : The ZSTD dynamic library (DLL)
7
+ - `dll\libzstd.lib` : The import library of the ZSTD dynamic library (DLL) for Visual C++
8
+ - `example\` : The example of usage of the ZSTD library
9
+ - `include\` : Header files required by the ZSTD library
11
10
  - `static\libzstd_static.lib` : The static ZSTD library (LIB)
12
11
 
13
-
14
- #### Usage of Command Line Interface
12
+ ## Usage of Command Line Interface
15
13
 
16
14
  Command Line Interface (CLI) supports gzip-like arguments.
17
15
  By default CLI takes an input file and compresses it to an output file:
18
- ```
16
+
19
17
  Usage: zstd [arg] [input] [output]
20
- ```
18
+
21
19
  The full list of commands for CLI can be obtained with `-h` or `-H`. The ratio can
22
20
  be improved with commands from `-3` to `-16` but higher levels also have slower
23
21
  compression. CLI includes in-memory compression benchmark module with compression
@@ -25,36 +23,32 @@ levels starting from `-b` and ending with `-e` with iteration time of `-i` secon
25
23
  CLI supports aggregation of parameters i.e. `-b1`, `-e18`, and `-i1` can be joined
26
24
  into `-b1e18i1`.
27
25
 
28
-
29
- #### The example of usage of static and dynamic ZSTD libraries with gcc/MinGW
26
+ ## The example of usage of static and dynamic ZSTD libraries with gcc/MinGW
30
27
 
31
28
  Use `cd example` and `make` to build `fullbench-dll` and `fullbench-lib`.
32
29
  `fullbench-dll` uses a dynamic ZSTD library from the `dll` directory.
33
30
  `fullbench-lib` uses a static ZSTD library from the `lib` directory.
34
31
 
35
-
36
- #### Using ZSTD DLL with gcc/MinGW
32
+ ## Using ZSTD DLL with gcc/MinGW
37
33
 
38
34
  The header files from `include\` and the dynamic library `dll\libzstd.dll`
39
35
  are required to compile a project using gcc/MinGW.
40
36
  The dynamic library has to be added to linking options.
41
37
  It means that if a project that uses ZSTD consists of a single `test-dll.c`
42
38
  file it should be linked with `dll\libzstd.dll`. For example:
43
- ```
39
+
44
40
  gcc $(CFLAGS) -Iinclude\ test-dll.c -o test-dll dll\libzstd.dll
45
- ```
46
- The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`.
47
41
 
42
+ The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`.
48
43
 
49
- #### The example of usage of static and dynamic ZSTD libraries with Visual C++
44
+ ## The example of usage of static and dynamic ZSTD libraries with Visual C++
50
45
 
51
46
  Open `example\fullbench-dll.sln` to compile `fullbench-dll` that uses a
52
47
  dynamic ZSTD library from the `dll` directory. The solution works with Visual C++
53
48
  2010 or newer. When one will open the solution with Visual C++ newer than 2010
54
49
  then the solution will upgraded to the current version.
55
50
 
56
-
57
- #### Using ZSTD DLL with Visual C++
51
+ ## Using ZSTD DLL with Visual C++
58
52
 
59
53
  The header files from `include\` and the import library `dll\libzstd.lib`
60
54
  are required to compile a project using Visual C++.
@@ -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
@@ -18,9 +18,9 @@ extern "C" {
18
18
  /* *************************************
19
19
  * Includes
20
20
  ***************************************/
21
- #include "mem.h" /* MEM_STATIC */
22
- #include "error_private.h" /* ERROR */
23
- #include "zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
21
+ #include "../common/mem.h" /* MEM_STATIC */
22
+ #include "../common/error_private.h" /* ERROR */
23
+ #include "../common/zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
24
24
 
25
25
  #if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
26
26
  # undef ZSTD_LEGACY_SUPPORT
@@ -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
  ******************************************/
15
15
  #include <stddef.h> /* size_t, ptrdiff_t */
16
16
  #include "zstd_v01.h"
17
- #include "error_private.h"
17
+ #include "../common/error_private.h"
18
18
 
19
19
 
20
20
  /******************************************
@@ -204,10 +204,7 @@ typedef signed long long S64;
204
204
  * Prefer these methods in priority order (0 > 1 > 2)
205
205
  */
206
206
  #ifndef FSE_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
207
- # 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__) )
208
- # define FSE_FORCE_MEMORY_ACCESS 2
209
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
210
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
207
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
211
208
  # define FSE_FORCE_MEMORY_ACCESS 1
212
209
  # endif
213
210
  #endif
@@ -257,7 +254,7 @@ static U64 FSE_read64(const void* memPtr)
257
254
  U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
258
255
  }
259
256
 
260
- #endif // FSE_FORCE_MEMORY_ACCESS
257
+ #endif /* FSE_FORCE_MEMORY_ACCESS */
261
258
 
262
259
  static U16 FSE_readLE16(const void* memPtr)
263
260
  {
@@ -343,8 +340,7 @@ FORCE_INLINE unsigned FSE_highbit32 (U32 val)
343
340
  {
344
341
  # if defined(_MSC_VER) /* Visual */
345
342
  unsigned long r;
346
- _BitScanReverse ( &r, val );
347
- return (unsigned) r;
343
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
348
344
  # elif defined(__GNUC__) && (GCC_VERSION >= 304) /* GCC Intrinsic */
349
345
  return __builtin_clz (val) ^ 31;
350
346
  # else /* Software version */
@@ -1078,7 +1074,7 @@ static size_t HUF_decompress_usingDTable( /* -3% slower when non static */
1078
1074
  BYTE* const ostart = (BYTE*) dst;
1079
1075
  BYTE* op = ostart;
1080
1076
  BYTE* const omax = op + maxDstSize;
1081
- BYTE* const olimit = omax-15;
1077
+ BYTE* const olimit = maxDstSize < 15 ? op : omax-15;
1082
1078
 
1083
1079
  const void* ptr = DTable;
1084
1080
  const HUF_DElt* const dt = (const HUF_DElt*)(ptr)+1;
@@ -1092,7 +1088,7 @@ static size_t HUF_decompress_usingDTable( /* -3% slower when non static */
1092
1088
  const size_t length1 = FSE_readLE16(jumpTable);
1093
1089
  const size_t length2 = FSE_readLE16(jumpTable+1);
1094
1090
  const size_t length3 = FSE_readLE16(jumpTable+2);
1095
- const size_t length4 = cSrcSize - 6 - length1 - length2 - length3; // check coherency !!
1091
+ const size_t length4 = cSrcSize - 6 - length1 - length2 - length3; /* check coherency !! */
1096
1092
  const char* const start1 = (const char*)(cSrc) + 6;
1097
1093
  const char* const start2 = start1 + length1;
1098
1094
  const char* const start3 = start2 + length2;
@@ -1150,11 +1146,11 @@ static size_t HUF_decompress_usingDTable( /* -3% slower when non static */
1150
1146
 
1151
1147
  /* tail */
1152
1148
  {
1153
- // bitTail = bitD1; // *much* slower : -20% !??!
1149
+ /* bitTail = bitD1; */ /* *much* slower : -20% !??! */
1154
1150
  FSE_DStream_t bitTail;
1155
1151
  bitTail.ptr = bitD1.ptr;
1156
1152
  bitTail.bitsConsumed = bitD1.bitsConsumed;
1157
- bitTail.bitContainer = bitD1.bitContainer; // required in case of FSE_DStream_endOfBuffer
1153
+ bitTail.bitContainer = bitD1.bitContainer; /* required in case of FSE_DStream_endOfBuffer */
1158
1154
  bitTail.start = start1;
1159
1155
  for ( ; (FSE_reloadDStream(&bitTail) < FSE_DStream_completed) && (op<omax) ; op++)
1160
1156
  {
@@ -1280,7 +1276,11 @@ static size_t HUF_decompress (void* dst, size_t maxDstSize, const void* cSrc, si
1280
1276
  * Basic Types
1281
1277
  *********************************************************/
1282
1278
  #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
1283
- # include <stdint.h>
1279
+ # if defined(_AIX)
1280
+ # include <inttypes.h>
1281
+ # else
1282
+ # include <stdint.h> /* intptr_t */
1283
+ # endif
1284
1284
  typedef uint8_t BYTE;
1285
1285
  typedef uint16_t U16;
1286
1286
  typedef int16_t S16;
@@ -1483,7 +1483,9 @@ static size_t ZSTDv01_getcBlockSize(const void* src, size_t srcSize, blockProper
1483
1483
  static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
1484
1484
  {
1485
1485
  if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
1486
- memcpy(dst, src, srcSize);
1486
+ if (srcSize > 0) {
1487
+ memcpy(dst, src, srcSize);
1488
+ }
1487
1489
  return srcSize;
1488
1490
  }
1489
1491
 
@@ -1502,7 +1504,7 @@ static size_t ZSTD_decompressLiterals(void* ctx,
1502
1504
  if (srcSize <= 3) return ERROR(corruption_detected);
1503
1505
 
1504
1506
  litSize = ip[1] + (ip[0]<<8);
1505
- litSize += ((ip[-3] >> 3) & 7) << 16; // mmmmh....
1507
+ litSize += ((ip[-3] >> 3) & 7) << 16; /* mmmmh.... */
1506
1508
  op = oend - litSize;
1507
1509
 
1508
1510
  (void)ctx;
@@ -1541,7 +1543,9 @@ static size_t ZSTDv01_decodeLiteralsBlock(void* ctx,
1541
1543
  size_t rleSize = litbp.origSize;
1542
1544
  if (rleSize>maxDstSize) return ERROR(dstSize_tooSmall);
1543
1545
  if (!srcSize) return ERROR(srcSize_wrong);
1544
- memset(oend - rleSize, *ip, rleSize);
1546
+ if (rleSize > 0) {
1547
+ memset(oend - rleSize, *ip, rleSize);
1548
+ }
1545
1549
  *litStart = oend - rleSize;
1546
1550
  *litSize = rleSize;
1547
1551
  ip++;
@@ -1901,8 +1905,10 @@ static size_t ZSTD_decompressSequences(
1901
1905
  {
1902
1906
  size_t lastLLSize = litEnd - litPtr;
1903
1907
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
1904
- if (op != litPtr) memmove(op, litPtr, lastLLSize);
1905
- op += lastLLSize;
1908
+ if (lastLLSize > 0) {
1909
+ if (op != litPtr) memmove(op, litPtr, lastLLSize);
1910
+ op += lastLLSize;
1911
+ }
1906
1912
  }
1907
1913
  }
1908
1914
 
@@ -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
@@ -11,7 +11,7 @@
11
11
 
12
12
  #include <stddef.h> /* size_t, ptrdiff_t */
13
13
  #include "zstd_v02.h"
14
- #include "error_private.h"
14
+ #include "../common/error_private.h"
15
15
 
16
16
 
17
17
  /******************************************
@@ -89,7 +89,11 @@ extern "C" {
89
89
  * Basic Types
90
90
  *****************************************************************/
91
91
  #if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
92
- # include <stdint.h>
92
+ # if defined(_AIX)
93
+ # include <inttypes.h>
94
+ # else
95
+ # include <stdint.h> /* intptr_t */
96
+ # endif
93
97
  typedef uint8_t BYTE;
94
98
  typedef uint16_t U16;
95
99
  typedef int16_t S16;
@@ -125,10 +129,7 @@ extern "C" {
125
129
  * Prefer these methods in priority order (0 > 1 > 2)
126
130
  */
127
131
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
128
- # 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__) )
129
- # define MEM_FORCE_MEMORY_ACCESS 2
130
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
131
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
132
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
132
133
  # define MEM_FORCE_MEMORY_ACCESS 1
133
134
  # endif
134
135
  #endif
@@ -189,7 +190,7 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
189
190
  memcpy(memPtr, &value, sizeof(value));
190
191
  }
191
192
 
192
- #endif // MEM_FORCE_MEMORY_ACCESS
193
+ #endif /* MEM_FORCE_MEMORY_ACCESS */
193
194
 
194
195
 
195
196
  MEM_STATIC U16 MEM_readLE16(const void* memPtr)
@@ -349,9 +350,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
349
350
  MEM_STATIC unsigned BIT_highbit32 (U32 val)
350
351
  {
351
352
  # if defined(_MSC_VER) /* Visual */
352
- unsigned long r=0;
353
- _BitScanReverse ( &r, val );
354
- return (unsigned) r;
353
+ unsigned long r;
354
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
355
355
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
356
356
  return __builtin_clz (val) ^ 31;
357
357
  # else /* Software version */
@@ -2836,7 +2836,9 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
2836
2836
  static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
2837
2837
  {
2838
2838
  if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
2839
- memcpy(dst, src, srcSize);
2839
+ if (srcSize > 0) {
2840
+ memcpy(dst, src, srcSize);
2841
+ }
2840
2842
  return srcSize;
2841
2843
  }
2842
2844
 
@@ -3229,8 +3231,10 @@ static size_t ZSTD_decompressSequences(
3229
3231
  size_t lastLLSize = litEnd - litPtr;
3230
3232
  if (litPtr > litEnd) return ERROR(corruption_detected);
3231
3233
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
3232
- if (op != litPtr) memmove(op, litPtr, lastLLSize);
3233
- op += lastLLSize;
3234
+ if (lastLLSize > 0) {
3235
+ if (op != litPtr) memmove(op, litPtr, lastLLSize);
3236
+ op += lastLLSize;
3237
+ }
3234
3238
  }
3235
3239
  }
3236
3240
 
@@ -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
@@ -11,7 +11,7 @@
11
11
 
12
12
  #include <stddef.h> /* size_t, ptrdiff_t */
13
13
  #include "zstd_v03.h"
14
- #include "error_private.h"
14
+ #include "../common/error_private.h"
15
15
 
16
16
 
17
17
  /******************************************
@@ -90,7 +90,11 @@ extern "C" {
90
90
  * Basic Types
91
91
  *****************************************************************/
92
92
  #if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
93
- # include <stdint.h>
93
+ # if defined(_AIX)
94
+ # include <inttypes.h>
95
+ # else
96
+ # include <stdint.h> /* intptr_t */
97
+ # endif
94
98
  typedef uint8_t BYTE;
95
99
  typedef uint16_t U16;
96
100
  typedef int16_t S16;
@@ -126,10 +130,7 @@ extern "C" {
126
130
  * Prefer these methods in priority order (0 > 1 > 2)
127
131
  */
128
132
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
129
- # 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__) )
130
- # define MEM_FORCE_MEMORY_ACCESS 2
131
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
132
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
133
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
133
134
  # define MEM_FORCE_MEMORY_ACCESS 1
134
135
  # endif
135
136
  #endif
@@ -191,7 +192,7 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
191
192
  }
192
193
 
193
194
 
194
- #endif // MEM_FORCE_MEMORY_ACCESS
195
+ #endif /* MEM_FORCE_MEMORY_ACCESS */
195
196
 
196
197
 
197
198
  MEM_STATIC U16 MEM_readLE16(const void* memPtr)
@@ -352,9 +353,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
352
353
  MEM_STATIC unsigned BIT_highbit32 (U32 val)
353
354
  {
354
355
  # if defined(_MSC_VER) /* Visual */
355
- unsigned long r=0;
356
- _BitScanReverse ( &r, val );
357
- return (unsigned) r;
356
+ unsigned long r;
357
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
358
358
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
359
359
  return __builtin_clz (val) ^ 31;
360
360
  # else /* Software version */
@@ -2477,7 +2477,9 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
2477
2477
  static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
2478
2478
  {
2479
2479
  if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
2480
- memcpy(dst, src, srcSize);
2480
+ if (srcSize > 0) {
2481
+ memcpy(dst, src, srcSize);
2482
+ }
2481
2483
  return srcSize;
2482
2484
  }
2483
2485
 
@@ -2870,8 +2872,10 @@ static size_t ZSTD_decompressSequences(
2870
2872
  size_t lastLLSize = litEnd - litPtr;
2871
2873
  if (litPtr > litEnd) return ERROR(corruption_detected);
2872
2874
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
2873
- if (op != litPtr) memmove(op, litPtr, lastLLSize);
2874
- op += lastLLSize;
2875
+ if (lastLLSize > 0) {
2876
+ if (op != litPtr) memmove(op, litPtr, lastLLSize);
2877
+ op += lastLLSize;
2878
+ }
2875
2879
  }
2876
2880
  }
2877
2881
 
@@ -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
@@ -16,7 +16,7 @@
16
16
  #include <string.h> /* memcpy */
17
17
 
18
18
  #include "zstd_v04.h"
19
- #include "error_private.h"
19
+ #include "../common/error_private.h"
20
20
 
21
21
 
22
22
  /* ******************************************************************
@@ -52,7 +52,11 @@ extern "C" {
52
52
  * Basic Types
53
53
  *****************************************************************/
54
54
  #if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
55
- # include <stdint.h>
55
+ # if defined(_AIX)
56
+ # include <inttypes.h>
57
+ # else
58
+ # include <stdint.h> /* intptr_t */
59
+ # endif
56
60
  typedef uint8_t BYTE;
57
61
  typedef uint16_t U16;
58
62
  typedef int16_t S16;
@@ -74,7 +78,7 @@ extern "C" {
74
78
  /*-*************************************
75
79
  * Debug
76
80
  ***************************************/
77
- #include "debug.h"
81
+ #include "../common/debug.h"
78
82
  #ifndef assert
79
83
  # define assert(condition) ((void)0)
80
84
  #endif
@@ -97,10 +101,7 @@ extern "C" {
97
101
  * Prefer these methods in priority order (0 > 1 > 2)
98
102
  */
99
103
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
100
- # 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__) )
101
- # define MEM_FORCE_MEMORY_ACCESS 2
102
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
103
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
104
+ # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
104
105
  # define MEM_FORCE_MEMORY_ACCESS 1
105
106
  # endif
106
107
  #endif
@@ -161,7 +162,7 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
161
162
  memcpy(memPtr, &value, sizeof(value));
162
163
  }
163
164
 
164
- #endif // MEM_FORCE_MEMORY_ACCESS
165
+ #endif /* MEM_FORCE_MEMORY_ACCESS */
165
166
 
166
167
 
167
168
  MEM_STATIC U16 MEM_readLE16(const void* memPtr)
@@ -623,9 +624,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
623
624
  MEM_STATIC unsigned BIT_highbit32 (U32 val)
624
625
  {
625
626
  # if defined(_MSC_VER) /* Visual */
626
- unsigned long r=0;
627
- _BitScanReverse ( &r, val );
628
- return (unsigned) r;
627
+ unsigned long r;
628
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
629
629
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
630
630
  return __builtin_clz (val) ^ 31;
631
631
  # else /* Software version */
@@ -2603,7 +2603,9 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
2603
2603
  static size_t ZSTD_copyRawBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
2604
2604
  {
2605
2605
  if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
2606
- memcpy(dst, src, srcSize);
2606
+ if (srcSize > 0) {
2607
+ memcpy(dst, src, srcSize);
2608
+ }
2607
2609
  return srcSize;
2608
2610
  }
2609
2611
 
@@ -3008,8 +3010,10 @@ static size_t ZSTD_decompressSequences(
3008
3010
  size_t lastLLSize = litEnd - litPtr;
3009
3011
  if (litPtr > litEnd) return ERROR(corruption_detected);
3010
3012
  if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
3011
- if (op != litPtr) memcpy(op, litPtr, lastLLSize);
3012
- op += lastLLSize;
3013
+ if (lastLLSize > 0) {
3014
+ if (op != litPtr) memcpy(op, litPtr, lastLLSize);
3015
+ op += lastLLSize;
3016
+ }
3013
3017
  }
3014
3018
  }
3015
3019
 
@@ -3407,7 +3411,9 @@ static size_t ZBUFF_decompressWithDictionary(ZBUFF_DCtx* zbc, const void* src, s
3407
3411
  static size_t ZBUFF_limitCopy(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
3408
3412
  {
3409
3413
  size_t length = MIN(maxDstSize, srcSize);
3410
- memcpy(dst, src, length);
3414
+ if (length > 0) {
3415
+ memcpy(dst, src, length);
3416
+ }
3411
3417
  return length;
3412
3418
  }
3413
3419
 
@@ -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