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

ruby-changes:34070

From: nobu <ko1@a...>
Date: Tue, 27 May 2014 11:13:09 +0900 (JST)
Subject: [ruby-changes:34070] nobu:r46151 (trunk): io.c: no error on frozen IO

nobu	2014-05-27 11:12:59 +0900 (Tue, 27 May 2014)

  New Revision: 46151

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

  Log:
    io.c: no error on frozen IO
    
    * io.c (rb_io_fileno, rb_io_inspect): non-modification does not
      error on frozen IO.  [ruby-dev:48241] [Bug #9865]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46150)
+++ ChangeLog	(revision 46151)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 27 11:12:56 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (rb_io_fileno, rb_io_inspect): non-modification does not
+	  error on frozen IO.  [ruby-dev:48241] [Bug #9865]
+
 Tue May 27 00:00:21 2014  yui-knk  <spiketeika@g...>
 
 	* insns.def (defineclass): fix typo in the instruction comment.
Index: io.c
===================================================================
--- io.c	(revision 46150)
+++ io.c	(revision 46151)
@@ -1996,10 +1996,10 @@ rb_io_fdatasync(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L1996
 static VALUE
 rb_io_fileno(VALUE io)
 {
-    rb_io_t *fptr;
+    rb_io_t *fptr = RFILE(io)->fptr;
     int fd;
 
-    GetOpenFile(io, fptr);
+    rb_io_check_closed(fptr);
     fd = fptr->fd;
     return INT2FIX(fd);
 }
@@ -2051,7 +2051,7 @@ rb_io_inspect(VALUE obj) https://github.com/ruby/ruby/blob/trunk/io.c#L2051
     VALUE result;
     static const char closed[] = " (closed)";
 
-    fptr = RFILE(rb_io_taint_check(obj))->fptr;
+    fptr = RFILE(obj)->fptr;
     if (!fptr) return rb_any_to_s(obj);
     result = rb_str_new_cstr("#<");
     rb_str_append(result, rb_class_name(CLASS_OF(obj)));
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 46150)
+++ test/ruby/test_io.rb	(revision 46151)
@@ -1122,6 +1122,8 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L1122
   def test_inspect
     with_pipe do |r, w|
       assert_match(/^#<IO:fd \d+>$/, r.inspect)
+      r.freeze
+      assert_match(/^#<IO:fd \d+>$/, r.inspect)
     end
   end
 
@@ -2786,6 +2788,14 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2788
     assert_equal(2, $stderr.fileno)
   end
 
+  def test_frozen_fileno
+    bug9865 = '[ruby-dev:48241] [Bug #9865]'
+    with_pipe do |r,w|
+      fd = r.fileno
+      assert_equal(fd, r.freeze.fileno, bug9865)
+    end
+  end
+
   def test_sysread_locktmp
     bug6099 = '[ruby-dev:45297]'
     buf = " " * 100

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

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