From 2e868a3442cec49813bab8a0be780cb42f79afcf Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 28 Oct 2009 04:20:35 +0000 Subject: [PATCH] * vm_insnhelper.c (vm_setup_method): should push call frame before raising exception, to put the Ruby-defined method name in the error message. [ruby-core:26333] * vm_insnhelper.c (VM_CALLEE_SETUP_ARG): macro modified. * vm_insnhelper.c (vm_yield_setup_args): modified for new VM_CALLEE_SETUP_ARG macro. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ vm_insnhelper.c | 33 ++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a96dea362c..13a29cc529 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,17 @@ Wed Oct 28 13:02:10 2009 Shugo Maeda * lib/net/ftp.rb (Net::FTP#login): calls send_type_command instead of binary=. +Wed Oct 28 12:26:51 2009 Yukihiro Matsumoto + + * vm_insnhelper.c (vm_setup_method): should push call frame before + raising exception, to put the Ruby-defined method name in the + error message. [ruby-core:26333] + + * vm_insnhelper.c (VM_CALLEE_SETUP_ARG): macro modified. + + * vm_insnhelper.c (vm_yield_setup_args): modified for new + VM_CALLEE_SETUP_ARG macro. + Tue Oct 27 22:46:44 2009 NARUSE, Yui * lib/net/ftp.rb (Net::FTP#initialize): @sock = nil. diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 25b0d5b3b2..5b965d2157 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -98,22 +98,23 @@ vm_pop_frame(rb_thread_t *th) /* method dispatch */ -#define VM_CALLEE_SETUP_ARG(ret, th, iseq, orig_argc, orig_argv, block) \ +#define VM_CALLEE_SETUP_ARG(ret, th, iseq, orig_argc, orig_argv, block, e) \ if (LIKELY(iseq->arg_simple & 0x01)) { \ /* simple check */ \ - if (orig_argc != iseq->argc) { \ - rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", orig_argc, iseq->argc); \ - } \ + e = -1; \ ret = 0; \ + if (orig_argc != iseq->argc) { \ + e = iseq->argc; \ + } \ } \ else { \ - ret = vm_callee_setup_arg_complex(th, iseq, orig_argc, orig_argv, block); \ + ret = vm_callee_setup_arg_complex(th, iseq, orig_argc, orig_argv, block, &e); \ } static inline int vm_callee_setup_arg_complex(rb_thread_t *th, const rb_iseq_t * iseq, int orig_argc, VALUE * orig_argv, - const rb_block_t **block) + const rb_block_t **block, int *argerr) { const int m = iseq->argc; int argc = orig_argc; @@ -124,8 +125,11 @@ vm_callee_setup_arg_complex(rb_thread_t *th, const rb_iseq_t * iseq, /* mandatory */ if (argc < (m + iseq->arg_post_len)) { /* check with post arg */ - rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", - argc, m + iseq->arg_post_len); + *argerr = m + iseq->arg_post_len; + return 0; + } + else { + *argerr = -1; } argv += m; @@ -443,8 +447,9 @@ vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, int opt_pc, i; VALUE *sp, *rsp = cfp->sp - argc; rb_iseq_t *iseq = me->def->body.iseq; + int eargc = 0; - VM_CALLEE_SETUP_ARG(opt_pc, th, iseq, argc, rsp, &blockptr); + VM_CALLEE_SETUP_ARG(opt_pc, th, iseq, argc, rsp, &blockptr, eargc); /* stack overflow check */ CHECK_STACK_OVERFLOW(cfp, iseq->stack_max); @@ -487,6 +492,9 @@ vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, VM_FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, iseq->iseq_encoded + opt_pc, sp, 0, 0); } + if (eargc >= 0) { + rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, eargc); + } } static inline VALUE @@ -886,8 +894,11 @@ vm_yield_setup_args(rb_thread_t * const th, const rb_iseq_t *iseq, if (lambda) { /* call as method */ - int opt_pc; - VM_CALLEE_SETUP_ARG(opt_pc, th, iseq, argc, argv, &blockptr); + int opt_pc, e; + VM_CALLEE_SETUP_ARG(opt_pc, th, iseq, argc, argv, &blockptr, e); + if (e >= 0) { + rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, e); + } return opt_pc; } else {