extzstd 0.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/README.md +38 -56
  4. data/contrib/zstd/CHANGELOG +613 -0
  5. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  6. data/contrib/zstd/CONTRIBUTING.md +406 -0
  7. data/contrib/zstd/COPYING +339 -0
  8. data/contrib/zstd/Makefile +420 -0
  9. data/contrib/zstd/README.md +179 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +292 -0
  12. data/contrib/zstd/lib/BUCK +234 -0
  13. data/contrib/zstd/lib/Makefile +451 -0
  14. data/contrib/zstd/lib/README.md +207 -0
  15. data/contrib/zstd/{common → lib/common}/bitstream.h +187 -138
  16. data/contrib/zstd/lib/common/compiler.h +288 -0
  17. data/contrib/zstd/lib/common/cpu.h +213 -0
  18. data/contrib/zstd/lib/common/debug.c +24 -0
  19. data/contrib/zstd/lib/common/debug.h +107 -0
  20. data/contrib/zstd/lib/common/entropy_common.c +362 -0
  21. data/contrib/zstd/{common → lib/common}/error_private.c +25 -12
  22. data/contrib/zstd/{common → lib/common}/error_private.h +14 -10
  23. data/contrib/zstd/{common → lib/common}/fse.h +173 -92
  24. data/contrib/zstd/{common → lib/common}/fse_decompress.c +149 -85
  25. data/contrib/zstd/lib/common/huf.h +361 -0
  26. data/contrib/zstd/{common → lib/common}/mem.h +115 -59
  27. data/contrib/zstd/lib/common/pool.c +350 -0
  28. data/contrib/zstd/lib/common/pool.h +84 -0
  29. data/contrib/zstd/lib/common/threading.c +122 -0
  30. data/contrib/zstd/lib/common/threading.h +155 -0
  31. data/contrib/zstd/{common → lib/common}/xxhash.c +55 -96
  32. data/contrib/zstd/{common → lib/common}/xxhash.h +23 -47
  33. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  34. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  35. data/contrib/zstd/lib/common/zstd_errors.h +95 -0
  36. data/contrib/zstd/lib/common/zstd_internal.h +478 -0
  37. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +214 -319
  38. data/contrib/zstd/lib/compress/hist.c +181 -0
  39. data/contrib/zstd/lib/compress/hist.h +75 -0
  40. data/contrib/zstd/lib/compress/huf_compress.c +913 -0
  41. data/contrib/zstd/lib/compress/zstd_compress.c +5208 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1203 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +433 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +849 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  49. data/contrib/zstd/lib/compress/zstd_cwksp.h +561 -0
  50. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  52. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  54. data/contrib/zstd/lib/compress/zstd_lazy.c +1412 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.h +87 -0
  56. data/contrib/zstd/lib/compress/zstd_ldm.c +660 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.h +116 -0
  58. data/contrib/zstd/lib/compress/zstd_opt.c +1345 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  60. data/contrib/zstd/lib/compress/zstdmt_compress.c +1811 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.h +110 -0
  62. data/contrib/zstd/lib/decompress/huf_decompress.c +1350 -0
  63. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  65. data/contrib/zstd/lib/decompress/zstd_decompress.c +1930 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1540 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +62 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +190 -0
  69. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +68 -45
  70. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  71. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  73. data/contrib/zstd/lib/dictBuilder/cover.c +1245 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  75. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  77. data/contrib/zstd/lib/dictBuilder/fastcover.c +758 -0
  78. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +318 -194
  79. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  80. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +171 -15
  81. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +191 -124
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +19 -5
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +125 -125
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +19 -5
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +125 -124
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +20 -6
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +151 -299
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +19 -5
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +237 -243
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +19 -6
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +130 -143
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +18 -5
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +158 -157
  94. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +19 -5
  95. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  96. data/contrib/zstd/lib/zstd.h +2391 -0
  97. data/ext/depend +2 -0
  98. data/ext/extconf.rb +15 -6
  99. data/ext/extzstd.c +76 -145
  100. data/ext/extzstd.h +80 -31
  101. data/ext/extzstd_stream.c +417 -142
  102. data/ext/libzstd_conf.h +8 -0
  103. data/ext/zstd_common.c +10 -7
  104. data/ext/zstd_compress.c +14 -5
  105. data/ext/zstd_decompress.c +5 -4
  106. data/ext/zstd_dictbuilder.c +9 -4
  107. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  108. data/ext/zstd_legacy_v01.c +3 -1
  109. data/ext/zstd_legacy_v02.c +3 -1
  110. data/ext/zstd_legacy_v03.c +3 -1
  111. data/ext/zstd_legacy_v04.c +3 -1
  112. data/ext/zstd_legacy_v05.c +3 -1
  113. data/ext/zstd_legacy_v06.c +3 -1
  114. data/ext/zstd_legacy_v07.c +3 -1
  115. data/gemstub.rb +10 -24
  116. data/lib/extzstd.rb +64 -179
  117. data/lib/extzstd/version.rb +6 -1
  118. data/test/test_basic.rb +9 -6
  119. metadata +113 -57
  120. data/HISTORY.ja +0 -5
  121. data/contrib/zstd/common/entropy_common.c +0 -225
  122. data/contrib/zstd/common/huf.h +0 -228
  123. data/contrib/zstd/common/zstd_common.c +0 -83
  124. data/contrib/zstd/common/zstd_errors.h +0 -60
  125. data/contrib/zstd/common/zstd_internal.h +0 -267
  126. data/contrib/zstd/compress/huf_compress.c +0 -533
  127. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  128. data/contrib/zstd/compress/zstd_compress.c +0 -3264
  129. data/contrib/zstd/compress/zstd_opt.h +0 -900
  130. data/contrib/zstd/decompress/huf_decompress.c +0 -883
  131. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  132. data/contrib/zstd/decompress/zstd_decompress.c +0 -1842
  133. data/contrib/zstd/dictBuilder/zdict.h +0 -111
  134. data/contrib/zstd/zstd.h +0 -640
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright (c) 2016-2020, Yann Collet, 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
+ #ifndef POOL_H
12
+ #define POOL_H
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+
19
+ #include "zstd_deps.h"
20
+ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
21
+ #include "../zstd.h"
22
+
23
+ typedef struct POOL_ctx_s POOL_ctx;
24
+
25
+ /*! POOL_create() :
26
+ * Create a thread pool with at most `numThreads` threads.
27
+ * `numThreads` must be at least 1.
28
+ * The maximum number of queued jobs before blocking is `queueSize`.
29
+ * @return : POOL_ctx pointer on success, else NULL.
30
+ */
31
+ POOL_ctx* POOL_create(size_t numThreads, size_t queueSize);
32
+
33
+ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
34
+ ZSTD_customMem customMem);
35
+
36
+ /*! POOL_free() :
37
+ * Free a thread pool returned by POOL_create().
38
+ */
39
+ void POOL_free(POOL_ctx* ctx);
40
+
41
+ /*! POOL_resize() :
42
+ * Expands or shrinks pool's number of threads.
43
+ * This is more efficient than releasing + creating a new context,
44
+ * since it tries to preserve and re-use existing threads.
45
+ * `numThreads` must be at least 1.
46
+ * @return : 0 when resize was successful,
47
+ * !0 (typically 1) if there is an error.
48
+ * note : only numThreads can be resized, queueSize remains unchanged.
49
+ */
50
+ int POOL_resize(POOL_ctx* ctx, size_t numThreads);
51
+
52
+ /*! POOL_sizeof() :
53
+ * @return threadpool memory usage
54
+ * note : compatible with NULL (returns 0 in this case)
55
+ */
56
+ size_t POOL_sizeof(POOL_ctx* ctx);
57
+
58
+ /*! POOL_function :
59
+ * The function type that can be added to a thread pool.
60
+ */
61
+ typedef void (*POOL_function)(void*);
62
+
63
+ /*! POOL_add() :
64
+ * Add the job `function(opaque)` to the thread pool. `ctx` must be valid.
65
+ * Possibly blocks until there is room in the queue.
66
+ * Note : The function may be executed asynchronously,
67
+ * therefore, `opaque` must live until function has been completed.
68
+ */
69
+ void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
70
+
71
+
72
+ /*! POOL_tryAdd() :
73
+ * Add the job `function(opaque)` to thread pool _if_ a worker is available.
74
+ * Returns immediately even if not (does not block).
75
+ * @return : 1 if successful, 0 if not.
76
+ */
77
+ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque);
78
+
79
+
80
+ #if defined (__cplusplus)
81
+ }
82
+ #endif
83
+
84
+ #endif
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Copyright (c) 2016 Tino Reichardt
3
+ * All rights reserved.
4
+ *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
8
+ * This source code is licensed under both the BSD-style license (found in the
9
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
10
+ * in the COPYING file in the root directory of this source tree).
11
+ * You may select, at your option, one of the above-listed licenses.
12
+ */
13
+
14
+ /**
15
+ * This file will hold wrapper for systems, which do not support pthreads
16
+ */
17
+
18
+ #include "threading.h"
19
+
20
+ /* create fake symbol to avoid empty translation unit warning */
21
+ int g_ZSTD_threading_useless_symbol;
22
+
23
+ #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
24
+
25
+ /**
26
+ * Windows minimalist Pthread Wrapper, based on :
27
+ * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
28
+ */
29
+
30
+
31
+ /* === Dependencies === */
32
+ #include <process.h>
33
+ #include <errno.h>
34
+
35
+
36
+ /* === Implementation === */
37
+
38
+ static unsigned __stdcall worker(void *arg)
39
+ {
40
+ ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg;
41
+ thread->arg = thread->start_routine(thread->arg);
42
+ return 0;
43
+ }
44
+
45
+ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
46
+ void* (*start_routine) (void*), void* arg)
47
+ {
48
+ (void)unused;
49
+ thread->arg = arg;
50
+ thread->start_routine = start_routine;
51
+ thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL);
52
+
53
+ if (!thread->handle)
54
+ return errno;
55
+ else
56
+ return 0;
57
+ }
58
+
59
+ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
60
+ {
61
+ DWORD result;
62
+
63
+ if (!thread.handle) return 0;
64
+
65
+ result = WaitForSingleObject(thread.handle, INFINITE);
66
+ switch (result) {
67
+ case WAIT_OBJECT_0:
68
+ if (value_ptr) *value_ptr = thread.arg;
69
+ return 0;
70
+ case WAIT_ABANDONED:
71
+ return EINVAL;
72
+ default:
73
+ return GetLastError();
74
+ }
75
+ }
76
+
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
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Copyright (c) 2016 Tino Reichardt
3
+ * All rights reserved.
4
+ *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
8
+ * This source code is licensed under both the BSD-style license (found in the
9
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
10
+ * in the COPYING file in the root directory of this source tree).
11
+ * You may select, at your option, one of the above-listed licenses.
12
+ */
13
+
14
+ #ifndef THREADING_H_938743
15
+ #define THREADING_H_938743
16
+
17
+ #include "debug.h"
18
+
19
+ #if defined (__cplusplus)
20
+ extern "C" {
21
+ #endif
22
+
23
+ #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
24
+
25
+ /**
26
+ * Windows minimalist Pthread Wrapper, based on :
27
+ * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
28
+ */
29
+ #ifdef WINVER
30
+ # undef WINVER
31
+ #endif
32
+ #define WINVER 0x0600
33
+
34
+ #ifdef _WIN32_WINNT
35
+ # undef _WIN32_WINNT
36
+ #endif
37
+ #define _WIN32_WINNT 0x0600
38
+
39
+ #ifndef WIN32_LEAN_AND_MEAN
40
+ # define WIN32_LEAN_AND_MEAN
41
+ #endif
42
+
43
+ #undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
44
+ #include <windows.h>
45
+ #undef ERROR
46
+ #define ERROR(name) ZSTD_ERROR(name)
47
+
48
+
49
+ /* mutex */
50
+ #define ZSTD_pthread_mutex_t CRITICAL_SECTION
51
+ #define ZSTD_pthread_mutex_init(a, b) ((void)(b), InitializeCriticalSection((a)), 0)
52
+ #define ZSTD_pthread_mutex_destroy(a) DeleteCriticalSection((a))
53
+ #define ZSTD_pthread_mutex_lock(a) EnterCriticalSection((a))
54
+ #define ZSTD_pthread_mutex_unlock(a) LeaveCriticalSection((a))
55
+
56
+ /* condition variable */
57
+ #define ZSTD_pthread_cond_t CONDITION_VARIABLE
58
+ #define ZSTD_pthread_cond_init(a, b) ((void)(b), InitializeConditionVariable((a)), 0)
59
+ #define ZSTD_pthread_cond_destroy(a) ((void)(a))
60
+ #define ZSTD_pthread_cond_wait(a, b) SleepConditionVariableCS((a), (b), INFINITE)
61
+ #define ZSTD_pthread_cond_signal(a) WakeConditionVariable((a))
62
+ #define ZSTD_pthread_cond_broadcast(a) WakeAllConditionVariable((a))
63
+
64
+ /* ZSTD_pthread_create() and ZSTD_pthread_join() */
65
+ typedef struct {
66
+ HANDLE handle;
67
+ void* (*start_routine)(void*);
68
+ void* arg;
69
+ } ZSTD_pthread_t;
70
+
71
+ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
72
+ void* (*start_routine) (void*), void* arg);
73
+
74
+ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
75
+
76
+ /**
77
+ * add here more wrappers as required
78
+ */
79
+
80
+
81
+ #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
82
+ /* === POSIX Systems === */
83
+ # include <pthread.h>
84
+
85
+ #if DEBUGLEVEL < 1
86
+
87
+ #define ZSTD_pthread_mutex_t pthread_mutex_t
88
+ #define ZSTD_pthread_mutex_init(a, b) pthread_mutex_init((a), (b))
89
+ #define ZSTD_pthread_mutex_destroy(a) pthread_mutex_destroy((a))
90
+ #define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock((a))
91
+ #define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock((a))
92
+
93
+ #define ZSTD_pthread_cond_t pthread_cond_t
94
+ #define ZSTD_pthread_cond_init(a, b) pthread_cond_init((a), (b))
95
+ #define ZSTD_pthread_cond_destroy(a) pthread_cond_destroy((a))
96
+ #define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait((a), (b))
97
+ #define ZSTD_pthread_cond_signal(a) pthread_cond_signal((a))
98
+ #define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast((a))
99
+
100
+ #define ZSTD_pthread_t pthread_t
101
+ #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
102
+ #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
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
+
131
+ #else /* ZSTD_MULTITHREAD not defined */
132
+ /* No multithreading support */
133
+
134
+ typedef int ZSTD_pthread_mutex_t;
135
+ #define ZSTD_pthread_mutex_init(a, b) ((void)(a), (void)(b), 0)
136
+ #define ZSTD_pthread_mutex_destroy(a) ((void)(a))
137
+ #define ZSTD_pthread_mutex_lock(a) ((void)(a))
138
+ #define ZSTD_pthread_mutex_unlock(a) ((void)(a))
139
+
140
+ typedef int ZSTD_pthread_cond_t;
141
+ #define ZSTD_pthread_cond_init(a, b) ((void)(a), (void)(b), 0)
142
+ #define ZSTD_pthread_cond_destroy(a) ((void)(a))
143
+ #define ZSTD_pthread_cond_wait(a, b) ((void)(a), (void)(b))
144
+ #define ZSTD_pthread_cond_signal(a) ((void)(a))
145
+ #define ZSTD_pthread_cond_broadcast(a) ((void)(a))
146
+
147
+ /* do not use ZSTD_pthread_t */
148
+
149
+ #endif /* ZSTD_MULTITHREAD */
150
+
151
+ #if defined (__cplusplus)
152
+ }
153
+ #endif
154
+
155
+ #endif /* THREADING_H_938743 */
@@ -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
  */
