diff options
| author | Kouichi Nakanishi <[email protected]> | 2017-03-30 16:16:19 +0900 |
|---|---|---|
| committer | Kouichi Nakanishi <[email protected]> | 2017-03-30 16:29:47 +0900 |
| commit | 5efe77fede8c3d57f8be57f5e5b26ab77b8d9c9c (patch) | |
| tree | d9163c5c65574a8a8db360f2cd12417e5e2be23d /src/variable.c | |
| parent | 898077a2c28def75b7894cea03f20bb8796b9d27 (diff) | |
| download | mruby-5efe77fede8c3d57f8be57f5e5b26ab77b8d9c9c.tar.gz mruby-5efe77fede8c3d57f8be57f5e5b26ab77b8d9c9c.zip | |
Modify class variable definition in singleton class; fix #3539
Diffstat (limited to 'src/variable.c')
| -rw-r--r-- | src/variable.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/variable.c b/src/variable.c index 2e823453f..f5d261dec 100644 --- a/src/variable.c +++ b/src/variable.c @@ -819,12 +819,22 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v) c = c->super; } - if (!cls->iv) { - cls->iv = iv_new(mrb); + if (cls && cls->tt == MRB_TT_SCLASS) { + mrb_value klass; + klass = mrb_obj_iv_get(mrb, (struct RObject*)cls, + mrb_intern_lit(mrb, "__attached__")); + + c = mrb_class_ptr(klass); + }else{ + c = cls; + } + + if (!c->iv) { + c->iv = iv_new(mrb); } - mrb_write_barrier(mrb, (struct RBasic*)cls); - iv_put(mrb, cls->iv, sym, v); + mrb_write_barrier(mrb, (struct RBasic*)c); + iv_put(mrb, c->iv, sym, v); } MRB_API void |
