zlib 2.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/zlib/extconf.rb +2 -0
  3. data/ext/zlib/zlib.c +100 -53
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38b96853c00eb5d1b6b2ad47512fc97d4f4c589e77106dd6cc7f501a3de7ce0c
4
- data.tar.gz: 8fc6e8d0207cc631d85a2cb248502263faf6b2184fab4de0c762d360c95b482f
3
+ metadata.gz: 41b7725d22718acab4587061657664b5bc968f2bf1c49ce138da93d74bcab5b6
4
+ data.tar.gz: afcafcf39db41825d341a3b8ae6ae8430c111eff53ba0498054b0c6eb1be3a21
5
5
  SHA512:
6
- metadata.gz: 3b9a862a80f4b7146e5d918b917990349ed3be78c8636346636f787b6955c764406717330d1206ec8ea9347149ebe544d03e571c8e9754840f1fd6ac38b794df
7
- data.tar.gz: ca43a10903aa4c981f8de059fd12c695ec4a31b2e8c5ccf34161f828f059660108d7406851c416f90eca9d54f07332cab606c305f566b5b0dac805a94b57e573
6
+ metadata.gz: 4b7db251e4e66d850419c1f943ca33e4de1239a69230d3b8674ae4c3b4f32ecc72525f928407719601be73dfcbd9ee2162dcfe89c73883b979e7b15a6c9e30bf
7
+ data.tar.gz: ab12bdb64f407df968bbf8da42a68c361aa00a151d261ad3557a0a4ca38807184e783bf0c10f79fb0ecc4a1cce7d896e63244f21949824db4d2d19ab9e231196
data/ext/zlib/extconf.rb CHANGED
@@ -121,10 +121,12 @@ if have_zlib
121
121
  $defs << "-DHAVE_CRC32_COMBINE"
122
122
  $defs << "-DHAVE_ADLER32_COMBINE"
123
123
  $defs << "-DHAVE_TYPE_Z_CRC_T"
124
+ $defs << "-DHAVE_TYPE_Z_SIZE_T"
124
125
  else
125
126
  have_func('crc32_combine', 'zlib.h')
126
127
  have_func('adler32_combine', 'zlib.h')
127
128
  have_type('z_crc_t', 'zlib.h')
129
+ have_type('z_size_t', 'zlib.h')
128
130
  end
129
131
 
130
132
  create_makefile('zlib') {|conf|
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 "2.1.1"
28
+ #define RUBY_ZLIB_VERSION "3.0.0"
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)
@@ -44,6 +44,14 @@
44
44
  #endif
45
45
  #endif
46
46
 
47
+ #if defined(HAVE_TYPE_Z_SIZE_T)
48
+ typedef uLong (*checksum_func)(uLong, const Bytef*, z_size_t);
49
+ # define crc32 crc32_z
50
+ # define adler32 adler32_z
51
+ #else
52
+ typedef uLong (*checksum_func)(uLong, const Bytef*, uInt);
53
+ #endif
54
+
47
55
  #if SIZEOF_LONG > SIZEOF_INT
48
56
  static inline uInt
49
57
  max_uint(long n)
@@ -65,7 +73,7 @@ static ID id_dictionaries, id_read, id_buffer;
65
73
 
66
74
  static NORETURN(void raise_zlib_error(int, const char*));
67
75
  static VALUE rb_zlib_version(VALUE);
68
- static VALUE do_checksum(int, VALUE*, uLong (*)(uLong, const Bytef*, uInt));
76
+ static VALUE do_checksum(int, VALUE*, checksum_func);
69
77
  static VALUE rb_zlib_adler32(int, VALUE*, VALUE);
70
78
  static VALUE rb_zlib_crc32(int, VALUE*, VALUE);
71
79
  static VALUE rb_zlib_crc_table(VALUE);
@@ -288,6 +296,7 @@ static VALUE rb_gzreader_readlines(int, VALUE*, VALUE);
288
296
  * - Zlib::MemError
289
297
  * - Zlib::BufError
290
298
  * - Zlib::VersionError
299
+ * - Zlib::InProgressError
291
300
  *
292
301
  * (if you have GZIP_SUPPORT)
293
302
  * - Zlib::GzipReader
@@ -304,7 +313,7 @@ void Init_zlib(void);
304
313
  /*--------- Exceptions --------*/
305
314
 
306
315
  static VALUE cZError, cStreamEnd, cNeedDict;
