Exclude the top-level closure from `each_object`; fix
MODIFY
src/load.c
src/load.c
@@ -623,10 +623,11 @@ irep_error(mrb_state *mrb)
mrb_exc_set(mrb, mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "irep load error"));
}
-MRB_API mrb_value
-mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
+void mrb_codedump_all(mrb_state*, struct RProc*);
+
+static mrb_value
+load_irep(mrb_state *mrb, mrb_irep *irep, mrbc_context *c)
{
- mrb_irep *irep = mrb_read_irep(mrb, bin);
struct RProc *proc;
if (!irep) {
@@ -634,11 +635,19 @@ mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
return mrb_nil_value();
}
proc = mrb_proc_new(mrb, irep);
+ proc->c = NULL;
mrb_irep_decref(mrb, irep);
+ if (c && c->dump_result) mrb_codedump_all(mrb, proc);
if (c && c->no_exec) return mrb_obj_value(proc);
return mrb_top_run(mrb, proc, mrb_top_self(mrb), 0);
}
+MRB_API mrb_value
+mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
+{
+ return load_irep(mrb, mrb_read_irep(mrb, bin), c);
+}
+
MRB_API mrb_value
mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
{
@@ -681,25 +690,10 @@ irep_exit:
return irep;
}
-void mrb_codedump_all(mrb_state*, struct RProc*);
-
MRB_API mrb_value
mrb_load_irep_file_cxt(mrb_state *mrb, FILE* fp, mrbc_context *c)
{
- mrb_irep *irep = mrb_read_irep_file(mrb, fp);
- mrb_value val;
- struct RProc *proc;
-
- if (!irep) {
- irep_error(mrb);
- return mrb_nil_value();
- }
- proc = mrb_proc_new(mrb, irep);
- mrb_irep_decref(mrb, irep);
- if (c && c->dump_result) mrb_codedump_all(mrb, proc);
- if (c && c->no_exec) return mrb_obj_value(proc);
- val = mrb_top_run(mrb, proc, mrb_top_self(mrb), 0);
- return val;
+ return load_irep(mrb, mrb_read_irep_file(mrb, fp), c);
}
MRB_API mrb_value

Exclude the top-level closure from `each_object`; fix #3793