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

ruby-changes:32331

From: naruse <ko1@a...>
Date: Wed, 25 Dec 2013 16:58:49 +0900 (JST)
Subject: [ruby-changes:32331] naruse:r44410 (ruby_2_1): merge revision(s) 44380: [Backport #9296]

naruse	2013-12-25 16:58:38 +0900 (Wed, 25 Dec 2013)

  New Revision: 44410

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

  Log:
    merge revision(s) 44380: [Backport #9296]
    
    * proc.c (rb_mod_define_method): consider visibility only if self
      in the caller is same as the receiver, otherwise make public as
      well as old behavior.  [ruby-core:57747] [Bug #9005]
      [ruby-core:58497] [Bug #9141]
    
    * vm.c (rb_vm_cref_in_context): return ruby level cref if self is
      same.

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/proc.c
    branches/ruby_2_1/test/ruby/test_method.rb
    branches/ruby_2_1/vm.c
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 44409)
+++ ruby_2_1/ChangeLog	(revision 44410)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Wed Dec 25 16:58:31 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (rb_mod_define_method): consider visibility only if self
+	  in the caller is same as the receiver, otherwise make public as
+	  well as old behavior.  [ruby-core:57747] [Bug #9005]
+	  [ruby-core:58497] [Bug #9141]
+
+	* vm.c (rb_vm_cref_in_context): return ruby level cref if self is
+	  same.
+
 Wed Dec 25 16:35:34 2013  Yusuke Endoh  <mame@t...>
 
 	* sample/trick2013/: added the award-winning entries of TRICK 2013.
Index: ruby_2_1/proc.c
===================================================================
--- ruby_2_1/proc.c	(revision 44409)
+++ ruby_2_1/proc.c	(revision 44410)
@@ -14,6 +14,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/proc.c#L14
 #include "gc.h"
 #include "iseq.h"
 
+NODE *rb_vm_cref_in_context(VALUE self);
+
 struct METHOD {
     VALUE recv;
     VALUE rclass;
@@ -1619,7 +1621,12 @@ rb_mod_define_method(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/ruby_2_1/proc.c#L1621
 {
     ID id;
     VALUE body;
-    int noex = (int)rb_vm_cref()->nd_visi;
+    int noex = NOEX_PUBLIC;
+    const NODE *cref = rb_vm_cref_in_context(mod);
+
+    if (cref && cref->nd_clss == mod) {
+	noex = (int)cref->nd_visi;
+    }
 
     if (argc == 1) {
 	id = rb_to_id(argv[0]);
Index: ruby_2_1/vm.c
===================================================================
--- ruby_2_1/vm.c	(revision 44409)
+++ ruby_2_1/vm.c	(revision 44410)
@@ -930,6 +930,15 @@ rb_vm_cref(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm.c#L930
     return rb_vm_get_cref(cfp->iseq, cfp->ep);
 }
 
+NODE *
+rb_vm_cref_in_context(VALUE self)
+{
+    rb_thread_t *th = GET_THREAD();
+    const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
+    if (cfp->self != self) return NULL;
+    return rb_vm_get_cref(cfp->iseq, cfp->ep);
+}
+
 #if 0
 void
 debug_cref(NODE *cref)
Index: ruby_2_1/test/ruby/test_method.rb
===================================================================
--- ruby_2_1/test/ruby/test_method.rb	(revision 44409)
+++ ruby_2_1/test/ruby/test_method.rb	(revision 44410)
@@ -338,6 +338,29 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_method.rb#L338
     assert_equal(true, m.private_method_defined?(:foo))
   end
 
+  def test_define_method_in_private_scope
+    bug9005 = '[ruby-core:57747] [Bug #9005]'
+    c = Class.new
+    class << c
+      public :define_method
+    end
+    TOPLEVEL_BINDING.eval("proc{|c|c.define_method(:x) {|*x|throw x}}").call(c)
+    o = c.new
+    assert_throw(bug9005) {o.x(bug9005)}
+  end
+
+  def test_singleton_define_method_in_private_scope
+    bug9141 = '[ruby-core:58497] [Bug #9141]'
+    o = Object.new
+    class << o
+      public :define_singleton_method
+    end
+    TOPLEVEL_BINDING.eval("proc{|o|o.define_singleton_method(:x) {|x|throw x}}").call(o)
+    assert_throw(bug9141) do
+      o.x(bug9141)
+    end
+  end
+
   def test_super_in_proc_from_define_method
     c1 = Class.new {
       def m

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44380


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

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