Thanks to visit codestin.com
Credit goes to github.com

Skip to content

2.2 backport: Show stack trace on SystemStackError #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ exc_setup_cause(VALUE exc, VALUE cause)
return exc;
}

static inline int
sysstack_error_p(VALUE exc)
{
return exc == sysstack_error || (!SPECIAL_CONST_P(exc) && RBASIC_CLASS(exc) == rb_eSysStackError);
}

static void
setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
{
Expand All @@ -487,8 +493,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
rb_iv_set(mesg, "bt", at);
}
else {
at = get_backtrace(mesg);
if (NIL_P(at)) {
if (sysstack_error_p(mesg) || NIL_P(at = get_backtrace(mesg))) {
at = rb_vm_backtrace_object();
if (OBJ_FROZEN(mesg)) {
mesg = rb_obj_dup(mesg);
Expand Down Expand Up @@ -657,7 +662,7 @@ make_exception(int argc, VALUE *argv, int isstr)
exc = argv[0];
n = 1;
exception_call:
if (exc == sysstack_error) return exc;
if (sysstack_error_p(exc)) return exc;
CONST_ID(exception, "exception");
mesg = rb_check_funcall(exc, exception, n, argv+1);
if (mesg == Qundef) {
Expand Down
1 change: 1 addition & 0 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,7 @@ Init_Proc(void)
sysstack_error = rb_exc_new3(rb_eSysStackError,
rb_obj_freeze(rb_str_new2("stack level too deep")));
OBJ_TAINT(sysstack_error);
OBJ_FREEZE(sysstack_error);

/* utility functions */
rb_define_global_function("proc", rb_block_proc, 0);
Expand Down
3 changes: 2 additions & 1 deletion test/ruby/test_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ def m;
end

def test_stackoverflow
assert_raise(SystemStackError){m}
e = assert_raise(SystemStackError){m}
assert_operator(e.backtrace.size, :>, 10)
end

def test_machine_stackoverflow
Expand Down
5 changes: 4 additions & 1 deletion vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ static rb_control_frame_t *vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_cont
static void
vm_stackoverflow(void)
{
rb_exc_raise(sysstack_error);
void rb_obj_copy_ivar(VALUE dest, VALUE obj);
VALUE e = rb_obj_alloc(rb_eSysStackError);
rb_obj_copy_ivar(e, sysstack_error);
rb_exc_raise(e);
}

static inline rb_control_frame_t *
Expand Down