zstd-ruby 1.3.8.0 → 1.4.5.0

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -5
  3. data/README.md +1 -1
  4. data/ext/zstdruby/libzstd/Makefile +133 -61
  5. data/ext/zstdruby/libzstd/README.md +51 -18
  6. data/ext/zstdruby/libzstd/common/bitstream.h +38 -39
  7. data/ext/zstdruby/libzstd/common/compiler.h +41 -6
  8. data/ext/zstdruby/libzstd/common/cpu.h +1 -1
  9. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  10. data/ext/zstdruby/libzstd/common/debug.h +11 -31
  11. data/ext/zstdruby/libzstd/common/entropy_common.c +13 -33
  12. data/ext/zstdruby/libzstd/common/error_private.c +2 -1
  13. data/ext/zstdruby/libzstd/common/error_private.h +6 -2
  14. data/ext/zstdruby/libzstd/common/fse.h +13 -33
  15. data/ext/zstdruby/libzstd/common/fse_decompress.c +12 -35
  16. data/ext/zstdruby/libzstd/common/huf.h +15 -33
  17. data/ext/zstdruby/libzstd/common/mem.h +75 -2
  18. data/ext/zstdruby/libzstd/common/pool.c +8 -4
  19. data/ext/zstdruby/libzstd/common/pool.h +2 -2
  20. data/ext/zstdruby/libzstd/common/threading.c +52 -6
  21. data/ext/zstdruby/libzstd/common/threading.h +36 -4
  22. data/ext/zstdruby/libzstd/common/xxhash.c +25 -37
  23. data/ext/zstdruby/libzstd/common/xxhash.h +11 -31
  24. data/ext/zstdruby/libzstd/common/zstd_common.c +1 -1
  25. data/ext/zstdruby/libzstd/common/zstd_errors.h +2 -1
  26. data/ext/zstdruby/libzstd/common/zstd_internal.h +203 -22
  27. data/ext/zstdruby/libzstd/compress/fse_compress.c +19 -42
  28. data/ext/zstdruby/libzstd/compress/hist.c +15 -35
  29. data/ext/zstdruby/libzstd/compress/hist.h +12 -32
  30. data/ext/zstdruby/libzstd/compress/huf_compress.c +92 -92
  31. data/ext/zstdruby/libzstd/compress/zstd_compress.c +1460 -1472
  32. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +330 -65
  33. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
  34. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +419 -0
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +845 -0
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  39. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +525 -0
  40. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +65 -43
  41. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  42. data/ext/zstdruby/libzstd/compress/zstd_fast.c +264 -159
  43. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  44. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +74 -42
  45. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +2 -2
  46. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +33 -11
  47. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +7 -2
  48. data/ext/zstdruby/libzstd/compress/zstd_opt.c +108 -125
  49. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  50. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +129 -93
  51. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +46 -28
  52. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +76 -60
  53. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +14 -10
  54. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
  55. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +471 -258
  56. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +471 -346
  57. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +3 -3
  58. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +25 -4
  59. data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
  60. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
  61. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
  62. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  63. data/ext/zstdruby/libzstd/dictBuilder/cover.c +220 -65
  64. data/ext/zstdruby/libzstd/dictBuilder/cover.h +81 -7
  65. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +85 -56
  66. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +43 -19
  67. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +73 -35
  68. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  69. data/ext/zstdruby/libzstd/dll/example/build_package.bat +3 -2
  70. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +49 -15
  71. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +142 -117
  72. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +13 -8
  73. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +54 -25
  74. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +13 -8
  75. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +55 -25
  76. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +13 -8
  77. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +62 -29
  78. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +13 -8
  79. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +145 -109
  80. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +14 -9
  81. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +56 -26
  82. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +11 -6
  83. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +65 -28
  84. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +11 -6
  85. data/ext/zstdruby/libzstd/libzstd.pc.in +3 -2
  86. data/ext/zstdruby/libzstd/zstd.h +921 -597
  87. data/lib/zstd-ruby/version.rb +1 -1
  88. data/zstd-ruby.gemspec +2 -2
  89. metadata +19 -14
  90. data/ext/zstdruby/libzstd/dll/libzstd.def +0 -87
