diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 6bce1fdcc0..dae5725119 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -248,15 +248,6 @@ namespace fmt } }; - template - FORCE_INLINE SAFE_BUFFERS(const fmt_type_info*) get_type_info() - { - // Constantly initialized null-terminated list of type-specific information - static constexpr fmt_type_info result[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - - return result; - } - template constexpr const fmt_type_info type_info_v[sizeof...(Args) + 1]{fmt_type_info::make>()...}; @@ -267,8 +258,7 @@ namespace fmt template FORCE_INLINE SAFE_BUFFERS(void) append(std::string& out, const CharT(&fmt)[N], const Args&... args) { - static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - raw_append(out, reinterpret_cast(fmt), type_list, fmt_args_t{fmt_unveil::get(args)...}); + raw_append(out, reinterpret_cast(fmt), type_info_v, fmt_args_t{fmt_unveil::get(args)...}); } // Formatting function @@ -293,8 +283,7 @@ namespace fmt const char* file = __builtin_FILE(), const char* func = __builtin_FUNCTION()) { - static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - raw_throw_exception({line, col, file, func}, reinterpret_cast(fmt), type_list, fmt_args_t{fmt_unveil::get(args)...}); + raw_throw_exception({line, col, file, func}, reinterpret_cast(fmt), type_info_v, fmt_args_t{fmt_unveil::get(args)...}); } #ifndef _MSC_VER diff --git a/rpcs3/Emu/Cell/ErrorCodes.h b/rpcs3/Emu/Cell/ErrorCodes.h index 2928108417..68581460c5 100644 --- a/rpcs3/Emu/Cell/ErrorCodes.h +++ b/rpcs3/Emu/Cell/ErrorCodes.h @@ -12,20 +12,26 @@ public: error_code() = default; // Implementation must be provided independently - static s32 error_report(const fmt_type_info* sup, u64 arg, const fmt_type_info* sup2, u64 arg2); + static s32 error_report(s32 result, const char* fmt, const fmt_type_info* sup, const u64* args); // Common constructor template error_code(const ET& value) - : value(static_cast(value)) + : value(error_report(static_cast(value), " : %s", fmt::type_info_v, fmt_args_t{fmt_unveil::get(value)})) { - this->value = error_report(fmt::get_type_info>(), fmt_unveil::get(value), nullptr, 0); } // Error constructor (2 args) - template - error_code(const ET& value, const T2& value2) - : value(error_report(fmt::get_type_info>(), fmt_unveil::get(value), fmt::get_type_info>(), fmt_unveil::get(value2))) + template + error_code(const ET& value, const T& arg) + : value(error_report(static_cast(value), " : %s, %s", fmt::type_info_v, fmt_args_t{fmt_unveil::get(value), fmt_unveil::get(arg)})) + { + } + + // Formatting constructor (error, format string, variadic list) + template requires (sizeof...(Args) > 0) + error_code(const ET& value, const const_str& fmt, const Args&... args) + : value(error_report(static_cast(value), fmt, fmt::type_info_v, fmt_args_t{fmt_unveil::get(args)...})) { } diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index 9712123987..81bc695067 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -574,7 +574,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v if (const auto ecode = savedata_check_args(operation, version, dirName, errDialog, setList, setBuf, funcList, funcFixed, funcStat, funcFile, container, unk_op_flags, userdata, userId, funcDone)) { - return {CELL_SAVEDATA_ERROR_PARAM, std::to_string(ecode)}; + return {CELL_SAVEDATA_ERROR_PARAM, " (error %d)", ecode}; } std::unique_lock lock(g_fxo->get().mutex, std::try_to_lock); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 88cf9cba9c..f059a4c4d6 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1640,14 +1640,14 @@ std::string Emulator::GetFormattedTitle(double fps) const return rpcs3::get_formatted_title(title_data); } -s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_info* sup2, u64 arg2) +s32 error_code::error_report(s32 result, const char* fmt, const fmt_type_info* sup, const u64* args) { static thread_local std::unordered_map g_tls_error_stats; static thread_local std::string g_tls_error_str; - if (!sup) + if (!sup && !args) { - if (!sup2) + if (!fmt) { // Report and clean error state for (auto&& pair : g_tls_error_stats) @@ -1681,7 +1681,8 @@ s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_i // Format log message (use preallocated buffer) g_tls_error_str.clear(); - fmt::append(g_tls_error_str, "'%s' failed with 0x%08x%s%s%s%s", func, arg, sup ? " : " : "", std::make_pair(sup, arg), sup2 ? ", " : "", std::make_pair(sup2, arg2)); + fmt::append(g_tls_error_str, "'%s' failed with 0x%08x", func, result); + fmt::raw_append(g_tls_error_str, fmt, sup, args); // Update stats and check log threshold const auto stat = ++g_tls_error_stats[g_tls_error_str]; @@ -1691,7 +1692,7 @@ s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_i channel->error("%s [%u]", g_tls_error_str, stat); } - return static_cast(arg); + return result; } void Emulator::ConfigurePPUCache() const diff --git a/rpcs3/util/logs.hpp b/rpcs3/util/logs.hpp index 345560ea5a..61f894a340 100644 --- a/rpcs3/util/logs.hpp +++ b/rpcs3/util/logs.hpp @@ -91,8 +91,7 @@ namespace logs {\ if constexpr (sizeof...(Args) > 0)\ {\ - static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...};\ - msg_##_sev.broadcast(fmt, type_list, u64{fmt_unveil::get(args)}...);\ + msg_##_sev.broadcast(fmt, fmt::type_info_v, u64{fmt_unveil::get(args)}...);\ }\ else\ {\