Skip to content

Commit 09a29e1

Browse files
Add the class variable and the class itself in Ractor::IsolationError (ruby#15562)
1 parent 6b35f07 commit 09a29e1

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

bootstraptest/test_ractor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ def initialize
10221022
}
10231023

10241024
# cvar in shareable-objects are not allowed to access from non-main Ractor
1025-
assert_equal 'can not access class variables from non-main Ractors', %q{
1025+
assert_equal 'can not access class variables from non-main Ractors (@@cv from C)', %q{
10261026
class C
10271027
@@cv = 'str'
10281028
end
@@ -1041,7 +1041,7 @@ class C
10411041
}
10421042

10431043
# also cached cvar in shareable-objects are not allowed to access from non-main Ractor
1044-
assert_equal 'can not access class variables from non-main Ractors', %q{
1044+
assert_equal 'can not access class variables from non-main Ractors (@@cv from C)', %q{
10451045
class C
10461046
@@cv = 'str'
10471047
def self.cv

variable.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,13 @@ IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(ID id)
11951195
}
11961196
}
11971197

1198-
#define CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR() \
1199-
if (UNLIKELY(!rb_ractor_main_p())) { \
1200-
rb_raise(rb_eRactorIsolationError, "can not access class variables from non-main Ractors"); \
1201-
}
1198+
static void
1199+
CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(VALUE klass, ID id)
1200+
{
1201+
if (UNLIKELY(!rb_ractor_main_p())) {
1202+
rb_raise(rb_eRactorIsolationError, "can not access class variables from non-main Ractors (%"PRIsVALUE" from %"PRIsVALUE")", rb_id2str(id), klass);
1203+
}
1204+
}
12021205

12031206
static inline void
12041207
ivar_ractor_check(VALUE obj, ID id)
@@ -4202,7 +4205,7 @@ cvar_overtaken(VALUE front, VALUE target, ID id)
42024205
}
42034206

42044207
#define CVAR_LOOKUP(v,r) do {\
4205-
CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(); \
4208+
CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(klass, id); \
42064209
if (cvar_lookup_at(klass, id, (v))) {r;}\
42074210
CVAR_FOREACH_ANCESTORS(klass, v, r);\
42084211
} while(0)

0 commit comments

Comments
 (0)