zstd-ruby 1.3.1.1 → 1.3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/zstdruby/libzstd/.gitignore +1 -0
  4. data/ext/zstdruby/libzstd/Makefile +40 -26
  5. data/ext/zstdruby/libzstd/README.md +68 -45
  6. data/ext/zstdruby/libzstd/common/bitstream.h +35 -23
  7. data/ext/zstdruby/libzstd/common/compiler.h +1 -0
  8. data/ext/zstdruby/libzstd/common/error_private.c +4 -2
  9. data/ext/zstdruby/libzstd/common/error_private.h +4 -4
  10. data/ext/zstdruby/libzstd/common/fse.h +1 -1
  11. data/ext/zstdruby/libzstd/common/huf.h +1 -1
  12. data/ext/zstdruby/libzstd/common/mem.h +1 -0
  13. data/ext/zstdruby/libzstd/common/pool.c +61 -46
  14. data/ext/zstdruby/libzstd/common/pool.h +4 -0
  15. data/ext/zstdruby/libzstd/common/threading.c +11 -15
  16. data/ext/zstdruby/libzstd/common/threading.h +52 -32
  17. data/ext/zstdruby/libzstd/common/zstd_common.c +2 -2
  18. data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
  19. data/ext/zstdruby/libzstd/common/zstd_internal.h +95 -21
  20. data/ext/zstdruby/libzstd/compress/fse_compress.c +3 -1
  21. data/ext/zstdruby/libzstd/compress/huf_compress.c +4 -3
  22. data/ext/zstdruby/libzstd/compress/zstd_compress.c +922 -2102
  23. data/ext/zstdruby/libzstd/compress/zstd_compress.h +307 -0
  24. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +308 -0
  25. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +28 -0
  26. data/ext/zstdruby/libzstd/compress/zstd_fast.c +242 -0
  27. data/ext/zstdruby/libzstd/compress/zstd_fast.h +30 -0
  28. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +749 -0
  29. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +38 -0
  30. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +707 -0
  31. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +67 -0
  32. data/ext/zstdruby/libzstd/compress/zstd_opt.c +957 -0
  33. data/ext/zstdruby/libzstd/compress/zstd_opt.h +14 -922
  34. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +210 -133
  35. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +20 -3
  36. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +373 -196
  37. data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -0
  38. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -0
  39. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -0
  40. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -0
  41. data/ext/zstdruby/libzstd/dictBuilder/cover.c +33 -22
  42. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +8 -5
  43. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +1 -0
  44. data/ext/zstdruby/libzstd/dll/example/Makefile +5 -5
  45. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -0
  46. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +1 -0
  47. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -0
  48. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +1 -0
  49. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -0
  50. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +1 -0
  51. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -0
  52. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +1 -0
  53. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -0
  54. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +1 -0
  55. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -0
  56. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +1 -0
  57. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -0
  58. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +1 -0
  59. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -0
  60. data/ext/zstdruby/libzstd/zstd.h +366 -118
  61. data/lib/zstd-ruby/version.rb +1 -1
  62. metadata +11 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94a56402c61bd26301a2e7b7283641f5f20a1ef8
4
- data.tar.gz: 2f677687590b21d6d7eaac5e32821e61329e8394
3
+ metadata.gz: a3ec9d9502cfbffe84f2b05b9af56f3c2cf4d10c
4
+ data.tar.gz: 343ba202deae64999f24b3e75d9bdf9efa1d6c47
5
5
  SHA512:
6
- metadata.gz: 26e898a1075a13c3f20f9b9bc80cf6475d40697096a99f5aab46266a4ecc8079982634603fb4d99c999fd5436e642554ac043f7973f4023505e5387c255cb7f8
7
- data.tar.gz: 61bcdcf4ef08f8fa54b5962abac10db0ffaee0170b80ca7546d4751baf9e1dd7f259a27c5607cda774d412f0eaa0a3d99bbc657cc64291eac499b732f06707d3
6
+ metadata.gz: fa08f0458b2b2c66390fbc83e7719f7976de1de4ea6508dc5f834405c624ac446337bdcf186daab047f66f6fdb70b4bf01fde68d3050997e9f52729ef07c3006
7
+ data.tar.gz: da151831f7354ec3f3d000f32aa5d55b846f22e4aebb00ded8db412fcfa7921c0e005b2c24126ef07c4a4cde4eadc7230a9f53f4601798b33053f1f7583e9434
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.3.1 (https://github.com/facebook/zstd/tree/v1.3.1)
12
+ v1.3.2 (https://github.com/facebook/zstd/tree/v1.3.2)
13
13
 
14
14
  ## Installation
15
15
 
@@ -1,2 +1,3 @@
1
1
  # make install artefact
2
2
  libzstd.pc
3
+ libzstd-nomt
@@ -1,13 +1,11 @@
1
- # ##########################################################################
2
- # Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
1
+ # ################################################################
2
+ # Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
3
3
  # All rights reserved.
4
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
- # ##########################################################################
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
+ # ################################################################
11
9
 
12
10
  # Version numbers
13
11
  LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
@@ -31,7 +29,7 @@ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
31
29
  FLAGS = $(CPPFLAGS) $(CFLAGS)
32
30
 
33
31
 
34
- ZSTD_FILES := $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)
32
+ ZSTD_FILES := $(sort $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c))
35
33
 
