zstd-ruby 1.1.3.0 → 1.1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/zstdruby/libzstd/Makefile +9 -6
  4. data/ext/zstdruby/libzstd/common/bitstream.h +3 -0
  5. data/ext/zstdruby/libzstd/common/entropy_common.c +13 -19
  6. data/ext/zstdruby/libzstd/common/fse.h +48 -22
  7. data/ext/zstdruby/libzstd/common/fse_decompress.c +0 -1
  8. data/ext/zstdruby/libzstd/common/huf.h +27 -5
  9. data/ext/zstdruby/libzstd/common/mem.h +14 -12
  10. data/ext/zstdruby/libzstd/common/threading.c +5 -4
  11. data/ext/zstdruby/libzstd/common/threading.h +1 -1
  12. data/ext/zstdruby/libzstd/common/xxhash.c +3 -1
  13. data/ext/zstdruby/libzstd/common/xxhash.h +11 -15
  14. data/ext/zstdruby/libzstd/common/zstd_common.c +1 -1
  15. data/ext/zstdruby/libzstd/common/zstd_internal.h +4 -0
  16. data/ext/zstdruby/libzstd/compress/fse_compress.c +16 -9
  17. data/ext/zstdruby/libzstd/compress/huf_compress.c +103 -28
  18. data/ext/zstdruby/libzstd/compress/zstd_compress.c +90 -37
  19. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  20. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +7 -8
  21. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +20 -17
  22. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +429 -120
  23. data/ext/zstdruby/libzstd/deprecated/zbuff.h +3 -1
  24. data/ext/zstdruby/libzstd/dictBuilder/cover.c +16 -8
  25. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +1 -1
  26. data/ext/zstdruby/libzstd/dll/example/build_package.bat +1 -0
  27. data/ext/zstdruby/libzstd/dll/libzstd.def +2 -0
  28. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +122 -7
  29. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +31 -0
  30. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +8 -0
  31. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +37 -0
  32. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +8 -0
  33. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +37 -0
  34. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +8 -0
  35. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +33 -0
  36. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +8 -0
  37. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +29 -0
  38. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +7 -0
  39. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +32 -1
  40. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +7 -0
  41. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +44 -6
  42. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +8 -0
  43. data/ext/zstdruby/libzstd/zstd.h +87 -13
  44. data/lib/zstd-ruby/version.rb +1 -1
  45. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 477faa534daab9e4b42a615f87b29a6ef16676b9
4
- data.tar.gz: 3ad80717437d8b90e07b3c6c55762fa248a38a14
3
+ metadata.gz: d2610367f572e8865e7d21cc0ae3d2862f197aee
4
+ data.tar.gz: a698813faf919578970b8deb156c81e51d4045b9
5
5
  SHA512:
6
- metadata.gz: c35693a0ffc216560e455cc78f5659797b4baefe685e8efe2ff0e37b712543914673fa31879261c3ba8b62a7b2c3589efe75512162c91e5b095ee75bb6f99d26
7
- data.tar.gz: 086228081f38a4eabe4de8979fb07c61964e62e233c0233e15872d43deea534d98fa2ab7ef3022703984e3be8dc16b694211edd1b0beb231a8f8a12f6553e6fd
6
+ metadata.gz: 6d742c4cf0fb3d0aae716a096317ddfa36ee933a10cc28111781b1897083d8ba9129f96518f8122e398be3137a73d0b3741f9fd289b6d9c824483439c6473614
7
+ data.tar.gz: 835e4c344677e64c979be1a5f4c2cbd50aac95f29d214e3f23c84520d549f1e213d7a395a94e7a4bd8e0bdc8c3b3823167985c39e8ba566b3029cf3a425c4d0c
data/README.md CHANGED
@@ -9,7 +9,7 @@ See https://github.com/facebook/zstd
9
9
  Fork from https://github.com/jarredholman/ruby-zstd.
10
10
 
11
11
  ## Zstd version
