mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 09:33:59 +02:00
Add test for IO::Buffer.for(frozen_string) {}
and omit rb_str_{,un}locktmp in that case
This commit is contained in:
parent
83fb07fb2c
commit
2956573b09
Notes:
git
2025-06-16 20:59:21 +00:00
2 changed files with 16 additions and 2 deletions
|
@ -496,7 +496,9 @@ io_buffer_for_yield_instance(VALUE _arguments)
|
||||||
|
|
||||||
arguments->instance = io_buffer_for_make_instance(arguments->klass, arguments->string, arguments->flags);
|
arguments->instance = io_buffer_for_make_instance(arguments->klass, arguments->string, arguments->flags);
|
||||||
|
|
||||||
|
if (!RB_OBJ_FROZEN(arguments->string)) {
|
||||||
rb_str_locktmp(arguments->string);
|
rb_str_locktmp(arguments->string);
|
||||||
|
}
|
||||||
|
|
||||||
return rb_yield(arguments->instance);
|
return rb_yield(arguments->instance);
|
||||||
}
|
}
|
||||||
|
@ -510,7 +512,9 @@ io_buffer_for_yield_instance_ensure(VALUE _arguments)
|
||||||
rb_io_buffer_free(arguments->instance);
|
rb_io_buffer_free(arguments->instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!RB_OBJ_FROZEN(arguments->string)) {
|
||||||
rb_str_unlocktmp(arguments->string);
|
rb_str_unlocktmp(arguments->string);
|
||||||
|
}
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,16 @@ class TestIOBuffer < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_string_mapped_buffer_frozen
|
||||||
|
string = "Hello World".freeze
|
||||||
|
IO::Buffer.for(string) do |buffer|
|
||||||
|
assert_raise IO::Buffer::AccessError, "Buffer is not writable!" do
|
||||||
|
buffer.set_string("abc")
|
||||||
|
end
|
||||||
|
assert_equal "H".ord, buffer.get_value(:U8, 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_non_string
|
def test_non_string
|
||||||
not_string = Object.new
|
not_string = Object.new
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue