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

ruby-changes:22533

From: knu <ko1@a...>
Date: Mon, 13 Feb 2012 23:02:58 +0900 (JST)
Subject: [ruby-changes:22533] knu:r34582 (trunk): * vm_method.c (rb_method_boundp):

knu	2012-02-13 23:02:26 +0900 (Mon, 13 Feb 2012)

  New Revision: 34582

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

  Log:
    * vm_method.c (rb_method_boundp):
      obj.respond_to?(:a_protected_method) should return false because
      calling a protected method may cause NoMethodError if called
      from outside the class inheritance tree.  Kernel#respond_to? is
      mostly used to test if it is safe to call a method, so the false
      positive should be avoided. [ruby-dev:40461] [ruby-dev:41739]
      [ruby-dev:41837]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_method.rb
    trunk/vm_method.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34581)
+++ ChangeLog	(revision 34582)
@@ -1,3 +1,13 @@
+Mon Feb 13 23:01:50 2012  Akinori MUSHA  <knu@i...>
+
+	* vm_method.c (rb_method_boundp):
+	  obj.respond_to?(:a_protected_method) should return false because
+	  calling a protected method may cause NoMethodError if called
+	  from outside the class inheritance tree.  Kernel#respond_to? is
+	  mostly used to test if it is safe to call a method, so the false
+	  positive should be avoided. [ruby-dev:40461] [ruby-dev:41739]
+	  [ruby-dev:41837]
+
 Mon Feb 13 21:52:06 2012  Narihiro Nakamura  <authornari@g...>
 
 	* gc.c (HEAP_OBJ_LIMIT, HEAP_BITMAP_LIMIT): HEAP_OBJ_LIMIT used
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 34581)
+++ vm_method.c	(revision 34582)
@@ -547,8 +547,10 @@
     rb_method_entry_t *me = rb_method_entry(klass, id);
 
     if (me != 0) {
-	if ((ex & ~NOEX_RESPONDS) && (me->flag & NOEX_PRIVATE)) {
-	    return FALSE;
+	if ((ex & ~NOEX_RESPONDS) &&
+	    ((me->flag & NOEX_PRIVATE) ||
+	     ((ex & NOEX_RESPONDS) && (me->flag & NOEX_PROTECTED)))) {
+	    return 0;
 	}
 	if (!me->def) return 0;
 	if (me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
@@ -1263,11 +1265,11 @@
 
 /*
  *  call-seq:
- *     obj.respond_to?(symbol, include_private=false) -> true or false
+ *     obj.respond_to?(symbol, include_all=false) -> true or false
  *
- *  Returns +true+ if _obj_ responds to the given
- *  method. Private methods are included in the search only if the
- *  optional second parameter evaluates to +true+.
+ *  Returns +true+ if _obj_ responds to the given method.  Private and
+ *  protected methods are included in the search only if the optional
+ *  second parameter evaluates to +true+.
  *
  *  If the method is not implemented,
  *  as Process.fork on Windows, File.lchmod on GNU/Linux, etc.,
@@ -1300,7 +1302,7 @@
 
 /*
  *  call-seq:
- *     obj.respond_to_missing?(symbol, include_private) -> true or false
+ *     obj.respond_to_missing?(symbol, include_all) -> true or false
  *
  *  Hook method to return whether the _obj_ can respond to _id_ method
  *  or not.
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 34581)
+++ test/ruby/test_method.rb	(revision 34582)
@@ -420,7 +420,7 @@
 
     assert_equal(true,  respond_to?(:mv1))
     assert_equal(false, respond_to?(:mv2))
-    assert_equal(true, respond_to?(:mv3))
+    assert_equal(false, respond_to?(:mv3))
 
     assert_equal(true,  respond_to?(:mv1, true))
     assert_equal(true,  respond_to?(:mv2, true))
@@ -442,7 +442,7 @@
 
     assert_equal(true,  v.respond_to?(:mv1))
     assert_equal(false, v.respond_to?(:mv2))
-    assert_equal(true, v.respond_to?(:mv3))
+    assert_equal(false, v.respond_to?(:mv3))
 
     assert_equal(true,  v.respond_to?(:mv1, true))
     assert_equal(true,  v.respond_to?(:mv2, true))

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

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