summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-05 06:32:37 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-05 06:32:37 +0000
commit5358a5c016de6162433baf80c127be27ce2ca11c (patch)
treebbc94913a101e94cdc510e74d310921d1af653b9
parent09c2f41211709047eff6f8829ff7afc827ef288c (diff)
* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--eval.c23
-rw-r--r--test/ruby/test_method.rb26
3 files changed, 56 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b8cf8a0c58..45a1b66b4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu May 5 15:03:51 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
+
+ * 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
+
Wed May 4 22:13:09 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* benchmark/bm_vm4_pipe.rb: Reduced iterations. Too slow benchmark
diff --git a/eval.c b/eval.c
index 8501f64f5c..de9f6f5785 100644
--- a/eval.c
+++ b/eval.c
@@ -753,12 +753,27 @@ 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 0;
+ if (cfp->me) {
return cfp->me->def->original_id;
}
while (iseq) {
@@ -767,6 +782,10 @@ frame_func_id(rb_control_frame_t *cfp)
if (ifunc->nd_aid) return ifunc->nd_aid;
return rb_intern("<ifunc>");
}
+ me_local = method_entry_of_iseq(cfp, iseq);
+ if (me_local) {
+ return me_local->def->original_id;
+ }
if (iseq->defined_method_id) {
return iseq->defined_method_id;
}
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index fa5f9988f5..90f7ddacde 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -92,6 +92,32 @@ class TestMethod < Test::Unit::TestCase
assert_nil(eval("class TestCallee; __method__; end"))
end
+ def test_method_in_define_method_block
+ bug4606 = '[ruby-core:35386]'
+ c = Class.new do
+ [:m1, :m2].each do |m|
+ define_method(m) do
+ __method__
+ end
+ end
+ end
+ assert_equal(:m1, c.new.m1, bug4606)
+ assert_equal(:m2, c.new.m2, bug4606)
+ end
+
+ def test_method_in_block_in_define_method_block
+ bug4606 = '[ruby-core:35386]'
+ c = Class.new do
+ [:m1, :m2].each do |m|
+ define_method(m) do
+ tap { return __method__ }
+ end
+ end
+ end
+ assert_equal(:m1, c.new.m1, bug4606)
+ assert_equal(:m2, c.new.m2, bug4606)
+ end
+
def test_body
o = Object.new
def o.foo; end