@@ -96,58 +77,29 @@
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
- static void* XXH_malloc(size_t s) { return malloc(s); }
102
- static void XXH_free (void* p) { free(p); }
103
- /* for memcpy() */
104
- #include <string.h>
105
- static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
106
-
107
- #define XXH_STATIC_LINKING_ONLY
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); }
86
+
87
+ #ifndef XXH_STATIC_LINKING_ONLY
88
+ # define XXH_STATIC_LINKING_ONLY
89
+ #endif
108
90
  #include "xxhash.h"
109
91
 
110
92
 
111
93
  /* *************************************
112
94
  * Compiler Specific Options
113
95
  ***************************************/
114
- #ifdef _MSC_VER /* Visual Studio */
115
- # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
116
- # define FORCE_INLINE static __forceinline
117
- #else
118
- # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
119
- # ifdef __GNUC__
120
- # define FORCE_INLINE static inline __attribute__((always_inline))
121
- # else
122
- # define FORCE_INLINE static inline
123
- # endif
124
- # else
125
- # define FORCE_INLINE static
126
- # endif /* __STDC_VERSION__ */
127
- #endif
96
+ #include "compiler.h"
128
97
 
129
98
 
130
99
  /* *************************************
131
100
  * Basic Types
132
101
  ***************************************/
