zstd-ruby 1.4.1.0 → 1.5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) 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/libzstd/BUCK +5 -7
  6. data/ext/zstdruby/libzstd/Makefile +304 -113
  7. data/ext/zstdruby/libzstd/README.md +83 -20
  8. data/ext/zstdruby/libzstd/common/bitstream.h +59 -51
  9. data/ext/zstdruby/libzstd/common/compiler.h +150 -8
  10. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  11. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  12. data/ext/zstdruby/libzstd/common/debug.h +22 -49
  13. data/ext/zstdruby/libzstd/common/entropy_common.c +201 -75
  14. data/ext/zstdruby/libzstd/common/error_private.c +3 -1
  15. data/ext/zstdruby/libzstd/common/error_private.h +8 -4
  16. data/ext/zstdruby/libzstd/common/fse.h +50 -42
  17. data/ext/zstdruby/libzstd/common/fse_decompress.c +149 -55
  18. data/ext/zstdruby/libzstd/common/huf.h +43 -39
  19. data/ext/zstdruby/libzstd/common/mem.h +69 -25
  20. data/ext/zstdruby/libzstd/common/pool.c +30 -20
  21. data/ext/zstdruby/libzstd/common/pool.h +3 -3
  22. data/ext/zstdruby/libzstd/common/threading.c +51 -4
  23. data/ext/zstdruby/libzstd/common/threading.h +36 -4
  24. data/ext/zstdruby/libzstd/common/xxhash.c +40 -92
  25. data/ext/zstdruby/libzstd/common/xxhash.h +12 -32
  26. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  27. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  28. data/ext/zstdruby/libzstd/common/zstd_internal.h +230 -111
  29. data/ext/zstdruby/libzstd/common/zstd_trace.h +154 -0
  30. data/ext/zstdruby/libzstd/compress/fse_compress.c +47 -63
  31. data/ext/zstdruby/libzstd/compress/hist.c +41 -63
  32. data/ext/zstdruby/libzstd/compress/hist.h +13 -33
  33. data/ext/zstdruby/libzstd/compress/huf_compress.c +332 -193
  34. data/ext/zstdruby/libzstd/compress/zstd_compress.c +3614 -1696
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +546 -86
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +441 -0
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +572 -0
  41. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  42. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +662 -0
  43. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +43 -41
  44. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  45. data/ext/zstdruby/libzstd/compress/zstd_fast.c +85 -80
  46. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  47. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +1184 -111
  48. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +59 -1
  49. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +333 -208
  50. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +15 -3
  51. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
  52. data/ext/zstdruby/libzstd/compress/zstd_opt.c +228 -129
  53. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  54. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +151 -440
  55. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +32 -114
  56. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +395 -276
  57. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +20 -16
  58. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +3 -3
  59. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +630 -231
  60. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +606 -380
  61. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -5
  62. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +39 -9
  63. data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
  64. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
  65. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
  66. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  67. data/ext/zstdruby/libzstd/dictBuilder/cover.c +55 -46
  68. data/ext/zstdruby/libzstd/dictBuilder/cover.h +20 -9
  69. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  70. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +43 -31
  71. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +53 -30
  72. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  73. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  74. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +4 -4
  75. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +24 -14
  76. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  77. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +17 -8
  78. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  79. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +17 -8
  80. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  81. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +25 -11
  82. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  83. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +43 -32
  84. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
  85. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +27 -19
  86. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  87. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +32 -20
  88. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  89. data/ext/zstdruby/libzstd/libzstd.pc.in +2 -1
  90. data/ext/zstdruby/libzstd/{dictBuilder/zdict.h → zdict.h} +201 -31
  91. data/ext/zstdruby/libzstd/zstd.h +740 -153
  92. data/ext/zstdruby/libzstd/{common/zstd_errors.h → zstd_errors.h} +3 -1
  93. data/lib/zstd-ruby/version.rb +1 -1
  94. data/zstd-ruby.gemspec +1 -1
  95. metadata +21 -10
  96. data/.travis.yml +0 -14
@@ -2,18 +2,21 @@
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
 
18
+ #include "threading.h"
19
+
17
20
  /* create fake symbol to avoid empty translation unit warning */
18
21
  int g_ZSTD_threading_useless_symbol;
19
22
 
@@ -28,7 +31,6 @@ int g_ZSTD_threading_useless_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,48 @@ 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
+ #define ZSTD_DEPS_NEED_MALLOC
82
+ #include "zstd_deps.h"
83
+
84
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
85
+ {
86
+ *mutex = (pthread_mutex_t*)ZSTD_malloc(sizeof(pthread_mutex_t));
87
+ if (!*mutex)
88
+ return 1;
89
+ return pthread_mutex_init(*mutex, attr);
90
+ }
91
+
92
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
93
+ {
94
+ if (!*mutex)
95
+ return 0;
96
+ {
97
+ int const ret = pthread_mutex_destroy(*mutex);
98
+ ZSTD_free(*mutex);
99
+ return ret;
100
+ }
101
+ }
102
+
103
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
104
+ {
105
+ *cond = (pthread_cond_t*)ZSTD_malloc(sizeof(pthread_cond_t));
106
+ if (!*cond)
107
+ return 1;
108
+ return pthread_cond_init(*cond, attr);
109
+ }
110
+
111
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
112
+ {
113
+ if (!*cond)
114
+ return 0;
115
+ {
116
+ int const ret = pthread_cond_destroy(*cond);
117
+ ZSTD_free(*cond);
118
+ return ret;
119
+ }
120
+ }
121
+
122
+ #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) 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
 
@@ -50,10 +30,9 @@
50
30
  * Prefer these methods in priority order (0 > 1 > 2)
51
31
  */
52
32
  #ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
53
- # 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
- # define XXH_FORCE_MEMORY_ACCESS 2
55
- # 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__) ))
33
+ # if (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
34
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) || \
35
+ defined(__ICCARM__)
57
36
  # define XXH_FORCE_MEMORY_ACCESS 1
58
37
  # endif
59
38
  #endif
@@ -96,14 +75,12 @@
96
75
  * Includes & Memory related functions
97
76
  ***************************************/
98
77
  /* Modify the local functions below should you wish to use some other memory routines */
99
- /* for malloc(), free() */
100
- #include <stdlib.h>
101
- #include <stddef.h> /* size_t */
102
- static void* XXH_malloc(size_t s) { return malloc(s); }
103
- static void XXH_free (void* p) { free(p); }
104
- /* for memcpy() */
105
- #include <string.h>
106
- static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
78
+ /* for ZSTD_malloc(), ZSTD_free() */
79
+ #define ZSTD_DEPS_NEED_MALLOC
80
+ #include "zstd_deps.h" /* size_t, ZSTD_malloc, ZSTD_free, ZSTD_memcpy */
81
+ static void* XXH_malloc(size_t s) { return ZSTD_malloc(s); }
82
+ static void XXH_free (void* p) { ZSTD_free(p); }
83
+ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return ZSTD_memcpy(dest,src,size); }
107
84
 
108
85
  #ifndef XXH_STATIC_LINKING_ONLY
109
86
  # define XXH_STATIC_LINKING_ONLY
@@ -114,49 +91,13 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
114
91
  /* *************************************
115
92
  * Compiler Specific Options
116
93
  ***************************************/
117
- #if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
118
- # define INLINE_KEYWORD inline
119
- #else
120
- # define INLINE_KEYWORD
121
- #endif
122
-
123
- #if defined(__GNUC__)
124
- # define FORCE_INLINE_ATTR __attribute__((always_inline))
125
- #elif defined(_MSC_VER)
126
- # define FORCE_INLINE_ATTR __forceinline
127
- #else
128
- # define FORCE_INLINE_ATTR
129
- #endif
130
-
131
- #define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
132
-
133
-
134
- #ifdef _MSC_VER
135
- # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
136
- #endif
94
+ #include "compiler.h"
137
95
 
138
96
 
139
97
  /* *************************************
140
98
  * Basic Types
141
99
  ***************************************/
142
- #ifndef MEM_MODULE
143
- # define MEM_MODULE
144
- # if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
145
- # include <stdint.h>
146
- typedef uint8_t BYTE;
147
- typedef uint16_t U16;
148
- typedef uint32_t U32;
149
- typedef int32_t S32;
150
- typedef uint64_t U64;
151
- # else
152
- typedef unsigned char BYTE;
153
- typedef unsigned short U16;
154
- typedef unsigned int U32;
155
- typedef signed int S32;
156
- typedef unsigned long long U64; /* if your compiler doesn't support unsigned long long, replace by another 64-bit type here. Note that xxhash.h will also need to be updated. */
157
- # endif
158
- #endif
159
-
100
+ #include "mem.h" /* BYTE, U32, U64, size_t */
160
101
 
161
102
  #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
162
103
 
@@ -182,14 +123,14 @@ static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
182
123
  static U32 XXH_read32(const void* memPtr)
183
124
  {
184
125
  U32 val;
185
- memcpy(&val, memPtr, sizeof(val));
126
+ ZSTD_memcpy(&val, memPtr, sizeof(val));
186
127
  return val;
187
128
  }
188
129
 
189
130
  static U64 XXH_read64(const void* memPtr)
190
131
  {
191
132
  U64 val;
192
- memcpy(&val, memPtr, sizeof(val));
133
+ ZSTD_memcpy(&val, memPtr, sizeof(val));
193
134
  return val;
194
135
  }
195
136
 
@@ -206,7 +147,12 @@ static U64 XXH_read64(const void* memPtr)
206
147
  # define XXH_rotl32(x,r) _rotl(x,r)
207
148
  # define XXH_rotl64(x,r) _rotl64(x,r)
208
149
  #else
150
+ #if defined(__ICCARM__)
151
+ # include <intrinsics.h>
152
+ # define XXH_rotl32(x,r) __ROR(x,(32 - r))
153
+ #else
209
154
  # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
155
+ #endif
210
156
  # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
211
157
  #endif
212
158
 
@@ -321,12 +267,12 @@ XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
321
267
  ****************************/
