Skip to content

Commit a55bca0

Browse files
author
haruyama.makoto
committed
Update zstd to v1.3.5
1 parent f0ef07d commit a55bca0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3700
-1841
lines changed

ext/zstdruby/libzstd/Makefile

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,44 @@ DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
2828
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
2929
FLAGS = $(CPPFLAGS) $(CFLAGS)
3030

31-
32-
ZSTD_FILES := $(sort $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c))
31+
ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
32+
ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
33+
ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
34+
ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
35+
ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
36+
ZSTD_FILES := $(ZSTDCOMMON_FILES)
3337

3438
ZSTD_LEGACY_SUPPORT ?= 4
39+
ZSTD_LIB_COMPRESSION ?= 1
40+
ZSTD_LIB_DECOMPRESSION ?= 1
41+
ZSTD_LIB_DICTBUILDER ?= 1
42+
ZSTD_LIB_DEPRECATED ?= 1
43+
44+
ifeq ($(ZSTD_LIB_COMPRESSION), 0)
45+
ZSTD_LIB_DICTBUILDER = 0
46+
ZSTD_LIB_DEPRECATED = 0
47+
endif
48+
49+
ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
50+
ZSTD_LEGACY_SUPPORT = 0
51+
ZSTD_LIB_DEPRECATED = 0
52+
endif
53+
54+
ifneq ($(ZSTD_LIB_COMPRESSION), 0)
55+
ZSTD_FILES += $(ZSTDCOMP_FILES)
56+
endif
57+
58+
ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
59+
ZSTD_FILES += $(ZSTDDECOMP_FILES)
60+
endif
61+
62+
ifneq ($(ZSTD_LIB_DEPRECATED), 0)
63+
ZSTD_FILES += $(ZDEPR_FILES)
64+
endif
65+
66+
ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
67+
ZSTD_FILES += $(ZDICT_FILES)
68+
endif
3569

3670
ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
3771
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
@@ -43,7 +77,7 @@ CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
4377

4478
ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES))
4579

46-
# OS X linker doesn't support -soname, and use different extension
80+
# macOS linker doesn't support -soname, and use different extension
4781
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
4882
ifeq ($(shell uname), Darwin)
4983
SHARED_EXT = dylib
@@ -111,14 +145,14 @@ libzstd-nomt: $(ZSTD_NOMT_FILES)
111145
@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
112146

113147
clean:
114-
@$(RM) -r *.dSYM # Mac OS-X specific
148+
@$(RM) -r *.dSYM # macOS-specific
115149
@$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
116150
@$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
117151
@$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
118152
@echo Cleaning library completed
119153

120154
#-----------------------------------------------------------------------------
121-
# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
155+
# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
122156
#-----------------------------------------------------------------------------
123157
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
124158

@@ -134,7 +168,7 @@ LIBDIR ?= $(libdir)
134168
includedir ?= $(PREFIX)/include
135169
INCLUDEDIR ?= $(includedir)
136170

137-
ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly))
171+
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
138172
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
139173
else
140174
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
@@ -159,20 +193,32 @@ libzstd.pc: libzstd.pc.in
159193
-e 's|@VERSION@|$(VERSION)|' \
160194
$< >$@
161195

162-
install: libzstd.a libzstd libzstd.pc
163-
@$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/
196+
install: install-pc install-static install-shared install-includes
197+
@echo zstd static and shared library installed
198+
199+
install-pc: libzstd.pc
200+
@$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
164201
@$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
165-
@echo Installing libraries
202+
203+
install-static: libzstd.a
204+
@echo Installing static library
205+
@$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
166206
@$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
207+
208+
install-shared: libzstd
209+
@echo Installing shared library
210+
@$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
167211
@$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
168212
@ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
169213
@ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
214+
215+
install-includes:
170216
@echo Installing includes
217+
@$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
171218
@$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
172219
@$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
173220
@$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
174221
@$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
175-
@echo zstd static and shared library installed
176222