36
34
  ZSTD_LEGACY_SUPPORT ?= 4
37
35
 
@@ -103,10 +101,19 @@ lib-release lib-release-mt: DEBUGFLAGS :=
103
101
  lib-release: lib
104
102
  lib-release-mt: lib-mt
105
103
 
104
+ # Special case : building library in single-thread mode _and_ without zstdmt_compress.c
105
+ ZSTDMT_FILES = compress/zstdmt_compress.c
106
+ ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
107
+ libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
108
+ libzstd-nomt: $(ZSTD_NOMT_FILES)
109
+ @echo compiling single-thread dynamic library $(LIBVER)
110
+ @echo files : $(ZSTD_NOMT_FILES)
111
+ @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
112
+
106
113
  clean:
107
114
  @$(RM) -r *.dSYM # Mac OS-X specific
108
115
  @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
109
- @$(RM) dll/libzstd.dll dll/libzstd.lib
116
+ @$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
110
117
  @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
111
118
  @echo Cleaning library completed
112
119
 
@@ -115,16 +122,17 @@ clean:
115
122
  #-----------------------------------------------------------------------------
116
123
  ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
117
124
 
118
- ifneq (,$(filter $(shell uname),SunOS))
119
- INSTALL ?= ginstall
120
- else
121
- INSTALL ?= install
122
- endif
123
-
124
- PREFIX ?= /usr/local
125
- DESTDIR ?=
126
- LIBDIR ?= $(PREFIX)/lib
127
- INCLUDEDIR ?= $(PREFIX)/include
125
+ DESTDIR ?=
126
+ # directory variables : GNU conventions prefer lowercase
127
+ # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
128
+ # support both lower and uppercase (BSD), use uppercase in script
129
+ prefix ?= /usr/local
130
+ PREFIX ?= $(prefix)
131
+ exec_prefix ?= $(PREFIX)
132
+ libdir ?= $(exec_prefix)/lib
133
+ LIBDIR ?= $(libdir)
134
+ includedir ?= $(PREFIX)/include
135
+ INCLUDEDIR ?= $(includedir)
128
136
 
129
137
  ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly))
130
138
  PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
@@ -132,8 +140,14 @@ else
132
140
  PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
133
141
  endif
134
142
 
135
- INSTALL_LIB ?= $(INSTALL) -m 755
136
- INSTALL_DATA ?= $(INSTALL) -m 644
143
+ ifneq (,$(filter $(shell uname),SunOS))
144
+ INSTALL ?= ginstall
145
+ else
146
+ INSTALL ?= install
147
+ endif
148
+
149
+ INSTALL_PROGRAM ?= $(INSTALL)
150
+ INSTALL_DATA ?= $(INSTALL) -m 644
137
151
 
138
152
 
139
153
  libzstd.pc:
@@ -150,9 +164,9 @@ install: libzstd.a libzstd libzstd.pc
150
164
  @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
151
165
  @echo Installing libraries
152
166
  @$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
153
- @$(INSTALL_LIB) libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)
154
- @ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
155
- @ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
167
+ @$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
168
+ @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
169
+ @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
156
170
  @echo Installing includes
157
171
  @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
158
172
  @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
@@ -164,7 +178,7 @@ uninstall:
164
178
  @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
165
179
  @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
166
180
  @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
167
- @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_VER)
181
+ @$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
168
182
  @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
169
183
  @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
170
184
  @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
@@ -1,57 +1,78 @@
1
1
  Zstandard library files
2
2
  ================================
3
3
 
