diff --git a/AK/Format.cpp b/AK/Format.cpp index 62384c82e44..a59aae67a03 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -500,7 +500,7 @@ void FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char fill) put_char_view(bytes.size()); } -void vformat(StringBuilder& builder, StringView fmtstr, TypeErasedFormatParams params) +void vformat(StringBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params) { FormatBuilder fmtbuilder { builder }; FormatParser parser { fmtstr }; @@ -608,7 +608,7 @@ void Formatter::format(FormatBuilder& builder, StringView value) builder.put_string(value, m_align, m_width.value(), m_precision.value(), m_fill); } -void Formatter::vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams params) +void Formatter::vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params) { return Formatter::format(builder, String::vformatted(fmtstr, params)); } @@ -754,7 +754,7 @@ void Formatter::format(FormatBuilder& builder, float value) #endif #ifndef KERNEL -void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams params, bool newline) +void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool newline) { StringBuilder builder; vformat(builder, fmtstr, params); @@ -778,7 +778,7 @@ void set_debug_enabled(bool value) is_debug_enabled = value; } -void vdbgln(StringView fmtstr, TypeErasedFormatParams params) +void vdbgln(StringView fmtstr, TypeErasedFormatParams& params) { if (!is_debug_enabled) return; @@ -817,7 +817,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams params) } #ifdef KERNEL -void vdmesgln(StringView fmtstr, TypeErasedFormatParams params) +void vdmesgln(StringView fmtstr, TypeErasedFormatParams& params) { StringBuilder builder; @@ -837,7 +837,7 @@ void vdmesgln(StringView fmtstr, TypeErasedFormatParams params) kernelputstr(string.characters_without_null_termination(), string.length()); } -void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams params) +void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams& params) { // FIXME: Try to avoid memory allocations further to prevent faulting // at OOM conditions. diff --git a/AK/Format.h b/AK/Format.h index e6013e3558c..657be6d8e38 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -466,16 +466,24 @@ struct Formatter : Formatter { } }; -void vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams); +void vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&); #ifndef KERNEL -void vout(FILE*, StringView fmtstr, TypeErasedFormatParams, bool newline = false); +void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false); template -void out(FILE* file, CheckedFormatString&& fmtstr, const Parameters&... parameters) { vout(file, fmtstr.view(), VariadicFormatParams { parameters... }); } +void out(FILE* file, CheckedFormatString&& fmtstr, const Parameters&... parameters) +{ + VariadicFormatParams variadic_format_params { parameters... }; + vout(file, fmtstr.view(), variadic_format_params); +} template -void outln(FILE* file, CheckedFormatString&& fmtstr, const Parameters&... parameters) { vout(file, fmtstr.view(), VariadicFormatParams { parameters... }, true); } +void outln(FILE* file, CheckedFormatString&& fmtstr, const Parameters&... parameters) +{ + VariadicFormatParams variadic_format_params { parameters... }; + vout(file, fmtstr.view(), variadic_format_params, true); +} inline void outln(FILE* file) { fputc('\n', file); } @@ -512,12 +520,13 @@ inline void warnln() { outln(stderr); } #endif -void vdbgln(StringView fmtstr, TypeErasedFormatParams); +void vdbgln(StringView fmtstr, TypeErasedFormatParams&); template void dbgln(CheckedFormatString&& fmtstr, const Parameters&... parameters) { - vdbgln(fmtstr.view(), VariadicFormatParams { parameters... }); + VariadicFormatParams variadic_format_params { parameters... }; + vdbgln(fmtstr.view(), variadic_format_params); } inline void dbgln() { dbgln(""); } @@ -525,22 +534,24 @@ inline void dbgln() { dbgln(""); } void set_debug_enabled(bool); #ifdef KERNEL -void vdmesgln(StringView fmtstr, TypeErasedFormatParams); +void vdmesgln(StringView fmtstr, TypeErasedFormatParams&); template void dmesgln(CheckedFormatString&& fmt, const Parameters&... parameters) { - vdmesgln(fmt.view(), VariadicFormatParams { parameters... }); + VariadicFormatParams variadic_format_params { parameters... }; + vdmesgln(fmt.view(), variadic_format_params); } -void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams); +void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams&); // be very careful to not cause any allocations here, since we could be in // a very unstable situation template void critical_dmesgln(CheckedFormatString&& fmt, const Parameters&... parameters) { - v_critical_dmesgln(fmt.view(), VariadicFormatParams { parameters... }); + VariadicFormatParams variadic_format_params { parameters... }; + v_critical_dmesgln(fmt.view(), variadic_format_params); } #endif @@ -584,9 +595,10 @@ struct Formatter : Formatter { template void format(FormatBuilder& builder, StringView fmtstr, const Parameters&... parameters) { - vformat(builder, fmtstr, VariadicFormatParams { parameters... }); + VariadicFormatParams variadic_format_params { parameters... }; + vformat(builder, fmtstr, variadic_format_params); } - void vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams params); + void vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params); }; } // namespace AK diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 6f3d0b5380c..78363370f00 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -35,7 +35,8 @@ public: template void appendff(CheckedFormatString&& fmtstr, Parameters const&... parameters) { - vformat(*this, fmtstr.view(), VariadicFormatParams { parameters... }); + VariadicFormatParams variadic_format_params { parameters... }; + vformat(*this, fmtstr.view(), variadic_format_params); } [[nodiscard]] String build() const; diff --git a/Kernel/KBufferBuilder.h b/Kernel/KBufferBuilder.h index 8cdd1476471..728e83d79ca 100644 --- a/Kernel/KBufferBuilder.h +++ b/Kernel/KBufferBuilder.h @@ -32,7 +32,8 @@ public: { // FIXME: This really not ideal, but vformat expects StringBuilder. StringBuilder builder; - vformat(builder, fmtstr.view(), AK::VariadicFormatParams { parameters... }); + AK::VariadicFormatParams variadic_format_params { parameters... }; + vformat(builder, fmtstr.view(), variadic_format_params); append_bytes(builder.string_view().bytes()); } diff --git a/Userland/DevTools/UserspaceEmulator/Report.h b/Userland/DevTools/UserspaceEmulator/Report.h index 453a0dd78fc..7f1aa8ac9a0 100644 --- a/Userland/DevTools/UserspaceEmulator/Report.h +++ b/Userland/DevTools/UserspaceEmulator/Report.h @@ -13,8 +13,10 @@ extern bool g_report_to_debug; template void reportln(const StringView& format, Ts... args) { - if (g_report_to_debug) - AK::vdbgln(format, AK::VariadicFormatParams { args... }); - else + if (g_report_to_debug) { + AK::VariadicFormatParams variadic_format_params { args... }; + AK::vdbgln(format, variadic_format_params); + } else { warnln(format, args...); + } }