summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-10 13:27:08 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-10 18:27:44 +0900
commit72f1c43584df714a011864ca9fafc6e15ace392c (patch)
tree250ed361e404e63467530a225e9e6acee5fa4232 /gc.c
parent7856da5fe75a76bec909778e411270c10a04ca3a (diff)
ObjectSpace._id2ref should not support unshareable
ObjectSpace._id2ref(id) can return any objects even if they are unshareable, so this patch raises RangeError if it runs on multi-ractor mode and the found object is unshareable.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3878
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gc.c b/gc.c
index c583ed28da..75255bdaf6 100644
--- a/gc.c
+++ b/gc.c
@@ -3987,6 +3987,8 @@ id2ref_obj_tbl(rb_objspace_t *objspace, VALUE objid)
* r = ObjectSpace._id2ref(s.object_id) #=> "I am a string"
* r == s #=> true
*
+ * On multi-ractor mode, if the object is not sharable, it raises
+ * RangeError.
*/
static VALUE
@@ -4023,7 +4025,13 @@ id2ref(VALUE objid)
if ((orig = id2ref_obj_tbl(objspace, objid)) != Qundef &&
is_live_object(objspace, orig)) {
- return orig;
+
+ if (!rb_multi_ractor_p() || rb_ractor_shareable_p(orig)) {
+ return orig;
+ }
+ else {
+ rb_raise(rb_eRangeError, "%+"PRIsVALUE" is id of the unshareable object on multi-ractor", rb_int2str(objid, 10));
+ }
}
if (rb_int_ge(objid, objspace->next_object_id)) {