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

ruby-changes:32852

From: shugo <ko1@a...>
Date: Thu, 13 Feb 2014 23:44:46 +0900 (JST)
Subject: [ruby-changes:32852] shugo:r44931 (trunk): * vm_insnhelper.c (vm_call_method): should check ci->me->flag of

shugo	2014-02-13 23:44:41 +0900 (Thu, 13 Feb 2014)

  New Revision: 44931

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

  Log:
    * vm_insnhelper.c (vm_call_method): should check ci->me->flag of
      a refining method in case the method is private.
      [ruby-core:60111] [Bug #9452]
    
    * vm_method.c (make_method_entry_refined): set me->flag of a refined
      method entry to NOEX_PUBLIC in case the original method is private
      and it is refined as a public method.  The original flag is stored
      in me->def->body.orig_me, so it's OK to make a refined method
      entry public.  [ruby-core:60111] [Bug #9452]
    
    * test/ruby/test_refinement.rb: related tests.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_refinement.rb
    trunk/vm_insnhelper.c
    trunk/vm_method.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44930)
+++ ChangeLog	(revision 44931)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb 13 23:30:30 2014  Shugo Maeda  <shugo@r...>
+
+	* vm_insnhelper.c (vm_call_method): should check ci->me->flag of
+	  a refining method in case the method is private.
+	  [ruby-core:60111] [Bug #9452]
+
+	* vm_method.c (make_method_entry_refined): set me->flag of a refined
+	  method entry to NOEX_PUBLIC in case the original method is private
+	  and it is refined as a public method.  The original flag is stored
+	  in me->def->body.orig_me, so it's OK to make a refined method
+	  entry public.  [ruby-core:60111] [Bug #9452]
+
+	* test/ruby/test_refinement.rb: related tests.
+
 Thu Feb 13 18:38:15 2014  Eric Wong  <e@8...>
 
 	* re.c (rb_reg_raise): remove volatile
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 44930)
+++ vm_method.c	(revision 44931)
@@ -217,6 +217,7 @@ make_method_entry_refined(rb_method_entr https://github.com/ruby/ruby/blob/trunk/vm_method.c#L217
     *new_def->body.orig_me = *me;
     rb_vm_check_redefinition_opt_method(me, me->klass);
     if (me->def) me->def->alias_count++;
+    me->flag = NOEX_WITH_SAFE(NOEX_PUBLIC);
     me->def = new_def;
 }
 
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 44930)
+++ vm_insnhelper.c	(revision 44931)
@@ -1829,7 +1829,7 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1829
 		    ci->me = me;
 		    ci->defined_class = defined_class;
 		    if (me->def->type != VM_METHOD_TYPE_REFINED) {
-			goto normal_method_dispatch;
+			goto start_method_dispatch;
 		    }
 		}
 
@@ -1838,11 +1838,8 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1838
 		    ci->me = ci->me->def->body.orig_me;
 		    if (UNDEFINED_METHOD_ENTRY_P(ci->me)) {
 			ci->me = 0;
-			goto start_method_dispatch;
-		    }
-		    else {
-			goto normal_method_dispatch;
 		    }
+		    goto start_method_dispatch;
 		}
 		else {
 		    klass = ci->me->klass;
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 44930)
+++ test/ruby/test_refinement.rb	(revision 44931)
@@ -1107,6 +1107,51 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1107
     INPUT
   end
 
+  def test_adding_private_method
+    bug9452 = '[ruby-core:60111] [Bug #9452]'
+
+    assert_in_out_err([], <<-INPUT, ["Success!", "NoMethodError"], [], bug9452)
+      module R
+        refine Object do
+          def m
+            puts "Success!"
+          end
+
+          private(:m)
+        end
+      end
+
+      using R
+
+      m
+      42.m rescue p($!.class)
+    INPUT
+  end
+
+  def test_making_private_method_public
+    bug9452 = '[ruby-core:60111] [Bug #9452]'
+
+    assert_in_out_err([], <<-INPUT, ["Success!", "Success!"], [], bug9452)
+        class Object
+          private
+          def m
+          end
+        end
+
+        module R
+          refine Object do
+            def m
+              puts "Success!"
+            end
+          end
+        end
+
+        using R
+        m
+        42.m
+    INPUT
+  end
+
   private
 
   def eval_using(mod, s)

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

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