ruby-changes:23562
From: naruse <ko1@a...>
Date: Fri, 11 May 2012 01:05:23 +0900 (JST)
Subject: [ruby-changes:23562] naruse:r35613 (ruby_1_9_3): merge revision(s) 35594: [Backport #6422]
naruse 2012-05-11 01:05:13 +0900 (Fri, 11 May 2012) New Revision: 35613 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35613 Log: merge revision(s) 35594: [Backport #6422] * 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: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/io.c branches/ruby_1_9_3/test/ruby/test_io_m17n.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 35612) +++ ruby_1_9_3/ChangeLog (revision 35613) @@ -1,3 +1,13 @@ +Fri May 11 01:04:54 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. + Wed May 9 15:59:17 2012 Nobuyoshi Nakada <nobu@r...> * configure.in (RUBY_WERROR_FLAG): append all warning flags which Index: ruby_1_9_3/io.c =================================================================== --- ruby_1_9_3/io.c (revision 35612) +++ ruby_1_9_3/io.c (revision 35613) @@ -302,6 +302,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: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 35612) +++ ruby_1_9_3/version.h (revision 35613) @@ -1,10 +1,10 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 207 +#define RUBY_PATCHLEVEL 208 -#define RUBY_RELEASE_DATE "2012-05-09" +#define RUBY_RELEASE_DATE "2012-05-11" #define RUBY_RELEASE_YEAR 2012 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 9 +#define RUBY_RELEASE_DAY 11 #include "ruby/version.h" Index: ruby_1_9_3/test/ruby/test_io_m17n.rb =================================================================== --- ruby_1_9_3/test/ruby/test_io_m17n.rb (revision 35612) +++ ruby_1_9_3/test/ruby/test_io_m17n.rb (revision 35613) @@ -2363,6 +2363,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/