@@ -1,35 +1,15 @@
1
1
  /* ******************************************************************
2
- FSE : Finite State Entropy decoder
3
- Copyright (C) 2013-2015, Yann Collet.
4
-
5
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
-
7
- Redistribution and use in source and binary forms, with or without
8
- modification, are permitted provided that the following conditions are
9
- met:
10
-
11
- * Redistributions of source code must retain the above copyright
12
- notice, this list of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above
14
- copyright notice, this list of conditions and the following disclaimer
15
- in the documentation and/or other materials provided with the
16
- distribution.
17
-
18
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
-
30
- You can contact the author at :
31
- - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
32
- - Public forum : https://groups.google.com/forum/#!forum/lz4c
2
+ * FSE : Finite State Entropy decoder
3
+ * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4
+ *
5
+ * You can contact the author at :
6
+ * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
7
+ * - Public forum : https://groups.google.com/forum/#!forum/lz4c
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  ****************************************************************** */
34
14
 
35
15
 
@@ -51,9 +31,6 @@
51
31
  #define FSE_isError ERR_isError
52
32
  #define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
53
33
 
54
- /* check and forward error code */
55
- #define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
56
-
57
34
 
58
35
  /* **************************************************************
59
36
  * Templates
@@ -285,7 +262,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size
285
262
  /* normal FSE decoding mode */
286
263
  size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize);
287
264
  if (FSE_isError(NCountLength)) return NCountLength;
288
- //if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); /* too small input size; supposed to be already checked in NCountLength, only remaining case : NCountLength==cSrcSize */
265
+ /* if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); */ /* too small input size; supposed to be already checked in NCountLength, only remaining case : NCountLength==cSrcSize */
289
266
  if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
290
267
  ip += NCountLength;
291
268
  cSrcSize -= NCountLength;
@@ -1,35 +1,15 @@
1
1
  /* ******************************************************************
2
- huff0 huffman codec,
3
- part of Finite State Entropy library
4
- Copyright (C) 2013-present, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
-
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
-
12
- * Redistributions of source code must retain the above copyright
13
- notice, this list of conditions and the following disclaimer.
14
- * Redistributions in binary form must reproduce the above
15
- copyright notice, this list of conditions and the following disclaimer
16
- in the documentation and/or other materials provided with the
17
- distribution.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- You can contact the author at :
32
- - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
2
+ * huff0 huffman codec,
3
+ * part of Finite State Entropy library
4
+ * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
7
+ * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  ****************************************************************** */
34
14
 
35
15
  #if defined (__cplusplus)
@@ -110,7 +90,7 @@ HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity,
110
90
  /** HUF_compress4X_wksp() :
111
91
  * Same as HUF_compress2(), but uses externally allocated `workSpace`.
112
92
  * `workspace` must have minimum alignment of 4, and be at least as large as HUF_WORKSPACE_SIZE */
113
- #define HUF_WORKSPACE_SIZE (6 << 10)
93
+ #define HUF_WORKSPACE_SIZE ((6 << 10) + 256)
114
94
  #define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
115
95
  HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
116
96
  const void* src, size_t srcSize,
@@ -208,6 +188,8 @@ typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
208
188
  size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
209
189
  size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
210
190
  size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
191
+ size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
192
+ int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
211
193
 
