zstdlib 0.11.0-x86_64-darwin → 0.13.0-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +16 -0
- data/Rakefile +1 -1
- data/ext/zstdlib_c/extconf.rb +9 -4
- data/ext/zstdlib_c/ruby/zlib-3.3/zstdlib.c +5090 -0
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/adler32.c +5 -27
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/compress.c +5 -16
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/crc32.c +94 -161
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/deflate.c +362 -434
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/deflate.h +43 -12
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzclose.c +1 -3
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzguts.h +13 -18
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzlib.c +28 -85
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzread.c +23 -73
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzwrite.c +19 -65
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/infback.c +17 -30
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffast.c +1 -4
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffast.h +1 -1
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inflate.c +36 -102
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inftrees.c +6 -11
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inftrees.h +6 -6
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/trees.c +290 -355
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/uncompr.c +4 -12
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zconf.h +23 -14
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zlib.h +202 -199
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zutil.c +18 -44
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zutil.h +13 -33
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/allocations.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/bitstream.h +49 -29
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/compiler.h +114 -22
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/cpu.h +36 -0
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/debug.c +6 -0
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/debug.h +20 -11
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/error_private.h +45 -36
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/fse.h +3 -2
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/fse_decompress.c +19 -17
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/huf.h +14 -1
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/mem.h +0 -9
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/pool.c +1 -1
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/pool.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/portability_macros.h +2 -0
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/threading.c +8 -2
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/xxhash.c +5 -11
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/xxhash.h +2341 -1007
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_internal.h +5 -5
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/fse_compress.c +8 -7
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/huf_compress.c +54 -25
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress.c +282 -161
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_internal.h +29 -27
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_superblock.c +224 -113
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_cwksp.h +19 -13
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_double_fast.c +17 -5
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_double_fast.h +11 -0
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_fast.c +14 -6
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_lazy.c +129 -87
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_lazy.h +103 -28
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_ldm.c +8 -2
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_opt.c +216 -112
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_opt.h +31 -7
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstdmt_compress.c +94 -79
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/huf_decompress.c +188 -126
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/huf_decompress_amd64.S +38 -19
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress.c +84 -32
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress_block.c +231 -208
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress_block.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress_internal.h +2 -0
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/zstd.h +129 -60
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzclose.c +1 -3
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzlib.c +20 -73
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzread.c +17 -58
- data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzwrite.c +18 -58
- data/lib/2.4/zstdlib_c.bundle +0 -0
- data/lib/2.5/zstdlib_c.bundle +0 -0
- data/lib/2.6/zstdlib_c.bundle +0 -0
- data/lib/2.7/zstdlib_c.bundle +0 -0
- data/lib/3.0/zstdlib_c.bundle +0 -0
- data/lib/3.1/zstdlib_c.bundle +0 -0
- data/lib/3.2/zstdlib_c.bundle +0 -0
- data/lib/3.3/zstdlib_c.bundle +0 -0
- metadata +105 -103
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/crc32.h +0 -0
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffixed.h +0 -0
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inflate.h +0 -0
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/trees.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/bits.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/entropy_common.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/error_private.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/threading.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_common.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_deps.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_trace.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/clevels.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/hist.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/hist.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_literals.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_literals.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_sequences.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_sequences.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_superblock.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_fast.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_ldm.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_ldm_geartab.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstdmt_compress.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_ddict.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_ddict.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/zdict.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/zstd_errors.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzcompatibility.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzguts.h +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/zstd_zlibwrapper.c +0 -0
- /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/zstd_zlibwrapper.h +0 -0
@@ -24,13 +24,11 @@ z_const char * const z_errmsg[10] = {
|
|
24
24
|
};
|
25
25
|
|
26
26
|
|
27
|
-
const char * ZEXPORT zlibVersion()
|
28
|
-
{
|
27
|
+
const char * ZEXPORT zlibVersion(void) {
|
29
28
|
return ZLIB_VERSION;
|
30
29
|
}
|
31
30
|
|
32
|
-
uLong ZEXPORT zlibCompileFlags()
|
33
|
-
{
|
31
|
+
uLong ZEXPORT zlibCompileFlags(void) {
|
34
32
|
uLong flags;
|
35
33
|
|
36
34
|
flags = 0;
|
@@ -61,9 +59,11 @@ uLong ZEXPORT zlibCompileFlags()
|
|
61
59
|
#ifdef ZLIB_DEBUG
|
62
60
|
flags += 1 << 8;
|
63
61
|
#endif
|
62
|
+
/*
|
64
63
|
#if defined(ASMV) || defined(ASMINF)
|
65
64
|
flags += 1 << 9;
|
66
65
|
#endif
|
66
|
+
*/
|
67
67
|
#ifdef ZLIB_WINAPI
|
68
68
|
flags += 1 << 10;
|
69
69
|
#endif
|
@@ -119,9 +119,7 @@ uLong ZEXPORT zlibCompileFlags()
|
|
119
119
|
# endif
|
120
120
|
int ZLIB_INTERNAL z_verbose = verbose;
|
121
121
|
|
122
|
-
void ZLIB_INTERNAL z_error
|
123
|
-
char *m;
|
124
|
-
{
|
122
|
+
void ZLIB_INTERNAL z_error(char *m) {
|
125
123
|
fprintf(stderr, "%s\n", m);
|
126
124
|
exit(1);
|
127
125
|
}
|
@@ -130,9 +128,7 @@ void ZLIB_INTERNAL z_error (m)
|
|
130
128
|
/* exported to allow conversion of error code to string for compress() and
|
131
129
|
* uncompress()
|
132
130
|
*/
|
133
|
-
const char * ZEXPORT zError(err)
|
134
|
-
int err;
|
135
|
-
{
|
131
|
+
const char * ZEXPORT zError(int err) {
|
136
132
|
return ERR_MSG(err);
|
137
133
|
}
|
138
134
|
|
@@ -146,22 +142,14 @@ const char * ZEXPORT zError(err)
|
|
146
142
|
|
147
143
|
#ifndef HAVE_MEMCPY
|
148
144
|
|
149
|
-
void ZLIB_INTERNAL zmemcpy(dest, source, len)
|
150
|
-
Bytef* dest;
|
151
|
-
const Bytef* source;
|
152
|
-
uInt len;
|
153
|
-
{
|
145
|
+
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
|
154
146
|
if (len == 0) return;
|
155
147
|
do {
|
156
148
|
*dest++ = *source++; /* ??? to be unrolled */
|
157
149
|
} while (--len != 0);
|
158
150
|
}
|
159
151
|
|
160
|
-
int ZLIB_INTERNAL zmemcmp(s1, s2, len)
|
161
|
-
const Bytef* s1;
|
162
|
-
const Bytef* s2;
|
163
|
-
uInt len;
|
164
|
-
{
|
152
|
+
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
|
165
153
|
uInt j;
|
166
154
|
|
167
155
|
for (j = 0; j < len; j++) {
|
@@ -170,10 +158,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len)
|
|
170
158
|
return 0;
|
171
159
|
}
|
172
160
|
|
173
|
-
void ZLIB_INTERNAL zmemzero(dest, len)
|
174
|
-
Bytef* dest;
|
175
|
-
uInt len;
|
176
|
-
{
|
161
|
+
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
|
177
162
|
if (len == 0) return;
|
178
163
|
do {
|
179
164
|
*dest++ = 0; /* ??? to be unrolled */
|
@@ -214,8 +199,7 @@ local ptr_table table[MAX_PTR];
|
|
214
199
|
* a protected system like OS/2. Use Microsoft C instead.
|
215
200
|
*/
|
216
201
|
|
217
|
-
voidpf ZLIB_INTERNAL zcalloc
|
218
|
-
{
|
202
|
+
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
|
219
203
|
voidpf buf;
|
220
204
|
ulg bsize = (ulg)items*size;
|
221
205
|
|
@@ -240,8 +224,7 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
|
|
240
224
|
return buf;
|
241
225
|
}
|
242
226
|
|
243
|
-
void ZLIB_INTERNAL zcfree
|
244
|
-
{
|
227
|
+
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
245
228
|
int n;
|
246
229
|
|
247
230
|
(void)opaque;
|
@@ -277,14 +260,12 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
|
277
260
|
# define _hfree hfree
|
278
261
|
#endif
|
279
262
|
|
280
|
-
voidpf ZLIB_INTERNAL zcalloc
|
281
|
-
{
|
263
|
+
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
|
282
264
|
(void)opaque;
|
283
265
|
return _halloc((long)items, size);
|
284
266
|
}
|
285
267
|
|
286
|
-
void ZLIB_INTERNAL zcfree
|
287
|
-
{
|
268
|
+
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
288
269
|
(void)opaque;
|
289
270
|
_hfree(ptr);
|
290
271
|
}
|
@@ -297,25 +278,18 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
|
297
278
|
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
298
279
|
|
299
280
|
#ifndef STDC
|
300
|
-
extern voidp
|
301
|
-
extern voidp
|
302
|
-
extern void
|
281
|
+
extern voidp malloc(uInt size);
|
282
|
+
extern voidp calloc(uInt items, uInt size);
|
283
|
+
extern void free(voidpf ptr);
|
303
284
|
#endif
|
304
285
|
|
305
|
-
voidpf ZLIB_INTERNAL zcalloc
|
306
|
-
voidpf opaque;
|
307
|
-
unsigned items;
|
308
|
-
unsigned size;
|
309
|
-
{
|
286
|
+
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
|
310
287
|
(void)opaque;
|
311
288
|
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
|
312
289
|
(voidpf)calloc(items, size);
|
313
290
|
}
|
314
291
|
|
315
|
-
void ZLIB_INTERNAL zcfree
|
316
|
-
voidpf opaque;
|
317
|
-
voidpf ptr;
|
318
|
-
{
|
292
|
+
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
319
293
|
(void)opaque;
|
320
294
|
free(ptr);
|
321
295
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* zutil.h -- internal interface and configuration of the compression library
|
2
|
-
* Copyright (C) 1995-
|
2
|
+
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*/
|
5
5
|
|
@@ -56,7 +56,7 @@ typedef unsigned long ulg;
|
|
56
56
|
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
57
57
|
/* (size given to avoid silly warnings with Visual C++) */
|
58
58
|
|
59
|
-
#define ERR_MSG(err) z_errmsg[
|
59
|
+
#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
|
60
60
|
|
61
61
|
#define ERR_RETURN(strm,err) \
|
62
62
|
return (strm->msg = ERR_MSG(err), (err))
|
@@ -137,17 +137,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|
137
137
|
# endif
|
138
138
|
#endif
|
139
139
|
|
140
|
-
#if defined(MACOS)
|
140
|
+
#if defined(MACOS)
|
141
141
|
# define OS_CODE 7
|
142
|
-
# ifndef Z_SOLO
|
143
|
-
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
144
|
-
# include <unix.h> /* for fdopen */
|
145
|
-
# else
|
146
|
-
# ifndef fdopen
|
147
|
-
# define fdopen(fd,mode) NULL /* No fdopen() */
|
148
|
-
# endif
|
149
|
-
# endif
|
150
|
-
# endif
|
151
142
|
#endif
|
152
143
|
|
153
144
|
#ifdef __acorn
|
@@ -170,18 +161,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|
170
161
|
# define OS_CODE 19
|
171
162
|
#endif
|
172
163
|
|
173
|
-
#if defined(_BEOS_) || defined(RISCOS)
|
174
|
-
# define fdopen(fd,mode) NULL /* No fdopen() */
|
175
|
-
#endif
|
176
|
-
|
177
|
-
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
|
178
|
-
# if defined(_WIN32_WCE)
|
179
|
-
# define fdopen(fd,mode) NULL /* No fdopen() */
|
180
|
-
# else
|
181
|
-
# define fdopen(fd,type) _fdopen(fd,type)
|
182
|
-
# endif
|
183
|
-
#endif
|
184
|
-
|
185
164
|
#if defined(__BORLANDC__) && !defined(MSDOS)
|
186
165
|
#pragma warn -8004
|
187
166
|
#pragma warn -8008
|
@@ -191,8 +170,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|
191
170
|
/* provide prototypes for these when building zlib without LFS */
|
192
171
|
#if !defined(_WIN32) && \
|
193
172
|
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
194
|
-
ZEXTERN uLong ZEXPORT adler32_combine64
|
195
|
-
ZEXTERN uLong ZEXPORT crc32_combine64
|
173
|
+
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
|
174
|
+
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
|
175
|
+
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
|
196
176
|
#endif
|
197
177
|
|
198
178
|
/* common defaults */
|
@@ -231,16 +211,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|
231
211
|
# define zmemzero(dest, len) memset(dest, 0, len)
|
232
212
|
# endif
|
233
213
|
#else
|
234
|
-
void ZLIB_INTERNAL zmemcpy
|
235
|
-
int ZLIB_INTERNAL zmemcmp
|
236
|
-
void ZLIB_INTERNAL zmemzero
|
214
|
+
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
|
215
|
+
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
|
216
|
+
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
|
237
217
|
#endif
|
238
218
|
|
239
219
|
/* Diagnostic functions */
|
240
220
|
#ifdef ZLIB_DEBUG
|
241
221
|
# include <stdio.h>
|
242
222
|
extern int ZLIB_INTERNAL z_verbose;
|
243
|
-
extern void ZLIB_INTERNAL z_error
|
223
|
+
extern void ZLIB_INTERNAL z_error(char *m);
|
244
224
|
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
245
225
|
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
246
226
|
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
@@ -257,9 +237,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|
257
237
|
#endif
|
258
238
|
|
259
239
|
#ifndef Z_SOLO
|
260
|
-
voidpf ZLIB_INTERNAL zcalloc
|
261
|
-
|
262
|
-
void ZLIB_INTERNAL zcfree
|
240
|
+
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
|
241
|
+
unsigned size);
|
242
|
+
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
|
263
243
|
#endif
|
264
244
|
|
265
245
|
#define ZALLOC(strm, items, size) \
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#define ZSTD_DEPS_NEED_MALLOC
|
15
15
|
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
|
16
16
|
|
17
|
-
#include "
|
17
|
+
#include "compiler.h" /* MEM_STATIC */
|
18
18
|
#define ZSTD_STATIC_LINKING_ONLY
|
19
19
|
#include "../zstd.h" /* ZSTD_customMem */
|
20
20
|
|
@@ -90,19 +90,20 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
|
|
90
90
|
/*-********************************************
|
91
91
|
* bitStream decoding API (read backward)
|
92
92
|
**********************************************/
|
93
|
+
typedef size_t BitContainerType;
|
93
94
|
typedef struct {
|
94
|
-
|
95
|
+
BitContainerType bitContainer;
|
95
96
|
unsigned bitsConsumed;
|
96
97
|
const char* ptr;
|
97
98
|
const char* start;
|
98
99
|
const char* limitPtr;
|
99
100
|
} BIT_DStream_t;
|
100
101
|
|
101
|
-
typedef enum { BIT_DStream_unfinished = 0,
|
102
|
-
BIT_DStream_endOfBuffer = 1,
|
103
|
-
BIT_DStream_completed = 2,
|
104
|
-
BIT_DStream_overflow = 3
|
105
|
-
|
102
|
+
typedef enum { BIT_DStream_unfinished = 0, /* fully refilled */
|
103
|
+
BIT_DStream_endOfBuffer = 1, /* still some bits left in bitstream */
|
104
|
+
BIT_DStream_completed = 2, /* bitstream entirely consumed, bit-exact */
|
105
|
+
BIT_DStream_overflow = 3 /* user requested more bits than present in bitstream */
|
106
|
+
} BIT_DStream_status; /* result of BIT_reloadDStream() */
|
106
107
|
|
107
108
|
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize);
|
108
109
|
MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits);
|
@@ -112,7 +113,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
|
|
112
113
|
|
113
114
|
/* Start by invoking BIT_initDStream().
|
114
115
|
* A chunk of the bitStream is then stored into a local register.
|
115
|
-
* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (
|
116
|
+
* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (BitContainerType).
|
116
117
|
* You can then retrieve bitFields stored into the local register, **in reverse order**.
|
117
118
|
* Local register is explicitly reloaded from memory by the BIT_reloadDStream() method.
|
118
119
|
* A reload guarantee a minimum of ((8*sizeof(bitD->bitContainer))-7) bits when its result is BIT_DStream_unfinished.
|
@@ -162,7 +163,7 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
|
|
162
163
|
return 0;
|
163
164
|
}
|
164
165
|
|
165
|
-
|
166
|
+
FORCE_INLINE_TEMPLATE size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
166
167
|
{
|
167
168
|
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS)
|
168
169
|
return _bzhi_u64(bitContainer, nbBits);
|
@@ -267,22 +268,22 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|
267
268
|
bitD->bitContainer = *(const BYTE*)(bitD->start);
|
268
269
|
switch(srcSize)
|
269
270
|
{
|
270
|
-
case 7: bitD->bitContainer += (
|
271
|
+
case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
|
271
272
|
ZSTD_FALLTHROUGH;
|
272
273
|
|
273
|
-
case 6: bitD->bitContainer += (
|
274
|
+
case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
|
274
275
|
ZSTD_FALLTHROUGH;
|
275
276
|
|
276
|
-
case 5: bitD->bitContainer += (
|
277
|
+
case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
|
277
278
|
ZSTD_FALLTHROUGH;
|
278
279
|
|
279
|
-
case 4: bitD->bitContainer += (
|
280
|
+
case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
|
280
281
|
ZSTD_FALLTHROUGH;
|
281
282
|
|
282
|
-
case 3: bitD->bitContainer += (
|
283
|
+
case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
|
283
284
|
ZSTD_FALLTHROUGH;
|
284
285
|
|
285
|
-
case 2: bitD->bitContainer += (
|
286
|
+
case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8;
|
286
287
|
ZSTD_FALLTHROUGH;
|
287
288
|
|
288
289
|
default: break;
|
@@ -297,12 +298,12 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|
297
298
|
return srcSize;
|
298
299
|
}
|
299
300
|
|
300
|
-
|
301
|
+
FORCE_INLINE_TEMPLATE size_t BIT_getUpperBits(BitContainerType bitContainer, U32 const start)
|
301
302
|
{
|
302
303
|
return bitContainer >> start;
|
303
304
|
}
|
304
305
|
|
305
|
-
|
306
|
+
FORCE_INLINE_TEMPLATE size_t BIT_getMiddleBits(BitContainerType bitContainer, U32 const start, U32 const nbBits)
|
306
307
|
{
|
307
308
|
U32 const regMask = sizeof(bitContainer)*8 - 1;
|
308
309
|
/* if start > regMask, bitstream is corrupted, and result is undefined */
|
@@ -325,7 +326,7 @@ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 c
|
|
325
326
|
* On 32-bits, maxNbBits==24.
|
326
327
|
* On 64-bits, maxNbBits==56.
|
327
328
|
* @return : value extracted */
|
328
|
-
|
329
|
+
FORCE_INLINE_TEMPLATE size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
|
329
330
|
{
|
330
331
|
/* arbitrate between double-shift and shift+mask */
|
331
332
|
#if 1
|
@@ -348,7 +349,7 @@ MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits)
|
|
348
349
|
return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
|
349
350
|
}
|
350
351
|
|
351
|
-
|
352
|
+
FORCE_INLINE_TEMPLATE void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
352
353
|
{
|
353
354
|
bitD->bitsConsumed += nbBits;
|
354
355
|
}
|
@@ -357,7 +358,7 @@ MEM_STATIC FORCE_INLINE_ATTR void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
|
357
358
|
* Read (consume) next n bits from local register and update.
|
358
359
|
* Pay attention to not read more than nbBits contained into local register.
|
359
360
|
* @return : extracted value. */
|
360
|
-
|
361
|
+
FORCE_INLINE_TEMPLATE size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
|
361
362
|
{
|
362
363
|
size_t const value = BIT_lookBits(bitD, nbBits);
|
363
364
|
BIT_skipBits(bitD, nbBits);
|
@@ -374,6 +375,21 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
|
|
374
375
|
return value;
|
375
376
|
}
|
376
377
|
|
378
|
+
/*! BIT_reloadDStream_internal() :
|
379
|
+
* Simple variant of BIT_reloadDStream(), with two conditions:
|
380
|
+
* 1. bitstream is valid : bitsConsumed <= sizeof(bitD->bitContainer)*8
|
381
|
+
* 2. look window is valid after shifted down : bitD->ptr >= bitD->start
|
382
|
+
*/
|
383
|
+
MEM_STATIC BIT_DStream_status BIT_reloadDStream_internal(BIT_DStream_t* bitD)
|
384
|
+
{
|
385
|
+
assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
|
386
|
+
bitD->ptr -= bitD->bitsConsumed >> 3;
|
387
|
+
assert(bitD->ptr >= bitD->start);
|
388
|
+
bitD->bitsConsumed &= 7;
|
389
|
+
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
390
|
+
return BIT_DStream_unfinished;
|
391
|
+
}
|
392
|
+
|
377
393
|
/*! BIT_reloadDStreamFast() :
|
378
394
|
* Similar to BIT_reloadDStream(), but with two differences:
|
379
395
|
* 1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
|
@@ -384,31 +400,35 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
|
|
384
400
|
{
|
385
401
|
if (UNLIKELY(bitD->ptr < bitD->limitPtr))
|
386
402
|
return BIT_DStream_overflow;
|
387
|
-
|
388
|
-
bitD->ptr -= bitD->bitsConsumed >> 3;
|
389
|
-
bitD->bitsConsumed &= 7;
|
390
|
-
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
391
|
-
return BIT_DStream_unfinished;
|
403
|
+
return BIT_reloadDStream_internal(bitD);
|
392
404
|
}
|
393
405
|
|
394
406
|
/*! BIT_reloadDStream() :
|
395
407
|
* Refill `bitD` from buffer previously set in BIT_initDStream() .
|
396
|
-
* This function is safe, it guarantees it will not
|
408
|
+
* This function is safe, it guarantees it will not never beyond src buffer.
|
397
409
|
* @return : status of `BIT_DStream_t` internal register.
|
398
410
|
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
|
399
|
-
|
411
|
+
FORCE_INLINE_TEMPLATE BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
400
412
|
{
|
401
|
-
|
413
|
+
/* note : once in overflow mode, a bitstream remains in this mode until it's reset */
|
414
|
+
if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
|
415
|
+
static const BitContainerType zeroFilled = 0;
|
416
|
+
bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
|
417
|
+
/* overflow detected, erroneous scenario or end of stream: no update */
|
402
418
|
return BIT_DStream_overflow;
|
419
|
+
}
|
420
|
+
|
421
|
+
assert(bitD->ptr >= bitD->start);
|
403
422
|
|
404
423
|
if (bitD->ptr >= bitD->limitPtr) {
|
405
|
-
return
|
424
|
+
return BIT_reloadDStream_internal(bitD);
|
406
425
|
}
|
407
426
|
if (bitD->ptr == bitD->start) {
|
427
|
+
/* reached end of bitStream => no update */
|
408
428
|
if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
|
409
429
|
return BIT_DStream_completed;
|
410
430
|
}
|
411
|
-
/* start < ptr < limitPtr */
|
431
|
+
/* start < ptr < limitPtr => cautious update */
|
412
432
|
{ U32 nbBytes = bitD->bitsConsumed >> 3;
|
413
433
|
BIT_DStream_status result = BIT_DStream_unfinished;
|
414
434
|
if (bitD->ptr - nbBytes < bitD->start) {
|
@@ -11,6 +11,8 @@
|
|
11
11
|
#ifndef ZSTD_COMPILER_H
|
12
12
|
#define ZSTD_COMPILER_H
|
13
13
|
|
14
|
+
#include <stddef.h>
|
15
|
+
|
14
16
|
#include "portability_macros.h"
|
15
17
|
|
16
18
|
/*-*******************************************************
|
@@ -51,12 +53,19 @@
|
|
51
53
|
# define WIN_CDECL
|
52
54
|
#endif
|
53
55
|
|
56
|
+
/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
|
57
|
+
#if defined(__GNUC__)
|
58
|
+
# define UNUSED_ATTR __attribute__((unused))
|
59
|
+
#else
|
60
|
+
# define UNUSED_ATTR
|
61
|
+
#endif
|
62
|
+
|
54
63
|
/**
|
55
64
|
* FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
|
56
65
|
* parameters. They must be inlined for the compiler to eliminate the constant
|
57
66
|
* branches.
|
58
67
|
*/
|
59
|
-
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
|
68
|
+
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR UNUSED_ATTR
|
60
69
|
/**
|
61
70
|
* HINT_INLINE is used to help the compiler generate better code. It is *not*
|
62
71
|
* used for "templates", so it can be tweaked based on the compilers
|
@@ -71,14 +80,28 @@
|
|
71
80
|
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
|
72
81
|
# define HINT_INLINE static INLINE_KEYWORD
|
73
82
|
#else
|
74
|
-
# define HINT_INLINE
|
83
|
+
# define HINT_INLINE FORCE_INLINE_TEMPLATE
|
75
84
|
#endif
|
76
85
|
|
77
|
-
/*
|
86
|
+
/* "soft" inline :
|
87
|
+
* The compiler is free to select if it's a good idea to inline or not.
|
88
|
+
* The main objective is to silence compiler warnings
|
89
|
+
* when a defined function in included but not used.
|
90
|
+
*
|
91
|
+
* Note : this macro is prefixed `MEM_` because it used to be provided by `mem.h` unit.
|
92
|
+
* Updating the prefix is probably preferable, but requires a fairly large codemod,
|
93
|
+
* since this name is used everywhere.
|
94
|
+
*/
|
95
|
+
#ifndef MEM_STATIC /* already defined in Linux Kernel mem.h */
|
78
96
|
#if defined(__GNUC__)
|
79
|
-
# define UNUSED_ATTR
|
97
|
+
# define MEM_STATIC static __inline UNUSED_ATTR
|
98
|
+
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
99
|
+
# define MEM_STATIC static inline
|
100
|
+
#elif defined(_MSC_VER)
|
101
|
+
# define MEM_STATIC static __inline
|
80
102
|
#else
|
81
|
-
# define
|
103
|
+
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
104
|
+
#endif
|
82
105
|
#endif
|
83
106
|
|
84
107
|
/* force no inlining */
|
@@ -109,10 +132,10 @@
|
|
109
132
|
/* prefetch
|
110
133
|
* can be disabled, by declaring NO_PREFETCH build macro */
|
111
134
|
#if defined(NO_PREFETCH)
|
112
|
-
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
|
113
|
-
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
|
135
|
+
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
|
136
|
+
# define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */
|
114
137
|
#else
|
115
|
-
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
|
138
|
+
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) && !defined(_M_ARM64EC) /* _mm_prefetch() is not defined outside of x86/x64 */
|
116
139
|
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
|
117
140
|
# define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
|
118
141
|
# define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
|
@@ -120,24 +143,25 @@
|
|
120
143
|
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
|
121
144
|
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
|
122
145
|
# elif defined(__aarch64__)
|
123
|
-
# define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
|
124
|
-
# define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
|
146
|
+
# define PREFETCH_L1(ptr) do { __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr))); } while (0)
|
147
|
+
# define PREFETCH_L2(ptr) do { __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr))); } while (0)
|
125
148
|
# else
|
126
|
-
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
|
127
|
-
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
|
149
|
+
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
|
150
|
+
# define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */
|
128
151
|
# endif
|
129
152
|
#endif /* NO_PREFETCH */
|
130
153
|
|
131
154
|
#define CACHELINE_SIZE 64
|
132
155
|
|
133
|
-
#define PREFETCH_AREA(p, s)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
}
|
156
|
+
#define PREFETCH_AREA(p, s) \
|
157
|
+
do { \
|
158
|
+
const char* const _ptr = (const char*)(p); \
|
159
|
+
size_t const _size = (size_t)(s); \
|
160
|
+
size_t _pos; \
|
161
|
+
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
|
162
|
+
PREFETCH_L2(_ptr + _pos); \
|
163
|
+
} \
|
164
|
+
} while (0)
|
141
165
|
|
142
166
|
/* vectorization
|
143
167
|
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
|
@@ -166,9 +190,9 @@
|
|
166
190
|
#endif
|
167
191
|
|
168
192
|
#if __has_builtin(__builtin_unreachable) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))
|
169
|
-
# define ZSTD_UNREACHABLE { assert(0), __builtin_unreachable(); }
|
193
|
+
# define ZSTD_UNREACHABLE do { assert(0), __builtin_unreachable(); } while (0)
|
170
194
|
#else
|
171
|
-
# define ZSTD_UNREACHABLE { assert(0); }
|
195
|
+
# define ZSTD_UNREACHABLE do { assert(0); } while (0)
|
172
196
|
#endif
|
173
197
|
|
174
198
|
/* disable warnings */
|
@@ -281,6 +305,74 @@
|
|
281
305
|
* Sanitizer
|
282
306
|
*****************************************************************/
|
283
307
|
|
308
|
+
/**
|
309
|
+
* Zstd relies on pointer overflow in its decompressor.
|
310
|
+
* We add this attribute to functions that rely on pointer overflow.
|
311
|
+
*/
|
312
|
+
#ifndef ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
313
|
+
# if __has_attribute(no_sanitize)
|
314
|
+
# if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 8
|
315
|
+
/* gcc < 8 only has signed-integer-overlow which triggers on pointer overflow */
|
316
|
+
# define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR __attribute__((no_sanitize("signed-integer-overflow")))
|
317
|
+
# else
|
318
|
+
/* older versions of clang [3.7, 5.0) will warn that pointer-overflow is ignored. */
|
319
|
+
# define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR __attribute__((no_sanitize("pointer-overflow")))
|
320
|
+
# endif
|
321
|
+
# else
|
322
|
+
# define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
323
|
+
# endif
|
324
|
+
#endif
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Helper function to perform a wrapped pointer difference without trigging
|
328
|
+
* UBSAN.
|
329
|
+
*
|
330
|
+
* @returns lhs - rhs with wrapping
|
331
|
+
*/
|
332
|
+
MEM_STATIC
|
333
|
+
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
334
|
+
ptrdiff_t ZSTD_wrappedPtrDiff(unsigned char const* lhs, unsigned char const* rhs)
|
335
|
+
{
|
336
|
+
return lhs - rhs;
|
337
|
+
}
|
338
|
+
|
339
|
+
/**
|
340
|
+
* Helper function to perform a wrapped pointer add without triggering UBSAN.
|
341
|
+
*
|
342
|
+
* @return ptr + add with wrapping
|
343
|
+
*/
|
344
|
+
MEM_STATIC
|
345
|
+
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
346
|
+
unsigned char const* ZSTD_wrappedPtrAdd(unsigned char const* ptr, ptrdiff_t add)
|
347
|
+
{
|
348
|
+
return ptr + add;
|
349
|
+
}
|
350
|
+
|
351
|
+
/**
|
352
|
+
* Helper function to perform a wrapped pointer subtraction without triggering
|
353
|
+
* UBSAN.
|
354
|
+
*
|
355
|
+
* @return ptr - sub with wrapping
|
356
|
+
*/
|
357
|
+
MEM_STATIC
|
358
|
+
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
359
|
+
unsigned char const* ZSTD_wrappedPtrSub(unsigned char const* ptr, ptrdiff_t sub)
|
360
|
+
{
|
361
|
+
return ptr - sub;
|
362
|
+
}
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Helper function to add to a pointer that works around C's undefined behavior
|
366
|
+
* of adding 0 to NULL.
|
367
|
+
*
|
368
|
+
* @returns `ptr + add` except it defines `NULL + 0 == NULL`.
|
369
|
+
*/
|
370
|
+
MEM_STATIC
|
371
|
+
unsigned char* ZSTD_maybeNullPtrAdd(unsigned char* ptr, ptrdiff_t add)
|
372
|
+
{
|
373
|
+
return add > 0 ? ptr + add : ptr;
|
374
|
+
}
|
375
|
+
|
284
376
|
/* Issue #3240 reports an ASAN failure on an llvm-mingw build. Out of an
|
285
377
|
* abundance of caution, disable our custom poisoning on mingw. */
|
286
378
|
#ifdef __MINGW32__
|