summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2022-02-19 14:33:05 +0900
committernagachika <nagachika@ruby-lang.org>2022-02-19 14:33:05 +0900
commitebbe2fc9233c929ebd5a243fb82aaa7c0115d39b (patch)
tree7601c70cab39adf16be95ead4dba3c271fcceace /ext
parent4868d4b439123a7ce2b24770833d2a575b81e3a5 (diff)
merge revision(s) cf831f49189c4a890da6845e39199a5dfaf4fb48,3260602fa3d905ba310b9afbc5365ee52cb53d62:
zlib: fix Gzip{Writer,Reader}.new fails with a O_TMPFILE file --- ext/zlib/zlib.c | 18 ++++++++++++++---- test/zlib/test_zlib.rb | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) Adjusted indents [ci skip] --- ext/zlib/zlib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Diffstat (limited to 'ext')
-rw-r--r--ext/zlib/zlib.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 7b74a40860..fdf92e29f1 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -3520,6 +3520,16 @@ rb_gzfile_path(VALUE obj)
return gz->path;
}
+static VALUE
+gzfile_initialize_path_partial(VALUE obj)
+{
+ struct gzfile* gz;
+ TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
+ gz->path = rb_funcall(gz->io, id_path, 0);
+ rb_define_singleton_method(obj, "path", rb_gzfile_path, 0);
+ return Qnil;
+}
+
static void
rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
{
@@ -3628,8 +3638,8 @@ rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj)
rb_gzfile_ecopts(gz, opt);
if (rb_respond_to(io, id_path)) {
- gz->path = rb_funcall(gz->io, id_path, 0);
- rb_define_singleton_method(obj, "path", rb_gzfile_path, 0);
+ /* File#path may raise IOError in case when a path is unavailable */
+ rb_rescue2(gzfile_initialize_path_partial, obj, NULL, Qnil, rb_eIOError, (VALUE)0);
}
return obj;
@@ -3890,8 +3900,8 @@ rb_gzreader_initialize(int argc, VALUE *argv, VALUE obj)
rb_gzfile_ecopts(gz, opt);
if (rb_respond_to(io, id_path)) {
- gz->path = rb_funcall(gz->io, id_path, 0);
- rb_define_singleton_method(obj, "path", rb_gzfile_path, 0);
+ /* File#path may raise IOError in case when a path is unavailable */
+ rb_rescue2(gzfile_initialize_path_partial, obj, NULL, Qnil, rb_eIOError, (VALUE)0);
}
return obj;