Permalink
Browse files

Handles exceptions from code generation phase; fix #3695

  • Loading branch information...
matz committed Jun 7, 2017
1 parent fc7096f commit b9f771dc50653451d945154671f529903a329033
@@ -236,7 +236,10 @@ main(int argc, char **argv)
mrb_gc_arena_restore(mrb, ai);
mrbc_context_free(mrb, c);
if (mrb->exc) {
if (!mrb_undef_p(v)) {
if (mrb_undef_p(v)) {
mrb_p(mrb, mrb_obj_value(mrb->exc));
}
else {
mrb_print_error(mrb);
}
n = -1;
@@ -2993,6 +2993,7 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
{
codegen_scope *scope = scope_new(mrb, 0, 0);
struct RProc *proc;
struct mrb_jmpbuf *prev_jmp = mrb->jmp;
if (!scope) {
return NULL;
@@ -3003,17 +3004,20 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
scope->filename_index = p->current_filename_index;
MRB_TRY(&scope->jmp) {
mrb->jmp = &scope->jmp;
/* prepare irep */
codegen(scope, p->tree, NOVAL);
proc = mrb_proc_new(mrb, scope->irep);
mrb_irep_decref(mrb, scope->irep);
mrb_pool_close(scope->mpool);
proc->c = NULL;
mrb->jmp = prev_jmp;
return proc;
}
MRB_CATCH(&scope->jmp) {
mrb_irep_decref(mrb, scope->irep);
mrb_pool_close(scope->mpool);
mrb->jmp = prev_jmp;
return NULL;
}
MRB_END_EXC(&scope->jmp);
@@ -5579,7 +5579,6 @@ mrb_parser_parse(parser_state *p, mrbc_context *c)
}
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;
@@ -5789,15 +5788,19 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
return mrb_undef_value();
}
else {
mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
if (mrb->exc == NULL) {
mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
}
mrb_parser_free(p);
return mrb_undef_value();
}
}
proc = mrb_generate_code(mrb, p);
mrb_parser_free(p);
if (proc == NULL) {
mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
if (mrb->exc == NULL) {
mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
}
return mrb_undef_value();
}
if (c) {

0 comments on commit b9f771d

Please sign in to comment.