diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-26 07:51:04 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-26 07:51:04 +0000 |
commit | f8665e42f01f5caff4cb90e1ba0893a8518d521f (patch) | |
tree | e7994866dfc9937de8e77fd306b98f5e44e7b1b0 | |
parent | 7e88248f7dfc639492df59bb3b251bfb4163c996 (diff) |
merge revision(s) 40525,40526,40528,40530: [Backport #8345]
proc.c: remove unnecessary static function
* proc.c (proc_lambda): remove and use rb_block_lambda directly
instead.
* include/ruby/intern.h (rb_block_lambda): add declaration instead of
deprecated rb_f_lambda.
* 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.
* defs/id.def (predefined): add "idProc".
* proc.c (mnew, mproc, mlambda): use predefined IDs.
* vm.c (Init_VM): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@41649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | id.c | 1 | ||||
-rw-r--r-- | include/ruby/intern.h | 2 | ||||
-rw-r--r-- | proc.c | 28 | ||||
-rw-r--r-- | template/id.h.tmpl | 2 | ||||
-rw-r--r-- | test/ruby/test_proc.rb | 11 | ||||
-rw-r--r-- | version.h | 2 | ||||
-rw-r--r-- | vm.c | 2 |
8 files changed, 42 insertions, 19 deletions
@@ -1,3 +1,16 @@ +Wed Jun 26 16:36:39 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * defs/id.def (predefined): add "idProc". + + * proc.c (mnew, mproc, mlambda): use predefined IDs. + + * vm.c (Init_VM): ditto. + +Wed Jun 26 16:36:39 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * include/ruby/intern.h (rb_block_lambda): add declaration instead of + deprecated rb_f_lambda. + Wed Jun 26 16:31:49 2013 Shugo Maeda <shugo@ruby-lang.org> * lib/net/imap.rb (capability_response): should ignore trailing @@ -35,6 +35,7 @@ Init_id(void) REGISTER_SYMID(idEach, "each"); REGISTER_SYMID(idLength, "length"); REGISTER_SYMID(idSize, "size"); + REGISTER_SYMID(idProc, "proc"); REGISTER_SYMID(idLambda, "lambda"); REGISTER_SYMID(idIntern, "intern"); REGISTER_SYMID(idGets, "gets"); diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 32ce0ef951..98ef95230f 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -350,7 +350,7 @@ VALUE rb_require_safe(VALUE, int); void rb_obj_call_init(VALUE, int, VALUE*); VALUE rb_class_new_instance(int, VALUE*, VALUE); VALUE rb_block_proc(void); -VALUE rb_f_lambda(void); +VALUE rb_block_lambda(void); VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE); VALUE rb_obj_is_proc(VALUE); VALUE rb_proc_call(VALUE, VALUE); @@ -465,6 +465,14 @@ rb_block_proc(void) return proc_new(rb_cProc, FALSE); } +/* + * call-seq: + * lambda { |...| block } -> a_proc + * + * Equivalent to <code>Proc.new</code>, except the resulting Proc objects + * check the number of parameters passed when called. + */ + VALUE rb_block_lambda(void) { @@ -478,20 +486,6 @@ rb_f_lambda(void) return rb_block_lambda(); } -/* - * call-seq: - * lambda { |...| block } -> a_proc - * - * Equivalent to <code>Proc.new</code>, except the resulting Proc objects - * check the number of parameters passed when called. - */ - -static VALUE -proc_lambda(void) -{ - return rb_block_lambda(); -} - /* Document-method: === * * call-seq: @@ -1798,13 +1792,13 @@ method_inspect(VALUE method) static VALUE mproc(VALUE method) { - return rb_funcall(Qnil, rb_intern("proc"), 0); + return rb_funcall2(rb_mRubyVMFrozenCore, idProc, 0, 0); } static VALUE mlambda(VALUE method) { - return rb_funcall(Qnil, rb_intern("lambda"), 0); + return rb_funcall(rb_mRubyVMFrozenCore, idLambda, 0, 0); } static VALUE @@ -2151,7 +2145,7 @@ Init_Proc(void) /* utility functions */ rb_define_global_function("proc", rb_block_proc, 0); - rb_define_global_function("lambda", proc_lambda, 0); + rb_define_global_function("lambda", rb_block_lambda, 0); /* Method */ rb_cMethod = rb_define_class("Method", rb_cObject); diff --git a/template/id.h.tmpl b/template/id.h.tmpl index 5ad91452ec..ae30cf98a0 100644 --- a/template/id.h.tmpl +++ b/template/id.h.tmpl @@ -98,6 +98,7 @@ enum ruby_method_ids { tGets, tSucc, tEach, + tProc, tLambda, tSend, t__send__, @@ -120,6 +121,7 @@ enum ruby_method_ids { TOKEN2ID(Gets), TOKEN2ID(Succ), TOKEN2ID(Each), + TOKEN2ID(Proc), TOKEN2ID(Lambda), TOKEN2ID(Send), TOKEN2ID(__send__), diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 3cac94a100..31180bab8f 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestProc < Test::Unit::TestCase def setup @@ -818,4 +819,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 @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 440 +#define RUBY_PATCHLEVEL 441 #define RUBY_RELEASE_DATE "2013-06-26" #define RUBY_RELEASE_YEAR 2013 @@ -2109,6 +2109,8 @@ Init_VM(void) rb_define_method_id(klass, id_core_define_method, m_core_define_method, 3); rb_define_method_id(klass, id_core_define_singleton_method, m_core_define_singleton_method, 3); rb_define_method_id(klass, id_core_set_postexe, m_core_set_postexe, 1); + rb_define_method_id(klass, idProc, rb_block_proc, 0); + rb_define_method_id(klass, idLambda, rb_block_lambda, 0); rb_obj_freeze(fcore); rb_gc_register_mark_object(fcore); rb_mRubyVMFrozenCore = fcore; |