diff --git a/vm.c b/vm.c index 750c756..91c8b8c 100644 --- a/vm.c +++ b/vm.c @@ -550,7 +550,7 @@ rb_vm_env_local_variables(VALUE envval) return local_var_list_finish(&vars); } -static void vm_rewrite_ep_in_errinfo(rb_thread_t *th); +static void vm_rewrite_errinfo_in_stack(rb_thread_t *th); static VALUE vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block); static VALUE vm_make_env_object(rb_thread_t * th, rb_control_frame_t *cfp, VALUE *blockprocptr); @@ -577,7 +577,7 @@ vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *blockprocptr } envval = vm_make_env_each(th, cfp, cfp->ep, lep); - vm_rewrite_ep_in_errinfo(th); + vm_rewrite_errinfo_in_stack(th); if (PROCDEBUG) { check_env_value(envval); @@ -586,27 +586,32 @@ vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *blockprocptr return envval; } +void +rb_vm_rewrite_ep_in_errinfo(rb_thread_t *th, VALUE errinfo) +{ + /* rewrite ep in errinfo to point to heap */ + if (RB_TYPE_P(errinfo, T_NODE)) { + VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(errinfo); + if (! ENV_IN_HEAP_P(th, escape_ep)) { + VALUE epval = *escape_ep; + if (!SPECIAL_CONST_P(epval) && RBASIC(epval)->klass == rb_cEnv) { + rb_env_t *epenv; + GetEnvPtr(epval, epenv); + SET_THROWOBJ_CATCH_POINT(errinfo, (VALUE)(epenv->env + epenv->local_size)); + } + } + } +} + static void -vm_rewrite_ep_in_errinfo(rb_thread_t *th) +vm_rewrite_errinfo_in_stack(rb_thread_t *th) { rb_control_frame_t *cfp = th->cfp; while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) { - /* rewrite ep in errinfo to point to heap */ if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) && (cfp->iseq->type == ISEQ_TYPE_RESCUE || cfp->iseq->type == ISEQ_TYPE_ENSURE)) { - VALUE errinfo = cfp->ep[-2]; /* #$! */ - if (RB_TYPE_P(errinfo, T_NODE)) { - VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(errinfo); - if (! ENV_IN_HEAP_P(th, escape_ep)) { - VALUE epval = *escape_ep; - if (!SPECIAL_CONST_P(epval) && RBASIC(epval)->klass == rb_cEnv) { - rb_env_t *epenv; - GetEnvPtr(epval, epenv); - SET_THROWOBJ_CATCH_POINT(errinfo, (VALUE)(epenv->env + epenv->local_size)); - } - } - } + rb_vm_rewrite_ep_in_errinfo(th, cfp->ep[-2]); /* #$! */ } cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } diff --git a/vm_core.h b/vm_core.h index 809da4e..4814a3f 100644 --- a/vm_core.h +++ b/vm_core.h @@ -992,6 +992,7 @@ rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const r rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp); int rb_vm_get_sourceline(const rb_control_frame_t *); VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method); +void rb_vm_rewrite_ep_in_errinfo(rb_thread_t *th, VALUE errinfo); void rb_vm_stack_to_heap(rb_thread_t *th); void ruby_thread_init_stack(rb_thread_t *th); int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp); diff --git a/vm_trace.c b/vm_trace.c index e50ea99..828ce4b 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -348,6 +348,7 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p) if (state) goto terminate; th->errinfo = errinfo; + rb_vm_rewrite_ep_in_errinfo(th, th->errinfo); } terminate: th->trace_arg = 0;