zlib 3.2.0 → 3.2.1
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 +4 -4
- data/ext/zlib/zlib.c +180 -117
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92e21e7d156e0a92bfb671d2c63ce8773f14faa73376b134d2b50619ee0d5cf1
|
4
|
+
data.tar.gz: 4dbf1207f8e6bfde47c7c7ad3e6e4fb34ac925ab6aa46c801b5f6260c1a81031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d651705b95865f99bc0b47efb06a2b8bbd0154c63dc905c7e21733ce1ce244489eb67925bd83dd48eb9b7f8a8fd1cd3622b2a73159e33d8d51c9f78ae5f723e
|
7
|
+
data.tar.gz: 22166bec315ebd5c069c6c32bd451bc8af24d90904d9051b78c867a839617b5a49133e9dd25afa6e357bb321a3ac46e4b2dec307f7835ec7b094a7d0d6782dfe
|
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.
|
28
|
+
#define RUBY_ZLIB_VERSION "3.2.1"
|
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
|
-
|
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
|
724
|
-
zstream_expand_buffer_protect(
|
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
|
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
|
-
|
1023
|
+
zstream_run_once(void *_arguments)
|
1027
1024
|
{
|
1028
|
-
struct zstream_run_args *
|
1029
|
-
|
1030
|
-
struct zstream *z = args->z;
|
1031
|
-
uInt n;
|
1032
|
-
|
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));
|
1038
|
-
|
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
|
-
}
|
1025
|
+
struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
|
1026
|
+
struct zstream *z = arguments->z;
|
1068
1027
|
|
1069
|
-
|
1070
|
-
err = Z_OK; /* buffer expanded but stream processing was stopped */
|
1071
|
-
args->jump_state = state;
|
1072
|
-
break;
|
1073
|
-
}
|
1074
|
-
}
|
1028
|
+
uintptr_t error = z->func->run(&z->stream, arguments->flush);
|
1075
1029
|
|
1076
|
-
return (void
|
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
|
-
|
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
|
-
|
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
|
-
|
1852
|
+
struct rb_zlib_deflate_arguments arguments = {z, src, ARG_FLUSH(flush)};
|
1807
1853
|
|
1808
|
-
return
|
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
|
-
*
|
2106
|
-
|
2107
|
-
*
|
2108
|
-
|
2109
|
-
|
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
|
-
|
2157
|
+
rb_inflate_inflate_body(VALUE _arguments)
|
2152
2158
|
{
|
2153
|
-
struct
|
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
|
*
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
- UENO Katsuhiro
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby interface for the zlib compression/decompression library
|
15
15
|
email:
|
16
16
|
- matz@ruby-lang.org
|
17
|
-
-
|
17
|
+
-
|
18
18
|
executables: []
|
19
19
|
extensions:
|
20
20
|
- ext/zlib/extconf.rb
|
@@ -31,7 +31,7 @@ licenses:
|
|
31
31
|
- Ruby
|
32
32
|
- BSD-2-Clause
|
33
33
|
metadata: {}
|
34
|
-
post_install_message:
|
34
|
+
post_install_message:
|
35
35
|
rdoc_options: []
|
36
36
|
require_paths:
|
37
37
|
- lib
|
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubygems_version: 3.5.11
|
50
|
-
signing_key:
|
50
|
+
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: Ruby interface for the zlib compression/decompression library
|
53
53
|
test_files: []
|