summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-06-07 13:07:11 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-06-07 13:29:08 +0900
commitb9f771dc50653451d945154671f529903a329033 (patch)
tree7b8104ec13567c38c3824734a8908aac7b81321d /mrbgems/mruby-compiler
parentfc7096f18ac48fd92323ea75b8ee541748bff78b (diff)
downloadmruby-b9f771dc50653451d945154671f529903a329033.tar.gz
mruby-b9f771dc50653451d945154671f529903a329033.zip
Handles exceptions from code generation phase; fix #3695
Diffstat (limited to 'mrbgems/mruby-compiler')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c4
-rw-r--r--mrbgems/mruby-compiler/core/parse.y9
2 files changed, 10 insertions, 3 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 174be4196..daf6100a3 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -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);
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 2c1a943be..1266bb8f5 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -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,7 +5788,9 @@ 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();
}
@@ -5797,7 +5798,9 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
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) {