zstd-ruby 2.0.3 → 2.0.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: 65a00efff2063419d15ec39be7fb8f30bc55adae0300544aa05acef44e3c18b7
4
- data.tar.gz: a19e44f78c56c8b6711e6f857bfb9b29a8e05e47d0096b0471799e663e67a90f
3
+ metadata.gz: 3c3c7ba2ca27786f539bd8083ec97ae1822a529d075147ef1f12f5b565201a3a
4
+ data.tar.gz: 961f3e60ceb142982e9dadec995b4246e77535abb538250f7c488f1ef2e1dab4
5
5
  SHA512:
6
- metadata.gz: e9dd0a8b325b42e9ea0438f65a452c5c19f928e5d7848be16ea2cc3d81841d7bf820aa776ff10e717c669c0171ba6e5fc2951fff3771315996c8e483a9af9b85
7
- data.tar.gz: 843ef5641e08729a1519c06a9408cc8b363cbd6c4cfc5d4df57da56ce0d7a7c33c22fa62f6a0ceca0922ebacf83cfb607541dff6788888e93a1cbfd6b13d03be
6
+ metadata.gz: a3a8b7e573f0c356d7cfaa72416f7f306ccf4d989f17c3265d648956a869f3fa6e166d57a8f0764da070e46014a07fef46b5a05ca814371df5d1d6f470fc595e
7
+ data.tar.gz: 3014a12287071ba7c4d868313ff63e70f99a026f7b0cd28a6c4d5e70a0c0a13497adf0d984a736ca14d5388739c14a10f1342ff01b49d44ba80f59e49f38197f
data/README.md CHANGED
@@ -7,8 +7,6 @@ Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
7
7
 
8
8
  See https://github.com/facebook/zstd
9
9
 
10
- Fork from https://github.com/jarredholman/ruby-zstd.
11
-
12
10
  ## Zstd version
13
11
  [v1.5.7](https://github.com/facebook/zstd/tree/v1.5.7)
14
12
 
@@ -10,11 +10,17 @@
10
10
 
11
11
  extern VALUE rb_cCDict, rb_cDDict;
12
12
 
13
- static int convert_compression_level(VALUE compression_level_value)
13
+ static int convert_compression_level(ZSTD_CCtx* ctx, VALUE compression_level_value)
14
14
  {
15
15
  if (NIL_P(compression_level_value)) {
16
16
  return ZSTD_CLEVEL_DEFAULT;
17
17
  }
18
+ if (!RB_INTEGER_TYPE_P(compression_level_value)) {
19
+ if (ctx) {
20
+ ZSTD_freeCCtx(ctx);
21
+ }
22
+ rb_raise(rb_eTypeError, "compression level must be an Integer");
23
+ }
18
24
  return NUM2INT(compression_level_value);
19
25
  }
20
26
 
@@ -28,7 +34,7 @@ static void set_compress_params(ZSTD_CCtx* const ctx, VALUE kwargs)
28
34
 
29
35
  int compression_level = ZSTD_CLEVEL_DEFAULT;
30
36
  if (kwargs_values[0] != Qundef && kwargs_values[0] != Qnil) {
31
- compression_level = convert_compression_level(kwargs_values[0]);
37
+ compression_level = convert_compression_level(ctx, kwargs_values[0]);
32
38
  }
33
39
  ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionLevel, compression_level);
34
40
 
@@ -14,6 +14,8 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
14
14
  VALUE kwargs;
15
15
  rb_scan_args(argc, argv, "10:", &input_value, &kwargs);
16
16
 
17
+ StringValue(input_value);
18
+
17
19
  ZSTD_CCtx* const ctx = ZSTD_createCCtx();
18
20
  if (ctx == NULL) {
19
21
  rb_raise(rb_eRuntimeError, "%s", "ZSTD_createCCtx error");
@@ -21,7 +23,6 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
21
23
 
22
24
  set_compress_params(ctx, kwargs);
23
25
 
24
- StringValue(input_value);
25
26
  char* input_data = RSTRING_PTR(input_value);
26
27
  size_t input_size = RSTRING_LEN(input_value);
27
28
 
@@ -30,12 +31,12 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
30
31
  char* output_data = RSTRING_PTR(output);
31
32
 
32
33
  size_t const ret = zstd_compress(ctx, output_data, max_compressed_size, input_data, input_size, false);
34
+ ZSTD_freeCCtx(ctx);
33
35
  if (ZSTD_isError(ret)) {
34
36
  rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
35
37
  }
36
38
  rb_str_resize(output, ret);
37
39
 
38
- ZSTD_freeCCtx(ctx);
39
40
  return output;
40
41
  }
41
42
 
@@ -77,9 +78,7 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
77
78
  StringValue(input_value);
78
79
 
79
80
  size_t in_size = RSTRING_LEN(input_value);
80
- const unsigned char *in_r = (const unsigned char *)RSTRING_PTR(input_value);
81
- unsigned char *in = ALLOC_N(unsigned char, in_size);
82
- memcpy(in, in_r, in_size);
81
+ const unsigned char *in = (const unsigned char *)RSTRING_PTR(input_value);
83
82
 
84
83
  size_t off = 0;
85
84
  const uint32_t ZSTD_MAGIC = 0xFD2FB528U;
@@ -106,14 +105,12 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
106
105
  if (magic == ZSTD_MAGIC) {
107
106
  ZSTD_DCtx *dctx = ZSTD_createDCtx();
108
107
  if (!dctx) {
109
- xfree(in);
110
108
  rb_raise(rb_eRuntimeError, "ZSTD_createDCtx failed");
111
109
  }
112
110
 
113
111
  VALUE out = decode_one_frame(dctx, in + off, in_size - off, kwargs);
114
112
 
115
113
  ZSTD_freeDCtx(dctx);
116
- xfree(in);
117
114
  RB_GC_GUARD(input_value);
118
115
  return out;
119
116
  }
@@ -121,7 +118,6 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
121
118
  off += 1;
122
119
  }
123
120
 
124
- xfree(in);
125
121
  RB_GC_GUARD(input_value);
126
122
  rb_raise(rb_eRuntimeError, "not a zstd frame (magic not found)");
127
123
  }
@@ -169,7 +165,7 @@ static VALUE rb_cdict_initialize(int argc, VALUE *argv, VALUE self)
169
165
  VALUE dict;
170
166
  VALUE compression_level_value;
171
167
  rb_scan_args(argc, argv, "11", &dict, &compression_level_value);
172
- int compression_level = convert_compression_level(compression_level_value);
168
+ int compression_level = convert_compression_level(NULL, compression_level_value);
173
169
 
174
170
  StringValue(dict);
175
171
  char* dict_buffer = RSTRING_PTR(dict);
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zstd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - SpringMT
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-02 00:00:00.000000000 Z
10
+ date: 2026-01-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler