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

ruby-changes:7364

From: akr <ko1@a...>
Date: Thu, 28 Aug 2008 00:10:03 +0900 (JST)
Subject: [ruby-changes:7364] Ruby:r18883 (trunk): * io.c (rb_io_initialize): don't accept IO object.

akr	2008-08-28 00:09:47 +0900 (Thu, 28 Aug 2008)

  New Revision: 18883

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

  Log:
    * io.c (rb_io_initialize): don't accept IO object.  [ruby-dev:35895]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18882)
+++ ChangeLog	(revision 18883)
@@ -1,3 +1,7 @@
+Thu Aug 28 00:07:59 2008  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_io_initialize): don't accept IO object.  [ruby-dev:35895]
+
 Wed Aug 27 23:28:51 2008  Masaki Suketa  <masaki.suketa@n...>
 
 	* ext/win32ole/win32ole.c (ole_invoke): WIN32OLE#[] and WIN32OLE#[]=
Index: io.c
===================================================================
--- io.c	(revision 18882)
+++ io.c	(revision 18883)
@@ -5541,8 +5541,8 @@
 static VALUE
 rb_io_initialize(int argc, VALUE *argv, VALUE io)
 {
-    VALUE fnum, mode, orig;
-    rb_io_t *fp, *ofp = NULL;
+    VALUE fnum, mode;
+    rb_io_t *fp;
     int fd, flags, modenum = O_RDONLY;
     convconfig_t convconfig;
     VALUE opt;
@@ -5552,49 +5552,22 @@
     opt = pop_last_hash(&argc, &argv);
     rb_scan_args(argc, argv, "11", &fnum, &mode);
     rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
-    orig = rb_io_check_io(fnum);
-    if (NIL_P(orig)) {
-	fd = NUM2INT(fnum);
-        UPDATE_MAXFD(fd);
-	if (NIL_P(mode)) {
+
+    fd = NUM2INT(fnum);
+    UPDATE_MAXFD(fd);
+    if (NIL_P(mode)) {
 #if defined(HAVE_FCNTL) && defined(F_GETFL)
-	    modenum = fcntl(fd, F_GETFL);
-	    if (modenum == -1) rb_sys_fail(0);
-            flags = rb_io_modenum_flags(modenum);
+        modenum = fcntl(fd, F_GETFL);
+        if (modenum == -1) rb_sys_fail(0);
+        flags = rb_io_modenum_flags(modenum);
 #endif
-	}
-	MakeOpenFile(io, fp);
-        fp->fd = fd;
-	fp->mode = flags;
-        fp->encs = convconfig;
-        clear_codeconv(fp);
-        io_check_tty(fp);
     }
-    else if (RFILE(io)->fptr) {
-	rb_raise(rb_eRuntimeError, "reinitializing IO");
-    }
-    else {
-	GetOpenFile(orig, ofp);
-	if (ofp->refcnt == LONG_MAX) {
-	    VALUE s = rb_inspect(orig);
-	    rb_raise(rb_eIOError, "too many shared IO for %s", StringValueCStr(s));
-	}
-	if (!NIL_P(mode)) {
-	    if ((ofp->mode ^ flags) & (FMODE_READWRITE|FMODE_BINMODE)) {
-                if (TYPE(mode) != T_STRING) {
-		    rb_raise(rb_eArgError, "incompatible mode 0x%x", modenum);
-		}
-		else {
-		    rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_PTR(mode));
-		}
-	    }
-	}
-        if (convconfig.enc || convconfig.enc2) {
-            rb_raise(rb_eArgError, "encoding specified for shared IO");
-        }
-	ofp->refcnt++;
-	RFILE(io)->fptr = ofp;
-    }
+    MakeOpenFile(io, fp);
+    fp->fd = fd;
+    fp->mode = flags;
+    fp->encs = convconfig;
+    clear_codeconv(fp);
+    io_check_tty(fp);
 
     return io;
 }
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 18882)
+++ test/ruby/test_io.rb	(revision 18883)
@@ -1189,31 +1189,6 @@
 
     assert_equal("foo\nbar\nbaz\n", File.read(t.path))
 
-    with_pipe do |r, w|
-      assert_raise(RuntimeError) do
-        o = Object.new
-        class << o; self; end.instance_eval do
-          define_method(:to_io) { r }
-        end
-        w.instance_eval { initialize(o) }
-      end
-    end
-
-    pipe(proc do |w|
-      w = IO.new(w)
-      w.puts "foo"
-      w.puts "bar"
-      w.puts "baz"
-      w.close
-    end, proc do |r|
-      r = IO.new(r)
-      assert_equal("foo\nbar\nbaz\n", r.read)
-    end)
-
-    with_pipe do |r, w|
-      assert_raise(ArgumentError) { IO.new(r, "r+") }
-    end
-
     f = open(t.path)
     assert_raise(RuntimeError) do
       f.instance_eval { initialize }

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

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