Skip to content

Commit 5faeea8

Browse files
committed
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.
1 parent e9e4647 commit 5faeea8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

gc.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,30 @@ rb_gc_event_hook(VALUE obj, rb_event_flag_t event)
242242
rb_execution_context_t *ec = rb_gc_get_ec();
243243
if (!ec->cfp) return;
244244

245+
#if USE_MODULAR_GC
246+
bool gc_thread_p = false;
247+
if (!GET_EC()) {
248+
gc_thread_p = true;
249+
250+
# ifdef RB_THREAD_LOCAL_SPECIFIER
251+
rb_current_ec_set(ec);
252+
# else
253+
native_tls_set(ruby_current_ec_key, ec);
254+
# endif
255+
}
256+
#endif
257+
245258
EXEC_EVENT_HOOK(ec, event, ec->cfp->self, 0, 0, 0, obj);
259+
260+
#if USE_MODULAR_GC
261+
if (gc_thread_p) {
262+
# ifdef RB_THREAD_LOCAL_SPECIFIER
263+
rb_current_ec_set(NULL);
264+
# else
265+
native_tls_set(ruby_current_ec_key, NULL);
266+
# endif
267+
}
268+
#endif
246269
}
247270

248271
void *

0 commit comments

Comments
 (0)