133
- #ifndef MEM_MODULE
134
- # define MEM_MODULE
135
- # if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
136
- # include <stdint.h>
137
- typedef uint8_t BYTE;
138
- typedef uint16_t U16;
139
- typedef uint32_t U32;
140
- typedef int32_t S32;
141
- typedef uint64_t U64;
142
- # else
143
- typedef unsigned char BYTE;
144
- typedef unsigned short U16;
145
- typedef unsigned int U32;
146
- typedef signed int S32;
147
- 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. */
148
- # endif
149
- #endif
150
-
102
+ #include "mem.h" /* BYTE, U32, U64, size_t */
151
103
 
152
104
  #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
153
105
 
@@ -173,14 +125,14 @@ static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
173
125
  static U32 XXH_read32(const void* memPtr)
174
126
  {
175
127
  U32 val;
176
- memcpy(&val, memPtr, sizeof(val));
128
+ ZSTD_memcpy(&val, memPtr, sizeof(val));
177
129
  return val;
178
130
  }
179
131
 
180
132
  static U64 XXH_read64(const void* memPtr)
181
133
  {
182
134
  U64 val;
183
- memcpy(&val, memPtr, sizeof(val));
135
+ ZSTD_memcpy(&val, memPtr, sizeof(val));
184
136
  return val;
185
137
  }
