ruby-changes:29342
From: nagachika <ko1@a...>
Date: Wed, 19 Jun 2013 04:18:28 +0900 (JST)
Subject: [ruby-changes:29342] nagachika:r41394 (ruby_2_0_0): merge revision(s) 40525,40526,40528,40530: [Backport #8345]
nagachika 2013-06-19 04:18:15 +0900 (Wed, 19 Jun 2013) New Revision: 41394 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41394 Log: 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. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/defs/id.def branches/ruby_2_0_0/include/ruby/intern.h branches/ruby_2_0_0/proc.c branches/ruby_2_0_0/test/ruby/test_proc.rb branches/ruby_2_0_0/version.h branches/ruby_2_0_0/vm.c Index: ruby_2_0_0/defs/id.def =================================================================== --- ruby_2_0_0/defs/id.def (revision 41393) +++ ruby_2_0_0/defs/id.def (revision 41394) @@ -7,6 +7,7 @@ firstline, predefined = __LINE__+1, %[\ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/defs/id.def#L7 gets succ each + proc lambda send __send__ @@ -48,7 +49,10 @@ const_ids = [] https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/defs/id.def#L49 class_ids = [] names = {} predefined.split(/^/).each_with_index do |line, num| - next if /^#/ =~ line or (name, token = line.split; !name) + next if /^#/ =~ line + line.sub!(/\s+#.*/, '') + name, token = line.split + next unless name token ||= name if /#/ =~ token token = "_#{token.gsub(/\W+/, '_')}" Index: ruby_2_0_0/include/ruby/intern.h =================================================================== --- ruby_2_0_0/include/ruby/intern.h (revision 41393) +++ ruby_2_0_0/include/ruby/intern.h (revision 41394) @@ -382,7 +382,7 @@ VALUE rb_require_safe(VALUE, int); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/include/ruby/intern.h#L382 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); Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 41393) +++ ruby_2_0_0/ChangeLog (revision 41394) @@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Wed Jun 19 03:54:04 2013 Nobuyoshi Nakada <nobu@r...> + + * defs/id.def (predefined): add "idProc". + + * proc.c (mnew, mproc, mlambda): use predefined IDs. + + * vm.c (Init_VM): ditto. + +Wed Jun 19 03:54:04 2013 Nobuyoshi Nakada <nobu@r...> + + * include/ruby/intern.h (rb_block_lambda): add declaration instead of + deprecated rb_f_lambda. + Wed Jun 19 03:24:07 2013 Kazuki Tsujimoto <kazuki@c...> * include/ruby/ruby.h, vm_eval.c (rb_funcall_with_block): Index: ruby_2_0_0/proc.c =================================================================== --- ruby_2_0_0/proc.c (revision 41393) +++ ruby_2_0_0/proc.c (revision 41394) @@ -481,6 +481,14 @@ rb_block_proc(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L481 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) { @@ -494,20 +502,6 @@ rb_f_lambda(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L502 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: @@ -952,7 +946,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALU https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L946 again: me = rb_method_entry_without_refinements(klass, id, &defined_class); if (UNDEFINED_METHOD_ENTRY_P(me)) { - ID rmiss = rb_intern("respond_to_missing?"); + ID rmiss = idRespond_to_missing; VALUE sym = ID2SYM(id); if (obj != Qundef && !rb_method_basic_definition_p(klass, rmiss)) { @@ -1993,13 +1987,13 @@ method_inspect(VALUE method) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L1987 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 @@ -2339,7 +2333,7 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L2333 /* 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); Index: ruby_2_0_0/vm.c =================================================================== --- ruby_2_0_0/vm.c (revision 41393) +++ ruby_2_0_0/vm.c (revision 41394) @@ -2260,6 +2260,8 @@ Init_VM(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm.c#L2260 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_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; Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 41393) +++ ruby_2_0_0/version.h (revision 41394) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-06-19" -#define RUBY_PATCHLEVEL 231 +#define RUBY_PATCHLEVEL 232 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_0_0/test/ruby/test_proc.rb =================================================================== --- ruby_2_0_0/test/ruby/test_proc.rb (revision 41393) +++ ruby_2_0_0/test/ruby/test_proc.rb (revision 41394) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_proc.rb#L1 require 'test/unit' +require_relative 'envutil' class TestProc < Test::Unit::TestCase def setup @@ -1196,4 +1197,14 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_proc.rb#L1197 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 Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r40525-40526,40528,40530 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/