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

ruby-changes:15689

From: ko1 <ko1@a...>
Date: Tue, 4 May 2010 12:52:58 +0900 (JST)
Subject: [ruby-changes:15689] Ruby:r27609 (trunk): * vm_insnhelper.c (argument_error): push correct backtrace.

ko1	2010-05-04 12:50:39 +0900 (Tue, 04 May 2010)

  New Revision: 27609

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

  Log:
    * vm_insnhelper.c (argument_error): push correct backtrace.
      Bug #2281 [ruby-core:26333]

  Modified files:
    trunk/ChangeLog
    trunk/vm_insnhelper.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27608)
+++ ChangeLog	(revision 27609)
@@ -1,3 +1,8 @@
+Tue May  4 12:46:09 2010  Koichi Sasada  <ko1@a...>
+
+	* vm_insnhelper.c (argument_error): push correct backtrace.
+	  Bug #2281 [ruby-core:26333]
+
 Tue May  4 12:38:40 2010  Tanaka Akira  <akr@f...>
 
 	* ext/socket/option.c (sockopt_inspect): use rb_str_cat2 and
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 27608)
+++ vm_insnhelper.c	(revision 27609)
@@ -102,11 +102,37 @@
 
 /* method dispatch */
 
+static void
+argument_error(const rb_iseq_t *iseq, int miss_argc, int correct_argc)
+{
+    VALUE mesg = rb_sprintf("wrong number of arguments (%d for %d)", miss_argc, correct_argc);
+    VALUE exc = rb_exc_new3(rb_eArgError, mesg);
+    VALUE bt = rb_make_backtrace();
+    VALUE err_line = 0;
+
+    if (iseq) {
+	int line_no = 1;
+	const char *name;
+
+	if (iseq->insn_info_size) {
+	    line_no = iseq->insn_info_table[0].line_no;
+	}
+
+	err_line = rb_sprintf("%s:%d:in `%s'",
+			      RSTRING_PTR(iseq->filename),
+			      line_no, RSTRING_PTR(iseq->name));
+	rb_funcall(bt, rb_intern("unshift"), 1, err_line);
+    }
+
+    rb_funcall(exc, rb_intern("set_backtrace"), 1, bt);
+    rb_exc_raise(exc);
+}
+
 #define VM_CALLEE_SETUP_ARG(ret, th, iseq, orig_argc, orig_argv, block) \
     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); \
+	    argument_error(iseq, orig_argc, iseq->argc); \
 	} \
 	ret = 0; \
     } \
@@ -128,8 +154,7 @@
 
     /* 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);
+	argument_error(iseq, argc, m + iseq->arg_post_len);
     }
 
     argv += m;
@@ -152,8 +177,7 @@
 	const int opts = iseq->arg_opts - 1 /* no opt */;
 
 	if (iseq->arg_rest == -1 && argc > opts) {
-	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
-		     orig_argc, m + opts + iseq->arg_post_len);
+	    argument_error(iseq, orig_argc, m + opts + iseq->arg_post_len);
 	}
 
 	if (argc > opts) {
@@ -183,8 +207,7 @@
 	const rb_block_t *blockptr = *block;
 
 	if (argc != 0) {
-	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
-		     orig_argc, m + iseq->arg_post_len);
+	    argument_error(iseq, orig_argc, m + iseq->arg_post_len);
 	}
 
 	if (blockptr) {

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

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