177223
uninstall:
178224
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a

ext/zstdruby/libzstd/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ It's possible to compile only a limited set of features.
6161
Each version also provides an additional dedicated set of advanced API.
6262
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
6363
Note : `lib/legacy` only supports _decoding_ legacy formats.
64+
- Similarly, you can define `ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
65+
and `ZSTD_LIB_DEPRECATED` as 0 to forgo compilation of the corresponding features. This will
66+
also disable compilation of all dependencies (eg. `ZSTD_LIB_COMPRESSION=0` will also disable
67+
dictBuilder).
6468

6569

6670
#### Multithreading support

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* ******************************************************************
22
bitstream
33
Part of FSE library
4-
header file (to include)
5-
Copyright (C) 2013-2017, Yann Collet.
4+
Copyright (C) 2013-present, Yann Collet.
65
76
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
87
@@ -49,21 +48,10 @@ extern "C" {
4948
* Dependencies
5049
******************************************/
5150
#include "mem.h" /* unaligned access routines */
51+
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
5252
#include "error_private.h" /* error codes and messages */
5353

5454

55-
/*-*************************************
56-
* Debug
57-
***************************************/
58-
#if defined(BIT_DEBUG) && (BIT_DEBUG>=1)
59-
# include <assert.h>
60-
#else
61-
# ifndef assert
62-
# define assert(condition) ((void)0)
63-
# endif
64-
#endif
65-
66-
6755
/*=========================================
6856
* Target specific
6957
=========================================*/
@@ -83,8 +71,7 @@ extern "C" {
8371
* A critical property of these streams is that they encode and decode in **reverse** direction.
8472
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
8573
*/
86-
typedef struct
87-
{
74+
typedef struct {
8875
size_t bitContainer;
8976
unsigned bitPos;
9077
char* startPtr;
@@ -118,8 +105,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
118105
/*-********************************************
119106
* bitStream decoding API (read backward)
120107
**********************************************/
121-
typedef struct
122-
{
108+
typedef struct {
123109
size_t bitContainer;
124110
unsigned bitsConsumed;
125111
const char* ptr;
@@ -236,7 +222,8 @@ MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
236222
}
237223

238224
/*! BIT_addBitsFast() :
239-
* works only if `value` is _clean_, meaning all high bits above nbBits are 0 */
225+
* works only if `value` is _clean_,
226+
* meaning all high bits above nbBits are 0 */
240227
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
241228
size_t value, unsigned nbBits)
242229
{

ext/zstdruby/libzstd/common/compiler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
7878
*/
7979
#ifndef DYNAMIC_BMI2
80-
#if (defined(__clang__) && __has_attribute(__target__)) \
80+
#if ((defined(__clang__) && __has_attribute(__target__)) \
8181
|| (defined(__GNUC__) \
82-
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) \
82+
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
8383
&& (defined(__x86_64__) || defined(_M_X86)) \
8484
&& !defined(__BMI2__)
8585
# define DYNAMIC_BMI2 1
@@ -92,7 +92,7 @@
9292
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
9393
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
9494
# define PREFETCH(ptr) _mm_prefetch((const char*)ptr, _MM_HINT_T0)
95-
#elif defined(__GNUC__)
95+
#elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
9696
# define PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0)
9797
#else
9898
# define PREFETCH(ptr) /* disabled */

ext/zstdruby/libzstd/common/cpu.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
7272
"cpuid\n\t"
7373
"popl %%ebx\n\t"
7474
: "=a"(f1a), "=c"(f1c), "=d"(f1d)
75-
: "a"(1)
76-
:);
75+
: "a"(1));
7776
}
7877
if (n >= 7) {
7978
__asm__(

ext/zstdruby/libzstd/common/debug.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ******************************************************************
2+
debug
3+
Part of FSE library
4+
Copyright (C) 2013-present, Yann Collet.
5+
6+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are
10+
met:
11+
12+
* Redistributions of source code must retain the above copyright
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
33+
****************************************************************** */
34+
35+
36+
/*
37+
* This module only hosts one global variable
38+
* which can be used to dynamically influence the verbosity of traces,
39+
* such as DEBUGLOG and RAWLOG
40+
*/
41+
42+
#include "debug.h"
43+
44+
int g_debuglevel = DEBUGLEVEL;

ext/zstdruby/libzstd/common/debug.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* ******************************************************************
2+
debug
3+
Part of FSE library
4+
Copyright (C) 2013-present, Yann Collet.
5+
6+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are
10+
met:
11+
12+
* Redistributions of source code must retain the above copyright
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
33+
****************************************************************** */
34+
35+
36+
/*
37+
* The purpose of this header is to enable debug functions.
38+
* They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
39+
* and DEBUG_STATIC_ASSERT() for compile-time.
40+
*
41+
* By default, DEBUGLEVEL==0, which means run-time debug is disabled.
42+
*
43+
* Level 1 enables assert() only.
44+
* Starting level 2, traces can be generated and pushed to stderr.
45+
* The higher the level, the more verbose the traces.
46+
*
47+
* It's possible to dynamically adjust level using variable g_debug_level,
48+
* which is only declared if DEBUGLEVEL>=2,
49+
* and is a global variable, not multi-thread protected (use with care)
50+
*/
51+
52+
#ifndef DEBUG_H_12987983217
53+
#define DEBUG_H_12987983217
54+
55+
#if defined (__cplusplus)
56+
extern "C" {
57+
#endif
58+
59+
60+
/* static assert is triggered at compile time, leaving no runtime artefact,
61+
* but can only work with compile-time constants.
62+
* This variant can only be used inside a function. */
63+
#define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
64+
65+
66+
/* DEBUGLEVEL is expected to be defined externally,
67+
* typically through compiler command line.
68+
* Value must be a number. */
69+
#ifndef DEBUGLEVEL
70+
# define DEBUGLEVEL 0
71+
#endif
72+
73+
/* recommended values for DEBUGLEVEL :
74+
* 0 : no debug, all run-time functions disabled
75+
* 1 : no display, enables assert() only
76+
* 2 : reserved, for currently active debug path
77+
* 3 : events once per object lifetime (CCtx, CDict, etc.)
78+
* 4 : events once per frame
79+
* 5 : events once per block
80+
* 6 : events once per sequence (verbose)
81+
* 7+: events at every position (*very* verbose)
82+
*
83+
* It's generally inconvenient to output traces > 5.
84+
* In which case, it's possible to selectively enable higher verbosity levels
85+
* by modifying g_debug_level.
86+
*/
87+
88+
#if (DEBUGLEVEL>=1)
89+
# include <assert.h>
90+
#else
91+
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
92+
# define assert(condition) ((void)0) /* disable assert (default) */
93+
# endif
94+
#endif
95+
96+
#if (DEBUGLEVEL>=2)
97+
# include <stdio.h>
98+
extern int g_debuglevel; /* here, this variable is only declared,
99+
it actually lives in debug.c,
100+
and is shared by the whole process.
101+
It's typically used to enable very verbose levels
102+
on selective conditions (such as position in src) */
103+
104+
# define RAWLOG(l, ...) { \
105+
if (l<=g_debuglevel) { \
106+
fprintf(stderr, __VA_ARGS__); \
107+
} }
108+
# define DEBUGLOG(l, ...) { \
109+
if (l<=g_debuglevel) { \
110+
fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
111+
fprintf(stderr, " \n"); \
112+
} }
113+
#else
114+
# define RAWLOG(l, ...) {} /* disabled */
115+
# define DEBUGLOG(l, ...) {} /* disabled */
116+
#endif
117+
118+
119+
#if defined (__cplusplus)
120+
}
121+
#endif
122+
123+
#endif /* DEBUG_H_12987983217 */

0 commit comments

Comments
 (0)