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

ruby-changes:28531

From: nobu <ko1@a...>
Date: Sun, 5 May 2013 16:29:56 +0900 (JST)
Subject: [ruby-changes:28531] nobu:r40583 (trunk): insns.def: method entry from method frame

nobu	2013-05-05 16:29:44 +0900 (Sun, 05 May 2013)

  New Revision: 40583

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

  Log:
    insns.def: method entry from method frame
    
    * insns.def (defined): get method entry from the method top level
      frame, not block frame.  [ruby-core:54769] [Bug #8367]

  Modified files:
    trunk/ChangeLog
    trunk/insns.def
    trunk/test/ruby/test_defined.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40582)
+++ ChangeLog	(revision 40583)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May  5 16:29:41 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* insns.def (defined): get method entry from the method top level
+	  frame, not block frame.  [ruby-core:54769] [Bug #8367]
+
 Sun May  5 13:28:54 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* template/ruby.pc.in (Cflags): use rubyarchhdrdir for multiarch.
Index: insns.def
===================================================================
--- insns.def	(revision 40582)
+++ insns.def	(revision 40583)
@@ -765,6 +765,17 @@ defined https://github.com/ruby/ruby/blob/trunk/insns.def#L765
 	break;
       case DEFINED_ZSUPER:{
 	const rb_method_entry_t *me = GET_CFP()->me;
+	if (!me) {
+	    const rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(GET_THREAD());
+	    const rb_control_frame_t *cfp = GET_CFP();
+	    const VALUE *const local_ep = rb_vm_ep_local_ep(cfp->ep);
+	    while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp), end_cfp)) {
+		if (cfp->ep == local_ep) {
+		    me = cfp->me;
+		    break;
+		}
+	    }
+	}
 	if (me) {
 	    VALUE klass = vm_search_normal_superclass(GET_CFP()->klass);
 	    ID id = me->def ? me->def->original_id : me->called_id;
Index: test/ruby/test_defined.rb
===================================================================
--- test/ruby/test_defined.rb	(revision 40582)
+++ test/ruby/test_defined.rb	(revision 40583)
@@ -188,4 +188,20 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L188
     end
     assert_equal("super", c.new.m)
   end
+
+  def test_super_in_block
+    bug8367 = '[ruby-core:54769] [Bug #8367]'
+    c = Class.new do
+      def x; end
+    end
+
+    m = Module.new do
+      def b; yield; end
+      def x; b {return defined?(super)}; end
+    end
+
+    o = c.new
+    o.extend(m)
+    assert_equal("super", o.x)
+  end
 end

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

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