186
138
 
@@ -197,7 +149,12 @@ static U64 XXH_read64(const void* memPtr)
197
149
  # define XXH_rotl32(x,r) _rotl(x,r)
198
150
  # define XXH_rotl64(x,r) _rotl64(x,r)
199
151
  #else
152
+ #if defined(__ICCARM__)
153
+ # include <intrinsics.h>
154
+ # define XXH_rotl32(x,r) __ROR(x,(32 - r))
155
+ #else
200
156
  # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
157
+ #endif
201
158
  # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
202
159
  #endif
203
160
 
@@ -246,7 +203,7 @@ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
246
203
  *****************************/
247
204
  typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
248
205
 
249
- FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
206
+ FORCE_INLINE_TEMPLATE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
250
207
  {
251
208
  if (align==XXH_unaligned)
252
209
  return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
@@ -254,7 +211,7 @@ FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_a
254
211
  return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
255
212
  }
256
213
 
257
- FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
214
+ FORCE_INLINE_TEMPLATE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
258
215
  {
259
216
  return XXH_readLE32_align(ptr, endian, XXH_unaligned);
260
217
  }
@@ -264,7 +221,7 @@ static U32 XXH_readBE32(const void* ptr)
264
221
  return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
265
222
  }
266
223
 
267
- FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
224
+ FORCE_INLINE_TEMPLATE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
268
225
  {
269
226
  if (align==XXH_unaligned)
270
227
  return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
@@ -272,7 +229,7 @@ FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_a
272
229
  return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
273
230
  }
