mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #92 from palkan/master
Handle shared/frozen strings in IO#sysread
This commit is contained in:
@@ -630,8 +630,11 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
|
||||
if (mrb_nil_p(buf)) {
|
||||
buf = mrb_str_new(mrb, NULL, maxlen);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user