summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2024-11-04 14:38:18 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2024-11-04 14:38:18 -0800
commit12ea98e8c8af0ed6778aad26e7ec5f95e2c239e5 (patch)
treee9f7bc7ae0701bf5fdcdc689ada446f526f56bdf
parent34a0f41d0aaff190f1647a6fa0e905690d0eff98 (diff)
merge revision(s) 637067440f74043c6d79fc649ab8acf1afea25a5: [Backport #20752]
[Bug #20752] Slice of readonly `IO::Buffer` also should be readonly
-rw-r--r--io_buffer.c1
-rw-r--r--test/ruby/test_io_buffer.rb12
-rw-r--r--version.h2
3 files changed, 14 insertions, 1 deletions
diff --git a/io_buffer.c b/io_buffer.c
index 7715aa0d37..6e313d02e4 100644
--- a/io_buffer.c
+++ b/io_buffer.c
@@ -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;
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb
index 7a58ec0c5a..7087a2b957 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -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)
diff --git a/version.h b/version.h
index 9be17cfcf1..cf0215bd58 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 5
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 104
+#define RUBY_PATCHLEVEL 105
#include "ruby/version.h"
#include "ruby/internal/abi.h"