extzstd 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja +5 -0
  3. data/README.md +5 -5
  4. data/contrib/zstd/CONTRIBUTING.md +42 -0
  5. data/contrib/zstd/LICENSE-examples +11 -0
  6. data/contrib/zstd/Makefile +315 -0
  7. data/contrib/zstd/NEWS +261 -0
  8. data/contrib/zstd/PATENTS +33 -0
  9. data/contrib/zstd/README.md +121 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +178 -0
  12. data/contrib/zstd/circle.yml +75 -0
  13. data/contrib/zstd/lib/BUCK +186 -0
  14. data/contrib/zstd/lib/Makefile +163 -0
  15. data/contrib/zstd/lib/README.md +77 -0
  16. data/contrib/zstd/{common → lib/common}/bitstream.h +7 -4
  17. data/contrib/zstd/{common → lib/common}/entropy_common.c +19 -23
  18. data/contrib/zstd/{common → lib/common}/error_private.c +0 -0
  19. data/contrib/zstd/{common → lib/common}/error_private.h +0 -0
  20. data/contrib/zstd/{common → lib/common}/fse.h +94 -34
  21. data/contrib/zstd/{common → lib/common}/fse_decompress.c +18 -19
  22. data/contrib/zstd/{common → lib/common}/huf.h +52 -20
  23. data/contrib/zstd/{common → lib/common}/mem.h +17 -13
  24. data/contrib/zstd/lib/common/pool.c +194 -0
  25. data/contrib/zstd/lib/common/pool.h +56 -0
  26. data/contrib/zstd/lib/common/threading.c +80 -0
  27. data/contrib/zstd/lib/common/threading.h +104 -0
  28. data/contrib/zstd/{common → lib/common}/xxhash.c +3 -1
  29. data/contrib/zstd/{common → lib/common}/xxhash.h +11 -15
  30. data/contrib/zstd/{common → lib/common}/zstd_common.c +1 -11
  31. data/contrib/zstd/{common → lib/common}/zstd_errors.h +16 -2
  32. data/contrib/zstd/{common → lib/common}/zstd_internal.h +17 -1
  33. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +138 -91
  34. data/contrib/zstd/{compress → lib/compress}/huf_compress.c +218 -67
  35. data/contrib/zstd/{compress → lib/compress}/zstd_compress.c +231 -108
  36. data/contrib/zstd/{compress → lib/compress}/zstd_opt.h +44 -25
  37. data/contrib/zstd/lib/compress/zstdmt_compress.c +739 -0
  38. data/contrib/zstd/lib/compress/zstdmt_compress.h +78 -0
  39. data/contrib/zstd/{decompress → lib/decompress}/huf_decompress.c +28 -23
  40. data/contrib/zstd/{decompress → lib/decompress}/zstd_decompress.c +814 -176
  41. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +60 -39
  42. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  43. data/contrib/zstd/lib/deprecated/zbuff_compress.c +145 -0
  44. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +74 -0
  45. data/contrib/zstd/lib/dictBuilder/cover.c +1029 -0
  46. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +0 -0
  47. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  48. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +68 -18
  49. data/contrib/zstd/lib/dictBuilder/zdict.h +201 -0
  50. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +122 -7
  51. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +34 -3
  52. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +8 -0
  53. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +45 -12
  54. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +8 -0
  55. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +45 -12
  56. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +8 -0
  57. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +56 -33
  58. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +8 -0
  59. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +45 -18
  60. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +7 -0
  61. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +43 -16
  62. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +7 -0
  63. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +57 -23
  64. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +8 -0
  65. data/contrib/zstd/lib/libzstd.pc.in +14 -0
  66. data/contrib/zstd/{zstd.h → lib/zstd.h} +206 -71
  67. data/ext/depend +2 -0
  68. data/ext/extconf.rb +4 -4
  69. data/ext/extzstd.c +1 -1
  70. data/ext/zstd_common.c +5 -5
  71. data/ext/zstd_compress.c +3 -3
  72. data/ext/zstd_decompress.c +2 -2
  73. data/ext/zstd_dictbuilder.c +2 -2
  74. data/ext/zstd_legacy_v01.c +1 -1
  75. data/ext/zstd_legacy_v02.c +1 -1
  76. data/ext/zstd_legacy_v03.c +1 -1
  77. data/ext/zstd_legacy_v04.c +1 -1
  78. data/ext/zstd_legacy_v05.c +1 -1
  79. data/ext/zstd_legacy_v06.c +1 -1
  80. data/ext/zstd_legacy_v07.c +1 -1
  81. data/gemstub.rb +9 -5
  82. data/lib/extzstd/version.rb +1 -1
  83. metadata +73 -51
  84. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  85. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  86. data/contrib/zstd/dictBuilder/zdict.h +0 -111
