From b6d5ce7975667cc32d7d86a992d5206627e5ff73 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 8 Mar 2015 13:52:51 +0000 Subject: * ext/zlib/zlib.c (rb_gzfile_close): Don't raise on double close for consistent to IO#close. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/zlib/zlib.c | 6 +++++- test/zlib/test_zlib.rb | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5e7790783a..d45f02545c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Mar 8 22:50:57 2015 Tanaka Akira + + * ext/zlib/zlib.c (rb_gzfile_close): Don't raise on double + close for consistent to IO#close. + Sun Mar 8 16:57:35 2015 Nobuyoshi Nakada * dir.c (glob_helper): match patterns against legacy short names diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 8f24b77d8f..9c2b7b624f 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -3297,9 +3297,13 @@ rb_gzfile_set_comment(VALUE obj, VALUE str) static VALUE rb_gzfile_close(VALUE obj) { - struct gzfile *gz = get_gzfile(obj); + struct gzfile *gz; VALUE io; + TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz); + if (!ZSTREAM_IS_READY(&gz->z)) { + return Qnil; + } io = gz->io; gzfile_close(gz, 1); return io; diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 3a2fe9274d..63bbd27cc6 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -962,6 +962,19 @@ if defined? Zlib assert_equal(content, read_size) } end + + def test_double_close + Tempfile.create("test_zlib_gzip_reader_close") {|t| + t.binmode + content = "foo" + Zlib::GzipWriter.wrap(t) {|gz| gz.print(content) } + r = Zlib::GzipReader.open(t.path) + assert_equal(content, r.read) + assert_nothing_raised { r.close } + assert_nothing_raised { r.close } + } + end + end class TestZlibGzipWriter < Test::Unit::TestCase @@ -1022,6 +1035,15 @@ if defined? Zlib assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read }) } end + + def test_double_close + Tempfile.create("test_zlib_gzip_reader_close") {|t| + t.binmode + w = Zlib::GzipWriter.wrap(t) + assert_nothing_raised { w.close } + assert_nothing_raised { w.close } + } + end end class TestZlib < Test::Unit::TestCase -- cgit v1.2.3