aboutsummaryrefslogtreecommitdiffstats
path: root/class.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-02 04:20:30 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-02 04:20:30 +0000
commitdc61ecce09ac75e0dcc336b31b4deb544d3598b1 (patch)
tree4eb5c4ef7ac97b4da216c22bcc1defa67942388f /class.c
parentbfb7e27fe2b73e054d0382990ceef7189de71d28 (diff)
downloadruby-dc61ecce09ac75e0dcc336b31b4deb544d3598b1.tar.gz
* method.h: make rb_method_entry_t a VALUE.
Motivation and new data structure are described in [Bug #11203]. This patch also solve the following issues. * [Bug #11200] Memory leak of method entries * [Bug #11046] __callee__ returns incorrect method name in orphan proc * test/ruby/test_method.rb: add a test for [Bug #11046]. * vm_core.h: remvoe rb_control_frame_t::me. me is located at value stack. * vm_core.h, gc.c, vm_method.c: remove unlinked_method... codes because method entries are simple VALUEs. * method.h: Now, all method entries has own independent method definititons. Strictly speaking, this change is not essential, but for future changes. * rb_method_entry_t::flag is move to rb_method_definition_t::flag. * rb_method_definition_t::alias_count is now rb_method_definition_t::alias_count_ptr, a pointer to the counter. * vm_core.h, vm_insnhelper.c (rb_vm_frame_method_entry) added to search the current method entry from value stack. * vm_insnhelper.c (VM_CHECK_MODE): introduced to enable/disable assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/class.c b/class.c
index cbeeb05300..a32b8606af 100644
--- a/class.c
+++ b/class.c
@@ -243,18 +243,21 @@ rb_class_new(VALUE super)
static void
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
{
- VALUE newiseqval;
- if (me->def && me->def->type == VM_METHOD_TYPE_ISEQ) {
- rb_iseq_t *iseq;
- rb_cref_t *new_cref;
- newiseqval = rb_iseq_clone(me->def->body.iseq_body.iseq->self, klass);
- GetISeqPtr(newiseqval, iseq);
- rb_vm_rewrite_cref_stack(me->def->body.iseq_body.cref, me->klass, klass, &new_cref);
- rb_add_method_iseq(klass, mid, iseq, new_cref, me->flag);
- RB_GC_GUARD(newiseqval);
+ if (me->def) {
+ if (me->def->type == VM_METHOD_TYPE_ISEQ) {
+ VALUE newiseqval;
+ rb_cref_t *new_cref;
+ newiseqval = rb_iseq_clone(me->def->body.iseq.iseqval, klass);
+ rb_vm_rewrite_cref_stack(me->def->body.iseq.cref, me->klass, klass, &new_cref);
+ rb_add_method_iseq(klass, mid, newiseqval, new_cref, me->def->flag);
+ RB_GC_GUARD(newiseqval);
+ }
+ else {
+ rb_method_entry_set(klass, mid, me, me->def->flag);
+ }
}
else {
- rb_method_entry_set(klass, mid, me, me->flag);
+ rb_bug("clone_method: unsupported");
}
}
@@ -904,11 +907,9 @@ move_refined_method(st_data_t key, st_data_t value, st_data_t data)
if (me->def->body.orig_me) {
rb_method_entry_t *orig_me = me->def->body.orig_me, *new_me;
me->def->body.orig_me = NULL;
- new_me = ALLOC(rb_method_entry_t);
- *new_me = *me;
+ new_me = rb_method_entry_clone(me);
st_add_direct(tbl, key, (st_data_t) new_me);
- *me = *orig_me;
- xfree(orig_me);
+ rb_method_entry_copy(me, orig_me);
return ST_CONTINUE;
}
else {
@@ -1125,7 +1126,7 @@ method_entry_i(st_data_t key, st_data_t value, st_data_t data)
type = -1; /* none */
}
else {
- type = VISI(me->flag);
+ type = VISI(me->def->flag);
}
st_add_direct(arg->list, key, type);
}