4
- The __lib__ directory contains several directories.
5
- Depending on target use case, it's enough to include only files from relevant directories.
4
+ The __lib__ directory is split into several sub-directories,
5
+ in order to make it easier to select or exclude specific features.
6
+
7
+
8
+ #### Building
9
+
10
+ `Makefile` script is provided, supporting the standard set of commands,
11
+ directories, and variables (see https://www.gnu.org/prep/standards/html_node/Command-Variables.html).
12
+ - `make` : generates both static and dynamic libraries
13
+ - `make install` : install libraries in default system directories
6
14
 
7
15
 
8
16
  #### API
9
17
 
10
- Zstandard's stable API is exposed within [zstd.h](zstd.h),
11
- at the root of `lib` directory.
18
+ Zstandard's stable API is exposed within [lib/zstd.h](zstd.h).
12
19
 
13
20
 
14
21
  #### Advanced API
15
22
 
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.
23
+ Optional advanced features are exposed via :
24
+
25
+ - `lib/common/zstd_errors.h` : translates `size_t` function results
26
+ into an `ZSTD_ErrorCode`, for accurate error handling.
27
+ - `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`,
28
+ it unlocks access to advanced experimental API,
29
+ exposed in second part of `zstd.h`.
21
30
  These APIs shall ___never be used with dynamic library___ !
22
31
  They are not "stable", their definition may change in the future.
23
32
  Only static linking is allowed.
24
33
 
25
- #### ZSTDMT API
26
-
27
- To enable multithreaded compression within the library, invoke `make lib-mt` target.
28
- Prototypes are defined in header file `compress/zstdmt_compress.h`.
29
- When linking a program that uses ZSTDMT API against libzstd.a on a POSIX system,
30
- `-pthread` flag must be provided to the compiler and linker.
31
- Note : ZSTDMT prototypes can still be used with a library built without multithread support,
32
- but in this case, they will be single threaded only.
33
34
 
34
35
  #### Modular build
35
36
 
36
- Directory `common/` is required in all circumstances.
37
- You can select to support compression only, by just adding files from the `compress/` directory,
38
- In a similar way, you can build a decompressor-only library with the `decompress/` directory.
39
-
40
- Other optional functionalities provided are :
41
-
42
- - `dictBuilder/` : source files to create dictionaries.
43
- The API can be consulted in `dictBuilder/zdict.h`.
44
- This module also depends on `common/` and `compress/` .
45
-
46
- - `legacy/` : source code to decompress previous versions of zstd, starting from `v0.1`.
47
- This module also depends on `common/` and `decompress/` .
48
- Library compilation must include directive `ZSTD_LEGACY_SUPPORT = 1` .
49
- The main API can be consulted in `legacy/zstd_legacy.h`.
50
- Advanced API from each version can be found in their relevant header file.
51
- For example, advanced API for version `v0.4` is in `legacy/zstd_v04.h` .
52
-
53
-
54
- #### Using MinGW+MSYS to create DLL
37
+ - Directory `lib/common` is always required, for all variants.
38
+ - Compression source code lies in `lib/compress`
39
+ - Decompression source code lies in `lib/decompress`
40
+ - It's possible to include only `compress` or only `decompress`, they don't depend on each other.
41
+ - `lib/dictBuilder` : makes it possible to generate dictionaries from a set of samples.
42
+ The API is exposed in `lib/dictBuilder/zdict.h`.
43
+ This module depends on both `lib/common` and `lib/compress` .
44
+ - `lib/legacy` : source code to decompress older zstd formats, starting from `v0.1`.
45
+ This module depends on `lib/common` and `lib/decompress`.
46
+ To enable this feature, it's necessary to define `ZSTD_LEGACY_SUPPORT = 1` during compilation.
47
+ Typically, with `gcc`, add argument `-DZSTD_LEGACY_SUPPORT=1`.
48
+ Using higher number limits the number of version supported.
49
+ For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats starting from v0.2+".
50
+ The API is exposed in `lib/legacy/zstd_legacy.h`.
51
+ Each version also provides a (dedicated) set of advanced API.
52
+ For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
53
+
54
+
55
+ #### Multithreading support
56
+
57
+ Multithreading is disabled by default when building with `make`.
58
+ Enabling multithreading requires 2 conditions :
59
+ - set macro `ZSTD_MULTITHREAD`
60
+ - on POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc` for example)
61
+
62
+ Both conditions are automatically triggered by invoking `make lib-mt` target.
63
+ Note that, when linking a POSIX program with a multithreaded version of `libzstd`,
64
+ it's necessary to trigger `-pthread` flag during link stage.
65
+
66
+ Multithreading capabilities are exposed via :
67
+ - private API `lib/compress/zstdmt_compress.h`.
68
+ Symbols defined in this header are currently exposed in `libzstd`, hence usable.
69
+ Note however that this API is planned to be locked and remain strictly internal in the future.
70
+ - advanced API `ZSTD_compress_generic()`, defined in `lib/zstd.h`, experimental section.
71
+ This API is still considered experimental, but is designed to be labelled "stable" at some point in the future.
72
+ It's the recommended entry point for multi-threading operations.
73
+
74
+
75
+ #### Windows : using MinGW+MSYS to create DLL
55
76
 
56
77
  DLL can be created using MinGW+MSYS with the `make libzstd` command.
57
78
  This command creates `dll\libzstd.dll` and the import library `dll\libzstd.lib`.
@@ -67,19 +88,21 @@ file it should be linked with `dll\libzstd.dll`. For example:
67
88
  The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`.
68
89
 
69
90
 
70
- #### Obsolete streaming API
91
+ #### Deprecated API
71
92
 
72
- Streaming is now provided within `zstd.h`.
73
- Older streaming API is still available within `deprecated/zbuff.h`.
74
- It will be removed in a future version.
75
- Consider migrating code towards newer streaming API in `zstd.h`.
93
+ Obsolete API on their way out are stored in directory `lib/deprecated`.
94
+ At this stage, it contains older streaming prototypes, in `lib/deprecated/zbuff.h`.
95
+ Presence in this directory is temporary.
96
+ These prototypes will be removed in some future version.
97
+ Consider migrating code towards supported streaming API exposed in `zstd.h`.
76
98
 
77
99
 
78
100
  #### Miscellaneous
79
101
 
80
102
  The other files are not source code. There are :
81
103
 
82
- - LICENSE : contains the BSD license text
83
- - Makefile : script to compile or install zstd library (static and dynamic)
84
- - libzstd.pc.in : for pkg-config (`make install`)
85
- - README.md : this file
104
+ - `LICENSE` : contains the BSD license text
105
+ - `Makefile` : `make` script to build and install zstd library (static and dynamic)
106
+ - `BUCK` : support for `buck` build system (https://buckbuild.com/)
107
+ - `libzstd.pc.in` : for `pkg-config` (used in `make install`)
108
+ - `README.md` : this file
@@ -169,33 +169,39 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
169
169
  ****************************************************************/
170
170
  MEM_STATIC unsigned BIT_highbit32 (register U32 val)
171
171
  {
172
+ assert(val != 0);
173
+ {
172
174
  # if defined(_MSC_VER) /* Visual */
173
- unsigned long r=0;
174
- _BitScanReverse ( &r, val );
175
- return (unsigned) r;
175
+ unsigned long r=0;
176
+ _BitScanReverse ( &r, val );
177
+ return (unsigned) r;
176
178
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
177
- return 31 - __builtin_clz (val);
179
+ return 31 - __builtin_clz (val);
178
180
  # else /* Software version */
179
- static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
180
- 11, 14, 16, 18, 22, 25, 3, 30,
181
- 8, 12, 20, 28, 15, 17, 24, 7,
182
- 19, 27, 23, 6, 26, 5, 4, 31 };
183
- U32 v = val;
184
- v |= v >> 1;
185
- v |= v >> 2;
186
- v |= v >> 4;
187
- v |= v >> 8;
188
- v |= v >> 16;
189
- return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27];
181
+ static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
182
+ 11, 14, 16, 18, 22, 25, 3, 30,
183
+ 8, 12, 20, 28, 15, 17, 24, 7,
184
+ 19, 27, 23, 6, 26, 5, 4, 31 };
185
+ U32 v = val;
186
+ v |= v >> 1;
187
+ v |= v >> 2;
188
+ v |= v >> 4;
189
+ v |= v >> 8;
190
+ v |= v >> 16;
191
+ return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27];
190
192
  # endif