@@ -0,0 +1,186 @@
1
+ cxx_library(
2
+ name='zstd',
3
+ header_namespace='',
4
+ visibility=['PUBLIC'],
5
+ deps=[
6
+ ':common',
7
+ ':compress',
8
+ ':decompress',
9
+ ':deprecated',
10
+ ],
11
+ )
12
+
13
+ cxx_library(
14
+ name='compress',
15
+ header_namespace='',
16
+ visibility=['PUBLIC'],
17
+ exported_headers=subdir_glob([
18
+ ('compress', 'zstdmt_compress.h'),
19
+ ]),
20
+ headers=subdir_glob([
21
+ ('compress', 'zstd_opt.h'),
22
+ ]),
23
+ srcs=[
24
+ 'compress/zstd_compress.c',
25
+ 'compress/zstdmt_compress.c',
26
+ ],
27
+ deps=[':common'],
28
+ )
29
+
30
+ cxx_library(
31
+ name='decompress',
32
+ header_namespace='',
33
+ visibility=['PUBLIC'],
34
+ srcs=['decompress/zstd_decompress.c'],
35
+ deps=[
36
+ ':common',
37
+ ':legacy',
38
+ ],
39
+ )
40
+
41
+ cxx_library(
42
+ name='deprecated',
43
+ header_namespace='',
44
+ visibility=['PUBLIC'],
45
+ exported_headers=subdir_glob([
46
+ ('decprecated', '*.h'),
47
+ ]),
48
+ srcs=glob(['deprecated/*.c']),
49
+ deps=[':common'],
50
+ )
51
+
52
+ cxx_library(
53
+ name='legacy',
54
+ header_namespace='',
55
+ visibility=['PUBLIC'],
56
+ exported_headers=subdir_glob([
57
+ ('legacy', '*.h'),
58
+ ]),
59
+ srcs=glob(['legacy/*.c']),
60
+ deps=[':common'],
61
+ )
62
+
63
+ cxx_library(
64
+ name='zdict',
65
+ header_namespace='',
66
+ visibility=['PUBLIC'],
67
+ exported_headers=subdir_glob([
68
+ ('dictBuilder', 'zdict.h'),
69
+ ]),
70
+ headers=subdir_glob([
71
+ ('dictBuilder', 'divsufsort.h'),
72
+ ]),
73
+ srcs=glob(['dictBuilder/*.c']),
74
+ deps=[':common'],
75
+ )
76
+
77
+ cxx_library(
78
+ name='bitstream',
79
+ header_namespace='',
80
+ visibility=['PUBLIC'],
81
+ exported_headers=subdir_glob([
82
+ ('common', 'bitstream.h'),
83
+ ]),
84
+ )
85
+
86
+ cxx_library(
87
+ name='entropy',
88
+ header_namespace='',
89
+ visibility=['PUBLIC'],
90
+ exported_headers=subdir_glob([
91
+ ('common', 'fse.h'),
92
+ ('common', 'huf.h'),
93
+ ]),
94
+ srcs=[
95
+ 'common/entropy_common.c',
96
+ 'common/fse_decompress.c',
97
+ 'compress/fse_compress.c',
98
+ 'compress/huf_compress.c',
99
+ 'decompress/huf_decompress.c',
100
+ ],
101
+ deps=[
102
+ ':bitstream',
103
+ ':errors',
104
+ ':mem',
105
+ ],
106
+ )
107
+
108
+ cxx_library(
109
+ name='errors',
110
+ header_namespace='',
111
+ visibility=['PUBLIC'],
112
+ exported_headers=subdir_glob([
113
+ ('common', 'error_private.h'),
114
+ ('common', 'zstd_errors.h'),
115
+ ]),
116
+ srcs=['common/error_private.c'],
117
+ )
118
+
119
+ cxx_library(
120
+ name='mem',
121
+ header_namespace='',
122
+ visibility=['PUBLIC'],
123
+ exported_headers=subdir_glob([
124
+ ('common', 'mem.h'),
125
+ ]),
126
+ )
127
+
128
+ cxx_library(
129
+ name='pool',
130
+ header_namespace='',
131
+ visibility=['PUBLIC'],
132
+ exported_headers=subdir_glob([
133
+ ('common', 'pool.h'),
134
+ ]),
135
+ srcs=['common/pool.c'],
136
+ deps=[':threading'],
137
+ )
138
+
139
+ cxx_library(
140
+ name='threading',
141
+ header_namespace='',
142
+ visibility=['PUBLIC'],
143
+ exported_headers=subdir_glob([
144
+ ('common', 'threading.h'),
145
+ ]),
146
+ srcs=['common/threading.c'],
147
+ )
148
+
149
+ cxx_library(
150
+ name='xxhash',
151
+ header_namespace='',
152
+ visibility=['PUBLIC'],
153
+ exported_headers=subdir_glob([
154
+ ('common', 'xxhash.h'),
155
+ ]),
156
+ srcs=['common/xxhash.c'],
157
+ )
158
+
159
+ cxx_library(
160
+ name='zstd_common',
161
+ header_namespace='',
162
+ visibility=['PUBLIC'],
163
+ exported_headers=subdir_glob([
164
+ ('', 'zstd.h'),
165
+ ('common', 'zstd_internal.h'),
166
+ ]),
167
+ srcs=['common/zstd_common.c'],
168
+ deps=[
169
+ ':errors',
170
+ ':mem',
171
+ ],
172
+ )
173
+
174
+ cxx_library(
175
+ name='common',
176
+ deps=[
177
+ ':bitstream',
178
+ ':entropy',
179
+ ':errors',
180
+ ':mem',
181
+ ':pool',
182
+ ':threading',
183
+ ':xxhash',
184
+ ':zstd_common',
185
+ ]
186
+ )
@@ -0,0 +1,163 @@
1
+ # ##########################################################################
2
+ # Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
6
+ #
7
+ # This source code is licensed under the BSD-style license found in the
8
+ # LICENSE file in the root directory of this source tree. An additional grant
9
+ # of patent rights can be found in the PATENTS file in the same directory.
10
+ # ##########################################################################
11
+
12
+ # Version numbers
13
+ LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
14
+ LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
15
+ LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
16
+ LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
17
+ LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
18
+ LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
19
+ LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
20
+ LIBVER := $(shell echo $(LIBVER_SCRIPT))
21
+ VERSION?= $(LIBVER)
22
+
23
+ CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
24
+ CFLAGS ?= -O3
25
+ DEBUGFLAGS = -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
26
+ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
27
+ -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security
28
+ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
29
+ FLAGS = $(CPPFLAGS) $(CFLAGS)
30
+
31
+
32
+ ZSTD_FILES := $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)
33
+
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
41
+ endif
42
+ CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
43
+
44
+ ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES))
45
+
46
+ # OS X linker doesn't support -soname, and use different extension
47
+ # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
48
+ ifeq ($(shell uname), Darwin)
49
+ SHARED_EXT = dylib
50
+ SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
51
+ SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
52
+ SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
53
+ else
54
+ SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
55
+ SHARED_EXT = so
56
+ SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
57
+ SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
58
+ endif
59
+
60
+ LIBZSTD = libzstd.$(SHARED_EXT_VER)
61
+
62
+
63
+ .PHONY: default all clean install uninstall
64
+
65
+ default: lib-release
66
+
67
+ all: lib
68
+
69
+ libzstd.a: ARFLAGS = rcs
70
+ libzstd.a: $(ZSTD_OBJ)
71
+ @echo compiling static library
72
+ @$(AR) $(ARFLAGS) $@ $^
73
+
74
+ $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
75
+ $(LIBZSTD): $(ZSTD_FILES)
76
+ @echo compiling dynamic library $(LIBVER)
77
+ ifneq (,$(filter Windows%,$(OS)))
78
+ @$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll
79
+ dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib
80
+ else
81
+ @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
82
+ @echo creating versioned links
83
+ @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
84
+ @ln -sf $@ libzstd.$(SHARED_EXT)
85
+ endif
86
+
87
+ libzstd : $(LIBZSTD)
88
+
89
+ lib: libzstd.a libzstd
90
+
91
+ lib-release: DEBUGFLAGS :=
92
+ lib-release: lib
93
+
94
+ clean:
95
+ @$(RM) -r *.dSYM # Mac OS-X specific
96
+ @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
97
+ @$(RM) dll/libzstd.dll dll/libzstd.lib
98
+ @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
99
+ @echo Cleaning library completed
100
+
101
+ #-----------------------------------------------------------------------------
102
+ # make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
103
+ #-----------------------------------------------------------------------------
104
+ ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
105
+
106
+ ifneq (,$(filter $(shell uname),SunOS))
107
+ INSTALL ?= ginstall
108
+ else
109
+ INSTALL ?= install
110
+ endif
111
+
112
+ PREFIX ?= /usr/local
113
+ DESTDIR ?=
114
+ LIBDIR ?= $(PREFIX)/lib
115
+ INCLUDEDIR ?= $(PREFIX)/include
116
+
117
+ ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly))
118
+ PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
119
+ else
120
+ PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
121
+ endif
122
+
123
+ INSTALL_LIB ?= $(INSTALL) -m 755
124
+ INSTALL_DATA ?= $(INSTALL) -m 644
125
+
126
+
127
+ libzstd.pc:
128
+ libzstd.pc: libzstd.pc.in
129
+ @echo creating pkgconfig
130
+ @sed -e 's|@PREFIX@|$(PREFIX)|' \
131
+ -e 's|@LIBDIR@|$(LIBDIR)|' \
132
+ -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
133
+ -e 's|@VERSION@|$(VERSION)|' \
134
+ $< >$@
135
+
136
+ install: libzstd.a libzstd libzstd.pc
137
+ @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/
138
+ @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
139
+ @echo Installing libraries
140
+ @$(INSTALL_LIB) libzstd.a $(DESTDIR)$(LIBDIR)
141
+ @$(INSTALL_LIB) libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)
142
+ @ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
143
+ @ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
144
+ @echo Installing includes
145
+ @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
146
+ @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
147
+ @$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
148
+ @$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
149
+ @echo zstd static and shared library installed
150
+
151
+ uninstall:
152
+ @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
153
+ @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
154
+ @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
155
+ @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_VER)
156
+ @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
157
+ @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
158
+ @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
159
+ @$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
160
+ @$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
161
+ @echo zstd libraries successfully uninstalled
162
+
163
+ endif
@@ -0,0 +1,77 @@
1
+ Zstandard library files
2
+ ================================
3
+
4
+ The __lib__ directory contains several directories.
5
+ Depending on target use case, it's enough to include only files from relevant directories.
6
+
7
+
8
+ #### API
9
+
10
+ Zstandard's stable API is exposed within [zstd.h](zstd.h),
11
+ at the root of `lib` directory.
12
+
13
+
14
+ #### Advanced API
15
+
16
+ Some additional API may be useful if you're looking into advanced features :
17
+ - common/error_public.h : transforms `size_t` function results into an `enum`,
18
+ for precise error handling.
19
+ - ZSTD_STATIC_LINKING_ONLY : if you define this macro _before_ including `zstd.h`,
20
+ it will give access to advanced and experimental API.
21
+ These APIs shall ___never be used with dynamic library___ !
22
+ They are not "stable", their definition may change in the future.
23
+ Only static linking is allowed.
24
+
25
+
26
+ #### Modular build
27
+
28
+ Directory `common/` is required in all circumstances.
29
+ You can select to support compression only, by just adding files from the `compress/` directory,
30
+ In a similar way, you can build a decompressor-only library with the `decompress/` directory.
31
+
32
+ Other optional functionalities provided are :
33
+
34
+ - `dictBuilder/` : source files to create dictionaries.
35
+ The API can be consulted in `dictBuilder/zdict.h`.
36
+ This module also depends on `common/` and `compress/` .
37
+
38
+ - `legacy/` : source code to decompress previous versions of zstd, starting from `v0.1`.
39
+ This module also depends on `common/` and `decompress/` .
40
+ Library compilation must include directive `ZSTD_LEGACY_SUPPORT = 1` .
41
+ The main API can be consulted in `legacy/zstd_legacy.h`.
42
+ Advanced API from each version can be found in their relevant header file.
43
+ For example, advanced API for version `v0.4` is in `legacy/zstd_v04.h` .
44
+
45
+
46
+ #### Using MinGW+MSYS to create DLL
47
+
48
+ DLL can be created using MinGW+MSYS with the `make libzstd` command.
49
+ This command creates `dll\libzstd.dll` and the import library `dll\libzstd.lib`.
50
+ The import library is only required with Visual C++.
51
+ The header file `zstd.h` and the dynamic library `dll\libzstd.dll` are required to
52
+ compile a project using gcc/MinGW.
53
+ The dynamic library has to be added to linking options.
54
+ It means that if a project that uses ZSTD consists of a single `test-dll.c`
55
+ file it should be linked with `dll\libzstd.dll`. For example:
56
+ ```
57
+ gcc $(CFLAGS) -Iinclude/ test-dll.c -o test-dll dll\libzstd.dll
58
+ ```
59
+ The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`.
60
+
61
+
62
+ #### Obsolete streaming API
63
+
64
+ Streaming is now provided within `zstd.h`.
65
+ Older streaming API is still available within `deprecated/zbuff.h`.
66
+ It will be removed in a future version.
67
+ Consider migrating code towards newer streaming API in `zstd.h`.
68
+
69
+
70
+ #### Miscellaneous
71
+
72
+ The other files are not source code. There are :
73
+
74
+ - LICENSE : contains the BSD license text
75
+ - Makefile : script to compile or install zstd library (static and dynamic)
76
+ - libzstd.pc.in : for pkg-config (`make install`)
77
+ - README.md : this file
@@ -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)
@@ -266,7 +269,7 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
266
269
  bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
267
270
  bitD->bitContainer = MEM_readLEST(bitD->ptr);
268
271
  { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
269
- bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
272
+ bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */
270
273
  if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
271
274
  } else {
272
275
  bitD->start = (const char*)srcBuffer;
@@ -298,7 +301,7 @@ MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
298
301
 
299
302
  MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
300
303
  {
301
- #if defined(__BMI__) && defined(__GNUC__) /* experimental */
304
+ #if defined(__BMI__) && defined(__GNUC__) && __GNUC__*1000+__GNUC_MINOR__ >= 4008 /* experimental */
302
305
  # if defined(__x86_64__)
303
306
  if (sizeof(bitContainer)==8)
304
307
  return _bextr_u64(bitContainer, start, nbBits);
@@ -367,10 +370,10 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
367
370
  }
368
371
 
369
372
  /*! BIT_reloadDStream() :
370
- * Refill `BIT_DStream_t` from src buffer previously defined (see BIT_initDStream() ).
373
+ * Refill `bitD` from buffer previously set in BIT_initDStream() .
371
374
  * This function is safe, it guarantees it will not read beyond src buffer.
372
375
  * @return : status of `BIT_DStream_t` internal register.
373
- if status == unfinished, internal register is filled with >= (sizeof(bitD->bitContainer)*8 - 7) bits */
376
+ if status == BIT_DStream_unfinished, internal register is filled with >= (sizeof(bitD->bitContainer)*8 - 7) bits */
374
377
  MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
375
378
  {
376
379
  if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should not happen => corruption detected */
@@ -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--;
@@ -159,6 +153,7 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
159
153
  /*! HUF_readStats() :
160
154
  Read compact Huffman tree, saved by HUF_writeCTable().
161
155
  `huffWeight` is destination buffer.
156
+ `rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
162
157
  @return : size read from `src` , or an error Code .
