From 59383b1f9cffc2815d4a213710be253d9b6114d4 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 16 Sep 2012 02:39:18 +0000 Subject: io.c: io_set_read_length * io.c (io_set_read_length): if the read length equals to the buffer string size then nothing to do. or ensure the string modifiable before setting the length only when the former is shorter. based on the patch in [ruby-core:47541] by Hiroshi Shirosaki. [ruby-core:46586] [Bug #6764] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/ruby/test_io.rb') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f165c640b1..e266f115ba 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2446,5 +2446,54 @@ End assert_raise(Errno::ESPIPE, Errno::EINVAL) { w.advise(:willneed) } end end + + def assert_buffer_not_raise_shared_string_error + bug6764 = '[ruby-core:46586]' + size = 28 + data = [*"a".."z", *"A".."Z"].shuffle.join("") + t = Tempfile.new("test_io") + t.write(data) + t.close + w = Tempfile.new("test_io") + assert_nothing_raised(RuntimeError, bug6764) do + File.open(t.path, "r") do |r| + buf = '' + while yield(r, size, buf) + w << buf + end + end + end + w.close + assert_equal(data, w.open.read, bug6764) + ensure + t.close! + w.close! + end + + def test_read_buffer_not_raise_shared_string_error + assert_buffer_not_raise_shared_string_error do |r, size, buf| + r.read(size, buf) + end + end + + def test_sysread_buffer_not_raise_shared_string_error + assert_buffer_not_raise_shared_string_error do |r, size, buf| + begin + r.sysread(size, buf) + rescue EOFError + nil + end + end + end + + def test_readpartial_buffer_not_raise_shared_string_error + assert_buffer_not_raise_shared_string_error do |r, size, buf| + begin + r.readpartial(size, buf) + rescue EOFError + nil + end + end + end end -- cgit v1.2.3