ruby-changes:15050
From: nobu <ko1@a...>
Date: Mon, 15 Mar 2010 04:42:03 +0900 (JST)
Subject: [ruby-changes:15050] Ruby:r26926 (trunk): * io.c (rb_io_each_codepoint): read directly when readconv is
nobu 2010-03-15 04:41:32 +0900 (Mon, 15 Mar 2010) New Revision: 26926 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26926 Log: * io.c (rb_io_each_codepoint): read directly when readconv is needed but internal encoding is not set. [ruby-core:28650] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 26925) +++ ChangeLog (revision 26926) @@ -1,3 +1,8 @@ +Mon Mar 15 04:41:25 2010 Nobuyoshi Nakada <nobu@r...> + + * io.c (rb_io_each_codepoint): read directly when readconv is + needed but internal encoding is not set. [ruby-core:28650] + Mon Mar 15 04:18:31 2010 Nobuyoshi Nakada <nobu@r...> * tool/file2lastrev.rb (VCS::{SVN,GIT}#get_revisions): Index: io.c =================================================================== --- io.c (revision 26925) +++ io.c (revision 26926) @@ -2895,9 +2895,14 @@ rb_enc_name(fptr->encs.enc)); } n = MBCLEN_CHARFOUND_LEN(r); - c = rb_enc_codepoint(fptr->cbuf+fptr->cbuf_off, - fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len, - fptr->encs.enc); + if (fptr->encs.enc) { + c = rb_enc_codepoint(fptr->cbuf+fptr->cbuf_off, + fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len, + fptr->encs.enc); + } + else { + c = (unsigned char)fptr->cbuf[fptr->cbuf_off]; + } fptr->cbuf_off += n; fptr->cbuf_len -= n; rb_yield(UINT2NUM(c)); Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 26925) +++ test/ruby/test_io.rb (revision 26926) @@ -150,6 +150,16 @@ r.close end + def test_each_codepoint + t = make_tempfile + bug2959 = '[ruby-core:28650]' + a = "" + File.open(t, 'rt') {|f| + f.each_codepoint {|c| a << c} + } + assert_equal("foo\nbar\nbaz\n", a, bug2959) + end + def test_rubydev33072 assert_raise(Errno::ENOENT, "[ruby-dev:33072]") do File.read("empty", nil, nil, {}) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/