274
231
 
275
- FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
232
+ FORCE_INLINE_TEMPLATE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
276
233
  {
277
234
  return XXH_readLE64_align(ptr, endian, XXH_unaligned);
278
235
  }
@@ -312,12 +269,12 @@ XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
312
269
  ****************************/
313
270
  XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState)
314
271
  {
315
- memcpy(dstState, srcState, sizeof(*dstState));
272
+ ZSTD_memcpy(dstState, srcState, sizeof(*dstState));
316
273
  }
317
274
 
318
275
  XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState)
319
276
  {
320
- memcpy(dstState, srcState, sizeof(*dstState));
277
+ ZSTD_memcpy(dstState, srcState, sizeof(*dstState));
321
278
  }
322
279
 
323
280
 
@@ -333,7 +290,7 @@ static U32 XXH32_round(U32 seed, U32 input)
333
290
  return seed;
334
291
  }
335
292
 
336
- FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
293
+ FORCE_INLINE_TEMPLATE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
337
294
  {
338
295
  const BYTE* p = (const BYTE*)input;
339
296
  const BYTE* bEnd = p + len;
@@ -433,7 +390,7 @@ static U64 XXH64_mergeRound(U64 acc, U64 val)
433
390
  return acc;
434
391
  }
435
392
 
436
- FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
393
+ FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
437
394
  {
438
395
  const BYTE* p = (const BYTE*)input;
439
396
  const BYTE* const bEnd = p + len;
@@ -559,12 +516,12 @@ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
559
516
  XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
560
517
  {
561
518
  XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
562
- 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 */
563
520
  state.v1 = seed + PRIME32_1 + PRIME32_2;
564
521
  state.v2 = seed + PRIME32_2;
565
522
  state.v3 = seed + 0;
566
523
  state.v4 = seed - PRIME32_1;
567
- memcpy(statePtr, &state, sizeof(state));
524
+ ZSTD_memcpy(statePtr, &state, sizeof(state));
568
525
  return XXH_OK;
569
526
  }
570
527
 
@@ -572,17 +529,17 @@ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int s
572
529
  XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
573
530
  {
574
531
  XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
575
- 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 */
576
533
  state.v1 = seed + PRIME64_1 + PRIME64_2;
577
534
  state.v2 = seed + PRIME64_2;
578
535
  state.v3 = seed + 0;
579
536
  state.v4 = seed - PRIME64_1;
580
- memcpy(statePtr, &state, sizeof(state));
537
+ ZSTD_memcpy(statePtr, &state, sizeof(state));
581
538
  return XXH_OK;
582
539
  }
583
540
 
584
541
 
585
- FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
542
+ FORCE_INLINE_TEMPLATE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
586
543
  {
587
544
  const BYTE* p = (const BYTE*)input;
588
545
  const BYTE* const bEnd = p + len;
@@ -652,7 +609,7 @@ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void*
652
609
 
653
610
 
654
611
 
655
- FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
612
+ FORCE_INLINE_TEMPLATE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
656
613
  {
657
614
  const BYTE * p = (const BYTE*)state->mem32;
658
615
  const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
@@ -702,7 +659,7 @@ XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in)
702
659
 
703
660
  /* **** XXH64 **** */
704
661
 
705
- FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
662
+ FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
706
663
  {
707
664
  const BYTE* p = (const BYTE*)input;
708
665
  const BYTE* const bEnd = p + len;
@@ -714,7 +671,9 @@ FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void
714
671
  state->total_len += len;
715
672
 
716
673
  if (state->memsize + len < 32) { /* fill in tmp buffer */
717
- XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
674
+ if (input != NULL) {
675
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
676
+ }
718
677
  state->memsize += (U32)len;
719
678
  return XXH_OK;
720
679
  }
@@ -769,7 +728,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void*
769
728
 
770
729
 
771
730
 
772
- FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
731
+ FORCE_INLINE_TEMPLATE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
773
732
  {
774
733
  const BYTE * p = (const BYTE*)state->mem64;
775
734
  const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize;
@@ -846,14 +805,14 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t
846
805
  {
847
806
  XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t));
848
807
  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
849
- memcpy(dst, &hash, sizeof(*dst));
808
+ ZSTD_memcpy(dst, &hash, sizeof(*dst));
850
809
  }
851
810
 
852
811
  XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash)
853
812
  {
854
813
  XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
855
814
  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
856
- memcpy(dst, &hash, sizeof(*dst));
815
+ ZSTD_memcpy(dst, &hash, sizeof(*dst));
857
816
  }
858
817
 
859
818
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src)