From 2d8f4fa92fe14d5ec012533ade65eb013a8fc73a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 4 Sep 2021 13:50:32 +0900 Subject: proc.c: need to preserve `target_class` in `callinfo`. Otherwise `target_class` can be lost when it differs from `proc`'s `target_class`, e.g. when called from `instance_eval`. Also we should not pass `target_class` to `MRB_OBJ_ALLOC` since it checks instance type from the class, and `target_class` may not have proper information. ref #5272 --- src/proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/proc.c b/src/proc.c index 6b3e19a6b..d48145f13 100644 --- a/src/proc.c +++ b/src/proc.c @@ -81,7 +81,8 @@ mrb_env_new(mrb_state *mrb, struct mrb_context *c, mrb_callinfo *ci, int nstacks struct REnv *e; mrb_int bidx; - e = MRB_OBJ_ALLOC(mrb, MRB_TT_ENV, tc); + e = MRB_OBJ_ALLOC(mrb, MRB_TT_ENV, NULL); + e->c = tc; MRB_ENV_SET_LEN(e, nstacks); bidx = ci->argc; if (bidx < 0) bidx = 2; @@ -105,7 +106,7 @@ closure_setup(mrb_state *mrb, struct RProc *p) /* do nothing, because e is assigned already */ } else if (up) { - struct RClass *tc = MRB_PROC_TARGET_CLASS(p); + struct RClass *tc = ci->u.target_class; e = mrb_env_new(mrb, mrb->c, ci, up->body.irep->nlocals, ci->stack, tc); ci->u.env = e; -- cgit v1.2.3