ruby-changes:34279
From: nobu <ko1@a...>
Date: Fri, 6 Jun 2014 13:40:06 +0900 (JST)
Subject: [ruby-changes:34279] nobu:r46360 (trunk): io.c: not shorten buffer unless succeeded
nobu 2014-06-06 13:39:37 +0900 (Fri, 06 Jun 2014) New Revision: 46360 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46360 Log: io.c: not shorten buffer unless succeeded * io.c (io_setstrbuf, io_read): should not shorten the given buffer until read succeeds. [ruby-core:55951] [Bug #8625] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46359) +++ ChangeLog (revision 46360) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jun 6 13:39:32 2014 Nobuyoshi Nakada <nobu@r...> + + * io.c (io_setstrbuf, io_read): should not shorten the given buffer until + read succeeds. [ruby-core:55951] [Bug #8625] + Fri Jun 6 07:41:41 2014 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/visitors/yaml_tree.rb: dump empty symbols with a Index: io.c =================================================================== --- io.c (revision 46359) +++ io.c (revision 46360) @@ -2372,9 +2372,6 @@ io_setstrbuf(VALUE *str, long len) https://github.com/ruby/ruby/blob/trunk/io.c#L2372 long clen = RSTRING_LEN(s); if (clen >= len) { rb_str_modify(s); - if (clen != len) { - rb_str_set_len(s, len); - } return; } len -= clen; @@ -2902,7 +2899,10 @@ io_read(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2899 GetOpenFile(io, fptr); rb_io_check_byte_readable(fptr); - if (len == 0) return str; + if (len == 0) { + io_set_read_length(str, 0); + return str; + } READ_CHECK(fptr); #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 46359) +++ test/ruby/test_io.rb (revision 46360) @@ -1230,6 +1230,14 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L1230 t.value assert_equal("", s) end + with_pipe do |r, w| + s = "xxx" + t = Thread.new {r.read(2, s)} + Thread.pass until t.stop? + t.kill + t.value + assert_equal("xxx", s) + end end def test_write_nonblock -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/