mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
merge revision(s) 41019,41020,41021,41041,41045,41057: [Backport #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 #8463] * compile.c (iseq_set_arguments): not a simple single argument if any keyword arguments exist. [ruby-core:55203] [Bug #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
This commit is contained in:
parent
63bc35ffb0
commit
1135cc3596
6 changed files with 48 additions and 9 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Wed Jun 12 23:41:21 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019.
|
||||||
|
The code is not useless.
|
||||||
|
|
||||||
|
Wed Jun 12 23:41:21 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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 #8463]
|
||||||
|
|
||||||
Wed Jun 12 23:05:41 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jun 12 23:05:41 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (io_getc): fix 7bit coderange condition, check if ascii read
|
* io.c (io_getc): fix 7bit coderange condition, check if ascii read
|
||||||
|
|
|
@ -1264,7 +1264,8 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iseq->type == ISEQ_TYPE_BLOCK) {
|
if (iseq->type == ISEQ_TYPE_BLOCK) {
|
||||||
if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 && iseq->arg_rest == -1) {
|
if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 &&
|
||||||
|
iseq->arg_rest == -1 && iseq->arg_keyword == -1) {
|
||||||
if (iseq->argc == 1 && last_comma == 0) {
|
if (iseq->argc == 1 && last_comma == 0) {
|
||||||
/* {|a|} */
|
/* {|a|} */
|
||||||
iseq->arg_simple |= 0x02;
|
iseq->arg_simple |= 0x02;
|
||||||
|
|
|
@ -263,9 +263,16 @@ class TestKeywordArguments < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_rest_keyrest
|
def test_rest_keyrest
|
||||||
bug7665 = '[ruby-core:51278]'
|
bug7665 = '[ruby-core:51278]'
|
||||||
|
bug8463 = '[ruby-core:55203] [Bug #8463]'
|
||||||
expect = [*%w[foo bar], {zzz: 42}]
|
expect = [*%w[foo bar], {zzz: 42}]
|
||||||
assert_equal(expect, rest_keyrest(*expect), bug7665)
|
assert_equal(expect, rest_keyrest(*expect), bug7665)
|
||||||
assert_equal(expect, proc {|*args, **opt| next *args, opt}.call(*expect), bug7665)
|
pr = proc {|*args, **opt| next *args, opt}
|
||||||
|
assert_equal(expect, pr.call(*expect), bug7665)
|
||||||
|
assert_equal(expect, pr.call(expect), bug8463)
|
||||||
|
pr = proc {|a, *b, **opt| next a, *b, opt}
|
||||||
|
assert_equal(expect, pr.call(expect), bug8463)
|
||||||
|
pr = proc {|a, **opt| next a, opt}
|
||||||
|
assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_bare_kwrest
|
def test_bare_kwrest
|
||||||
|
|
|
@ -379,4 +379,15 @@ class TestRubyYieldGen < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_block_with_mock
|
||||||
|
y = Object.new
|
||||||
|
def y.s(a)
|
||||||
|
yield(a)
|
||||||
|
end
|
||||||
|
m = Object.new
|
||||||
|
def m.method_missing(*a)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
assert_equal [m, nil], y.s(m){|a,b|[a,b]}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.0.0"
|
#define RUBY_VERSION "2.0.0"
|
||||||
#define RUBY_RELEASE_DATE "2013-06-12"
|
#define RUBY_RELEASE_DATE "2013-06-12"
|
||||||
#define RUBY_PATCHLEVEL 215
|
#define RUBY_PATCHLEVEL 216
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2013
|
#define RUBY_RELEASE_YEAR 2013
|
||||||
#define RUBY_RELEASE_MONTH 6
|
#define RUBY_RELEASE_MONTH 6
|
||||||
|
|
|
@ -2166,11 +2166,6 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
|
||||||
|
|
||||||
th->mark_stack_len = argc;
|
th->mark_stack_len = argc;
|
||||||
|
|
||||||
/* keyword argument */
|
|
||||||
if (iseq->arg_keyword != -1) {
|
|
||||||
argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* yield [1, 2]
|
* yield [1, 2]
|
||||||
* => {|a|} => a = [1, 2]
|
* => {|a|} => a = [1, 2]
|
||||||
|
@ -2178,7 +2173,10 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
|
||||||
*/
|
*/
|
||||||
arg0 = argv[0];
|
arg0 = argv[0];
|
||||||
if (!(iseq->arg_simple & 0x02) && /* exclude {|a|} */
|
if (!(iseq->arg_simple & 0x02) && /* exclude {|a|} */
|
||||||
((m + iseq->arg_post_len) > 0 || iseq->arg_opts > 2) && /* this process is meaningful */
|
((m + iseq->arg_post_len) > 0 || /* positional arguments exist */
|
||||||
|
iseq->arg_opts > 2 || /* multiple optional arguments exist */
|
||||||
|
iseq->arg_keyword != -1 || /* any keyword arguments */
|
||||||
|
0) &&
|
||||||
argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */
|
argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */
|
||||||
th->mark_stack_len = argc = RARRAY_LENINT(ary);
|
th->mark_stack_len = argc = RARRAY_LENINT(ary);
|
||||||
|
|
||||||
|
@ -2187,9 +2185,20 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
|
||||||
MEMCPY(argv, RARRAY_PTR(ary), VALUE, argc);
|
MEMCPY(argv, RARRAY_PTR(ary), VALUE, argc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* vm_push_frame current argv is at the top of sp because vm_invoke_block
|
||||||
|
* set sp at the first element of argv.
|
||||||
|
* Therefore when rb_check_array_type(arg0) called to_ary and called to_ary
|
||||||
|
* or method_missing run vm_push_frame, it initializes local variables.
|
||||||
|
* see also https://bugs.ruby-lang.org/issues/8484
|
||||||
|
*/
|
||||||
argv[0] = arg0;
|
argv[0] = arg0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* keyword argument */
|
||||||
|
if (iseq->arg_keyword != -1) {
|
||||||
|
argc = vm_callee_setup_keyword_arg(iseq, argc, m, argv, &keyword_hash);
|
||||||
|
}
|
||||||
|
|
||||||
for (i=argc; i<m; i++) {
|
for (i=argc; i<m; i++) {
|
||||||
argv[i] = Qnil;
|
argv[i] = Qnil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue