From 09a29e1312121fed5704ac196413c3b5ecb83fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Tue, 16 Dec 2025 17:06:33 +0100 Subject: [PATCH] Add the class variable and the class itself in Ractor::IsolationError (#15562) --- bootstraptest/test_ractor.rb | 4 ++-- variable.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 6b35bbb46b..2b268e9966 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -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 diff --git a/variable.c b/variable.c index 47b5218566..a189927472 100644 --- a/variable.c +++ b/variable.c @@ -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)