zstd-ruby 1.5.6.3 → 1.5.6.5
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/ext/zstdruby/common.h +74 -12
- data/ext/zstdruby/streaming_compress.c +3 -3
- data/ext/zstdruby/streaming_decompress.c +1 -1
- data/ext/zstdruby/zstdruby.c +11 -14
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63e93f85ee472c512ed26f0e7da7fd352b143fab32dcf5e902772bc1f202c7b0
|
4
|
+
data.tar.gz: 681ea9a091527554620a032b003f578684a743ecba43c66dfb1682b1e15db794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4245143daaf4a8c905e7c82eec53c60fcf391f55e21fa1f39c9aca76cccefedc6c90a25a9c581255f6fc3ea909501eb83a219c461b1b24b1f2e6552c4281d16e
|
7
|
+
data.tar.gz: 6294213e536fd3117e6f2de7efdb58d9754344bc9d4aff83ec6943e0958dfe4e1cdae9316c6ca2a778e08f6573390fdf026f053677def60aa92abf8e5c98518f
|
data/ext/zstdruby/common.h
CHANGED
@@ -44,7 +44,7 @@ static void set_compress_params(ZSTD_CCtx* const ctx, VALUE level_from_args, VAL
|
|
44
44
|
}
|
45
45
|
}
|
46
46
|
|
47
|
-
struct
|
47
|
+
struct stream_compress_params {
|
48
48
|
ZSTD_CCtx* ctx;
|
49
49
|
ZSTD_outBuffer* output;
|
50
50
|
ZSTD_inBuffer* input;
|
@@ -52,21 +52,21 @@ struct compress_params {
|
|
52
52
|
size_t ret;
|
53
53
|
};
|
54
54
|
|
55
|
-
static void*
|
55
|
+
static void* stream_compress_wrapper(void* args)
|
56
56
|
{
|
57
|
-
struct
|
57
|
+
struct stream_compress_params* params = args;
|
58
58
|
params->ret = ZSTD_compressStream2(params->ctx, params->output, params->input, params->endOp);
|
59
59
|
return NULL;
|
60
60
|
}
|
61
61
|
|
62
|
-
static size_t
|
62
|
+
static size_t zstd_stream_compress(ZSTD_CCtx* const ctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, ZSTD_EndDirective endOp, bool gvl)
|
63
63
|
{
|
64
64
|
#ifdef HAVE_RUBY_THREAD_H
|
65
65
|
if (gvl) {
|
66
66
|
return ZSTD_compressStream2(ctx, output, input, endOp);
|
67
67
|
} else {
|
68
|
-
struct
|
69
|
-
rb_thread_call_without_gvl(
|
68
|
+
struct stream_compress_params params = { ctx, output, input, endOp };
|
69
|
+
rb_thread_call_without_gvl(stream_compress_wrapper, ¶ms, NULL, NULL);
|
70
70
|
return params.ret;
|
71
71
|
}
|
72
72
|
#else
|
@@ -74,6 +74,37 @@ static size_t zstd_compress(ZSTD_CCtx* const ctx, ZSTD_outBuffer* output, ZSTD_i
|
|
74
74
|
#endif
|
75
75
|
}
|
76
76
|
|
77
|
+
struct compress_params {
|
78
|
+
ZSTD_CCtx* ctx;
|
79
|
+
char* output_data;
|
80
|
+
size_t output_size;
|
81
|
+
char* input_data;
|
82
|
+
size_t input_size;
|
83
|
+
size_t ret;
|
84
|
+
};
|
85
|
+
|
86
|
+
static void* compress_wrapper(void* args)
|
87
|
+
{
|
88
|
+
struct compress_params* params = args;
|
89
|
+
params->ret = ZSTD_compress2(params->ctx ,params->output_data, params->output_size, params->input_data, params->input_size);
|
90
|
+
return NULL;
|
91
|
+
}
|
92
|
+
|
93
|
+
static size_t zstd_compress(ZSTD_CCtx* const ctx, char* output_data, size_t output_size, char* input_data, size_t input_size, bool gvl)
|
94
|
+
{
|
95
|
+
#ifdef HAVE_RUBY_THREAD_H
|
96
|
+
if (gvl) {
|
97
|
+
return ZSTD_compress2(ctx , output_data, output_size, input_data, input_size);
|
98
|
+
} else {
|
99
|
+
struct compress_params params = { ctx, output_data, output_size, input_data, input_size };
|
100
|
+
rb_thread_call_without_gvl(compress_wrapper, ¶ms, NULL, NULL);
|
101
|
+
return params.ret;
|
102
|
+
}
|
103
|
+
#else
|
104
|
+
return ZSTD_compress2(ctx , output_data, output_size, input_data, input_size);
|
105
|
+
#endif
|
106
|
+
}
|
107
|
+
|
77
108
|
static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
|
78
109
|
{
|
79
110
|
ID kwargs_keys[1];
|
@@ -92,28 +123,28 @@ static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
|
|
92
123
|
}
|
93
124
|
}
|
94
125
|
|
95
|
-
struct
|
126
|
+
struct stream_decompress_params {
|
96
127
|
ZSTD_DCtx* dctx;
|
97
128
|
ZSTD_outBuffer* output;
|
98
129
|
ZSTD_inBuffer* input;
|
99
130
|
size_t ret;
|
100
131
|
};
|
101
132
|
|
102
|
-
static void*
|
133
|
+
static void* stream_decompress_wrapper(void* args)
|
103
134
|
{
|
104
|
-
struct
|
135
|
+
struct stream_decompress_params* params = args;
|
105
136
|
params->ret = ZSTD_decompressStream(params->dctx, params->output, params->input);
|
106
137
|
return NULL;
|
107
138
|
}
|
108
139
|
|
109
|
-
static size_t
|
140
|
+
static size_t zstd_stream_decompress(ZSTD_DCtx* const dctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, bool gvl)
|
110
141
|
{
|
111
142
|
#ifdef HAVE_RUBY_THREAD_H
|
112
143
|
if (gvl) {
|
113
144
|
return ZSTD_decompressStream(dctx, output, input);
|
114
145
|
} else {
|
115
|
-
struct
|
116
|
-
rb_thread_call_without_gvl(
|
146
|
+
struct stream_decompress_params params = { dctx, output, input };
|
147
|
+
rb_thread_call_without_gvl(stream_decompress_wrapper, ¶ms, NULL, NULL);
|
117
148
|
return params.ret;
|
118
149
|
}
|
119
150
|
#else
|
@@ -121,4 +152,35 @@ static size_t zstd_decompress(ZSTD_DCtx* const dctx, ZSTD_outBuffer* output, ZST
|
|
121
152
|
#endif
|
122
153
|
}
|
123
154
|
|
155
|
+
struct decompress_params {
|
156
|
+
ZSTD_DCtx* dctx;
|
157
|
+
char* output_data;
|
158
|
+
size_t output_size;
|
159
|
+
char* input_data;
|
160
|
+
size_t input_size;
|
161
|
+
size_t ret;
|
162
|
+
};
|
163
|
+
|
164
|
+
static void* decompress_wrapper(void* args)
|
165
|
+
{
|
166
|
+
struct decompress_params* params = args;
|
167
|
+
params->ret = ZSTD_decompressDCtx(params->dctx, params->output_data, params->output_size, params->input_data, params->input_size);
|
168
|
+
return NULL;
|
169
|
+
}
|
170
|
+
|
171
|
+
static size_t zstd_decompress(ZSTD_DCtx* const dctx, char* output_data, size_t output_size, char* input_data, size_t input_size, bool gvl)
|
172
|
+
{
|
173
|
+
#ifdef HAVE_RUBY_THREAD_H
|
174
|
+
if (gvl) {
|
175
|
+
return ZSTD_decompressDCtx(dctx, output_data, output_size, input_data, input_size);
|
176
|
+
} else {
|
177
|
+
struct decompress_params params = { dctx, output_data, output_size, input_data, input_size };
|
178
|
+
rb_thread_call_without_gvl(decompress_wrapper, ¶ms, NULL, NULL);
|
179
|
+
return params.ret;
|
180
|
+
}
|
181
|
+
#else
|
182
|
+
return ZSTD_decompressDCtx(dctx, output_data, output_size, input_data, input_size);
|
183
|
+
#endif
|
184
|
+
}
|
185
|
+
|
124
186
|
#endif /* ZSTD_RUBY_H */
|
@@ -106,7 +106,7 @@ no_compress(struct streaming_compress_t* sc, ZSTD_EndDirective endOp)
|
|
106
106
|
do {
|
107
107
|
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
|
108
108
|
|
109
|
-
size_t const ret =
|
109
|
+
size_t const ret = zstd_stream_compress(sc->ctx, &output, &input, endOp, false);
|
110
110
|
if (ZSTD_isError(ret)) {
|
111
111
|
rb_raise(rb_eRuntimeError, "flush error error code: %s", ZSTD_getErrorName(ret));
|
112
112
|
}
|
@@ -130,7 +130,7 @@ rb_streaming_compress_compress(VALUE obj, VALUE src)
|
|
130
130
|
VALUE result = rb_str_new(0, 0);
|
131
131
|
while (input.pos < input.size) {
|
132
132
|
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
|
133
|
-
size_t const ret =
|
133
|
+
size_t const ret = zstd_stream_compress(sc->ctx, &output, &input, ZSTD_e_continue, false);
|
134
134
|
if (ZSTD_isError(ret)) {
|
135
135
|
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
136
136
|
}
|
@@ -157,7 +157,7 @@ rb_streaming_compress_write(int argc, VALUE *argv, VALUE obj)
|
|
157
157
|
|
158
158
|
while (input.pos < input.size) {
|
159
159
|
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
|
160
|
-
size_t const ret =
|
160
|
+
size_t const ret = zstd_stream_compress(sc->ctx, &output, &input, ZSTD_e_continue, false);
|
161
161
|
if (ZSTD_isError(ret)) {
|
162
162
|
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
163
163
|
}
|
@@ -104,7 +104,7 @@ rb_streaming_decompress_decompress(VALUE obj, VALUE src)
|
|
104
104
|
VALUE result = rb_str_new(0, 0);
|
105
105
|
while (input.pos < input.size) {
|
106
106
|
ZSTD_outBuffer output = { (void*)output_data, sd->buf_size, 0 };
|
107
|
-
size_t const ret =
|
107
|
+
size_t const ret = zstd_stream_decompress(sd->dctx, &output, &input, false);
|
108
108
|
if (ZSTD_isError(ret)) {
|
109
109
|
rb_raise(rb_eRuntimeError, "decompress error error code: %s", ZSTD_getErrorName(ret));
|
110
110
|
}
|
data/ext/zstdruby/zstdruby.c
CHANGED
@@ -25,22 +25,19 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
|
|
25
25
|
StringValue(input_value);
|
26
26
|
char* input_data = RSTRING_PTR(input_value);
|
27
27
|
size_t input_size = RSTRING_LEN(input_value);
|
28
|
-
|
29
|
-
// ZSTD_compressBound causes SEGV under multi-thread
|
28
|
+
|
30
29
|
size_t max_compressed_size = ZSTD_compressBound(input_size);
|
31
|
-
VALUE
|
32
|
-
char* output_data = RSTRING_PTR(
|
33
|
-
ZSTD_outBuffer output = { (void*)output_data, max_compressed_size, 0 };
|
30
|
+
VALUE output = rb_str_new(NULL, max_compressed_size);
|
31
|
+
char* output_data = RSTRING_PTR(output);
|
34
32
|
|
35
|
-
size_t const ret = zstd_compress(ctx,
|
33
|
+
size_t const ret = zstd_compress(ctx, output_data, max_compressed_size, input_data, input_size, false);
|
36
34
|
if (ZSTD_isError(ret)) {
|
37
|
-
|
38
|
-
rb_raise(rb_eRuntimeError, "%s: %s", "compress failed", ZSTD_getErrorName(ret));
|
35
|
+
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
39
36
|
}
|
40
|
-
|
41
|
-
|
37
|
+
rb_str_resize(output, ret);
|
38
|
+
|
42
39
|
ZSTD_freeCCtx(ctx);
|
43
|
-
return
|
40
|
+
return output;
|
44
41
|
}
|
45
42
|
|
46
43
|
static VALUE rb_compress_using_dict(int argc, VALUE *argv, VALUE self)
|
@@ -99,7 +96,7 @@ static VALUE decompress_buffered(ZSTD_DCtx* dctx, const char* input_data, size_t
|
|
99
96
|
rb_str_resize(output_string, output.size);
|
100
97
|
output.dst = RSTRING_PTR(output_string);
|
101
98
|
|
102
|
-
size_t ret =
|
99
|
+
size_t ret = zstd_stream_decompress(dctx, &output, &input, false);
|
103
100
|
if (ZSTD_isError(ret)) {
|
104
101
|
ZSTD_freeDCtx(dctx);
|
105
102
|
rb_raise(rb_eRuntimeError, "%s: %s", "ZSTD_decompressStream failed", ZSTD_getErrorName(ret));
|
@@ -137,11 +134,11 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
137
134
|
VALUE output = rb_str_new(NULL, uncompressed_size);
|
138
135
|
char* output_data = RSTRING_PTR(output);
|
139
136
|
|
140
|
-
size_t const decompress_size =
|
137
|
+
size_t const decompress_size = zstd_decompress(dctx, output_data, uncompressed_size, input_data, input_size, false);
|
141
138
|
if (ZSTD_isError(decompress_size)) {
|
142
139
|
rb_raise(rb_eRuntimeError, "%s: %s", "decompress error", ZSTD_getErrorName(decompress_size));
|
143
140
|
}
|
144
|
-
|
141
|
+
ZSTD_freeDCtx(dctx);
|
145
142
|
return output;
|
146
143
|
}
|
147
144
|
|
data/lib/zstd-ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zstd-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.6.
|
4
|
+
version: 1.5.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SpringMT
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|