Skip to content

Commit 9967966

Browse files
committed
merge revision(s) r46775: [Backport ruby#10016]
* 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 ruby#10016] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 39b896c commit 9967966

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Mon Aug 11 22:14:28 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack
4+
pointer to get rid of overwriting splat arguments by arguments
5+
for `to_hash` conversion. [ruby-core:63593] [Bug #10016]
6+
17
Fri Aug 8 23:36:01 2014 Nobuyoshi Nakada <[email protected]>
28

39
* ext/stringio/stringio.c (strio_write): use rb_str_append to

test/ruby/test_keyword.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,16 @@ def o2.to_hash() { b: 2 } end
463463
assert_equal({a: 1, b: 2}, m1(**o, **o2) {|x| break x}, bug9898)
464464
end
465465

466+
def test_implicit_hash_conversion
467+
bug10016 = '[ruby-core:63593] [Bug #10016]'
468+
469+
o = Object.new
470+
def o.to_hash() { k: 9 } end
471+
assert_equal([1, 42, [], o, :key, {}, nil], f9(1, o))
472+
assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016)
473+
assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016)
474+
end
475+
466476
def test_gced_object_in_stack
467477
bug8964 = '[ruby-dev:47729] [Bug #8964]'
468478
assert_normal_exit %q{

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.2"
2-
#define RUBY_RELEASE_DATE "2014-08-08"
3-
#define RUBY_PATCHLEVEL 196
2+
#define RUBY_RELEASE_DATE "2014-08-11"
3+
#define RUBY_PATCHLEVEL 197
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 8
7-
#define RUBY_RELEASE_DAY 8
7+
#define RUBY_RELEASE_DAY 11
88

99
#include "ruby/version.h"
1010

vm_insnhelper.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,10 +1067,15 @@ vm_caller_setup_args(const rb_thread_t *th, rb_control_frame_t *cfp, rb_call_inf
10671067
}
10681068

10691069
static inline int
1070-
vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd)
1070+
vm_callee_setup_keyword_arg(rb_thread_t *th, const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd)
10711071
{
10721072
VALUE keyword_hash = 0, orig_hash;
10731073
int optional = iseq->arg_keywords - iseq->arg_keyword_required;
1074+
VALUE *const sp = th->cfp->sp;
1075+
const int mark_stack_len = th->mark_stack_len;
1076+
1077+
th->cfp->sp += argc;
1078+
th->mark_stack_len -= argc;
10741079

10751080
if (argc > m &&
10761081
!NIL_P(orig_hash = rb_check_hash_type(orig_argv[argc-1])) &&
@@ -1085,10 +1090,14 @@ vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_
10851090
rb_get_kwargs(keyword_hash, iseq->arg_keyword_table, iseq->arg_keyword_required,
10861091
(iseq->arg_keyword_check ? optional : -1-optional),
10871092
NULL);
1093+
10881094
if (!keyword_hash) {
10891095
keyword_hash = rb_hash_new();
10901096
}
10911097

1098+
th->cfp->sp = sp;
1099+
th->mark_stack_len = mark_stack_len;
1100+
10921101
*kwd = keyword_hash;
10931102

10941103
return argc;
@@ -1111,7 +1120,7 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t
11111120

11121121
/* keyword argument */
11131122
if (iseq->arg_keyword != -1) {
1114-
argc = vm_callee_setup_keyword_arg(iseq, argc, min, orig_argv, &keyword_hash);
1123+
argc = vm_callee_setup_keyword_arg(th, iseq, argc, min, orig_argv, &keyword_hash);
11151124
}
11161125

11171126
/* mandatory */
@@ -2212,7 +2221,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
22122221

22132222
/* keyword argument */
22142223
if (iseq->arg_keyword != -1) {
2215-
argc = vm_callee_setup_keyword_arg(iseq, argc, min, argv, &keyword_hash);
2224+
argc = vm_callee_setup_keyword_arg(th, iseq, argc, min, argv, &keyword_hash);
22162225
}
22172226

22182227
for (i=argc; i<m; i++) {

0 commit comments

Comments
 (0)