12
- v1.1.3 (https://github.com/facebook/zstd/releases/tag/v1.1.3)
12
+ v1.1.4 (https://github.com/facebook/zstd/releases/tag/v1.1.4)
13
13
 
14
14
  ## Installation
15
15
 
@@ -24,19 +24,22 @@ CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
24
24
  CFLAGS ?= -O3
25
25
  DEBUGFLAGS = -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
26
26
  -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
27
- -Wstrict-prototypes -Wundef -Wpointer-arith
27
+ -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security
28
28
  CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
29
29
  FLAGS = $(CPPFLAGS) $(CFLAGS)
30
30
 
31
31
 
32
32
  ZSTD_FILES := $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)
33
33
 
34
- ifeq ($(ZSTD_LEGACY_SUPPORT), 0)
35
- CPPFLAGS += -DZSTD_LEGACY_SUPPORT=0
36
- else
37
- CPPFLAGS += -I./legacy -DZSTD_LEGACY_SUPPORT=1
38
- ZSTD_FILES+= $(wildcard legacy/*.c)
34
+ ZSTD_LEGACY_SUPPORT ?= 4
35
+
36
+ ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
37
+ ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
38
+ ZSTD_FILES += $(shell ls legacy/*.c | grep 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
39
+ endif
40
+ CPPFLAGS += -I./legacy
39
41
  endif
42
+ CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
40
43
 
41
44
  ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES))
42
45
 
@@ -60,6 +60,9 @@ extern "C" {
60
60
  # include <immintrin.h> /* support for bextr (experimental) */
61
61
  #endif
62
62
 
63
+ #define STREAM_ACCUMULATOR_MIN_32 25
64
+ #define STREAM_ACCUMULATOR_MIN_64 57
65
+ #define STREAM_ACCUMULATOR_MIN ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))
63
66
 
64
67
  /*-******************************************
65
68
  * bitStream encoding API (write forward)
@@ -43,27 +43,21 @@
43
43
  #include "huf.h"
44
44
 
45
45
 
46
- /*-****************************************
47
- * FSE Error Management
48
- ******************************************/
49
- unsigned FSE_isError(size_t code) { return ERR_isError(code); }
46
+ /*=== Version ===*/
47
+ unsigned FSE_versionNumber(void) { return FSE_VERSION_NUMBER; }
50
48
 
51
- const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); }
52
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
53
 
54
- /* **************************************************************
55
- * HUF Error Management
56
- ****************************************************************/
57
54
  unsigned HUF_isError(size_t code) { return ERR_isError(code); }
58
-
59
55
  const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
60
56
 
61
57
 
62
58
  /*-**************************************************************
63
59
  * FSE NCount encoding-decoding
64
60
  ****************************************************************/
65
- static short FSE_abs(short a) { return (short)(a<0 ? -a : a); }
66
-
67
61
  size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
68
62
  const void* headerBuffer, size_t hbSize)
69
63
  {
@@ -117,21 +111,21 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
117
111
  } else {
118
112
  bitStream >>= 2;
119
113
  } }
