mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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.
This commit is contained in:
parent
7856da5fe7
commit
72f1c43584
Notes:
git
2020-12-10 18:28:09 +09:00
2 changed files with 22 additions and 1 deletions
|
@ -919,6 +919,19 @@ assert_equal '0', %q{
|
||||||
}.take
|
}.take
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ObjectSpace._id2ref can not handle unshareable objects with Ractors
|
||||||
|
assert_equal 'ok', %q{
|
||||||
|
s = 'hello'
|
||||||
|
|
||||||
|
Ractor.new s.object_id do |id ;s|
|
||||||
|
begin
|
||||||
|
s = ObjectSpace._id2ref(id)
|
||||||
|
rescue => e
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end.take
|
||||||
|
}
|
||||||
|
|
||||||
# Ractor.make_shareable(obj)
|
# Ractor.make_shareable(obj)
|
||||||
assert_equal 'true', %q{
|
assert_equal 'true', %q{
|
||||||
class C
|
class C
|
||||||
|
|
8
gc.c
8
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 = ObjectSpace._id2ref(s.object_id) #=> "I am a string"
|
||||||
* r == s #=> true
|
* r == s #=> true
|
||||||
*
|
*
|
||||||
|
* On multi-ractor mode, if the object is not sharable, it raises
|
||||||
|
* RangeError.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -4023,8 +4025,14 @@ id2ref(VALUE objid)
|
||||||
|
|
||||||
if ((orig = id2ref_obj_tbl(objspace, objid)) != Qundef &&
|
if ((orig = id2ref_obj_tbl(objspace, objid)) != Qundef &&
|
||||||
is_live_object(objspace, orig)) {
|
is_live_object(objspace, orig)) {
|
||||||
|
|
||||||
|
if (!rb_multi_ractor_p() || rb_ractor_shareable_p(orig)) {
|
||||||
return 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)) {
|
if (rb_int_ge(objid, objspace->next_object_id)) {
|
||||||
rb_raise(rb_eRangeError, "%+"PRIsVALUE" is not id value", rb_int2str(objid, 10));
|
rb_raise(rb_eRangeError, "%+"PRIsVALUE" is not id value", rb_int2str(objid, 10));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue