deflate-ruby 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/CLAUDE.md +95 -92
- data/LICENSE.txt +6 -6
- data/README.md +87 -65
- data/Rakefile +23 -0
- data/ext/deflate_ruby/{libdeflate/lib/x86/adler32_impl.h → adler32_impl.h} +8 -7
- data/ext/deflate_ruby/common_defs.h +748 -0
- data/ext/deflate_ruby/{libdeflate/lib/x86/cpu_features.c → cpu_features.c} +46 -16
- data/ext/deflate_ruby/{libdeflate/lib/x86/cpu_features.h → cpu_features.h} +2 -1
- data/ext/deflate_ruby/{libdeflate/lib/x86/crc32_impl.h → crc32_impl.h} +22 -23
- data/ext/deflate_ruby/{libdeflate/lib/crc32_multipliers.h → crc32_multipliers.h} +2 -4
- data/ext/deflate_ruby/{libdeflate/lib/x86/crc32_pclmul_template.h → crc32_pclmul_template.h} +23 -94
- data/ext/deflate_ruby/{libdeflate/lib/crc32_tables.h → crc32_tables.h} +1 -1
- data/ext/deflate_ruby/{libdeflate/lib/deflate_compress.c → deflate_compress.c} +59 -60
- data/ext/deflate_ruby/deflate_ruby.c +392 -218
- data/ext/deflate_ruby/deflate_ruby.h +6 -0
- data/ext/deflate_ruby/extconf.rb +35 -25
- data/ext/deflate_ruby/libdeflate/adler32.c +162 -0
- data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/adler32_impl.h +14 -7
- data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/crc32_impl.h +25 -31
- data/ext/deflate_ruby/libdeflate/arm/crc32_pmull_helpers.h +156 -0
- data/ext/deflate_ruby/libdeflate/arm/crc32_pmull_wide.h +226 -0
- data/ext/deflate_ruby/libdeflate/bt_matchfinder.h +342 -0
- data/ext/deflate_ruby/libdeflate/common_defs.h +2 -1
- data/ext/deflate_ruby/libdeflate/cpu_features_common.h +93 -0
- data/ext/deflate_ruby/libdeflate/crc32.c +262 -0
- data/ext/deflate_ruby/libdeflate/crc32_multipliers.h +375 -0
- data/ext/deflate_ruby/libdeflate/crc32_tables.h +587 -0
- data/ext/deflate_ruby/libdeflate/decompress_template.h +777 -0
- data/ext/deflate_ruby/libdeflate/deflate_compress.c +4128 -0
- data/ext/deflate_ruby/libdeflate/deflate_compress.h +15 -0
- data/ext/deflate_ruby/libdeflate/deflate_constants.h +56 -0
- data/ext/deflate_ruby/libdeflate/deflate_decompress.c +1208 -0
- data/ext/deflate_ruby/libdeflate/gzip_compress.c +90 -0
- data/ext/deflate_ruby/libdeflate/gzip_constants.h +45 -0
- data/ext/deflate_ruby/libdeflate/gzip_decompress.c +144 -0
- data/ext/deflate_ruby/libdeflate/hc_matchfinder.h +401 -0
- data/ext/deflate_ruby/libdeflate/ht_matchfinder.h +234 -0
- data/ext/deflate_ruby/libdeflate/lib_common.h +106 -0
- data/ext/deflate_ruby/libdeflate/libdeflate.h +2 -2
- data/ext/deflate_ruby/libdeflate/{lib/matchfinder_common.h → matchfinder_common.h} +3 -3
- data/ext/deflate_ruby/libdeflate/x86/adler32_impl.h +135 -0
- data/ext/deflate_ruby/libdeflate/x86/adler32_template.h +518 -0
- data/ext/deflate_ruby/libdeflate/x86/cpu_features.c +213 -0
- data/ext/deflate_ruby/libdeflate/x86/cpu_features.h +170 -0
- data/ext/deflate_ruby/libdeflate/x86/crc32_impl.h +159 -0
- data/ext/deflate_ruby/libdeflate/x86/crc32_pclmul_template.h +424 -0
- data/ext/deflate_ruby/libdeflate/x86/decompress_impl.h +57 -0
- data/ext/deflate_ruby/libdeflate.h +411 -0
- data/ext/deflate_ruby/matchfinder_common.h +224 -0
- data/ext/deflate_ruby/matchfinder_impl.h +122 -0
- data/ext/deflate_ruby/utils.c +141 -0
- data/ext/deflate_ruby/zlib_compress.c +82 -0
- data/ext/deflate_ruby/zlib_constants.h +21 -0
- data/ext/deflate_ruby/zlib_decompress.c +104 -0
- data/lib/deflate_ruby/version.rb +1 -1
- data/lib/deflate_ruby.rb +1 -63
- data/sig/deflate_ruby.rbs +4 -0
- data/test/test_deflate_ruby.rb +220 -0
- data/test/test_helper.rb +6 -0
- metadata +89 -144
- data/ext/deflate_ruby/libdeflate/CMakeLists.txt +0 -270
- data/ext/deflate_ruby/libdeflate/NEWS.md +0 -494
- data/ext/deflate_ruby/libdeflate/README.md +0 -228
- data/ext/deflate_ruby/libdeflate/libdeflate-config.cmake.in +0 -3
- data/ext/deflate_ruby/libdeflate/libdeflate.pc.in +0 -18
- data/ext/deflate_ruby/libdeflate/programs/CMakeLists.txt +0 -105
- data/ext/deflate_ruby/libdeflate/programs/benchmark.c +0 -696
- data/ext/deflate_ruby/libdeflate/programs/checksum.c +0 -218
- data/ext/deflate_ruby/libdeflate/programs/config.h.in +0 -19
- data/ext/deflate_ruby/libdeflate/programs/gzip.c +0 -688
- data/ext/deflate_ruby/libdeflate/programs/prog_util.c +0 -521
- data/ext/deflate_ruby/libdeflate/programs/prog_util.h +0 -225
- data/ext/deflate_ruby/libdeflate/programs/test_checksums.c +0 -200
- data/ext/deflate_ruby/libdeflate/programs/test_custom_malloc.c +0 -155
- data/ext/deflate_ruby/libdeflate/programs/test_incomplete_codes.c +0 -385
- data/ext/deflate_ruby/libdeflate/programs/test_invalid_streams.c +0 -130
- data/ext/deflate_ruby/libdeflate/programs/test_litrunlen_overflow.c +0 -72
- data/ext/deflate_ruby/libdeflate/programs/test_overread.c +0 -95
- data/ext/deflate_ruby/libdeflate/programs/test_slow_decompression.c +0 -472
- data/ext/deflate_ruby/libdeflate/programs/test_trailing_bytes.c +0 -151
- data/ext/deflate_ruby/libdeflate/programs/test_util.c +0 -237
- data/ext/deflate_ruby/libdeflate/programs/test_util.h +0 -61
- data/ext/deflate_ruby/libdeflate/programs/tgetopt.c +0 -118
- data/ext/deflate_ruby/libdeflate/scripts/android_build.sh +0 -118
- data/ext/deflate_ruby/libdeflate/scripts/android_tests.sh +0 -69
- data/ext/deflate_ruby/libdeflate/scripts/benchmark.sh +0 -10
- data/ext/deflate_ruby/libdeflate/scripts/checksum.sh +0 -10
- data/ext/deflate_ruby/libdeflate/scripts/checksum_benchmarks.sh +0 -253
- data/ext/deflate_ruby/libdeflate/scripts/cmake-helper.sh +0 -17
- data/ext/deflate_ruby/libdeflate/scripts/deflate_benchmarks.sh +0 -119
- data/ext/deflate_ruby/libdeflate/scripts/exec_tests.sh +0 -38
- data/ext/deflate_ruby/libdeflate/scripts/gen-release-archives.sh +0 -37
- data/ext/deflate_ruby/libdeflate/scripts/gen_bitreverse_tab.py +0 -19
- data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_multipliers.c +0 -199
- data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_tables.c +0 -105
- data/ext/deflate_ruby/libdeflate/scripts/gen_default_litlen_costs.py +0 -44
- data/ext/deflate_ruby/libdeflate/scripts/gen_offset_slot_map.py +0 -29
- data/ext/deflate_ruby/libdeflate/scripts/gzip_tests.sh +0 -523
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/corpus/0 +0 -0
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/fuzz.c +0 -95
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/corpus/0 +0 -3
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/fuzz.c +0 -62
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/fuzz.sh +0 -108
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/corpus/0 +0 -0
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/fuzz.c +0 -19
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/corpus/0 +0 -3
- data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/fuzz.c +0 -19
- data/ext/deflate_ruby/libdeflate/scripts/run_tests.sh +0 -416
- data/ext/deflate_ruby/libdeflate/scripts/toolchain-i686-w64-mingw32.cmake +0 -8
- data/ext/deflate_ruby/libdeflate/scripts/toolchain-x86_64-w64-mingw32.cmake +0 -8
- /data/ext/deflate_ruby/{libdeflate/lib/adler32.c → adler32.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/x86/adler32_template.h → adler32_template.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/bt_matchfinder.h → bt_matchfinder.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/cpu_features_common.h → cpu_features_common.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/crc32.c → crc32.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/arm/crc32_pmull_helpers.h → crc32_pmull_helpers.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/arm/crc32_pmull_wide.h → crc32_pmull_wide.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/x86/decompress_impl.h → decompress_impl.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/decompress_template.h → decompress_template.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/deflate_compress.h → deflate_compress.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/deflate_constants.h → deflate_constants.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/deflate_decompress.c → deflate_decompress.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/gzip_compress.c → gzip_compress.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/gzip_constants.h → gzip_constants.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/gzip_decompress.c → gzip_decompress.c} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/hc_matchfinder.h → hc_matchfinder.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/ht_matchfinder.h → ht_matchfinder.h} +0 -0
- /data/ext/deflate_ruby/{libdeflate/lib/lib_common.h → lib_common.h} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/cpu_features.c +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/cpu_features.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/arm → arm}/matchfinder_impl.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/riscv → riscv}/matchfinder_impl.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/utils.c → utils.c} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/x86 → x86}/matchfinder_impl.h +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/zlib_compress.c → zlib_compress.c} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/zlib_constants.h → zlib_constants.h} +0 -0
- /data/ext/deflate_ruby/libdeflate/{lib/zlib_decompress.c → zlib_decompress.c} +0 -0
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* prog_util.h - common header for the programs; must be included first
|
|
3
|
-
*
|
|
4
|
-
* Copyright 2016 Eric Biggers
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person
|
|
7
|
-
* obtaining a copy of this software and associated documentation
|
|
8
|
-
* files (the "Software"), to deal in the Software without
|
|
9
|
-
* restriction, including without limitation the rights to use,
|
|
10
|
-
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the
|
|
12
|
-
* Software is furnished to do so, subject to the following
|
|
13
|
-
* conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be
|
|
16
|
-
* included in all copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
20
|
-
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
23
|
-
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
24
|
-
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
25
|
-
* OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
#ifndef PROGRAMS_PROG_UTIL_H
|
|
29
|
-
#define PROGRAMS_PROG_UTIL_H
|
|
30
|
-
|
|
31
|
-
/*
|
|
32
|
-
* This header provides some utility functions and macros for the programs. It
|
|
33
|
-
* also defines some macros that control the behavior of system headers, and for
|
|
34
|
-
* that reason it must be included before any system header.
|
|
35
|
-
*
|
|
36
|
-
* The latter part could be handled in this directory's CMakeLists.txt instead.
|
|
37
|
-
* We put as much as possible here, directly in the source, to make it easier to
|
|
38
|
-
* build the programs using other build systems (or "no build system").
|
|
39
|
-
*
|
|
40
|
-
* Note: CMakeLists.txt does do some dynamic feature detection, which can't be
|
|
41
|
-
* done in the source code. For that reason, it duplicates some of the logic
|
|
42
|
-
* that defines macros like _GNU_SOURCE. Keep this logic in sync.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
#ifdef _WIN32
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* To keep the code similar on all platforms, sometimes we intentionally use
|
|
49
|
-
* the "deprecated" non-underscore-prefixed variants of functions in msvcrt.
|
|
50
|
-
*/
|
|
51
|
-
# undef _CRT_NONSTDC_NO_DEPRECATE
|
|
52
|
-
# define _CRT_NONSTDC_NO_DEPRECATE 1
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
* Similarly, to match other platforms we intentionally use the "non-secure"
|
|
56
|
-
* variants, which aren't actually any less secure when used properly.
|
|
57
|
-
*/
|
|
58
|
-
# undef _CRT_SECURE_NO_WARNINGS
|
|
59
|
-
# define _CRT_SECURE_NO_WARNINGS 1
|
|
60
|
-
|
|
61
|
-
#else
|
|
62
|
-
|
|
63
|
-
/* Needed to work with files >= 2 GiB on 32-bit systems */
|
|
64
|
-
# undef _FILE_OFFSET_BITS
|
|
65
|
-
# define _FILE_OFFSET_BITS 64
|
|
66
|
-
|
|
67
|
-
/* Note: when making changes here, update programs/CMakeLists.txt too. */
|
|
68
|
-
# if defined(__linux__)
|
|
69
|
-
/*
|
|
70
|
-
* May be needed for clock_gettime(), posix_fadvise(), posix_madvise(),
|
|
71
|
-
* futimens(), and MAP_ANONYMOUS, depending on the C library version.
|
|
72
|
-
*/
|
|
73
|
-
# undef _GNU_SOURCE
|
|
74
|
-
# define _GNU_SOURCE
|
|
75
|
-
# undef _POSIX_C_SOURCE
|
|
76
|
-
# define _POSIX_C_SOURCE 200809L
|
|
77
|
-
# elif defined(__APPLE__)
|
|
78
|
-
/* Needed for O_NOFOLLOW and MAP_ANON */
|
|
79
|
-
# undef _DARWIN_C_SOURCE
|
|
80
|
-
# define _DARWIN_C_SOURCE
|
|
81
|
-
# undef _POSIX_C_SOURCE
|
|
82
|
-
# elif defined(__sun)
|
|
83
|
-
/* Needed for futimens() */
|
|
84
|
-
# undef __EXTENSIONS__
|
|
85
|
-
# define __EXTENSIONS__
|
|
86
|
-
# undef _POSIX_C_SOURCE
|
|
87
|
-
# else
|
|
88
|
-
/*
|
|
89
|
-
* Else assume that nothing else is needed. Don't use _POSIX_C_SOURCE on
|
|
90
|
-
* BSD, since it causes anything non-POSIX, such as MAP_ANON, to be hidden.
|
|
91
|
-
*/
|
|
92
|
-
# undef _POSIX_C_SOURCE
|
|
93
|
-
# endif
|
|
94
|
-
#endif
|
|
95
|
-
|
|
96
|
-
#ifdef HAVE_CONFIG_H
|
|
97
|
-
# include "config.h"
|
|
98
|
-
#endif
|
|
99
|
-
|
|
100
|
-
#include "../common_defs.h"
|
|
101
|
-
|
|
102
|
-
#include <inttypes.h>
|
|
103
|
-
#include <limits.h>
|
|
104
|
-
#include <stdio.h>
|
|
105
|
-
#include <stdlib.h>
|
|
106
|
-
#include <string.h>
|
|
107
|
-
#ifndef _WIN32
|
|
108
|
-
# include <sys/types.h>
|
|
109
|
-
#endif
|
|
110
|
-
|
|
111
|
-
#if defined(__GNUC__) || __has_attribute(format)
|
|
112
|
-
# define _printf(str_idx, args_idx) \
|
|
113
|
-
__attribute__((format(printf, str_idx, args_idx)))
|
|
114
|
-
#else
|
|
115
|
-
# define _printf(str_idx, args_idx)
|
|
116
|
-
#endif
|
|
117
|
-
|
|
118
|
-
#ifdef _WIN32
|
|
119
|
-
|
|
120
|
-
/*
|
|
121
|
-
* Definitions for Windows builds. Mainly, 'tchar' is defined to be the 2-byte
|
|
122
|
-
* 'wchar_t' type instead of 'char'. This is the only "easy" way I know of to
|
|
123
|
-
* get full Unicode support on Windows...
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
#include <io.h>
|
|
127
|
-
#include <wchar.h>
|
|
128
|
-
int wmain(int argc, wchar_t **argv);
|
|
129
|
-
# define tmain wmain
|
|
130
|
-
# define tchar wchar_t
|
|
131
|
-
# define _T(text) L##text
|
|
132
|
-
# define T(text) _T(text)
|
|
133
|
-
# define TS "ls"
|
|
134
|
-
# define TC "lc"
|
|
135
|
-
# define tmemcpy wmemcpy
|
|
136
|
-
# define topen _wopen
|
|
137
|
-
# define tstrchr wcschr
|
|
138
|
-
# define tstrcmp wcscmp
|
|
139
|
-
# define tstrlen wcslen
|
|
140
|
-
# define tstrrchr wcsrchr
|
|
141
|
-
# define tstrtoul wcstoul
|
|
142
|
-
# define tstrxcmp wcsicmp
|
|
143
|
-
# define tunlink _wunlink
|
|
144
|
-
# define tutimbuf __utimbuf64
|
|
145
|
-
# define tutime _wutime64
|
|
146
|
-
# define tstat _wstat64
|
|
147
|
-
# define tfstat _fstat64
|
|
148
|
-
# define stat_t struct _stat64
|
|
149
|
-
# ifdef _MSC_VER
|
|
150
|
-
# define STDIN_FILENO 0
|
|
151
|
-
# define STDOUT_FILENO 1
|
|
152
|
-
# define STDERR_FILENO 2
|
|
153
|
-
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
154
|
-
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
155
|
-
# endif
|
|
156
|
-
|
|
157
|
-
#else /* _WIN32 */
|
|
158
|
-
|
|
159
|
-
/* Standard definitions for everyone else */
|
|
160
|
-
|
|
161
|
-
# define tmain main
|
|
162
|
-
# define tchar char
|
|
163
|
-
# define T(text) text
|
|
164
|
-
# define TS "s"
|
|
165
|
-
# define TC "c"
|
|
166
|
-
# define tmemcpy memcpy
|
|
167
|
-
# define topen open
|
|
168
|
-
# define tstrchr strchr
|
|
169
|
-
# define tstrcmp strcmp
|
|
170
|
-
# define tstrlen strlen
|
|
171
|
-
# define tstrrchr strrchr
|
|
172
|
-
# define tstrtoul strtoul
|
|
173
|
-
# define tstrxcmp strcmp
|
|
174
|
-
# define tunlink unlink
|
|
175
|
-
# define tutimbuf utimbuf
|
|
176
|
-
# define tutime utime
|
|
177
|
-
# define tstat stat
|
|
178
|
-
# define tfstat fstat
|
|
179
|
-
# define stat_t struct stat
|
|
180
|
-
|
|
181
|
-
#endif /* !_WIN32 */
|
|
182
|
-
|
|
183
|
-
extern const tchar *prog_invocation_name;
|
|
184
|
-
extern bool suppress_warnings;
|
|
185
|
-
|
|
186
|
-
void _printf(1, 2) msg(const char *fmt, ...);
|
|
187
|
-
void _printf(1, 2) msg_errno(const char *fmt, ...);
|
|
188
|
-
void _printf(1, 2) warn(const char *fmt, ...);
|
|
189
|
-
|
|
190
|
-
void *xmalloc(size_t size);
|
|
191
|
-
|
|
192
|
-
void begin_program(tchar *argv[]);
|
|
193
|
-
|
|
194
|
-
struct file_stream {
|
|
195
|
-
int fd;
|
|
196
|
-
tchar *name;
|
|
197
|
-
bool is_standard_stream;
|
|
198
|
-
void *mmap_token;
|
|
199
|
-
void *mmap_mem;
|
|
200
|
-
size_t mmap_size;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
int xopen_for_read(const tchar *path, bool symlink_ok,
|
|
204
|
-
struct file_stream *strm);
|
|
205
|
-
int xopen_for_write(const tchar *path, bool force, struct file_stream *strm);
|
|
206
|
-
int map_file_contents(struct file_stream *strm, u64 size);
|
|
207
|
-
|
|
208
|
-
ssize_t xread(struct file_stream *strm, void *buf, size_t count);
|
|
209
|
-
int full_write(struct file_stream *strm, const void *buf, size_t count);
|
|
210
|
-
|
|
211
|
-
int xclose(struct file_stream *strm);
|
|
212
|
-
|
|
213
|
-
int parse_compression_level(tchar opt_char, const tchar *arg);
|
|
214
|
-
|
|
215
|
-
struct libdeflate_compressor *alloc_compressor(int level);
|
|
216
|
-
struct libdeflate_decompressor *alloc_decompressor(void);
|
|
217
|
-
|
|
218
|
-
/* tgetopt.c */
|
|
219
|
-
|
|
220
|
-
extern tchar *toptarg;
|
|
221
|
-
extern int toptind, topterr, toptopt;
|
|
222
|
-
|
|
223
|
-
int tgetopt(int argc, tchar *argv[], const tchar *optstring);
|
|
224
|
-
|
|
225
|
-
#endif /* PROGRAMS_PROG_UTIL_H */
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* test_checksums.c
|
|
3
|
-
*
|
|
4
|
-
* Verify that libdeflate's Adler-32 and CRC-32 functions produce the same
|
|
5
|
-
* results as their zlib equivalents.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
#include "test_util.h"
|
|
9
|
-
|
|
10
|
-
#include <stdlib.h>
|
|
11
|
-
#include <time.h>
|
|
12
|
-
|
|
13
|
-
static unsigned int rng_seed;
|
|
14
|
-
|
|
15
|
-
typedef u32 (*cksum_fn_t)(u32, const void *, size_t);
|
|
16
|
-
|
|
17
|
-
static u32
|
|
18
|
-
adler32_libdeflate(u32 adler, const void *buf, size_t len)
|
|
19
|
-
{
|
|
20
|
-
return libdeflate_adler32(adler, buf, len);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static u32
|
|
24
|
-
crc32_libdeflate(u32 crc, const void *buf, size_t len)
|
|
25
|
-
{
|
|
26
|
-
return libdeflate_crc32(crc, buf, len);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static u32
|
|
30
|
-
adler32_zlib(u32 adler, const void *buf, size_t len)
|
|
31
|
-
{
|
|
32
|
-
return adler32(adler, buf, len);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static u32
|
|
36
|
-
crc32_zlib(u32 crc, const void *buf, size_t len)
|
|
37
|
-
{
|
|
38
|
-
return crc32(crc, buf, len);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static u32
|
|
42
|
-
select_initial_crc(void)
|
|
43
|
-
{
|
|
44
|
-
if (rand() & 1)
|
|
45
|
-
return 0;
|
|
46
|
-
return ((u32)rand() << 16) | rand();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static u32
|
|
50
|
-
select_initial_adler(void)
|
|
51
|
-
{
|
|
52
|
-
u32 lo, hi;
|
|
53
|
-
|
|
54
|
-
if (rand() & 1)
|
|
55
|
-
return 1;
|
|
56
|
-
|
|
57
|
-
lo = (rand() % 4 == 0 ? 65520 : rand() % 65521);
|
|
58
|
-
hi = (rand() % 4 == 0 ? 65520 : rand() % 65521);
|
|
59
|
-
return (hi << 16) | lo;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static void
|
|
63
|
-
test_initial_values(cksum_fn_t cksum, u32 expected)
|
|
64
|
-
{
|
|
65
|
-
ASSERT(cksum(0, NULL, 0) == expected);
|
|
66
|
-
if (cksum != adler32_zlib) /* broken */
|
|
67
|
-
ASSERT(cksum(0, NULL, 1) == expected);
|
|
68
|
-
ASSERT(cksum(0, NULL, 1234) == expected);
|
|
69
|
-
ASSERT(cksum(1234, NULL, 0) == expected);
|
|
70
|
-
ASSERT(cksum(1234, NULL, 1234) == expected);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
static void
|
|
74
|
-
test_multipart(const u8 *buffer, size_t size, const char *name,
|
|
75
|
-
cksum_fn_t cksum, u32 v, u32 expected)
|
|
76
|
-
{
|
|
77
|
-
size_t division = rand() % (size + 1);
|
|
78
|
-
v = cksum(v, buffer, division);
|
|
79
|
-
v = cksum(v, buffer + division, size - division);
|
|
80
|
-
if (v != expected) {
|
|
81
|
-
fprintf(stderr, "%s checksum failed multipart test\n", name);
|
|
82
|
-
ASSERT(0);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static void
|
|
87
|
-
test_checksums(const void *buffer, size_t size, const char *name,
|
|
88
|
-
cksum_fn_t cksum1, cksum_fn_t cksum2, u32 initial_value)
|
|
89
|
-
{
|
|
90
|
-
u32 v1 = cksum1(initial_value, buffer, size);
|
|
91
|
-
u32 v2 = cksum2(initial_value, buffer, size);
|
|
92
|
-
|
|
93
|
-
if (v1 != v2) {
|
|
94
|
-
fprintf(stderr, "%s checksum mismatch\n", name);
|
|
95
|
-
fprintf(stderr, "initial_value=0x%08"PRIx32", buffer=%p, "
|
|
96
|
-
"size=%zu, buffer=", initial_value, buffer, size);
|
|
97
|
-
for (size_t i = 0; i < MIN(size, 256); i++)
|
|
98
|
-
fprintf(stderr, "%02x", ((const u8 *)buffer)[i]);
|
|
99
|
-
if (size > 256)
|
|
100
|
-
fprintf(stderr, "...");
|
|
101
|
-
fprintf(stderr, "\n");
|
|
102
|
-
ASSERT(0);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if ((rand() & 15) == 0) {
|
|
106
|
-
test_multipart(buffer, size, name, cksum1, initial_value, v1);
|
|
107
|
-
test_multipart(buffer, size, name, cksum2, initial_value, v1);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
static void
|
|
112
|
-
test_crc32(const void *buffer, size_t size, u32 initial_value)
|
|
113
|
-
{
|
|
114
|
-
test_checksums(buffer, size, "CRC-32",
|
|
115
|
-
crc32_libdeflate, crc32_zlib, initial_value);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
static void
|
|
119
|
-
test_adler32(const void *buffer, size_t size, u32 initial_value)
|
|
120
|
-
{
|
|
121
|
-
test_checksums(buffer, size, "Adler-32",
|
|
122
|
-
adler32_libdeflate, adler32_zlib, initial_value);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
static void test_random_buffers(u8 *buf_start, u8 *buf_end, size_t limit,
|
|
126
|
-
u32 num_iter)
|
|
127
|
-
{
|
|
128
|
-
for (u32 i = 0; i < num_iter; i++) {
|
|
129
|
-
size_t start = rand() % limit;
|
|
130
|
-
size_t len = rand() % (limit - start);
|
|
131
|
-
u32 a0 = select_initial_adler();
|
|
132
|
-
u32 c0 = select_initial_crc();
|
|
133
|
-
|
|
134
|
-
for (size_t j = start; j < start + len; j++)
|
|
135
|
-
buf_start[j] = rand();
|
|
136
|
-
|
|
137
|
-
/* Test with chosen size and alignment */
|
|
138
|
-
test_adler32(&buf_start[start], len, a0);
|
|
139
|
-
test_crc32(&buf_start[start], len, c0);
|
|
140
|
-
|
|
141
|
-
/* Test with chosen size, with guard page before input buffer */
|
|
142
|
-
memmove(buf_start, &buf_start[start], len);
|
|
143
|
-
test_adler32(buf_start, len, a0);
|
|
144
|
-
test_crc32(buf_start, len, c0);
|
|
145
|
-
|
|
146
|
-
/* Test with chosen size, with guard page after input buffer */
|
|
147
|
-
memmove(buf_end - len, buf_start, len);
|
|
148
|
-
test_adler32(buf_end - len, len, a0);
|
|
149
|
-
test_crc32(buf_end - len, len, c0);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
int
|
|
154
|
-
tmain(int argc, tchar *argv[])
|
|
155
|
-
{
|
|
156
|
-
u8 *buf_start, *buf_end;
|
|
157
|
-
|
|
158
|
-
begin_program(argv);
|
|
159
|
-
|
|
160
|
-
alloc_guarded_buffer(262144, &buf_start, &buf_end);
|
|
161
|
-
|
|
162
|
-
rng_seed = time(NULL);
|
|
163
|
-
srand(rng_seed);
|
|
164
|
-
|
|
165
|
-
test_initial_values(adler32_libdeflate, 1);
|
|
166
|
-
test_initial_values(adler32_zlib, 1);
|
|
167
|
-
test_initial_values(crc32_libdeflate, 0);
|
|
168
|
-
test_initial_values(crc32_zlib, 0);
|
|
169
|
-
|
|
170
|
-
/* Test different buffer sizes and alignments */
|
|
171
|
-
test_random_buffers(buf_start, buf_end, 256, 5000);
|
|
172
|
-
test_random_buffers(buf_start, buf_end, 1024, 500);
|
|
173
|
-
test_random_buffers(buf_start, buf_end, 32768, 50);
|
|
174
|
-
test_random_buffers(buf_start, buf_end, 262144, 50);
|
|
175
|
-
|
|
176
|
-
/*
|
|
177
|
-
* Test Adler-32 overflow cases. For example, given all 0xFF bytes and
|
|
178
|
-
* the highest possible initial (s1, s2) of (65520, 65520), then s2 if
|
|
179
|
-
* stored as a 32-bit unsigned integer will overflow if > 5552 bytes are
|
|
180
|
-
* processed. Implementations must make sure to reduce s2 modulo 65521
|
|
181
|
-
* before that point. Also, some implementations make use of 16-bit
|
|
182
|
-
* counters which can overflow earlier.
|
|
183
|
-
*/
|
|
184
|
-
memset(buf_start, 0xFF, 32768);
|
|
185
|
-
for (u32 i = 0; i < 20; i++) {
|
|
186
|
-
u32 initial_value;
|
|
187
|
-
|
|
188
|
-
if (i == 0)
|
|
189
|
-
initial_value = ((u32)65520 << 16) | 65520;
|
|
190
|
-
else
|
|
191
|
-
initial_value = select_initial_adler();
|
|
192
|
-
|
|
193
|
-
test_adler32(buf_start, 5553, initial_value);
|
|
194
|
-
test_adler32(buf_start, rand() % 32769, initial_value);
|
|
195
|
-
buf_start[rand() % 32768] = 0xFE;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
free_guarded_buffer(buf_start, buf_end);
|
|
199
|
-
return 0;
|
|
200
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* test_custom_malloc.c
|
|
3
|
-
*
|
|
4
|
-
* Test the support for custom memory allocators.
|
|
5
|
-
* Also test injecting allocation failures.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
#include "test_util.h"
|
|
9
|
-
|
|
10
|
-
static int malloc_count = 0;
|
|
11
|
-
static int free_count = 0;
|
|
12
|
-
|
|
13
|
-
static void *do_malloc(size_t size)
|
|
14
|
-
{
|
|
15
|
-
malloc_count++;
|
|
16
|
-
return malloc(size);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static void *do_fail_malloc(size_t size)
|
|
20
|
-
{
|
|
21
|
-
malloc_count++;
|
|
22
|
-
return NULL;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static void do_free(void *ptr)
|
|
26
|
-
{
|
|
27
|
-
free_count++;
|
|
28
|
-
free(ptr);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static void reset_state(void)
|
|
32
|
-
{
|
|
33
|
-
libdeflate_set_memory_allocator(malloc, free);
|
|
34
|
-
malloc_count = 0;
|
|
35
|
-
free_count = 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/* Test that the custom allocator is actually used when requested. */
|
|
39
|
-
static void do_custom_memalloc_test(bool global)
|
|
40
|
-
{
|
|
41
|
-
static const struct libdeflate_options options = {
|
|
42
|
-
.sizeof_options = sizeof(options),
|
|
43
|
-
.malloc_func = do_malloc,
|
|
44
|
-
.free_func = do_free,
|
|
45
|
-
};
|
|
46
|
-
int level;
|
|
47
|
-
struct libdeflate_compressor *c;
|
|
48
|
-
struct libdeflate_decompressor *d;
|
|
49
|
-
|
|
50
|
-
if (global)
|
|
51
|
-
libdeflate_set_memory_allocator(do_malloc, do_free);
|
|
52
|
-
|
|
53
|
-
for (level = 0; level <= 12; level++) {
|
|
54
|
-
malloc_count = free_count = 0;
|
|
55
|
-
if (global)
|
|
56
|
-
c = libdeflate_alloc_compressor(level);
|
|
57
|
-
else
|
|
58
|
-
c = libdeflate_alloc_compressor_ex(level, &options);
|
|
59
|
-
ASSERT(c != NULL);
|
|
60
|
-
ASSERT(malloc_count == 1);
|
|
61
|
-
ASSERT(free_count == 0);
|
|
62
|
-
libdeflate_free_compressor(c);
|
|
63
|
-
ASSERT(malloc_count == 1);
|
|
64
|
-
ASSERT(free_count == 1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
malloc_count = free_count = 0;
|
|
68
|
-
if (global)
|
|
69
|
-
d = libdeflate_alloc_decompressor();
|
|
70
|
-
else
|
|
71
|
-
d = libdeflate_alloc_decompressor_ex(&options);
|
|
72
|
-
ASSERT(d != NULL);
|
|
73
|
-
ASSERT(malloc_count == 1);
|
|
74
|
-
ASSERT(free_count == 0);
|
|
75
|
-
libdeflate_free_decompressor(d);
|
|
76
|
-
ASSERT(malloc_count == 1);
|
|
77
|
-
ASSERT(free_count == 1);
|
|
78
|
-
|
|
79
|
-
reset_state();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#define offsetofend(type, field) \
|
|
83
|
-
(offsetof(type, field) + sizeof(((type *)NULL)->field))
|
|
84
|
-
|
|
85
|
-
/* Test some edge cases involving libdeflate_options. */
|
|
86
|
-
static void do_options_test(void)
|
|
87
|
-
{
|
|
88
|
-
struct libdeflate_options options = { 0 };
|
|
89
|
-
struct libdeflate_compressor *c;
|
|
90
|
-
struct libdeflate_decompressor *d;
|
|
91
|
-
/* Size in libdeflate v1.19 */
|
|
92
|
-
size_t min_size = offsetofend(struct libdeflate_options, free_func);
|
|
93
|
-
|
|
94
|
-
/* sizeof_options must be at least the minimum size. */
|
|
95
|
-
for (; options.sizeof_options < min_size;
|
|
96
|
-
options.sizeof_options++) {
|
|
97
|
-
c = libdeflate_alloc_compressor_ex(6, &options);
|
|
98
|
-
ASSERT(c == NULL);
|
|
99
|
-
d = libdeflate_alloc_decompressor_ex(&options);
|
|
100
|
-
ASSERT(d == NULL);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/* NULL malloc_func and free_func means "use the global allocator". */
|
|
104
|
-
options.sizeof_options = min_size;
|
|
105
|
-
malloc_count = free_count = 0;
|
|
106
|
-
libdeflate_set_memory_allocator(do_malloc, do_free);
|
|
107
|
-
c = libdeflate_alloc_compressor_ex(6, &options);
|
|
108
|
-
libdeflate_free_compressor(c);
|
|
109
|
-
ASSERT(malloc_count == 1);
|
|
110
|
-
ASSERT(free_count == 1);
|
|
111
|
-
d = libdeflate_alloc_decompressor_ex(&options);
|
|
112
|
-
libdeflate_free_decompressor(d);
|
|
113
|
-
ASSERT(malloc_count == 2);
|
|
114
|
-
ASSERT(free_count == 2);
|
|
115
|
-
|
|
116
|
-
reset_state();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* Test injecting memory allocation failures. */
|
|
120
|
-
static void do_fault_injection_test(void)
|
|
121
|
-
{
|
|
122
|
-
int level;
|
|
123
|
-
struct libdeflate_compressor *c;
|
|
124
|
-
struct libdeflate_decompressor *d;
|
|
125
|
-
|
|
126
|
-
libdeflate_set_memory_allocator(do_fail_malloc, do_free);
|
|
127
|
-
|
|
128
|
-
for (level = 0; level <= 12; level++) {
|
|
129
|
-
malloc_count = free_count = 0;
|
|
130
|
-
c = libdeflate_alloc_compressor(level);
|
|
131
|
-
ASSERT(c == NULL);
|
|
132
|
-
ASSERT(malloc_count == 1);
|
|
133
|
-
ASSERT(free_count == 0);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
malloc_count = free_count = 0;
|
|
137
|
-
d = libdeflate_alloc_decompressor();
|
|
138
|
-
ASSERT(d == NULL);
|
|
139
|
-
ASSERT(malloc_count == 1);
|
|
140
|
-
ASSERT(free_count == 0);
|
|
141
|
-
|
|
142
|
-
reset_state();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
int
|
|
146
|
-
tmain(int argc, tchar *argv[])
|
|
147
|
-
{
|
|
148
|
-
begin_program(argv);
|
|
149
|
-
|
|
150
|
-
do_custom_memalloc_test(true);
|
|
151
|
-
do_custom_memalloc_test(false);
|
|
152
|
-
do_options_test();
|
|
153
|
-
do_fault_injection_test();
|
|
154
|
-
return 0;
|
|
155
|
-
}
|