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

ruby-changes:37179

From: akr <ko1@a...>
Date: Fri, 16 Jan 2015 00:26:19 +0900 (JST)
Subject: [ruby-changes:37179] akr:r49260 (trunk): * io.c (rb_io_close_m): Don't raise when the IO object is closed.

akr	2015-01-16 00:26:03 +0900 (Fri, 16 Jan 2015)

  New Revision: 49260

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

  Log:
    * io.c (rb_io_close_m): Don't raise when the IO object is closed.
      [ruby-core:67444] [Feature #10718]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io.rb
    trunk/test/socket/test_basicsocket.rb
    trunk/test/zlib/test_zlib.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49259)
+++ ChangeLog	(revision 49260)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 15 23:55:15 2015  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_io_close_m): Don't raise when the IO object is closed.
+	  [ruby-core:67444] [Feature #10718]
+
 Thu Jan 15 21:34:57 2015  Seiei Higa  <hanachin@g...>
 
 	* proc.c (rb_obj_singleton_method): Kernel#singleton_method should
Index: io.c
===================================================================
--- io.c	(revision 49259)
+++ io.c	(revision 49260)
@@ -4415,11 +4415,18 @@ rb_io_close(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4415
  *
  *  If <em>ios</em> is opened by <code>IO.popen</code>,
  *  <code>close</code> sets <code>$?</code>.
+ *
+ *  Calling this method on closed IO object is just ignored since Ruby 2.3.
  */
 
 static VALUE
 rb_io_close_m(VALUE io)
 {
+    rb_io_t *fptr = RFILE(io)->fptr;
+    rb_io_check_initialized(fptr);
+    if (fptr->fd < 0) {
+        return Qnil;
+    }
     rb_io_check_closed(RFILE(io)->fptr);
     rb_io_close(io);
     return Qnil;
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 49259)
+++ test/ruby/test_io.rb	(revision 49260)
@@ -3159,4 +3159,17 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L3159
       end
     end
   end
+
+  def test_close_twice
+    open(__FILE__) {|f|
+      assert_equal(nil, f.close)
+      assert_equal(nil, f.close)
+    }
+  end
+
+  def test_close_uninitialized
+    io = IO.allocate
+    assert_raise(IOError) { io.close } 
+  end
+
 end
Index: test/zlib/test_zlib.rb
===================================================================
--- test/zlib/test_zlib.rb	(revision 49259)
+++ test/zlib/test_zlib.rb	(revision 49260)
@@ -929,7 +929,7 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L929
         f = open(t.path)
         f.binmode
         assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
-        assert_raise(IOError) { f.close }
+        assert(f.closed?)
       }
     end
 
Index: test/socket/test_basicsocket.rb
===================================================================
--- test/socket/test_basicsocket.rb	(revision 49259)
+++ test/socket/test_basicsocket.rb	(revision 49260)
@@ -9,7 +9,7 @@ class TestSocket_BasicSocket < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/socket/test_basicsocket.rb#L9
     sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
     yield sock
   ensure
-    assert_raise(IOError) {sock.close}
+    assert(sock.closed?)
   end
 
   def test_getsockopt

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

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