Skip to content

Commit 12ea98e

Browse files
committed
merge revision(s) 6370674: [Backport #20752]
[Bug #20752] Slice of readonly `IO::Buffer` also should be readonly
1 parent 34a0f41 commit 12ea98e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

io_buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,7 @@ rb_io_buffer_slice(struct rb_io_buffer *buffer, VALUE self, size_t offset, size_
15321532
struct rb_io_buffer *slice = NULL;
15331533
TypedData_Get_Struct(instance, struct rb_io_buffer, &rb_io_buffer_type, slice);
15341534

1535+
slice->flags |= (buffer->flags & RB_IO_BUFFER_READONLY);
15351536
slice->base = (char*)buffer->base + offset;
15361537
slice->size = length;
15371538

test/ruby/test_io_buffer.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ def test_slice_bounds_error
236236
end
237237
end
238238

239+
def test_slice_readonly
240+
hello = %w"Hello World".join(" ").freeze
241+
buffer = IO::Buffer.for(hello)
242+
slice = buffer.slice
243+
assert_predicate slice, :readonly?
244+
assert_raise IO::Buffer::AccessError do
245+
# This breaks the literal in string pool and many other tests in this file.
246+
slice.set_string("Adios", 0, 5)
247+
end
248+
assert_equal "Hello World", hello
249+
end
250+
239251
def test_locked
240252
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)
241253

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 5
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 104
14+
#define RUBY_PATCHLEVEL 105
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)