mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 06:25:31 +02:00
Workaround of instance variable on hidden object
Since 9d9aea7fe5
, generic instance
variables need `iv_index_tbl` in the object's class. As hidden
objects, however, have no class, access to the variables causes a
segfault. Get rid of that segfault by raising an exception, for
the time being.
This commit is contained in:
parent
921916ff9e
commit
52cdf400ef
2 changed files with 17 additions and 2 deletions
|
@ -65,6 +65,18 @@ class TestEncoding < Test::Unit::TestCase
|
||||||
END;
|
END;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_extra_encoding
|
||||||
|
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
begin;
|
||||||
|
200.times {|i|
|
||||||
|
Encoding::UTF_8.replicate("dummy#{i}")
|
||||||
|
}
|
||||||
|
e = Encoding.list.last
|
||||||
|
format = "%d".force_encoding(e)
|
||||||
|
assert_raise(TypeError) {format % 0}
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
|
||||||
def test_dummy_p
|
def test_dummy_p
|
||||||
assert_equal(true, Encoding::ISO_2022_JP.dummy?)
|
assert_equal(true, Encoding::ISO_2022_JP.dummy?)
|
||||||
assert_equal(false, Encoding::UTF_8.dummy?)
|
assert_equal(false, Encoding::UTF_8.dummy?)
|
||||||
|
|
|
@ -1134,9 +1134,12 @@ static st_table *
|
||||||
iv_index_tbl_make(VALUE obj)
|
iv_index_tbl_make(VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE klass = rb_obj_class(obj);
|
VALUE klass = rb_obj_class(obj);
|
||||||
st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(klass);
|
st_table *iv_index_tbl;
|
||||||
|
|
||||||
if (!iv_index_tbl) {
|
if (!klass) {
|
||||||
|
rb_raise(rb_eTypeError, "hidden object cannot have instance variables");
|
||||||
|
}
|
||||||
|
if (!(iv_index_tbl = RCLASS_IV_INDEX_TBL(klass))) {
|
||||||
iv_index_tbl = RCLASS_IV_INDEX_TBL(klass) = st_init_numtable();
|
iv_index_tbl = RCLASS_IV_INDEX_TBL(klass) = st_init_numtable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue