diff --git a/vm_core.h b/vm_core.h index 9aa93b7e21010c..2b991aad4ab97b 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1798,7 +1798,7 @@ extern bool rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb extern bool rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc, FILE *); extern bool rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, FILE *); -#define SDR() rb_vmdebug_stack_dump_raw(GET_EC(), GET_EC()->cfp, stderr) +#define SDR() WITH_EC(ec) {rb_vmdebug_stack_dump_raw(ec, ec->cfp, stderr)} #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_EC(), (cfp), stderr) bool rb_vm_bugreport(const void *, FILE *); typedef void (*ruby_sighandler_t)(int); @@ -1916,6 +1916,13 @@ RUBY_EXTERN unsigned int ruby_vm_event_local_num; #define GET_THREAD() rb_current_thread() #define GET_EC() rb_current_execution_context(true) +#define WITH_VAR(type, var, expr) \ + for (type var = (expr), const *var ## _once = &var; var ## _once; var ## _once = 0) +#define WITH_VM(var) WITH_VAR(rb_vm_t *, var, GET_VM()) +#define WITH_RACTOR(var) WITH_VAR(rb_ractor_t *, var, GET_RACTOR()) +#define WITH_THREAD(var) WITH_VAR(rb_thread_t *, var, GET_THREAD()) +#define WITH_EC(var) WITH_VAR(rb_execution_context_t *, var, GET_EC()) + static inline rb_thread_t * rb_ec_thread_ptr(const rb_execution_context_t *ec) {