193
+ }
191
194
  }
192
195
 
193
196
  /*===== Local Constants =====*/
194
- static const unsigned BIT_mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F,
195
- 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF,
196
- 0xFFFF, 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF,
197
- 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF }; /* up to 26 bits */
198
-
197
+ static const unsigned BIT_mask[] = {
198
+ 0, 1, 3, 7, 0xF, 0x1F,
199
+ 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF,
200
+ 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF,
201
+ 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF,
202
+ 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF,
203
+ 0x3FFFFFFF, 0x7FFFFFFF}; /* up to 31 bits */
204
+ #define BIT_MASK_SIZE (sizeof(BIT_mask) / sizeof(BIT_mask[0]))
199
205
 
200
206
  /*-**************************************************************
201
207
  * bitStream encoding
@@ -217,11 +223,14 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
217
223
  }
218
224
 
219
225
  /*! BIT_addBits() :
220
- * can add up to 26 bits into `bitC`.
226
+ * can add up to 31 bits into `bitC`.
221
227
  * Note : does not check for register overflow ! */
222
228
  MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
223
229
  size_t value, unsigned nbBits)
224
230
  {
231
+ MEM_STATIC_ASSERT(BIT_MASK_SIZE == 32);
232
+ assert(nbBits < BIT_MASK_SIZE);
233
+ assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
234
  bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
226
235
  bitC->bitPos += nbBits;
227
236
  }
