Add the class variable and the class itself in Ractor::IsolationError (#15562)

This commit is contained in:
Étienne Barrié 2025-12-16 17:06:33 +01:00 committed by GitHub
parent 6b35f074bd
commit 09a29e1312
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-12-16 16:07:04 +00:00
Merged-By: luke-gru <luke.gru@gmail.com>
2 changed files with 10 additions and 7 deletions

View File

@ -1022,7 +1022,7 @@ assert_equal '1234', %q{
}
# cvar in shareable-objects are not allowed to access from non-main Ractor
assert_equal 'can not access class variables from non-main Ractors', %q{
assert_equal 'can not access class variables from non-main Ractors (@@cv from C)', %q{
class C
@@cv = 'str'
end
@ -1041,7 +1041,7 @@ assert_equal 'can not access class variables from non-main Ractors', %q{
}
# also cached cvar in shareable-objects are not allowed to access from non-main Ractor
assert_equal 'can not access class variables from non-main Ractors', %q{
assert_equal 'can not access class variables from non-main Ractors (@@cv from C)', %q{
class C
@@cv = 'str'
def self.cv

View File

@ -1195,10 +1195,13 @@ IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(ID id)
}
}
#define CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR() \
if (UNLIKELY(!rb_ractor_main_p())) { \
rb_raise(rb_eRactorIsolationError, "can not access class variables from non-main Ractors"); \
}
static void
CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(VALUE klass, ID id)
{
if (UNLIKELY(!rb_ractor_main_p())) {
rb_raise(rb_eRactorIsolationError, "can not access class variables from non-main Ractors (%"PRIsVALUE" from %"PRIsVALUE")", rb_id2str(id), klass);
}
}
static inline void
ivar_ractor_check(VALUE obj, ID id)
@ -4202,7 +4205,7 @@ cvar_overtaken(VALUE front, VALUE target, ID id)
}
#define CVAR_LOOKUP(v,r) do {\
CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(); \
CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(klass, id); \
if (cvar_lookup_at(klass, id, (v))) {r;}\
CVAR_FOREACH_ANCESTORS(klass, v, r);\
} while(0)