extzstd 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/contrib/zstd/CHANGELOG +188 -1
  4. data/contrib/zstd/CONTRIBUTING.md +157 -74
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +81 -58
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +59 -35
  9. data/contrib/zstd/TESTING.md +2 -3
  10. data/contrib/zstd/appveyor.yml +49 -136
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +87 -181
  13. data/contrib/zstd/lib/README.md +23 -6
  14. data/contrib/zstd/lib/common/allocations.h +55 -0
  15. data/contrib/zstd/lib/common/bits.h +200 -0
  16. data/contrib/zstd/lib/common/bitstream.h +33 -59
  17. data/contrib/zstd/lib/common/compiler.h +115 -45
  18. data/contrib/zstd/lib/common/cpu.h +1 -1
  19. data/contrib/zstd/lib/common/debug.c +1 -1
  20. data/contrib/zstd/lib/common/debug.h +1 -1
  21. data/contrib/zstd/lib/common/entropy_common.c +15 -37
  22. data/contrib/zstd/lib/common/error_private.c +9 -2
  23. data/contrib/zstd/lib/common/error_private.h +82 -3
  24. data/contrib/zstd/lib/common/fse.h +9 -85
  25. data/contrib/zstd/lib/common/fse_decompress.c +29 -111
  26. data/contrib/zstd/lib/common/huf.h +84 -172
  27. data/contrib/zstd/lib/common/mem.h +58 -49
  28. data/contrib/zstd/lib/common/pool.c +37 -16
  29. data/contrib/zstd/lib/common/pool.h +9 -3
  30. data/contrib/zstd/lib/common/portability_macros.h +156 -0
  31. data/contrib/zstd/lib/common/threading.c +68 -14
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +7 -809
  34. data/contrib/zstd/lib/common/xxhash.h +5568 -167
  35. data/contrib/zstd/lib/common/zstd_common.c +1 -36
  36. data/contrib/zstd/lib/common/zstd_deps.h +1 -1
  37. data/contrib/zstd/lib/common/zstd_internal.h +64 -150
  38. data/contrib/zstd/lib/common/zstd_trace.h +163 -0
  39. data/contrib/zstd/lib/compress/clevels.h +134 -0
  40. data/contrib/zstd/lib/compress/fse_compress.c +69 -150
  41. data/contrib/zstd/lib/compress/hist.c +1 -1
  42. data/contrib/zstd/lib/compress/hist.h +1 -1
  43. data/contrib/zstd/lib/compress/huf_compress.c +773 -251
  44. data/contrib/zstd/lib/compress/zstd_compress.c +2650 -826
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +509 -180
  46. data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
  47. data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
  48. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
  49. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
  50. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +33 -305
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +266 -85
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +369 -132
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +722 -258
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1105 -360
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +41 -1
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +272 -208
  60. data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
  61. data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  62. data/contrib/zstd/lib/compress/zstd_opt.c +324 -197
  63. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +109 -53
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1071 -539
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -0
  68. data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
  69. data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
  70. data/contrib/zstd/lib/decompress/zstd_decompress.c +507 -82
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +962 -310
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +54 -6
  74. data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
  75. data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
  76. data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
  77. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  78. data/contrib/zstd/lib/dictBuilder/cover.c +44 -32
  79. data/contrib/zstd/lib/dictBuilder/cover.h +6 -5
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +24 -16
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +88 -95
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +16 -53
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +24 -69
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +25 -72
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +23 -69
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +35 -85
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +42 -87
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +35 -82
  97. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  98. data/contrib/zstd/lib/libzstd.mk +214 -0
  99. data/contrib/zstd/lib/libzstd.pc.in +4 -3
  100. data/contrib/zstd/lib/module.modulemap +35 -0
  101. data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
  102. data/contrib/zstd/lib/zstd.h +922 -293
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
  104. data/ext/extconf.rb +7 -6
  105. data/ext/extzstd.c +13 -10
  106. data/ext/libzstd_conf.h +0 -1
  107. data/ext/zstd_decompress_asm.S +1 -0
  108. metadata +16 -5
@@ -1,5 +1,5 @@
1
1
  # ################################################################
2
- # Copyright (c) 2015-2020, Yann Collet, Facebook, Inc.
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  # All rights reserved.
4
4
  #
5
5
  # This source code is licensed under both the BSD-style license (found in the
@@ -8,103 +8,13 @@
8
8
  # You may select, at your option, one of the above-listed licenses.