307
- static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError;
316
+ static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError, cInProgressError;
308
317
 
309
318
  static void
310
319
  raise_zlib_error(int err, const char *msg)
@@ -373,26 +382,32 @@ rb_zlib_version(VALUE klass)
373
382
  return rb_str_new2(zlibVersion());
374
383
  }
375
384
 
376
- #if SIZEOF_LONG > SIZEOF_INT
385
+ #if SIZEOF_LONG * CHAR_BIT > 32
386
+ # define mask32(x) ((x) & 0xffffffff)
387
+ #else
388
+ # define mask32(x) (x)
389
+ #endif
390
+
391
+ #if SIZEOF_LONG > SIZEOF_INT && !defined(HAVE_TYPE_Z_SIZE_T)
377
392
  static uLong
378
393
  checksum_long(uLong (*func)(uLong, const Bytef*, uInt), uLong sum, const Bytef *ptr, long len)
379
394
  {
380
395
  if (len > UINT_MAX) {
381
396
  do {
382
- sum = func(sum, ptr, UINT_MAX);
397
+ sum = func(mask32(sum), ptr, UINT_MAX);
383
398
  ptr += UINT_MAX;
384
399
  len -= UINT_MAX;
385
400
  } while (len >= UINT_MAX);
386
401
  }
387
- if (len > 0) sum = func(sum, ptr, (uInt)len);
402
+ if (len > 0) sum = func(mask32(sum), ptr, (uInt)len);
388
403
  return sum;
389
404
  }
390
405
  #else
391
- #define checksum_long(func, sum, ptr, len) (func)((sum), (ptr), (len))
406
+ #define checksum_long(func, sum, ptr, len) (func)(mask32(sum), (ptr), (len))
392
407
  #endif
393
408
 
394
409
  static VALUE
395
- do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
410
+ do_checksum(int argc, VALUE *argv, checksum_func func)
396
411
  {
397
412
  VALUE str, vsum;
398
413
  unsigned long sum;
@@ -410,7 +425,7 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
410
425
  }
411
426
 
412
427
  if (NIL_P(str)) {
413
- sum = func(sum, Z_NULL, 0);
428
+ sum = func(mask32(sum), Z_NULL, 0);
414
429
  }
415
430
  else if (rb_obj_is_kind_of(str, rb_cIO)) {
416
431
  VALUE buf;
@@ -460,7 +475,7 @@ rb_zlib_adler32(int argc, VALUE *argv, VALUE klass)
460
475
  *
461
476
  * call-seq: Zlib.adler32_combine(adler1, adler2, len2)
462
477
  *
463
- * Combine two Adler-32 check values in to one. +alder1+ is the first Adler-32
478
+ * Combine two Adler-32 check values in to one. +adler1+ is the first Adler-32
464
479
  * value, +adler2+ is the second Adler-32 value. +len2+ is the length of the
465
480
  * string used to generate +adler2+.
466
481
  *
@@ -557,14 +572,15 @@ struct zstream {
557
572
  } *func;
558
573
  };
559
574
 
560
- #define ZSTREAM_FLAG_READY 0x1
561
- #define ZSTREAM_FLAG_IN_STREAM 0x2
562
- #define ZSTREAM_FLAG_FINISHED 0x4
563
- #define ZSTREAM_FLAG_CLOSING 0x8
564
- #define ZSTREAM_FLAG_GZFILE 0x10 /* disallows yield from expand_buffer for
575
+ #define ZSTREAM_FLAG_READY (1 << 0)
576
+ #define ZSTREAM_FLAG_IN_STREAM (1 << 1)
577
+ #define ZSTREAM_FLAG_FINISHED (1 << 2)
578
+ #define ZSTREAM_FLAG_CLOSING (1 << 3)
579
+ #define ZSTREAM_FLAG_GZFILE (1 << 4) /* disallows yield from expand_buffer for
565
580
  gzip*/
566
- #define ZSTREAM_REUSE_BUFFER 0x20
567
- #define ZSTREAM_FLAG_UNUSED 0x40
581
+ #define ZSTREAM_REUSE_BUFFER (1 << 5)
582
+ #define ZSTREAM_IN_PROGRESS (1 << 6)
583
+ #define ZSTREAM_FLAG_UNUSED (1 << 7)
568
584
 
569
585
  #define ZSTREAM_READY(z) ((z)->flags |= ZSTREAM_FLAG_READY)