120
- { short const max = (short)((2*threshold-1)-remaining);
121
- short count;
114
+ { int const max = (2*threshold-1) - remaining;
115
+ int count;
122
116
 
123
117
  if ((bitStream & (threshold-1)) < (U32)max) {
124
- count = (short)(bitStream & (threshold-1));
125
- bitCount += nbBits-1;
118
+ count = bitStream & (threshold-1);
119
+ bitCount += nbBits-1;
126
120
  } else {
127
- count = (short)(bitStream & (2*threshold-1));
121
+ count = bitStream & (2*threshold-1);
128
122
  if (count >= threshold) count -= max;
129
- bitCount += nbBits;
123
+ bitCount += nbBits;
130
124
  }
131
125
 
132
126
  count--; /* extra accuracy */
133
- remaining -= FSE_abs(count);
134
- normalizedCounter[charnum++] = count;
127
+ remaining -= count < 0 ? -count : count; /* -1 means +1 */
128
+ normalizedCounter[charnum++] = (short)count;
135
129
  previous0 = !count;
136
130
  while (remaining < threshold) {
137
131
  nbBits--;
@@ -45,6 +45,32 @@ extern "C" {
45
45
  #include <stddef.h> /* size_t, ptrdiff_t */
46
46
 
47
47
 
48
+ /*-*****************************************
49
+ * FSE_PUBLIC_API : control library symbols visibility
50
+ ******************************************/
51
+ #if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4)
52
+ # define FSE_PUBLIC_API __attribute__ ((visibility ("default")))
53
+ #elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */
54
+ # define FSE_PUBLIC_API __declspec(dllexport)
55
+ #elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1)
56
+ # define FSE_PUBLIC_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
57
+ #else
58
+ # define FSE_PUBLIC_API
59
+ #endif
60
+
61
+ /*------ Version ------*/
62
+ #define FSE_VERSION_MAJOR 0
63
+ #define FSE_VERSION_MINOR 9
64
+ #define FSE_VERSION_RELEASE 0
65
+
66
+ #define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE
67
+ #define FSE_QUOTE(str) #str
68
+ #define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str)
69
+ #define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION)
70
+
71
+ #define FSE_VERSION_NUMBER (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE)
72
+ FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */
73
+
48
74
  /*-****************************************
49
75
  * FSE simple functions
50
76
  ******************************************/
@@ -56,8 +82,8 @@ extern "C" {
56
82
  if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead.
57
83
  if FSE_isError(return), compression failed (more details using FSE_getErrorName())
58
84
  */
59
- size_t FSE_compress(void* dst, size_t dstCapacity,
60
- const void* src, size_t srcSize);
85
+ FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity,
86
+ const void* src, size_t srcSize);
61
87
 
62
88
  /*! FSE_decompress():
63
89
  Decompress FSE data from buffer 'cSrc', of size 'cSrcSize',
@@ -69,18 +95,18 @@ size_t FSE_compress(void* dst, size_t dstCapacity,
69
95
  Why ? : making this distinction requires a header.
70
96
  Header management is intentionally delegated to the user layer, which can better manage special cases.
71
97
  */
72
- size_t FSE_decompress(void* dst, size_t dstCapacity,
73
- const void* cSrc, size_t cSrcSize);
98
+ FSE_PUBLIC_API size_t FSE_decompress(void* dst, size_t dstCapacity,
99
+ const void* cSrc, size_t cSrcSize);
74
100
 
75
101
 
76
102
  /*-*****************************************
77
103
  * Tool functions
78
104
  ******************************************/
79
- size_t FSE_compressBound(size_t size); /* maximum compressed size */
105
+ FSE_PUBLIC_API size_t FSE_compressBound(size_t size); /* maximum compressed size */
80
106
 
81
107
  /* Error Management */
82
- unsigned FSE_isError(size_t code); /* tells if a return value is an error code */
83
- const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */
108
+ FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return value is an error code */
109
+ FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */
84
110
 
85
111
 
86
112
  /*-*****************************************
@@ -94,7 +120,7 @@ const char* FSE_getErrorName(size_t code); /* provides error code string (usef
94
120
  if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression.
95
121
  if FSE_isError(return), it's an error code.
96
122
  */
97
- size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
123
+ FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
98
124
 
99
125
 
100
126
  /*-*****************************************
@@ -127,50 +153,50 @@ or to save and provide normalized distribution using external method.
127
153
  @return : the count of the most frequent symbol (which is not identified).
128
154
  if return == srcSize, there is only one symbol.
129
155
  Can also return an error code, which can be tested with FSE_isError(). */
130
- size_t FSE_count(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
156
+ FSE_PUBLIC_API size_t FSE_count(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
131
157
 
132
158
  /*! FSE_optimalTableLog():
133
159
  dynamically downsize 'tableLog' when conditions are met.
134
160
  It saves CPU time, by using smaller tables, while preserving or even improving compression ratio.
135
161
  @return : recommended tableLog (necessarily <= 'maxTableLog') */
136
- unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
162
+ FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
137
163
 
138
164
  /*! FSE_normalizeCount():
139
165
  normalize counts so that sum(count[]) == Power_of_2 (2^tableLog)
140
166
  'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1).
141
167
  @return : tableLog,
142
168
  or an errorCode, which can be tested using FSE_isError() */
143
- size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog, const unsigned* count, size_t srcSize, unsigned maxSymbolValue);
169
+ FSE_PUBLIC_API size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog, const unsigned* count, size_t srcSize, unsigned maxSymbolValue);
144
170
 
145
171
  /*! FSE_NCountWriteBound():
146
172
  Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'.
147
173
  Typically useful for allocation purpose. */
148
- size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog);
174
+ FSE_PUBLIC_API size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog);
149
175
 
150
176
  /*! FSE_writeNCount():
151
177
  Compactly save 'normalizedCounter' into 'buffer'.
152
178
  @return : size of the compressed table,
153
179
  or an errorCode, which can be tested using FSE_isError(). */
154
- size_t FSE_writeNCount (void* buffer, size_t bufferSize, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
180
+ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
155
181
 
156
182
 
157
183
  /*! Constructor and Destructor of FSE_CTable.
158
184
  Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
159
185
  typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
160
- FSE_CTable* FSE_createCTable (unsigned tableLog, unsigned maxSymbolValue);
161
- void FSE_freeCTable (FSE_CTable* ct);
186
+ FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned tableLog, unsigned maxSymbolValue);
187
+ FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct);
162
188
 
163
189
  /*! FSE_buildCTable():
164
190
  Builds `ct`, which must be already allocated, using FSE_createCTable().
165
191
  @return : 0, or an errorCode, which can be tested using FSE_isError() */
166
- size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
192
+ FSE_PUBLIC_API size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
167
193
 
168
194
  /*! FSE_compress_usingCTable():
169
195
  Compress `src` using `ct` into `dst` which must be already allocated.
170
196
  @return : size of compressed data (<= `dstCapacity`),
171
197
  or 0 if compressed data could not fit into `dst`,
172
198
  or an errorCode, which can be tested using FSE_isError() */
173
- size_t FSE_compress_usingCTable (void* dst, size_t dstCapacity, const void* src, size_t srcSize, const FSE_CTable* ct);
199
+ FSE_PUBLIC_API size_t FSE_compress_usingCTable (void* dst, size_t dstCapacity, const void* src, size_t srcSize, const FSE_CTable* ct);
174
200
 
175
201
  /*!
176
202
  Tutorial :
@@ -223,25 +249,25 @@ If there is an error, the function will return an ErrorCode (which can be tested
223
249
  @return : size read from 'rBuffer',
224
250
  or an errorCode, which can be tested using FSE_isError().
225
251
  maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */
226
- size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSymbolValuePtr, unsigned* tableLogPtr, const void* rBuffer, size_t rBuffSize);
252
+ FSE_PUBLIC_API size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSymbolValuePtr, unsigned* tableLogPtr, const void* rBuffer, size_t rBuffSize);
227
253
 
228
254
  /*! Constructor and Destructor of FSE_DTable.
229
255
  Note that its size depends on 'tableLog' */
230
256
  typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */
231
- FSE_DTable* FSE_createDTable(unsigned tableLog);
232
- void FSE_freeDTable(FSE_DTable* dt);
257
+ FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog);
258
+ FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable* dt);
233
259
 
234
260
  /*! FSE_buildDTable():
235
261
  Builds 'dt', which must be already allocated, using FSE_createDTable().
236
262
  return : 0, or an errorCode, which can be tested using FSE_isError() */
237
- size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
263
+ FSE_PUBLIC_API size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
238
264
 
239
265
  /*! FSE_decompress_usingDTable():
240
266
  Decompress compressed source `cSrc` of size `cSrcSize` using `dt`
241
267
  into `dst` which must be already allocated.
242
268
  @return : size of regenerated data (necessarily <= `dstCapacity`),
243
269
  or an errorCode, which can be tested using FSE_isError() */
244
- size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt);
270
+ FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt);
245
271
 
246
272
  /*!
247
273
  Tutorial :
@@ -59,7 +59,6 @@
59
59
  ****************************************************************/
60
60
  #include <stdlib.h> /* malloc, free, qsort */
61
61
  #include <string.h> /* memcpy, memset */
62
- #include <stdio.h> /* printf (debug) */
63
62
  #include "bitstream.h"
64
63
  #define FSE_STATIC_LINKING_ONLY
65
64
  #include "fse.h"
@@ -91,7 +91,7 @@ size_t HUF_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize
91
91
 
92
92
  /** HUF_compress4X_wksp() :
93
93
  * Same as HUF_compress2(), but uses externally allocated `workSpace`, which must be a table of >= 1024 unsigned */
94
- size_t HUF_compress4X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least 1024 unsigned */
94
+ size_t HUF_compress4X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
95
95
 
96
96
 
97
97
 
@@ -102,10 +102,11 @@ size_t HUF_compress4X_wksp (void* dst, size_t dstSize, const void* src, size_t s
102
102
 
103
103
 
104
104
  /* *** Constants *** */
105
- #define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
106
- #define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
105
+ #define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
107
106
  #define HUF_TABLELOG_DEFAULT 11 /* tableLog by default, when not specified */
108
- #define HUF_SYMBOLVALUE_MAX 255
107
+ #define HUF_SYMBOLVALUE_MAX 255
108
+
109
+ #define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
109
110
  #if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
110
111
  # error "HUF_TABLELOG_MAX is too large !"
111
112
  #endif
@@ -133,6 +134,10 @@ typedef U32 HUF_DTable;
133
134
  #define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \
134
135
  HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) }
