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

ruby-changes:31255

From: shugo <ko1@a...>
Date: Thu, 17 Oct 2013 17:44:33 +0900 (JST)
Subject: [ruby-changes:31255] shugo:r43334 (trunk): * vm_insnhelper.c (vm_call_method): set ci->me to 0 when the

shugo	2013-10-17 17:44:26 +0900 (Thu, 17 Oct 2013)

  New Revision: 43334

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

  Log:
    * vm_insnhelper.c (vm_call_method): set ci->me to 0 when the
      original method of a refined method is undef to avoid SEGV.
    
    * vm_method.c (rb_method_entry_without_refinements): return 0 when
      the original method of a refined method is undef to avoid SEGV.
    
    * test/ruby/test_refinement.rb: related test.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_refinement.rb
    trunk/vm_insnhelper.c
    trunk/vm_method.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43333)
+++ ChangeLog	(revision 43334)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct 17 17:43:00 2013  Shugo Maeda  <shugo@r...>
+
+	* vm_insnhelper.c (vm_call_method): set ci->me to 0 when the
+	  original method of a refined method is undef to avoid SEGV.
+
+	* vm_method.c (rb_method_entry_without_refinements): return 0 when
+	  the original method of a refined method is undef to avoid SEGV.
+
+	* test/ruby/test_refinement.rb: related test.
+
 Thu Oct 17 17:38:36 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c, internal.h: rename ruby_xsizefree/realloc to
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 43333)
+++ vm_method.c	(revision 43334)
@@ -670,7 +670,12 @@ rb_method_entry_without_refinements(VALU https://github.com/ruby/ruby/blob/trunk/vm_method.c#L670
     }
     if (defined_class_ptr)
 	*defined_class_ptr = defined_class;
-    return me;
+    if (UNDEFINED_METHOD_ENTRY_P(me)) {
+	return 0;
+    }
+    else {
+	return me;
+    }
 }
 
 static void
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 43333)
+++ vm_insnhelper.c	(revision 43334)
@@ -1903,7 +1903,13 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1903
 	      no_refinement_dispatch:
 		if (ci->me->def->body.orig_me) {
 		    ci->me = ci->me->def->body.orig_me;
-		    goto normal_method_dispatch;
+		    if (UNDEFINED_METHOD_ENTRY_P(ci->me)) {
+			ci->me = 0;
+			goto start_method_dispatch;
+		    }
+		    else {
+			goto normal_method_dispatch;
+		    }
 		}
 		else {
 		    klass = ci->me->klass;
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 43333)
+++ test/ruby/test_refinement.rb	(revision 43334)
@@ -1059,6 +1059,54 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1059
     INPUT
   end
 
+  def test_refine_undefed_method_and_call
+    assert_in_out_err([], <<-INPUT, ["NoMethodError"], [])
+      class Foo
+        def foo
+        end
+
+        undef foo
+      end
+
+      module FooExt
+        refine Foo do
+          def foo
+          end
+        end
+      end
+
+      begin
+        Foo.new.foo
+      rescue => e
+        p e.class
+      end
+    INPUT
+  end
+
+  def test_refine_undefed_method_and_send
+    assert_in_out_err([], <<-INPUT, ["NoMethodError"], [])
+      class Foo
+        def foo
+        end
+
+        undef foo
+      end
+
+      module FooExt
+        refine Foo do
+          def foo
+          end
+        end
+      end
+
+      begin
+        Foo.new.send(:foo)
+      rescue => e
+        p e.class
+      end
+    INPUT
+  end
+
   private
 
   def eval_using(mod, s)

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

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