diff options
author | Jean Boussier <byroot@ruby-lang.org> | 2023-11-02 17:38:24 +0100 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2023-11-02 19:57:14 +0100 |
commit | 0cb1fc3850db6367fa720bf3b603bb1fde2ef813 (patch) | |
tree | d3469453b772c3372ade9cb09559a133b720749c /vm_insnhelper.c | |
parent | 4c3cc25ea2bc176aa699d14f155b566655936a38 (diff) | |
download | ruby-0cb1fc3850db6367fa720bf3b603bb1fde2ef813.tar.gz |
Fix vm_getivar to handle module with TOO_COMPLEX shape
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 6b354dd19a..e28323e588 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1289,7 +1289,27 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call rb_shape_t *shape = rb_shape_get_shape_by_id(shape_id); if (shape_id == OBJ_TOO_COMPLEX_SHAPE_ID) { - if (!st_lookup(ROBJECT_IV_HASH(obj), id, &val)) { + st_table *table = NULL; + switch (BUILTIN_TYPE(obj)) { + case T_CLASS: + case T_MODULE: + table = (st_table *)RCLASS_IVPTR(obj); + break; + + case T_OBJECT: + table = ROBJECT_IV_HASH(obj); + break; + + default: { + struct gen_ivtbl *ivtbl; + if (rb_gen_ivtbl_get(obj, 0, &ivtbl)) { + table = ivtbl->as.complex.table; + } + break; + } + } + + if (!table || !st_lookup(table, id, &val)) { val = default_value; } } |