Skip to content

Commit e847173

Browse files
committed
Make log_cmd_error() use variadic templates.
1 parent f2946f7 commit e847173

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

kernel/log.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,10 @@ void log_abort_internal(const char *file, int line)
407407
log_error("Abort in %s:%d.\n", file, line);
408408
}
409409

410-
void log_cmd_error(const char *format, ...)
410+
void log_formatted_cmd_error(std::string str)
411411
{
412-
va_list ap;
413-
va_start(ap, format);
414-
415412
if (log_cmd_error_throw) {
416-
log_last_error = vstringf(format, ap);
413+
log_last_error = str;
417414

418415
// Make sure the error message gets through any selective silencing
419416
// of log output
@@ -423,7 +420,7 @@ void log_cmd_error(const char *format, ...)
423420
pop_errfile = true;
424421
}
425422

426-
log("ERROR: %s", log_last_error.c_str());
423+
log("ERROR: %s", log_last_error);
427424
log_flush();
428425

429426
if (pop_errfile)
@@ -432,7 +429,7 @@ void log_cmd_error(const char *format, ...)
432429
throw log_cmd_error_exception();
433430
}
434431

435-
log_formatted_error(vstringf(format, ap));
432+
log_formatted_error(str);
436433
}
437434

438435
void log_spacer()

kernel/log.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ extern int log_debug_suppressed;
124124
void set_verific_logging(void (*cb)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg));
125125
extern void (*log_verific_callback)(int msg_type, const char *message_id, const char* file_path, unsigned int left_line, unsigned int left_col, unsigned int right_line, unsigned int right_col, const char *msg);
126126

127-
[[noreturn]] void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
128-
129127
#ifndef NDEBUG
130128
static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; }
131129
#else
@@ -194,6 +192,13 @@ template <typename... Args>
194192
log_formatted_file_error(filename, lineno, fmt.format(args...));
195193
}
196194

195+
[[noreturn]] void log_formatted_cmd_error(std::string str);
196+
template <typename... Args>
197+
[[noreturn]] void log_cmd_error(FmtString<TypeIdentity<Args>...> fmt, const Args &... args)
198+
{
199+
log_formatted_cmd_error(fmt.format(args...));
200+
}
201+
197202
static inline void log_suppressed() {
198203
if (log_debug_suppressed && !log_make_debug) {
199204
log("<suppressed ~%d debug messages>\n", log_debug_suppressed);

0 commit comments

Comments
 (0)