Fix handling of frozens strings.
This commit is contained in:
parent
9de5c4ec76
commit
71bf5cef75
Notes:
git
2021-12-21 08:26:09 +09:00
@ -279,7 +279,12 @@ rb_io_buffer_type_for(VALUE klass, VALUE string)
|
|||||||
|
|
||||||
rb_str_locktmp(string);
|
rb_str_locktmp(string);
|
||||||
|
|
||||||
io_buffer_initialize(data, RSTRING_PTR(string), RSTRING_LEN(string), RB_IO_BUFFER_EXTERNAL, string);
|
enum rb_io_buffer_flags flags = RB_IO_BUFFER_EXTERNAL;
|
||||||
|
|
||||||
|
if (RB_OBJ_FROZEN(string))
|
||||||
|
flags |= RB_IO_BUFFER_IMMUTABLE;
|
||||||
|
|
||||||
|
io_buffer_initialize(data, RSTRING_PTR(string), RSTRING_LEN(string), flags, string);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ class TestIOBuffer < Test::Unit::TestCase
|
|||||||
def test_string_mapped
|
def test_string_mapped
|
||||||
string = "Hello World"
|
string = "Hello World"
|
||||||
buffer = IO::Buffer.for(string)
|
buffer = IO::Buffer.for(string)
|
||||||
|
refute buffer.immutable?
|
||||||
|
|
||||||
# Cannot modify string as it's locked by the buffer:
|
# Cannot modify string as it's locked by the buffer:
|
||||||
assert_raise RuntimeError do
|
assert_raise RuntimeError do
|
||||||
@ -99,6 +100,13 @@ class TestIOBuffer < Test::Unit::TestCase
|
|||||||
assert_equal "Hello World", string
|
assert_equal "Hello World", string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_string_mapped_frozen
|
||||||
|
string = "Hello World".freeze
|
||||||
|
buffer = IO::Buffer.for(string)
|
||||||
|
|
||||||
|
assert buffer.immutable?
|
||||||
|
end
|
||||||
|
|
||||||
def test_non_string
|
def test_non_string
|
||||||
not_string = Object.new
|
not_string = Object.new
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user