zstd-ruby 1.5.6.3 → 1.5.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 729474c9a3f3196fe69a06dfdd280c5879bc368b1884b8d508b75164aa7e1dcd
4
- data.tar.gz: 1cdf1b0554dd89aa1f7b6450be8eb183773a0f3b895024715ae7b3243cec598b
3
+ metadata.gz: fe4c394ffc4bcfd9e48c1baaa1dd91f8bf19f9bd65397218017c39145db14106
4
+ data.tar.gz: 5b87fa1c74eff20d0abe4b90260ac6fdb0db8fc65afd4a571bf0f7b10aa419b2
5
5
  SHA512:
6
- metadata.gz: d69bc35190b5dbc8ce36f9e5acf6ef26a2c85a899ddd409f8eee4a83b005166b20d22e2659cae1b101fb1b97f6a7bf12cf4066e3da94b2a1991d41bf255cd1ce
7
- data.tar.gz: 2ee85e56a8ae268da1e4b69bf35a016a5d9bc677f240435725e082b5c5279e60d7f8be32dbe57283e618b7cf59b3937b57aa859f6cbb0aafa64458a903747fa2
6
+ metadata.gz: ea1413beb577cc5c735f2a6514e99071bba67e40de2216d84b11afa77b653d36b026db573f06002797e4f258142b441331eaa4f9fb71e5426d1408ad4123bfeb
7
+ data.tar.gz: 58476bc0ce00c3d612e1aa460728a2255fbb9e289b132dc76106f539b535323d71ce5c0cda3adcded4cd8407066b332f79efff8fe41085e64e8bdee6ac14f563
@@ -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
@@ -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
  }
@@ -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
30
- 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 };
34
28
 
35
- size_t const ret = zstd_compress(ctx, &output, &input, ZSTD_e_end, true);
29
+ size_t const max_compressed_size = ZSTD_compressBound(input_size);
30
+ VALUE output = rb_str_new(NULL, max_compressed_size);
31
+ const char* output_data = RSTRING_PTR(output);
32
+
33
+ size_t const ret = ZSTD_compress2(ctx,(void*)output_data, max_compressed_size, (void*)input_data, input_size);
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)
@@ -141,7 +138,7 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
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.4"
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.4
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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler