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

ruby-changes:31064

From: nagachika <ko1@a...>
Date: Sat, 5 Oct 2013 02:13:21 +0900 (JST)
Subject: [ruby-changes:31064] nagachika:r43143 (ruby_2_0_0): merge revision(s) 43090, 43091: [Backport #8966]

nagachika	2013-10-05 02:13:11 +0900 (Sat, 05 Oct 2013)

  New Revision: 43143

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

  Log:
    merge revision(s) 43090,43091: [Backport #8966]
    
    * vm_method.c (rb_undef): raise a NameError if the original method
      of a refined method is not defined. 
    
    * vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV.
    
    * test/ruby/test_refinement.rb: related test.
      of a refined method is not defined.

  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_method.c
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 43142)
+++ ruby_2_0_0/ChangeLog	(revision 43143)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Sat Oct  5 01:59:50 2013  Shugo Maeda  <shugo@r...>
+
+	* vm_method.c (rb_undef): raise a NameError if the original method
+	  of a refined method is not defined.
+
+	* vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV.
+
+	* test/ruby/test_refinement.rb: related test.
+
 Sat Oct  5 00:16:33 2013  NARUSE, Yui  <naruse@r...>
 
 	* process.c (rb_daemon): daemon(3) is implemented with fork(2).
Index: ruby_2_0_0/vm_method.c
===================================================================
--- ruby_2_0_0/vm_method.c	(revision 43142)
+++ ruby_2_0_0/vm_method.c	(revision 43143)
@@ -852,7 +852,9 @@ rb_undef(VALUE klass, ID id) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_method.c#L852
 
     me = search_method(klass, id, 0);
 
-    if (UNDEFINED_METHOD_ENTRY_P(me)) {
+    if (UNDEFINED_METHOD_ENTRY_P(me) ||
+	(me->def->type == VM_METHOD_TYPE_REFINED &&
+	 UNDEFINED_METHOD_ENTRY_P(me->def->body.orig_me))) {
 	const char *s0 = " class";
 	VALUE c = klass;
 
@@ -1092,9 +1094,9 @@ rb_method_entry_eq(const rb_method_entry https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_method.c#L1094
 static int
 rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_definition_t *d2)
 {
-    if (d1 && d1->type == VM_METHOD_TYPE_REFINED)
+    if (d1 && d1->type == VM_METHOD_TYPE_REFINED && d1->body.orig_me)
 	d1 = d1->body.orig_me->def;
-    if (d2 && d2->type == VM_METHOD_TYPE_REFINED)
+    if (d2 && d2->type == VM_METHOD_TYPE_REFINED && d2->body.orig_me)
 	d2 = d2->body.orig_me->def;
     if (d1 == d2) return 1;
     if (!d1 || !d2) return 0;
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 43142)
+++ ruby_2_0_0/version.h	(revision 43143)
@@ -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-05"
-#define RUBY_PATCHLEVEL 324
+#define RUBY_PATCHLEVEL 325
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 10
Index: ruby_2_0_0/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_refinement.rb	(revision 43142)
+++ ruby_2_0_0/test/ruby/test_refinement.rb	(revision 43143)
@@ -827,7 +827,8 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_refinement.rb#L827
   end
 
   def test_case_dispatch_is_aware_of_refinements
-    assert_in_out_err([], <<-RUBY, ["refinement used"], ["-:2: warning: Refinements are experimental, and the behavior may change in future versions of Ruby!"])
+    assert_in_out_err([], <<-RUBY, ["refinement used"], [])
+      $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
       module RefineSymbol
         refine Symbol do
           def ===(other)
@@ -858,6 +859,52 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_refinement.rb#L859
     assert_not_send([FooSub, :method_defined?, :z])
   end
 
+  def test_undef_refined_method
+    bug8966 = '[ruby-core:57466] [Bug #8966]'
+
+    assert_in_out_err([], <<-INPUT, ["NameError"], [], bug8966)
+      $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
+      module Foo
+        refine Object do
+          def foo
+            puts "foo"
+          end
+        end
+      end
+
+      using Foo
+
+      class Object
+        begin
+          undef foo
+        rescue Exception => e
+          p e.class
+        end
+      end
+    INPUT
+
+    assert_in_out_err([], <<-INPUT, ["NameError"], [], bug8966)
+      $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
+      module Foo
+        refine Object do
+          def foo
+            puts "foo"
+          end
+        end
+      end
+
+      # without `using Foo'
+
+      class Object
+        begin
+          undef foo
+        rescue Exception => e
+          p e.class
+        end
+      end
+    INPUT
+  end
+
   private
 
   def eval_using(mod, s)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r43090-43091


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

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