9
9
  # ################################################################
10
10
 
11
- .PHONY: default
12
- default: lib-release
13
-
14
- # define silent mode as default (verbose mode with V=1 or VERBOSE=1)
15
- $(V)$(VERBOSE).SILENT:
16
-
17
- # When cross-compiling from linux to windows,
18
- # one might need to specify TARGET_SYSTEM as "Windows."
19
- # Building from Fedora fails without it.
20
- # (but Ubuntu and Debian don't need to set anything)
21
- TARGET_SYSTEM ?= $(OS)
22
-
23
- # Version numbers
24
- LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
25
- LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
26
- LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
27
- LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
28
- LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
29
- LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
30
- LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
31
- LIBVER := $(shell echo $(LIBVER_SCRIPT))
32
- VERSION?= $(LIBVER)
33
- CCVER := $(shell $(CC) --version)
34
-
35
- # ZSTD_LIB_MINIFY is a helper variable that
36
- # configures a bunch of other variables to space-optimized defaults.
37
- ZSTD_LIB_MINIFY ?= 0
38
- ifneq ($(ZSTD_LIB_MINIFY), 0)
39
- HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
40
- ZSTD_LEGACY_SUPPORT ?= 0
41
- ZSTD_LIB_DEPRECATED ?= 0
42
- HUF_FORCE_DECOMPRESS_X1 ?= 1
43
- ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
44
- ZSTD_NO_INLINE ?= 1
45
- ZSTD_STRIP_ERROR_STRINGS ?= 1
46
- ifneq ($(HAVE_CC_OZ), 0)
47
- # Some compilers (clang) support an even more space-optimized setting.
48
- CFLAGS += -Oz
49
- else
50
- CFLAGS += -Os
51
- endif
52
- CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
53
- -DDYNAMIC_BMI2=0 -DNDEBUG
54
- else
55
- CFLAGS += -O3
56
- endif
57
-
58
- DEBUGLEVEL ?= 0
59
- CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
60
- ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
61
- CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
62
- endif
63
- DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
64
- -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
65
- -Wstrict-prototypes -Wundef -Wpointer-arith \
66
- -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
67
- -Wredundant-decls -Wmissing-prototypes -Wc++-compat
68
- CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
69
- FLAGS = $(CPPFLAGS) $(CFLAGS)
70
-
71
- HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
72
- GREP_OPTIONS ?=
73
- ifeq ($HAVE_COLORNEVER, 1)
74
- GREP_OPTIONS += --color=never
75
- endif
76
- GREP = grep $(GREP_OPTIONS)
77
- SED_ERE_OPT ?= -E
78
-
79
- ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
80
- ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
81
- ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
82
- ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
83
- ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
84
- ZSTD_FILES := $(ZSTDCOMMON_FILES)
85
-
86
- ifeq ($(findstring GCC,$(CCVER)),GCC)
87
- decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
88
- endif
89
-
90
11
  # Modules
91
12
  ZSTD_LIB_COMPRESSION ?= 1
92
13
  ZSTD_LIB_DECOMPRESSION ?= 1
93
14
  ZSTD_LIB_DICTBUILDER ?= 1
94
- ZSTD_LIB_DEPRECATED ?= 1
95
-
96
- # Legacy support
97
- ZSTD_LEGACY_SUPPORT ?= 5
98
- ZSTD_LEGACY_MULTITHREADED_API ?= 0
99
-
100
- # Build size optimizations
101
- HUF_FORCE_DECOMPRESS_X1 ?= 0
102
- HUF_FORCE_DECOMPRESS_X2 ?= 0
103
- ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
104
- ZSTD_FORCE_DECOMPRESS_LONG ?= 0
105
- ZSTD_NO_INLINE ?= 0
106
- ZSTD_STRIP_ERROR_STRINGS ?= 0
15
+ ZSTD_LIB_DEPRECATED ?= 0
107
16
 
17
+ # Input variables for libzstd.mk
108
18
  ifeq ($(ZSTD_LIB_COMPRESSION), 0)
109
19
  ZSTD_LIB_DICTBUILDER = 0
110
20
  ZSTD_LIB_DEPRECATED = 0
@@ -115,82 +25,46 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
115
25
  ZSTD_LIB_DEPRECATED = 0
116
26
  endif
117
27
 
28
+ include libzstd.mk
29
+
30
+ ZSTD_FILES := $(ZSTD_COMMON_FILES) $(ZSTD_LEGACY_FILES)
31
+
118
32
  ifneq ($(ZSTD_LIB_COMPRESSION), 0)
