Skip to content

Commit

Permalink
error.c: protect mrb_print_error() from exceptions.
Browse files Browse the repository at this point in the history
Now the function can be called when `mrb->jmp` is not set.
  • Loading branch information
matz committed May 6, 2022
1 parent c3e4ee0 commit 38b69b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/error.c
Expand Up @@ -630,6 +630,26 @@ mrb_raise_nomemory(mrb_state *mrb)
}
}

MRB_API void
mrb_print_error(mrb_state *mrb)
{
#ifndef MRB_NO_STDIO
if (mrb->jmp == NULL) {
struct mrb_jmpbuf c_jmp;
MRB_TRY(&c_jmp) {
mrb->jmp = &c_jmp;
mrb_print_backtrace(mrb);
} MRB_CATCH(&c_jmp) {
/* ignore exception during print_backtrace() */
} MRB_END_EXC(&c_jmp);
mrb->jmp = NULL;
}
else {
mrb_print_backtrace(mrb);
}
#endif
}

void
mrb_init_exception(mrb_state *mrb)
{
Expand Down
11 changes: 0 additions & 11 deletions src/print.c
Expand Up @@ -49,12 +49,6 @@ mrb_p(mrb_state *mrb, mrb_value obj)
}


MRB_API void
mrb_print_error(mrb_state *mrb)
{
mrb_print_backtrace(mrb);
}

MRB_API void
mrb_show_version(mrb_state *mrb)
{
Expand All @@ -78,11 +72,6 @@ mrb_p(mrb_state *mrb, mrb_value obj)
{
}

MRB_API void
mrb_print_error(mrb_state *mrb)
{
}

MRB_API void
mrb_show_version(mrb_state *mrb)
{
Expand Down

0 comments on commit 38b69b6

Please sign in to comment.