From ffafcd96e66ec6a4b7150616b00bd0bab145671d Mon Sep 17 00:00:00 2001 From: yugui Date: Tue, 31 May 2011 00:11:26 +0000 Subject: merges r31436 and r31437 from trunk into ruby_1_9_2. -- * eval.c (frame_func_id): __method__ return different name from methods defined by Module#define_method with a same block. [ruby-core:35386] fixes #4606 * eval (method_entry_of_iseq): new helper function. search control frame stack for a method entry which has given iseq. * test/ruby/test_method.rb: add tests for #4696 -- * eval.c (frame_func_id): store result of method_entry_of_iseq() to cfp->me because method_entry_of_iseq() might become expensive. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- eval.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 95d1b8c860..a2516f9ec9 100644 --- a/eval.c +++ b/eval.c @@ -751,17 +751,38 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE return result; } +static const rb_method_entry_t * +method_entry_of_iseq(rb_control_frame_t *cfp, rb_iseq_t *iseq) +{ + rb_thread_t *th = GET_THREAD(); + 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; + cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); + } + return 0; +} + static ID frame_func_id(rb_control_frame_t *cfp) { + const rb_method_entry_t *me_local; rb_iseq_t *iseq = cfp->iseq; - if (!iseq) { + if (cfp->me) { return cfp->me->def->original_id; } while (iseq) { if (RUBY_VM_IFUNC_P(iseq)) { return rb_intern(""); } + 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) { return iseq->defined_method_id; } -- cgit v1.2.3