protect returning irep (in proc) from GC

This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-11-09 04:08:24 +09:00
parent de790bdc27
commit 7aabc657f1
2 changed files with 9 additions and 2 deletions
+1
View File
@@ -2906,6 +2906,7 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
// 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);
return proc;
}
+8 -2
View File
@@ -462,12 +462,15 @@ mrb_value
mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
{
mrb_irep *irep = mrb_read_irep(mrb, bin);
mrb_value val;
if (!irep) {
irep_error(mrb);
return mrb_nil_value();
}
return mrb_context_run(mrb, mrb_proc_new(mrb, irep), mrb_top_self(mrb), 0);
val = mrb_context_run(mrb, mrb_proc_new(mrb, irep), mrb_top_self(mrb), 0);
mrb_irep_decref(mrb, irep);
return val;
}
#ifdef ENABLE_STDIO
@@ -694,11 +697,14 @@ mrb_value
mrb_load_irep_file(mrb_state *mrb, FILE* fp)
{
mrb_irep *irep = mrb_read_irep_file(mrb, fp);
mrb_value val;
if (!irep) {
irep_error(mrb);
return mrb_nil_value();
}
return mrb_context_run(mrb, mrb_proc_new(mrb, irep), mrb_top_self(mrb), 0);
val = mrb_context_run(mrb, mrb_proc_new(mrb, irep), mrb_top_self(mrb), 0);
mrb_irep_decref(mrb, irep);
return val;
}
#endif /* ENABLE_STDIO */