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,236 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Common functions of New Generation Entropy library
|
3
|
-
Copyright (C) 2016, Yann Collet.
|
4
|
-
|
5
|
-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
6
|
-
|
7
|
-
Redistribution and use in source and binary forms, with or without
|
8
|
-
modification, are permitted provided that the following conditions are
|
9
|
-
met:
|
10
|
-
|
11
|
-
* Redistributions of source code must retain the above copyright
|
12
|
-
notice, this list of conditions and the following disclaimer.
|
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+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
32
|
-
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
33
|
-
*************************************************************************** */
|
34
|
-
|
35
|
-
/* *************************************
|
36
|
-
* Dependencies
|
37
|
-
***************************************/
|
38
|
-
#include "mem.h"
|
39
|
-
#include "error_private.h" /* ERR_*, ERROR */
|
40
|
-
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
|
41
|
-
#include "fse.h"
|
42
|
-
#define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */
|
43
|
-
#include "huf.h"
|
44
|
-
|
45
|
-
|
46
|
-
/*=== Version ===*/
|
47
|
-
unsigned FSE_versionNumber(void) { return FSE_VERSION_NUMBER; }
|
48
|
-
|
49
|
-
|
50
|
-
/*=== Error Management ===*/
|
51
|
-
unsigned FSE_isError(size_t code) { return ERR_isError(code); }
|
52
|
-
const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
53
|
-
|
54
|
-
unsigned HUF_isError(size_t code) { return ERR_isError(code); }
|
55
|
-
const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
56
|
-
|
57
|
-
|
58
|
-
/*-**************************************************************
|
59
|
-
* FSE NCount encoding-decoding
|
60
|
-
****************************************************************/
|
61
|
-
size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
62
|
-
const void* headerBuffer, size_t hbSize)
|
63
|
-
{
|
64
|
-
const BYTE* const istart = (const BYTE*) headerBuffer;
|
65
|
-
const BYTE* const iend = istart + hbSize;
|
66
|
-
const BYTE* ip = istart;
|
67
|
-
int nbBits;
|
68
|
-
int remaining;
|
69
|
-
int threshold;
|
70
|
-
U32 bitStream;
|
71
|
-
int bitCount;
|
72
|
-
unsigned charnum = 0;
|
73
|
-
int previous0 = 0;
|
74
|
-
|
75
|
-
if (hbSize < 4) {
|
76
|
-
/* This function only works when hbSize >= 4 */
|
77
|
-
char buffer[4];
|
78
|
-
memset(buffer, 0, sizeof(buffer));
|
79
|
-
memcpy(buffer, headerBuffer, hbSize);
|
80
|
-
{ size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
|
81
|
-
buffer, sizeof(buffer));
|
82
|
-
if (FSE_isError(countSize)) return countSize;
|
83
|
-
if (countSize > hbSize) return ERROR(corruption_detected);
|
84
|
-
return countSize;
|
85
|
-
} }
|
86
|
-
assert(hbSize >= 4);
|
87
|
-
|
88
|
-
/* init */
|
89
|
-
memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */
|
90
|
-
bitStream = MEM_readLE32(ip);
|
91
|
-
nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
|
92
|
-
if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
|
93
|
-
bitStream >>= 4;
|
94
|
-
bitCount = 4;
|
95
|
-
*tableLogPtr = nbBits;
|
96
|
-
remaining = (1<<nbBits)+1;
|
97
|
-
threshold = 1<<nbBits;
|
98
|
-
nbBits++;
|
99
|
-
|
100
|
-
while ((remaining>1) & (charnum<=*maxSVPtr)) {
|
101
|
-
if (previous0) {
|
102
|
-
unsigned n0 = charnum;
|
103
|
-
while ((bitStream & 0xFFFF) == 0xFFFF) {
|
104
|
-
n0 += 24;
|
105
|
-
if (ip < iend-5) {
|
106
|
-
ip += 2;
|
107
|
-
bitStream = MEM_readLE32(ip) >> bitCount;
|
108
|
-
} else {
|
109
|
-
bitStream >>= 16;
|
110
|
-
bitCount += 16;
|
111
|
-
} }
|
112
|
-
while ((bitStream & 3) == 3) {
|
113
|
-
n0 += 3;
|
114
|
-
bitStream >>= 2;
|
115
|
-
bitCount += 2;
|
116
|
-
}
|
117
|
-
n0 += bitStream & 3;
|
118
|
-
bitCount += 2;
|
119
|
-
if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall);
|
120
|
-
while (charnum < n0) normalizedCounter[charnum++] = 0;
|
121
|
-
if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
122
|
-
assert((bitCount >> 3) <= 3); /* For first condition to work */
|
123
|
-
ip += bitCount>>3;
|
124
|
-
bitCount &= 7;
|
125
|
-
bitStream = MEM_readLE32(ip) >> bitCount;
|
126
|
-
} else {
|
127
|
-
bitStream >>= 2;
|
128
|
-
} }
|
129
|
-
{ int const max = (2*threshold-1) - remaining;
|
130
|
-
int count;
|
131
|
-
|
132
|
-
if ((bitStream & (threshold-1)) < (U32)max) {
|
133
|
-
count = bitStream & (threshold-1);
|
134
|
-
bitCount += nbBits-1;
|
135
|
-
} else {
|
136
|
-
count = bitStream & (2*threshold-1);
|
137
|
-
if (count >= threshold) count -= max;
|
138
|
-
bitCount += nbBits;
|
139
|
-
}
|
140
|
-
|
141
|
-
count--; /* extra accuracy */
|
142
|
-
remaining -= count < 0 ? -count : count; /* -1 means +1 */
|
143
|
-
normalizedCounter[charnum++] = (short)count;
|
144
|
-
previous0 = !count;
|
145
|
-
while (remaining < threshold) {
|
146
|
-
nbBits--;
|
147
|
-
threshold >>= 1;
|
148
|
-
}
|
149
|
-
|
150
|
-
if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
151
|
-
ip += bitCount>>3;
|
152
|
-
bitCount &= 7;
|
153
|
-
} else {
|
154
|
-
bitCount -= (int)(8 * (iend - 4 - ip));
|
155
|
-
ip = iend - 4;
|
156
|
-
}
|
157
|
-
bitStream = MEM_readLE32(ip) >> (bitCount & 31);
|
158
|
-
} } /* while ((remaining>1) & (charnum<=*maxSVPtr)) */
|
159
|
-
if (remaining != 1) return ERROR(corruption_detected);
|
160
|
-
if (bitCount > 32) return ERROR(corruption_detected);
|
161
|
-
*maxSVPtr = charnum-1;
|
162
|
-
|
163
|
-
ip += (bitCount+7)>>3;
|
164
|
-
return ip-istart;
|
165
|
-
}
|
166
|
-
|
167
|
-
|
168
|
-
/*! HUF_readStats() :
|
169
|
-
Read compact Huffman tree, saved by HUF_writeCTable().
|
170
|
-
`huffWeight` is destination buffer.
|
171
|
-
`rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
|
172
|
-
@return : size read from `src` , or an error Code .
|
173
|
-
Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
|
174
|
-
*/
|
175
|
-
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
176
|
-
U32* nbSymbolsPtr, U32* tableLogPtr,
|
177
|
-
const void* src, size_t srcSize)
|
178
|
-
{
|
179
|
-
U32 weightTotal;
|
180
|
-
const BYTE* ip = (const BYTE*) src;
|
181
|
-
size_t iSize;
|
182
|
-
size_t oSize;
|
183
|
-
|
184
|
-
if (!srcSize) return ERROR(srcSize_wrong);
|
185
|
-
iSize = ip[0];
|
186
|
-
/* memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
|
187
|
-
|
188
|
-
if (iSize >= 128) { /* special header */
|
189
|
-
oSize = iSize - 127;
|
190
|
-
iSize = ((oSize+1)/2);
|
191
|
-
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
192
|
-
if (oSize >= hwSize) return ERROR(corruption_detected);
|
193
|
-
ip += 1;
|
194
|
-
{ U32 n;
|
195
|
-
for (n=0; n<oSize; n+=2) {
|
196
|
-
huffWeight[n] = ip[n/2] >> 4;
|
197
|
-
huffWeight[n+1] = ip[n/2] & 15;
|
198
|
-
} } }
|
199
|
-
else { /* header compressed with FSE (normal case) */
|
200
|
-
FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
|
201
|
-
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
202
|
-
oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */
|
203
|
-
if (FSE_isError(oSize)) return oSize;
|
204
|
-
}
|
205
|
-
|
206
|
-
/* collect weight stats */
|
207
|
-
memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
|
208
|
-
weightTotal = 0;
|
209
|
-
{ U32 n; for (n=0; n<oSize; n++) {
|
210
|
-
if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
211
|
-
rankStats[huffWeight[n]]++;
|
212
|
-
weightTotal += (1 << huffWeight[n]) >> 1;
|
213
|
-
} }
|
214
|
-
if (weightTotal == 0) return ERROR(corruption_detected);
|
215
|
-
|
216
|
-
/* get last non-null symbol weight (implied, total must be 2^n) */
|
217
|
-
{ U32 const tableLog = BIT_highbit32(weightTotal) + 1;
|
218
|
-
if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
219
|
-
*tableLogPtr = tableLog;
|
220
|
-
/* determine last weight */
|
221
|
-
{ U32 const total = 1 << tableLog;
|
222
|
-
U32 const rest = total - weightTotal;
|
223
|
-
U32 const verif = 1 << BIT_highbit32(rest);
|
224
|
-
U32 const lastWeight = BIT_highbit32(rest) + 1;
|
225
|
-
if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
|
226
|
-
huffWeight[oSize] = (BYTE)lastWeight;
|
227
|
-
rankStats[lastWeight]++;
|
228
|
-
} }
|
229
|
-
|
230
|
-
/* check tree construction validity */
|
231
|
-
if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected); /* by construction : at least 2 elts of rank 1, must be even */
|
232
|
-
|
233
|
-
/* results */
|
234
|
-
*nbSymbolsPtr = (U32)(oSize+1);
|
235
|
-
return iSize+1;
|
236
|
-
}
|
@@ -1,76 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* This source code is licensed under both the BSD-style license (found in the
|
6
|
-
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
-
* in the COPYING file in the root directory of this source tree).
|
8
|
-
* You may select, at your option, one of the above-listed licenses.
|
9
|
-
*/
|
10
|
-
|
11
|
-
/* Note : this module is expected to remain private, do not expose it */
|
12
|
-
|
13
|
-
#ifndef ERROR_H_MODULE
|
14
|
-
#define ERROR_H_MODULE
|
15
|
-
|
16
|
-
#if defined (__cplusplus)
|
17
|
-
extern "C" {
|
18
|
-
#endif
|
19
|
-
|
20
|
-
|
21
|
-
/* ****************************************
|
22
|
-
* Dependencies
|
23
|
-
******************************************/
|
24
|
-
#include <stddef.h> /* size_t */
|
25
|
-
#include "zstd_errors.h" /* enum list */
|
26
|
-
|
27
|
-
|
28
|
-
/* ****************************************
|
29
|
-
* Compiler-specific
|
30
|
-
******************************************/
|
31
|
-
#if defined(__GNUC__)
|
32
|
-
# define ERR_STATIC static __attribute__((unused))
|
33
|
-
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
34
|
-
# define ERR_STATIC static inline
|
35
|
-
#elif defined(_MSC_VER)
|
36
|
-
# define ERR_STATIC static __inline
|
37
|
-
#else
|
38
|
-
# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
39
|
-
#endif
|
40
|
-
|
41
|
-
|
42
|
-
/*-****************************************
|
43
|
-
* Customization (error_public.h)
|
44
|
-
******************************************/
|
45
|
-
typedef ZSTD_ErrorCode ERR_enum;
|
46
|
-
#define PREFIX(name) ZSTD_error_##name
|
47
|
-
|
48
|
-
|
49
|
-
/*-****************************************
|
50
|
-
* Error codes handling
|
51
|
-
******************************************/
|
52
|
-
#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
|
53
|
-
#define ERROR(name) ZSTD_ERROR(name)
|
54
|
-
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
55
|
-
|
56
|
-
ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
|
57
|
-
|
58
|
-
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
|
59
|
-
|
60
|
-
|
61
|
-
/*-****************************************
|
62
|
-
* Error Strings
|
63
|
-
******************************************/
|
64
|
-
|
65
|
-
const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
|
66
|
-
|
67
|
-
ERR_STATIC const char* ERR_getErrorName(size_t code)
|
68
|
-
{
|
69
|
-
return ERR_getErrorString(ERR_getErrorCode(code));
|
70
|
-
}
|
71
|
-
|
72
|
-
#if defined (__cplusplus)
|
73
|
-
}
|
74
|
-
#endif
|
75
|
-
|
76
|
-
#endif /* ERROR_H_MODULE */
|