ruby-changes:31002
From: ktsj <ko1@a...>
Date: Sun, 29 Sep 2013 18:50:29 +0900 (JST)
Subject: [ruby-changes:31002] ktsj:r43081 (trunk): * vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args):
ktsj 2013-09-29 18:50:24 +0900 (Sun, 29 Sep 2013) New Revision: 43081 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43081 Log: * vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args): clear keyword arguments to prevent GC bug which occurs while marking VM stack. [ruby-dev:47729] [Bug #8964] * test/ruby/test_keyword.rb: tests for the above. Modified files: trunk/ChangeLog trunk/test/ruby/test_keyword.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43080) +++ ChangeLog (revision 43081) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Sep 29 18:45:05 2013 Kazuki Tsujimoto <kazuki@c...> + + * vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args): + clear keyword arguments to prevent GC bug which occurs + while marking VM stack. + [ruby-dev:47729] [Bug #8964] + + * test/ruby/test_keyword.rb: tests for the above. + Sat Sep 28 23:25:56 2013 Nobuyoshi Nakada <nobu@r...> * math.c (math_log, math_log2, math_log10): fix for Bignum argument. Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 43080) +++ vm_insnhelper.c (revision 43081) @@ -1226,6 +1226,11 @@ vm_callee_setup_arg_complex(rb_thread_t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1226 /* keyword argument */ if (iseq->arg_keyword != -1) { + int i; + int arg_keywords_end = iseq->arg_keyword - (iseq->arg_block != -1); + for (i = iseq->arg_keywords; 0 < i; i--) { + orig_argv[arg_keywords_end - i] = Qnil; + } orig_argv[iseq->arg_keyword] = keyword_hash; } @@ -2302,6 +2307,10 @@ vm_yield_setup_block_args(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2307 /* keyword argument */ if (iseq->arg_keyword != -1) { + int arg_keywords_end = iseq->arg_keyword - (iseq->arg_block != -1); + for (i = iseq->arg_keywords; 0 < i; i--) { + argv[arg_keywords_end - i] = Qnil; + } argv[iseq->arg_keyword] = keyword_hash; } Index: test/ruby/test_keyword.rb =================================================================== --- test/ruby/test_keyword.rb (revision 43080) +++ test/ruby/test_keyword.rb (revision 43081) @@ -396,4 +396,23 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L396 assert_equal([{}, {}], a.new.foo({})) assert_equal([{}, {:bar=>"x"}], a.new.foo({}, bar: "x")) end + + def test_gced_object_in_stack + bug8964 = '[ruby-dev:47729] [Bug #8964]' + assert_normal_exit %q{ + def m(a: []) + end + GC.stress = true + tap { m } + GC.start + tap { m } + }, bug8964 + assert_normal_exit %q{ + prc = Proc.new {|a: []|} + GC.stress = true + tap { prc.call } + GC.start + tap { prc.call } + }, bug8964 + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/