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

ruby-changes:27017

From: nobu <ko1@a...>
Date: Tue, 5 Feb 2013 16:30:59 +0900 (JST)
Subject: [ruby-changes:27017] nobu:r39069 (trunk): vm_method.c: drop include_all flag

nobu	2013-02-05 16:25:27 +0900 (Tue, 05 Feb 2013)

  New Revision: 39069

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

  Log:
    vm_method.c: drop include_all flag
    
    * vm_method.c (rb_obj_respond_to): drop optional include_all flag if
      respond_to? method is defined in old style.  [Bug #7722]

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39068)
+++ ChangeLog	(revision 39069)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb  5 16:25:25 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_method.c (rb_obj_respond_to): drop optional include_all flag if
+	  respond_to? method is defined in old style.  [Bug #7722]
+
 Tue Feb 05 15:04:34 2013  Koichi Sasada  <ko1@a...>
 
 	* proc.c (rb_binding_new_with_cfp): permit to create binding object
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 39068)
+++ vm_method.c	(revision 39069)
@@ -1521,7 +1521,24 @@ rb_obj_respond_to(VALUE obj, ID id, int https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1521
 	return basic_obj_respond_to(obj, id, !RTEST(priv));
     }
     else {
-	return RTEST(rb_funcall(obj, idRespond_to, priv ? 2 : 1, ID2SYM(id), Qtrue));
+	int argc = 1;
+	VALUE args[2];
+	args[0] = ID2SYM(id);
+	args[1] = Qtrue;
+	if (priv) {
+	    if (rb_obj_method_arity(obj, idRespond_to) != 1) {
+		argc = 2;
+	    }
+	    else {
+		VALUE klass = CLASS_OF(obj);
+		rb_warn("%"PRIsVALUE"%c""respond_to?(:%"PRIsVALUE") is"
+			" old fashion which takes only one parameter",
+			(FL_TEST(klass, FL_SINGLETON) ? obj : klass),
+			(FL_TEST(klass, FL_SINGLETON) ? '.' : '#'),
+			QUOTE_ID(id));
+	    }
+	}
+	return RTEST(rb_funcall2(obj, idRespond_to, argc,  args));
     }
 }
 
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 39068)
+++ test/ruby/test_marshal.rb	(revision 39069)
@@ -550,4 +550,16 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L550
     assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1cTestMarshal::TestModule\x06:\x0e@ivar_bug\"\x08bug")}
     assert_not_operator(TestModule, :instance_variable_defined?, :@bug)
   end
+
+  class TestForRespondToFalse
+    def respond_to?(a)
+      false
+    end
+  end
+
+  def test_marshal_respond_to_arity
+    assert_nothing_raised(ArgumentError, '[Bug #7722]') do
+      Marshal.dump(TestForRespondToFalse.new)
+    end
+  end
 end

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

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