summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-16 02:39:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-16 02:39:18 +0000
commit59383b1f9cffc2815d4a213710be253d9b6114d4 (patch)
treee34c754cdde6b80559a115615e98b8747a6f5cf5 /test
parent4a906510a289475bb4baf662a70e07e6b01fad3b (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io.rb49
1 files changed, 49 insertions, 0 deletions
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