zstd-ruby 1.5.6.4 → 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: fe4c394ffc4bcfd9e48c1baaa1dd91f8bf19f9bd65397218017c39145db14106
4
- data.tar.gz: 5b87fa1c74eff20d0abe4b90260ac6fdb0db8fc65afd4a571bf0f7b10aa419b2
3
+ metadata.gz: 63e93f85ee472c512ed26f0e7da7fd352b143fab32dcf5e902772bc1f202c7b0
4
+ data.tar.gz: 681ea9a091527554620a032b003f578684a743ecba43c66dfb1682b1e15db794
5
5
  SHA512:
6
- metadata.gz: ea1413beb577cc5c735f2a6514e99071bba67e40de2216d84b11afa77b653d36b026db573f06002797e4f258142b441331eaa4f9fb71e5426d1408ad4123bfeb
7
- data.tar.gz: 58476bc0ce00c3d612e1aa460728a2255fbb9e289b132dc76106f539b535323d71ce5c0cda3adcded4cd8407066b332f79efff8fe41085e64e8bdee6ac14f563
6
+ metadata.gz: 4245143daaf4a8c905e7c82eec53c60fcf391f55e21fa1f39c9aca76cccefedc6c90a25a9c581255f6fc3ea909501eb83a219c461b1b24b1f2e6552c4281d16e
7
+ data.tar.gz: 6294213e536fd3117e6f2de7efdb58d9754344bc9d4aff83ec6943e0958dfe4e1cdae9316c6ca2a778e08f6573390fdf026f053677def60aa92abf8e5c98518f
@@ -74,6 +74,37 @@ static size_t zstd_stream_compress(ZSTD_CCtx* const ctx, ZSTD_outBuffer* output,
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 */
@@ -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
  }
@@ -26,11 +26,11 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
26
26
  char* input_data = RSTRING_PTR(input_value);
27
27
  size_t input_size = RSTRING_LEN(input_value);
28
28
 
29
- size_t const max_compressed_size = ZSTD_compressBound(input_size);
29
+ size_t max_compressed_size = ZSTD_compressBound(input_size);
30
30
  VALUE output = rb_str_new(NULL, max_compressed_size);
31
- const char* output_data = RSTRING_PTR(output);
31
+ char* output_data = RSTRING_PTR(output);
32
32
 
33
- size_t const ret = ZSTD_compress2(ctx,(void*)output_data, max_compressed_size, (void*)input_data, input_size);
33
+ size_t const ret = zstd_compress(ctx, output_data, max_compressed_size, input_data, input_size, false);
34
34
  if (ZSTD_isError(ret)) {
35
35
  rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
36
36
  }
@@ -96,7 +96,7 @@ static VALUE decompress_buffered(ZSTD_DCtx* dctx, const char* input_data, size_t
96
96
  rb_str_resize(output_string, output.size);
97
97
  output.dst = RSTRING_PTR(output_string);
98
98
 
99
- size_t ret = zstd_decompress(dctx, &output, &input, true);
99
+ size_t ret = zstd_stream_decompress(dctx, &output, &input, false);
100
100
  if (ZSTD_isError(ret)) {
101
101
  ZSTD_freeDCtx(dctx);
102
102
  rb_raise(rb_eRuntimeError, "%s: %s", "ZSTD_decompressStream failed", ZSTD_getErrorName(ret));
@@ -134,7 +134,7 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
134
134
  VALUE output = rb_str_new(NULL, uncompressed_size);
135
135
  char* output_data = RSTRING_PTR(output);
136
136
 
137
- 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);
138
138
  if (ZSTD_isError(decompress_size)) {
139
139
  rb_raise(rb_eRuntimeError, "%s: %s", "decompress error", ZSTD_getErrorName(decompress_size));
140
140
  }
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "1.5.6.4"
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.4
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-16 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