322
268
  XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState)
323
269
  {
324
- memcpy(dstState, srcState, sizeof(*dstState));
270
+ ZSTD_memcpy(dstState, srcState, sizeof(*dstState));
325
271
  }
326
272
 
327
273
  XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState)
328
274
  {
329
- memcpy(dstState, srcState, sizeof(*dstState));
275
+ ZSTD_memcpy(dstState, srcState, sizeof(*dstState));
330
276
  }
331
277
 
332
278
 
@@ -568,12 +514,12 @@ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
568
514
  XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
569
515
  {
570
516
  XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
571
- memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
517
+ ZSTD_memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
572
518
  state.v1 = seed + PRIME32_1 + PRIME32_2;
573
519
  state.v2 = seed + PRIME32_2;
574
520
  state.v3 = seed + 0;
575
521
  state.v4 = seed - PRIME32_1;
576
- memcpy(statePtr, &state, sizeof(state));
522
+ ZSTD_memcpy(statePtr, &state, sizeof(state));
577
523
  return XXH_OK;
578
524
  }
579
525
 
@@ -581,12 +527,12 @@ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int s
581
527
  XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
582
528
  {
583
529
  XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
584
- memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
530
+ ZSTD_memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
585
531
  state.v1 = seed + PRIME64_1 + PRIME64_2;
586
532
  state.v2 = seed + PRIME64_2;
587
533
  state.v3 = seed + 0;
588
534
  state.v4 = seed - PRIME64_1;
589
- memcpy(statePtr, &state, sizeof(state));
535
+ ZSTD_memcpy(statePtr, &state, sizeof(state));
590
536
  return XXH_OK;
591
537
  }
592
538
 
@@ -723,7 +669,9 @@ FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, c
723
669
  state->total_len += len;
724
670
 
725
671
  if (state->memsize + len < 32) { /* fill in tmp buffer */
726
- XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
672
+ if (input != NULL) {
673
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
674
+ }
727
675
  state->memsize += (U32)len;
728
676
  return XXH_OK;
729
677
  }
@@ -855,14 +803,14 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t
855
803
  {
856
804
  XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t));
857
805
  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
858
- memcpy(dst, &hash, sizeof(*dst));
806
+ ZSTD_memcpy(dst, &hash, sizeof(*dst));
859
807
  }
860
808
 
861
809
  XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash)
862
810
  {
863
811
  XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
864
812
  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
865
- memcpy(dst, &hash, sizeof(*dst));
813
+ ZSTD_memcpy(dst, &hash, sizeof(*dst));
866
814
  }
867
815
 
868
816
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src)
@@ -1,35 +1,15 @@
1
1
  /*
2
- xxHash - Extremely Fast Hash algorithm
3
- Header File
4
- Copyright (C) 2012-2016, 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
- - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Extremely Fast Hash algorithm
3
+ * Header File
4
+ * Copyright (c) Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
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
  /* Notice extracted from xxHash homepage :
@@ -75,7 +55,7 @@ extern "C" {
75
55
  /* ****************************
76
56
  * Definitions
77
57
  ******************************/
78
- #include <stddef.h> /* size_t */
58
+ #include "zstd_deps.h"
79
59
  typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
80
60
 
81
61
 
@@ -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
@@ -13,8 +13,8 @@
13
13
  /*-*************************************
14
14
  * Dependencies
15
15
  ***************************************/
16
- #include <stdlib.h> /* malloc, calloc, free */
17
- #include <string.h> /* memset */
16
+ #define ZSTD_DEPS_NEED_MALLOC
17
+ #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
18
18
  #include "error_private.h"
19
19
  #include "zstd_internal.h"
20
20
 
@@ -53,31 +53,31 @@ const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString
53
53
  /*=**************************************************************
54
54
  * Custom allocator
55
55
  ****************************************************************/
56
- void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
56
+ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
57
57
  {
58
58
  if (customMem.customAlloc)
59
59
  return customMem.customAlloc(customMem.opaque, size);
60
- return malloc(size);
60
+ return ZSTD_malloc(size);
61
61
  }
62
62
 
63
- void* ZSTD_calloc(size_t size, ZSTD_customMem customMem)
63
+ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
64
64
  {
65
65
  if (customMem.customAlloc) {
66
66
  /* calloc implemented as malloc+memset;
67
67
  * not as efficient as calloc, but next best guess for custom malloc */
68
68
  void* const ptr = customMem.customAlloc(customMem.opaque, size);
69
- memset(ptr, 0, size);
69
+ ZSTD_memset(ptr, 0, size);
70
70
  return ptr;
71
71
  }
72
- return calloc(1, size);
72
+ return ZSTD_calloc(1, size);
73
73
  }
74
74
 
75
- void ZSTD_free(void* ptr, ZSTD_customMem customMem)
75
+ void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
76
76
  {
77
77
  if (ptr!=NULL) {
78
78
  if (customMem.customFree)
79
79
  customMem.customFree(customMem.opaque, ptr);
80
80
  else
81
- free(ptr);
81
+ ZSTD_free(ptr);
82
82
  }
83
83
  }