212
194
  typedef enum {
213
195
  HUF_repeat_none, /**< Cannot use the previous table */
@@ -246,7 +228,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,
246
228
 
247
229
  /** HUF_readCTable() :
248
230
  * Loading a CTable saved with HUF_writeCTable() */
249
- size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
231
+ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
250
232
 
251
233
  /** HUF_getNbBits() :
252
234
  * Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -47,6 +47,79 @@ extern "C" {
47
47
  #define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
48
48
  MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
49
49
 
50
+ /* detects whether we are being compiled under msan */
51
+ #if defined (__has_feature)
52
+ # if __has_feature(memory_sanitizer)
53
+ # define MEMORY_SANITIZER 1
54
+ # endif
55
+ #endif
56
+
57
+ #if defined (MEMORY_SANITIZER)
58
+ /* Not all platforms that support msan provide sanitizers/msan_interface.h.
59
+ * We therefore declare the functions we need ourselves, rather than trying to
60
+ * include the header file... */
61
+
62
+ #include <stdint.h> /* intptr_t */
63
+
64
+ /* Make memory region fully initialized (without changing its contents). */
65
+ void __msan_unpoison(const volatile void *a, size_t size);
66
+
67
+ /* Make memory region fully uninitialized (without changing its contents).
68
+ This is a legacy interface that does not update origin information. Use
69
+ __msan_allocated_memory() instead. */
70
+ void __msan_poison(const volatile void *a, size_t size);
71
+
72
+ /* Returns the offset of the first (at least partially) poisoned byte in the
73
+ memory range, or -1 if the whole range is good. */
74
+ intptr_t __msan_test_shadow(const volatile void *x, size_t size);
75
+ #endif
76
+
77
+ /* detects whether we are being compiled under asan */
78
+ #if defined (__has_feature)
79
+ # if __has_feature(address_sanitizer)
80
+ # define ADDRESS_SANITIZER 1
81
+ # endif
82
+ #elif defined(__SANITIZE_ADDRESS__)
83
+ # define ADDRESS_SANITIZER 1
84
+ #endif
85
+
86
+ #if defined (ADDRESS_SANITIZER)
87
+ /* Not all platforms that support asan provide sanitizers/asan_interface.h.
88
+ * We therefore declare the functions we need ourselves, rather than trying to
89
+ * include the header file... */
90
+
91
+ /**
92
+ * Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
93
+ *
94
+ * This memory must be previously allocated by your program. Instrumented
95
+ * code is forbidden from accessing addresses in this region until it is
96
+ * unpoisoned. This function is not guaranteed to poison the entire region -
97
+ * it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
98
+ * alignment restrictions.
99
+ *
100
+ * \note This function is not thread-safe because no two threads can poison or
101
+ * unpoison memory in the same memory region simultaneously.
102
+ *
103
+ * \param addr Start of memory region.
104
+ * \param size Size of memory region. */
105
+ void __asan_poison_memory_region(void const volatile *addr, size_t size);
106
+
107
+ /**
108
+ * Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
109
+ *
110
+ * This memory must be previously allocated by your program. Accessing
111
+ * addresses in this region is allowed until this region is poisoned again.
112
+ * This function could unpoison a super-region of <c>[addr, addr+size)</c> due
113
+ * to ASan alignment restrictions.
114
+ *
115
+ * \note This function is not thread-safe because no two threads can
116
+ * poison or unpoison memory in the same memory region simultaneously.
117
+ *
118
+ * \param addr Start of memory region.
119
+ * \param size Size of memory region. */
120
+ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
121
+ #endif
122
+
50
123
 
51
124
  /*-**************************************************************
52
125
  * Basic Types
@@ -102,7 +175,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
102
175
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
103
176
  # 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__) )
104
177
  # define MEM_FORCE_MEMORY_ACCESS 2
105
- # elif defined(__INTEL_COMPILER) || defined(__GNUC__)
178
+ # elif defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
106
179
  # define MEM_FORCE_MEMORY_ACCESS 1
107
180
  # endif
108
181
  #endif
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -127,9 +127,13 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
127
127
  ctx->queueTail = 0;
128
128
  ctx->numThreadsBusy = 0;
129
129
  ctx->queueEmpty = 1;
130
- (void)ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
131
- (void)ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
132
- (void)ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
130
+ {
131
+ int error = 0;
132
+ error |= ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
133
+ error |= ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
134
+ error |= ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
135
+ if (error) { POOL_free(ctx); return NULL; }
136
+ }
133
137
  ctx->shutdown = 0;
134
138
  /* Allocate space for the thread handles */
135
139
  ctx->threads = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -18,7 +18,7 @@ extern "C" {
18
18
 
19
19
  #include <stddef.h> /* size_t */
20
20
  #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
21
- #include "zstd.h"
21
+ #include "../zstd.h"
22
22
 
23
23
  typedef struct POOL_ctx_s POOL_ctx;
24
24
 
@@ -2,20 +2,23 @@
2
2
  * Copyright (c) 2016 Tino Reichardt
3
3
  * All rights reserved.
4
4
  *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
5
8
  * This source code is licensed under both the BSD-style license (found in the
6
9
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
10
  * in the COPYING file in the root directory of this source tree).
8
- *
9
- * You can contact the author at:
10
- * - zstdmt source repository: https://github.com/mcmilk/zstdmt
11
+ * You may select, at your option, one of the above-listed licenses.
11
12
  */
12
13
 
13
14
  /**
14
15
  * This file will hold wrapper for systems, which do not support pthreads
15
16
  */
16
17
 
17
- /* create fake symbol to avoid empty trnaslation unit warning */
18
- int g_ZSTD_threading_useles_symbol;
18
+ #include "threading.h"
19
+
20
+ /* create fake symbol to avoid empty translation unit warning */
21
+ int g_ZSTD_threading_useless_symbol;
19
22
 
20
23
  #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
21
24
 
@@ -28,7 +31,6 @@ int g_ZSTD_threading_useles_symbol;
28
31
  /* === Dependencies === */
29
32
  #include <process.h>
30
33
  #include <errno.h>
31
- #include "threading.h"
32
34
 
33
35
 
34
36
  /* === Implementation === */
@@ -73,3 +75,47 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
73
75
  }
74
76
 
75
77
  #endif /* ZSTD_MULTITHREAD */
78
+
79
+ #if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
80
+
81
+ #include <stdlib.h>
82
+
83
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
84
+ {
85
+ *mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
86
+ if (!*mutex)
87
+ return 1;
88
+ return pthread_mutex_init(*mutex, attr);
89
+ }
90
+
91
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
92
+ {
93
+ if (!*mutex)
94
+ return 0;
95
+ {
96
+ int const ret = pthread_mutex_destroy(*mutex);
97
+ free(*mutex);
98
+ return ret;
99
+ }
100
+ }
101
+
102
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
103
+ {
104
+ *cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
105
+ if (!*cond)
106
+ return 1;
107
+ return pthread_cond_init(*cond, attr);
108
+ }
109
+
110
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
111
+ {
112
+ if (!*cond)
113
+ return 0;
114
+ {
115
+ int const ret = pthread_cond_destroy(*cond);
116
+ free(*cond);
117
+ return ret;
118
+ }
119
+ }
120
+
121
+ #endif
@@ -2,17 +2,20 @@
2
2
  * Copyright (c) 2016 Tino Reichardt
3
3
  * All rights reserved.
4
4
  *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
5
8
  * This source code is licensed under both the BSD-style license (found in the
6
9
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
10
  * in the COPYING file in the root directory of this source tree).
8
- *
9
- * You can contact the author at:
10
- * - zstdmt source repository: https://github.com/mcmilk/zstdmt
11
+ * You may select, at your option, one of the above-listed licenses.
11
12
  */
12
13
 
13
14
  #ifndef THREADING_H_938743
14
15
  #define THREADING_H_938743
15
16
 
17
+ #include "debug.h"
18
+
16
19
  #if defined (__cplusplus)
17
20
  extern "C" {
18
21
  #endif
@@ -75,10 +78,12 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
75
78
  */
76
79
 
77
80
 
78
- #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
81
+ #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
79
82
  /* === POSIX Systems === */
80
83
  # include <pthread.h>
81
84
 
85
+ #if DEBUGLEVEL < 1
86
+
82
87
  #define ZSTD_pthread_mutex_t pthread_mutex_t
83
88
  #define ZSTD_pthread_mutex_init(a, b) pthread_mutex_init((a), (b))
84
89
  #define ZSTD_pthread_mutex_destroy(a) pthread_mutex_destroy((a))
@@ -96,6 +101,33 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
96
101
  #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
97
102
  #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
98
103
 
104
+ #else /* DEBUGLEVEL >= 1 */
105
+
106
+ /* Debug implementation of threading.
107
+ * In this implementation we use pointers for mutexes and condition variables.
108
+ * This way, if we forget to init/destroy them the program will crash or ASAN
109
+ * will report leaks.
110
+ */
111
+
112
+ #define ZSTD_pthread_mutex_t pthread_mutex_t*
113
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr);
114
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex);
115
+ #define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock(*(a))
116
+ #define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock(*(a))
117
+
118
+ #define ZSTD_pthread_cond_t pthread_cond_t*
119
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr);
120
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond);
121
+ #define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait(*(a), *(b))
122
+ #define ZSTD_pthread_cond_signal(a) pthread_cond_signal(*(a))
123
+ #define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast(*(a))
124
+
125
+ #define ZSTD_pthread_t pthread_t
126
+ #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
127
+ #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
128
+
129
+ #endif
130
+
99
131
  #else /* ZSTD_MULTITHREAD not defined */
