Handle shared/frozen strings in IO#sysread

See https://github.com/mruby/mruby/commit/7edbe428caca6814841195a3f2720745cf04353e
This commit is contained in:
Vladimir Dementyev
2017-10-05 14:40:43 +03:00
parent 04774e5bf2
commit 4c255c7739
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -630,8 +630,13 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
if (mrb_nil_p(buf)) {
buf = mrb_str_new(mrb, NULL, maxlen);
}
mrb_str_modify(mrb, RSTRING(buf));
if (RSTRING_LEN(buf) != maxlen) {
buf = mrb_str_resize(mrb, buf, maxlen);
} else {
mrb_str_modify(mrb, RSTRING(buf));
}
fptr = (struct mrb_io *)io_get_open_fptr(mrb, io);
+5
View File
@@ -250,6 +250,11 @@ assert('IO.sysopen, IO#sysread') do
io.sysread(10000)
io.sysread(10000)
end
assert_raise RuntimeError do
io.sysread(5, "abcde".freeze)
end
io.close
assert_equal "", io.sysread(0)
assert_raise(IOError) { io.sysread(1) }