Skip to content

Commit 1135cc3

Browse files
committed
merge revision(s) 41019,41020,41021,41041,41045,41057: [Backport ruby#8463]
vm_insnhelper.c: add comments * vm_insnhelper.c (vm_yield_setup_block_args): break a long line and add comments. remove useless code. * vm_insnhelper.c (vm_yield_setup_block_args): split single parameter if any keyword arguments exist, and then extract keyword arguments. [ruby-core:55203] [Bug ruby#8463] * compile.c (iseq_set_arguments): not a simple single argument if any keyword arguments exist. [ruby-core:55203] [Bug ruby#8463] * vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019. The code is not useless. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@41262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 63bc35f commit 1135cc3

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Wed Jun 12 23:41:21 2013 NARUSE, Yui <[email protected]>
2+
3+
* vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019.
4+
The code is not useless.
5+
6+
Wed Jun 12 23:41:21 2013 Nobuyoshi Nakada <[email protected]>
7+
8+
* vm_insnhelper.c (vm_yield_setup_block_args): split single parameter
9+
if any keyword arguments exist, and then extract keyword arguments.
10+
[ruby-core:55203] [Bug #8463]
11+
112
Wed Jun 12 23:05:41 2013 Nobuyoshi Nakada <[email protected]>
213

314
* io.c (io_getc): fix 7bit coderange condition, check if ascii read

compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,8 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
12641264
}
12651265

12661266
if (iseq->type == ISEQ_TYPE_BLOCK) {
1267-
if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 && iseq->arg_rest == -1) {
1267+
if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 &&
1268+
iseq->arg_rest == -1 && iseq->arg_keyword == -1) {
12681269
if (iseq->argc == 1 && last_comma == 0) {
12691270
/* {|a|} */
12701271
iseq->arg_simple |= 0x02;

test/ruby/test_keyword.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,16 @@ def rest_keyrest(*args, **opt)
263263

264264
def test_rest_keyrest
265265
bug7665 = '[ruby-core:51278]'
266+
bug8463 = '[ruby-core:55203] [Bug #8463]'
266267
expect = [*%w[foo bar], {zzz: 42}]
267268
assert_equal(expect, rest_keyrest(*expect), bug7665)
268-
assert_equal(expect, proc {|*args, **opt| next *args, opt}.call(*expect), bug7665)
269+
pr = proc {|*args, **opt| next *args, opt}
270+
assert_equal(expect, pr.call(*expect), bug7665)
271+
assert_equal(expect, pr.call(expect), bug8463)
272+
pr = proc {|a, *b, **opt| next a, *b, opt}
273+
assert_equal(expect, pr.call(expect), bug8463)
274+
pr = proc {|a, **opt| next a, opt}
275+
assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
269276
end
270277

271278
def test_bare_kwrest

test/ruby/test_yield.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,15 @@ def test_yield_enum
379379
}
380380
end
381381

382+
def test_block_with_mock
383+
y = Object.new
384+
def y.s(a)
385+
yield(a)
386+
end
387+
m = Object.new
388+
def m.method_missing(*a)
389+
super
390+
end
391+
assert_equal [m, nil], y.s(m){|a,b|[a,b]}
392+
end
382393
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.0.0"
22
#define RUBY_RELEASE_DATE "2013-06-12"
3-
#define RUBY_PATCHLEVEL 215
3+
#define RUBY_PATCHLEVEL 216
44

55
#define RUBY_RELEASE_YEAR 2013
66
#define RUBY_RELEASE_MONTH 6

vm_insnhelper.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,19 +2166,17 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
21662166

21672167
th->mark_stack_len = argc;
21682168

2169-
/* keyword argument */
2170-
if (iseq->arg_keyword != -1) {
2171-
argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
2172-
}
2173-
21742169
/*
21752170
* yield [1, 2]
21762171
* => {|a|} => a = [1, 2]
21772172
* => {|a, b|} => a, b = [1, 2]
21782173
*/
21792174
arg0 = argv[0];
21802175
if (!(iseq->arg_simple & 0x02) && /* exclude {|a|} */
2181-
((m + iseq->arg_post_len) > 0 || iseq->arg_opts > 2) && /* this process is meaningful */
2176+
((m + iseq->arg_post_len) > 0 || /* positional arguments exist */
2177+
iseq->arg_opts > 2 || /* multiple optional arguments exist */
2178+
iseq->arg_keyword != -1 || /* any keyword arguments */
2179+
0) &&
21822180
argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */
21832181
th->mark_stack_len = argc = RARRAY_LENINT(ary);
21842182

@@ -2187,9 +2185,20 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
21872185
MEMCPY(argv, RARRAY_PTR(ary), VALUE, argc);
21882186
}
21892187
else {
2188+
/* vm_push_frame current argv is at the top of sp because vm_invoke_block
2189+
* set sp at the first element of argv.
2190+
* Therefore when rb_check_array_type(arg0) called to_ary and called to_ary
2191+
* or method_missing run vm_push_frame, it initializes local variables.
2192+
* see also https://bugs.ruby-lang.org/issues/8484
2193+
*/
21902194
argv[0] = arg0;
21912195
}
21922196

2197+
/* keyword argument */
2198+
if (iseq->arg_keyword != -1) {
2199+
argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
2200+
}
2201+
21932202
for (i=argc; i<m; i++) {
21942203
argv[i] = Qnil;
21952204
}

0 commit comments

Comments
 (0)