100
132
  /* No multithreading support */
101
133
 
@@ -1,35 +1,15 @@
1
1
  /*
2
- * xxHash - Fast Hash algorithm
3
- * Copyright (C) 2012-2016, Yann Collet
4
- *
5
- * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions are
9
- * met:
10
- *
11
- * * Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- * * Redistributions in binary form must reproduce the above
14
- * copyright notice, this list of conditions and the following disclaimer
15
- * in the documentation and/or other materials provided with the
16
- * distribution.
17
- *
18
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- *
30
- * You can contact the author at :
31
- * - xxHash homepage: http://www.xxhash.com
32
- * - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Fast Hash algorithm
3
+ * Copyright (c) 2012-2020, Yann Collet, Facebook, Inc.
4
+ *
5
+ * You can contact the author at :
6
+ * - xxHash homepage: http://www.xxhash.com
7
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  */
34
14
 
35
15
 
@@ -53,7 +33,8 @@
53
33
  # 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__) )
54
34
  # define XXH_FORCE_MEMORY_ACCESS 2
55
35
  # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
56
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
36
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) || \
37
+ defined(__ICCARM__)
57
38
  # define XXH_FORCE_MEMORY_ACCESS 1
58
39
  # endif
59
40
  #endif
@@ -66,10 +47,10 @@
66
47
  /* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */
