extzstd 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.ja.md +8 -0
- data/README.md +1 -1
- data/contrib/zstd/CHANGELOG +94 -0
- data/contrib/zstd/CONTRIBUTING.md +351 -1
- data/contrib/zstd/Makefile +32 -10
- data/contrib/zstd/README.md +33 -10
- data/contrib/zstd/TESTING.md +2 -2
- data/contrib/zstd/appveyor.yml +42 -4
- data/contrib/zstd/lib/Makefile +128 -60
- data/contrib/zstd/lib/README.md +47 -16
- data/contrib/zstd/lib/common/bitstream.h +38 -39
- data/contrib/zstd/lib/common/compiler.h +40 -5
- data/contrib/zstd/lib/common/cpu.h +1 -1
- data/contrib/zstd/lib/common/debug.c +11 -31
- data/contrib/zstd/lib/common/debug.h +11 -31
- data/contrib/zstd/lib/common/entropy_common.c +13 -33
- data/contrib/zstd/lib/common/error_private.c +2 -1
- data/contrib/zstd/lib/common/error_private.h +6 -2
- data/contrib/zstd/lib/common/fse.h +12 -32
- data/contrib/zstd/lib/common/fse_decompress.c +12 -35
- data/contrib/zstd/lib/common/huf.h +15 -33
- data/contrib/zstd/lib/common/mem.h +75 -2
- data/contrib/zstd/lib/common/pool.c +8 -4
- data/contrib/zstd/lib/common/pool.h +2 -2
- data/contrib/zstd/lib/common/threading.c +50 -4
- data/contrib/zstd/lib/common/threading.h +36 -4
- data/contrib/zstd/lib/common/xxhash.c +23 -35
- data/contrib/zstd/lib/common/xxhash.h +11 -31
- data/contrib/zstd/lib/common/zstd_common.c +1 -1
- data/contrib/zstd/lib/common/zstd_errors.h +2 -1
- data/contrib/zstd/lib/common/zstd_internal.h +154 -26
- data/contrib/zstd/lib/compress/fse_compress.c +17 -40
- data/contrib/zstd/lib/compress/hist.c +15 -35
- data/contrib/zstd/lib/compress/hist.h +12 -32
- data/contrib/zstd/lib/compress/huf_compress.c +92 -92
- data/contrib/zstd/lib/compress/zstd_compress.c +1191 -1330
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +317 -55
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
- data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.c +65 -43
- data/contrib/zstd/lib/compress/zstd_double_fast.h +2 -2
- data/contrib/zstd/lib/compress/zstd_fast.c +92 -66
- data/contrib/zstd/lib/compress/zstd_fast.h +2 -2
- data/contrib/zstd/lib/compress/zstd_lazy.c +74 -42
- data/contrib/zstd/lib/compress/zstd_lazy.h +1 -1
- data/contrib/zstd/lib/compress/zstd_ldm.c +32 -10
- data/contrib/zstd/lib/compress/zstd_ldm.h +7 -2
- data/contrib/zstd/lib/compress/zstd_opt.c +81 -114
- data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
- data/contrib/zstd/lib/compress/zstdmt_compress.c +95 -51
- data/contrib/zstd/lib/compress/zstdmt_compress.h +3 -2
- data/contrib/zstd/lib/decompress/huf_decompress.c +76 -60
- data/contrib/zstd/lib/decompress/zstd_ddict.c +12 -8
- data/contrib/zstd/lib/decompress/zstd_ddict.h +2 -2
- data/contrib/zstd/lib/decompress/zstd_decompress.c +292 -172
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +459 -338
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +3 -3
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +18 -4
- data/contrib/zstd/lib/deprecated/zbuff.h +9 -8
- data/contrib/zstd/lib/deprecated/zbuff_common.c +2 -2
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +1 -1
- data/contrib/zstd/lib/dictBuilder/cover.c +164 -54
- data/contrib/zstd/lib/dictBuilder/cover.h +52 -7
- data/contrib/zstd/lib/dictBuilder/fastcover.c +60 -43
- data/contrib/zstd/lib/dictBuilder/zdict.c +43 -19
- data/contrib/zstd/lib/dictBuilder/zdict.h +56 -28
- data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -4
- data/contrib/zstd/lib/legacy/zstd_v01.c +110 -110
- data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +23 -13
- data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +23 -13
- data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +30 -17
- data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v05.c +113 -102
- data/contrib/zstd/lib/legacy/zstd_v05.h +2 -2
- data/contrib/zstd/lib/legacy/zstd_v06.c +20 -18
- data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +25 -19
- data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
- data/contrib/zstd/lib/libzstd.pc.in +3 -2
- data/contrib/zstd/lib/zstd.h +265 -88
- data/ext/extzstd.h +1 -1
- data/ext/libzstd_conf.h +8 -0
- data/ext/zstd_common.c +1 -3
- data/ext/zstd_compress.c +3 -3
- data/ext/zstd_decompress.c +1 -5
- data/ext/zstd_dictbuilder.c +2 -3
- data/ext/zstd_dictbuilder_fastcover.c +1 -3
- data/ext/zstd_legacy_v01.c +2 -0
- data/ext/zstd_legacy_v02.c +2 -0
- data/ext/zstd_legacy_v03.c +2 -0
- data/ext/zstd_legacy_v04.c +2 -0
- data/ext/zstd_legacy_v05.c +2 -0
- data/ext/zstd_legacy_v06.c +2 -0
- data/ext/zstd_legacy_v07.c +2 -0
- data/lib/extzstd.rb +18 -10
- data/lib/extzstd/version.rb +1 -1
- metadata +15 -6
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2020, 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
|
@@ -47,6 +47,7 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
47
47
|
/* following error codes are not stable and may be removed or changed in a future version */
|
48
48
|
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
49
49
|
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
50
|
+
case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
|
50
51
|
case PREFIX(maxCode):
|
51
52
|
default: return notErrorCode;
|
52
53
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2020, 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
|
@@ -49,7 +49,7 @@ typedef ZSTD_ErrorCode ERR_enum;
|
|
49
49
|
/*-****************************************
|
50
50
|
* Error codes handling
|
51
51
|
******************************************/
|
52
|
-
#undef ERROR /*
|
52
|
+
#undef ERROR /* already defined on Visual Studio */
|
53
53
|
#define ERROR(name) ZSTD_ERROR(name)
|
54
54
|
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
55
55
|
|
@@ -57,6 +57,10 @@ ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
|
|
57
57
|
|
58
58
|
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
|
59
59
|
|
60
|
+
/* check and forward error code */
|
61
|
+
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
62
|
+
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
63
|
+
|
60
64
|
|
61
65
|
/*-****************************************
|
62
66
|
* Error Strings
|
@@ -1,35 +1,15 @@
|
|
1
1
|
/* ******************************************************************
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
2
|
+
* FSE : Finite State Entropy codec
|
3
|
+
* Public Prototypes declaration
|
4
|
+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
|
5
|
+
*
|
6
|
+
* You can contact the author at :
|
7
|
+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
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
|
#if defined (__cplusplus)
|
@@ -308,7 +288,7 @@ If there is an error, the function will return an error code, which can be teste
|
|
308
288
|
*******************************************/
|
309
289
|
/* FSE buffer bounds */
|
310
290
|
#define FSE_NCOUNTBOUND 512
|
311
|
-
#define FSE_BLOCKBOUND(size) (size + (size>>7))
|
291
|
+
#define FSE_BLOCKBOUND(size) (size + (size>>7) + 4 /* fse states */ + sizeof(size_t) /* bitContainer */)
|
312
292
|
#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
313
293
|
|
314
294
|
/* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */
|
@@ -1,35 +1,15 @@
|
|
1
1
|
/* ******************************************************************
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
* Redistributions in binary form must reproduce the above
|
14
|
-
copyright notice, this list of conditions and the following disclaimer
|
15
|
-
in the documentation and/or other materials provided with the
|
16
|
-
distribution.
|
17
|
-
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
You can contact the author at :
|
31
|
-
- FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
32
|
-
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
2
|
+
* FSE : Finite State Entropy decoder
|
3
|
+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
|
4
|
+
*
|
5
|
+
* You can contact the author at :
|
6
|
+
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
7
|
+
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
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
|
|
@@ -51,9 +31,6 @@
|
|
51
31
|
#define FSE_isError ERR_isError
|
52
32
|
#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
53
33
|
|
54
|
-
/* check and forward error code */
|
55
|
-
#define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
|
56
|
-
|
57
34
|
|
58
35
|
/* **************************************************************
|
59
36
|
* Templates
|
@@ -285,7 +262,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size
|
|
285
262
|
/* normal FSE decoding mode */
|
286
263
|
size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize);
|
287
264
|
if (FSE_isError(NCountLength)) return NCountLength;
|
288
|
-
|
265
|
+
/* if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); */ /* too small input size; supposed to be already checked in NCountLength, only remaining case : NCountLength==cSrcSize */
|
289
266
|
if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
|
290
267
|
ip += NCountLength;
|
291
268
|
cSrcSize -= NCountLength;
|
@@ -1,35 +1,15 @@
|
|
1
1
|
/* ******************************************************************
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
2
|
+
* huff0 huffman codec,
|
3
|
+
* part of Finite State Entropy library
|
4
|
+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
|
5
|
+
*
|
6
|
+
* You can contact the author at :
|
7
|
+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
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
|
#if defined (__cplusplus)
|
@@ -110,7 +90,7 @@ HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity,
|
|
110
90
|
/** HUF_compress4X_wksp() :
|
111
91
|
* Same as HUF_compress2(), but uses externally allocated `workSpace`.
|
112
92
|
* `workspace` must have minimum alignment of 4, and be at least as large as HUF_WORKSPACE_SIZE */
|
113
|
-
#define HUF_WORKSPACE_SIZE (6 << 10)
|
93
|
+
#define HUF_WORKSPACE_SIZE ((6 << 10) + 256)
|
114
94
|
#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
|
115
95
|
HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
116
96
|
const void* src, size_t srcSize,
|
@@ -208,6 +188,8 @@ typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
|
|
208
188
|
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
|
209
189
|
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
210
190
|
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
191
|
+
size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
192
|
+
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
211
193
|
|
212
194
|
typedef enum {
|
213
195
|
HUF_repeat_none, /**< Cannot use the previous table */
|
@@ -246,7 +228,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,
|
|
246
228
|
|
247
229
|
/** HUF_readCTable() :
|
248
230
|
* Loading a CTable saved with HUF_writeCTable() */
|
249
|
-
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
|
231
|
+
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
|
250
232
|
|
251
233
|
/** HUF_getNbBits() :
|
252
234
|
* Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2020, 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
|
@@ -47,6 +47,79 @@ extern "C" {
|
|
47
47
|
#define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
|
48
48
|
MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
49
49
|
|
50
|
+
/* detects whether we are being compiled under msan */
|
51
|
+
#if defined (__has_feature)
|
52
|
+
# if __has_feature(memory_sanitizer)
|
53
|
+
# define MEMORY_SANITIZER 1
|
54
|
+
# endif
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#if defined (MEMORY_SANITIZER)
|
58
|
+
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
59
|
+
* We therefore declare the functions we need ourselves, rather than trying to
|
60
|
+
* include the header file... */
|
61
|
+
|
62
|
+
#include <stdint.h> /* intptr_t */
|
63
|
+
|
64
|
+
/* Make memory region fully initialized (without changing its contents). */
|
65
|
+
void __msan_unpoison(const volatile void *a, size_t size);
|
66
|
+
|
67
|
+
/* Make memory region fully uninitialized (without changing its contents).
|
68
|
+
This is a legacy interface that does not update origin information. Use
|
69
|
+
__msan_allocated_memory() instead. */
|
70
|
+
void __msan_poison(const volatile void *a, size_t size);
|
71
|
+
|
72
|
+
/* Returns the offset of the first (at least partially) poisoned byte in the
|
73
|
+
memory range, or -1 if the whole range is good. */
|
74
|
+
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
|
75
|
+
#endif
|
76
|
+
|
77
|
+
/* detects whether we are being compiled under asan */
|
78
|
+
#if defined (__has_feature)
|
79
|
+
# if __has_feature(address_sanitizer)
|
80
|
+
# define ADDRESS_SANITIZER 1
|
81
|
+
# endif
|
82
|
+
#elif defined(__SANITIZE_ADDRESS__)
|
83
|
+
# define ADDRESS_SANITIZER 1
|
84
|
+
#endif
|
85
|
+
|
86
|
+
#if defined (ADDRESS_SANITIZER)
|
87
|
+
/* Not all platforms that support asan provide sanitizers/asan_interface.h.
|
88
|
+
* We therefore declare the functions we need ourselves, rather than trying to
|
89
|
+
* include the header file... */
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
|
93
|
+
*
|
94
|
+
* This memory must be previously allocated by your program. Instrumented
|
95
|
+
* code is forbidden from accessing addresses in this region until it is
|
96
|
+
* unpoisoned. This function is not guaranteed to poison the entire region -
|
97
|
+
* it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
|
98
|
+
* alignment restrictions.
|
99
|
+
*
|
100
|
+
* \note This function is not thread-safe because no two threads can poison or
|
101
|
+
* unpoison memory in the same memory region simultaneously.
|
102
|
+
*
|
103
|
+
* \param addr Start of memory region.
|
104
|
+
* \param size Size of memory region. */
|
105
|
+
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
|
109
|
+
*
|
110
|
+
* This memory must be previously allocated by your program. Accessing
|
111
|
+
* addresses in this region is allowed until this region is poisoned again.
|
112
|
+
* This function could unpoison a super-region of <c>[addr, addr+size)</c> due
|
113
|
+
* to ASan alignment restrictions.
|
114
|
+
*
|
115
|
+
* \note This function is not thread-safe because no two threads can
|
116
|
+
* poison or unpoison memory in the same memory region simultaneously.
|
117
|
+
*
|
118
|
+
* \param addr Start of memory region.
|
119
|
+
* \param size Size of memory region. */
|
120
|
+
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
121
|
+
#endif
|
122
|
+
|
50
123
|
|
51
124
|
/*-**************************************************************
|
52
125
|
* Basic Types
|
@@ -102,7 +175,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
102
175
|
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
103
176
|
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
104
177
|
# define MEM_FORCE_MEMORY_ACCESS 2
|
105
|
-
# elif defined(__INTEL_COMPILER) || defined(__GNUC__)
|
178
|
+
# elif defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
|
106
179
|
# define MEM_FORCE_MEMORY_ACCESS 1
|
107
180
|
# endif
|
108
181
|
#endif
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2020, 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
|
@@ -127,9 +127,13 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
|
127
127
|
ctx->queueTail = 0;
|
128
128
|
ctx->numThreadsBusy = 0;
|
129
129
|
ctx->queueEmpty = 1;
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
{
|
131
|
+
int error = 0;
|
132
|
+
error |= ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
|
133
|
+
error |= ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
|
134
|
+
error |= ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
|
135
|
+
if (error) { POOL_free(ctx); return NULL; }
|
136
|
+
}
|
133
137
|
ctx->shutdown = 0;
|
134
138
|
/* Allocate space for the thread handles */
|
135
139
|
ctx->threads = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2020, 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
|
@@ -18,7 +18,7 @@ extern "C" {
|
|
18
18
|
|
19
19
|
#include <stddef.h> /* size_t */
|
20
20
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
|
21
|
-
#include "zstd.h"
|
21
|
+
#include "../zstd.h"
|
22
22
|
|
23
23
|
typedef struct POOL_ctx_s POOL_ctx;
|
24
24
|
|
@@ -2,18 +2,21 @@
|
|
2
2
|
* Copyright (c) 2016 Tino Reichardt
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
|
+
* You can contact the author at:
|
6
|
+
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
7
|
+
*
|
5
8
|
* This source code is licensed under both the BSD-style license (found in the
|
6
9
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
10
|
* in the COPYING file in the root directory of this source tree).
|
8
|
-
*
|
9
|
-
* You can contact the author at:
|
10
|
-
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
11
|
+
* You may select, at your option, one of the above-listed licenses.
|
11
12
|
*/
|
12
13
|
|
13
14
|
/**
|
14
15
|
* This file will hold wrapper for systems, which do not support pthreads
|
15
16
|
*/
|
16
17
|
|
18
|
+
#include "threading.h"
|
19
|
+
|
17
20
|
/* create fake symbol to avoid empty translation unit warning */
|
18
21
|
int g_ZSTD_threading_useless_symbol;
|
19
22
|
|
@@ -28,7 +31,6 @@ int g_ZSTD_threading_useless_symbol;
|
|
28
31
|
/* === Dependencies === */
|
29
32
|
#include <process.h>
|
30
33
|
#include <errno.h>
|
31
|
-
#include "threading.h"
|
32
34
|
|
33
35
|
|
34
36
|
/* === Implementation === */
|
@@ -73,3 +75,47 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
|
|
73
75
|
}
|
74
76
|
|
75
77
|
#endif /* ZSTD_MULTITHREAD */
|
78
|
+
|
79
|
+
#if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
|
80
|
+
|
81
|
+
#include <stdlib.h>
|
82
|
+
|
83
|
+
int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
|
84
|
+
{
|
85
|
+
*mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
|
86
|
+
if (!*mutex)
|
87
|
+
return 1;
|
88
|
+
return pthread_mutex_init(*mutex, attr);
|
89
|
+
}
|
90
|
+
|
91
|
+
int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
|
92
|
+
{
|
93
|
+
if (!*mutex)
|
94
|
+
return 0;
|
95
|
+
{
|
96
|
+
int const ret = pthread_mutex_destroy(*mutex);
|
97
|
+
free(*mutex);
|
98
|
+
return ret;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
|
103
|
+
{
|
104
|
+
*cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
|
105
|
+
if (!*cond)
|
106
|
+
return 1;
|
107
|
+
return pthread_cond_init(*cond, attr);
|
108
|
+
}
|
109
|
+
|
110
|
+
int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
|
111
|
+
{
|
112
|
+
if (!*cond)
|
113
|
+
return 0;
|
114
|
+
{
|
115
|
+
int const ret = pthread_cond_destroy(*cond);
|
116
|
+
free(*cond);
|
117
|
+
return ret;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
#endif
|