119
- ZSTD_FILES += $(ZSTDCOMP_FILES)
33
+ ZSTD_FILES += $(ZSTD_COMPRESS_FILES)
120
34
  endif
121
35
 
122
36
  ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
123
- ZSTD_FILES += $(ZSTDDECOMP_FILES)
37
+ ZSTD_FILES += $(ZSTD_DECOMPRESS_FILES)
124
38
  endif
125
39
 
126
40
  ifneq ($(ZSTD_LIB_DEPRECATED), 0)
127
- ZSTD_FILES += $(ZDEPR_FILES)
41
+ ZSTD_FILES += $(ZSTD_DEPRECATED_FILES)
128
42
  endif
129
43
 
130
44
  ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
131
- ZSTD_FILES += $(ZDICT_FILES)
132
- endif
133
-
134
- ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
135
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
136
- endif
137
-
138
- ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
139
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
140
- endif
141
-
142
- ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
143
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
144
- endif
145
-
146
- ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
147
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
148
- endif
149
-
150
- ifneq ($(ZSTD_NO_INLINE), 0)
151
- CFLAGS += -DZSTD_NO_INLINE
152
- endif
153
-
154
- ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
155
- CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
156
- endif
157
-
158
- ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
159
- CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
160
- endif
161
-
162
- ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
163
- ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
164
- ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
165
- endif
45
+ ZSTD_FILES += $(ZSTD_DICTBUILDER_FILES)
166
46
  endif
167
- CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
168
47
 
169
48
  ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
170
- ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)
49
+ ZSTD_LOCAL_OBJ0 := $(ZSTD_LOCAL_SRC:.c=.o)
50
+ ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_OBJ0:.S=.o)
171
51
 
172
- ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
173
- vpath %.c $(ZSTD_SUBDIR)
52
+ VERSION := $(ZSTD_VERSION)
53
+
54
+ # Note: by default, the static library is built single-threaded and dynamic library is built
55
+ # multi-threaded. It is possible to force multi or single threaded builds by appending
56
+ # -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
57
+ .PHONY: default
58
+ default: lib-release
174
59
 
175
- UNAME := $(shell uname)
60
+ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
61
+ LDFLAGS_DYNLIB += -pthread
62
+ CPPFLAGS_STATLIB += # static library build defaults to single-threaded
176
63
 
177
- ifndef BUILD_DIR
178
- ifeq ($(UNAME), Darwin)
179
- HASH ?= md5
180
- else ifeq ($(UNAME), FreeBSD)
181
- HASH ?= gmd5sum
182
- else ifeq ($(UNAME), OpenBSD)
183
- HASH ?= md5
184
- endif
185
- HASH ?= md5sum
186
64
 
