[Bug #20752] Slice of readonly IO::Buffer
also should be readonly
This commit is contained in:
parent
b93c51c114
commit
637067440f
Notes:
git
2024-09-30 11:40:03 +00:00
@ -1532,6 +1532,7 @@ rb_io_buffer_slice(struct rb_io_buffer *buffer, VALUE self, size_t offset, size_
|
||||
struct rb_io_buffer *slice = NULL;
|
||||
TypedData_Get_Struct(instance, struct rb_io_buffer, &rb_io_buffer_type, slice);
|
||||
|
||||
slice->flags |= (buffer->flags & RB_IO_BUFFER_READONLY);
|
||||
slice->base = (char*)buffer->base + offset;
|
||||
slice->size = length;
|
||||
|
||||
|
@ -236,6 +236,18 @@ class TestIOBuffer < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_slice_readonly
|
||||
hello = %w"Hello World".join(" ").freeze
|
||||
buffer = IO::Buffer.for(hello)
|
||||
slice = buffer.slice
|
||||
assert_predicate slice, :readonly?
|
||||
assert_raise IO::Buffer::AccessError do
|
||||
# This breaks the literal in string pool and many other tests in this file.
|
||||
slice.set_string("Adios", 0, 5)
|
||||
end
|
||||
assert_equal "Hello World", hello
|
||||
end
|
||||
|
||||
def test_locked
|
||||
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user