zlib 3.2.0 → 3.2.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/zlib/zlib.c +192 -133
  3. metadata +4 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4f3ce4aeaaaf23f2bd617eeb0bd83378b727dabddb3a57bd35cda7edc64a36b
4
- data.tar.gz: cd9e3b9ccbd1207c468190771e38103a24dceaf6f3ae897073cfd1d9c7a7848e
3
+ metadata.gz: e92920fce616b99c265e4e452c1d47e8d1719294d3581e4a671c1400b4295eba
4
+ data.tar.gz: e2717c9804e532c8a955e2b9a971d8a43b0370057251730bcf8097f790c4e53a
5
5
  SHA512:
6
- metadata.gz: b8c1eb5a13d1d37b84c2fc5d30db95aea73587665d0a5a606cc0aca871da6dea229a2eb4acbaa79dbe5a51354b89fecd107f81fa4ffb7df9b95df914ca047595
7
- data.tar.gz: 12430704e1af5489bb474c8b6a5dc7a925ee1738c10d66886cc620ce9e21f58cdf860d4ab86e02ad88e28f892c309df292d0af2fe5bd98ce75d58054e6ff4230
6
+ metadata.gz: 5bcb8b1c903694ea3757a3da20284986e3109f3a9826c52deb1528475a328d667fddb541b323c0b509719d8c1874998c7036f8af57cc35a95b870db908c646e2
7
+ data.tar.gz: 3b78d38c768cb8b8c50f1cdc9dcf13255b1585d5475882060a011fe6f5829fee00f4ea956d4357d28b23034b05f02cd7cb6b4be34caa9e7b564507ebc4e9c161
data/ext/zlib/zlib.c CHANGED
@@ -25,7 +25,7 @@
25
25
  # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
26
26
  #endif
27
27
 
28
- #define RUBY_ZLIB_VERSION "3.2.0"
28
+ #define RUBY_ZLIB_VERSION "3.2.2"
29
29
 
30
30
  #ifndef RB_PASS_CALLED_KEYWORDS
31
31
  # define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass)
@@ -674,9 +674,7 @@ zstream_expand_buffer(struct zstream *z)
674
674
  rb_obj_reveal(z->buf, rb_cString);
675
675
  }
676
676
 
677
- rb_mutex_unlock(z->mutex);
678
- rb_protect(rb_yield, z->buf, &state);
679
- rb_mutex_lock(z->mutex);
677
+ rb_protect(rb_yield, z->buf, &state);
680
678
 
681
679
  if (ZSTREAM_REUSE_BUFFER_P(z)) {
682
680
  rb_str_modify(z->buf);
@@ -720,15 +718,14 @@ zstream_expand_buffer_into(struct zstream *z, unsigned long size)
720
718
  }
721
719
  }
722
720
 
723
- static void *
724
- zstream_expand_buffer_protect(void *ptr)
721
+ static int
722
+ zstream_expand_buffer_protect(struct zstream *z)
725
723
  {
726
- struct zstream *z = (struct zstream *)ptr;
727
724
  int state = 0;
728
725
 
729
726
  rb_protect((VALUE (*)(VALUE))zstream_expand_buffer, (VALUE)z, &state);
730
727
 
731
- return (void *)(VALUE)state;
728
+ return state;
732
729
  }
733
730
 
734
731
  static int
@@ -1023,57 +1020,14 @@ zstream_ensure_end(VALUE v)
1023
1020
  }
1024
1021
 
1025
1022
  static void *
1026
- zstream_run_func(void *ptr)
1023
+ zstream_run_once(void *_arguments)
1027
1024
  {
1028
- struct zstream_run_args *args = (struct zstream_run_args *)ptr;
1029
- int err, state, flush = args->flush;
1030
- struct zstream *z = args->z;
1031
- uInt n;
1025
+ struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
1026
+ struct zstream *z = arguments->z;
1032
1027
 
1033
- err = Z_OK;
1034
- while (!args->interrupt) {
1035
- n = z->stream.avail_out;
1036
- err = z->func->run(&z->stream, flush);
1037
- rb_str_set_len(z->buf, ZSTREAM_BUF_FILLED(z) + (n - z->stream.avail_out));
1028
+ uintptr_t error = z->func->run(&z->stream, arguments->flush);
1038
1029
 
1039
- if (err == Z_STREAM_END) {
1040
- z->flags &= ~ZSTREAM_FLAG_IN_STREAM;
1041
- z->flags |= ZSTREAM_FLAG_FINISHED;
1042
- break;
1043
- }
1044
-
1045
- if (err != Z_OK && err != Z_BUF_ERROR)
1046
- break;
1047
-
1048
- if (z->stream.avail_out > 0) {
1049
- z->flags |= ZSTREAM_FLAG_IN_STREAM;
1050
- break;
1051
- }
1052
-
1053
- if (z->stream.avail_in == 0 && z->func == &inflate_funcs) {
1054
- /* break here because inflate() return Z_BUF_ERROR when avail_in == 0. */
1055
- /* but deflate() could be called with avail_in == 0 (there's hidden buffer
1056
- in zstream->state) */
1057
- z->flags |= ZSTREAM_FLAG_IN_STREAM;
1058
- break;
1059
- }
1060
-
1061
- if (args->stream_output) {
1062
- state = (int)(VALUE)rb_thread_call_with_gvl(zstream_expand_buffer_protect,
1063
- (void *)z);
1064
- }
1065
- else {
1066
- state = zstream_expand_buffer_non_stream(z);
1067
- }
1068
-
1069
- if (state) {
1070
- err = Z_OK; /* buffer expanded but stream processing was stopped */
1071
- args->jump_state = state;
1072
- break;
1073
- }
1074
- }
1075
-
1076
- return (void *)(VALUE)err;
1030
+ return (void*)error;
1077
1031
  }
1078
1032
 
1079
1033
  /*
@@ -1088,6 +1042,91 @@ zstream_unblock_func(void *ptr)
1088
1042
  args->interrupt = 1;
1089
1043
  }
1090
1044
 
1045
+ #ifndef RB_NOGVL_OFFLOAD_SAFE
1046
+ // Default to no-op if it's not defined:
1047
+ #define RB_NOGVL_OFFLOAD_SAFE 0
1048
+ #endif
1049
+
1050
+ static VALUE
1051
+ zstream_run_once_begin(VALUE _arguments)
1052
+ {
1053
+ struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
1054
+ struct zstream *z = arguments->z;
1055
+
1056
+ rb_str_locktmp(z->buf);
1057
+
1058
+ #ifndef RB_NOGVL_UBF_ASYNC_SAFE
1059
+ return (VALUE)rb_thread_call_without_gvl(zstream_run_once, (void *)arguments, zstream_unblock_func, (void *)arguments);
1060
+ #else
1061
+ return (VALUE)rb_nogvl(zstream_run_once, (void *)arguments, zstream_unblock_func, (void *)arguments, RB_NOGVL_UBF_ASYNC_SAFE | RB_NOGVL_OFFLOAD_SAFE);
1062
+ #endif
1063
+ }
1064
+
1065
+ static VALUE
1066
+ zstream_run_once_ensure(VALUE _arguments)
1067
+ {
1068
+ struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
1069
+ struct zstream *z = arguments->z;
1070
+
1071
+ rb_str_unlocktmp(z->buf);
1072
+
1073
+ return Qnil;
1074
+ }
1075
+
1076
+ static int
1077
+ zstream_run_func(struct zstream_run_args *args)
1078
+ {
1079
+ struct zstream *z = args->z;
1080
+ int state;
1081
+ uInt n;
1082
+
1083
+ int err = Z_OK;
1084
+ while (!args->interrupt) {
1085
+ n = z->stream.avail_out;
1086
+
1087
+ err = (int)(VALUE)rb_ensure(zstream_run_once_begin, (VALUE)args, zstream_run_once_ensure, (VALUE)args);
1088
+
1089
+ rb_str_set_len(z->buf, ZSTREAM_BUF_FILLED(z) + (n - z->stream.avail_out));
1090
+
1091
+ if (err == Z_STREAM_END) {
1092
+ z->flags &= ~ZSTREAM_FLAG_IN_STREAM;
1093
+ z->flags |= ZSTREAM_FLAG_FINISHED;
1094
+ break;
1095
+ }
1096
+
1097
+ if (err != Z_OK && err != Z_BUF_ERROR)
1098
+ break;
1099
+
1100
+ if (z->stream.avail_out > 0) {
1101
+ z->flags |= ZSTREAM_FLAG_IN_STREAM;
1102
+ break;
1103
+ }
1104
+
1105
+ if (z->stream.avail_in == 0 && z->func == &inflate_funcs) {
1106
+ /* break here because inflate() return Z_BUF_ERROR when avail_in == 0. */
1107
+ /* but deflate() could be called with avail_in == 0 (there's hidden buffer
1108
+ in zstream->state) */
1109
+ z->flags |= ZSTREAM_FLAG_IN_STREAM;
1110
+ break;
1111
+ }
1112
+
1113
+ if (args->stream_output) {
1114
+ state = zstream_expand_buffer_protect(z);
1115
+ }
1116
+ else {
1117
+ state = zstream_expand_buffer_non_stream(z);
1118
+ }
1119
+
1120
+ if (state) {
1121
+ err = Z_OK; /* buffer expanded but stream processing was stopped */
1122
+ args->jump_state = state;
1123
+ break;
1124
+ }
1125
+ }
1126
+
1127
+ return err;
1128
+ }
1129
+
1091
1130
  static VALUE
