mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e9fa3108f1
commit
787cdae5df
4 changed files with 22 additions and 3 deletions
|
@ -1,4 +1,10 @@
|
|||
Tue Apr 30 12:30:18 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Tue Apr 30 12:31:40 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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.
|
||||
|
|
4
proc.c
4
proc.c
|
@ -2000,13 +2000,13 @@ method_inspect(VALUE method)
|
|||
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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'test/unit'
|
||||
require_relative 'envutil'
|
||||
|
||||
class TestProc < Test::Unit::TestCase
|
||||
def setup
|
||||
|
@ -1157,4 +1158,14 @@ class TestProc < Test::Unit::TestCase
|
|||
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
|
||||
|
|
2
vm.c
2
vm.c
|
@ -2258,6 +2258,8 @@ Init_VM(void)
|
|||
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;
|
||||
|
|
Loading…
Reference in a new issue