135
136
 
137
+ /* The workspace must have alignment at least 4 and be at least this large */
138
+ #define HUF_WORKSPACE_SIZE (6 << 10)
139
+ #define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
140
+
136
141
 
137
142
  /* ****************************************
138
143
  * Advanced decompression functions
@@ -168,6 +173,17 @@ size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSym
168
173
  size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
169
174
  size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
170
175
 
176
+ typedef enum {
177
+ HUF_repeat_none, /**< Cannot use the previous table */
178
+ HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */
179
+ HUF_repeat_valid /**< Can use the previous table and it is asumed to be valid */
180
+ } HUF_repeat;
181
+ /** HUF_compress4X_repeat() :
182
+ * Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
183
+ * If it uses hufTable it does not modify hufTable or repeat.
184
+ * If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
185
+ * If preferRepeat then the old table will always be used if valid. */
186
+ size_t HUF_compress4X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
171
187
 
172
188
  /** HUF_buildCTable_wksp() :
173
189
  * Same as HUF_buildCTable(), but using externally allocated scratch buffer.
@@ -214,8 +230,14 @@ size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const void* c
214
230
  /* single stream variants */
215
231
 
216
232
  size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
217
- size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least 1024 unsigned */
233
+ size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
218
234
  size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
235
+ /** HUF_compress1X_repeat() :
236
+ * Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
237
+ * If it uses hufTable it does not modify hufTable or repeat.
238
+ * If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
239
+ * If preferRepeat then the old table will always be used if valid. */
240
+ size_t HUF_compress1X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
219
241
 
220
242
  size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
221
243
  size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
@@ -48,14 +48,15 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
48
48
  *****************************************************************/
49
49
  #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
50
50
  # include <stdint.h>
51
- typedef uint8_t BYTE;
52
- typedef uint16_t U16;
53
- typedef int16_t S16;
54
- typedef uint32_t U32;
55
- typedef int32_t S32;
56
- typedef uint64_t U64;
57
- typedef int64_t S64;
58
- typedef intptr_t iPtrDiff;
51
+ typedef uint8_t BYTE;
52
+ typedef uint16_t U16;
53
+ typedef int16_t S16;
54
+ typedef uint32_t U32;
55
+ typedef int32_t S32;
56
+ typedef uint64_t U64;
57
+ typedef int64_t S64;
58
+ typedef intptr_t iPtrDiff;
59
+ typedef uintptr_t uPtrDiff;
59
60
  #else
60
61
  typedef unsigned char BYTE;
61
62
  typedef unsigned short U16;
@@ -65,6 +66,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
65
66
  typedef unsigned long long U64;
66
67
  typedef signed long long S64;
67
68
  typedef ptrdiff_t iPtrDiff;
69
+ typedef size_t uPtrDiff;
68
70
  #endif
69
71
 
70
72
 
@@ -76,11 +78,11 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
76
78
  * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
77
79
  * The below switch allow to select different access method for improved performance.
78
80
  * Method 0 (default) : use `memcpy()`. Safe and portable.
79
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
81
+ * Method 1 : `__packed` statement. It depends on compiler extension (i.e., not portable).
80
82
  * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
81
83
  * Method 2 : direct access. This method is portable but violate C standard.
82
84
  * It can generate buggy code on targets depending on alignment.
83
- * In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
85
+ * In some circumstances, it's the only known way to get the most performance (i.e. GCC + ARMv6)
84
86
  * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
85
87
  * Prefer these methods in priority order (0 > 1 > 2)
86
88
  */
