Permalink
Browse files

Exceptions may be raised in yyparse(); fix #3600

  • Loading branch information...
matz committed Apr 12, 2017
1 parent 918e7bb commit 326e043a64b37a6c0859ced234689f1dff8d6bee
Showing with 23 additions and 4 deletions.
  1. +22 −4 mrbgems/mruby-compiler/core/parse.y
  2. +1 −0 src/vm.c
@@ -5514,18 +5514,37 @@ void mrb_parser_dump(mrb_state *mrb, node *tree, int offset);
MRB_API void
mrb_parser_parse(parser_state *p, mrbc_context *c)
{
struct mrb_jmpbuf buf;
p->jmp = &buf;
struct mrb_jmpbuf buf1;
p->jmp = &buf1;
MRB_TRY(p->jmp) {
int n;
p->cmd_start = TRUE;
p->in_def = p->in_single = 0;
p->nerr = p->nwarn = 0;
p->lex_strterm = NULL;
parser_init_cxt(p, c);
if (yyparse(p) != 0 || p->nerr > 0) {
if (p->mrb->jmp) {
n = yyparse(p);
}
else {
struct mrb_jmpbuf buf2;
p->mrb->jmp = &buf2;
MRB_TRY(p->mrb->jmp) {
n = yyparse(p);
}
MRB_CATCH(p->mrb->jmp) {
p->nerr++;
mrb_p(p->mrb, mrb_obj_value(p->mrb->exc));
}
MRB_END_EXC(p->mrb->jmp);
p->mrb->jmp = 0;
}
if (n != 0 || p->nerr > 0) {
p->tree = 0;
return;
}
@@ -5536,7 +5555,6 @@ mrb_parser_parse(parser_state *p, mrbc_context *c)
if (c && c->dump_result) {
mrb_parser_dump(p->mrb, p->tree, 0);
}
}
MRB_CATCH(p->jmp) {
yyerror(p, "memory allocation error");
View
@@ -369,6 +369,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
val = mrb_obj_value(mrb->exc);
}
MRB_END_EXC(&c_jmp);
mrb->jmp = 0;
}
else {
struct RProc *p;

0 comments on commit 326e043

Please sign in to comment.