diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-01 22:36:15 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-01 22:36:15 +0000 |
commit | a7b5c603b4747704d8ed7ce22c342649e88f6993 (patch) | |
tree | 9ec74b2215a215f0364e0ec3adec42bdb18405dc /vm_eval.c | |
parent | 1c4e92c1851d1027f22b64cdd6e4d40d212609b6 (diff) | |
download | bundler-a7b5c603b4747704d8ed7ce22c342649e88f6993.tar.gz |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@21932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r-- | vm_eval.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -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 |