1092
1131
  zstream_run_try(VALUE value_arg)
1093
1132
  {
@@ -1126,14 +1165,7 @@ zstream_run_try(VALUE value_arg)
1126
1165
  }
1127
1166
 
1128
1167
  loop:
1129
- #ifndef RB_NOGVL_UBF_ASYNC_SAFE
1130
- err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_func, (void *)args,
1131
- zstream_unblock_func, (void *)args);
1132
- #else
1133
- err = (int)(VALUE)rb_nogvl(zstream_run_func, (void *)args,
1134
- zstream_unblock_func, (void *)args,
1135
- RB_NOGVL_UBF_ASYNC_SAFE);
1136
- #endif
1168
+ err = zstream_run_func(args);
1137
1169
 
1138
1170
  /* retry if no exception is thrown */
1139
1171
  if (err == Z_OK && args->interrupt) {
@@ -1184,7 +1216,6 @@ zstream_run_ensure(VALUE value_arg)
1184
1216
 
1185
1217
  /* Remove ZSTREAM_IN_PROGRESS flag to signal that this zstream is not in use. */
1186
1218
  z->flags &= ~ZSTREAM_IN_PROGRESS;
1187
- rb_mutex_unlock(z->mutex);
1188
1219
 
1189
1220
  return Qnil;
1190
1221
  }
@@ -1201,7 +1232,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1201
1232
  .jump_state = 0,
1202
1233
  .stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p(),
1203
1234
  };
1204
- rb_mutex_lock(z->mutex);
1235
+
1205
1236
  rb_ensure(zstream_run_try, (VALUE)&args, zstream_run_ensure, (VALUE)&args);
1206
1237
  if (args.jump_state)
1207
1238
  rb_jump_tag(args.jump_state);
@@ -1770,6 +1801,22 @@ do_deflate(struct zstream *z, VALUE src, int flush)
1770
1801
  }
1771
1802
  }
1772
1803
 
1804
+ struct rb_zlib_deflate_arguments {
1805
+ struct zstream *z;
1806
+ VALUE src;
1807
+ int flush;
1808
+ };
1809
+
1810
+ static VALUE
1811
+ rb_deflate_deflate_body(VALUE args)
1812
+ {
1813
+ struct rb_zlib_deflate_arguments *arguments = (struct rb_zlib_deflate_arguments *)args;
1814
+
1815
+ do_deflate(arguments->z, arguments->src, arguments->flush);
1816
+
1817
+ return zstream_detach_buffer(arguments->z);
1818
+ }
1819
+
1773
1820
  /*
1774
1821
  * Document-method: Zlib::Deflate#deflate
1775
1822
  *
@@ -1801,11 +1848,10 @@ rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
1801
1848
  {
1802
1849
  struct zstream *z = get_zstream(obj);
1803
1850
  VALUE src, flush;
1804
-
1805
1851
  rb_scan_args(argc, argv, "11", &src, &flush);
1806
- do_deflate(z, src, ARG_FLUSH(flush));
1852
+ struct rb_zlib_deflate_arguments arguments = {z, src, ARG_FLUSH(flush)};
1807
1853
 
1808
- return zstream_detach_buffer(z);
1854
+ return rb_mutex_synchronize(z->mutex, rb_deflate_deflate_body, (VALUE)&arguments);
1809
1855
  }
1810
1856
 
1811
1857
  /*
@@ -2101,56 +2147,19 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
2101
2147
  return obj;
2102
2148
  }
2103
2149
 
2104
- /*
2105
- * Document-method: Zlib::Inflate#inflate
2106
- *
2107
- * call-seq:
2108
- * inflate(deflate_string, buffer: nil) -> String
2109
- * inflate(deflate_string, buffer: nil) { |chunk| ... } -> nil
2110
- *
2111
- * Inputs +deflate_string+ into the inflate stream and returns the output from
2112
- * the stream. Calling this method, both the input and the output buffer of
2113
- * the stream are flushed. If string is +nil+, this method finishes the
2114
- * stream, just like Zlib::ZStream#finish.
2115
- *
2116
- * If a block is given consecutive inflated chunks from the +deflate_string+
2117
- * are yielded to the block and +nil+ is returned.
2118
- *
2119
- * If a :buffer keyword argument is given and not nil:
2120
- *
2121
- * * The :buffer keyword should be a String, and will used as the output buffer.
2122
- * Using this option can reuse the memory required during inflation.
2123
- * * When not passing a block, the return value will be the same object as the
2124
- * :buffer keyword argument.
2125
- * * When passing a block, the yielded chunks will be the same value as the
2126
- * :buffer keyword argument.
2127
- *
2128
- * Raises a Zlib::NeedDict exception if a preset dictionary is needed to
2129
- * decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
2130
- * call this method again with an empty string to flush the stream:
2131
- *
2132
- * inflater = Zlib::Inflate.new
2133
- *
2134
- * begin
2135
- * out = inflater.inflate compressed
2136
- * rescue Zlib::NeedDict
2137
- * # ensure the dictionary matches the stream's required dictionary
2138
- * raise unless inflater.adler == Zlib.adler32(dictionary)
2139
- *
2140
- * inflater.set_dictionary dictionary
2141
- * inflater.inflate ''
2142
- * end
2143
- *
2144
- * # ...
2145
- *
2146
- * inflater.close
2147
- *
2148
- * See also Zlib::Inflate.new
2149
- */
2150
+ struct rb_zlib_inflate_arguments {
2151
+ struct zstream *z;
2152
+ int argc;
2153
+ VALUE *argv;
2154
+ };
2155
+
2150
2156
  static VALUE
2151
- rb_inflate_inflate(int argc, VALUE* argv, VALUE obj)
2157
+ rb_inflate_inflate_body(VALUE _arguments)
2152
2158
  {
2153
- struct zstream *z = get_zstream(obj);
2159
+ struct rb_zlib_inflate_arguments *arguments = (struct rb_zlib_inflate_arguments*)_arguments;
2160
+ struct zstream *z = arguments->z;
2161
+ int argc = arguments->argc;
2162
+ VALUE *argv = arguments->argv;
2154
2163
  VALUE dst, src, opts, buffer = Qnil;
2155
2164
 
2156
2165
  if (OPTHASH_GIVEN_P(opts)) {
@@ -2205,6 +2214,60 @@ rb_inflate_inflate(int argc, VALUE* argv, VALUE obj)
2205
2214
  return dst;
2206
2215
  }
2207
2216
 
2217
+ /*
2218
+ * Document-method: Zlib::Inflate#inflate
2219
+ *
2220
+ * call-seq:
2221
+ * inflate(deflate_string, buffer: nil) -> String
2222
+ * inflate(deflate_string, buffer: nil) { |chunk| ... } -> nil
2223
+ *
2224
+ * Inputs +deflate_string+ into the inflate stream and returns the output from
2225
+ * the stream. Calling this method, both the input and the output buffer of
2226
+ * the stream are flushed. If string is +nil+, this method finishes the
2227
+ * stream, just like Zlib::ZStream#finish.
2228
+ *
2229
+ * If a block is given consecutive inflated chunks from the +deflate_string+
2230
+ * are yielded to the block and +nil+ is returned.
2231
+ *
2232
+ * If a :buffer keyword argument is given and not nil:
2233
+ *
2234
+ * * The :buffer keyword should be a String, and will used as the output buffer.
2235
+ * Using this option can reuse the memory required during inflation.
2236
+ * * When not passing a block, the return value will be the same object as the
2237
+ * :buffer keyword argument.
2238
+ * * When passing a block, the yielded chunks will be the same value as the
2239
+ * :buffer keyword argument.
2240
+ *
2241
+ * Raises a Zlib::NeedDict exception if a preset dictionary is needed to
2242
+ * decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
2243
+ * call this method again with an empty string to flush the stream:
2244
+ *
2245
+ * inflater = Zlib::Inflate.new
2246
+ *
2247
+ * begin
2248
+ * out = inflater.inflate compressed
2249
+ * rescue Zlib::NeedDict
2250
+ * # ensure the dictionary matches the stream's required dictionary
2251
+ * raise unless inflater.adler == Zlib.adler32(dictionary)
2252
+ *
2253
+ * inflater.set_dictionary dictionary
2254
+ * inflater.inflate ''
2255
+ * end
2256
+ *
2257
+ * # ...
2258
+ *
2259
+ * inflater.close
2260
+ *
2261
+ * See also Zlib::Inflate.new
2262
+ */
2263
+ static VALUE
2264
+ rb_inflate_inflate(int argc, VALUE* argv, VALUE obj)
2265
+ {
2266
+ struct zstream *z = get_zstream(obj);
2267
+ struct rb_zlib_inflate_arguments arguments = {z, argc, argv};
2268
+ return rb_mutex_synchronize(z->mutex, rb_inflate_inflate_body, (VALUE)&arguments);
2269
+ }
2270
+
2208
2271
  /*
2209
2272
  * call-seq: << string
2210
2273
  *
@@ -2381,17 +2444,16 @@ struct gzfile {
2381
2444
 
2382
2445
  #define GZFILE_READ_SIZE 2048
2383
2446
 
2447
+ enum { read_raw_arg_len, read_raw_arg_buf, read_raw_arg__count};
2384
2448
  struct read_raw_arg {
2385
2449
  VALUE io;
2386
- union {
2387
- const VALUE argv[2]; /* for rb_funcallv */
2388
- struct {
2389
- VALUE len;
2390
- VALUE buf;
2391
- } in;
2392
- } as;
2450
+ const VALUE argv[read_raw_arg__count]; /* for rb_funcallv */
2393
2451
  };
