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

ruby-changes:12571

From: nobu <ko1@a...>
Date: Sun, 26 Jul 2009 18:30:26 +0900 (JST)
Subject: [ruby-changes:12571] Ruby:r24280 (trunk): * vm_insnhelper.c (vm_call_method): __send__ can call protected

nobu	2009-07-26 18:30:08 +0900 (Sun, 26 Jul 2009)

  New Revision: 24280

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

  Log:
    * vm_insnhelper.c (vm_call_method): __send__ can call protected
      methods.  [ruby-core:24500]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_module.rb
    trunk/vm_insnhelper.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24279)
+++ ChangeLog	(revision 24280)
@@ -1,3 +1,8 @@
+Sun Jul 26 18:30:02 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_insnhelper.c (vm_call_method): __send__ can call protected
+	  methods.  [ruby-core:24500]
+
 Sun Jul 26 01:09:14 2009  Alexander Zavorine  <alexandre.zavorine@n...>
 
 	* ext/bigdecimal.c: moved BASE_FIG definition before it is used
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 24279)
+++ vm_insnhelper.c	(revision 24280)
@@ -496,6 +496,7 @@
 	       ID id, const rb_method_entry_t *me, VALUE recv)
 {
     VALUE val;
+    int opt_send = 0;
 
   start_method_dispatch:
 
@@ -567,6 +568,7 @@
 		    num -= 1;
 		    DEC_SP(1);
 		    flag |= VM_CALL_FCALL_BIT;
+		    opt_send = 1;
 
 		    goto start_method_dispatch;
 		  }
@@ -605,7 +607,7 @@
 		}
 		val = vm_method_missing(th, id, recv, num, blockptr, stat);
 	    }
-	    else if ((me->flag & NOEX_MASK) & NOEX_PROTECTED) {
+	    else if (!opt_send && (me->flag & NOEX_MASK) & NOEX_PROTECTED) {
 		VALUE defined_class = me->klass;
 
 		if (TYPE(defined_class) == T_ICLASS) {
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 24279)
+++ test/ruby/test_module.rb	(revision 24280)
@@ -104,12 +104,15 @@
     private_class_method :cm1, "cm3"
 
     def aClass
+      :aClass
     end
 
     def aClass1
+      :aClass1
     end
 
     def aClass2
+      :aClass2
     end
 
     private :aClass1
@@ -118,15 +121,18 @@
 
   class BClass < AClass
     def bClass1
+      :bClass1
     end
 
     private
 
     def bClass2
+      :bClass2
     end
 
     protected
     def bClass3
+      :bClass3
     end
   end
 
@@ -489,7 +495,7 @@
 
     c = Class.new
     assert_raise(NameError) do
-      c.instance_eval { attr_reader :"$" }
+      c.instance_eval { attr_reader :"." }
     end
   end
 
@@ -721,4 +727,18 @@
       }.call
     end
   end
+
+  def test_send
+    a = AClass.new
+    assert_equal(:aClass, a.__send__(:aClass))
+    assert_equal(:aClass1, a.__send__(:aClass1))
+    assert_equal(:aClass2, a.__send__(:aClass2))
+    b = BClass.new
+    assert_equal(:aClass, b.__send__(:aClass))
+    assert_equal(:aClass1, b.__send__(:aClass1))
+    assert_equal(:aClass2, b.__send__(:aClass2))
+    assert_equal(:bClass1, b.__send__(:bClass1))
+    assert_equal(:bClass2, b.__send__(:bClass2))
+    assert_equal(:bClass3, b.__send__(:bClass3))
+  end
 end

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

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