[前][次][番号順一覧][スレッド一覧]

ruby-changes:19785

From: yugui <ko1@a...>
Date: Tue, 31 May 2011 09:11:36 +0900 (JST)
Subject: [ruby-changes:19785] yugui:r31830 (ruby_1_9_2): merges r31436 and r31437 from trunk into ruby_1_9_2.

yugui	2011-05-31 09:11:26 +0900 (Tue, 31 May 2011)

  New Revision: 31830

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31830

  Log:
    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.

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/eval.c
    branches/ruby_1_9_2/test/ruby/test_method.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 31829)
+++ ruby_1_9_2/ChangeLog	(revision 31830)
@@ -1,3 +1,17 @@
+Thu May  5 17:36:31 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
+
+	* eval.c (frame_func_id): store result of method_entry_of_iseq() to
+	  cfp->me because method_entry_of_iseq() might become expensive.
+
+Thu May  5 15:03:51 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
+
+	* 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
+
 Mon May  2 00:36:12 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* ext/socket/init.c (rsock_connect): add to care EINTR. based
Index: ruby_1_9_2/eval.c
===================================================================
--- ruby_1_9_2/eval.c	(revision 31829)
+++ ruby_1_9_2/eval.c	(revision 31830)
@@ -751,17 +751,38 @@
     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("<ifunc>");
 	}
+	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;
 	}
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 31829)
+++ ruby_1_9_2/version.h	(revision 31830)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 247
+#define RUBY_PATCHLEVEL 248
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/ruby/test_method.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_method.rb	(revision 31829)
+++ ruby_1_9_2/test/ruby/test_method.rb	(revision 31830)
@@ -78,6 +78,32 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]