2394
2452
 
2453
+ #define read_raw_arg_argc(ra) \
2454
+ ((int)read_raw_arg__count - NIL_P((ra)->argv[read_raw_arg__count - 1]))
2455
+ #define read_raw_arg_init(io, len, buf) { io, { len, buf } }
2456
+
2395
2457
  static void
2396
2458
  gzfile_mark(void *p)
2397
2459
  {
@@ -2517,9 +2579,9 @@ gzfile_read_raw_partial(VALUE arg)
2517
2579
  {
2518
2580
  struct read_raw_arg *ra = (struct read_raw_arg *)arg;
2519
2581
  VALUE str;
2520
- int argc = NIL_P(ra->as.argv[1]) ? 1 : 2;
2582
+ int argc = read_raw_arg_argc(ra);
2521
2583
 
2522
- str = rb_funcallv(ra->io, id_readpartial, argc, ra->as.argv);
2584
+ str = rb_funcallv(ra->io, id_readpartial, argc, ra->argv);
2523
2585
  Check_Type(str, T_STRING);
2524
2586
  return str;
2525
2587
  }
@@ -2530,8 +2592,8 @@ gzfile_read_raw_rescue(VALUE arg, VALUE _)
2530
2592
  struct read_raw_arg *ra = (struct read_raw_arg *)arg;
2531
2593
  VALUE str = Qnil;
2532
2594
  if (rb_obj_is_kind_of(rb_errinfo(), rb_eNoMethodError)) {
2533
- int argc = NIL_P(ra->as.argv[1]) ? 1 : 2;
2534
- str = rb_funcallv(ra->io, id_read, argc, ra->as.argv);
2595
+ int argc = read_raw_arg_argc(ra);
2596
+ str = rb_funcallv(ra->io, id_read, argc, ra->argv);
2535
2597
  if (!NIL_P(str)) {
2536
2598
  Check_Type(str, T_STRING);
2537
2599
  }
@@ -2542,11 +2604,8 @@ gzfile_read_raw_rescue(VALUE arg, VALUE _)
2542
2604
  static VALUE
2543
2605
  gzfile_read_raw(struct gzfile *gz, VALUE outbuf)
2544
2606
  {
2545
- struct read_raw_arg ra;
2546
-
2547
- ra.io = gz->io;
2548
- ra.as.in.len = INT2FIX(GZFILE_READ_SIZE);
2549
- ra.as.in.buf = outbuf;
2607
+ struct read_raw_arg ra =
2608
+ read_raw_arg_init(gz->io, INT2FIX(GZFILE_READ_SIZE), outbuf);
2550
2609
 
2551
2610
  return rb_rescue2(gzfile_read_raw_partial, (VALUE)&ra,
2552
2611
  gzfile_read_raw_rescue, (VALUE)&ra,
metadata CHANGED
@@ -1,20 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  - UENO Katsuhiro
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2024-11-12 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Ruby interface for the zlib compression/decompression library
15
14
  email:
16
15
  - matz@ruby-lang.org
17
- -
16
+ -
18
17
  executables: []
19
18
  extensions:
20
19
  - ext/zlib/extconf.rb
@@ -31,7 +30,6 @@ licenses:
31
30
  - Ruby
32
31
  - BSD-2-Clause
33
32
  metadata: {}
34
- post_install_message:
35
33
  rdoc_options: []
36
34
  require_paths:
37
35
  - lib
@@ -46,8 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
44
  - !ruby/object:Gem::Version
47
45
  version: '0'
48
46
  requirements: []
49
- rubygems_version: 3.5.11
50
- signing_key:
47
+ rubygems_version: 3.6.9
51
48
  specification_version: 4
52
49
  summary: Ruby interface for the zlib compression/decompression library
53
50
  test_files: []