From d741c77b5fd976300815c1ea987e76e92b71122f Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 11 Dec 2020 16:37:20 +0900 Subject: fix ivar with shareable objects issue Instance variables of sharable objects are accessible only from main ractor, so we need to check it correctly. --- variable.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 81c0a7da2f..45385fb9e0 100644 --- a/variable.c +++ b/variable.c @@ -926,6 +926,8 @@ generic_ivtbl(VALUE obj, ID id, bool force_check_ractor) !RB_OBJ_FROZEN_RAW(obj) && UNLIKELY(!rb_ractor_main_p()) && UNLIKELY(rb_ractor_shareable_p(obj))) { + + // TODO: RuntimeError? rb_raise(rb_eRuntimeError, "can not access instance variables of shareable objects from non-main Ractors"); } return generic_iv_tbl_; @@ -961,6 +963,21 @@ rb_ivar_generic_ivtbl_lookup(VALUE obj, struct gen_ivtbl **ivtbl) return gen_ivtbl_get(obj, 0, ivtbl); } +MJIT_FUNC_EXPORTED VALUE +rb_ivar_generic_lookup_with_index(VALUE obj, ID id, uint32_t index) +{ + struct gen_ivtbl *ivtbl; + + if (gen_ivtbl_get(obj, id, &ivtbl)) { + if (LIKELY(index < ivtbl->numiv)) { + VALUE val = ivtbl->ivptr[index]; + return val; + } + } + + return Qundef; +} + static VALUE generic_ivar_delete(VALUE obj, ID id, VALUE undef) { -- cgit v1.2.3