zstd-ruby 1.4.0.0 → 1.4.9.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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/README.md +2 -2
  4. data/ext/zstdruby/libzstd/Makefile +274 -107
  5. data/ext/zstdruby/libzstd/README.md +75 -16
  6. data/ext/zstdruby/libzstd/common/bitstream.h +59 -51
  7. data/ext/zstdruby/libzstd/common/compiler.h +154 -5
  8. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  9. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  10. data/ext/zstdruby/libzstd/common/debug.h +22 -49
  11. data/ext/zstdruby/libzstd/common/entropy_common.c +201 -75
  12. data/ext/zstdruby/libzstd/common/error_private.c +3 -1
  13. data/ext/zstdruby/libzstd/common/error_private.h +7 -3
  14. data/ext/zstdruby/libzstd/common/fse.h +50 -42
  15. data/ext/zstdruby/libzstd/common/fse_decompress.c +134 -50
  16. data/ext/zstdruby/libzstd/common/huf.h +41 -38
  17. data/ext/zstdruby/libzstd/common/mem.h +68 -22
  18. data/ext/zstdruby/libzstd/common/pool.c +30 -20
  19. data/ext/zstdruby/libzstd/common/pool.h +3 -3
  20. data/ext/zstdruby/libzstd/common/threading.c +51 -4
  21. data/ext/zstdruby/libzstd/common/threading.h +36 -4
  22. data/ext/zstdruby/libzstd/common/xxhash.c +39 -89
  23. data/ext/zstdruby/libzstd/common/xxhash.h +12 -32
  24. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  25. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  26. data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
  27. data/ext/zstdruby/libzstd/common/zstd_internal.h +231 -72
  28. data/ext/zstdruby/libzstd/common/zstd_trace.c +42 -0
  29. data/ext/zstdruby/libzstd/common/zstd_trace.h +152 -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 +288 -172
  34. data/ext/zstdruby/libzstd/compress/zstd_compress.c +2504 -1626
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +446 -85
  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 +433 -0
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +849 -0
  41. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  42. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +561 -0
  43. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +82 -60
  44. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  45. data/ext/zstdruby/libzstd/compress/zstd_fast.c +106 -80
  46. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  47. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +411 -105
  48. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
  49. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +296 -207
  50. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +14 -3
  51. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
  52. data/ext/zstdruby/libzstd/compress/zstd_opt.c +260 -148
  53. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  54. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +153 -440
  55. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +29 -110
  56. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +356 -238
  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 +641 -238
  60. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +600 -371
  61. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -5
  62. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +40 -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 +197 -78
  68. data/ext/zstdruby/libzstd/dictBuilder/cover.h +52 -7
  69. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  70. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +84 -66
  71. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +58 -36
  72. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +60 -31
  73. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  74. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  75. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +8 -4
  76. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +115 -111
  77. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  78. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +28 -14
  79. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  80. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +28 -14
  81. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  82. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +36 -19
  83. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  84. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +122 -107
  85. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
  86. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +29 -23
  87. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  88. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +34 -24
  89. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  90. data/ext/zstdruby/libzstd/libzstd.pc.in +2 -1
  91. data/ext/zstdruby/libzstd/zstd.h +655 -118
  92. data/lib/zstd-ruby/version.rb +1 -1
  93. data/zstd-ruby.gemspec +1 -1
  94. metadata +20 -10
  95. data/.travis.yml +0 -14
@@ -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-2021, 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
@@ -96,14 +77,12 @@
96
77
  * Includes & Memory related functions
97
78
  ***************************************/
98
79
  /* 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); }
80
+ /* for ZSTD_malloc(), ZSTD_free() */
81
+ #define ZSTD_DEPS_NEED_MALLOC
82
+ #include "zstd_deps.h" /* size_t, ZSTD_malloc, ZSTD_free, ZSTD_memcpy */
83
+ static void* XXH_malloc(size_t s) { return ZSTD_malloc(s); }
84
+ static void XXH_free (void* p) { ZSTD_free(p); }
85
+ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return ZSTD_memcpy(dest,src,size); }
107
86
 
108
87
  #ifndef XXH_STATIC_LINKING_ONLY
