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

ruby-changes:15979

From: mame <ko1@a...>
Date: Thu, 20 May 2010 22:08:10 +0900 (JST)
Subject: [ruby-changes:15979] Ruby:r27924 (trunk): * vm.c (vm_backtrace_each): now takes an init function to distinguish

mame	2010-05-20 22:07:58 +0900 (Thu, 20 May 2010)

  New Revision: 27924

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

  Log:
    * vm.c (vm_backtrace_each): now takes an init function to distinguish
      an empty stack from out of stack.  [ruby-dev:41366]
    
    * vm_eval.c (print_backtrace, rb_thread_backtrace): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/vm.c
    trunk/vm_eval.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27923)
+++ ChangeLog	(revision 27924)
@@ -1,3 +1,10 @@
+Thu May 20 22:04:05 2010  Yusuke Endoh  <mame@t...>
+
+	* vm.c (vm_backtrace_each): now takes an init function to distinguish
+	  an empty stack from out of stack.  [ruby-dev:41366]
+
+	* vm_eval.c (print_backtrace, rb_thread_backtrace): ditto.
+
 Thu May 20 20:47:46 2010  Masaki Suketa <masaki.suketa@n...>
 
 	* ext/win32ole/win32ole.c (ole_invoke): raise NoMethodError
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 27923)
+++ vm_eval.c	(revision 27924)
@@ -16,7 +16,7 @@
 static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref);
 static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
 static inline VALUE vm_backtrace(rb_thread_t *th, int lev);
-static int vm_backtrace_each(rb_thread_t *th, int lev, rb_backtrace_iter_func *iter, void *arg);
+static int vm_backtrace_each(rb_thread_t *th, int lev, void (*init)(void *), rb_backtrace_iter_func *iter, void *arg);
 static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr);
 static VALUE vm_exec(rb_thread_t *th);
 static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref);
@@ -1574,9 +1574,7 @@
     if (lev < 0)
 	rb_raise(rb_eArgError, "negative level (%d)", lev);
 
-    ary = vm_backtrace(GET_THREAD(), lev);
-    if (NIL_P(ary)) ary = rb_ary_new();
-    return ary;
+    return vm_backtrace(GET_THREAD(), lev);
 }
 
 static int
@@ -1598,7 +1596,7 @@
 void
 rb_backtrace(void)
 {
-    vm_backtrace_each(GET_THREAD(), -1, print_backtrace, stderr);
+    vm_backtrace_each(GET_THREAD(), -1, NULL, print_backtrace, stderr);
 }
 
 VALUE
@@ -1629,7 +1627,7 @@
 int
 rb_backtrace_each(rb_backtrace_iter_func *iter, void *arg)
 {
-    return vm_backtrace_each(GET_THREAD(), -1, iter, arg);
+    return vm_backtrace_each(GET_THREAD(), -1, NULL, iter, arg);
 }
 
 /*
Index: vm.c
===================================================================
--- vm.c	(revision 27923)
+++ vm.c	(revision 27924)
@@ -706,19 +706,20 @@
 }
 
 static int
-vm_backtrace_each(rb_thread_t *th, int lev, rb_backtrace_iter_func *iter, void *arg)
+vm_backtrace_each(rb_thread_t *th, int lev, void (*init)(void *), rb_backtrace_iter_func *iter, void *arg)
 {
     const rb_control_frame_t *limit_cfp = th->cfp;
     const rb_control_frame_t *cfp = (void *)(th->stack + th->stack_size);
-    VALUE file = Qnil;
+    VALUE file = Qnil, *aryp = arg;
     int line_no = 0;
 
     cfp -= 2;
     while (lev-- >= 0) {
-	if (++limit_cfp >= cfp) {
+	if (++limit_cfp > cfp) {
 	    return FALSE;
 	}
     }
+    if (init) (*init)(arg);
     limit_cfp = RUBY_VM_NEXT_CONTROL_FRAME(limit_cfp);
     if (th->vm->progname) file = th->vm->progname;
     while (cfp > limit_cfp) {
@@ -747,15 +748,19 @@
     return TRUE;
 }
 
+static void
+vm_backtrace_alloc(void *arg)
+{
+    VALUE *aryp = arg;
+    *aryp = rb_ary_new();
+}
+
 static int
 vm_backtrace_push(void *arg, VALUE file, int line_no, VALUE name)
 {
     VALUE *aryp = arg;
     VALUE bt;
 
-    if (!*aryp) {
-	*aryp = rb_ary_new();
-    }
     bt = rb_enc_sprintf(rb_enc_compatible(file, name), "%s:%d:in `%s'",
 			RSTRING_PTR(file), line_no, RSTRING_PTR(name));
     rb_ary_push(*aryp, bt);
@@ -770,7 +775,7 @@
     if (lev < 0) {
 	ary = rb_ary_new();
     }
-    vm_backtrace_each(th, lev, vm_backtrace_push, &ary);
+    vm_backtrace_each(th, lev, vm_backtrace_alloc, vm_backtrace_push, &ary);
     if (!ary) return Qnil;
     return rb_ary_reverse(ary);
 }

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

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