diff options
author | Sorah Fukumori <sorah@cookpad.com> | 2021-03-17 02:16:27 +0900 |
---|---|---|
committer | Sorah Fukumori <sorah@cookpad.com> | 2021-03-17 02:16:27 +0900 |
commit | cf831f49189c4a890da6845e39199a5dfaf4fb48 (patch) | |
tree | 5c6edeb03084ebeca133032cd56590187fa0cecf /ext | |
parent | a47697aa4459e8cc0cc4fd336ca31cfea9d734fc (diff) | |
download | ruby-cf831f49189c4a890da6845e39199a5dfaf4fb48.tar.gz |
zlib: fix Gzip{Writer,Reader}.new fails with a O_TMPFILE file
Diffstat (limited to 'ext')
-rw-r--r-- | ext/zlib/zlib.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 1db5bdb4d9..a1da5f8211 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; |