ruby-changes:43532
From: shugo <ko1@a...>
Date: Thu, 7 Jul 2016 20:08:58 +0900 (JST)
Subject: [ruby-changes:43532] shugo:r55605 (trunk): * vm_args.c (vm_caller_setup_arg_block): disable symbol block
shugo 2016-07-07 20:08:52 +0900 (Thu, 07 Jul 2016) New Revision: 55605 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55605 Log: * vm_args.c (vm_caller_setup_arg_block): disable symbol block argument optimization when tail call optimization is enabled, in order to avoid SEGV. [ruby-core:76288] [Bug #12565] Modified files: trunk/ChangeLog trunk/test/ruby/test_optimization.rb trunk/vm_args.c Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 55604) +++ test/ruby/test_optimization.rb (revision 55605) @@ -301,6 +301,21 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L301 assert_equal("should be rescued", result.message, bug12082) end + def test_tailcall_symbol_block_arg + bug12565 = '[ruby-core:46065]' + tailcall(<<-EOF) + def apply_one_and_two(&block) + yield(1, 2) + end + + def add_one_and_two + apply_one_and_two(&:+) + end + EOF + assert_equal(3, add_one_and_two, + message(bug12565) {disasm(:add_one_and_two)}) + end + class Bug10557 def [](_) block_given? Index: vm_args.c =================================================================== --- vm_args.c (revision 55604) +++ vm_args.c (revision 55605) @@ -778,7 +778,8 @@ vm_caller_setup_arg_block(const rb_threa https://github.com/ruby/ruby/blob/trunk/vm_args.c#L778 if (NIL_P(proc)) { calling->blockptr = NULL; } - else if (SYMBOL_P(proc) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) { + else if (LIKELY(!(ci->flag & VM_CALL_TAILCALL)) && SYMBOL_P(proc) && + rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) { calling->blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp); calling->blockptr->iseq = (rb_iseq_t *)proc; calling->blockptr->proc = proc; Index: ChangeLog =================================================================== --- ChangeLog (revision 55604) +++ ChangeLog (revision 55605) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jul 7 20:08:37 2016 Shugo Maeda <shugo@r...> + + * vm_args.c (vm_caller_setup_arg_block): disable symbol block + argument optimization when tail call optimization is enabled, + in order to avoid SEGV. [ruby-core:76288] [Bug #12565] + Thu Jul 7 16:37:53 2016 Nobuyoshi Nakada <nobu@r...> * numeric.c (flo_round): [EXPERIMENTAL] adjust the case that the -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/