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

ruby-changes:13567

From: nobu <ko1@a...>
Date: Thu, 15 Oct 2009 14:58:12 +0900 (JST)
Subject: [ruby-changes:13567] Ruby:r25348 (trunk): * io.c (io_reopen): unread current buffer before telling the

nobu	2009-10-15 14:58:00 +0900 (Thu, 15 Oct 2009)

  New Revision: 25348

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

  Log:
    * io.c (io_reopen): unread current buffer before telling the
      position, for the case of reopening same file.  [ruby-dev:39479]

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25347)
+++ ChangeLog	(revision 25348)
@@ -1,3 +1,8 @@
+Thu Oct 15 14:57:58 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (io_reopen): unread current buffer before telling the
+	  position, for the case of reopening same file.  [ruby-dev:39479]
+
 Thu Oct 15 14:20:58 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/iconv/iconv.c (iconv_create): cannot retry with given block.
Index: io.c
===================================================================
--- io.c	(revision 25347)
+++ io.c	(revision 25348)
@@ -5654,6 +5654,13 @@
 		     rb_io_fmode_modestr(orig->mode));
 	}
     }
+    if (fptr->mode & FMODE_WRITABLE) {
+        if (io_fflush(fptr) < 0)
+            rb_sys_fail(0);
+    }
+    else {
+	io_tell(fptr);
+    }
     if (orig->mode & FMODE_READABLE) {
 	pos = io_tell(orig);
     }
@@ -5661,13 +5668,6 @@
         if (io_fflush(orig) < 0)
             rb_sys_fail(0);
     }
-    if (fptr->mode & FMODE_WRITABLE) {
-        if (io_fflush(fptr) < 0)
-            rb_sys_fail(0);
-    }
-    else {
-	io_tell(fptr);
-    }
 
     /* copy rb_io_t structure */
     fptr->mode = orig->mode | (fptr->mode & FMODE_PREP);
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 25347)
+++ test/ruby/test_io.rb	(revision 25348)
@@ -1286,6 +1286,15 @@
         assert_equal("bar\n", f.gets, '[ruby-core:24240]')
       }
     end
+
+    open(__FILE__) do |f|
+      f2 = open(t.path)
+      f.reopen(f2)
+      assert_equal("foo\n", f.gets)
+      assert_equal("bar\n", f.gets)
+      f.reopen(f2)
+      assert_equal("baz\n", f.gets, '[ruby-dev:39479]')
+    end
   end
 
   def test_foreach

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

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