summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2026-05-08 18:02:12 -0400
committerPeter Zhu <peter@peterzhu.ca>2026-05-08 19:33:02 -0400
commit5faeea873ba4249c685c7f390e939560d736fea8 (patch)
tree8f6b1cc1bcb73ec4e9027586c80d4ba3e991eb75
parente9e4647e6667743e26db037beaa6a56bc8c70f48 (diff)
Set EC in rb_gc_event_hook
The event hook may use the EC and it will be null when it is running from a GC thread.
-rw-r--r--gc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index 0976d6b7b0..1d3f6fa6ed 100644
--- a/gc.c
+++ b/gc.c
@@ -242,7 +242,30 @@ rb_gc_event_hook(VALUE obj, rb_event_flag_t event)
rb_execution_context_t *ec = rb_gc_get_ec();
if (!ec->cfp) return;
+#if USE_MODULAR_GC
+ bool gc_thread_p = false;
+ if (!GET_EC()) {
+ gc_thread_p = true;
+
+# ifdef RB_THREAD_LOCAL_SPECIFIER
+ rb_current_ec_set(ec);
+# else
+ native_tls_set(ruby_current_ec_key, ec);
+# endif
+ }
+#endif
+
EXEC_EVENT_HOOK(ec, event, ec->cfp->self, 0, 0, 0, obj);
+
+#if USE_MODULAR_GC
+ if (gc_thread_p) {
+# ifdef RB_THREAD_LOCAL_SPECIFIER
+ rb_current_ec_set(NULL);
+# else
+ native_tls_set(ruby_current_ec_key, NULL);
+# endif
+ }
+#endif
}
void *