zlib 2.1.1 → 3.1.0

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: 38b96853c00eb5d1b6b2ad47512fc97d4f4c589e77106dd6cc7f501a3de7ce0c
4
- data.tar.gz: 8fc6e8d0207cc631d85a2cb248502263faf6b2184fab4de0c762d360c95b482f
3
+ metadata.gz: 5a142899fbd58686f35175f42086f71f273cc7d286d01a9bb78ff8bd11e408cb
4
+ data.tar.gz: f734de045270183857df81bf0996ab49d59eb5ff5999ca9d334d688ba50a06b8
5
5
  SHA512:
6
- metadata.gz: 3b9a862a80f4b7146e5d918b917990349ed3be78c8636346636f787b6955c764406717330d1206ec8ea9347149ebe544d03e571c8e9754840f1fd6ac38b794df
7
- data.tar.gz: ca43a10903aa4c981f8de059fd12c695ec4a31b2e8c5ccf34161f828f059660108d7406851c416f90eca9d54f07332cab606c305f566b5b0dac805a94b57e573
6
+ metadata.gz: b7fa3e4abea3e1ca2ee1f02ff5ebf57cdc1fb3ef43a8220a2fe2cfadae9e63ce95790092251bd790d90dd6a38e4645449ec67ac0e737b7b8c0b6870c797e5017
7
+ data.tar.gz: 15bb4093a7645e09a3dddc209dab70ad9ea550086439867c230fb14eeeb64113518bd7c4c23f1ee64140fc6e82bc6c548d35f65dc9668d314b4659536541a99c
data/ext/zlib/extconf.rb CHANGED
@@ -11,10 +11,9 @@ require 'rbconfig'
11
11
  dir_config 'zlib'
12
12
 
13
13
  libs = $libs
14
- if %w'z libz zlib1 zlib zdll zlibwapi'.find {|z| have_library(z, 'deflateReset')} and
15
- have_header('zlib.h') then
16
- have_zlib = true
17
- else
14
+ have_zlib = %w'z libz zlib1 zlib zdll zlibwapi'.any? {|z| have_library(z, 'deflateReset(NULL)', 'zlib.h')}
15
+
16
+ unless have_zlib
18
17
  $libs = libs
19
18
  unless File.directory?(zsrc = "#{$srcdir}/zlib")
20
19
  dirs = Dir.open($srcdir) {|z| z.grep(/\Azlib-\d+[.\d]*\z/) {|x|"#{$srcdir}/#{x}"}}
@@ -121,10 +120,18 @@ if have_zlib
121
120
  $defs << "-DHAVE_CRC32_COMBINE"
122
121
  $defs << "-DHAVE_ADLER32_COMBINE"
123
122
  $defs << "-DHAVE_TYPE_Z_CRC_T"
123
+ $defs << "-DHAVE_CRC32_Z"
124
+ $defs << "-DHAVE_ADLER32_Z"
125
+ $defs << "-DHAVE_ZLIB_SIZE_T_FUNCS"
124
126
  else
125
127
  have_func('crc32_combine', 'zlib.h')
126
128
  have_func('adler32_combine', 'zlib.h')
127
129
  have_type('z_crc_t', 'zlib.h')
130
+ if (have_type('z_size_t', 'zlib.h') &&
131
+ have_func('crc32_z', 'zlib.h') &&
132
+ have_func('adler32_z', 'zlib.h'))
133
+ $defs << "-DHAVE_ZLIB_SIZE_T_FUNCS"
134
+ end
128
135
  end
129
136
 
130
137
  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.1.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_ZLIB_SIZE_T_FUNCS)
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_ZLIB_SIZE_T_FUNCS)
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 {
@@ -906,7 +923,7 @@ zstream_discard_input(struct zstream *z, long len)
906
923
  z->input = Qnil;
907
924
  }
908
925
  else {
909
- z->input = rb_str_substr(z->input, len,
926
+ z->input = rb_str_subseq(z->input, len,
910
927
  RSTRING_LEN(z->input) - len);
911
928
  }
912
929
  }
@@ -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
  *
data/zlib.gemspec CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = []
28
28
  spec.require_paths = ["lib"]
29
29
  spec.extensions = "ext/zlib/extconf.rb"
30
- spec.required_ruby_version = ">= 2.3.0"
30
+ spec.required_ruby_version = ">= 2.5.0"
31
31
  end
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.1.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: 2023-11-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby interface for the zlib compression/decompression library
15
15
  email:
@@ -38,14 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 2.3.0
41
+ version: 2.5.0
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubygems_version: 3.3.0.dev
48
+ rubygems_version: 3.5.0.dev
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Ruby interface for the zlib compression/decompression library