extzstd 0.3.2 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/contrib/zstd/CHANGELOG +225 -1
- data/contrib/zstd/CONTRIBUTING.md +158 -75
- data/contrib/zstd/LICENSE +4 -4
- data/contrib/zstd/Makefile +106 -69
- data/contrib/zstd/Package.swift +36 -0
- data/contrib/zstd/README.md +64 -36
- data/contrib/zstd/SECURITY.md +15 -0
- data/contrib/zstd/TESTING.md +2 -3
- data/contrib/zstd/lib/BUCK +5 -7
- data/contrib/zstd/lib/Makefile +117 -199
- data/contrib/zstd/lib/README.md +37 -7
- data/contrib/zstd/lib/common/allocations.h +55 -0
- data/contrib/zstd/lib/common/bits.h +200 -0
- data/contrib/zstd/lib/common/bitstream.h +80 -86
- data/contrib/zstd/lib/common/compiler.h +225 -63
- data/contrib/zstd/lib/common/cpu.h +37 -1
- data/contrib/zstd/lib/common/debug.c +7 -1
- data/contrib/zstd/lib/common/debug.h +21 -12
- data/contrib/zstd/lib/common/entropy_common.c +15 -37
- data/contrib/zstd/lib/common/error_private.c +9 -2
- data/contrib/zstd/lib/common/error_private.h +93 -5
- data/contrib/zstd/lib/common/fse.h +12 -87
- data/contrib/zstd/lib/common/fse_decompress.c +37 -117
- data/contrib/zstd/lib/common/huf.h +97 -172
- data/contrib/zstd/lib/common/mem.h +58 -58
- data/contrib/zstd/lib/common/pool.c +38 -17
- data/contrib/zstd/lib/common/pool.h +10 -4
- data/contrib/zstd/lib/common/portability_macros.h +158 -0
- data/contrib/zstd/lib/common/threading.c +74 -14
- data/contrib/zstd/lib/common/threading.h +5 -10
- data/contrib/zstd/lib/common/xxhash.c +6 -814
- data/contrib/zstd/lib/common/xxhash.h +6930 -195
- data/contrib/zstd/lib/common/zstd_common.c +1 -36
- data/contrib/zstd/lib/common/zstd_deps.h +1 -1
- data/contrib/zstd/lib/common/zstd_internal.h +68 -154
- data/contrib/zstd/lib/common/zstd_trace.h +163 -0
- data/contrib/zstd/lib/compress/clevels.h +134 -0
- data/contrib/zstd/lib/compress/fse_compress.c +75 -155
- data/contrib/zstd/lib/compress/hist.c +1 -1
- data/contrib/zstd/lib/compress/hist.h +1 -1
- data/contrib/zstd/lib/compress/huf_compress.c +810 -259
- data/contrib/zstd/lib/compress/zstd_compress.c +2864 -919
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +523 -192
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +251 -412
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/contrib/zstd/lib/compress/zstd_cwksp.h +284 -97
- data/contrib/zstd/lib/compress/zstd_double_fast.c +382 -133
- data/contrib/zstd/lib/compress/zstd_double_fast.h +14 -2
- data/contrib/zstd/lib/compress/zstd_fast.c +732 -260
- data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
- data/contrib/zstd/lib/compress/zstd_lazy.c +1177 -390
- data/contrib/zstd/lib/compress/zstd_lazy.h +129 -14
- data/contrib/zstd/lib/compress/zstd_ldm.c +280 -210
- data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
- data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +516 -285
- data/contrib/zstd/lib/compress/zstd_opt.h +32 -8
- data/contrib/zstd/lib/compress/zstdmt_compress.c +202 -131
- data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
- data/contrib/zstd/lib/decompress/huf_decompress.c +1149 -555
- data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/contrib/zstd/lib/decompress/zstd_decompress.c +583 -106
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1054 -379
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +56 -6
- data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/contrib/zstd/lib/dictBuilder/cover.c +60 -44
- data/contrib/zstd/lib/dictBuilder/cover.h +6 -11
- data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
- data/contrib/zstd/lib/dictBuilder/fastcover.c +26 -18
- data/contrib/zstd/lib/dictBuilder/zdict.c +100 -101
- data/contrib/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/contrib/zstd/lib/legacy/zstd_v01.c +18 -53
- data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +28 -85
- data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +29 -88
- data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +27 -80
- data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v05.c +36 -85
- data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v06.c +44 -96
- data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +37 -92
- data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
- data/contrib/zstd/lib/libzstd.mk +237 -0
- data/contrib/zstd/lib/libzstd.pc.in +4 -3
- data/contrib/zstd/lib/module.modulemap +35 -0
- data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
- data/contrib/zstd/lib/zstd.h +1030 -332
- data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
- data/ext/extconf.rb +26 -7
- data/ext/extzstd.c +51 -24
- data/ext/extzstd.h +33 -6
- data/ext/extzstd_stream.c +74 -31
- data/ext/libzstd_conf.h +0 -1
- data/ext/zstd_decompress_asm.S +1 -0
- metadata +17 -7
- data/contrib/zstd/appveyor.yml +0 -292
- data/ext/depend +0 -2
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -20,19 +20,31 @@ extern "C" {
|
|
20
20
|
|
21
21
|
|
22
22
|
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
|
23
|
-
#ifndef
|
24
|
-
|
25
|
-
#
|
23
|
+
#ifndef ZSTDERRORLIB_VISIBLE
|
24
|
+
/* Backwards compatibility with old macro name */
|
25
|
+
# ifdef ZSTDERRORLIB_VISIBILITY
|
26
|
+
# define ZSTDERRORLIB_VISIBLE ZSTDERRORLIB_VISIBILITY
|
27
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
28
|
+
# define ZSTDERRORLIB_VISIBLE __attribute__ ((visibility ("default")))
|
26
29
|
# else
|
27
|
-
# define
|
30
|
+
# define ZSTDERRORLIB_VISIBLE
|
28
31
|
# endif
|
29
32
|
#endif
|
33
|
+
|
34
|
+
#ifndef ZSTDERRORLIB_HIDDEN
|
35
|
+
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
36
|
+
# define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
37
|
+
# else
|
38
|
+
# define ZSTDERRORLIB_HIDDEN
|
39
|
+
# endif
|
40
|
+
#endif
|
41
|
+
|
30
42
|
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
31
|
-
# define ZSTDERRORLIB_API __declspec(dllexport)
|
43
|
+
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBLE
|
32
44
|
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
33
|
-
# define ZSTDERRORLIB_API __declspec(dllimport)
|
45
|
+
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
34
46
|
#else
|
35
|
-
# define ZSTDERRORLIB_API
|
47
|
+
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
|
36
48
|
#endif
|
37
49
|
|
38
50
|
/*-*********************************************
|
@@ -58,14 +70,17 @@ typedef enum {
|
|
58
70
|
ZSTD_error_frameParameter_windowTooLarge = 16,
|
59
71
|
ZSTD_error_corruption_detected = 20,
|
60
72
|
ZSTD_error_checksum_wrong = 22,
|
73
|
+
ZSTD_error_literals_headerWrong = 24,
|
61
74
|
ZSTD_error_dictionary_corrupted = 30,
|
62
75
|
ZSTD_error_dictionary_wrong = 32,
|
63
76
|
ZSTD_error_dictionaryCreation_failed = 34,
|
64
77
|
ZSTD_error_parameter_unsupported = 40,
|
78
|
+
ZSTD_error_parameter_combination_unsupported = 41,
|
65
79
|
ZSTD_error_parameter_outOfBound = 42,
|
66
80
|
ZSTD_error_tableLog_tooLarge = 44,
|
67
81
|
ZSTD_error_maxSymbolValue_tooLarge = 46,
|
68
82
|
ZSTD_error_maxSymbolValue_tooSmall = 48,
|
83
|
+
ZSTD_error_stabilityCondition_notRespected = 50,
|
69
84
|
ZSTD_error_stage_wrong = 60,
|
70
85
|
ZSTD_error_init_missing = 62,
|
71
86
|
ZSTD_error_memory_allocation = 64,
|
@@ -73,11 +88,15 @@ typedef enum {
|
|
73
88
|
ZSTD_error_dstSize_tooSmall = 70,
|
74
89
|
ZSTD_error_srcSize_wrong = 72,
|
75
90
|
ZSTD_error_dstBuffer_null = 74,
|
91
|
+
ZSTD_error_noForwardProgress_destFull = 80,
|
92
|
+
ZSTD_error_noForwardProgress_inputEmpty = 82,
|
76
93
|
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
77
94
|
ZSTD_error_frameIndex_tooLarge = 100,
|
78
95
|
ZSTD_error_seekableIO = 102,
|
79
96
|
ZSTD_error_dstBuffer_wrong = 104,
|
80
97
|
ZSTD_error_srcBuffer_wrong = 105,
|
98
|
+
ZSTD_error_sequenceProducer_failed = 106,
|
99
|
+
ZSTD_error_externalSequences_invalid = 107,
|
81
100
|
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
82
101
|
} ZSTD_ErrorCode;
|
83
102
|
|
data/ext/extconf.rb
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
require "mkmf"
|
4
4
|
|
5
|
+
using Module.new {
|
6
|
+
refine Object do
|
7
|
+
def has_function_modifier?(modifier_code)
|
8
|
+
try_compile(<<~CODE)
|
9
|
+
#{modifier_code}
|
10
|
+
void
|
11
|
+
func1(void) {
|
12
|
+
}
|
13
|
+
CODE
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
5
18
|
$INCFLAGS = %w(
|
6
19
|
-I$(srcdir)/../contrib
|
7
20
|
-I$(srcdir)/../contrib/zstd/lib
|
@@ -10,12 +23,13 @@ $INCFLAGS = %w(
|
|
10
23
|
-I$(srcdir)/../contrib/zstd/lib/legacy
|
11
24
|
).join(" ") + " #$INCFLAGS"
|
12
25
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
26
|
+
#if libzstd が 1.5.1 以降で gcc/clang であれば
|
27
|
+
dir = __dir__
|
28
|
+
dir1 = dir.gsub(/[\[\{\?\*]/, "[\\0]")
|
29
|
+
filepattern = "**/*.[cS]"
|
30
|
+
target = File.join(dir1, filepattern)
|
31
|
+
$srcs = Dir.glob(target).sort
|
32
|
+
#end
|
19
33
|
|
20
34
|
if RbConfig::CONFIG["arch"] =~ /mingw/i
|
21
35
|
$LDFLAGS << " -static-libgcc" if try_ldflags("-static-libgcc")
|
@@ -25,9 +39,14 @@ __attribute__ ((visibility("hidden"))) int conftest(void) { return 0; }
|
|
25
39
|
VISIBILITY
|
26
40
|
if try_cflags("-fvisibility=hidden")
|
27
41
|
$CFLAGS << " -fvisibility=hidden"
|
28
|
-
$defs << %(
|
42
|
+
$defs << %(-DRBEXT_API='__attribute__ ((visibility("default")))')
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
47
|
+
mod = %w(__attribute__((__noreturn__)) __declspec(noreturn) [[noreturn]] _Noreturn).find { |m|
|
48
|
+
has_function_modifier?(m)
|
49
|
+
}
|
50
|
+
$defs << %(-DRBEXT_NORETURN='#{mod}')
|
51
|
+
|
33
52
|
create_makefile File.join(RUBY_VERSION.slice(/\d+\.\d+/), "extzstd")
|
data/ext/extzstd.c
CHANGED
@@ -71,6 +71,7 @@ extzstd_check_error(ssize_t errcode)
|
|
71
71
|
}
|
72
72
|
}
|
73
73
|
|
74
|
+
RBEXT_NORETURN
|
74
75
|
void
|
75
76
|
extzstd_error(ssize_t errcode)
|
76
77
|
{
|
@@ -80,8 +81,6 @@ extzstd_error(ssize_t errcode)
|
|
80
81
|
VALUE
|
81
82
|
extzstd_make_errorf(ssize_t errcode, const char *fmt, ...)
|
82
83
|
{
|
83
|
-
VALUE e;
|
84
|
-
|
85
84
|
if (fmt && strlen(fmt) > 0) {
|
86
85
|
VALUE args[] = { SSIZET2NUM(errcode), Qnil };
|
87
86
|
va_list va;
|
@@ -171,13 +170,14 @@ init_constants(void)
|
|
171
170
|
rb_define_const(mConstants, "ZSTD_HASHLOG_MIN", INT2NUM(ZSTD_HASHLOG_MIN));
|
172
171
|
rb_define_const(mConstants, "ZSTD_CHAINLOG_MAX", INT2NUM(ZSTD_CHAINLOG_MAX));
|
173
172
|
rb_define_const(mConstants, "ZSTD_CHAINLOG_MIN", INT2NUM(ZSTD_CHAINLOG_MIN));
|
174
|
-
rb_define_const(mConstants, "ZSTD_HASHLOG3_MAX", INT2NUM(ZSTD_HASHLOG3_MAX));
|
175
173
|
rb_define_const(mConstants, "ZSTD_SEARCHLOG_MAX", INT2NUM(ZSTD_SEARCHLOG_MAX));
|
176
174
|
rb_define_const(mConstants, "ZSTD_SEARCHLOG_MIN", INT2NUM(ZSTD_SEARCHLOG_MIN));
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
175
|
+
rb_define_const(mConstants, "ZSTD_MINMATCH_MAX", INT2NUM(ZSTD_MINMATCH_MAX));
|
176
|
+
rb_define_const(mConstants, "ZSTD_MINMATCH_MIN", INT2NUM(ZSTD_MINMATCH_MIN));
|
177
|
+
rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
|
178
|
+
rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
|
179
|
+
rb_define_const(mConstants, "ZSTD_STRATEGY_MIN", INT2NUM(ZSTD_STRATEGY_MIN));
|
180
|
+
rb_define_const(mConstants, "ZSTD_STRATEGY_MAX", INT2NUM(ZSTD_STRATEGY_MAX));
|
181
181
|
|
182
182
|
rb_define_const(mConstants, "FAST", INT2NUM(ZSTD_fast));
|
183
183
|
rb_define_const(mConstants, "DFAST", INT2NUM(ZSTD_dfast));
|
@@ -194,13 +194,15 @@ init_constants(void)
|
|
194
194
|
rb_define_const(mConstants, "HASHLOG_MIN", INT2NUM(ZSTD_HASHLOG_MIN));
|
195
195
|
rb_define_const(mConstants, "CHAINLOG_MAX", INT2NUM(ZSTD_CHAINLOG_MAX));
|
196
196
|
rb_define_const(mConstants, "CHAINLOG_MIN", INT2NUM(ZSTD_CHAINLOG_MIN));
|
197
|
-
rb_define_const(mConstants, "HASHLOG3_MAX", INT2NUM(ZSTD_HASHLOG3_MAX));
|
198
197
|
rb_define_const(mConstants, "SEARCHLOG_MAX", INT2NUM(ZSTD_SEARCHLOG_MAX));
|
199
198
|
rb_define_const(mConstants, "SEARCHLOG_MIN", INT2NUM(ZSTD_SEARCHLOG_MIN));
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
rb_define_const(mConstants, "MINMATCH_MAX", INT2NUM(ZSTD_MINMATCH_MAX));
|
200
|
+
rb_define_const(mConstants, "MINMATCH_MIN", INT2NUM(ZSTD_MINMATCH_MIN));
|
201
|
+
rb_define_const(mConstants, "TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
|
202
|
+
rb_define_const(mConstants, "TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
|
203
|
+
rb_define_const(mConstants, "STRATEGY_MIN", INT2NUM(ZSTD_STRATEGY_MIN));
|
204
|
+
rb_define_const(mConstants, "STRATEGY_MAX", INT2NUM(ZSTD_STRATEGY_MAX));
|
205
|
+
|
204
206
|
}
|
205
207
|
|
206
208
|
/*
|
@@ -458,17 +460,22 @@ static VALUE
|
|
458
460
|
dict_s_add_entropy_tables_from_buffer(VALUE mod, VALUE dict, VALUE dict_capacity, VALUE sample)
|
459
461
|
{
|
460
462
|
/*
|
461
|
-
* size_t
|
462
|
-
*
|
463
|
-
*
|
463
|
+
* ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dstDictBuffer, size_t maxDictSize,
|
464
|
+
* const void* dictContent, size_t dictContentSize,
|
465
|
+
* const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
466
|
+
* ZDICT_params_t parameters);
|
464
467
|
*/
|
465
468
|
|
466
469
|
rb_check_type(dict, RUBY_T_STRING);
|
467
470
|
rb_check_type(sample, RUBY_T_STRING);
|
468
471
|
size_t capa = NUM2SIZET(dict_capacity);
|
469
472
|
aux_str_modify_expand(dict, capa);
|
473
|
+
char *destptr = RSTRING_PTR(dict);
|
474
|
+
size_t destlen = RSTRING_LEN(dict);
|
475
|
+
const char *sampleptr = RSTRING_PTR(sample);
|
470
476
|
size_t samplesize = RSTRING_LEN(sample);
|
471
|
-
|
477
|
+
ZDICT_params_t params = { 0, 0, 0 };
|
478
|
+
size_t s = ZDICT_finalizeDictionary(destptr, capa, destptr, destlen, sampleptr, &samplesize, 1, params);
|
472
479
|
extzstd_check_error(s);
|
473
480
|
rb_str_set_len(dict, s);
|
474
481
|
return dict;
|
@@ -536,15 +543,32 @@ less_s_encode(VALUE mod, VALUE src, VALUE dest, VALUE maxdest, VALUE predict, VA
|
|
536
543
|
|
537
544
|
if (extzstd_params_p(params)) {
|
538
545
|
/*
|
539
|
-
* ZSTDLIB_API size_t
|
540
|
-
*
|
541
|
-
*
|
542
|
-
*
|
543
|
-
*
|
544
|
-
* ZSTD_parameters params);
|
546
|
+
* ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
|
547
|
+
* void* dst, size_t dstCapacity,
|
548
|
+
* const void* src, size_t srcSize);
|
549
|
+
* ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
|
550
|
+
* ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
|
545
551
|
*/
|
546
552
|
ZSTD_CCtx *zstd = ZSTD_createCCtx();
|
547
|
-
|
553
|
+
ZSTD_parameters *param = extzstd_getparams(params);
|
554
|
+
|
555
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_windowLog, param->cParams.windowLog);
|
556
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_chainLog, param->cParams.chainLog);
|
557
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_hashLog, param->cParams.hashLog);
|
558
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_searchLog, param->cParams.searchLog);
|
559
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_minMatch, param->cParams.minMatch);
|
560
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_targetLength, param->cParams.targetLength);
|
561
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_strategy, param->cParams.strategy);
|
562
|
+
|
563
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_contentSizeFlag, param->fParams.contentSizeFlag);
|
564
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_checksumFlag, param->fParams.checksumFlag);
|
565
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_dictIDFlag, !param->fParams.noDictIDFlag);
|
566
|
+
|
567
|
+
//aux_ZSTD_CCtx_setPledgedSrcSize(zstd, (unsigned long long)qsize);
|
568
|
+
|
569
|
+
aux_ZSTD_CCtx_loadDictionary(zstd, d, dsize);
|
570
|
+
|
571
|
+
size_t s = ZSTD_compress2(zstd, r, rsize, q, qsize);
|
548
572
|
ZSTD_freeCCtx(zstd);
|
549
573
|
extzstd_check_error(s);
|
550
574
|
rb_str_set_len(dest, s);
|
@@ -584,7 +608,7 @@ less_s_decode(VALUE mod, VALUE src, VALUE dest, VALUE maxdest, VALUE predict)
|
|
584
608
|
aux_string_pointer(src, &q, &qsize);
|
585
609
|
|
586
610
|
char *r;
|
587
|
-
size_t rsize = (NIL_P(maxdest)) ?
|
611
|
+
size_t rsize = (NIL_P(maxdest)) ? ZSTD_getFrameContentSize(q, qsize) : NUM2SIZET(maxdest);
|
588
612
|
aux_string_expand_pointer(dest, &r, rsize);
|
589
613
|
rb_obj_infect(dest, src);
|
590
614
|
|
@@ -631,4 +655,7 @@ Init_extzstd(void)
|
|
631
655
|
init_dictionary();
|
632
656
|
init_contextless();
|
633
657
|
extzstd_init_stream();
|
658
|
+
|
659
|
+
(void)params_alloc_dummy;
|
660
|
+
(void)getparamsp;
|
634
661
|
}
|
data/ext/extzstd.h
CHANGED
@@ -35,7 +35,7 @@ extern VALUE extzstd_eError;
|
|
35
35
|
extern void init_extzstd_stream(void);
|
36
36
|
extern void extzstd_init_buffered(void);
|
37
37
|
extern void extzstd_init_stream(void);
|
38
|
-
extern void extzstd_error(ssize_t errcode);
|
38
|
+
extern RBEXT_NORETURN void extzstd_error(ssize_t errcode);
|
39
39
|
extern void extzstd_check_error(ssize_t errcode);
|
40
40
|
extern VALUE extzstd_make_error(ssize_t errcode);
|
41
41
|
extern VALUE extzstd_make_errorf(ssize_t errcode, const char *fmt, ...);
|
@@ -44,7 +44,7 @@ extern ZSTD_parameters *extzstd_getparams(VALUE v);
|
|
44
44
|
extern int extzstd_params_p(VALUE v);
|
45
45
|
extern VALUE extzstd_params_alloc(ZSTD_parameters **p);
|
46
46
|
|
47
|
-
static inline void
|
47
|
+
static RBEXT_NORETURN inline void
|
48
48
|
referror(VALUE v)
|
49
49
|
{
|
50
50
|
rb_raise(rb_eRuntimeError,
|
@@ -52,7 +52,7 @@ referror(VALUE v)
|
|
52
52
|
rb_obj_classname(v), (void *)v);
|
53
53
|
}
|
54
54
|
|
55
|
-
static inline void
|
55
|
+
static RBEXT_NORETURN inline void
|
56
56
|
reiniterror(VALUE v)
|
57
57
|
{
|
58
58
|
rb_raise(rb_eRuntimeError,
|
@@ -200,14 +200,14 @@ aux_const_dig_str_0(VALUE obj, const char *p[], const char **pp)
|
|
200
200
|
#endif
|
201
201
|
|
202
202
|
|
203
|
-
static void
|
203
|
+
static inline void
|
204
204
|
aux_string_pointer(VALUE str, const char **ptr, size_t *size)
|
205
205
|
{
|
206
206
|
rb_check_type(str, RUBY_T_STRING);
|
207
207
|
RSTRING_GETMEM(str, *ptr, *size);
|
208
208
|
}
|
209
209
|
|
210
|
-
static void
|
210
|
+
static inline void
|
211
211
|
aux_string_pointer_with_nil(VALUE str, const char **ptr, size_t *size)
|
212
212
|
{
|
213
213
|
if (NIL_P(str)) {
|
@@ -218,7 +218,7 @@ aux_string_pointer_with_nil(VALUE str, const char **ptr, size_t *size)
|
|
218
218
|
}
|
219
219
|
}
|
220
220
|
|
221
|
-
static void
|
221
|
+
static inline void
|
222
222
|
aux_string_expand_pointer(VALUE str, char **ptr, size_t size)
|
223
223
|
{
|
224
224
|
rb_check_type(str, RUBY_T_STRING);
|
@@ -232,4 +232,31 @@ aux_string_expand_pointer(VALUE str, char **ptr, size_t size)
|
|
232
232
|
# define rb_obj_infect(dest, src) ((void)(dest), (void)(src))
|
233
233
|
#endif
|
234
234
|
|
235
|
+
#define MAKE_AUX_FUNC(auxdecl, funcall, cleanup) \
|
236
|
+
static inline size_t \
|
237
|
+
auxdecl \
|
238
|
+
{ \
|
239
|
+
size_t s = funcall; \
|
240
|
+
\
|
241
|
+
if (ZSTD_isError(s)) { \
|
242
|
+
cleanup; \
|
243
|
+
extzstd_error(s); \
|
244
|
+
} \
|
245
|
+
\
|
246
|
+
return s; \
|
247
|
+
} \
|
248
|
+
|
249
|
+
MAKE_AUX_FUNC(aux_ZSTD_CCtx_reset(ZSTD_CCtx *zstd, ZSTD_ResetDirective reset),
|
250
|
+
ZSTD_CCtx_reset(zstd, reset),
|
251
|
+
ZSTD_freeCCtx(zstd))
|
252
|
+
MAKE_AUX_FUNC(aux_ZSTD_CCtx_setParameter(ZSTD_CCtx *ctx, ZSTD_cParameter param, int value),
|
253
|
+
ZSTD_CCtx_setParameter(ctx, param, value),
|
254
|
+
ZSTD_freeCCtx(ctx))
|
255
|
+
MAKE_AUX_FUNC(aux_ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx *ctx, unsigned long long pledgedSrcSize),
|
256
|
+
ZSTD_CCtx_setPledgedSrcSize(ctx, pledgedSrcSize),
|
257
|
+
ZSTD_freeCCtx(ctx))
|
258
|
+
MAKE_AUX_FUNC(aux_ZSTD_CCtx_loadDictionary(ZSTD_CCtx *ctx, const void* dict, size_t dictSize),
|
259
|
+
ZSTD_CCtx_loadDictionary(ctx, dict, dictSize),
|
260
|
+
ZSTD_freeCCtx(ctx))
|
261
|
+
|
235
262
|
#endif /* EXTZSTD_H */
|
data/ext/extzstd_stream.c
CHANGED
@@ -9,12 +9,13 @@ enum {
|
|
9
9
|
};
|
10
10
|
|
11
11
|
static inline VALUE
|
12
|
-
aux_str_buf_recycle(VALUE str, size_t capacity)
|
12
|
+
aux_str_buf_recycle(VALUE *str, size_t capacity)
|
13
13
|
{
|
14
|
-
if (!RTEST(str) || rb_obj_frozen_p(str) || !rb_type_p(str, RUBY_T_STRING)) {
|
15
|
-
|
14
|
+
if (!RTEST(*str) || rb_obj_frozen_p(*str) || !rb_type_p(*str, RUBY_T_STRING)) {
|
15
|
+
*str = rb_str_buf_new(capacity);
|
16
|
+
return *str;
|
16
17
|
} else {
|
17
|
-
return aux_str_modify_expand(str, capacity);
|
18
|
+
return aux_str_modify_expand(*str, capacity);
|
18
19
|
}
|
19
20
|
}
|
20
21
|
|
@@ -128,10 +129,6 @@ enc_init(int argc, VALUE argv[], VALUE self)
|
|
128
129
|
rb_obj_classname(self), (void *)self);
|
129
130
|
}
|
130
131
|
|
131
|
-
AUX_TRY_WITH_GC(
|
132
|
-
p->context = ZSTD_createCStream(),
|
133
|
-
"failed ZSTD_createCStream()");
|
134
|
-
|
135
132
|
const void *predictp;
|
136
133
|
size_t predictsize;
|
137
134
|
if (NIL_P(predict)) {
|
@@ -143,13 +140,39 @@ enc_init(int argc, VALUE argv[], VALUE self)
|
|
143
140
|
RSTRING_GETMEM(predict, predictp, predictsize);
|
144
141
|
}
|
145
142
|
|
143
|
+
AUX_TRY_WITH_GC(
|
144
|
+
p->context = ZSTD_createCStream(),
|
145
|
+
"failed ZSTD_createCStream()");
|
146
|
+
|
146
147
|
if (extzstd_params_p(params)) {
|
147
148
|
ZSTD_parameters *paramsp = extzstd_getparams(params);
|
148
|
-
|
149
|
-
|
149
|
+
ZSTD_CCtx *zstd = p->context;
|
150
|
+
p->context = NULL; // 一時的に無効化する
|
151
|
+
|
152
|
+
aux_ZSTD_CCtx_reset(zstd, ZSTD_reset_session_and_parameters);
|
153
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_windowLog, paramsp->cParams.windowLog);
|
154
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_chainLog, paramsp->cParams.chainLog);
|
155
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_hashLog, paramsp->cParams.hashLog);
|
156
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_searchLog, paramsp->cParams.searchLog);
|
157
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_minMatch, paramsp->cParams.minMatch);
|
158
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_targetLength, paramsp->cParams.targetLength);
|
159
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_strategy, paramsp->cParams.strategy);
|
160
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_contentSizeFlag, paramsp->fParams.contentSizeFlag);
|
161
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_checksumFlag, paramsp->fParams.checksumFlag);
|
162
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_dictIDFlag, !paramsp->fParams.noDictIDFlag);
|
163
|
+
aux_ZSTD_CCtx_loadDictionary(zstd, predictp, predictsize);
|
164
|
+
|
165
|
+
p->context = zstd;
|
150
166
|
} else {
|
151
|
-
|
152
|
-
|
167
|
+
int clevel = aux_num2int(params, ZSTD_CLEVEL_DEFAULT);
|
168
|
+
ZSTD_CCtx *zstd = p->context;
|
169
|
+
p->context = NULL; // 一時的に無効化する
|
170
|
+
|
171
|
+
aux_ZSTD_CCtx_reset(zstd, ZSTD_reset_session_and_parameters);
|
172
|
+
aux_ZSTD_CCtx_setParameter(zstd, ZSTD_c_compressionLevel, clevel);
|
173
|
+
aux_ZSTD_CCtx_loadDictionary(zstd, predictp, predictsize);
|
174
|
+
|
175
|
+
p->context = zstd;
|
153
176
|
}
|
154
177
|
|
155
178
|
p->predict = predict;
|
@@ -170,7 +193,7 @@ enc_write(VALUE self, VALUE src)
|
|
170
193
|
ZSTD_inBuffer input = { RSTRING_PTR(src), RSTRING_LEN(src), 0 };
|
171
194
|
|
172
195
|
while (input.pos < input.size) {
|
173
|
-
|
196
|
+
aux_str_buf_recycle(&p->destbuf, ZSTD_CStreamOutSize() * 2);
|
174
197
|
rb_str_set_len(p->destbuf, 0);
|
175
198
|
rb_obj_infect(self, src);
|
176
199
|
rb_obj_infect(p->destbuf, self);
|
@@ -195,7 +218,7 @@ enc_sync(VALUE self)
|
|
195
218
|
*/
|
196
219
|
|
197
220
|
struct encoder *p = encoder_context(self);
|
198
|
-
aux_str_buf_recycle(p->destbuf, ZSTD_CStreamOutSize());
|
221
|
+
aux_str_buf_recycle(&p->destbuf, ZSTD_CStreamOutSize());
|
199
222
|
rb_str_set_len(p->destbuf, 0);
|
200
223
|
rb_obj_infect(p->destbuf, self);
|
201
224
|
ZSTD_outBuffer output = { RSTRING_PTR(p->destbuf), rb_str_capacity(p->destbuf), 0 };
|
@@ -216,7 +239,7 @@ enc_close(VALUE self)
|
|
216
239
|
*/
|
217
240
|
|
218
241
|
struct encoder *p = encoder_context(self);
|
219
|
-
aux_str_buf_recycle(p->destbuf, ZSTD_CStreamOutSize());
|
242
|
+
aux_str_buf_recycle(&p->destbuf, ZSTD_CStreamOutSize());
|
220
243
|
rb_str_set_len(p->destbuf, 0);
|
221
244
|
rb_obj_infect(p->destbuf, self);
|
222
245
|
ZSTD_outBuffer output = { RSTRING_PTR(p->destbuf), rb_str_capacity(p->destbuf), 0 };
|
@@ -241,11 +264,18 @@ static VALUE
|
|
241
264
|
enc_reset(VALUE self, VALUE pledged_srcsize)
|
242
265
|
{
|
243
266
|
/*
|
244
|
-
* ZSTDLIB_API size_t
|
267
|
+
* ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
|
245
268
|
*/
|
246
269
|
|
247
|
-
size_t s =
|
270
|
+
size_t s = ZSTD_CCtx_reset(encoder_context(self)->context, ZSTD_reset_session_only);
|
248
271
|
extzstd_check_error(s);
|
272
|
+
|
273
|
+
if (pledged_srcsize == Qnil) {
|
274
|
+
ZSTD_CCtx_setPledgedSrcSize(encoder_context(self)->context, ZSTD_CONTENTSIZE_UNKNOWN);
|
275
|
+
} else {
|
276
|
+
ZSTD_CCtx_setPledgedSrcSize(encoder_context(self)->context, NUM2ULL(pledged_srcsize));
|
277
|
+
}
|
278
|
+
|
249
279
|
return self;
|
250
280
|
}
|
251
281
|
|
@@ -281,6 +311,10 @@ init_encoder(void)
|
|
281
311
|
rb_define_alias(cStreamEncoder, "flush", "sync");
|
282
312
|
rb_define_alias(cStreamEncoder, "end", "close");
|
283
313
|
rb_define_alias(cStreamEncoder, "finish", "close");
|
314
|
+
|
315
|
+
(void)encoder_alloc_dummy;
|
316
|
+
(void)getencoderp;
|
317
|
+
(void)encoder_p;
|
284
318
|
}
|
285
319
|
|
286
320
|
/*
|
@@ -291,7 +325,7 @@ static VALUE cStreamDecoder;
|
|
291
325
|
|
292
326
|
struct decoder
|
293
327
|
{
|
294
|
-
|
328
|
+
ZSTD_DCtx *context;
|
295
329
|
VALUE inport;
|
296
330
|
VALUE readbuf;
|
297
331
|
VALUE predict;
|
@@ -313,7 +347,7 @@ dec_free(void *pp)
|
|
313
347
|
{
|
314
348
|
struct decoder *p = (struct decoder *)pp;
|
315
349
|
if (p->context) {
|
316
|
-
|
350
|
+
ZSTD_freeDCtx(p->context);
|
317
351
|
p->context = NULL;
|
318
352
|
}
|
319
353
|
xfree(p);
|
@@ -352,6 +386,8 @@ static VALUE
|
|
352
386
|
dec_init(int argc, VALUE argv[], VALUE self)
|
353
387
|
{
|
354
388
|
/*
|
389
|
+
* ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
|
390
|
+
*
|
355
391
|
* ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
|
356
392
|
* ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
|
357
393
|
*/
|
@@ -379,16 +415,19 @@ dec_init(int argc, VALUE argv[], VALUE self)
|
|
379
415
|
}
|
380
416
|
|
381
417
|
AUX_TRY_WITH_GC(
|
382
|
-
p->context =
|
383
|
-
"failed
|
418
|
+
p->context = ZSTD_createDCtx(),
|
419
|
+
"failed ZSTD_createDCtx()");
|
384
420
|
|
421
|
+
//ZSTD_DCtx_reset
|
422
|
+
//ZSTD_DCtx_loadDictionary
|
385
423
|
if (NIL_P(predict)) {
|
386
|
-
size_t s = ZSTD_initDStream(p->context);
|
387
|
-
extzstd_check_error(s);
|
424
|
+
//size_t s = ZSTD_initDStream(p->context);
|
425
|
+
//extzstd_check_error(s);
|
388
426
|
} else {
|
389
427
|
rb_check_type(predict, RUBY_T_STRING);
|
390
428
|
predict = rb_str_new_frozen(predict);
|
391
|
-
size_t s = ZSTD_initDStream_usingDict(p->context, RSTRING_PTR(predict), RSTRING_LEN(predict));
|
429
|
+
//size_t s = ZSTD_initDStream_usingDict(p->context, RSTRING_PTR(predict), RSTRING_LEN(predict));
|
430
|
+
size_t s = ZSTD_DCtx_loadDictionary(p->context, RSTRING_PTR(predict), RSTRING_LEN(predict));
|
392
431
|
extzstd_check_error(s);
|
393
432
|
}
|
394
433
|
|
@@ -401,8 +440,8 @@ dec_init(int argc, VALUE argv[], VALUE self)
|
|
401
440
|
static int
|
402
441
|
dec_read_fetch(VALUE o, struct decoder *p)
|
403
442
|
{
|
404
|
-
if (!p->inbuf.src || NIL_P(p->readbuf) || p->inbuf.pos >= RSTRING_LEN(p->readbuf)) {
|
405
|
-
|
443
|
+
if (!p->inbuf.src || NIL_P(p->readbuf) || p->inbuf.pos >= (size_t)RSTRING_LEN(p->readbuf)) {
|
444
|
+
aux_str_buf_recycle(&p->readbuf, EXT_PARTIAL_READ_SIZE);
|
406
445
|
VALUE st = AUX_FUNCALL(p->inport, id_read, INT2FIX(EXT_PARTIAL_READ_SIZE), p->readbuf);
|
407
446
|
if (NIL_P(st)) { return -1; }
|
408
447
|
rb_check_type(st, RUBY_T_STRING);
|
@@ -420,13 +459,14 @@ dec_read_fetch(VALUE o, struct decoder *p)
|
|
420
459
|
static size_t
|
421
460
|
dec_read_decode(VALUE o, struct decoder *p, char *buf, ssize_t size)
|
422
461
|
{
|
462
|
+
|
423
463
|
if (p->reached_eof != 0) {
|
424
464
|
return 0;
|
425
465
|
}
|
426
466
|
|
427
467
|
ZSTD_outBuffer output = { buf, size, 0 };
|
428
468
|
|
429
|
-
while (size < 0 || output.pos < size) {
|
469
|
+
while (size < 0 || output.pos < (size_t)size) {
|
430
470
|
if (dec_read_fetch(o, p) != 0) {
|
431
471
|
if (p->reached_eof == 0) {
|
432
472
|
rb_raise(rb_eRuntimeError,
|
@@ -563,10 +603,9 @@ dec_close(VALUE self)
|
|
563
603
|
static VALUE
|
564
604
|
dec_reset(VALUE self)
|
565
605
|
{
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
size_t s = ZSTD_resetDStream(decoder_context(self)->context);
|
606
|
+
//> ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
|
607
|
+
|
608
|
+
size_t s = ZSTD_DCtx_reset(decoder_context(self)->context, ZSTD_reset_session_only);
|
570
609
|
extzstd_check_error(s);
|
571
610
|
return self;
|
572
611
|
}
|
@@ -605,6 +644,10 @@ init_decoder(void)
|
|
605
644
|
rb_define_method(cStreamDecoder, "reset", dec_reset, 0);
|
606
645
|
rb_define_method(cStreamDecoder, "sizeof", dec_sizeof, 0);
|
607
646
|
rb_define_method(cStreamDecoder, "pos", dec_pos, 0);
|
647
|
+
|
648
|
+
(void)decoder_alloc_dummy;
|
649
|
+
(void)getdecoderp;
|
650
|
+
(void)decoder_p;
|
608
651
|
}
|
609
652
|
|
610
653
|
/*
|
data/ext/libzstd_conf.h
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
#include "../contrib/zstd/lib/decompress/huf_decompress_amd64.S"
|