109
88
  # define XXH_STATIC_LINKING_ONLY
@@ -114,49 +93,13 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
114
93
  /* *************************************
115
94
  * Compiler Specific Options
116
95
  ***************************************/
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
96
+ #include "compiler.h"
137
97
 
138
98
 
139
99
  /* *************************************
140
100
  * Basic Types
141
101
  ***************************************/
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
-
102
+ #include "mem.h" /* BYTE, U32, U64, size_t */
160
103
 
161
104
  #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
162
105
 
@@ -182,14 +125,14 @@ static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
182
125
  static U32 XXH_read32(const void* memPtr)
183
126
  {
184
127
  U32 val;
185
- memcpy(&val, memPtr, sizeof(val));
128
+ ZSTD_memcpy(&val, memPtr, sizeof(val));
186
129
  return val;
187
130
  }
188
131
 
189
132
  static U64 XXH_read64(const void* memPtr)
190
133
  {
191
134
  U64 val;
192
- memcpy(&val, memPtr, sizeof(val));
135
+ ZSTD_memcpy(&val, memPtr, sizeof(val));
193
136
  return val;
194
137
  }
195
138
 
@@ -206,7 +149,12 @@ static U64 XXH_read64(const void* memPtr)
206
149
  # define XXH_rotl32(x,r) _rotl(x,r)
207
150
  # define XXH_rotl64(x,r) _rotl64(x,r)
208
151
  #else
152
+ #if defined(__ICCARM__)
153
+ # include <intrinsics.h>
154
+ # define XXH_rotl32(x,r) __ROR(x,(32 - r))
155
+ #else
209
156
  # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
157
+ #endif
210
158
  # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
211
159
  #endif
212
160
 
@@ -321,12 +269,12 @@ XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
321
269
  ****************************/
322
270
  XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState)
323
271
  {
324
- memcpy(dstState, srcState, sizeof(*dstState));
272
+ ZSTD_memcpy(dstState, srcState, sizeof(*dstState));
325
273
  }
326
274
 
327
275
  XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState)
328
276
  {
329
- memcpy(dstState, srcState, sizeof(*dstState));
277
+ ZSTD_memcpy(dstState, srcState, sizeof(*dstState));
330
278
  }
331
279
 
332
280
 
@@ -568,12 +516,12 @@ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
568
516
  XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
569
517
  {
570
518
  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 */
519
+ ZSTD_memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
572
520
  state.v1 = seed + PRIME32_1 + PRIME32_2;
573
521
  state.v2 = seed + PRIME32_2;
574
522
  state.v3 = seed + 0;
575
523
  state.v4 = seed - PRIME32_1;
576
- memcpy(statePtr, &state, sizeof(state));
524
+ ZSTD_memcpy(statePtr, &state, sizeof(state));
577
525
  return XXH_OK;
578
526
  }
579
527
 
@@ -581,12 +529,12 @@ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int s
581
529
  XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
582
530
  {
583
531
  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 */
532
+ ZSTD_memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
585
533
  state.v1 = seed + PRIME64_1 + PRIME64_2;
586
534
  state.v2 = seed + PRIME64_2;
587
535
  state.v3 = seed + 0;
588
536
  state.v4 = seed - PRIME64_1;
589
- memcpy(statePtr, &state, sizeof(state));
537
+ ZSTD_memcpy(statePtr, &state, sizeof(state));
590
538
  return XXH_OK;
591
539
  }
592
540
 
@@ -723,7 +671,9 @@ FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, c
723
671
  state->total_len += len;
724
672
 
725
673
  if (state->memsize + len < 32) { /* fill in tmp buffer */
726
- XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
674
+ if (input != NULL) {
675
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
676
+ }
727
677
  state->memsize += (U32)len;
728
678
  return XXH_OK;
729
679
  }
@@ -855,14 +805,14 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t
855
805
  {
856
806
  XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t));
857
807
  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
858
- memcpy(dst, &hash, sizeof(*dst));
808
+ ZSTD_memcpy(dst, &hash, sizeof(*dst));
859
809
  }
860
810
 
861
811
  XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash)
862
812
  {
863
813
  XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
864
814
  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
865
- memcpy(dst, &hash, sizeof(*dst));
815
+ ZSTD_memcpy(dst, &hash, sizeof(*dst));
866
816
  }
867
817
 
868
818
  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) 2012-2021, 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) 2016-2021, 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
  }
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright (c) 2016-2021, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ /* This file provides common libc dependencies that zstd requires.
12
+ * The purpose is to allow replacing this file with a custom implementation
13
+ * to compile zstd without libc support.
14
+ */
15
+
16
+ /* Need:
17
+ * NULL
18
+ * INT_MAX
19
+ * UINT_MAX
20
+ * ZSTD_memcpy()
21
+ * ZSTD_memset()
22
+ * ZSTD_memmove()
23
+ */
24
+ #ifndef ZSTD_DEPS_COMMON
25
+ #define ZSTD_DEPS_COMMON
26
+
27
+ #include <limits.h>
28
+ #include <stddef.h>
29
+ #include <string.h>
30
+
31
+ #if defined(__GNUC__) && __GNUC__ >= 4
32
+ # define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
33
+ # define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
34
+ # define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
35
+ #else
36
+ # define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
37
+ # define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
38
+ # define ZSTD_memset(p,v,l) memset((p),(v),(l))
39
+ #endif
40
+
41
+ #endif /* ZSTD_DEPS_COMMON */
42
+
43
+ /* Need:
44
+ * ZSTD_malloc()
45
+ * ZSTD_free()
46
+ * ZSTD_calloc()
47
+ */
48
+ #ifdef ZSTD_DEPS_NEED_MALLOC
49
+ #ifndef ZSTD_DEPS_MALLOC
50
+ #define ZSTD_DEPS_MALLOC
51
+
52
+ #include <stdlib.h>
53
+
54
+ #define ZSTD_malloc(s) malloc(s)
55
+ #define ZSTD_calloc(n,s) calloc((n), (s))
56
+ #define ZSTD_free(p) free((p))
57
+
58
+ #endif /* ZSTD_DEPS_MALLOC */
59
+ #endif /* ZSTD_DEPS_NEED_MALLOC */
60
+
61
+ /*
62
+ * Provides 64-bit math support.
63
+ * Need:
64
+ * U64 ZSTD_div64(U64 dividend, U32 divisor)
65
+ */
66
+ #ifdef ZSTD_DEPS_NEED_MATH64
67
+ #ifndef ZSTD_DEPS_MATH64
68
+ #define ZSTD_DEPS_MATH64
69
+
70
+ #define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
71
+
72
+ #endif /* ZSTD_DEPS_MATH64 */
73
+ #endif /* ZSTD_DEPS_NEED_MATH64 */
74
+
75
+ /* Need:
76
+ * assert()
77
+ */
78
+ #ifdef ZSTD_DEPS_NEED_ASSERT
79
+ #ifndef ZSTD_DEPS_ASSERT
80
+ #define ZSTD_DEPS_ASSERT
81
+
82
+ #include <assert.h>
83
+
84
+ #endif /* ZSTD_DEPS_ASSERT */
85
+ #endif /* ZSTD_DEPS_NEED_ASSERT */
86
+
87
+ /* Need:
88
+ * ZSTD_DEBUG_PRINT()
89
+ */
90
+ #ifdef ZSTD_DEPS_NEED_IO
91
+ #ifndef ZSTD_DEPS_IO
92
+ #define ZSTD_DEPS_IO
93
+
94
+ #include <stdio.h>
95
+ #define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
96
+
97
+ #endif /* ZSTD_DEPS_IO */
98
+ #endif /* ZSTD_DEPS_NEED_IO */
99
+
100
+ /* Only requested when <stdint.h> is known to be present.
101
+ * Need:
102
+ * intptr_t
103
+ */
104
+ #ifdef ZSTD_DEPS_NEED_STDINT
105
+ #ifndef ZSTD_DEPS_STDINT
106
+ #define ZSTD_DEPS_STDINT
107
+
108
+ #include <stdint.h>
109
+
110
+ #endif /* ZSTD_DEPS_STDINT */
111
+ #endif /* ZSTD_DEPS_NEED_STDINT */