aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-11 16:37:20 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-12 06:19:18 +0900
commitd741c77b5fd976300815c1ea987e76e92b71122f (patch)
tree852e8cc6d6d66193cbb54c0ac9d2b6e7a1a239d6 /variable.c
parent31e8de2920935d500105949bda931f3ca22cdbff (diff)
downloadruby-d741c77b5fd976300815c1ea987e76e92b71122f.tar.gz
fix ivar with shareable objects issue
Instance variables of sharable objects are accessible only from main ractor, so we need to check it correctly.
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c17
1 files changed, 17 insertions, 0 deletions
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)
{