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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 729474c9a3f3196fe69a06dfdd280c5879bc368b1884b8d508b75164aa7e1dcd
4
- data.tar.gz: 1cdf1b0554dd89aa1f7b6450be8eb183773a0f3b895024715ae7b3243cec598b
3
+ metadata.gz: 63e93f85ee472c512ed26f0e7da7fd352b143fab32dcf5e902772bc1f202c7b0
4
+ data.tar.gz: 681ea9a091527554620a032b003f578684a743ecba43c66dfb1682b1e15db794
5
5
  SHA512:
6
- metadata.gz: d69bc35190b5dbc8ce36f9e5acf6ef26a2c85a899ddd409f8eee4a83b005166b20d22e2659cae1b101fb1b97f6a7bf12cf4066e3da94b2a1991d41bf255cd1ce
7
- data.tar.gz: 2ee85e56a8ae268da1e4b69bf35a016a5d9bc677f240435725e082b5c5279e60d7f8be32dbe57283e618b7cf59b3937b57aa859f6cbb0aafa64458a903747fa2
6
+ metadata.gz: 4245143daaf4a8c905e7c82eec53c60fcf391f55e21fa1f39c9aca76cccefedc6c90a25a9c581255f6fc3ea909501eb83a219c461b1b24b1f2e6552c4281d16e
7
+ data.tar.gz: 6294213e536fd3117e6f2de7efdb58d9754344bc9d4aff83ec6943e0958dfe4e1cdae9316c6ca2a778e08f6573390fdf026f053677def60aa92abf8e5c98518f
@@ -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 compress_params {
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* compress_wrapper(void* args)
55
+ static void* stream_compress_wrapper(void* args)
56
56
  {
57
- struct compress_params* params = args;
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 zstd_compress(ZSTD_CCtx* const ctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, ZSTD_EndDirective endOp, bool gvl)
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 compress_params params = { ctx, output, input, endOp };
69
- rb_thread_call_without_gvl(compress_wrapper, &params, NULL, NULL);
68
+ struct stream_compress_params params = { ctx, output, input, endOp };
69
+ rb_thread_call_without_gvl(stream_compress_wrapper, &params, 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, &params, 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 decompress_params {
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* decompress_wrapper(void* args)
133
+ static void* stream_decompress_wrapper(void* args)
103
134
  {
104
- struct decompress_params* params = args;
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 zstd_decompress(ZSTD_DCtx* const dctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, bool gvl)
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 decompress_params params = { dctx, output, input };
116
- rb_thread_call_without_gvl(decompress_wrapper, &params, NULL, NULL);
146
+ struct stream_decompress_params params = { dctx, output, input };
147
+ rb_thread_call_without_gvl(stream_decompress_wrapper, &params, 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, &params, 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 = zstd_compress(sc->ctx, &output, &input, endOp, false);
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 = zstd_compress(sc->ctx, &output, &input, ZSTD_e_continue, false);
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 = zstd_compress(sc->ctx, &output, &input, ZSTD_e_continue, false);
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 = zstd_decompress(sd->dctx, &output, &input, false);
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
  }
@@ -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
- ZSTD_inBuffer input = { input_data, input_size, 0 };
29
- // ZSTD_compressBound causes SEGV under multi-thread
28
+
30
29
  size_t max_compressed_size = ZSTD_compressBound(input_size);
31
- VALUE buf = rb_str_new(NULL, max_compressed_size);
32
- char* output_data = RSTRING_PTR(buf);
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, &output, &input, ZSTD_e_end, true);
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
- ZSTD_freeCCtx(ctx);
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
- VALUE result = rb_str_new(0, 0);
41
- rb_str_cat(result, output.dst, output.pos);
37
+ rb_str_resize(output, ret);
38
+
42
39
  ZSTD_freeCCtx(ctx);
43
- return result;
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 = zstd_decompress(dctx, &output, &input, true);
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 = ZSTD_decompressDCtx(dctx, output_data, uncompressed_size, input_data, input_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
 
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "1.5.6.3"
2
+ VERSION = "1.5.6.5"
3
3
  end
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.3
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-13 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler