ruby-changes:39502
From: nobu <ko1@a...>
Date: Sat, 15 Aug 2015 10:15:35 +0900 (JST)
Subject: [ruby-changes:39502] nobu:r51583 (trunk): io.c: read more data
nobu 2015-08-15 10:15:22 +0900 (Sat, 15 Aug 2015) New Revision: 51583 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51583 Log: io.c: read more data * io.c (rb_io_each_codepoint): read more data when read partially. [ruby-core:70379] [Bug #11444] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51582) +++ ChangeLog (revision 51583) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Aug 15 10:15:20 2015 Nobuyoshi Nakada <nobu@r...> + + * io.c (rb_io_each_codepoint): read more data when read partially. + [ruby-core:70379] [Bug #11444] + Sat Aug 15 04:33:39 2015 Eric Wong <e@8...> * hash.c (any_hash): skip rb_objid_hash for static syms Index: io.c =================================================================== --- io.c (revision 51582) +++ io.c (revision 51583) @@ -3763,8 +3763,25 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L3763 rb_yield(UINT2NUM(c)); } else if (MBCLEN_INVALID_P(r)) { + invalid: rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc)); } + else if (MBCLEN_NEEDMORE_P(r)) { + char cbuf[8], *p = cbuf; + int more = MBCLEN_NEEDMORE_LEN(r); + if (more > numberof(cbuf)) goto invalid; + more += n = fptr->rbuf.len; + if (more > numberof(cbuf)) goto invalid; + while ((n = (int)read_buffered_data(p, more, fptr)) > 0 && + (p += n, (more -= n) > 0)) { + if (io_fillbuf(fptr) < 0) goto invalid; + if ((n = fptr->rbuf.len) > more) n = more; + } + r = rb_enc_precise_mbclen(cbuf, p, enc); + if (!MBCLEN_CHARFOUND_P(r)) goto invalid; + c = rb_enc_codepoint(cbuf, p, enc); + rb_yield(UINT2NUM(c)); + } else { continue; } Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 51582) +++ test/ruby/test_io_m17n.rb (revision 51583) @@ -2562,4 +2562,24 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L2562 a.close rescue nil b.close rescue nil end + + def test_each_codepoint_need_more + code = <<-'end;' + c = nil + begin + STDIN.set_encoding(Encoding::UTF_8).each_codepoint{|i| c = i} + rescue ArgumentError => e + STDERR.puts e.message + else + printf "%x", c + end + end; + args = ['-e', code] + bug11444 = '[ruby-core:70379] [Bug #11444]' + assert_in_out_err(args, "\u{1f376}".b[0,3], [], + ["invalid byte sequence in UTF-8"], + bug11444, timeout: 1) + assert_in_out_err(args, "x"*8190+"\u{1f376}", ["1f376"], [], + bug11444, timeout: 1) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/