From 08213e32e817f83313b1586d76c0e8735ba210e7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 25 Jul 2012 08:53:49 +0900 Subject: const reference from instance_eval should not cause SEGV --- src/variable.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 501bed5a6..a1a7f2e82 100644 --- a/src/variable.c +++ b/src/variable.c @@ -10,6 +10,7 @@ #include "mruby/variable.h" #include "error.h" #include "mruby/array.h" +#include "mruby/proc.h" #ifdef ENABLE_REGEXP #include "re.h" @@ -342,7 +343,10 @@ mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym) mrb_value mrb_vm_const_get(mrb_state *mrb, mrb_sym sym) { - return const_get(mrb, mrb->ci->target_class, sym); + struct RClass *c = mrb->ci->proc->target_class; + + if (!c) c = mrb->ci->target_class; + return const_get(mrb, c, sym); } void @@ -355,7 +359,10 @@ mrb_const_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v) void mrb_vm_const_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { - mrb_obj_iv_set(mrb, (struct RObject*)mrb->ci->target_class, sym, v); + struct RClass *c = mrb->ci->proc->target_class; + + if (!c) c = mrb->ci->target_class; + mrb_obj_iv_set(mrb, (struct RObject*)c, sym, v); } void -- cgit v1.2.3