extzstd 0.1 → 0.3.2

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 (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
@@ -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-2020, 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 :
@@ -64,22 +44,18 @@ XXH64 13.8 GB/s 1.9 GB/s
64
44
  XXH32 6.8 GB/s 6.0 GB/s
65
45
  */
66
46
 
67
- #ifndef XXHASH_H_5627135585666179
68
- #define XXHASH_H_5627135585666179 1
69
-
70
47
  #if defined (__cplusplus)
71
48
  extern "C" {
72
49
  #endif
73
50
 
74
- #ifndef XXH_NAMESPACE
75
- # define XXH_NAMESPACE ZSTD_ /* Zstandard specific */
76
- #endif
51
+ #ifndef XXHASH_H_5627135585666179
52
+ #define XXHASH_H_5627135585666179 1
77
53
 
78
54
 
79
55
  /* ****************************
80
56
  * Definitions
81
57
  ******************************/
82
- #include <stddef.h> /* size_t */
58
+ #include "zstd_deps.h"
83
59
  typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
84
60
 
85
61
 
@@ -242,6 +218,11 @@ XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH
242
218
  /* **************************
243
219
  * Canonical representation
244
220
  ****************************/
221
+ /* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
222
+ * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
223
+ * These functions allow transformation of hash result into and from its canonical format.
224
+ * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
225
+ */
245
226
  typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
246
227
  typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
247
228
 
@@ -251,14 +232,9 @@ XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t
251
232
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
252
233
  XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
253
234
 
254
- /* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
255
- * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
256
- * These functions allow transformation of hash result into and from its canonical format.
257
- * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
258
- */
235
+ #endif /* XXHASH_H_5627135585666179 */
259
236
 
260
237
 
261
- #ifdef XXH_STATIC_LINKING_ONLY
262
238
 
263
239
  /* ================================================================================================
264
240
  This section contains definitions which are not guaranteed to remain stable.
@@ -266,6 +242,8 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
266
242
  They shall only be used with static linking.
267
243
  Never use these definitions in association with dynamic linking !
268
244
  =================================================================================================== */
245
+ #if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXH_STATIC_H_3543687687345)
246
+ #define XXH_STATIC_H_3543687687345
269
247
 
270
248
  /* These definitions are only meant to allow allocation of XXH state
271
249
  statically, on stack, or in a struct for example.
@@ -299,11 +277,9 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
299
277
  # include "xxhash.c" /* include xxhash functions as `static`, for inlining */
300
278
  # endif
301
279
 
302
- #endif /* XXH_STATIC_LINKING_ONLY */
280
+ #endif /* XXH_STATIC_LINKING_ONLY && XXH_STATIC_H_3543687687345 */
303
281
 
304
282
 
305
283
  #if defined (__cplusplus)
306
284
  }
307
285
  #endif
308
-
309
- #endif /* XXHASH_H_5627135585666179 */
@@ -0,0 +1,83 @@
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
+
12
+
13
+ /*-*************************************
14
+ * Dependencies
15
+ ***************************************/
16
+ #define ZSTD_DEPS_NEED_MALLOC
17
+ #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
18
+ #include "error_private.h"
19
+ #include "zstd_internal.h"
20
+
21
+
22
+ /*-****************************************
23
+ * Version
24
+ ******************************************/
25
+ unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
26
+
27
+ const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
28
+
29
+
30
+ /*-****************************************
31
+ * ZSTD Error Management
32
+ ******************************************/
33
+ #undef ZSTD_isError /* defined within zstd_internal.h */
34
+ /*! ZSTD_isError() :
35
+ * tells if a return value is an error code
36
+ * symbol is required for external callers */
37
+ unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
38
+
39
+ /*! ZSTD_getErrorName() :
40
+ * provides error code string from function result (useful for debugging) */
41
+ const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
42
+
43
+ /*! ZSTD_getError() :
44
+ * convert a `size_t` function result into a proper ZSTD_errorCode enum */
45
+ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
46
+
47
+ /*! ZSTD_getErrorString() :
48
+ * provides error code string from enum */
49
+ const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
50
+
51
+
52
+
53
+ /*=**************************************************************
54
+ * Custom allocator
55
+ ****************************************************************/
56
+ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
57
+ {
58
+ if (customMem.customAlloc)
59
+ return customMem.customAlloc(customMem.opaque, size);
60
+ return ZSTD_malloc(size);
61
+ }
62
+
63
+ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
64
+ {
65
+ if (customMem.customAlloc) {
66
+ /* calloc implemented as malloc+memset;
67
+ * not as efficient as calloc, but next best guess for custom malloc */
68
+ void* const ptr = customMem.customAlloc(customMem.opaque, size);
69
+ ZSTD_memset(ptr, 0, size);
70
+ return ptr;
71
+ }
72
+ return ZSTD_calloc(1, size);
73
+ }
74
+
75
+ void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
76
+ {
77
+ if (ptr!=NULL) {
78
+ if (customMem.customFree)
79
+ customMem.customFree(customMem.opaque, ptr);
80
+ else
81
+ ZSTD_free(ptr);
82
+ }
83
+ }
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright (c) 2016-2020, 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 */
@@ -0,0 +1,95 @@
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 ZSTD_ERRORS_H_398273423
12
+ #define ZSTD_ERRORS_H_398273423
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ /*===== dependency =====*/
19
+ #include <stddef.h> /* size_t */
20
+
21
+
22
+ /* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
23
+ #ifndef ZSTDERRORLIB_VISIBILITY
24
+ # if defined(__GNUC__) && (__GNUC__ >= 4)
25
+ # define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default")))
26
+ # else
27
+ # define ZSTDERRORLIB_VISIBILITY
28
+ # endif
29
+ #endif
30
+ #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
31
+ # define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY
32
+ #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
33
+ # define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
34
+ #else
35
+ # define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY
36
+ #endif
37
+
38
+ /*-*********************************************
39
+ * Error codes list
40
+ *-*********************************************
41
+ * Error codes _values_ are pinned down since v1.3.1 only.
42
+ * Therefore, don't rely on values if you may link to any version < v1.3.1.
43
+ *
44
+ * Only values < 100 are considered stable.
45
+ *
46
+ * note 1 : this API shall be used with static linking only.
47
+ * dynamic linking is not yet officially supported.
48
+ * note 2 : Prefer relying on the enum than on its value whenever possible
49
+ * This is the only supported way to use the error list < v1.3.1
50
+ * note 3 : ZSTD_isError() is always correct, whatever the library version.
51
+ **********************************************/
52
+ typedef enum {
53
+ ZSTD_error_no_error = 0,
54
+ ZSTD_error_GENERIC = 1,
55
+ ZSTD_error_prefix_unknown = 10,
56
+ ZSTD_error_version_unsupported = 12,
57
+ ZSTD_error_frameParameter_unsupported = 14,
58
+ ZSTD_error_frameParameter_windowTooLarge = 16,
59
+ ZSTD_error_corruption_detected = 20,
60
+ ZSTD_error_checksum_wrong = 22,
61
+ ZSTD_error_dictionary_corrupted = 30,
62
+ ZSTD_error_dictionary_wrong = 32,
63
+ ZSTD_error_dictionaryCreation_failed = 34,
64
+ ZSTD_error_parameter_unsupported = 40,
65
+ ZSTD_error_parameter_outOfBound = 42,
66
+ ZSTD_error_tableLog_tooLarge = 44,
67
+ ZSTD_error_maxSymbolValue_tooLarge = 46,
68
+ ZSTD_error_maxSymbolValue_tooSmall = 48,
69
+ ZSTD_error_stage_wrong = 60,
70
+ ZSTD_error_init_missing = 62,
71
+ ZSTD_error_memory_allocation = 64,
72
+ ZSTD_error_workSpace_tooSmall= 66,
73
+ ZSTD_error_dstSize_tooSmall = 70,
74
+ ZSTD_error_srcSize_wrong = 72,
75
+ ZSTD_error_dstBuffer_null = 74,
76
+ /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
77
+ ZSTD_error_frameIndex_tooLarge = 100,
78
+ ZSTD_error_seekableIO = 102,
79
+ ZSTD_error_dstBuffer_wrong = 104,
80
+ ZSTD_error_srcBuffer_wrong = 105,
81
+ ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
82
+ } ZSTD_ErrorCode;
83
+
84
+ /*! ZSTD_getErrorCode() :
85
+ convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
86
+ which can be used to compare with enum list published above */
87
+ ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
88
+ ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
89
+
90
+
91
+ #if defined (__cplusplus)
92
+ }
93
+ #endif
94
+
95
+ #endif /* ZSTD_ERRORS_H_398273423 */
@@ -0,0 +1,478 @@
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 ZSTD_CCOMMON_H_MODULE
12
+ #define ZSTD_CCOMMON_H_MODULE
13
+
14
+ /* this module contains definitions which must be identical
15
+ * across compression, decompression and dictBuilder.
16
+ * It also contains a few functions useful to at least 2 of them
17
+ * and which benefit from being inlined */
18
+
19
+ /*-*************************************
20
+ * Dependencies
21
+ ***************************************/
22
+ #if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
23
+ #include <arm_neon.h>
24
+ #endif
25
+ #include "compiler.h"
26
+ #include "mem.h"
27
+ #include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
28
+ #include "error_private.h"
29
+ #define ZSTD_STATIC_LINKING_ONLY
30
+ #include "../zstd.h"
31
+ #define FSE_STATIC_LINKING_ONLY
32
+ #include "fse.h"
33
+ #define HUF_STATIC_LINKING_ONLY
34
+ #include "huf.h"
35
+ #ifndef XXH_STATIC_LINKING_ONLY
36
+ # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
37
+ #endif
38
+ #include "xxhash.h" /* XXH_reset, update, digest */
39
+
40
+ #if defined (__cplusplus)
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* ---- static assert (debug) --- */
45
+ #define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
46
+ #define ZSTD_isError ERR_isError /* for inlining */
47
+ #define FSE_isError ERR_isError
48
+ #define HUF_isError ERR_isError
49
+
50
+
51
+ /*-*************************************
52
+ * shared macros
53
+ ***************************************/
54
+ #undef MIN
55
+ #undef MAX
56
+ #define MIN(a,b) ((a)<(b) ? (a) : (b))
57
+ #define MAX(a,b) ((a)>(b) ? (a) : (b))
58
+
59
+ /**
60
+ * Ignore: this is an internal helper.
61
+ *
62
+ * This is a helper function to help force C99-correctness during compilation.
63
+ * Under strict compilation modes, variadic macro arguments can't be empty.
64
+ * However, variadic function arguments can be. Using a function therefore lets
65
+ * us statically check that at least one (string) argument was passed,
66
+ * independent of the compilation flags.
67
+ */
68
+ static INLINE_KEYWORD UNUSED_ATTR
69
+ void _force_has_format_string(const char *format, ...) {
70
+ (void)format;
71
+ }
72
+
73
+ /**
74
+ * Ignore: this is an internal helper.
75
+ *
76
+ * We want to force this function invocation to be syntactically correct, but
77
+ * we don't want to force runtime evaluation of its arguments.
78
+ */
79
+ #define _FORCE_HAS_FORMAT_STRING(...) \
80
+ if (0) { \
81
+ _force_has_format_string(__VA_ARGS__); \
82
+ }
83
+
84
+ /**
85
+ * Return the specified error if the condition evaluates to true.
86
+ *
87
+ * In debug modes, prints additional information.
88
+ * In order to do that (particularly, printing the conditional that failed),
89
+ * this can't just wrap RETURN_ERROR().
90
+ */
91
+ #define RETURN_ERROR_IF(cond, err, ...) \
92
+ if (cond) { \
93
+ RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
94
+ __FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
95
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
96
+ RAWLOG(3, ": " __VA_ARGS__); \
97
+ RAWLOG(3, "\n"); \
98
+ return ERROR(err); \
99
+ }
100
+
101
+ /**
102
+ * Unconditionally return the specified error.
103
+ *
104
+ * In debug modes, prints additional information.
105
+ */
106
+ #define RETURN_ERROR(err, ...) \
107
+ do { \
108
+ RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
109
+ __FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
110
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
111
+ RAWLOG(3, ": " __VA_ARGS__); \
112
+ RAWLOG(3, "\n"); \
113
+ return ERROR(err); \
114
+ } while(0);
115
+
116
+ /**
117
+ * If the provided expression evaluates to an error code, returns that error code.
118
+ *
119
+ * In debug modes, prints additional information.
120
+ */
121
+ #define FORWARD_IF_ERROR(err, ...) \
122
+ do { \
123
+ size_t const err_code = (err); \
124
+ if (ERR_isError(err_code)) { \
125
+ RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
126
+ __FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
127
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
128
+ RAWLOG(3, ": " __VA_ARGS__); \
129
+ RAWLOG(3, "\n"); \
130
+ return err_code; \
131
+ } \
132
+ } while(0);
133
+
134
+
135
+ /*-*************************************
136
+ * Common constants
137
+ ***************************************/
138
+ #define ZSTD_OPT_NUM (1<<12)
139
+
140
+ #define ZSTD_REP_NUM 3 /* number of repcodes */
141
+ #define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
142
+ static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
143
+
144
+ #define KB *(1 <<10)
145
+ #define MB *(1 <<20)
146
+ #define GB *(1U<<30)
147
+
148
+ #define BIT7 128
149
+ #define BIT6 64
150
+ #define BIT5 32
151
+ #define BIT4 16
152
+ #define BIT1 2
153
+ #define BIT0 1
154
+
155
+ #define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
156
+ static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
157
+ static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
158
+
159
+ #define ZSTD_FRAMEIDSIZE 4 /* magic number size */
160
+
161
+ #define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
162
+ static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
163
+ typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
164
+
165
+ #define ZSTD_FRAMECHECKSUMSIZE 4
166
+
167
+ #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
168
+ #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
169
+
170
+ #define HufLog 12
171
+ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
172
+
173
+ #define LONGNBSEQ 0x7F00
174
+
175
+ #define MINMATCH 3
176
+
177
+ #define Litbits 8
178
+ #define MaxLit ((1<<Litbits) - 1)
179
+ #define MaxML 52
180
+ #define MaxLL 35
181
+ #define DefaultMaxOff 28
182
+ #define MaxOff 31
183
+ #define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
184
+ #define MLFSELog 9
185
+ #define LLFSELog 9
186
+ #define OffFSELog 8
187
+ #define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
188
+
189
+ #define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
190
+ /* Each table cannot take more than #symbols * FSELog bits */
191
+ #define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
192
+
193
+ static UNUSED_ATTR const U32 LL_bits[MaxLL+1] = {
194
+ 0, 0, 0, 0, 0, 0, 0, 0,
195
+ 0, 0, 0, 0, 0, 0, 0, 0,
196
+ 1, 1, 1, 1, 2, 2, 3, 3,
197
+ 4, 6, 7, 8, 9,10,11,12,
198
+ 13,14,15,16
199
+ };
200
+ static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
201
+ 4, 3, 2, 2, 2, 2, 2, 2,
202
+ 2, 2, 2, 2, 2, 1, 1, 1,
203
+ 2, 2, 2, 2, 2, 2, 2, 2,
204
+ 2, 3, 2, 1, 1, 1, 1, 1,
205
+ -1,-1,-1,-1
206
+ };
207
+ #define LL_DEFAULTNORMLOG 6 /* for static allocation */
208
+ static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
209
+
210
+ static UNUSED_ATTR const U32 ML_bits[MaxML+1] = {
211
+ 0, 0, 0, 0, 0, 0, 0, 0,
212
+ 0, 0, 0, 0, 0, 0, 0, 0,
213
+ 0, 0, 0, 0, 0, 0, 0, 0,
214
+ 0, 0, 0, 0, 0, 0, 0, 0,
215
+ 1, 1, 1, 1, 2, 2, 3, 3,
216
+ 4, 4, 5, 7, 8, 9,10,11,
217
+ 12,13,14,15,16
218
+ };
219
+ static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = {
220
+ 1, 4, 3, 2, 2, 2, 2, 2,
221
+ 2, 1, 1, 1, 1, 1, 1, 1,
222
+ 1, 1, 1, 1, 1, 1, 1, 1,
223
+ 1, 1, 1, 1, 1, 1, 1, 1,
224
+ 1, 1, 1, 1, 1, 1, 1, 1,
225
+ 1, 1, 1, 1, 1, 1,-1,-1,
226
+ -1,-1,-1,-1,-1
227
+ };
228
+ #define ML_DEFAULTNORMLOG 6 /* for static allocation */
229
+ static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
230
+
231
+ static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = {
232
+ 1, 1, 1, 1, 1, 1, 2, 2,
233
+ 2, 1, 1, 1, 1, 1, 1, 1,
234
+ 1, 1, 1, 1, 1, 1, 1, 1,
235
+ -1,-1,-1,-1,-1
236
+ };
237
+ #define OF_DEFAULTNORMLOG 5 /* for static allocation */
238
+ static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
239
+
240
+
241
+ /*-*******************************************
242
+ * Shared functions to include for inlining
243
+ *********************************************/
244
+ static void ZSTD_copy8(void* dst, const void* src) {
245
+ #if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
246
+ vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
247
+ #else
248
+ ZSTD_memcpy(dst, src, 8);
249
+ #endif
250
+ }
251
+
252
+ #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
253
+ static void ZSTD_copy16(void* dst, const void* src) {
254
+ #if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
255
+ vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
256
+ #else
257
+ ZSTD_memcpy(dst, src, 16);
258
+ #endif
259
+ }
260
+ #define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
261
+
262
+ #define WILDCOPY_OVERLENGTH 32
263
+ #define WILDCOPY_VECLEN 16
264
+
265
+ typedef enum {
266
+ ZSTD_no_overlap,
267
+ ZSTD_overlap_src_before_dst
268
+ /* ZSTD_overlap_dst_before_src, */
269
+ } ZSTD_overlap_e;
270
+
271
+ /*! ZSTD_wildcopy() :
272
+ * Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
273
+ * @param ovtype controls the overlap detection
274
+ * - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
275
+ * - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
276
+ * The src buffer must be before the dst buffer.
277
+ */
278
+ MEM_STATIC FORCE_INLINE_ATTR
279
+ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
280
+ {
281
+ ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
282
+ const BYTE* ip = (const BYTE*)src;
283
+ BYTE* op = (BYTE*)dst;
284
+ BYTE* const oend = op + length;
285
+
286
+ assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
287
+
288
+ if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
289
+ /* Handle short offset copies. */
290
+ do {
291
+ COPY8(op, ip)
292
+ } while (op < oend);
293
+ } else {
294
+ assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
295
+ /* Separate out the first COPY16() call because the copy length is
296
+ * almost certain to be short, so the branches have different
297
+ * probabilities. Since it is almost certain to be short, only do
298
+ * one COPY16() in the first call. Then, do two calls per loop since
299
+ * at that point it is more likely to have a high trip count.
300
+ */
301
+ #ifdef __aarch64__
302
+ do {
303
+ COPY16(op, ip);
304
+ }
305
+ while (op < oend);
306
+ #else
307
+ ZSTD_copy16(op, ip);
308
+ if (16 >= length) return;
309
+ op += 16;
310
+ ip += 16;
311
+ do {
312
+ COPY16(op, ip);
313
+ COPY16(op, ip);
314
+ }
315
+ while (op < oend);
316
+ #endif
317
+ }
318
+ }
319
+
320
+ MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
321
+ {
322
+ size_t const length = MIN(dstCapacity, srcSize);
323
+ if (length > 0) {
324
+ ZSTD_memcpy(dst, src, length);
325
+ }
326
+ return length;
327
+ }
328
+
329
+ /* define "workspace is too large" as this number of times larger than needed */
330
+ #define ZSTD_WORKSPACETOOLARGE_FACTOR 3
331
+
332
+ /* when workspace is continuously too large
333
+ * during at least this number of times,
334
+ * context's memory usage is considered wasteful,
335
+ * because it's sized to handle a worst case scenario which rarely happens.
336
+ * In which case, resize it down to free some memory */
337
+ #define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
338
+
339
+ /* Controls whether the input/output buffer is buffered or stable. */
340
+ typedef enum {
341
+ ZSTD_bm_buffered = 0, /* Buffer the input/output */
342
+ ZSTD_bm_stable = 1 /* ZSTD_inBuffer/ZSTD_outBuffer is stable */
343
+ } ZSTD_bufferMode_e;
344
+
345
+
346
+ /*-*******************************************
347
+ * Private declarations
348
+ *********************************************/
349
+ typedef struct seqDef_s {
350
+ U32 offset; /* Offset code of the sequence */
351
+ U16 litLength;
352
+ U16 matchLength;
353
+ } seqDef;
354
+
355
+ typedef struct {
356
+ seqDef* sequencesStart;
357
+ seqDef* sequences; /* ptr to end of sequences */
358
+ BYTE* litStart;
359
+ BYTE* lit; /* ptr to end of literals */
360
+ BYTE* llCode;
361
+ BYTE* mlCode;
362
+ BYTE* ofCode;
363
+ size_t maxNbSeq;
364
+ size_t maxNbLit;
365
+
366
+ /* longLengthPos and longLengthID to allow us to represent either a single litLength or matchLength
367
+ * in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
368
+ * the existing value of the litLength or matchLength by 0x10000.
369
+ */
370
+ U32 longLengthID; /* 0 == no longLength; 1 == Represent the long literal; 2 == Represent the long match; */
371
+ U32 longLengthPos; /* Index of the sequence to apply long length modification to */
372
+ } seqStore_t;
373
+
374
+ typedef struct {
375
+ U32 litLength;
376
+ U32 matchLength;
377
+ } ZSTD_sequenceLength;
378
+
379
+ /**
380
+ * Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
381
+ * indicated by longLengthPos and longLengthID, and adds MINMATCH back to matchLength.
382
+ */
383
+ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
384
+ {
385
+ ZSTD_sequenceLength seqLen;
386
+ seqLen.litLength = seq->litLength;
387
+ seqLen.matchLength = seq->matchLength + MINMATCH;
388
+ if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
389
+ if (seqStore->longLengthID == 1) {
390
+ seqLen.litLength += 0xFFFF;
391
+ }
392
+ if (seqStore->longLengthID == 2) {
393
+ seqLen.matchLength += 0xFFFF;
394
+ }
395
+ }
396
+ return seqLen;
397
+ }
398
+
399
+ /**
400
+ * Contains the compressed frame size and an upper-bound for the decompressed frame size.
401
+ * Note: before using `compressedSize`, check for errors using ZSTD_isError().
402
+ * similarly, before using `decompressedBound`, check for errors using:
403
+ * `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
404
+ */
405
+ typedef struct {
406
+ size_t compressedSize;
407
+ unsigned long long decompressedBound;
408
+ } ZSTD_frameSizeInfo; /* decompress & legacy */
409
+
410
+ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
411
+ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
412
+
413
+ /* custom memory allocation functions */
414
+ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
415
+ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
416
+ void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
417
+
418
+
419
+ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
420
+ {
421
+ assert(val != 0);
422
+ {
423
+ # if defined(_MSC_VER) /* Visual */
424
+ # if STATIC_BMI2 == 1
425
+ return _lzcnt_u32(val)^31;
426
+ # else
427
+ unsigned long r=0;
428
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
429
+ # endif
430
+ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
431
+ return __builtin_clz (val) ^ 31;
432
+ # elif defined(__ICCARM__) /* IAR Intrinsic */
433
+ return 31 - __CLZ(val);
434
+ # else /* Software version */
435
+ static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
436
+ U32 v = val;
437
+ v |= v >> 1;
438
+ v |= v >> 2;
439
+ v |= v >> 4;
440
+ v |= v >> 8;
441
+ v |= v >> 16;
442
+ return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
443
+ # endif
444
+ }
445
+ }
446
+
447
+
448
+ /* ZSTD_invalidateRepCodes() :
449
+ * ensures next compression will not use repcodes from previous block.
450
+ * Note : only works with regular variant;
451
+ * do not use with extDict variant ! */
452
+ void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx); /* zstdmt, adaptive_compression (shouldn't get this definition from here) */
453
+
454
+
455
+ typedef struct {
456
+ blockType_e blockType;
457
+ U32 lastBlock;
458
+ U32 origSize;
459
+ } blockProperties_t; /* declared here for decompress and fullbench */
460
+
461
+ /*! ZSTD_getcBlockSize() :
462
+ * Provides the size of compressed block from block header `src` */
463
+ /* Used by: decompress, fullbench (does not get its definition from here) */
464
+ size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
465
+ blockProperties_t* bpPtr);
466
+
467
+ /*! ZSTD_decodeSeqHeaders() :
468
+ * decode sequence header from src */
469
+ /* Used by: decompress, fullbench (does not get its definition from here) */
470
+ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
471
+ const void* src, size_t srcSize);
472
+
473
+
474
+ #if defined (__cplusplus)
475
+ }
476
+ #endif
477
+
478
+ #endif /* ZSTD_CCOMMON_H_MODULE */