mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Restructure irep->outer chain; fix #3804
Instead of `irep -> proc` chain, we use `irep -> irep` chain to avoid GC bugs like #3804. We added `target_class` reference to `mrb_irep` struct. That means one more word consumption per `irep`.
This commit is contained in:
+4
-6
@@ -1151,8 +1151,8 @@ static mrb_value
|
||||
mrb_local_variables(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
struct RProc *proc;
|
||||
mrb_irep *irep;
|
||||
mrb_value vars;
|
||||
struct mrb_irep *irep;
|
||||
size_t i;
|
||||
|
||||
proc = mrb->c->ci[-1].proc;
|
||||
@@ -1161,18 +1161,16 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
|
||||
return mrb_ary_new(mrb);
|
||||
}
|
||||
vars = mrb_hash_new(mrb);
|
||||
while (proc) {
|
||||
if (MRB_PROC_CFUNC_P(proc)) break;
|
||||
irep = proc->body.irep;
|
||||
irep = proc->body.irep;
|
||||
while (irep) {
|
||||
if (!irep->lv) break;
|
||||
for (i = 0; i + 1 < irep->nlocals; ++i) {
|
||||
if (irep->lv[i].name) {
|
||||
mrb_hash_set(mrb, vars, mrb_symbol_value(irep->lv[i].name), mrb_true_value());
|
||||
}
|
||||
}
|
||||
if (MRB_PROC_CLASS_P(proc)) break;
|
||||
if (!proc->env) break;
|
||||
proc = proc->body.irep->outer;
|
||||
irep = irep->outer;
|
||||
}
|
||||
|
||||
return mrb_hash_keys(mrb, vars);
|
||||
|
||||
Reference in New Issue
Block a user