570
586
  #define ZSTREAM_IS_READY(z) ((z)->flags & ZSTREAM_FLAG_READY)
@@ -593,7 +609,9 @@ static const struct zstream_funcs inflate_funcs = {
593
609
  };
594
610
 
595
611
  struct zstream_run_args {
596
- struct zstream * z;
612
+ struct zstream *const z;
613
+ Bytef *src;
614
+ long len;
597
615
  int flush; /* stream flush value for inflate() or deflate() */
598
616
  int interrupt; /* stop processing the stream and return to ruby */
599
617
  int jump_state; /* for buffer expansion block break or exception */
@@ -894,7 +912,6 @@ zstream_discard_input(struct zstream *z, long len)
894
912
  }
895
913
  rb_str_resize(z->input, newlen);
896
914
  if (newlen == 0) {
897
- rb_gc_force_recycle(z->input);
898
915
  z->input = Qnil;
899
916
  }
900
917
  else {
@@ -1059,19 +1076,18 @@ zstream_unblock_func(void *ptr)
1059
1076
  args->interrupt = 1;
1060
1077
  }
1061
1078
 
1062
- static void
1063
- zstream_run0(struct zstream *z, Bytef *src, long len, int flush)
1079
+ static VALUE
1080
+ zstream_run_try(VALUE value_arg)
1064
1081
  {
1065
- struct zstream_run_args args;
1082
+ struct zstream_run_args *args = (struct zstream_run_args *)value_arg;
1083
+ struct zstream *z = args->z;
1084
+ Bytef *src = args->src;
1085
+ long len = args->len;
1086
+ int flush = args->flush;
1087
+
1066
1088
  int err;
1067
1089
  VALUE old_input = Qnil;
1068
1090
 
1069
- args.z = z;
1070
- args.flush = flush;
1071
- args.interrupt = 0;
1072
- args.jump_state = 0;
1073
- args.stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p();
1074
-
1075
1091
  if (NIL_P(z->input) && len == 0) {
1076
1092
  z->stream.next_in = (Bytef*)"";
1077
1093
  z->stream.avail_in = 0;
@@ -1093,17 +1109,17 @@ zstream_run0(struct zstream *z, Bytef *src, long len, int flush)
1093
1109
 
1094
1110
  loop:
1095
1111
  #ifndef RB_NOGVL_UBF_ASYNC_SAFE
1096
- err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_func, (void *)&args,
1097
- zstream_unblock_func, (void *)&args);
1112
+ err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_func, (void *)args,
1113
+ zstream_unblock_func, (void *)args);
1098
1114
  #else
1099
- err = (int)(VALUE)rb_nogvl(zstream_run_func, (void *)&args,
1100
- zstream_unblock_func, (void *)&args,
1115
+ err = (int)(VALUE)rb_nogvl(zstream_run_func, (void *)args,
1116
+ zstream_unblock_func, (void *)args,
1101
1117
  RB_NOGVL_UBF_ASYNC_SAFE);
1102
1118
  #endif
1103
1119
 
1104
1120
  /* retry if no exception is thrown */
1105
- if (err == Z_OK && args.interrupt) {
1106
- args.interrupt = 0;
1121
+ if (err == Z_OK && args->interrupt) {
1122
+ args->interrupt = 0;
1107
1123
  goto loop;
1108
1124
  }
1109
1125
 
@@ -1137,37 +1153,54 @@ loop:
1137
1153
  }
1138
1154
  if (!NIL_P(old_input)) {
1139
1155
  rb_str_resize(old_input, 0);
1140
- rb_gc_force_recycle(old_input);
1141
1156
  }
1142
1157
 
1143
- if (args.jump_state)
1144
- rb_jump_tag(args.jump_state);
1158
+ if (args->jump_state)
1159
+ rb_jump_tag(args->jump_state);
1160
+
1161
+ return Qnil;
1145
1162
  }
1146
1163
 
1147
- struct zstream_run_synchronized_args {
1148
- struct zstream *z;
1149
- Bytef *src;
1150
- long len;
1151
- int flush;
1152
- };
1164
+ static VALUE
1165
+ zstream_run_ensure(VALUE value_arg)
1166
+ {
1167
+ struct zstream_run_args *args = (struct zstream_run_args *)value_arg;
1168
+
1169
+ /* Remove ZSTREAM_IN_PROGRESS flag to signal that this zstream is not in use. */
1170
+ args->z->flags &= ~ZSTREAM_IN_PROGRESS;
1171
+
1172
+ return Qnil;
1173
+ }
1153
1174
 
