@@ -519,13 +519,25 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
519519 rb_ivar_set (mesg , idBt_locations , at );
520520 }
521521 }
522- else if (NIL_P (get_backtrace (mesg ))) {
523- at = rb_vm_backtrace_object ();
524- if (OBJ_FROZEN (mesg )) {
525- mesg = rb_obj_dup (mesg );
522+ else {
523+ int status ;
524+
525+ TH_PUSH_TAG (th );
526+ if ((status = EXEC_TAG ()) == 0 ) {
527+ VALUE bt ;
528+ if (rb_threadptr_set_raised (th )) goto fatal ;
529+ bt = rb_get_backtrace (mesg );
530+ if (NIL_P (bt )) {
531+ at = rb_vm_backtrace_object ();
532+ if (OBJ_FROZEN (mesg )) {
533+ mesg = rb_obj_dup (mesg );
534+ }
535+ rb_ivar_set (mesg , idBt_locations , at );
536+ set_backtrace (mesg , at );
537+ }
538+ rb_threadptr_reset_raised (th );
526539 }
527- rb_ivar_set (mesg , idBt_locations , at );
528- set_backtrace (mesg , at );
540+ TH_POP_TAG ();
529541 }
530542 }
531543
@@ -567,6 +579,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
567579 }
568580
569581 if (rb_threadptr_set_raised (th )) {
582+ fatal :
570583 th -> errinfo = exception_error ;
571584 rb_threadptr_reset_raised (th );
572585 JUMP_TAG (TAG_FATAL );
@@ -1587,7 +1600,7 @@ errat_getter(ID id)
15871600{
15881601 VALUE err = get_errinfo ();
15891602 if (!NIL_P (err )) {
1590- return get_backtrace (err );
1603+ return rb_get_backtrace (err );
15911604 }
15921605 else {
15931606 return Qnil ;
0 commit comments