@@ -232,6 +241,7 @@ MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
232
241
  size_t value, unsigned nbBits)
233
242
  {
234
243
  assert((value>>nbBits) == 0);
244
+ assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
235
245
  bitC->bitContainer |= value << bitC->bitPos;
236
246
  bitC->bitPos += nbBits;
237
247
  }
@@ -242,7 +252,7 @@ MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
242
252
  MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC)
243
253
  {
244
254
  size_t const nbBytes = bitC->bitPos >> 3;
245
- assert( bitC->bitPos <= (sizeof(bitC->bitContainer)*8) );
255
+ assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
246
256
  MEM_writeLEST(bitC->ptr, bitC->bitContainer);
247
257
  bitC->ptr += nbBytes;
248
258
  assert(bitC->ptr <= bitC->endPtr);
@@ -258,7 +268,7 @@ MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC)
258
268
  MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC)
259
269
  {
260
270
  size_t const nbBytes = bitC->bitPos >> 3;
261
- assert( bitC->bitPos <= (sizeof(bitC->bitContainer)*8) );
271
+ assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
262
272
  MEM_writeLEST(bitC->ptr, bitC->bitContainer);
263
273
  bitC->ptr += nbBytes;
264
274
  if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
@@ -350,12 +360,14 @@ MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 co
350
360
  # endif
351
361
  return _bextr_u32(bitContainer, start, nbBits);
352
362
  #else
363
+ assert(nbBits < BIT_MASK_SIZE);
353
364
  return (bitContainer >> start) & BIT_mask[nbBits];
354
365
  #endif
355
366
  }
356
367
 
357
368
  MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
358
369
  {
370
+ assert(nbBits < BIT_MASK_SIZE);
359
371
  return bitContainer & BIT_mask[nbBits];
360
372
  }
361
373
 
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under both the BSD-style license (found in the
6
6
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
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.
8
9
  */
9
10
 
10
11
  #ifndef ZSTD_COMPILER_H
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under both the BSD-style license (found in the
6
6
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
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.
8
9
  */
9
10
 
10
11
  /* The purpose of this file is to have a single list of error strings embedded in binary */
@@ -29,14 +30,15 @@ const char* ERR_getErrorString(ERR_enum code)
29
30
  case PREFIX(init_missing): return "Context should be init first";
30
31
  case PREFIX(memory_allocation): return "Allocation error : not enough memory";
31
32
  case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
32
- case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
33
- case PREFIX(srcSize_wrong): return "Src size is incorrect";
34
33
  case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
35
34
  case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
36
35
  case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
37
36
  case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
38
37
  case PREFIX(dictionary_wrong): return "Dictionary mismatch";
39
38
  case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
39
+ case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
40
+ case PREFIX(srcSize_wrong): return "Src size is incorrect";
41
+ /* following error codes are not stable and may be removed or changed in a future version */
40
42
  case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
41
43
  case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
42
44
  case PREFIX(maxCode):
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under both the BSD-style license (found in the
6
6
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
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.
8
9
  */
9
10
 
10
11
  /* Note : this module is expected to remain private, do not expose it */
@@ -48,10 +49,9 @@ typedef ZSTD_ErrorCode ERR_enum;
48
49
  /*-****************************************
49
50
  * Error codes handling
50
51
  ******************************************/
51
- #ifdef ERROR
52
- # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
53
- #endif
54
- #define ERROR(name) ((size_t)-PREFIX(name))
52
+ #undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
53
+ #define ERROR(name) ZSTD_ERROR(name)
54
+ #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
55
55
 
56
56
  ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
57
57