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

ruby-changes:34084

From: akr <ko1@a...>
Date: Tue, 27 May 2014 19:10:01 +0900 (JST)
Subject: [ruby-changes:34084] akr:r46165 (trunk): * io.c (rb_io_autoclose_p): Don't raise on frozen IO.

akr	2014-05-27 19:09:55 +0900 (Tue, 27 May 2014)

  New Revision: 46165

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

  Log:
    * io.c (rb_io_autoclose_p): Don't raise on frozen IO.
    
    * test/lib/minitest/unit.rb: IO#autoclose? may raise IOError.

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/lib/minitest/unit.rb
    trunk/test/ruby/test_io.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46164)
+++ ChangeLog	(revision 46165)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 27 19:07:26 2014  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_io_autoclose_p): Don't raise on frozen IO.
+
+	* test/lib/minitest/unit.rb: IO#autoclose? may raise IOError.
+
 Tue May 27 19:01:49 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* test/openssl/test_pair.rb: Modify TestSSL#test_read_and_write
Index: io.c
===================================================================
--- io.c	(revision 46164)
+++ io.c	(revision 46165)
@@ -7607,8 +7607,8 @@ rb_io_s_for_fd(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/io.c#L7607
 static VALUE
 rb_io_autoclose_p(VALUE io)
 {
-    rb_io_t *fptr;
-    GetOpenFile(io, fptr);
+    rb_io_t *fptr = RFILE(io)->fptr;
+    rb_io_check_closed(fptr);
     return (fptr->mode & FMODE_PREP) ? Qfalse : Qtrue;
 }
 
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 46164)
+++ test/ruby/test_io.rb	(revision 46165)
@@ -2796,6 +2796,13 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2796
     end
   end
 
+  def test_frozen_autoclose
+    with_pipe do |r,w|
+      fd = r.fileno
+      assert_equal(true, r.freeze.autoclose?)
+    end
+  end
+
   def test_sysread_locktmp
     bug6099 = '[ruby-dev:45297]'
     buf = " " * 100
Index: test/lib/minitest/unit.rb
===================================================================
--- test/lib/minitest/unit.rb	(revision 46164)
+++ test/lib/minitest/unit.rb	(revision 46165)
@@ -1009,19 +1009,20 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/test/lib/minitest/unit.rb#L1009
         h = {}
         ObjectSpace.each_object(IO) {|io|
           begin
+            autoclose = io.autoclose?
             fd = io.fileno
           rescue IOError # closed IO object
             next
           end
-          (h[fd] ||= []) << io
+          (h[fd] ||= []) << [io, autoclose]
         }
         fd_leaked.each {|fd|
           str = ''
           if h[fd]
             str << ' :'
-            h[fd].map {|io|
+            h[fd].map {|io, autoclose|
               s = ' ' + io.inspect
-              s << "(not-autoclose)" if !io.autoclose?
+              s << "(not-autoclose)" if !autoclose
               s
             }.each {|s|
               str << s
@@ -1029,9 +1030,8 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/test/lib/minitest/unit.rb#L1030
           end
           puts "Leaked file descriptor: #{name}: #{fd}#{str}"
         }
-        h.each {|fd, ios|
-          next if ios.length <= 1
-          list = ios.map {|io| [io, io.autoclose?] }
+        h.each {|fd, list|
+          next if list.length <= 1
           if 1 < list.count {|io, autoclose| autoclose }
             str = list.map {|io, autoclose| " #{io.inspect}" + (autoclose ? "(autoclose)" : "") }.sort.join
             puts "Multiple autoclose IO object for a file descriptor:#{str}"

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

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