diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-12 15:03:22 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-12 15:03:22 +0000 |
commit | 1135cc3596e301495d2fa2230cd3411fd1f516a5 (patch) | |
tree | 81cc7c8957435771ea2b161e06c96534a11a32ee | |
parent | 63bc35ffb00b4231beeaae8f7c9b394c107cff92 (diff) |
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
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | compile.c | 3 | ||||
-rw-r--r-- | test/ruby/test_keyword.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_yield.rb | 11 | ||||
-rw-r--r-- | version.h | 2 | ||||
-rw-r--r-- | vm_insnhelper.c | 21 |
6 files changed, 48 insertions, 9 deletions
@@ -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> * 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->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) { /* {|a|} */ iseq->arg_simple |= 0x02; diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 05b3e06de1..8a00128605 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -263,9 +263,16 @@ class TestKeywordArguments < Test::Unit::TestCase def test_rest_keyrest bug7665 = '[ruby-core:51278]' + bug8463 = '[ruby-core:55203] [Bug #8463]' 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) + 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 def test_bare_kwrest diff --git a/test/ruby/test_yield.rb b/test/ruby/test_yield.rb index 3337aea078..143ee55a9f 100644 --- a/test/ruby/test_yield.rb +++ b/test/ruby/test_yield.rb @@ -379,4 +379,15 @@ class TestRubyYieldGen < Test::Unit::TestCase } 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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-06-12" -#define RUBY_PATCHLEVEL 215 +#define RUBY_PATCHLEVEL 216 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 6 diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 769e6c6c23..961d6f8daf 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2166,11 +2166,6 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq, 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] * => {|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]; 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 */ 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); } 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; } + /* 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++) { argv[i] = Qnil; } |