1154
1175
  static VALUE
1155
1176
  zstream_run_synchronized(VALUE value_arg)
1156
1177
  {
1157
- struct zstream_run_synchronized_args *run_args = (struct zstream_run_synchronized_args *)value_arg;
1158
- zstream_run0(run_args->z, run_args->src, run_args->len, run_args->flush);
1178
+ struct zstream_run_args *args = (struct zstream_run_args *)value_arg;
1179
+
1180
+ /* Cannot start zstream while it is in progress. */
1181
+ if (args->z->flags & ZSTREAM_IN_PROGRESS) {
1182
+ rb_raise(cInProgressError, "zlib stream is in progress");
1183
+ }
1184
+ args->z->flags |= ZSTREAM_IN_PROGRESS;
1185
+
1186
+ rb_ensure(zstream_run_try, value_arg, zstream_run_ensure, value_arg);
1187
+
1159
1188
  return Qnil;
1160
1189
  }
1161
1190
 
1162
1191
  static void
1163
1192
  zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1164
1193
  {
1165
- struct zstream_run_synchronized_args run_args;
1166
- run_args.z = z;
1167
- run_args.src = src;
1168
- run_args.len = len;
1169
- run_args.flush = flush;
1170
- rb_mutex_synchronize(z->mutex, zstream_run_synchronized, (VALUE)&run_args);
1194
+ struct zstream_run_args args = {
1195
+ .z = z,
1196
+ .src = src,
1197
+ .len = len,
1198
+ .flush = flush,
1199
+ .interrupt = 0,
1200
+ .jump_state = 0,
1201
+ .stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p(),
1202
+ };
1203
+ rb_mutex_synchronize(z->mutex, zstream_run_synchronized, (VALUE)&args);
1171
1204
  }
1172
1205
 
1173
1206
  static VALUE
@@ -2906,8 +2939,6 @@ gzfile_readpartial(struct gzfile *gz, long len, VALUE outbuf)
2906
2939
  if (!NIL_P(outbuf)) {
2907
2940
  rb_str_resize(outbuf, RSTRING_LEN(dst));
2908
2941
  memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
2909
- rb_str_resize(dst, 0);
2910
- rb_gc_force_recycle(dst);
2911
2942
  dst = outbuf;
2912
2943
  }
2913
2944
  return dst;
@@ -4619,6 +4650,7 @@ Init_zlib(void)
4619
4650
  cMemError = rb_define_class_under(mZlib, "MemError", cZError);
4620
4651
  cBufError = rb_define_class_under(mZlib, "BufError", cZError);
4621
4652
  cVersionError = rb_define_class_under(mZlib, "VersionError", cZError);
4653
+ cInProgressError = rb_define_class_under(mZlib, "InProgressError", cZError);
4622
4654
 
4623
4655
  rb_define_module_function(mZlib, "zlib_version", rb_zlib_version, 0);
4624
4656
  rb_define_module_function(mZlib, "adler32", rb_zlib_adler32, -1);
@@ -4926,6 +4958,7 @@ Init_zlib(void)
4926
4958
  * - Zlib::MemError
4927
4959
  * - Zlib::BufError
4928
4960
  * - Zlib::VersionError
4961
+ * - Zlib::InProgressError
4929
4962
  *
4930
4963
  */
4931
4964
 
@@ -5000,6 +5033,20 @@ Init_zlib(void)
5000
5033
  *
5001
5034
  */
5002
5035
 
5036
+ /*
5037
+ * Document-class: Zlib::InProgressError
5038
+ *
5039
+ * Subclass of Zlib::Error. This error is raised when the zlib
5040
+ * stream is currently in progress.
5041
+ *
5042
+ * For example:
5043
+ *
5044
+ * inflater = Zlib::Inflate.new
5045
+ * inflater.inflate(compressed) do
5046
+ * inflater.inflate(compressed) # Raises Zlib::InProgressError
5047
+ * end
5048
+ */
5049
+
5003
5050
  /*
5004
5051
  * Document-class: Zlib::GzipFile::Error
5005
5052
  *
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-10-19 00:00:00.000000000 Z
12
+ date: 2022-12-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby interface for the zlib compression/decompression library
15
15
  email:
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubygems_version: 3.3.0.dev
48
+ rubygems_version: 3.4.0.dev
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Ruby interface for the zlib compression/decompression library