summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/vm_eval.c b/vm_eval.c
index ea72365d9d..fefe6d6dfd 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1573,8 +1573,16 @@ rb_f_caller(int argc, VALUE *argv)
static int
print_backtrace(void *arg, VALUE file, int line, VALUE method)
{
- fprintf((FILE *)arg, "\tfrom %s:%d:in `%s'\n",
- RSTRING_PTR(file), line, RSTRING_PTR(method));
+ FILE *fp = arg;
+ const char *filename = NIL_P(file) ? "ruby" : RSTRING_PTR(file);
+ if (NIL_P(method)) {
+ fprintf(fp, "\tfrom %s:%d:in unknown method\n",
+ filename, line);
+ }
+ else {
+ fprintf(fp, "\tfrom %s:%d:in `%s'\n",
+ filename, line, RSTRING_PTR(method));
+ }
return FALSE;
}