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
This commit is contained in:
nobu 2014-07-10 06:02:54 +00:00
Родитель 01bced94a9
Коммит 813ad48975
3 изменённых файлов: 28 добавлений и 3 удалений

Просмотреть файл

@ -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().

Просмотреть файл

@ -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{

Просмотреть файл

@ -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++) {