diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-10 06:02:54 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-10 06:02:54 +0000 |
commit | 813ad48975420867ccd1919972ba138f13c6f6e5 (patch) | |
tree | 9d0bf03a23e034f95c2940e8f2519af13fc9b419 | |
parent | 01bced94a91cda4c7d560b1f3f099099aa8c7930 (diff) | |
download | ruby-813ad48975420867ccd1919972ba138f13c6f6e5.tar.gz |
vm_insnhelper.c: fix implicit splat keyword argument
* vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack
pointer to get rid of overwriting splat arguments by arguments
for `to_hash` conversion. [ruby-core:63593] [Bug #10016]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/ruby/test_keyword.rb | 10 | ||||
-rw-r--r-- | vm_insnhelper.c | 15 |
3 files changed, 28 insertions, 3 deletions
@@ -1,3 +1,9 @@ +Thu Jul 10 15:02:55 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack + pointer to get rid of overwriting splat arguments by arguments + for `to_hash` conversion. [ruby-core:63593] [Bug #10016] + Thu Jul 10 01:09:57 2014 Koichi Sasada <ko1@atdot.net> * symbol.c: remove rb_gc_mark_symbols(). diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 68dd8a91cf..a7249381d8 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -463,6 +463,16 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal({a: 1, b: 2}, m1(**o, **o2) {|x| break x}, bug9898) end + def test_implicit_hash_conversion + bug10016 = '[ruby-core:63593] [Bug #10016]' + + o = Object.new + def o.to_hash() { k: 9 } end + assert_equal([1, 42, [], o, :key, {}, nil], f9(1, o)) + assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016) + assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016) + end + def test_gced_object_in_stack bug8964 = '[ruby-dev:47729] [Bug #8964]' assert_normal_exit %q{ diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 8cd9295d66..9d77b01a0f 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1075,10 +1075,15 @@ vm_caller_setup_args(const rb_thread_t *th, rb_control_frame_t *cfp, rb_call_inf } static inline int -vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd) +vm_callee_setup_keyword_arg(rb_thread_t *th, const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd) { VALUE keyword_hash = 0, orig_hash; int optional = iseq->arg_keywords - iseq->arg_keyword_required; + VALUE *const sp = th->cfp->sp; + const int mark_stack_len = th->mark_stack_len; + + th->cfp->sp += argc; + th->mark_stack_len -= argc; if (argc > m && !NIL_P(orig_hash = rb_check_hash_type(orig_argv[argc-1])) && @@ -1093,10 +1098,14 @@ vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_ rb_get_kwargs(keyword_hash, iseq->arg_keyword_table, iseq->arg_keyword_required, (iseq->arg_keyword_check ? optional : -1-optional), NULL); + if (!keyword_hash) { keyword_hash = rb_hash_new(); } + th->cfp->sp = sp; + th->mark_stack_len = mark_stack_len; + *kwd = keyword_hash; return argc; @@ -1120,7 +1129,7 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t /* keyword argument */ if (iseq->arg_keyword != -1) { - argc = vm_callee_setup_keyword_arg(iseq, argc, min, orig_argv, &keyword_hash); + argc = vm_callee_setup_keyword_arg(th, iseq, argc, min, orig_argv, &keyword_hash); } /* mandatory */ @@ -2242,7 +2251,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq, /* keyword argument */ if (iseq->arg_keyword != -1) { - argc = vm_callee_setup_keyword_arg(iseq, argc, min, argv, &keyword_hash); + argc = vm_callee_setup_keyword_arg(th, iseq, argc, min, argv, &keyword_hash); } for (i=argc; i<m; i++) { |