[前][次][番号順一覧][スレッド一覧]

ruby-changes:37812

From: akr <ko1@a...>
Date: Sun, 8 Mar 2015 22:53:09 +0900 (JST)
Subject: [ruby-changes:37812] akr:r49893 (trunk): * ext/zlib/zlib.c (rb_gzfile_close): Don't raise on double

akr	2015-03-08 22:52:51 +0900 (Sun, 08 Mar 2015)

  New Revision: 49893

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49893

  Log:
    * ext/zlib/zlib.c (rb_gzfile_close): Don't raise on double
      close for consistent to IO#close.

  Modified files:
    trunk/ChangeLog
    trunk/ext/zlib/zlib.c
    trunk/test/zlib/test_zlib.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49892)
+++ ChangeLog	(revision 49893)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Mar  8 22:50:57 2015  Tanaka Akira  <akr@f...>
+
+	* 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  <nobu@r...>
 
 	* dir.c (glob_helper): match patterns against legacy short names
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 49892)
+++ ext/zlib/zlib.c	(revision 49893)
@@ -3297,9 +3297,13 @@ rb_gzfile_set_comment(VALUE obj, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3297
 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;
Index: test/zlib/test_zlib.rb
===================================================================
--- test/zlib/test_zlib.rb	(revision 49892)
+++ test/zlib/test_zlib.rb	(revision 49893)
@@ -962,6 +962,19 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L962
         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 https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L1035
         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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]