67
48
 
68
49
  /*!XXH_FORCE_NATIVE_FORMAT :
69
- * By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
50
+ * By default, xxHash library provides endian-independent Hash values, based on little-endian convention.
70
51
  * Results are therefore identical for little-endian and big-endian CPU.
71
52
  * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
72
- * Should endian-independance be of no importance for your application, you may set the #define below to 1,
53
+ * Should endian-independence be of no importance for your application, you may set the #define below to 1,
73
54
  * to improve speed for Big-endian CPU.
74
55
  * This option has no impact on Little_Endian CPU.
75
56
  */
@@ -114,13 +95,13 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
114
95
  /* *************************************
115
96
  * Compiler Specific Options
116
97
  ***************************************/
117
- #if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
98
+ #if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
118
99
  # define INLINE_KEYWORD inline
119
100
  #else
120
101
  # define INLINE_KEYWORD
121
102
  #endif
122
103
 
123
- #if defined(__GNUC__)
104
+ #if defined(__GNUC__) || defined(__ICCARM__)
124
105
  # define FORCE_INLINE_ATTR __attribute__((always_inline))
125
106
  #elif defined(_MSC_VER)
126
107
  # define FORCE_INLINE_ATTR __forceinline
@@ -206,7 +187,12 @@ static U64 XXH_read64(const void* memPtr)
206
187
  # define XXH_rotl32(x,r) _rotl(x,r)
207
188
  # define XXH_rotl64(x,r) _rotl64(x,r)
208
189
  #else
190
+ #if defined(__ICCARM__)
191
+ # include <intrinsics.h>
192
+ # define XXH_rotl32(x,r) __ROR(x,(32 - r))
193
+ #else
209
194
  # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
195
+ #endif
210
196
  # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
211
197
  #endif
212
198
 
@@ -723,7 +709,9 @@ FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, c
723
709
  state->total_len += len;
724
710
 
725
711
  if (state->memsize + len < 32) { /* fill in tmp buffer */
726
- XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
712
+ if (input != NULL) {
713
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
714
+ }
727
715
  state->memsize += (U32)len;
728
716
  return XXH_OK;
729
717
  }