aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval_error.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/eval_error.c b/eval_error.c
index 597f5d8d14..b671149bad 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -137,6 +137,11 @@ print_backtrace(const VALUE eclass, const VALUE errat, int reverse)
long i;
long len = RARRAY_LEN(errat);
int skip = eclass == rb_eSysStackError;
+ const int threshold = 1000000000;
+ int width = ((int)log10((double)(len > threshold ?
+ ((len - 1) / threshold) :
+ len - 1)) +
+ (len < ? 0 : 9) + 1);
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
#define TRACE_HEAD 8
@@ -145,7 +150,9 @@ print_backtrace(const VALUE eclass, const VALUE errat, int reverse)
for (i = 1; i < len; i++) {
VALUE line = RARRAY_AREF(errat, reverse ? len - i : i);
if (RB_TYPE_P(line, T_STRING)) {
- warn_print_str(rb_sprintf("\tfrom %"PRIsVALUE"\n", line));
+ VALUE str = rb_str_new_cstr("\t");
+ if (reverse) rb_str_catf(str, "%*ld: ", width, len - i);
+ warn_print_str(rb_str_catf(str, "from %"PRIsVALUE"\n", line));
}
if (skip && i == TRACE_HEAD && len > TRACE_MAX) {
warn_print_str(rb_sprintf("\t ... %ld levels...\n",
@@ -185,7 +192,7 @@ rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo)
}
}
if (rb_stderr_tty_p()) {
- if (0) warn_print("Traceback (most recent call last):\n");
+ warn_print("Traceback (most recent call last):\n");
print_backtrace(eclass, errat, TRUE);
print_errinfo(eclass, errat, emesg);
}