-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathstring-backtraces.diff
47 lines (43 loc) · 1.55 KB
/
string-backtraces.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
diff --git a/src/backtrace.c b/src/backtrace.c
index d6648cc43..9f98292b8 100644
--- a/src/backtrace.c
+++ b/src/backtrace.c
@@ -95,6 +95,7 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *
}
#ifndef MRB_NO_STDIO
+char superhack[1024*20];
static void
print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace)
@@ -102,24 +103,29 @@ print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace)
mrb_int i;
mrb_int n = RARRAY_LEN(backtrace);
mrb_value *loc, mesg;
+ char stream[1024];
+ superhack[0] = 0;
if (n != 0) {
if (n > 1) {
- fprintf(stderr, "trace (most recent call last):\n");
+ sprintf(stream, "trace (most recent call last):\n");
+ strcat(superhack, stream);
}
for (i=n-1,loc=&RARRAY_PTR(backtrace)[i]; i>0; i--,loc--) {
if (mrb_string_p(*loc)) {
- fprintf(stderr, "\t[%d] %.*s\n",
+ sprintf(stream, "\t[%d] %.*s\n",
(int)i, (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
+ strcat(superhack, stream);
}
}
if (mrb_string_p(*loc)) {
- fprintf(stderr, "%.*s: ", (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
+ sprintf(stream, "%.*s: ", (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
+ strcat(superhack, stream);
}
}
mesg = mrb_exc_inspect(mrb, mrb_obj_value(exc));
- fwrite(RSTRING_PTR(mesg), RSTRING_LEN(mesg), 1, stderr);
- fputc('\n', stderr);
+ sprintf(stream, "%.*s\n", (int)RSTRING_LEN(mesg), RSTRING_PTR(mesg));
+ strcat(superhack, stream);
}
/* mrb_print_backtrace