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

ruby-changes:43427

From: nobu <ko1@a...>
Date: Sat, 25 Jun 2016 02:33:41 +0900 (JST)
Subject: [ruby-changes:43427] nobu:r55500 (trunk): No respond_to? as if the default definition

nobu	2016-06-25 02:33:35 +0900 (Sat, 25 Jun 2016)

  New Revision: 55500

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55500

  Log:
    No respond_to? as if the default definition
    
    * vm_method.c (vm_respond_to): try method_missing if respond_to?
      is undefined, as if it is the default definition.
      [ruby-core:75377] [Bug #12353]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_marshal.rb
    trunk/vm_method.c
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 55499)
+++ test/ruby/test_marshal.rb	(revision 55500)
@@ -737,4 +737,24 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L737
       end
     RUBY
   end
+
+  MethodMissingWithoutRespondTo = Struct.new(:wrapped_object) do
+    undef respond_to?
+    def method_missing(*args, &block)
+      wrapped_object.public_send(*args, &block)
+    end
+    def respond_to_missing?(name, private = false)
+      wrapped_object.respond_to?(name, false)
+    end
+  end
+
+  def test_method_missing_without_respond_to
+    bug12353 = "[ruby-core:75377] [Bug #12353]: try method_missing if" \
+               " respond_to? is undefined"
+    obj = MethodMissingWithoutRespondTo.new("foo")
+    dump = assert_nothing_raised(NoMethodError, bug12353) do
+      Marshal.dump(obj)
+    end
+    assert_equal(obj, Marshal.load(dump))
+  end
 end
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 55499)
+++ vm_method.c	(revision 55500)
@@ -1916,7 +1916,7 @@ vm_respond_to(rb_thread_t *th, VALUE kla https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1916
     const rb_method_entry_t *const me =
 	method_entry_get(klass, resid, &defined_class);
 
-    if (!me) return TRUE;
+    if (!me) return -1;
     if (METHOD_ENTRY_BASIC(me)) {
 	return -1;
     }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55499)
+++ ChangeLog	(revision 55500)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 25 02:33:33 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_method.c (vm_respond_to): try method_missing if respond_to?
+	  is undefined, as if it is the default definition.
+	  [ruby-core:75377] [Bug #12353]
+
 Fri Jun 24 17:04:21 2016  SHIBATA Hiroshi  <hsbt@r...>
 
 	* ext/psych/*, test/psych/*: Upate psych 2.1.0

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

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