1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* class.c (clone_method): do not use me->klass, but use explicitly

passed argument.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-06-03 19:36:52 +00:00
parent 9ff020a009
commit 93f88afbd6
2 changed files with 28 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Thu Jun 4 04:28:45 2015 Koichi Sasada <ko1@atdot.net>
* class.c (clone_method): do not use me->klass, but use explicitly
passed argument.
Thu Jun 4 04:10:43 2015 Koichi Sasada <ko1@atdot.net> Thu Jun 4 04:10:43 2015 Koichi Sasada <ko1@atdot.net>
* vm_core.h (rb_vm_rewrite_cref_stack): rename to rb_vm_rewrite_cref(). * vm_core.h (rb_vm_rewrite_cref_stack): rename to rb_vm_rewrite_cref().

32
class.c
View file

@ -241,25 +241,31 @@ rb_class_new(VALUE super)
} }
static void static void
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me) clone_method(VALUE old_klass, VALUE new_klass, ID mid, const rb_method_entry_t *me)
{ {
if (me->def->type == VM_METHOD_TYPE_ISEQ) { if (me->def->type == VM_METHOD_TYPE_ISEQ) {
VALUE newiseqval; VALUE newiseqval;
rb_cref_t *new_cref; rb_cref_t *new_cref;
newiseqval = rb_iseq_clone(me->def->body.iseq.iseqptr->self, klass); newiseqval = rb_iseq_clone(me->def->body.iseq.iseqptr->self, new_klass);
rb_vm_rewrite_cref(me->def->body.iseq.cref, me->klass, klass, &new_cref); rb_vm_rewrite_cref(me->def->body.iseq.cref, old_klass, new_klass, &new_cref);
rb_add_method_iseq(klass, mid, newiseqval, new_cref, me->def->flags.visi); rb_add_method_iseq(new_klass, mid, newiseqval, new_cref, me->def->flags.visi);
RB_GC_GUARD(newiseqval); RB_GC_GUARD(newiseqval);
} }
else { else {
rb_method_entry_set(klass, mid, me, me->def->flags.visi); rb_method_entry_set(new_klass, mid, me, me->def->flags.visi);
} }
} }
struct clone_method_arg {
VALUE new_klass;
VALUE old_klass;
};
static int static int
clone_method_i(st_data_t key, st_data_t value, st_data_t data) clone_method_i(st_data_t key, st_data_t value, st_data_t data)
{ {
clone_method((VALUE)data, (ID)key, (const rb_method_entry_t *)value); const struct clone_method_arg *arg = (struct clone_method_arg *)data;
clone_method(arg->old_klass, arg->new_klass, (ID)key, (const rb_method_entry_t *)value);
return ST_CONTINUE; return ST_CONTINUE;
} }
@ -343,8 +349,11 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg); st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg);
} }
if (RCLASS_M_TBL(orig)) { if (RCLASS_M_TBL(orig)) {
struct clone_method_arg arg;
arg.old_klass = orig;
arg.new_klass = clone;
RCLASS_M_TBL_INIT(clone); RCLASS_M_TBL_INIT(clone);
st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone); st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)&arg);
} }
return clone; return clone;
@ -359,7 +368,7 @@ rb_singleton_class_clone(VALUE obj)
VALUE VALUE
rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach) rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
{ {
VALUE klass = RBASIC(obj)->klass; const VALUE klass = RBASIC(obj)->klass;
if (!FL_TEST(klass, FL_SINGLETON)) if (!FL_TEST(klass, FL_SINGLETON))
return klass; return klass;
@ -390,7 +399,12 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
rb_singleton_class_attached(clone, attach); rb_singleton_class_attached(clone, attach);
} }
RCLASS_M_TBL_INIT(clone); RCLASS_M_TBL_INIT(clone);
st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone); {
struct clone_method_arg arg;
arg.old_klass = klass;
arg.new_klass = clone;
st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)&arg);
}
rb_singleton_class_attached(RBASIC(clone)->klass, clone); rb_singleton_class_attached(RBASIC(clone)->klass, clone);
FL_SET(clone, FL_SINGLETON); FL_SET(clone, FL_SINGLETON);