summaryrefslogtreecommitdiffhomepage
path: root/src/vm.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-11-25 09:17:59 +0900
committerGitHub <[email protected]>2016-11-25 09:17:59 +0900
commita28fa35ea9de58e586441cbfdbfb0b7ba86aea99 (patch)
tree15612f2c5b645fffa54e58aba2724fc23901068a /src/vm.c
parent1e892c0ffa33e6e1548bde5fa182872ae7381ac8 (diff)
parent4523aaec015ff0bf900710efc2ec3411e8841fb1 (diff)
downloadmruby-a28fa35ea9de58e586441cbfdbfb0b7ba86aea99.tar.gz
mruby-a28fa35ea9de58e586441cbfdbfb0b7ba86aea99.zip
Merge pull request #3282 from bouk/fix-break-instance-class
Fix segfault when defining class inside instance_exec on primitive
Diffstat (limited to 'src/vm.c')
-rw-r--r--src/vm.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/vm.c b/src/vm.c
index a7418e6e7..41e19b0c0 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2261,7 +2261,7 @@ RETRY_TRY_BLOCK:
CASE(OP_CLASS) {
/* A B R(A) := newclass(R(A),Syms(B),R(A+1)) */
- struct RClass *c = 0;
+ struct RClass *c = 0, *baseclass;
int a = GETARG_A(i);
mrb_value base, super;
mrb_sym id = syms[GETARG_B(i)];
@@ -2269,7 +2269,10 @@ RETRY_TRY_BLOCK:
base = regs[a];
super = regs[a+1];
if (mrb_nil_p(base)) {
- base = mrb_obj_value(mrb->c->ci->target_class);
+ baseclass = mrb->c->ci->proc->target_class;
+ if (!baseclass) baseclass = mrb->c->ci->target_class;
+
+ base = mrb_obj_value(baseclass);
}
c = mrb_vm_define_class(mrb, base, super, id);
regs[a] = mrb_obj_value(c);
@@ -2279,14 +2282,17 @@ RETRY_TRY_BLOCK:
CASE(OP_MODULE) {
/* A B R(A) := newmodule(R(A),Syms(B)) */
- struct RClass *c = 0;
+ struct RClass *c = 0, *baseclass;
int a = GETARG_A(i);
mrb_value base;
mrb_sym id = syms[GETARG_B(i)];
base = regs[a];
if (mrb_nil_p(base)) {
- base = mrb_obj_value(mrb->c->ci->target_class);
+ baseclass = mrb->c->ci->proc->target_class;
+ if (!baseclass) baseclass = mrb->c->ci->target_class;
+
+ base = mrb_obj_value(baseclass);
}
c = mrb_vm_define_module(mrb, base, id);
regs[a] = mrb_obj_value(c);