Update rb_ractor_ensure_shareable

* Fixed use of rb_ractor_shareable_p
* Raise Ractor::IsolationError
This commit is contained in:
Nobuyoshi Nakada 2020-12-22 08:26:42 +09:00
Родитель b2aa21b868
Коммит c0a2d95cf3
2 изменённых файлов: 8 добавлений и 6 удалений

Просмотреть файл

@ -2445,10 +2445,10 @@ rb_ractor_make_shareable_copy(VALUE obj)
VALUE VALUE
rb_ractor_ensure_shareable(VALUE obj, VALUE name) rb_ractor_ensure_shareable(VALUE obj, VALUE name)
{ {
if (!RTEST(rb_ractor_shareable_p(obj))) { if (!rb_ractor_shareable_p(obj)) {
VALUE message = rb_sprintf("cannot assign unshareable object to %"PRIsVALUE, VALUE message = rb_sprintf("cannot assign unshareable object to %"PRIsVALUE,
name); name);
rb_exc_raise(rb_exc_new_str(rb_eRactorError, message)); rb_exc_raise(rb_exc_new_str(rb_eRactorIsolationError, message));
} }
return obj; return obj;
} }

Просмотреть файл

@ -1178,8 +1178,8 @@ x = __ENCODING__
Class.new.class_eval(code) Class.new.class_eval(code)
end end
def assert_ractor_error(message, code) def assert_raise_separately(error, message, code)
assert_raise_with_message(Ractor::Error, message) do assert_raise_with_message(error, message) do
eval_separately(code) eval_separately(code)
end end
end end
@ -1243,7 +1243,8 @@ x = __ENCODING__
end end
def test_shareable_constant_value_unshareable_literal def test_shareable_constant_value_unshareable_literal
assert_ractor_error(/unshareable/, "#{<<~"begin;"}\n#{<<~'end;'}") assert_raise_separately(Ractor::IsolationError, /unshareable/,
"#{<<~"begin;"}\n#{<<~'end;'}")
begin; begin;
# shareable_constant_value: literal # shareable_constant_value: literal
C = ["Not " + "shareable"] C = ["Not " + "shareable"]
@ -1264,7 +1265,8 @@ x = __ENCODING__
end end
def test_shareable_constant_value_unfrozen def test_shareable_constant_value_unfrozen
assert_ractor_error(/does not freeze object correctly/, "#{<<~"begin;"}\n#{<<~'end;'}") assert_raise_separately(Ractor::Error, /does not freeze object correctly/,
"#{<<~"begin;"}\n#{<<~'end;'}")
begin; begin;
# shareable_constant_value: experimental_everything # shareable_constant_value: experimental_everything
o = Object.new o = Object.new