diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-02 04:20:30 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-02 04:20:30 +0000 |
commit | 57b817f4c550e54ff57642b50723cc7c92bdd2fe (patch) | |
tree | 4eb5c4ef7ac97b4da216c22bcc1defa67942388f /eval.c | |
parent | ae042f21fb695fc80eb19273fa542e8dad85f19f (diff) | |
download | ruby-57b817f4c550e54ff57642b50723cc7c92bdd2fe.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 'eval.c')
-rw-r--r-- | eval.c | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -747,10 +747,11 @@ void rb_raise_jump(VALUE mesg, VALUE cause) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th->cfp; - VALUE klass = cfp->me->klass; + const rb_control_frame_t *cfp = th->cfp; + const rb_method_entry_t *me = rb_vm_frame_method_entry(cfp); + VALUE klass = me->klass; VALUE self = cfp->self; - ID mid = cfp->me->called_id; + ID mid = me->called_id; th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, mid, klass, Qnil); @@ -922,15 +923,14 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE } static const rb_method_entry_t * -method_entry_of_iseq(rb_control_frame_t *cfp, rb_iseq_t *iseq) +method_entry_of_iseq(const rb_control_frame_t *cfp, const rb_iseq_t *iseq) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp_limit; + const rb_control_frame_t *cfp_limit; cfp_limit = (rb_control_frame_t *)(th->stack + th->stack_size); while (cfp_limit > cfp) { - if (cfp->iseq == iseq) - return cfp->me; + if (cfp->iseq == iseq) return rb_vm_frame_method_entry(cfp); /* TODO: fix me */ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } return 0; @@ -940,9 +940,11 @@ static ID frame_func_id(rb_control_frame_t *cfp) { const rb_method_entry_t *me_local; - rb_iseq_t *iseq = cfp->iseq; - if (cfp->me) { - return cfp->me->def->original_id; + const rb_iseq_t *iseq = cfp->iseq; + const rb_method_entry_t *me = rb_vm_frame_method_entry(cfp); + + if (me) { + return me->def->original_id; } while (iseq) { if (RUBY_VM_IFUNC_P(iseq)) { @@ -952,7 +954,6 @@ frame_func_id(rb_control_frame_t *cfp) } me_local = method_entry_of_iseq(cfp, iseq); if (me_local) { - cfp->me = me_local; return me_local->def->original_id; } if (iseq->defined_method_id) { @@ -970,9 +971,11 @@ static ID frame_called_id(rb_control_frame_t *cfp) { const rb_method_entry_t *me_local; - rb_iseq_t *iseq = cfp->iseq; - if (cfp->me) { - return cfp->me->called_id; + const rb_iseq_t *iseq = cfp->iseq; + const rb_method_entry_t *me = rb_vm_frame_method_entry(cfp); + + if (me) { + return me->called_id; } while (iseq) { if (RUBY_VM_IFUNC_P(iseq)) { @@ -982,7 +985,6 @@ frame_called_id(rb_control_frame_t *cfp) } me_local = method_entry_of_iseq(cfp, iseq); if (me_local) { - cfp->me = me_local; return me_local->called_id; } if (iseq->defined_method_id) { @@ -1488,9 +1490,8 @@ top_using(VALUE self, VALUE module) const rb_cref_t *cref = rb_vm_cref(); rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD()); - if (CREF_NEXT(cref) || (prev_cfp && prev_cfp->me)) { - rb_raise(rb_eRuntimeError, - "main.using is permitted only at toplevel"); + if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) { + rb_raise(rb_eRuntimeError, "main.using is permitted only at toplevel"); } rb_using_module(cref, module); return self; |