From fc466622fd220b1d907d86cdbc3f74acc11a58ca Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 16 Aug 2007 16:29:11 +0000 Subject: [PATCH] * compile.c (iseq_set_arguments), insnhelper.ci (vm_callee_setup_arg, vm_yield_setup_args): fix block parameter problems. [ruby-dev:31437], [ruby-dev:31440] * bootstraptest/test_block.rb: add a test of [ruby-dev:31440]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ bootstraptest/test_block.rb | 7 +++++++ compile.c | 12 +++++++----- insnhelper.ci | 4 ++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4df8fa1289..a65ba3871b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Aug 17 01:25:23 2007 Koichi Sasada + + * compile.c (iseq_set_arguments), insnhelper.ci + (vm_callee_setup_arg, vm_yield_setup_args): fix + block parameter problems. [ruby-dev:31437], [ruby-dev:31440] + + * bootstraptest/test_block.rb: add a test of [ruby-dev:31440]. + Fri Aug 17 01:24:12 2007 Koichi Sasada * iseq.c (ruby_iseq_disasm): fix to show arg_simple value. diff --git a/bootstraptest/test_block.rb b/bootstraptest/test_block.rb index e93539684e..1d6a610bc9 100644 --- a/bootstraptest/test_block.rb +++ b/bootstraptest/test_block.rb @@ -417,3 +417,10 @@ assert_equal '0', %q{ end m {|*,v| v}.inspect }, '[ruby-dev:31437]' +assert_equal '[0]', %q{ + def m + yield [0] + end + m{|v, &b| v}.inspect +}, '[ruby-dev:31440]' + diff --git a/compile.c b/compile.c index 52fae34d59..6f655c3bd4 100644 --- a/compile.c +++ b/compile.c @@ -881,7 +881,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args) /* set arg_size: size of arguments */ if (iseq->arg_block != -1) { iseq->arg_size = iseq->arg_block + 1; - } + } else if (iseq->arg_post_len) { iseq->arg_size = iseq->arg_post_start + iseq->arg_post_len; } @@ -891,7 +891,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args) else if (iseq->arg_opts) { iseq->arg_size = iseq->argc + iseq->arg_opts - 1; } - else { + else { iseq->arg_size = iseq->argc; } } @@ -901,9 +901,11 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args) } if (iseq->type == ISEQ_TYPE_BLOCK) { - if (iseq->argc == 1 && iseq->arg_simple == 1 && last_comma == 0) { - /* {|a|} */ - iseq->arg_simple = 2; + if (iseq->arg_opts == 0 && iseq->arg_post_len == 0 && iseq->arg_rest == -1) { + if (iseq->argc == 1 && last_comma == 0) { + /* {|a|} */ + iseq->arg_simple = 2; + } } } } diff --git a/insnhelper.ci b/insnhelper.ci index 1fda1e82fe..bb87a432a7 100644 --- a/insnhelper.ci +++ b/insnhelper.ci @@ -103,7 +103,7 @@ vm_callee_setup_arg(rb_thread_t *th, rb_iseq_t *iseq, const int m = iseq->argc; const int orig_argc = argc; - if (iseq->arg_simple) { + if (iseq->arg_simple == 1) { /* simple check */ if (argc != m) { rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", @@ -675,7 +675,7 @@ vm_yield_setup_args(rb_thread_t *th, rb_iseq_t *iseq, * => {|a|} => a = [1, 2] * => {|a, b|} => a, b = [1, 2] */ - if (iseq->arg_simple != 2 && m > 0 && argc == 1 && TYPE(argv[0]) == T_ARRAY) { + if (iseq->arg_simple != 2 && (m + iseq->arg_post_len) > 0 && argc == 1 && TYPE(argv[0]) == T_ARRAY) { VALUE ary = argv[0]; th->mark_stack_len = argc = RARRAY_LEN(ary);