ruby-changes:71213
From: nagachika <ko1@a...>
Date: Sat, 19 Feb 2022 14:53:58 +0900 (JST)
Subject: [ruby-changes:71213] ebbe2fc923 (ruby_3_0): merge revision(s) cf831f49189c4a890da6845e39199a5dfaf4fb48,3260602fa3d905ba310b9afbc5365ee52cb53d62:
https://git.ruby-lang.org/ruby.git/commit/?id=ebbe2fc923 From ebbe2fc9233c929ebd5a243fb82aaa7c0115d39b Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Sat, 19 Feb 2022 14:33:05 +0900 Subject: 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(-) --- ext/zlib/zlib.c | 18 ++++++++++++++---- test/zlib/test_zlib.rb | 21 +++++++++++++++++++++ version.h | 2 +- 3 files changed, 36 insertions(+), 5 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) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3520 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) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3638 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) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3900 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; diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index addd4270e1..a51a00d329 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -3,6 +3,7 @@ https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L3 require 'test/unit' require 'stringio' require 'tempfile' +require 'tmpdir' begin require 'zlib' @@ -720,6 +721,26 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L721 gz.close } end + + if defined? File::TMPFILE + def test_path_tmpfile + sio = StringIO.new("".dup, 'w') + gz = Zlib::GzipWriter.new(sio) + gz.write "hi" + gz.close + + File.open(Dir.mktmpdir, File::RDWR | File::TMPFILE) do |io| + io.write sio.string + io.rewind + + gz = Zlib::GzipWriter.new(io) + assert_raise(NoMethodError) { gz.path } + + gz = Zlib::GzipReader.new(io) + assert_raise(NoMethodError) { gz.path } + end + end + end end class TestZlibGzipReader < Test::Unit::TestCase diff --git a/version.h b/version.h index 213f1924f4..6cd54a49f9 100644 --- a/version.h +++ b/version.h @@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 4 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 177 +#define RUBY_PATCHLEVEL 178 #define RUBY_RELEASE_YEAR 2022 #define RUBY_RELEASE_MONTH 2 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/