Permalink
Browse files

Kernel#caller: now honor the skip argument

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3524 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent a55157b commit 0849733df490d4f4700061cd0408a7d9a4bc6d09 @lrz lrz committed Feb 14, 2010
Showing with 16 additions and 16 deletions.
  1. +1 −1 debugger.cpp
  2. +9 −3 vm.cpp
  3. +1 −1 vm.h
  4. +5 −11 vm_eval.c
View
@@ -315,7 +315,7 @@ RoxorDebugger::trap(const char *file, const int line, VALUE self,
continue;
}
if (strcmp(cmd, "backtrace") == 0) {
- VALUE bt = rb_vm_backtrace(100);
+ VALUE bt = rb_vm_backtrace(0);
VALUE str = rb_ary_join(bt, rb_str_new2("\n"));
send(RSTRING_PTR(str));
continue;
View
12 vm.cpp
@@ -3503,15 +3503,15 @@ rb_vm_raise_current_exception(void)
{
VALUE exception = GET_VM()->current_exception();
assert(exception != Qnil);
- rb_iv_set(exception, "bt", rb_vm_backtrace(100));
+ rb_iv_set(exception, "bt", rb_vm_backtrace(0));
__vm_raise();
}
extern "C"
void
rb_vm_raise(VALUE exception)
{
- rb_iv_set(exception, "bt", rb_vm_backtrace(100));
+ rb_iv_set(exception, "bt", rb_vm_backtrace(0));
rb_objc_retain((void *)exception);
GET_VM()->push_current_exception(exception);
__vm_raise();
@@ -3678,8 +3678,10 @@ rb_vm_check_return_from_block_exc(RoxorReturnFromBlockException **pexc, int id)
extern "C"
VALUE
-rb_vm_backtrace(int level)
+rb_vm_backtrace(int skip)
{
+ assert(skip >= 0);
+
void *callstack[128];
int callstack_n = backtrace(callstack, 128);
@@ -3710,6 +3712,10 @@ rb_vm_backtrace(int level)
}
}
+ while (skip-- > 0) {
+ rb_ary_shift(ary);
+ }
+
return ary;
}
View
2 vm.h
@@ -453,7 +453,7 @@ void rb_vm_raise(VALUE exception);
void rb_vm_raise_current_exception(void);
VALUE rb_vm_current_exception(void);
void rb_vm_set_current_exception(VALUE exception);
-VALUE rb_vm_backtrace(int level);
+VALUE rb_vm_backtrace(int skip);
void rb_vm_print_current_exception(void);
#define TEST_THREAD_CANCEL() (pthread_testcancel())
View
@@ -736,10 +736,9 @@ static VALUE
rb_f_caller(VALUE klass, SEL sel, int argc, VALUE *argv)
{
VALUE level;
- int lev;
-
rb_scan_args(argc, argv, "01", &level);
+ int lev;
if (NIL_P(level)) {
lev = 1;
}
@@ -751,27 +750,22 @@ rb_f_caller(VALUE klass, SEL sel, int argc, VALUE *argv)
rb_raise(rb_eArgError, "negative level (%d)", lev);
}
- VALUE ary = rb_vm_backtrace(lev);
- rb_ary_shift(ary); // remove #caller
- return ary;
+ return rb_vm_backtrace(lev);
}
void
rb_backtrace(void)
{
- long i, count;
- VALUE ary;
-
- ary = rb_vm_backtrace(-1);
- for (i = 0, count = RARRAY_LEN(ary); i < count; i++) {
+ VALUE ary = rb_vm_backtrace(0);
+ for (long i = 0, count = RARRAY_LEN(ary); i < count; i++) {
printf("\tfrom %s\n", RSTRING_PTR(RARRAY_AT(ary, i)));
}
}
VALUE
rb_make_backtrace(void)
{
- return rb_vm_backtrace(-1);
+ return rb_vm_backtrace(0);
}
void

0 comments on commit 0849733

Please sign in to comment.