Fix crash if #inspect does not return a string value

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-12-16 19:26:40 +09:00
parent 05e6513fb4
commit fcbb7ec49d
+7 -2
View File
@@ -11,8 +11,13 @@
static void
p(mrb_state *mrb, mrb_value obj)
{
obj = mrb_funcall(mrb, obj, "inspect", 0);
fwrite(RSTRING_PTR(obj), RSTRING_LEN(obj), 1, stdout);
mrb_value val;
val = mrb_funcall(mrb, obj, "inspect", 0);
if (!mrb_string_p(val)) {
val = mrb_obj_as_string(mrb, obj);
}
fwrite(RSTRING_PTR(val), RSTRING_LEN(val), 1, stdout);
putc('\n', stdout);
}
#else