zstdlib 0.3.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +30 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/ext/zstdlib/extconf.rb +3 -3
- data/ext/zstdlib/ruby/zlib-2.7/zstdlib.c +4895 -0
- data/ext/zstdlib/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/bitstream.h +59 -51
- data/ext/zstdlib/zstd-1.5.0/lib/common/compiler.h +289 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/cpu.h +1 -3
- data/ext/zstdlib/zstd-1.5.0/lib/common/debug.c +24 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/debug.h +22 -49
- data/ext/zstdlib/zstd-1.5.0/lib/common/entropy_common.c +362 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/error_private.c +3 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/error_private.h +8 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/fse.h +50 -42
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/fse_decompress.c +149 -55
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/huf.h +43 -39
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/mem.h +69 -25
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/pool.c +30 -20
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/pool.h +3 -3
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/threading.c +51 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/threading.h +36 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/xxhash.c +40 -92
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/xxhash.h +12 -32
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/zstd_common.c +10 -10
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_internal.h +490 -0
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_trace.h +154 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/fse_compress.c +47 -63
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/hist.c +41 -63
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/hist.h +13 -33
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/huf_compress.c +332 -193
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress.c +6393 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_internal.h +522 -86
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_literals.c +25 -16
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_literals.h +2 -2
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_sequences.c +50 -24
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_sequences.h +11 -4
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress_superblock.c +572 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_cwksp.h +662 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_double_fast.c +43 -41
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_double_fast.h +2 -2
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_fast.c +85 -80
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_fast.h +2 -2
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_lazy.c +2184 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_lazy.h +125 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_ldm.c +333 -208
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_ldm.h +15 -3
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_opt.c +228 -129
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_opt.h +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstdmt_compress.c +151 -440
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstdmt_compress.h +110 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/huf_decompress.c +395 -276
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_ddict.c +20 -16
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_ddict.h +3 -3
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress.c +628 -231
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_block.c +606 -380
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_block.h +8 -5
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_internal.h +39 -9
- data/ext/zstdlib/zstd-1.5.0/lib/zdict.h +452 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/zstd.h +740 -153
- data/ext/zstdlib/{zstd-1.4.2/lib/common → zstd-1.5.0/lib}/zstd_errors.h +3 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzclose.c +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzcompatibility.h +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzguts.h +0 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzlib.c +9 -9
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzread.c +16 -8
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzwrite.c +8 -8
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/zstd_zlibwrapper.c +131 -45
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/zstd_zlibwrapper.h +1 -1
- metadata +74 -65
- data/ext/zstdlib/zstd-1.4.2/lib/common/compiler.h +0 -147
- data/ext/zstdlib/zstd-1.4.2/lib/common/debug.c +0 -44
- data/ext/zstdlib/zstd-1.4.2/lib/common/entropy_common.c +0 -236
- data/ext/zstdlib/zstd-1.4.2/lib/common/zstd_internal.h +0 -371
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_compress.c +0 -3904
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_lazy.c +0 -1111
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_lazy.h +0 -67
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstdmt_compress.h +0 -192
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -76,6 +76,8 @@ typedef enum {
|
|
76
76
|
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
77
77
|
ZSTD_error_frameIndex_tooLarge = 100,
|
78
78
|
ZSTD_error_seekableIO = 102,
|
79
|
+
ZSTD_error_dstBuffer_wrong = 104,
|
80
|
+
ZSTD_error_srcBuffer_wrong = 105,
|
79
81
|
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
80
82
|
} ZSTD_ErrorCode;
|
81
83
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
File without changes
|
@@ -216,7 +216,7 @@ local gzFile gz_open(path, fd, mode)
|
|
216
216
|
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
217
217
|
(void)snprintf(state.state->path, len + 1, "%s", (const char *)path);
|
218
218
|
#else
|
219
|
-
strcpy(state.state->path, path);
|
219
|
+
strcpy(state.state->path, (const char*)path);
|
220
220
|
#endif
|
221
221
|
|
222
222
|
/* compute the flags for open() */
|
@@ -325,7 +325,7 @@ int ZEXPORT gzbuffer(file, size)
|
|
325
325
|
/* get internal structure and check integrity */
|
326
326
|
if (file == NULL)
|
327
327
|
return -1;
|
328
|
-
state =
|
328
|
+
state.file = file;
|
329
329
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
330
330
|
return -1;
|
331
331
|
|
@@ -351,7 +351,7 @@ int ZEXPORT gzrewind(file)
|
|
351
351
|
/* get internal structure */
|
352
352
|
if (file == NULL)
|
353
353
|
return -1;
|
354
|
-
state =
|
354
|
+
state.file = file;
|
355
355
|
|
356
356
|
/* check that we're reading and that there's no error */
|
357
357
|
if (state.state->mode != GZ_READ ||
|
@@ -378,7 +378,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|
378
378
|
/* get internal structure and check integrity */
|
379
379
|
if (file == NULL)
|
380
380
|
return -1;
|
381
|
-
state =
|
381
|
+
state.file = file;
|
382
382
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
383
383
|
return -1;
|
384
384
|
|
@@ -463,7 +463,7 @@ z_off64_t ZEXPORT gztell64(file)
|
|
463
463
|
/* get internal structure and check integrity */
|
464
464
|
if (file == NULL)
|
465
465
|
return -1;
|
466
|
-
state =
|
466
|
+
state.file = file;
|
467
467
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
468
468
|
return -1;
|
469
469
|
|
@@ -491,7 +491,7 @@ z_off64_t ZEXPORT gzoffset64(file)
|
|
491
491
|
/* get internal structure and check integrity */
|
492
492
|
if (file == NULL)
|
493
493
|
return -1;
|
494
|
-
state =
|
494
|
+
state.file = file;
|
495
495
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
496
496
|
return -1;
|
497
497
|
|
@@ -523,7 +523,7 @@ int ZEXPORT gzeof(file)
|
|
523
523
|
/* get internal structure and check integrity */
|
524
524
|
if (file == NULL)
|
525
525
|
return 0;
|
526
|
-
state =
|
526
|
+
state.file = file;
|
527
527
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
528
528
|
return 0;
|
529
529
|
|
@@ -541,7 +541,7 @@ const char * ZEXPORT gzerror(file, errnum)
|
|
541
541
|
/* get internal structure and check integrity */
|
542
542
|
if (file == NULL)
|
543
543
|
return NULL;
|
544
|
-
state =
|
544
|
+
state.file = file;
|
545
545
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
546
546
|
return NULL;
|
547
547
|
|
@@ -561,7 +561,7 @@ void ZEXPORT gzclearerr(file)
|
|
561
561
|
/* get internal structure and check integrity */
|
562
562
|
if (file == NULL)
|
563
563
|
return;
|
564
|
-
state =
|
564
|
+
state.file = file;
|
565
565
|
if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
|
566
566
|
return;
|
567
567
|
|
@@ -8,6 +8,14 @@
|
|
8
8
|
|
9
9
|
#include "gzguts.h"
|
10
10
|
|
11
|
+
/* fix for Visual Studio, which doesn't support ssize_t type.
|
12
|
+
* see https://github.com/facebook/zstd/issues/1800#issuecomment-545945050 */
|
13
|
+
#if defined(_MSC_VER) && !defined(ssize_t)
|
14
|
+
# include <BaseTsd.h>
|
15
|
+
typedef SSIZE_T ssize_t;
|
16
|
+
#endif
|
17
|
+
|
18
|
+
|
11
19
|
/* Local functions */
|
12
20
|
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
|
13
21
|
local int gz_avail OF((gz_statep));
|
@@ -386,7 +394,7 @@ int ZEXPORT gzread(file, buf, len)
|
|
386
394
|
/* get internal structure */
|
387
395
|
if (file == NULL)
|
388
396
|
return -1;
|
389
|
-
state =
|
397
|
+
state.file = file;
|
390
398
|
|
391
399
|
/* check that we're reading and that there's no (serious) error */
|
392
400
|
if (state.state->mode != GZ_READ ||
|
@@ -424,7 +432,7 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
|
|
424
432
|
/* get internal structure */
|
425
433
|
if (file == NULL)
|
426
434
|
return 0;
|
427
|
-
state =
|
435
|
+
state.file = file;
|
428
436
|
|
429
437
|
/* check that we're reading and that there's no (serious) error */
|
430
438
|
if (state.state->mode != GZ_READ ||
|
@@ -470,7 +478,7 @@ int ZEXPORT gzgetc(file)
|
|
470
478
|
/* get internal structure */
|
471
479
|
if (file == NULL)
|
472
480
|
return -1;
|
473
|
-
state =
|
481
|
+
state.file = file;
|
474
482
|
|
475
483
|
/* check that we're reading and that there's no (serious) error */
|
476
484
|
if (state.state->mode != GZ_READ ||
|
@@ -485,7 +493,7 @@ int ZEXPORT gzgetc(file)
|
|
485
493
|
}
|
486
494
|
|
487
495
|
/* nothing there -- try gz_read() */
|
488
|
-
ret = (
|
496
|
+
ret = (int)gz_read(state, buf, 1);
|
489
497
|
return ret < 1 ? -1 : buf[0];
|
490
498
|
}
|
491
499
|
|
@@ -505,7 +513,7 @@ int ZEXPORT gzungetc(c, file)
|
|
505
513
|
/* get internal structure */
|
506
514
|
if (file == NULL)
|
507
515
|
return -1;
|
508
|
-
state =
|
516
|
+
state.file = file;
|
509
517
|
|
510
518
|
/* check that we're reading and that there's no (serious) error */
|
511
519
|
if (state.state->mode != GZ_READ ||
|
@@ -569,7 +577,7 @@ char * ZEXPORT gzgets(file, buf, len)
|
|
569
577
|
/* check parameters and get internal structure */
|
570
578
|
if (file == NULL || buf == NULL || len < 1)
|
571
579
|
return NULL;
|
572
|
-
state =
|
580
|
+
state.file = file;
|
573
581
|
|
574
582
|
/* check that we're reading and that there's no (serious) error */
|
575
583
|
if (state.state->mode != GZ_READ ||
|
@@ -628,7 +636,7 @@ int ZEXPORT gzdirect(file)
|
|
628
636
|
/* get internal structure */
|
629
637
|
if (file == NULL)
|
630
638
|
return 0;
|
631
|
-
state =
|
639
|
+
state.file = file;
|
632
640
|
|
633
641
|
/* if the state is not known, but we can find out, then do so (this is
|
634
642
|
mainly for right after a gzopen() or gzdopen()) */
|
@@ -649,7 +657,7 @@ int ZEXPORT gzclose_r(file)
|
|
649
657
|
/* get internal structure */
|
650
658
|
if (file == NULL)
|
651
659
|
return Z_STREAM_ERROR;
|
652
|
-
state =
|
660
|
+
state.file = file;
|
653
661
|
|
654
662
|
/* check that we're reading */
|
655
663
|
if (state.state->mode != GZ_READ)
|
@@ -258,7 +258,7 @@ int ZEXPORT gzwrite(file, buf, len)
|
|
258
258
|
/* get internal structure */
|
259
259
|
if (file == NULL)
|
260
260
|
return 0;
|
261
|
-
state =
|
261
|
+
state.file = file;
|
262
262
|
|
263
263
|
/* check that we're writing and that there's no error */
|
264
264
|
if (state.state->mode != GZ_WRITE || state.state->err != Z_OK)
|
@@ -289,7 +289,7 @@ z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
|
|
289
289
|
assert(size != 0);
|
290
290
|
if (file == NULL)
|
291
291
|
return 0;
|
292
|
-
state =
|
292
|
+
state.file = file;
|
293
293
|
|
294
294
|
/* check that we're writing and that there's no error */
|
295
295
|
if (state.state->mode != GZ_WRITE || state.state->err != Z_OK)
|
@@ -319,7 +319,7 @@ int ZEXPORT gzputc(file, c)
|
|
319
319
|
/* get internal structure */
|
320
320
|
if (file == NULL)
|
321
321
|
return -1;
|
322
|
-
state =
|
322
|
+
state.file = file;
|
323
323
|
strm = &(state.state->strm);
|
324
324
|
|
325
325
|
/* check that we're writing and that there's no error */
|
@@ -366,7 +366,7 @@ int ZEXPORT gzputs(file, str)
|
|
366
366
|
/* get internal structure */
|
367
367
|
if (file == NULL)
|
368
368
|
return -1;
|
369
|
-
state =
|
369
|
+
state.file = file;
|
370
370
|
|
371
371
|
/* check that we're writing and that there's no error */
|
372
372
|
if (state.state->mode != GZ_WRITE || state.state->err != Z_OK)
|
@@ -393,7 +393,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
|
393
393
|
/* get internal structure */
|
394
394
|
if (file == NULL)
|
395
395
|
return Z_STREAM_ERROR;
|
396
|
-
state =
|
396
|
+
state.file = file;
|
397
397
|
strm = &(state.state->strm);
|
398
398
|
|
399
399
|
/* check that we're writing and that there's no error */
|
@@ -565,7 +565,7 @@ int ZEXPORT gzflush(file, flush)
|
|
565
565
|
/* get internal structure */
|
566
566
|
if (file == NULL)
|
567
567
|
return Z_STREAM_ERROR;
|
568
|
-
state =
|
568
|
+
state.file = file;
|
569
569
|
|
570
570
|
/* check that we're writing and that there's no error */
|
571
571
|
if (state.state->mode != GZ_WRITE || state.state->err != Z_OK)
|
@@ -599,7 +599,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
|
|
599
599
|
/* get internal structure */
|
600
600
|
if (file == NULL)
|
601
601
|
return Z_STREAM_ERROR;
|
602
|
-
state =
|
602
|
+
state.file = file;
|
603
603
|
strm = &(state.state->strm);
|
604
604
|
|
605
605
|
/* check that we're writing and that there's no error */
|
@@ -639,7 +639,7 @@ int ZEXPORT gzclose_w(file)
|
|
639
639
|
/* get internal structure */
|
640
640
|
if (file == NULL)
|
641
641
|
return Z_STREAM_ERROR;
|
642
|
-
state =
|
642
|
+
state.file = file;
|
643
643
|
|
644
644
|
/* check that we're writing */
|
645
645
|
if (state.state->mode != GZ_WRITE)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -19,19 +19,19 @@
|
|
19
19
|
#include <stdlib.h>
|
20
20
|
#include <stdio.h> /* vsprintf */
|
21
21
|
#include <stdarg.h> /* va_list, for z_gzprintf */
|
22
|
+
#include <string.h>
|
22
23
|
#define NO_DUMMY_DECL
|
23
24
|
#define ZLIB_CONST
|
24
25
|
#include <zlib.h> /* without #define Z_PREFIX */
|
25
26
|
#include "zstd_zlibwrapper.h"
|
26
|
-
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_isFrame, ZSTD_MAGICNUMBER */
|
27
|
+
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_isFrame, ZSTD_MAGICNUMBER, ZSTD_customMem */
|
27
28
|
#include "zstd.h"
|
28
|
-
#include "zstd_internal.h" /* ZSTD_malloc, ZSTD_free */
|
29
29
|
|
30
30
|
|
31
31
|
/* === Constants === */
|
32
32
|
#define Z_INFLATE_SYNC 8
|
33
33
|
#define ZLIB_HEADERSIZE 4
|
34
|
-
#define ZSTD_HEADERSIZE ZSTD_FRAMEHEADERSIZE_MIN
|
34
|
+
#define ZSTD_HEADERSIZE ZSTD_FRAMEHEADERSIZE_MIN(ZSTD_f_zstd1)
|
35
35
|
#define ZWRAP_DEFAULT_CLEVEL 3 /* Z_DEFAULT_COMPRESSION is translated to ZWRAP_DEFAULT_CLEVEL for zstd */
|
36
36
|
|
37
37
|
|
@@ -42,6 +42,45 @@
|
|
42
42
|
#define FINISH_WITH_GZ_ERR(msg) { (void)msg; return Z_STREAM_ERROR; }
|
43
43
|
#define FINISH_WITH_NULL_ERR(msg) { (void)msg; return NULL; }
|
44
44
|
|
45
|
+
/* === Utility === */
|
46
|
+
|
47
|
+
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
48
|
+
|
49
|
+
static unsigned ZWRAP_isLittleEndian(void)
|
50
|
+
{
|
51
|
+
const union { unsigned u; char c[4]; } one = { 1 }; /* don't use static : performance detrimental */
|
52
|
+
return one.c[0];
|
53
|
+
}
|
54
|
+
|
55
|
+
#ifndef __has_builtin
|
56
|
+
# define __has_builtin(x) 0
|
57
|
+
#endif
|
58
|
+
|
59
|
+
static unsigned ZWRAP_swap32(unsigned in)
|
60
|
+
{
|
61
|
+
#if defined(_MSC_VER) /* Visual Studio */
|
62
|
+
return _byteswap_ulong(in);
|
63
|
+
#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
|
64
|
+
|| (defined(__clang__) && __has_builtin(__builtin_bswap32))
|
65
|
+
return __builtin_bswap32(in);
|
66
|
+
#else
|
67
|
+
return ((in << 24) & 0xff000000 ) |
|
68
|
+
((in << 8) & 0x00ff0000 ) |
|
69
|
+
((in >> 8) & 0x0000ff00 ) |
|
70
|
+
((in >> 24) & 0x000000ff );
|
71
|
+
#endif
|
72
|
+
}
|
73
|
+
|
74
|
+
static unsigned ZWRAP_readLE32(const void* ptr)
|
75
|
+
{
|
76
|
+
unsigned value;
|
77
|
+
memcpy(&value, ptr, sizeof(value));
|
78
|
+
if (ZWRAP_isLittleEndian())
|
79
|
+
return value;
|
80
|
+
else
|
81
|
+
return ZWRAP_swap32(value);
|
82
|
+
}
|
83
|
+
|
45
84
|
|
46
85
|
/* === Wrapper === */
|
47
86
|
static int g_ZWRAP_useZSTDcompression = ZWRAP_USE_ZSTD; /* 0 = don't use ZSTD */
|
@@ -54,7 +93,7 @@ int ZWRAP_isUsingZSTDcompression(void) { return g_ZWRAP_useZSTDcompression; }
|
|
54
93
|
|
55
94
|
static ZWRAP_decompress_type g_ZWRAPdecompressionType = ZWRAP_AUTO;
|
56
95
|
|
57
|
-
void ZWRAP_setDecompressionType(ZWRAP_decompress_type type) { g_ZWRAPdecompressionType = type; }
|
96
|
+
void ZWRAP_setDecompressionType(ZWRAP_decompress_type type) { g_ZWRAPdecompressionType = type; }
|
58
97
|
|
59
98
|
ZWRAP_decompress_type ZWRAP_getDecompressionType(void) { return g_ZWRAPdecompressionType; }
|
60
99
|
|
@@ -64,8 +103,6 @@ const char * zstdVersion(void) { return ZSTD_VERSION_STRING; }
|
|
64
103
|
|
65
104
|
ZEXTERN const char * ZEXPORT z_zlibVersion OF((void)) { return zlibVersion(); }
|
66
105
|
|
67
|
-
|
68
|
-
|
69
106
|
static void* ZWRAP_allocFunction(void* opaque, size_t size)
|
70
107
|
{
|
71
108
|
z_streamp strm = (z_streamp) opaque;
|
@@ -81,6 +118,35 @@ static void ZWRAP_freeFunction(void* opaque, void* address)
|
|
81
118
|
/* if (address) LOG_WRAPPERC("ZWRAP free %p \n", address); */
|
82
119
|
}
|
83
120
|
|
121
|
+
static void* ZWRAP_customMalloc(size_t size, ZSTD_customMem customMem)
|
122
|
+
{
|
123
|
+
if (customMem.customAlloc)
|
124
|
+
return customMem.customAlloc(customMem.opaque, size);
|
125
|
+
return malloc(size);
|
126
|
+
}
|
127
|
+
|
128
|
+
static void* ZWRAP_customCalloc(size_t size, ZSTD_customMem customMem)
|
129
|
+
{
|
130
|
+
if (customMem.customAlloc) {
|
131
|
+
/* calloc implemented as malloc+memset;
|
132
|
+
* not as efficient as calloc, but next best guess for custom malloc */
|
133
|
+
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
134
|
+
memset(ptr, 0, size);
|
135
|
+
return ptr;
|
136
|
+
}
|
137
|
+
return calloc(1, size);
|
138
|
+
}
|
139
|
+
|
140
|
+
static void ZWRAP_customFree(void* ptr, ZSTD_customMem customMem)
|
141
|
+
{
|
142
|
+
if (ptr!=NULL) {
|
143
|
+
if (customMem.customFree)
|
144
|
+
customMem.customFree(customMem.opaque, ptr);
|
145
|
+
else
|
146
|
+
free(ptr);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
84
150
|
|
85
151
|
|
86
152
|
/* === Compression === */
|
@@ -99,7 +165,7 @@ typedef struct {
|
|
99
165
|
unsigned long long pledgedSrcSize;
|
100
166
|
} ZWRAP_CCtx;
|
101
167
|
|
102
|
-
typedef ZWRAP_CCtx internal_state;
|
168
|
+
/* typedef ZWRAP_CCtx internal_state; */
|
103
169
|
|
104
170
|
|
105
171
|
|
@@ -107,7 +173,7 @@ static size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc)
|
|
107
173
|
{
|
108
174
|
if (zwc==NULL) return 0; /* support free on NULL */
|
109
175
|
ZSTD_freeCStream(zwc->zbc);
|
110
|
-
|
176
|
+
ZWRAP_customFree(zwc, zwc->customMem);
|
111
177
|
return 0;
|
112
178
|
}
|
113
179
|
|
@@ -115,18 +181,19 @@ static size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc)
|
|
115
181
|
static ZWRAP_CCtx* ZWRAP_createCCtx(z_streamp strm)
|
116
182
|
{
|
117
183
|
ZWRAP_CCtx* zwc;
|
184
|
+
ZSTD_customMem customMem = { NULL, NULL, NULL };
|
118
185
|
|
119
186
|
if (strm->zalloc && strm->zfree) {
|
120
|
-
|
121
|
-
|
122
|
-
memset(zwc, 0, sizeof(ZWRAP_CCtx));
|
123
|
-
memcpy(&zwc->allocFunc, strm, sizeof(z_stream));
|
124
|
-
{ ZSTD_customMem const ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, &zwc->allocFunc };
|
125
|
-
zwc->customMem = ZWRAP_customMem; }
|
126
|
-
} else {
|
127
|
-
zwc = (ZWRAP_CCtx*)calloc(1, sizeof(*zwc));
|
128
|
-
if (zwc==NULL) return NULL;
|
187
|
+
customMem.customAlloc = ZWRAP_allocFunction;
|
188
|
+
customMem.customFree = ZWRAP_freeFunction;
|
129
189
|
}
|
190
|
+
customMem.opaque = strm;
|
191
|
+
|
192
|
+
zwc = (ZWRAP_CCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_CCtx), customMem);
|
193
|
+
if (zwc == NULL) return NULL;
|
194
|
+
zwc->allocFunc = *strm;
|
195
|
+
customMem.opaque = &zwc->allocFunc;
|
196
|
+
zwc->customMem = customMem;
|
130
197
|
|
131
198
|
return zwc;
|
132
199
|
}
|
@@ -138,12 +205,21 @@ static int ZWRAP_initializeCStream(ZWRAP_CCtx* zwc, const void* dict, size_t dic
|
|
138
205
|
if (zwc == NULL || zwc->zbc == NULL) return Z_STREAM_ERROR;
|
139
206
|
|
140
207
|
if (!pledgedSrcSize) pledgedSrcSize = zwc->pledgedSrcSize;
|
141
|
-
{
|
142
|
-
|
208
|
+
{ unsigned initErr = 0;
|
209
|
+
ZSTD_parameters const params = ZSTD_getParams(zwc->compressionLevel, pledgedSrcSize, dictSize);
|
210
|
+
ZSTD_CCtx_params* cctxParams = ZSTD_createCCtxParams();
|
211
|
+
if (!cctxParams) return Z_STREAM_ERROR;
|
143
212
|
LOG_WRAPPERC("pledgedSrcSize=%d windowLog=%d chainLog=%d hashLog=%d searchLog=%d minMatch=%d strategy=%d\n",
|
144
213
|
(int)pledgedSrcSize, params.cParams.windowLog, params.cParams.chainLog, params.cParams.hashLog, params.cParams.searchLog, params.cParams.minMatch, params.cParams.strategy);
|
145
|
-
|
146
|
-
|
214
|
+
|
215
|
+
initErr |= ZSTD_isError(ZSTD_CCtx_reset(zwc->zbc, ZSTD_reset_session_only));
|
216
|
+
initErr |= ZSTD_isError(ZSTD_CCtxParams_init_advanced(cctxParams, params));
|
217
|
+
initErr |= ZSTD_isError(ZSTD_CCtx_setParametersUsingCCtxParams(zwc->zbc, cctxParams));
|
218
|
+
initErr |= ZSTD_isError(ZSTD_CCtx_setPledgedSrcSize(zwc->zbc, pledgedSrcSize));
|
219
|
+
initErr |= ZSTD_isError(ZSTD_CCtx_loadDictionary(zwc->zbc, dict, dictSize));
|
220
|
+
|
221
|
+
ZSTD_freeCCtxParams(cctxParams);
|
222
|
+
if (initErr) return Z_STREAM_ERROR;
|
147
223
|
}
|
148
224
|
|
149
225
|
return Z_OK;
|
@@ -179,6 +255,10 @@ int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize)
|
|
179
255
|
return Z_OK;
|
180
256
|
}
|
181
257
|
|
258
|
+
static struct internal_state* convert_into_sis(void* ptr)
|
259
|
+
{
|
260
|
+
return (struct internal_state*) ptr;
|
261
|
+
}
|
182
262
|
|
183
263
|
ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
184
264
|
const char *version, int stream_size))
|
@@ -199,7 +279,7 @@ ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
|
199
279
|
zwc->streamEnd = 0;
|
200
280
|
zwc->totalInBytes = 0;
|
201
281
|
zwc->compressionLevel = level;
|
202
|
-
strm->state = (
|
282
|
+
strm->state = convert_into_sis(zwc); /* use state which in not used by user */
|
203
283
|
strm->total_in = 0;
|
204
284
|
strm->total_out = 0;
|
205
285
|
strm->adler = 0;
|
@@ -301,9 +381,15 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
|
|
301
381
|
} else {
|
302
382
|
if (zwc->totalInBytes == 0) {
|
303
383
|
if (zwc->comprState == ZWRAP_useReset) {
|
304
|
-
size_t
|
384
|
+
size_t resetErr = ZSTD_CCtx_reset(zwc->zbc, ZSTD_reset_session_only);
|
385
|
+
if (ZSTD_isError(resetErr)) {
|
386
|
+
LOG_WRAPPERC("ERROR: ZSTD_CCtx_reset errorCode=%s\n",
|
387
|
+
ZSTD_getErrorName(resetErr));
|
388
|
+
return ZWRAPC_finishWithError(zwc, strm, 0);
|
389
|
+
}
|
390
|
+
resetErr = ZSTD_CCtx_setPledgedSrcSize(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pledgedSrcSize);
|
305
391
|
if (ZSTD_isError(resetErr)) {
|
306
|
-
LOG_WRAPPERC("ERROR:
|
392
|
+
LOG_WRAPPERC("ERROR: ZSTD_CCtx_setPledgedSrcSize errorCode=%s\n",
|
307
393
|
ZSTD_getErrorName(resetErr));
|
308
394
|
return ZWRAPC_finishWithError(zwc, strm, 0);
|
309
395
|
}
|
@@ -455,19 +541,19 @@ static void ZWRAP_initDCtx(ZWRAP_DCtx* zwd)
|
|
455
541
|
static ZWRAP_DCtx* ZWRAP_createDCtx(z_streamp strm)
|
456
542
|
{
|
457
543
|
ZWRAP_DCtx* zwd;
|
458
|
-
|
544
|
+
ZSTD_customMem customMem = { NULL, NULL, NULL };
|
459
545
|
|
460
546
|
if (strm->zalloc && strm->zfree) {
|
461
|
-
|
462
|
-
|
463
|
-
memset(zwd, 0, sizeof(ZWRAP_DCtx));
|
464
|
-
zwd->allocFunc = *strm; /* just to copy zalloc, zfree & opaque */
|
465
|
-
{ ZSTD_customMem const ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, &zwd->allocFunc };
|
466
|
-
zwd->customMem = ZWRAP_customMem; }
|
467
|
-
} else {
|
468
|
-
zwd = (ZWRAP_DCtx*)calloc(1, sizeof(*zwd));
|
469
|
-
if (zwd==NULL) return NULL;
|
547
|
+
customMem.customAlloc = ZWRAP_allocFunction;
|
548
|
+
customMem.customFree = ZWRAP_freeFunction;
|
470
549
|
}
|
550
|
+
customMem.opaque = strm;
|
551
|
+
|
552
|
+
zwd = (ZWRAP_DCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_DCtx), customMem);
|
553
|
+
if (zwd == NULL) return NULL;
|
554
|
+
zwd->allocFunc = *strm;
|
555
|
+
customMem.opaque = &zwd->allocFunc;
|
556
|
+
zwd->customMem = customMem;
|
471
557
|
|
472
558
|
ZWRAP_initDCtx(zwd);
|
473
559
|
return zwd;
|
@@ -477,8 +563,8 @@ static size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd)
|
|
477
563
|
{
|
478
564
|
if (zwd==NULL) return 0; /* support free on null */
|
479
565
|
ZSTD_freeDStream(zwd->zbd);
|
480
|
-
|
481
|
-
|
566
|
+
ZWRAP_customFree(zwd->version, zwd->customMem);
|
567
|
+
ZWRAP_customFree(zwd, zwd->customMem);
|
482
568
|
return 0;
|
483
569
|
}
|
484
570
|
|
@@ -509,7 +595,7 @@ static int ZWRAPD_finishWithErrorMsg(z_streamp strm, char* message)
|
|
509
595
|
|
510
596
|
|
511
597
|
ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
512
|
-
const char
|
598
|
+
const char* version, int stream_size))
|
513
599
|
{
|
514
600
|
if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB) {
|
515
601
|
strm->reserved = ZWRAP_ZLIB_STREAM;
|
@@ -520,13 +606,13 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
|
520
606
|
LOG_WRAPPERD("- inflateInit\n");
|
521
607
|
if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
522
608
|
|
523
|
-
zwd->version =
|
609
|
+
zwd->version = (char*)ZWRAP_customMalloc(strlen(version)+1, zwd->customMem);
|
524
610
|
if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
525
611
|
strcpy(zwd->version, version);
|
526
612
|
|
527
613
|
zwd->stream_size = stream_size;
|
528
614
|
zwd->totalInBytes = 0;
|
529
|
-
strm->state = (
|
615
|
+
strm->state = convert_into_sis(zwd);
|
530
616
|
strm->total_in = 0;
|
531
617
|
strm->total_out = 0;
|
532
618
|
strm->reserved = ZWRAP_UNKNOWN_STREAM;
|
@@ -666,7 +752,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
666
752
|
|
667
753
|
if (zwd->totalInBytes < ZLIB_HEADERSIZE) {
|
668
754
|
if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) {
|
669
|
-
if (
|
755
|
+
if (ZWRAP_readLE32(strm->next_in) != ZSTD_MAGICNUMBER) {
|
670
756
|
{ int const initErr = (zwd->windowBits) ?
|
671
757
|
inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) :
|
672
758
|
inflateInit_(strm, zwd->version, zwd->stream_size);
|
@@ -694,7 +780,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
694
780
|
strm->avail_in -= srcSize;
|
695
781
|
if (zwd->totalInBytes < ZLIB_HEADERSIZE) return Z_OK;
|
696
782
|
|
697
|
-
if (
|
783
|
+
if (ZWRAP_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) {
|
698
784
|
z_stream strm2;
|
699
785
|
strm2.next_in = strm->next_in;
|
700
786
|
strm2.avail_in = strm->avail_in;
|
@@ -758,7 +844,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
758
844
|
goto error;
|
759
845
|
}
|
760
846
|
} else {
|
761
|
-
size_t const resetErr =
|
847
|
+
size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only);
|
762
848
|
if (ZSTD_isError(resetErr)) goto error;
|
763
849
|
}
|
764
850
|
} else {
|
@@ -778,7 +864,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
778
864
|
goto error;
|
779
865
|
}
|
780
866
|
} else {
|
781
|
-
size_t const resetErr =
|
867
|
+
size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only);
|
782
868
|
if (ZSTD_isError(resetErr)) goto error;
|
783
869
|
}
|
784
870
|
|
@@ -1003,7 +1089,7 @@ ZEXTERN int ZEXPORT z_inflateBackEnd OF((z_streamp strm))
|
|
1003
1089
|
}
|
1004
1090
|
|
1005
1091
|
|
1006
|
-
ZEXTERN uLong ZEXPORT z_zlibCompileFlags OF((void)) { return zlibCompileFlags(); }
|
1092
|
+
ZEXTERN uLong ZEXPORT z_zlibCompileFlags OF((void)) { return zlibCompileFlags(); }
|
1007
1093
|
|
1008
1094
|
|
1009
1095
|
|