summaryrefslogtreecommitdiffstats
path: root/vm_eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-01 22:36:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-01 22:36:15 +0000
commita9ccdcf68119e5d445aedecefd311b52c9b5e3c7 (patch)
tree9ec74b2215a215f0364e0ec3adec42bdb18405dc /vm_eval.c
parent4c1ad0073e61a2dd67f9120b988a9d07415691b1 (diff)
downloadruby-a9ccdcf68119e5d445aedecefd311b52c9b5e3c7.tar.gz
ruby-a9ccdcf68119e5d445aedecefd311b52c9b5e3c7.tar.xz
ruby-a9ccdcf68119e5d445aedecefd311b52c9b5e3c7.zip
* 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
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c22
1 files changed, 15 insertions, 7 deletions
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