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

ruby-changes:23543

From: shirosaki <ko1@a...>
Date: Tue, 8 May 2012 21:01:15 +0900 (JST)
Subject: [ruby-changes:23543] shirosaki:r35594 (trunk): * io.c (io_unread): fix IO#pos with mode 'r' bug on Windows.

shirosaki	2012-05-08 21:01:05 +0900 (Tue, 08 May 2012)

  New Revision: 35594

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

  Log:
    * io.c (io_unread): fix IO#pos with mode 'r' bug on Windows.
      If the end of reading buffer is CR, io_unread() needs to unread one
      more byte.
      [ruby-core:44874] [Bug #6401]
    
    * test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_with_buffer_end_cr):
      add a test for above.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35593)
+++ ChangeLog	(revision 35594)
@@ -1,3 +1,13 @@
+Tue May  8 20:44:46 2012  Hiroshi Shirosaki  <h.shirosaki@g...>
+
+	* io.c (io_unread): fix IO#pos with mode 'r' bug on Windows.
+	  If the end of reading buffer is CR, io_unread() needs to unread one
+	  more byte.
+	  [ruby-core:44874] [Bug #6401]
+
+	* test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_with_buffer_end_cr):
+	  add a test for above.
+
 Tue May  8 13:38:17 2012  Ayumu AIZAWA  <ayumu.aizawa@g...>
 
 	* ext/date/date_core.c: improving introduction in Date/DateTime
Index: io.c
===================================================================
--- io.c	(revision 35593)
+++ io.c	(revision 35594)
@@ -457,6 +457,12 @@
     /* add extra offset for removed '\r' in rbuf */
     extra_max = (long)(pos - fptr->rbuf.len);
     p = fptr->rbuf.ptr + fptr->rbuf.off;
+
+    /* if the end of rbuf is '\r', rbuf doesn't have '\r' within rbuf.len */
+    if (*(fptr->rbuf.ptr + fptr->rbuf.capa - 1) == '\r') {
+	newlines++;
+    }
+
     for (i = 0; i < fptr->rbuf.len; i++) {
 	if (*p == '\n') newlines++;
 	if (extra_max == newlines) break;
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 35593)
+++ test/ruby/test_io_m17n.rb	(revision 35594)
@@ -2432,6 +2432,22 @@
     }
   end if /mswin|mingw/ =~ RUBY_PLATFORM
 
+  def test_pos_with_buffer_end_cr
+    bug6401 = '[ruby-core:44874]'
+    with_tmpdir {
+      # Read buffer size is 8191. This generates '\r' at 8191.
+      lines = ["X" * 8187, "X"]
+      generate_file("tmp", lines.join("\r\n") + "\r\n")
+
+      open("tmp", "r") do |f|
+        lines.each do |line|
+          f.pos
+          assert_equal(line, f.readline.chomp, bug6401)
+        end
+      end
+    }
+  end if /mswin|mingw/ =~ RUBY_PLATFORM
+
   def test_read_crlf_and_eof
     bug6271 = '[ruby-core:44189]'
     with_tmpdir {

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

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