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

ruby-changes:28476

From: nobu <ko1@a...>
Date: Tue, 30 Apr 2013 12:31:54 +0900 (JST)
Subject: [ruby-changes:28476] nobu:r40528 (trunk): proc.c: frozen core methods

nobu	2013-04-30 12:31:43 +0900 (Tue, 30 Apr 2013)

  New Revision: 40528

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

  Log:
    proc.c: frozen core methods
    
    * proc.c (mproc, mlambda): use frozen core methods instead of plain
      global methods, so that methods cannot be overridden.
      [ruby-core:54687] [Bug #8345]
    * vm.c (Init_VM): define proc and lambda on the frozen core object.

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_proc.rb
    trunk/vm.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40527)
+++ ChangeLog	(revision 40528)
@@ -1,4 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Tue Apr 30 12:30:18 2013  Nobuyoshi Nakada  <nobu@r...>
+Tue Apr 30 12:31:40 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (mproc, mlambda): use frozen core methods instead of plain
+	  global methods, so that methods cannot be overridden.
+	  [ruby-core:54687] [Bug #8345]
+
+	* vm.c (Init_VM): define proc and lambda on the frozen core object.
 
 	* include/ruby/intern.h (rb_block_lambda): add declaration instead of
 	  deprecated rb_f_lambda.
Index: proc.c
===================================================================
--- proc.c	(revision 40527)
+++ proc.c	(revision 40528)
@@ -2000,13 +2000,13 @@ method_inspect(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2000
 static VALUE
 mproc(VALUE method)
 {
-    return rb_funcall(Qnil, rb_intern("proc"), 0);
+    return rb_funcall2(rb_mRubyVMFrozenCore, rb_intern("proc"), 0, 0);
 }
 
 static VALUE
 mlambda(VALUE method)
 {
-    return rb_funcall(Qnil, rb_intern("lambda"), 0);
+    return rb_funcall(rb_mRubyVMFrozenCore, rb_intern("lambda"), 0, 0);
 }
 
 static VALUE
Index: vm.c
===================================================================
--- vm.c	(revision 40527)
+++ vm.c	(revision 40528)
@@ -2258,6 +2258,8 @@ Init_VM(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L2258
     rb_define_method_id(klass, id_core_hash_merge_ary, m_core_hash_merge_ary, 2);
     rb_define_method_id(klass, id_core_hash_merge_ptr, m_core_hash_merge_ptr, -1);
     rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, 2);
+    rb_define_method(klass, "proc", rb_block_proc, 0);
+    rb_define_method(klass, "lambda", rb_block_lambda, 0);
     rb_obj_freeze(fcore);
     rb_gc_register_mark_object(fcore);
     rb_mRubyVMFrozenCore = fcore;
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 40527)
+++ test/ruby/test_proc.rb	(revision 40528)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1
 require 'test/unit'
+require_relative 'envutil'
 
 class TestProc < Test::Unit::TestCase
   def setup
@@ -1157,4 +1158,14 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1158
       assert_equal('zot', o.method(:foo).to_proc.() {'zot'}, bug3792)
     }
   end
+
+  def test_overriden_lambda
+    bug8345 = '[ruby-core:54687] [Bug #8345]'
+    assert_normal_exit('def lambda; end; method(:puts).to_proc', bug8345)
+  end
+
+  def test_overriden_proc
+    bug8345 = '[ruby-core:54688] [Bug #8345]'
+    assert_normal_exit('def proc; end; ->{}.curry', bug8345)
+  end
 end

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

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