mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Avoid use of snprintf() when DISABLE_STDIO is set; fix #3632
ref #3492 #3515 #3517
This commit is contained in:
+4
-7
@@ -74,14 +74,12 @@ static void
|
||||
get_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data)
|
||||
{
|
||||
mrb_value ary, str;
|
||||
char buf[32];
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
|
||||
ary = mrb_obj_value((struct RArray*)data);
|
||||
|
||||
str = mrb_str_new_cstr(mrb, loc->filename);
|
||||
snprintf(buf, sizeof(buf), ":%d", loc->lineno);
|
||||
mrb_str_cat_cstr(mrb, str, buf);
|
||||
str = mrb_format(mrb, "%S:%S", str, mrb_fixnum_value(loc->lineno));
|
||||
|
||||
if (loc->method) {
|
||||
mrb_str_cat_lit(mrb, str, ":in ");
|
||||
@@ -400,14 +398,13 @@ mrb_restore_backtrace(mrb_state *mrb)
|
||||
int ai;
|
||||
mrb_backtrace_entry *entry;
|
||||
mrb_value mrb_entry;
|
||||
char buf[32];
|
||||
|
||||
ai = mrb_gc_arena_save(mrb);
|
||||
entry = &(mrb->backtrace.entries[i]);
|
||||
|
||||
mrb_entry = mrb_str_new_cstr(mrb, entry->filename);
|
||||
snprintf(buf, sizeof(buf), ":%d", entry->lineno);
|
||||
mrb_str_cat_cstr(mrb, mrb_entry, buf);
|
||||
mrb_entry = mrb_format(mrb, "%S:%S",
|
||||
mrb_str_new_cstr(mrb, entry->filename),
|
||||
mrb_fixnum_value(entry->lineno));
|
||||
if (entry->method_id != 0) {
|
||||
mrb_str_cat_lit(mrb, mrb_entry, ":in ");
|
||||
|
||||
|
||||
+8
-17
@@ -137,6 +137,7 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
|
||||
{
|
||||
mrb_value str, mesg, file, line;
|
||||
mrb_bool append_mesg;
|
||||
const char *cname;
|
||||
|
||||
mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
|
||||
file = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "file"));
|
||||
@@ -148,28 +149,18 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
|
||||
append_mesg = RSTRING_LEN(mesg) > 0;
|
||||
}
|
||||
|
||||
cname = mrb_obj_classname(mrb, exc);
|
||||
str = mrb_str_new_cstr(mrb, cname);
|
||||
if (mrb_string_p(file) && mrb_fixnum_p(line)) {
|
||||
char buf[32];
|
||||
|
||||
str = mrb_str_dup(mrb, file);
|
||||
snprintf(buf, sizeof(buf), ":%" MRB_PRId ": ", mrb_fixnum(line));
|
||||
mrb_str_cat_cstr(mrb, str, buf);
|
||||
if (append_mesg) {
|
||||
mrb_str_cat_str(mrb, str, mesg);
|
||||
mrb_str_cat_lit(mrb, str, " (");
|
||||
str = mrb_format(mrb, "%S:%S:%S (%S)", file, line, mesg, str);
|
||||
}
|
||||
mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, exc));
|
||||
if (append_mesg) {
|
||||
mrb_str_cat_lit(mrb, str, ")");
|
||||
else {
|
||||
str = mrb_format(mrb, "%S:%S:%S", file, line, str);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const char *cname = mrb_obj_classname(mrb, exc);
|
||||
str = mrb_str_new_cstr(mrb, cname);
|
||||
if (append_mesg) {
|
||||
mrb_str_cat_lit(mrb, str, ": ");
|
||||
mrb_str_cat_str(mrb, str, mesg);
|
||||
}
|
||||
else if (append_mesg) {
|
||||
str = mrb_format(mrb, "%S:%S", str, mesg);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user