1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

vm_insnhelper.c: keyrest should not overwrite rest arg

* vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args):
  set keyrest hash after making rest array, so that the last element
  will not be overwritten.  [ruby-core:51278] [Bug #7665]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-01-07 03:09:28 +00:00
parent 04d244642d
commit 8f1be27017
3 changed files with 36 additions and 7 deletions

View file

@ -1,3 +1,9 @@
Mon Jan 7 12:09:24 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args):
set keyrest hash after making rest array, so that the last element
will not be overwritten. [ruby-core:51278] [Bug #7665]
Mon Jan 7 09:37:24 2013 Koichi Sasada <ko1@atdot.net>
* NEWS: add a NEWS entry about RubyVM.

View file

@ -255,4 +255,15 @@ class TestKeywordArguments < Test::Unit::TestCase
assert_equal(["foo", 111111], m1(num: 111111, &blk))
assert_equal(["bar", 111111], m1(str: "bar", num: 111111, &blk))
end
def rest_keyrest(*args, **opt)
return *args, opt
end
def test_rest_keyrest
bug7665 = '[ruby-core:51278]'
expect = [*%w[foo bar], {zzz: 42}]
assert_equal(expect, rest_keyrest(*expect), bug7665)
assert_equal(expect, proc {|*args, **opt| next *args, opt}.call(*expect), bug7665)
end
end

View file

@ -1065,13 +1065,13 @@ 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, VALUE *orig_argv)
vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, VALUE *orig_argv, VALUE *kwd)
{
VALUE keyword_hash = Qnil;
VALUE keyword_hash;
int i, j;
if (argc > 0) keyword_hash = rb_check_hash_type(orig_argv[argc-1]);
if (!NIL_P(keyword_hash)) {
if (argc > 0 &&
!NIL_P(keyword_hash = rb_check_hash_type(orig_argv[argc-1]))) {
argc--;
keyword_hash = rb_hash_dup(keyword_hash);
if (iseq->arg_keyword_check) {
@ -1087,7 +1087,7 @@ vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, VALUE *orig_argv)
keyword_hash = rb_hash_new();
}
orig_argv[iseq->arg_keyword] = keyword_hash;
*kwd = keyword_hash;
return argc;
}
@ -1102,13 +1102,14 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t
const int orig_argc = ci->argc;
int argc = orig_argc;
VALUE *argv = orig_argv;
VALUE keyword_hash = Qnil;
rb_num_t opt_pc = 0;
th->mark_stack_len = argc + iseq->arg_size;
/* keyword argument */
if (iseq->arg_keyword != -1) {
argc = vm_callee_setup_keyword_arg(iseq, argc, orig_argv);
argc = vm_callee_setup_keyword_arg(iseq, argc, orig_argv, &keyword_hash);
}
/* mandatory */
@ -1154,6 +1155,11 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t
argc = 0;
}
/* keyword argument */
if (iseq->arg_keyword != -1) {
orig_argv[iseq->arg_keyword] = keyword_hash;
}
/* block arguments */
if (iseq->arg_block != -1) {
VALUE blockval = Qnil;
@ -2088,13 +2094,14 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
int argc = orig_argc;
const int m = iseq->argc;
VALUE ary, arg0;
VALUE keyword_hash = Qnil;
int opt_pc = 0;
th->mark_stack_len = argc;
/* keyword argument */
if (iseq->arg_keyword != -1) {
argc = vm_callee_setup_keyword_arg(iseq, argc, argv);
argc = vm_callee_setup_keyword_arg(iseq, argc, argv, &keyword_hash);
}
/*
@ -2155,6 +2162,11 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
th->mark_stack_len = iseq->arg_size;
}
/* keyword argument */
if (iseq->arg_keyword != -1) {
argv[iseq->arg_keyword] = keyword_hash;
}
/* {|&b|} */
if (iseq->arg_block != -1) {
VALUE procval = Qnil;