zstdlib 0.6.0-x64-mingw32 → 0.9.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +20 -0
- data/README.md +7 -1
- data/Rakefile +38 -8
- data/ext/{zstdlib → zstdlib_c}/extconf.rb +10 -5
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
- data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/adler32.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/compress.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzclose.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzguts.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzlib.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzread.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzwrite.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/infback.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffixed.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/uncompr.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zconf.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zlib.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
- data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +75 -57
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +1 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/debug.c +24 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +22 -49
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +3 -1
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +51 -42
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +149 -57
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +60 -54
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +87 -98
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +34 -23
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +5 -5
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +10 -8
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +4 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +10 -10
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_internal.h +493 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +105 -85
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +41 -63
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +13 -33
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress.c +6327 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +537 -82
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +21 -16
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +4 -2
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +61 -34
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +10 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.c +573 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +236 -95
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +321 -143
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +2 -2
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +328 -137
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +2 -2
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +336 -209
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +15 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +439 -239
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +1 -1
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +205 -462
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress.c +1889 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +20 -16
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +3 -3
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +691 -230
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress_block.c +2072 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +16 -7
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +71 -10
- data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +760 -234
- data/ext/{zstdlib/zstd-1.4.4/lib/common → zstdlib_c/zstd-1.5.2/lib}/zstd_errors.h +3 -1
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +1 -1
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +133 -44
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +1 -1
- data/ext/zstdlib_c/zstd.mk +15 -0
- data/lib/2.4/zstdlib_c.so +0 -0
- data/lib/2.5/zstdlib_c.so +0 -0
- data/lib/2.6/zstdlib_c.so +0 -0
- data/lib/2.7/zstdlib_c.so +0 -0
- data/lib/3.0/zstdlib_c.so +0 -0
- data/lib/zstdlib.rb +2 -2
- metadata +124 -114
- data/ext/zstdlib/zstd-1.4.4/lib/common/compiler.h +0 -159
- data/ext/zstdlib/zstd-1.4.4/lib/common/debug.c +0 -44
- data/ext/zstdlib/zstd-1.4.4/lib/common/entropy_common.c +0 -236
- data/ext/zstdlib/zstd-1.4.4/lib/common/error_private.h +0 -76
- data/ext/zstdlib/zstd-1.4.4/lib/common/xxhash.c +0 -882
- data/ext/zstdlib/zstd-1.4.4/lib/common/xxhash.h +0 -305
- data/ext/zstdlib/zstd-1.4.4/lib/common/zstd_internal.h +0 -350
- data/ext/zstdlib/zstd-1.4.4/lib/compress/huf_compress.c +0 -798
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_compress.c +0 -4103
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_lazy.c +0 -1115
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_lazy.h +0 -67
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstdmt_compress.h +0 -192
- data/ext/zstdlib/zstd-1.4.4/lib/decompress/huf_decompress.c +0 -1234
- data/ext/zstdlib/zstd-1.4.4/lib/decompress/zstd_decompress_block.c +0 -1323
- data/ext/zstdlib/zstd.mk +0 -14
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/2.7/zstdlib.so +0 -0
@@ -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
|
|
File without changes
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
@@ -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,13 +19,13 @@
|
|
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 === */
|
@@ -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 */
|
@@ -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 === */
|
@@ -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,20 +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 ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, NULL };
|
125
|
-
ZWRAP_customMem.opaque = &zwc->allocFunc;
|
126
|
-
zwc->customMem = ZWRAP_customMem;
|
127
|
-
}
|
128
|
-
} else {
|
129
|
-
zwc = (ZWRAP_CCtx*)calloc(1, sizeof(*zwc));
|
130
|
-
if (zwc==NULL) return NULL;
|
187
|
+
customMem.customAlloc = ZWRAP_allocFunction;
|
188
|
+
customMem.customFree = ZWRAP_freeFunction;
|
131
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;
|
132
197
|
|
133
198
|
return zwc;
|
134
199
|
}
|
@@ -140,12 +205,21 @@ static int ZWRAP_initializeCStream(ZWRAP_CCtx* zwc, const void* dict, size_t dic
|
|
140
205
|
if (zwc == NULL || zwc->zbc == NULL) return Z_STREAM_ERROR;
|
141
206
|
|
142
207
|
if (!pledgedSrcSize) pledgedSrcSize = zwc->pledgedSrcSize;
|
143
|
-
{
|
144
|
-
|
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;
|
145
212
|
LOG_WRAPPERC("pledgedSrcSize=%d windowLog=%d chainLog=%d hashLog=%d searchLog=%d minMatch=%d strategy=%d\n",
|
146
213
|
(int)pledgedSrcSize, params.cParams.windowLog, params.cParams.chainLog, params.cParams.hashLog, params.cParams.searchLog, params.cParams.minMatch, params.cParams.strategy);
|
147
|
-
|
148
|
-
|
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;
|
149
223
|
}
|
150
224
|
|
151
225
|
return Z_OK;
|
@@ -181,6 +255,10 @@ int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize)
|
|
181
255
|
return Z_OK;
|
182
256
|
}
|
183
257
|
|
258
|
+
static struct internal_state* convert_into_sis(void* ptr)
|
259
|
+
{
|
260
|
+
return (struct internal_state*) ptr;
|
261
|
+
}
|
184
262
|
|
185
263
|
ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
186
264
|
const char *version, int stream_size))
|
@@ -201,7 +279,7 @@ ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
|
201
279
|
zwc->streamEnd = 0;
|
202
280
|
zwc->totalInBytes = 0;
|
203
281
|
zwc->compressionLevel = level;
|
204
|
-
strm->state = (
|
282
|
+
strm->state = convert_into_sis(zwc); /* use state which in not used by user */
|
205
283
|
strm->total_in = 0;
|
206
284
|
strm->total_out = 0;
|
207
285
|
strm->adler = 0;
|
@@ -303,9 +381,15 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
|
|
303
381
|
} else {
|
304
382
|
if (zwc->totalInBytes == 0) {
|
305
383
|
if (zwc->comprState == ZWRAP_useReset) {
|
306
|
-
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);
|
307
391
|
if (ZSTD_isError(resetErr)) {
|
308
|
-
LOG_WRAPPERC("ERROR:
|
392
|
+
LOG_WRAPPERC("ERROR: ZSTD_CCtx_setPledgedSrcSize errorCode=%s\n",
|
309
393
|
ZSTD_getErrorName(resetErr));
|
310
394
|
return ZWRAPC_finishWithError(zwc, strm, 0);
|
311
395
|
}
|
@@ -457,21 +541,19 @@ static void ZWRAP_initDCtx(ZWRAP_DCtx* zwd)
|
|
457
541
|
static ZWRAP_DCtx* ZWRAP_createDCtx(z_streamp strm)
|
458
542
|
{
|
459
543
|
ZWRAP_DCtx* zwd;
|
460
|
-
|
544
|
+
ZSTD_customMem customMem = { NULL, NULL, NULL };
|
461
545
|
|
462
546
|
if (strm->zalloc && strm->zfree) {
|
463
|
-
|
464
|
-
|
465
|
-
memset(zwd, 0, sizeof(ZWRAP_DCtx));
|
466
|
-
zwd->allocFunc = *strm; /* just to copy zalloc, zfree & opaque */
|
467
|
-
{ ZSTD_customMem ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, NULL };
|
468
|
-
ZWRAP_customMem.opaque = &zwd->allocFunc;
|
469
|
-
zwd->customMem = ZWRAP_customMem;
|
470
|
-
}
|
471
|
-
} else {
|
472
|
-
zwd = (ZWRAP_DCtx*)calloc(1, sizeof(*zwd));
|
473
|
-
if (zwd==NULL) return NULL;
|
547
|
+
customMem.customAlloc = ZWRAP_allocFunction;
|
548
|
+
customMem.customFree = ZWRAP_freeFunction;
|
474
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;
|
475
557
|
|
476
558
|
ZWRAP_initDCtx(zwd);
|
477
559
|
return zwd;
|
@@ -481,8 +563,8 @@ static size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd)
|
|
481
563
|
{
|
482
564
|
if (zwd==NULL) return 0; /* support free on null */
|
483
565
|
ZSTD_freeDStream(zwd->zbd);
|
484
|
-
|
485
|
-
|
566
|
+
ZWRAP_customFree(zwd->version, zwd->customMem);
|
567
|
+
ZWRAP_customFree(zwd, zwd->customMem);
|
486
568
|
return 0;
|
487
569
|
}
|
488
570
|
|
@@ -524,13 +606,13 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
|
524
606
|
LOG_WRAPPERD("- inflateInit\n");
|
525
607
|
if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
526
608
|
|
527
|
-
zwd->version = (char*)
|
609
|
+
zwd->version = (char*)ZWRAP_customMalloc(strlen(version)+1, zwd->customMem);
|
528
610
|
if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
529
611
|
strcpy(zwd->version, version);
|
530
612
|
|
531
613
|
zwd->stream_size = stream_size;
|
532
614
|
zwd->totalInBytes = 0;
|
533
|
-
strm->state = (
|
615
|
+
strm->state = convert_into_sis(zwd);
|
534
616
|
strm->total_in = 0;
|
535
617
|
strm->total_out = 0;
|
536
618
|
strm->reserved = ZWRAP_UNKNOWN_STREAM;
|
@@ -670,7 +752,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
670
752
|
|
671
753
|
if (zwd->totalInBytes < ZLIB_HEADERSIZE) {
|
672
754
|
if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) {
|
673
|
-
if (
|
755
|
+
if (ZWRAP_readLE32(strm->next_in) != ZSTD_MAGICNUMBER) {
|
674
756
|
{ int const initErr = (zwd->windowBits) ?
|
675
757
|
inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) :
|
676
758
|
inflateInit_(strm, zwd->version, zwd->stream_size);
|
@@ -698,7 +780,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
698
780
|
strm->avail_in -= srcSize;
|
699
781
|
if (zwd->totalInBytes < ZLIB_HEADERSIZE) return Z_OK;
|
700
782
|
|
701
|
-
if (
|
783
|
+
if (ZWRAP_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) {
|
702
784
|
z_stream strm2;
|
703
785
|
strm2.next_in = strm->next_in;
|
704
786
|
strm2.avail_in = strm->avail_in;
|
@@ -762,7 +844,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
762
844
|
goto error;
|
763
845
|
}
|
764
846
|
} else {
|
765
|
-
size_t const resetErr =
|
847
|
+
size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only);
|
766
848
|
if (ZSTD_isError(resetErr)) goto error;
|
767
849
|
}
|
768
850
|
} else {
|
@@ -782,7 +864,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|
782
864
|
goto error;
|
783
865
|
}
|
784
866
|
} else {
|
785
|
-
size_t const resetErr =
|
867
|
+
size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only);
|
786
868
|
if (ZSTD_isError(resetErr)) goto error;
|
787
869
|
}
|
788
870
|
|
@@ -1107,3 +1189,10 @@ ZEXTERN const z_crc_t FAR * ZEXPORT z_get_crc_table OF((void))
|
|
1107
1189
|
return get_crc_table();
|
1108
1190
|
}
|
1109
1191
|
#endif
|
1192
|
+
|
1193
|
+
/* Error function */
|
1194
|
+
ZEXTERN const char * ZEXPORT z_zError OF((int err))
|
1195
|
+
{
|
1196
|
+
/* Just use zlib Error function */
|
1197
|
+
return zError(err);
|
1198
|
+
}
|
@@ -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
|
@@ -0,0 +1,15 @@
|
|
1
|
+
VPATH := $(SRCDIR)/common $(SRCDIR)/compress $(SRCDIR)/decompress
|
2
|
+
|
3
|
+
CSRCS := $(foreach dir,$(VPATH),$(wildcard $(dir)/*.c))
|
4
|
+
SSRCS := $(foreach dir,$(VPATH),$(wildcard $(dir)/*.S))
|
5
|
+
OBJS := $(patsubst %.c,%.o,$(foreach file,$(CSRCS),$(notdir $(file)))) $(patsubst %.S,%.o,$(foreach file,$(SSRCS),$(notdir $(file))))
|
6
|
+
|
7
|
+
CPPFLAGS += -I$(SRCDIR) -I$(SRCDIR)/common
|
8
|
+
|
9
|
+
LIB = ../libzstd.a
|
10
|
+
|
11
|
+
$(LIB) : $(OBJS)
|
12
|
+
$(AR) cr $@ $^
|
13
|
+
|
14
|
+
clean :
|
15
|
+
$(RM) -f $(LIB) $(OBJS)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/zstdlib.rb
CHANGED