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

ruby-changes:31266

From: nagachika <ko1@a...>
Date: Fri, 18 Oct 2013 02:34:29 +0900 (JST)
Subject: [ruby-changes:31266] nagachika:r43345 (ruby_2_0_0): merge revision(s) 43334: [Backport #9030]

nagachika	2013-10-18 02:34:22 +0900 (Fri, 18 Oct 2013)

  New Revision: 43345

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

  Log:
    merge revision(s) 43334: [Backport #9030]
    
    * 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 directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/test/ruby/test_refinement.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/vm_insnhelper.c
    branches/ruby_2_0_0/vm_method.c
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 43344)
+++ ruby_2_0_0/ChangeLog	(revision 43345)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Fri Oct 18 02:10: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.
+
 Fri Oct 18 02:05:45 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/file.c (rb_file_expand_path_internal): fix memory leaks at
Index: ruby_2_0_0/vm_method.c
===================================================================
--- ruby_2_0_0/vm_method.c	(revision 43344)
+++ ruby_2_0_0/vm_method.c	(revision 43345)
@@ -640,7 +640,12 @@ rb_method_entry_without_refinements(VALU https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_method.c#L640
     }
     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: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 43344)
+++ ruby_2_0_0/version.h	(revision 43345)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-10-18"
-#define RUBY_PATCHLEVEL 336
+#define RUBY_PATCHLEVEL 337
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 10
Index: ruby_2_0_0/vm_insnhelper.c
===================================================================
--- ruby_2_0_0/vm_insnhelper.c	(revision 43344)
+++ ruby_2_0_0/vm_insnhelper.c	(revision 43345)
@@ -1840,7 +1840,13 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L1840
 	      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: ruby_2_0_0/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_refinement.rb	(revision 43344)
+++ ruby_2_0_0/test/ruby/test_refinement.rb	(revision 43345)
@@ -905,6 +905,56 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_refinement.rb#L905
     INPUT
   end
 
+  def test_refine_undefed_method_and_call
+    assert_in_out_err([], <<-INPUT, ["NoMethodError"], [])
+      $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
+      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"], [])
+      $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
+      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)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r43334


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

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