[前][次][番号順一覧][スレッド一覧]

ruby-changes:13729

From: matz <ko1@a...>
Date: Wed, 28 Oct 2009 13:20:50 +0900 (JST)
Subject: [ruby-changes:13729] Ruby:r25521 (trunk): * vm_insnhelper.c (vm_setup_method): should push call frame before

matz	2009-10-28 13:20:35 +0900 (Wed, 28 Oct 2009)

  New Revision: 25521

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25521

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/vm_insnhelper.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25520)
+++ ChangeLog	(revision 25521)
@@ -12,6 +12,17 @@
 	* lib/net/ftp.rb (Net::FTP#login): calls send_type_command instead
 	  of binary=.
 
+Wed Oct 28 12:26:51 2009  Yukihiro Matsumoto  <matz@r...>
+
+	* 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  <naruse@r...>
 
 	* lib/net/ftp.rb (Net::FTP#initialize): @sock = nil.
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 25520)
+++ vm_insnhelper.c	(revision 25521)
@@ -98,22 +98,23 @@
 
 /* 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 */ \
+        e = -1; \
+	ret = 0; \
 	if (orig_argc != iseq->argc) { \
-	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", orig_argc, iseq->argc); \
+            e = iseq->argc; \
 	} \
-	ret = 0; \
     } \
     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,9 +125,12 @@
 
     /* 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;
     argc -= m;
@@ -443,8 +447,9 @@
     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_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 @@
 
     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 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]