From cd3f980ea2652b169bbeede8b9135066ac656978 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 18 Dec 2010 07:02:35 +0000 Subject: [PATCH] * compile.c (setup_args), vm.c (invoke_block_from_c), vm_insnhelper.c (caller_setup_args): fix of r30241. lambda block shoud check argument number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ compile.c | 1 + test/ruby/test_lambda.rb | 1 + vm.c | 5 ++++- vm_core.h | 1 + vm_insnhelper.c | 2 +- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 915129e9e4..1495ed9f1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Dec 18 16:02:27 2010 Nobuyoshi Nakada + + * compile.c (setup_args), vm.c (invoke_block_from_c), + vm_insnhelper.c (caller_setup_args): fix of r30241. lambda block + shoud check argument number. + Sat Dec 18 14:42:29 2010 Tanaka Akira * load.c: parenthesize macro arguments. diff --git a/compile.c b/compile.c index a623e05b8b..fb524011d5 100644 --- a/compile.c +++ b/compile.c @@ -2899,6 +2899,7 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, VALUE *flag, VALUE *b if (block && nd_type(argn->nd_body) == NODE_LAMBDA) { NODE *lambda = argn->nd_body; *block = NEW_CHILD_ISEQVAL(lambda->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, nd_line(lambda)); + *flag |= VM_CALL_BLOCK_LAMBDA_BIT; } else { COMPILE(arg_block, "block", argn->nd_body); diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb index 241042d2c7..6cbdd64385 100644 --- a/test/ruby/test_lambda.rb +++ b/test/ruby/test_lambda.rb @@ -29,6 +29,7 @@ __END__ a = 0 2.times(&->(_){ a += 1 }) assert_equal(a, 2) + assert_raise(ArgumentError) {1.times(&->(){ a += 1 })} end def test_call_rest_args diff --git a/vm.c b/vm.c index 015456bd93..098842e2bf 100644 --- a/vm.c +++ b/vm.c @@ -531,7 +531,10 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block, const rb_control_frame_t *cfp; rb_control_frame_t *ncfp; int i, opt_pc, arg_size = iseq->arg_size; - int type = block_proc_is_lambda(block->proc) ? + int type = + block->proc == Qtrue ? VM_FRAME_MAGIC_LAMBDA : + block->proc == Qfalse ? VM_FRAME_MAGIC_BLOCK : + block_proc_is_lambda(block->proc) ? VM_FRAME_MAGIC_LAMBDA : VM_FRAME_MAGIC_BLOCK; rb_vm_set_finish_env(th); diff --git a/vm_core.h b/vm_core.h index c1886a56d4..bfd00089f2 100644 --- a/vm_core.h +++ b/vm_core.h @@ -550,6 +550,7 @@ typedef struct { #define VM_CALL_TAILRECURSION_BIT (0x01 << 6) #define VM_CALL_SUPER_BIT (0x01 << 7) #define VM_CALL_OPT_SEND_BIT (0x01 << 8) +#define VM_CALL_BLOCK_LAMBDA_BIT (0x01 << 9) enum vm_special_object_type { VM_SPECIAL_OBJECT_VMCORE = 1, diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 46449df7b1..5405d2a857 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -265,7 +265,7 @@ caller_setup_args(const rb_thread_t *th, rb_control_frame_t *cfp, VALUE flag, else if (blockiseq) { blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp); blockptr->iseq = blockiseq; - blockptr->proc = 0; + blockptr->proc = (flag & VM_CALL_BLOCK_LAMBDA_BIT) ? Qtrue : Qfalse; *block = blockptr; } }