Ensure the shortcut cached in the class
As well as the other places using RCLASS_IV_INDEX_TBL. `IO#reopen` seems the only case that the class of an object can be changed.
This commit is contained in:
parent
27f7b047e0
commit
b52a501ca7
@ -2489,6 +2489,17 @@ class TestIO < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_reopen_ivar
|
||||||
|
assert_ruby_status([], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
begin;
|
||||||
|
f = File.open(IO::NULL)
|
||||||
|
f.instance_variable_set(:@foo, 42)
|
||||||
|
f.reopen(STDIN)
|
||||||
|
f.instance_variable_defined?(:@foo)
|
||||||
|
f.instance_variable_get(:@foo)
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
|
||||||
def test_foreach
|
def test_foreach
|
||||||
a = []
|
a = []
|
||||||
IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x }
|
IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x }
|
||||||
|
@ -885,7 +885,7 @@ generic_ivar_delete(VALUE obj, ID id, VALUE undef)
|
|||||||
st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(rb_obj_class(obj));
|
st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(rb_obj_class(obj));
|
||||||
st_data_t index;
|
st_data_t index;
|
||||||
|
|
||||||
if (st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
|
if (iv_index_tbl && st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
|
||||||
if (index < ivtbl->numiv) {
|
if (index < ivtbl->numiv) {
|
||||||
VALUE ret = ivtbl->ivptr[index];
|
VALUE ret = ivtbl->ivptr[index];
|
||||||
|
|
||||||
@ -906,7 +906,7 @@ generic_ivar_get(VALUE obj, ID id, VALUE undef)
|
|||||||
st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(rb_obj_class(obj));
|
st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(rb_obj_class(obj));
|
||||||
st_data_t index;
|
st_data_t index;
|
||||||
|
|
||||||
if (st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
|
if (iv_index_tbl && st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
|
||||||
if (index < ivtbl->numiv) {
|
if (index < ivtbl->numiv) {
|
||||||
VALUE ret = ivtbl->ivptr[index];
|
VALUE ret = ivtbl->ivptr[index];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user