@@ -182,7 +184,7 @@ MEM_STATIC U32 MEM_swap32(U32 in)
182
184
  {
183
185
  #if defined(_MSC_VER) /* Visual Studio */
184
186
  return _byteswap_ulong(in);
185
- #elif defined (__GNUC__)
187
+ #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
186
188
  return __builtin_bswap32(in);
187
189
  #else
188
190
  return ((in << 24) & 0xff000000 ) |
@@ -196,7 +198,7 @@ MEM_STATIC U64 MEM_swap64(U64 in)
196
198
  {
197
199
  #if defined(_MSC_VER) /* Visual Studio */
198
200
  return _byteswap_uint64(in);
199
- #elif defined (__GNUC__)
201
+ #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
200
202
  return __builtin_bswap64(in);
201
203
  #else
202
204
  return ((in << 56) & 0xff00000000000000ULL) |
@@ -15,10 +15,11 @@
15
15
  * This file will hold wrapper for systems, which do not support pthreads
16
16
  */
17
17
 
18
- /* ====== Compiler specifics ====== */
19
- #if defined(_MSC_VER)
20
- # pragma warning(disable : 4206) /* disable: C4206: translation unit is empty (when ZSTD_MULTITHREAD is not defined) */
21
- #endif
18
+ /* When ZSTD_MULTITHREAD is not defined, this file would become an empty translation unit.
19
+ * Include some ISO C header code to prevent this and portably avoid related warnings.
20
+ * (Visual C++: C4206 / GCC: -Wpedantic / Clang: -Wempty-translation-unit)
21
+ */
22
+ #include <stddef.h>
22
23
 
23
24
 
24
25
  #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
@@ -73,7 +73,7 @@ int _pthread_join(pthread_t* thread, void** value_ptr);
73
73
  */
74
74
 
75
75
 
76
- #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection mathod */
76
+ #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
77
77
  /* === POSIX Systems === */
78
78
  # include <pthread.h>
79
79
 
@@ -104,7 +104,9 @@ static void XXH_free (void* p) { free(p); }
104
104
  #include <string.h>
105
105
  static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
106
106
 
107
- #define XXH_STATIC_LINKING_ONLY
107
+ #ifndef XXH_STATIC_LINKING_ONLY
108
+ # define XXH_STATIC_LINKING_ONLY
109
+ #endif
108
110
  #include "xxhash.h"
109
111
 
110
112
 
@@ -64,16 +64,12 @@ XXH64 13.8 GB/s 1.9 GB/s
64
64
  XXH32 6.8 GB/s 6.0 GB/s
65
65
  */
66
66
 
67
- #ifndef XXHASH_H_5627135585666179
68
- #define XXHASH_H_5627135585666179 1
69
-
70
67
  #if defined (__cplusplus)
71
68
  extern "C" {
72
69
  #endif
73
70
 
74
- #ifndef XXH_NAMESPACE
75
- # define XXH_NAMESPACE ZSTD_ /* Zstandard specific */
76
- #endif
71
+ #ifndef XXHASH_H_5627135585666179
72
+ #define XXHASH_H_5627135585666179 1
77
73
 
78
74
 
79
75
  /* ****************************
@@ -242,6 +238,11 @@ XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH
242
238
  /* **************************
243
239
  * Canonical representation
244
240
  ****************************/
241
+ /* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
242
+ * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
243
+ * These functions allow transformation of hash result into and from its canonical format.
244
+ * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
245
+ */
245
246
  typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
246
247
  typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
247
248
 
@@ -251,14 +252,9 @@ XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t
251
252
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
252
253
  XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
253
254
 
254
- /* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
255
- * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
256
- * These functions allow transformation of hash result into and from its canonical format.
257
- * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
258
- */
255
+ #endif /* XXHASH_H_5627135585666179 */
259
256
 
260
257
 
261
- #ifdef XXH_STATIC_LINKING_ONLY
262
258
 
263
259
  /* ================================================================================================
264
260
  This section contains definitions which are not guaranteed to remain stable.
@@ -266,6 +262,8 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
266
262
  They shall only be used with static linking.
267
263
  Never use these definitions in association with dynamic linking !
268
264
  =================================================================================================== */
265
+ #if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXH_STATIC_H_3543687687345)
266
+ #define XXH_STATIC_H_3543687687345
269
267
 
270
268
  /* These definitions are only meant to allow allocation of XXH state
271
269
  statically, on stack, or in a struct for example.
@@ -299,11 +297,9 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
299
297
  # include "xxhash.c" /* include xxhash functions as `static`, for inlining */
300
298
  # endif
301
299
 
302
- #endif /* XXH_STATIC_LINKING_ONLY */
300
+ #endif /* XXH_STATIC_LINKING_ONLY && XXH_STATIC_H_3543687687345 */
303
301
 
304
302
 
305
303
  #if defined (__cplusplus)
306
304
  }
307
305
  #endif
308
-
309
- #endif /* XXHASH_H_5627135585666179 */
@@ -41,7 +41,7 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
41
41
 
42
42
  /*! ZSTD_getErrorString() :
43
43
  * provides error code string from enum */
44
- const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
44
+ const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
45
45
 
46
46
 
47
47
  /*=**************************************************************
@@ -49,6 +49,10 @@
49
49
  #include "error_private.h"
50
50
  #define ZSTD_STATIC_LINKING_ONLY
51
51
  #include "zstd.h"
52
+ #ifndef XXH_STATIC_LINKING_ONLY
53
+ # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
54
+ #endif
55
+ #include "xxhash.h" /* XXH_reset, update, digest */
52
56
 
53
57
 
54
58
  /*-*************************************
@@ -201,8 +201,6 @@ size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
201
201
  return maxSymbolValue ? maxHeaderSize : FSE_NCOUNTBOUND; /* maxSymbolValue==0 ? use default */
202
202
  }
203
203
 
204
- static short FSE_abs(short a) { return (short)(a<0 ? -a : a); }
205
-
206
204
  static size_t FSE_writeNCount_generic (void* header, size_t headerBufferSize,
207
205
  const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog,
208
206
  unsigned writeIsSafe)
@@ -258,16 +256,16 @@ static size_t FSE_writeNCount_generic (void* header, size_t headerBufferSize,
258
256
  bitStream >>= 16;
259
257
  bitCount -= 16;
260
258
  } }
