From a9ccdcf68119e5d445aedecefd311b52c9b5e3c7 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 1 Feb 2009 22:36:15 +0000 Subject: * vm.c (vm_backtrace_each): now takes an iterator function. * vm_core.h (rb_make_backtrace, rb_backtrace_each): added prototypes. * vm_dump.c (rb_vm_bugreport), vm_eval.c (rb_backtrace): gets rid of allocating objects. * vm_eval.c (rb_backtrace_each): new function which iterates over each backtrace info. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_eval.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'vm_eval.c') diff --git a/vm_eval.c b/vm_eval.c index e9774d278..ed0e34a6c 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -16,6 +16,7 @@ static inline VALUE rb_vm_set_finish_env(rb_thread_t * th); 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 NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex); static VALUE vm_exec(rb_thread_t *th); static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref); @@ -1304,16 +1305,17 @@ rb_f_caller(int argc, VALUE *argv) return vm_backtrace(GET_THREAD(), lev); } +static int +print_backtrace(void *arg, const char *file, int line, const char *method) +{ + fprintf((FILE *)arg, "\tfrom %s:%d:in `%s'\n", file, line, method); + return Qfalse; +} + void rb_backtrace(void) { - long i; - VALUE ary; - - ary = vm_backtrace(GET_THREAD(), -1); - for (i = 0; i < RARRAY_LEN(ary); i++) { - printf("\tfrom %s\n", RSTRING_PTR(RARRAY_PTR(ary)[i])); - } + vm_backtrace_each(GET_THREAD(), -1, print_backtrace, stdout); } VALUE @@ -1322,6 +1324,12 @@ rb_make_backtrace(void) return vm_backtrace(GET_THREAD(), -1); } +VALUE +rb_backtrace_each(rb_backtrace_iter_func *iter, void *arg) +{ + return vm_backtrace_each(GET_THREAD(), -1, iter, arg); +} + /* * call-seq: * local_variables => array -- cgit