From 5951d9d3033c75d0bec31babb158348739b45b17 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 22 Jul 2025 04:35:30 +0000 Subject: [PATCH] Make log_file_error() use variadic templates. --- kernel/log.cc | 18 +++++++----------- kernel/log.h | 8 +++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kernel/log.cc b/kernel/log.cc index b964f601f..5390cabc0 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -361,20 +361,16 @@ static void log_error_with_prefix(std::string_view prefix, std::string str) #endif } +void log_formatted_file_error(std::string_view filename, int lineno, std::string str) +{ + std::string prefix = stringf("%s:%d: ERROR: ", filename, lineno); + log_error_with_prefix(prefix, str); +} + void logv_file_error(const string &filename, int lineno, const char *format, va_list ap) { - std::string prefix = stringf("%s:%d: ERROR: ", - filename.c_str(), lineno); - log_error_with_prefix(prefix, vstringf(format, ap)); -} - -void log_file_error(const string &filename, int lineno, - const char *format, ...) -{ - va_list ap; - va_start(ap, format); - logv_file_error(filename, lineno, format, ap); + log_formatted_file_error(filename, lineno, vstringf(format, ap)); } void log_experimental(const std::string &str) diff --git a/kernel/log.h b/kernel/log.h index 839573963..036a2aa4d 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -124,7 +124,6 @@ extern int log_debug_suppressed; 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)); 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); -[[noreturn]] void log_file_error(const string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4)); [[noreturn]] void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2)); #ifndef NDEBUG @@ -188,6 +187,13 @@ template log_formatted_error(fmt.format(args...)); } +[[noreturn]] void log_formatted_file_error(std::string_view filename, int lineno, std::string str); +template +[[noreturn]] void log_file_error(std::string_view filename, int lineno, FmtString...> fmt, Args... args) +{ + log_formatted_file_error(filename, lineno, fmt.format(args...)); +} + static inline void log_suppressed() { if (log_debug_suppressed && !log_make_debug) { log("\n", log_debug_suppressed);