187
- HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
188
- HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
189
- ifeq ($(HAVE_HASH),0)
190
- $(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
191
- BUILD_DIR := obj/generic_noconf
65
+ ifeq ($(findstring GCC,$(CCVER)),GCC)
66
+ decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
192
67
  endif
193
- endif # BUILD_DIR
194
68
 
195
69
 
196
70
  # macOS linker doesn't support -soname, and use different extension
@@ -201,29 +75,31 @@ ifeq ($(UNAME), Darwin)
201
75
  SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
202
76
  SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
203
77
  else
204
- SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
78
+ ifeq ($(UNAME), AIX)
79
+ SONAME_FLAGS =
80
+ else
81
+ SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
82
+ endif
205
83
  SHARED_EXT = so
206
84
  SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
207
85
  SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
208
86
  endif
209
87
 
88
+
89
+ .PHONY: all
90
+ all: lib
91
+
92
+
93
+ .PHONY: libzstd.a # must be run every time
94
+ libzstd.a: CPPFLAGS += $(CPPFLAGS_STATLIB)
95
+
210
96
  SET_CACHE_DIRECTORY = \
211
- $(MAKE) --no-print-directory $@ \
97
+ +$(MAKE) --no-print-directory $@ \
212
98
  BUILD_DIR=obj/$(HASH_DIR) \
213
99
  CPPFLAGS="$(CPPFLAGS)" \
214
100
  CFLAGS="$(CFLAGS)" \
215
101
  LDFLAGS="$(LDFLAGS)"
216
102
 
217
-
218
- .PHONY: lib-all all clean install uninstall
219
-
220
- # alias
221
- lib-all: all
222
-
223
- all: lib
224
-
225
- .PHONY: libzstd.a # must be run every time
226
-
227
103
  ifndef BUILD_DIR
228
104
  # determine BUILD_DIR from compilation flags
229
105
 
@@ -239,7 +115,10 @@ ZSTD_STATLIB_OBJ := $(addprefix $(ZSTD_STATLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
239
115
  $(ZSTD_STATLIB): ARFLAGS = rcs
240
116
  $(ZSTD_STATLIB): | $(ZSTD_STATLIB_DIR)
241
117
  $(ZSTD_STATLIB): $(ZSTD_STATLIB_OBJ)
242
- @echo compiling static library
118
+ # Check for multithread flag at target execution time
119
+ $(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
120
+ @echo compiling multi-threaded static library $(LIBVER),\
121
+ @echo compiling single-threaded static library $(LIBVER))
243
122
  $(AR) $(ARFLAGS) $@ $^
244
123
 
245
124
  libzstd.a: $(ZSTD_STATLIB)
@@ -258,8 +137,9 @@ else # not Windows
258
137
 
259
138
  LIBZSTD = libzstd.$(SHARED_EXT_VER)
260
139
  .PHONY: $(LIBZSTD) # must be run every time
261
- $(LIBZSTD): CFLAGS += -fPIC
262
- $(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
140
+ $(LIBZSTD): CPPFLAGS += $(CPPFLAGS_DYNLIB)
141
+ $(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
142
+ $(LIBZSTD): LDFLAGS += -shared $(LDFLAGS_DYNLIB)
263
143
 
264
144
  ifndef BUILD_DIR
265
145
  # determine BUILD_DIR from compilation flags
@@ -276,7 +156,10 @@ ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
276
156
 
277
157
  $(ZSTD_DYNLIB): | $(ZSTD_DYNLIB_DIR)
278
158
  $(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
279
- @echo compiling dynamic library $(LIBVER)
159
+ # Check for multithread flag at target execution time
160
+ $(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
161
+ @echo compiling multi-threaded dynamic library $(LIBVER),\
162
+ @echo compiling single-threaded dynamic library $(LIBVER))
280
163
  $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
281
164
  @echo creating versioned links
282
165
  ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
@@ -298,10 +181,17 @@ lib : libzstd.a libzstd
298
181
  # note : do not define lib-mt or lib-release as .PHONY
299
182
  # make does not consider implicit pattern rule for .PHONY target
300
183
 
301
- %-mt : CPPFLAGS += -DZSTD_MULTITHREAD
302
- %-mt : LDFLAGS += -pthread
184
+ %-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
185
+ %-mt : CPPFLAGS_STATLIB := -DZSTD_MULTITHREAD
186
+ %-mt : LDFLAGS_DYNLIB := -pthread
303
187
  %-mt : %
304
- @echo multi-threading build completed
188
+ @echo multi-threaded build completed
189
+
190
+ %-nomt : CPPFLAGS_DYNLIB :=
191
+ %-nomt : LDFLAGS_DYNLIB :=
192
+ %-nomt : CPPFLAGS_STATLIB :=
193
+ %-nomt : %
194
+ @echo single-threaded build completed
305
195
 
306
196
  %-release : DEBUGFLAGS :=
307
197
  %-release : %
@@ -320,6 +210,14 @@ $(ZSTD_STATLIB_DIR)/%.o : %.c $(ZSTD_STATLIB_DIR)/%.d | $(ZSTD_STATLIB_DIR)
320
210
  @echo CC $@
321
211
  $(COMPILE.c) $(DEPFLAGS) $(ZSTD_STATLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
322
212
 
213
+ $(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
214
+ @echo AS $@
215
+ $(COMPILE.S) $(OUTPUT_OPTION) $<
216
+
217
+ $(ZSTD_STATLIB_DIR)/%.o : %.S | $(ZSTD_STATLIB_DIR)
218
+ @echo AS $@
219
+ $(COMPILE.S) $(OUTPUT_OPTION) $<
220
+
323
221
  MKDIR ?= mkdir
324
222
  $(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATLIB_DIR):
325
223
  $(MKDIR) -p $@
@@ -333,12 +231,14 @@ include $(wildcard $(DEPFILES))
333
231
  # Special case : building library in single-thread mode _and_ without zstdmt_compress.c
334
232
  ZSTDMT_FILES = compress/zstdmt_compress.c
335
233
  ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
336
- libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
234
+ libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
235
+ libzstd-nomt: LDFLAGS += -shared
337
236
  libzstd-nomt: $(ZSTD_NOMT_FILES)
338
237
  @echo compiling single-thread dynamic library $(LIBVER)
339
238
  @echo files : $(ZSTD_NOMT_FILES)
340
239
  $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
341
240
 
241
+ .PHONY: clean
342
242
  clean:
343
243
  $(RM) -r *.dSYM # macOS-specific
344
244
  $(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
@@ -349,9 +249,9 @@ clean:
349
249
  #-----------------------------------------------------------------------------
350
250
  # make install is validated only for below listed environments
351
251
  #-----------------------------------------------------------------------------
352
- ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
252
+ ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX))
353
253
 
354
- all: libzstd.pc
254
+ lib: libzstd.pc
355
255
 
356
256
  HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
357
257
 
@@ -396,24 +296,27 @@ INSTALL_PROGRAM ?= $(INSTALL)
396
296
  INSTALL_DATA ?= $(INSTALL) -m 644
397
297
 
398
298
 
399
- libzstd.pc:
400
299
  libzstd.pc: libzstd.pc.in
401
300
  @echo creating pkgconfig
402
- @sed $(SED_ERE_OPT) \
301
+ @sed \
403
302
  -e 's|@PREFIX@|$(PREFIX)|' \
404
303
  -e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
405
- -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
406
- -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
407
- -e 's|@VERSION@|$(VERSION)|' \
408
- $< >$@
304
+ -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
305
+ -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
306
+ -e 's|@VERSION@|$(VERSION)|' \
307
+ -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
308
+ $< >$@
409
309
 
310
+ .PHONY: install
410
311
  install: install-pc install-static install-shared install-includes
411
312
  @echo zstd static and shared library installed
412
313
 
314
+ .PHONY: install-pc
413
315
  install-pc: libzstd.pc
414
316
  [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
415
317
  $(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
416
318
 
319
+ .PHONY: install-static
417
320
  install-static:
418
321
  # only generate libzstd.a if it's not already present
419
322
  [ -e libzstd.a ] || $(MAKE) libzstd.a-release
@@ -421,6 +324,7 @@ install-static:
421
324
  @echo Installing static library
422
325
  $(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
423
326
 
327
+ .PHONY: install-shared
424
328
  install-shared:
425
329
  # only generate libzstd.so if it's not already present
426
330
  [ -e $(LIBZSTD) ] || $(MAKE) libzstd-release
@@ -430,13 +334,15 @@ install-shared:
430
334
  ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
431
335
  ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
432
336
 
337
+ .PHONY: install-includes
433
338
  install-includes:
434
339
  [ -e $(DESTDIR)$(INCLUDEDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
435
340
  @echo Installing includes
436
341
  $(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
437
- $(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
438
- $(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
342
+ $(INSTALL_DATA) zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
343
+ $(INSTALL_DATA) zdict.h $(DESTDIR)$(INCLUDEDIR)
439
344
 
345
+ .PHONY: uninstall
440
346
  uninstall:
441
347
  $(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
442
348
  $(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
@@ -19,12 +19,16 @@ The scope can be reduced on demand (see paragraph _modular build_).
19
19
 
20
20
  #### Multithreading support
21
21
 
22
- Multithreading is disabled by default when building with `make`.
22
+ When building with `make`, by default the dynamic library is multithreaded and static library is single-threaded (for compatibility reasons).
23
+
23
24
  Enabling multithreading requires 2 conditions :
24
25
  - set build macro `ZSTD_MULTITHREAD` (`-DZSTD_MULTITHREAD` for `gcc`)
25
26
  - for POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`)
26
27
 
27
- Both conditions are automatically applied when invoking `make lib-mt` target.
28
+ For convenience, we provide a build target to generate multi and single threaded libraries:
29
+ - Force enable multithreading on both dynamic and static libraries by appending `-mt` to the target, e.g. `make lib-mt`.
30
+ - Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`.
31
+ - By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`.
28
32
 
29
33
  When linking a POSIX program with a multithreaded version of `libzstd`,
30
34
  note that it's necessary to invoke the `-pthread` flag during link stage.
@@ -42,8 +46,8 @@ Zstandard's stable API is exposed within [lib/zstd.h](zstd.h).
42
46
 
43
47
  Optional advanced features are exposed via :
44
48
 
45
- - `lib/common/zstd_errors.h` : translates `size_t` function results
46
- into a `ZSTD_ErrorCode`, for accurate error handling.
49
+ - `lib/zstd_errors.h` : translates `size_t` function results
50
+ into a `ZSTD_ErrorCode`, for accurate error handling.
47
51
 
48
52
  - `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`,
49
53
  it unlocks access to the experimental API,
@@ -87,7 +91,7 @@ The file structure is designed to make this selection manually achievable for an
87
91
  `ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
88
92
  and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the
89
93
  corresponding features. This will also disable compilation of all
90
- dependencies (eg. `ZSTD_LIB_COMPRESSION=0` will also disable
94
+ dependencies (e.g. `ZSTD_LIB_COMPRESSION=0` will also disable
91
95
  dictBuilder).
92
96
 
93
97
  - There are a number of options that can help minimize the binary size of
@@ -121,7 +125,7 @@ The file structure is designed to make this selection manually achievable for an
121
125
  `ZSTD_getErrorName` (implied by `ZSTD_LIB_MINIFY`).
122
126
 
123
127
  Finally, when integrating into your application, make sure you're doing link-
124
- time optimation and unused symbol garbage collection (via some combination of,
128
+ time optimization and unused symbol garbage collection (via some combination of,
125
129
  e.g., `-flto`, `-ffat-lto-objects`, `-fuse-linker-plugin`,
126
130
  `-ffunction-sections`, `-fdata-sections`, `-fmerge-all-constants`,
127
131
  `-Wl,--gc-sections`, `-Wl,-z,norelro`, and an archiver that understands
@@ -151,6 +155,19 @@ The file structure is designed to make this selection manually achievable for an
151
155
  - The build macro `ZSTD_NO_INTRINSICS` can be defined to disable all explicit intrinsics.
152
156
  Compiler builtins are still used.
153
157
 
158
+ - The build macro `ZSTD_DECODER_INTERNAL_BUFFER` can be set to control
159
+ the amount of extra memory used during decompression to store literals.
160
+ This defaults to 64kB. Reducing this value reduces the memory footprint of
161
+ `ZSTD_DCtx` decompression contexts,
162
+ but might also result in a small decompression speed cost.
163
+
164
+ - The C compiler macros `ZSTDLIB_VISIBLE`, `ZSTDERRORLIB_VISIBLE` and `ZDICTLIB_VISIBLE`
165
+ can be overridden to control the visibility of zstd's API. Additionally,
166
+ `ZSTDLIB_STATIC_API` and `ZDICTLIB_STATIC_API` can be overridden to control the visibility
167
+ of zstd's static API. Specifically, it can be set to `ZSTDLIB_HIDDEN` to hide the symbols
168
+ from the shared library. These macros default to `ZSTDLIB_VISIBILITY`,
169
+ `ZSTDERRORLIB_VSIBILITY`, and `ZDICTLIB_VISIBILITY` if unset, for backwards compatibility
170
+ with the old macro names.
154
171
 
155
172
  #### Windows : using MinGW+MSYS to create DLL
156
173
 
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
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
+ /* This file provides custom allocation primitives
12
+ */
13
+
14
+ #define ZSTD_DEPS_NEED_MALLOC
15
+ #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16
+
17
+ #include "mem.h" /* MEM_STATIC */
18
+ #define ZSTD_STATIC_LINKING_ONLY
19
+ #include "../zstd.h" /* ZSTD_customMem */
20
+
21
+ #ifndef ZSTD_ALLOCATIONS_H
22
+ #define ZSTD_ALLOCATIONS_H
23
+
24
+ /* custom memory allocation functions */
25
+
26
+ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27
+ {
28
+ if (customMem.customAlloc)
29
+ return customMem.customAlloc(customMem.opaque, size);
30
+ return ZSTD_malloc(size);
31
+ }
32
+
33
+ MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34
+ {
35
+ if (customMem.customAlloc) {
36
+ /* calloc implemented as malloc+memset;
37
+ * not as efficient as calloc, but next best guess for custom malloc */
38
+ void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
+ ZSTD_memset(ptr, 0, size);
40
+ return ptr;
41
+ }
42
+ return ZSTD_calloc(1, size);
43
+ }
44
+
45
+ MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
46
+ {
47
+ if (ptr!=NULL) {
48
+ if (customMem.customFree)
49
+ customMem.customFree(customMem.opaque, ptr);
50
+ else
51
+ ZSTD_free(ptr);
52
+ }
53
+ }
54
+
55
+ #endif /* ZSTD_ALLOCATIONS_H */