zstdlib 0.6.0-x86-mingw32 → 0.9.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +20 -0
- data/README.md +7 -1
- data/Rakefile +38 -8
- data/ext/{zstdlib → zstdlib_c}/extconf.rb +10 -5
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
- data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/adler32.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/compress.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzclose.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzguts.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzlib.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzread.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzwrite.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/infback.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffixed.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/uncompr.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zconf.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zlib.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.c +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.h +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
- data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +75 -57
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +1 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/debug.c +24 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +22 -49
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +3 -1
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +51 -42
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +149 -57
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +60 -54
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +87 -98
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +34 -23
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +5 -5
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +10 -8
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +4 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +10 -10
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_internal.h +493 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +105 -85
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +41 -63
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +13 -33
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress.c +6327 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +537 -82
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +21 -16
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +4 -2
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +61 -34
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +10 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.c +573 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +236 -95
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +321 -143
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +2 -2
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +328 -137
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +2 -2
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +336 -209
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +15 -3
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +439 -239
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +1 -1
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +205 -462
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress.c +1889 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +20 -16
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +3 -3
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +691 -230
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress_block.c +2072 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +16 -7
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +71 -10
- data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +760 -234
- data/ext/{zstdlib/zstd-1.4.4/lib/common → zstdlib_c/zstd-1.5.2/lib}/zstd_errors.h +3 -1
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +1 -1
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +133 -44
- data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +1 -1
- data/ext/zstdlib_c/zstd.mk +15 -0
- data/lib/2.4/zstdlib_c.so +0 -0
- data/lib/2.5/zstdlib_c.so +0 -0
- data/lib/2.6/zstdlib_c.so +0 -0
- data/lib/2.7/zstdlib_c.so +0 -0
- data/lib/3.0/zstdlib_c.so +0 -0
- data/lib/3.1/zstdlib_c.so +0 -0
- data/lib/zstdlib.rb +2 -2
- metadata +125 -114
- data/ext/zstdlib/zstd-1.4.4/lib/common/compiler.h +0 -159
- data/ext/zstdlib/zstd-1.4.4/lib/common/debug.c +0 -44
- data/ext/zstdlib/zstd-1.4.4/lib/common/entropy_common.c +0 -236
- data/ext/zstdlib/zstd-1.4.4/lib/common/error_private.h +0 -76
- data/ext/zstdlib/zstd-1.4.4/lib/common/xxhash.c +0 -882
- data/ext/zstdlib/zstd-1.4.4/lib/common/xxhash.h +0 -305
- data/ext/zstdlib/zstd-1.4.4/lib/common/zstd_internal.h +0 -350
- data/ext/zstdlib/zstd-1.4.4/lib/compress/huf_compress.c +0 -798
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_compress.c +0 -4103
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_lazy.c +0 -1115
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_lazy.h +0 -67
- data/ext/zstdlib/zstd-1.4.4/lib/compress/zstdmt_compress.h +0 -192
- data/ext/zstdlib/zstd-1.4.4/lib/decompress/huf_decompress.c +0 -1234
- data/ext/zstdlib/zstd-1.4.4/lib/decompress/zstd_decompress_block.c +0 -1323
- data/ext/zstdlib/zstd.mk +0 -14
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/2.7/zstdlib.so +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -16,8 +16,6 @@
|
|
16
16
|
* https://github.com/facebook/folly/blob/master/folly/CpuId.h
|
17
17
|
*/
|
18
18
|
|
19
|
-
#include <string.h>
|
20
|
-
|
21
19
|
#include "mem.h"
|
22
20
|
|
23
21
|
#ifdef _MSC_VER
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/* ******************************************************************
|
2
|
+
* debug
|
3
|
+
* Part of FSE library
|
4
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
5
|
+
*
|
6
|
+
* You can contact the author at :
|
7
|
+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
8
|
+
*
|
9
|
+
* This source code is licensed under both the BSD-style license (found in the
|
10
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
11
|
+
* in the COPYING file in the root directory of this source tree).
|
12
|
+
* You may select, at your option, one of the above-listed licenses.
|
13
|
+
****************************************************************** */
|
14
|
+
|
15
|
+
|
16
|
+
/*
|
17
|
+
* This module only hosts one global variable
|
18
|
+
* which can be used to dynamically influence the verbosity of traces,
|
19
|
+
* such as DEBUGLOG and RAWLOG
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "debug.h"
|
23
|
+
|
24
|
+
int g_debuglevel = DEBUGLEVEL;
|
@@ -1,35 +1,15 @@
|
|
1
1
|
/* ******************************************************************
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
2
|
+
* debug
|
3
|
+
* Part of FSE library
|
4
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
5
|
+
*
|
6
|
+
* You can contact the author at :
|
7
|
+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
8
|
+
*
|
9
|
+
* This source code is licensed under both the BSD-style license (found in the
|
10
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
11
|
+
* in the COPYING file in the root directory of this source tree).
|
12
|
+
* You may select, at your option, one of the above-listed licenses.
|
33
13
|
****************************************************************** */
|
34
14
|
|
35
15
|
|
@@ -71,15 +51,6 @@ extern "C" {
|
|
71
51
|
#endif
|
72
52
|
|
73
53
|
|
74
|
-
/* DEBUGFILE can be defined externally,
|
75
|
-
* typically through compiler command line.
|
76
|
-
* note : currently useless.
|
77
|
-
* Value must be stderr or stdout */
|
78
|
-
#ifndef DEBUGFILE
|
79
|
-
# define DEBUGFILE stderr
|
80
|
-
#endif
|
81
|
-
|
82
|
-
|
83
54
|
/* recommended values for DEBUGLEVEL :
|
84
55
|
* 0 : release mode, no debug, all run-time checks disabled
|
85
56
|
* 1 : enables assert() only, no display
|
@@ -96,7 +67,8 @@ extern "C" {
|
|
96
67
|
*/
|
97
68
|
|
98
69
|
#if (DEBUGLEVEL>=1)
|
99
|
-
#
|
70
|
+
# define ZSTD_DEPS_NEED_ASSERT
|
71
|
+
# include "zstd_deps.h"
|
100
72
|
#else
|
101
73
|
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
|
102
74
|
# define assert(condition) ((void)0) /* disable assert (default) */
|
@@ -104,7 +76,8 @@ extern "C" {
|
|
104
76
|
#endif
|
105
77
|
|
106
78
|
#if (DEBUGLEVEL>=2)
|
107
|
-
#
|
79
|
+
# define ZSTD_DEPS_NEED_IO
|
80
|
+
# include "zstd_deps.h"
|
108
81
|
extern int g_debuglevel; /* the variable is only declared,
|
109
82
|
it actually lives in debug.c,
|
110
83
|
and is shared by the whole process.
|
@@ -112,14 +85,14 @@ extern int g_debuglevel; /* the variable is only declared,
|
|
112
85
|
It's useful when enabling very verbose levels
|
113
86
|
on selective conditions (such as position in src) */
|
114
87
|
|
115
|
-
# define RAWLOG(l, ...) {
|
116
|
-
if (l<=g_debuglevel) {
|
117
|
-
|
88
|
+
# define RAWLOG(l, ...) { \
|
89
|
+
if (l<=g_debuglevel) { \
|
90
|
+
ZSTD_DEBUG_PRINT(__VA_ARGS__); \
|
118
91
|
} }
|
119
|
-
# define DEBUGLOG(l, ...) {
|
120
|
-
if (l<=g_debuglevel) {
|
121
|
-
|
122
|
-
|
92
|
+
# define DEBUGLOG(l, ...) { \
|
93
|
+
if (l<=g_debuglevel) { \
|
94
|
+
ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
|
95
|
+
ZSTD_DEBUG_PRINT(" \n"); \
|
123
96
|
} }
|
124
97
|
#else
|
125
98
|
# define RAWLOG(l, ...) {} /* disabled */
|
@@ -0,0 +1,368 @@
|
|
1
|
+
/* ******************************************************************
|
2
|
+
* Common functions of New Generation Entropy library
|
3
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
4
|
+
*
|
5
|
+
* You can contact the author at :
|
6
|
+
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
7
|
+
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
8
|
+
*
|
9
|
+
* This source code is licensed under both the BSD-style license (found in the
|
10
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
11
|
+
* in the COPYING file in the root directory of this source tree).
|
12
|
+
* You may select, at your option, one of the above-listed licenses.
|
13
|
+
****************************************************************** */
|
14
|
+
|
15
|
+
/* *************************************
|
16
|
+
* Dependencies
|
17
|
+
***************************************/
|
18
|
+
#include "mem.h"
|
19
|
+
#include "error_private.h" /* ERR_*, ERROR */
|
20
|
+
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
|
21
|
+
#include "fse.h"
|
22
|
+
#define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */
|
23
|
+
#include "huf.h"
|
24
|
+
|
25
|
+
|
26
|
+
/*=== Version ===*/
|
27
|
+
unsigned FSE_versionNumber(void) { return FSE_VERSION_NUMBER; }
|
28
|
+
|
29
|
+
|
30
|
+
/*=== Error Management ===*/
|
31
|
+
unsigned FSE_isError(size_t code) { return ERR_isError(code); }
|
32
|
+
const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
33
|
+
|
34
|
+
unsigned HUF_isError(size_t code) { return ERR_isError(code); }
|
35
|
+
const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
36
|
+
|
37
|
+
|
38
|
+
/*-**************************************************************
|
39
|
+
* FSE NCount encoding-decoding
|
40
|
+
****************************************************************/
|
41
|
+
static U32 FSE_ctz(U32 val)
|
42
|
+
{
|
43
|
+
assert(val != 0);
|
44
|
+
{
|
45
|
+
# if defined(_MSC_VER) /* Visual */
|
46
|
+
if (val != 0) {
|
47
|
+
unsigned long r;
|
48
|
+
_BitScanForward(&r, val);
|
49
|
+
return (unsigned)r;
|
50
|
+
} else {
|
51
|
+
/* Should not reach this code path */
|
52
|
+
__assume(0);
|
53
|
+
}
|
54
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
55
|
+
return __builtin_ctz(val);
|
56
|
+
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
57
|
+
return __CTZ(val);
|
58
|
+
# else /* Software version */
|
59
|
+
U32 count = 0;
|
60
|
+
while ((val & 1) == 0) {
|
61
|
+
val >>= 1;
|
62
|
+
++count;
|
63
|
+
}
|
64
|
+
return count;
|
65
|
+
# endif
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
FORCE_INLINE_TEMPLATE
|
70
|
+
size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
71
|
+
const void* headerBuffer, size_t hbSize)
|
72
|
+
{
|
73
|
+
const BYTE* const istart = (const BYTE*) headerBuffer;
|
74
|
+
const BYTE* const iend = istart + hbSize;
|
75
|
+
const BYTE* ip = istart;
|
76
|
+
int nbBits;
|
77
|
+
int remaining;
|
78
|
+
int threshold;
|
79
|
+
U32 bitStream;
|
80
|
+
int bitCount;
|
81
|
+
unsigned charnum = 0;
|
82
|
+
unsigned const maxSV1 = *maxSVPtr + 1;
|
83
|
+
int previous0 = 0;
|
84
|
+
|
85
|
+
if (hbSize < 8) {
|
86
|
+
/* This function only works when hbSize >= 8 */
|
87
|
+
char buffer[8] = {0};
|
88
|
+
ZSTD_memcpy(buffer, headerBuffer, hbSize);
|
89
|
+
{ size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
|
90
|
+
buffer, sizeof(buffer));
|
91
|
+
if (FSE_isError(countSize)) return countSize;
|
92
|
+
if (countSize > hbSize) return ERROR(corruption_detected);
|
93
|
+
return countSize;
|
94
|
+
} }
|
95
|
+
assert(hbSize >= 8);
|
96
|
+
|
97
|
+
/* init */
|
98
|
+
ZSTD_memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */
|
99
|
+
bitStream = MEM_readLE32(ip);
|
100
|
+
nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
|
101
|
+
if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
|
102
|
+
bitStream >>= 4;
|
103
|
+
bitCount = 4;
|
104
|
+
*tableLogPtr = nbBits;
|
105
|
+
remaining = (1<<nbBits)+1;
|
106
|
+
threshold = 1<<nbBits;
|
107
|
+
nbBits++;
|
108
|
+
|
109
|
+
for (;;) {
|
110
|
+
if (previous0) {
|
111
|
+
/* Count the number of repeats. Each time the
|
112
|
+
* 2-bit repeat code is 0b11 there is another
|
113
|
+
* repeat.
|
114
|
+
* Avoid UB by setting the high bit to 1.
|
115
|
+
*/
|
116
|
+
int repeats = FSE_ctz(~bitStream | 0x80000000) >> 1;
|
117
|
+
while (repeats >= 12) {
|
118
|
+
charnum += 3 * 12;
|
119
|
+
if (LIKELY(ip <= iend-7)) {
|
120
|
+
ip += 3;
|
121
|
+
} else {
|
122
|
+
bitCount -= (int)(8 * (iend - 7 - ip));
|
123
|
+
bitCount &= 31;
|
124
|
+
ip = iend - 4;
|
125
|
+
}
|
126
|
+
bitStream = MEM_readLE32(ip) >> bitCount;
|
127
|
+
repeats = FSE_ctz(~bitStream | 0x80000000) >> 1;
|
128
|
+
}
|
129
|
+
charnum += 3 * repeats;
|
130
|
+
bitStream >>= 2 * repeats;
|
131
|
+
bitCount += 2 * repeats;
|
132
|
+
|
133
|
+
/* Add the final repeat which isn't 0b11. */
|
134
|
+
assert((bitStream & 3) < 3);
|
135
|
+
charnum += bitStream & 3;
|
136
|
+
bitCount += 2;
|
137
|
+
|
138
|
+
/* This is an error, but break and return an error
|
139
|
+
* at the end, because returning out of a loop makes
|
140
|
+
* it harder for the compiler to optimize.
|
141
|
+
*/
|
142
|
+
if (charnum >= maxSV1) break;
|
143
|
+
|
144
|
+
/* We don't need to set the normalized count to 0
|
145
|
+
* because we already memset the whole buffer to 0.
|
146
|
+
*/
|
147
|
+
|
148
|
+
if (LIKELY(ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
149
|
+
assert((bitCount >> 3) <= 3); /* For first condition to work */
|
150
|
+
ip += bitCount>>3;
|
151
|
+
bitCount &= 7;
|
152
|
+
} else {
|
153
|
+
bitCount -= (int)(8 * (iend - 4 - ip));
|
154
|
+
bitCount &= 31;
|
155
|
+
ip = iend - 4;
|
156
|
+
}
|
157
|
+
bitStream = MEM_readLE32(ip) >> bitCount;
|
158
|
+
}
|
159
|
+
{
|
160
|
+
int const max = (2*threshold-1) - remaining;
|
161
|
+
int count;
|
162
|
+
|
163
|
+
if ((bitStream & (threshold-1)) < (U32)max) {
|
164
|
+
count = bitStream & (threshold-1);
|
165
|
+
bitCount += nbBits-1;
|
166
|
+
} else {
|
167
|
+
count = bitStream & (2*threshold-1);
|
168
|
+
if (count >= threshold) count -= max;
|
169
|
+
bitCount += nbBits;
|
170
|
+
}
|
171
|
+
|
172
|
+
count--; /* extra accuracy */
|
173
|
+
/* When it matters (small blocks), this is a
|
174
|
+
* predictable branch, because we don't use -1.
|
175
|
+
*/
|
176
|
+
if (count >= 0) {
|
177
|
+
remaining -= count;
|
178
|
+
} else {
|
179
|
+
assert(count == -1);
|
180
|
+
remaining += count;
|
181
|
+
}
|
182
|
+
normalizedCounter[charnum++] = (short)count;
|
183
|
+
previous0 = !count;
|
184
|
+
|
185
|
+
assert(threshold > 1);
|
186
|
+
if (remaining < threshold) {
|
187
|
+
/* This branch can be folded into the
|
188
|
+
* threshold update condition because we
|
189
|
+
* know that threshold > 1.
|
190
|
+
*/
|
191
|
+
if (remaining <= 1) break;
|
192
|
+
nbBits = BIT_highbit32(remaining) + 1;
|
193
|
+
threshold = 1 << (nbBits - 1);
|
194
|
+
}
|
195
|
+
if (charnum >= maxSV1) break;
|
196
|
+
|
197
|
+
if (LIKELY(ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
198
|
+
ip += bitCount>>3;
|
199
|
+
bitCount &= 7;
|
200
|
+
} else {
|
201
|
+
bitCount -= (int)(8 * (iend - 4 - ip));
|
202
|
+
bitCount &= 31;
|
203
|
+
ip = iend - 4;
|
204
|
+
}
|
205
|
+
bitStream = MEM_readLE32(ip) >> bitCount;
|
206
|
+
} }
|
207
|
+
if (remaining != 1) return ERROR(corruption_detected);
|
208
|
+
/* Only possible when there are too many zeros. */
|
209
|
+
if (charnum > maxSV1) return ERROR(maxSymbolValue_tooSmall);
|
210
|
+
if (bitCount > 32) return ERROR(corruption_detected);
|
211
|
+
*maxSVPtr = charnum-1;
|
212
|
+
|
213
|
+
ip += (bitCount+7)>>3;
|
214
|
+
return ip-istart;
|
215
|
+
}
|
216
|
+
|
217
|
+
/* Avoids the FORCE_INLINE of the _body() function. */
|
218
|
+
static size_t FSE_readNCount_body_default(
|
219
|
+
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
220
|
+
const void* headerBuffer, size_t hbSize)
|
221
|
+
{
|
222
|
+
return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
223
|
+
}
|
224
|
+
|
225
|
+
#if DYNAMIC_BMI2
|
226
|
+
BMI2_TARGET_ATTRIBUTE static size_t FSE_readNCount_body_bmi2(
|
227
|
+
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
228
|
+
const void* headerBuffer, size_t hbSize)
|
229
|
+
{
|
230
|
+
return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
231
|
+
}
|
232
|
+
#endif
|
233
|
+
|
234
|
+
size_t FSE_readNCount_bmi2(
|
235
|
+
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
236
|
+
const void* headerBuffer, size_t hbSize, int bmi2)
|
237
|
+
{
|
238
|
+
#if DYNAMIC_BMI2
|
239
|
+
if (bmi2) {
|
240
|
+
return FSE_readNCount_body_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
241
|
+
}
|
242
|
+
#endif
|
243
|
+
(void)bmi2;
|
244
|
+
return FSE_readNCount_body_default(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
245
|
+
}
|
246
|
+
|
247
|
+
size_t FSE_readNCount(
|
248
|
+
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
249
|
+
const void* headerBuffer, size_t hbSize)
|
250
|
+
{
|
251
|
+
return FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize, /* bmi2 */ 0);
|
252
|
+
}
|
253
|
+
|
254
|
+
|
255
|
+
/*! HUF_readStats() :
|
256
|
+
Read compact Huffman tree, saved by HUF_writeCTable().
|
257
|
+
`huffWeight` is destination buffer.
|
258
|
+
`rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
|
259
|
+
@return : size read from `src` , or an error Code .
|
260
|
+
Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
|
261
|
+
*/
|
262
|
+
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
263
|
+
U32* nbSymbolsPtr, U32* tableLogPtr,
|
264
|
+
const void* src, size_t srcSize)
|
265
|
+
{
|
266
|
+
U32 wksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
|
267
|
+
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* bmi2 */ 0);
|
268
|
+
}
|
269
|
+
|
270
|
+
FORCE_INLINE_TEMPLATE size_t
|
271
|
+
HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
272
|
+
U32* nbSymbolsPtr, U32* tableLogPtr,
|
273
|
+
const void* src, size_t srcSize,
|
274
|
+
void* workSpace, size_t wkspSize,
|
275
|
+
int bmi2)
|
276
|
+
{
|
277
|
+
U32 weightTotal;
|
278
|
+
const BYTE* ip = (const BYTE*) src;
|
279
|
+
size_t iSize;
|
280
|
+
size_t oSize;
|
281
|
+
|
282
|
+
if (!srcSize) return ERROR(srcSize_wrong);
|
283
|
+
iSize = ip[0];
|
284
|
+
/* ZSTD_memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
|
285
|
+
|
286
|
+
if (iSize >= 128) { /* special header */
|
287
|
+
oSize = iSize - 127;
|
288
|
+
iSize = ((oSize+1)/2);
|
289
|
+
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
290
|
+
if (oSize >= hwSize) return ERROR(corruption_detected);
|
291
|
+
ip += 1;
|
292
|
+
{ U32 n;
|
293
|
+
for (n=0; n<oSize; n+=2) {
|
294
|
+
huffWeight[n] = ip[n/2] >> 4;
|
295
|
+
huffWeight[n+1] = ip[n/2] & 15;
|
296
|
+
} } }
|
297
|
+
else { /* header compressed with FSE (normal case) */
|
298
|
+
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
299
|
+
/* max (hwSize-1) values decoded, as last one is implied */
|
300
|
+
oSize = FSE_decompress_wksp_bmi2(huffWeight, hwSize-1, ip+1, iSize, 6, workSpace, wkspSize, bmi2);
|
301
|
+
if (FSE_isError(oSize)) return oSize;
|
302
|
+
}
|
303
|
+
|
304
|
+
/* collect weight stats */
|
305
|
+
ZSTD_memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
|
306
|
+
weightTotal = 0;
|
307
|
+
{ U32 n; for (n=0; n<oSize; n++) {
|
308
|
+
if (huffWeight[n] > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
309
|
+
rankStats[huffWeight[n]]++;
|
310
|
+
weightTotal += (1 << huffWeight[n]) >> 1;
|
311
|
+
} }
|
312
|
+
if (weightTotal == 0) return ERROR(corruption_detected);
|
313
|
+
|
314
|
+
/* get last non-null symbol weight (implied, total must be 2^n) */
|
315
|
+
{ U32 const tableLog = BIT_highbit32(weightTotal) + 1;
|
316
|
+
if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
317
|
+
*tableLogPtr = tableLog;
|
318
|
+
/* determine last weight */
|
319
|
+
{ U32 const total = 1 << tableLog;
|
320
|
+
U32 const rest = total - weightTotal;
|
321
|
+
U32 const verif = 1 << BIT_highbit32(rest);
|
322
|
+
U32 const lastWeight = BIT_highbit32(rest) + 1;
|
323
|
+
if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
|
324
|
+
huffWeight[oSize] = (BYTE)lastWeight;
|
325
|
+
rankStats[lastWeight]++;
|
326
|
+
} }
|
327
|
+
|
328
|
+
/* check tree construction validity */
|
329
|
+
if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected); /* by construction : at least 2 elts of rank 1, must be even */
|
330
|
+
|
331
|
+
/* results */
|
332
|
+
*nbSymbolsPtr = (U32)(oSize+1);
|
333
|
+
return iSize+1;
|
334
|
+
}
|
335
|
+
|
336
|
+
/* Avoids the FORCE_INLINE of the _body() function. */
|
337
|
+
static size_t HUF_readStats_body_default(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
338
|
+
U32* nbSymbolsPtr, U32* tableLogPtr,
|
339
|
+
const void* src, size_t srcSize,
|
340
|
+
void* workSpace, size_t wkspSize)
|
341
|
+
{
|
342
|
+
return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 0);
|
343
|
+
}
|
344
|
+
|
345
|
+
#if DYNAMIC_BMI2
|
346
|
+
static BMI2_TARGET_ATTRIBUTE size_t HUF_readStats_body_bmi2(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
347
|
+
U32* nbSymbolsPtr, U32* tableLogPtr,
|
348
|
+
const void* src, size_t srcSize,
|
349
|
+
void* workSpace, size_t wkspSize)
|
350
|
+
{
|
351
|
+
return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 1);
|
352
|
+
}
|
353
|
+
#endif
|
354
|
+
|
355
|
+
size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
356
|
+
U32* nbSymbolsPtr, U32* tableLogPtr,
|
357
|
+
const void* src, size_t srcSize,
|
358
|
+
void* workSpace, size_t wkspSize,
|
359
|
+
int bmi2)
|
360
|
+
{
|
361
|
+
#if DYNAMIC_BMI2
|
362
|
+
if (bmi2) {
|
363
|
+
return HUF_readStats_body_bmi2(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
364
|
+
}
|
365
|
+
#endif
|
366
|
+
(void)bmi2;
|
367
|
+
return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
368
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -47,6 +47,8 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
47
47
|
/* following error codes are not stable and may be removed or changed in a future version */
|
48
48
|
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
49
49
|
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
50
|
+
case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
|
51
|
+
case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
|
50
52
|
case PREFIX(maxCode):
|
51
53
|
default: return notErrorCode;
|
52
54
|
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
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
|
+
/* Note : this module is expected to remain private, do not expose it */
|
12
|
+
|
13
|
+
#ifndef ERROR_H_MODULE
|
14
|
+
#define ERROR_H_MODULE
|
15
|
+
|
16
|
+
#if defined (__cplusplus)
|
17
|
+
extern "C" {
|
18
|
+
#endif
|
19
|
+
|
20
|
+
|
21
|
+
/* ****************************************
|
22
|
+
* Dependencies
|
23
|
+
******************************************/
|
24
|
+
#include "../zstd_errors.h" /* enum list */
|
25
|
+
#include "compiler.h"
|
26
|
+
#include "debug.h"
|
27
|
+
#include "zstd_deps.h" /* size_t */
|
28
|
+
|
29
|
+
|
30
|
+
/* ****************************************
|
31
|
+
* Compiler-specific
|
32
|
+
******************************************/
|
33
|
+
#if defined(__GNUC__)
|
34
|
+
# define ERR_STATIC static __attribute__((unused))
|
35
|
+
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
36
|
+
# define ERR_STATIC static inline
|
37
|
+
#elif defined(_MSC_VER)
|
38
|
+
# define ERR_STATIC static __inline
|
39
|
+
#else
|
40
|
+
# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
41
|
+
#endif
|
42
|
+
|
43
|
+
|
44
|
+
/*-****************************************
|
45
|
+
* Customization (error_public.h)
|
46
|
+
******************************************/
|
47
|
+
typedef ZSTD_ErrorCode ERR_enum;
|
48
|
+
#define PREFIX(name) ZSTD_error_##name
|
49
|
+
|
50
|
+
|
51
|
+
/*-****************************************
|
52
|
+
* Error codes handling
|
53
|
+
******************************************/
|
54
|
+
#undef ERROR /* already defined on Visual Studio */
|
55
|
+
#define ERROR(name) ZSTD_ERROR(name)
|
56
|
+
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
57
|
+
|
58
|
+
ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
|
59
|
+
|
60
|
+
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
|
61
|
+
|
62
|
+
/* check and forward error code */
|
63
|
+
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
64
|
+
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
65
|
+
|
66
|
+
|
67
|
+
/*-****************************************
|
68
|
+
* Error Strings
|
69
|
+
******************************************/
|
70
|
+
|
71
|
+
const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
|
72
|
+
|
73
|
+
ERR_STATIC const char* ERR_getErrorName(size_t code)
|
74
|
+
{
|
75
|
+
return ERR_getErrorString(ERR_getErrorCode(code));
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Ignore: this is an internal helper.
|
80
|
+
*
|
81
|
+
* This is a helper function to help force C99-correctness during compilation.
|
82
|
+
* Under strict compilation modes, variadic macro arguments can't be empty.
|
83
|
+
* However, variadic function arguments can be. Using a function therefore lets
|
84
|
+
* us statically check that at least one (string) argument was passed,
|
85
|
+
* independent of the compilation flags.
|
86
|
+
*/
|
87
|
+
static INLINE_KEYWORD UNUSED_ATTR
|
88
|
+
void _force_has_format_string(const char *format, ...) {
|
89
|
+
(void)format;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Ignore: this is an internal helper.
|
94
|
+
*
|
95
|
+
* We want to force this function invocation to be syntactically correct, but
|
96
|
+
* we don't want to force runtime evaluation of its arguments.
|
97
|
+
*/
|
98
|
+
#define _FORCE_HAS_FORMAT_STRING(...) \
|
99
|
+
if (0) { \
|
100
|
+
_force_has_format_string(__VA_ARGS__); \
|
101
|
+
}
|
102
|
+
|
103
|
+
#define ERR_QUOTE(str) #str
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Return the specified error if the condition evaluates to true.
|
107
|
+
*
|
108
|
+
* In debug modes, prints additional information.
|
109
|
+
* In order to do that (particularly, printing the conditional that failed),
|
110
|
+
* this can't just wrap RETURN_ERROR().
|
111
|
+
*/
|
112
|
+
#define RETURN_ERROR_IF(cond, err, ...) \
|
113
|
+
if (cond) { \
|
114
|
+
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
|
115
|
+
__FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
|
116
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
117
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
118
|
+
RAWLOG(3, "\n"); \
|
119
|
+
return ERROR(err); \
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Unconditionally return the specified error.
|
124
|
+
*
|
125
|
+
* In debug modes, prints additional information.
|
126
|
+
*/
|
127
|
+
#define RETURN_ERROR(err, ...) \
|
128
|
+
do { \
|
129
|
+
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
|
130
|
+
__FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
|
131
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
132
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
133
|
+
RAWLOG(3, "\n"); \
|
134
|
+
return ERROR(err); \
|
135
|
+
} while(0);
|
136
|
+
|
137
|
+
/**
|
138
|
+
* If the provided expression evaluates to an error code, returns that error code.
|
139
|
+
*
|
140
|
+
* In debug modes, prints additional information.
|
141
|
+
*/
|
142
|
+
#define FORWARD_IF_ERROR(err, ...) \
|
143
|
+
do { \
|
144
|
+
size_t const err_code = (err); \
|
145
|
+
if (ERR_isError(err_code)) { \
|
146
|
+
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
|
147
|
+
__FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
|
148
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
149
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
150
|
+
RAWLOG(3, "\n"); \
|
151
|
+
return err_code; \
|
152
|
+
} \
|
153
|
+
} while(0);
|
154
|
+
|
155
|
+
#if defined (__cplusplus)
|
156
|
+
}
|
157
|
+
#endif
|
158
|
+
|
159
|
+
#endif /* ERROR_H_MODULE */
|