163
158
  Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
164
159
  */
@@ -187,16 +182,17 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
187
182
  huffWeight[n+1] = ip[n/2] & 15;
188
183
  } } }
189
184
  else { /* header compressed with FSE (normal case) */
185
+ FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
190
186
  if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
191
- oSize = FSE_decompress(huffWeight, hwSize-1, ip+1, iSize); /* max (hwSize-1) values decoded, as last one is implied */
187
+ oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */
192
188
  if (FSE_isError(oSize)) return oSize;
193
189
  }
194
190
 
195
191
  /* collect weight stats */
196
- memset(rankStats, 0, (HUF_TABLELOG_ABSOLUTEMAX + 1) * sizeof(U32));
192
+ memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
197
193
  weightTotal = 0;
198
194
  { U32 n; for (n=0; n<oSize; n++) {
199
- if (huffWeight[n] >= HUF_TABLELOG_ABSOLUTEMAX) return ERROR(corruption_detected);
195
+ if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
200
196
  rankStats[huffWeight[n]]++;
201
197
  weightTotal += (1 << huffWeight[n]) >> 1;
202
198
  } }
@@ -204,7 +200,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
204
200
 
205
201
  /* get last non-null symbol weight (implied, total must be 2^n) */
206
202
  { U32 const tableLog = BIT_highbit32(weightTotal) + 1;
207
- if (tableLog > HUF_TABLELOG_ABSOLUTEMAX) return ERROR(corruption_detected);
203
+ if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
208
204
  *tableLogPtr = tableLog;
209
205
  /* determine last weight */
210
206
  { U32 const total = 1 << tableLog;
File without changes
File without changes