261
- { short count = normalizedCounter[charnum++];
262
- const short max = (short)((2*threshold-1)-remaining);
263
- remaining -= FSE_abs(count);
264
- if (remaining<1) return ERROR(GENERIC);
259
+ { int count = normalizedCounter[charnum++];
260
+ int const max = (2*threshold-1)-remaining;
261
+ remaining -= count < 0 ? -count : count;
265
262
  count++; /* +1 for extra accuracy */
266
263
  if (count>=threshold) count += max; /* [0..max[ [max..threshold[ (...) [threshold+max 2*threshold[ */
267
264
  bitStream += count << bitCount;
268
265
  bitCount += nbBits;
269
266
  bitCount -= (count<max);
270
267
  previous0 = (count==1);
268
+ if (remaining<1) return ERROR(GENERIC);
271
269
  while (remaining<threshold) nbBits--, threshold>>=1;
272
270
  }
273
271
  if (bitCount>16) {
@@ -508,6 +506,7 @@ unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
508
506
 
509
507
  static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 maxSymbolValue)
510
508
  {
509
+ short const NOT_YET_ASSIGNED = -2;
511
510
  U32 s;
512
511
  U32 distributed = 0;
513
512
  U32 ToDistribute;
@@ -533,7 +532,8 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
533
532
  total -= count[s];
534
533
  continue;
535
534
  }
536
- norm[s]=-2;
535
+
536
+ norm[s]=NOT_YET_ASSIGNED;
537
537
  }
538
538
  ToDistribute = (1 << tableLog) - distributed;
539
539
 
@@ -541,7 +541,7 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
541
541
  /* risk of rounding to zero */
542
542
  lowOne = (U32)((total * 3) / (ToDistribute * 2));
543
543
  for (s=0; s<=maxSymbolValue; s++) {
544
- if ((norm[s] == -2) && (count[s] <= lowOne)) {
544
+ if ((norm[s] == NOT_YET_ASSIGNED) && (count[s] <= lowOne)) {
545
545
  norm[s] = 1;
546
546
  distributed++;
547
547
  total -= count[s];
@@ -561,12 +561,19 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
561
561
  return 0;
562
562
  }
563
563
 
564
+ if (total == 0) {
565
+ /* all of the symbols were low enough for the lowOne or lowThreshold */
566
+ for (s=0; ToDistribute > 0; s = (s+1)%(maxSymbolValue+1))
567
+ if (norm[s] > 0) ToDistribute--, norm[s]++;
568
+ return 0;
569
+ }
570
+
564
571
  { U64 const vStepLog = 62 - tableLog;
565
572
  U64 const mid = (1ULL << (vStepLog-1)) - 1;
566
573
  U64 const rStep = ((((U64)1<<vStepLog) * ToDistribute) + mid) / total; /* scale on remaining */
567
574
  U64 tmpTotal = mid;
568
575
  for (s=0; s<=maxSymbolValue; s++) {
569
- if (norm[s]==-2) {
576
+ if (norm[s]==NOT_YET_ASSIGNED) {
570
577
  U64 const end = tmpTotal + (count[s] * rStep);
571
578
  U32 const sStart = (U32)(tmpTotal >> vStepLog);
572
579
  U32 const sEnd = (U32)(end >> vStepLog);