From 587ae17aa2ac8b6d0da47640bbbb779197e1a51c Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 8 Nov 2019 00:36:59 +0300 Subject: [PATCH] Simplify fmt::throw_exception Gradual exception deprecation: disallow choosing exception type. However, the function itself can remain here forever. --- Utilities/Config.cpp | 8 ++++---- Utilities/File.cpp | 4 ++-- Utilities/StrFmt.cpp | 14 +------------- Utilities/StrFmt.h | 5 ++--- rpcs3/Emu/Cell/PPUThread.cpp | 2 +- rpcs3/Emu/Cell/SPURecompiler.cpp | 2 +- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Utilities/Config.cpp b/Utilities/Config.cpp index 635738af95..b3f044a55a 100644 --- a/Utilities/Config.cpp +++ b/Utilities/Config.cpp @@ -12,7 +12,7 @@ namespace cfg { if (_type != type::node) { - fmt::throw_exception("Invalid root node" HERE); + fmt::throw_exception("Invalid root node" HERE); } } @@ -23,7 +23,7 @@ namespace cfg { if (pair.first == name) { - fmt::throw_exception("Node already exists: %s" HERE, name); + fmt::throw_exception("Node already exists: %s" HERE, name); } } @@ -32,12 +32,12 @@ namespace cfg bool _base::from_string(const std::string&) { - fmt::throw_exception("from_string() purecall" HERE); + fmt::throw_exception("from_string() purecall" HERE); } bool _base::from_list(std::vector&&) { - fmt::throw_exception("from_list() purecall" HERE); + fmt::throw_exception("from_list() purecall" HERE); } // Emit YAML diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 7bc1963604..7aafea9b01 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -911,7 +911,7 @@ bool fs::utime(const std::string& path, s64 atime, s64 mtime) void fs::file::xnull() const { - fmt::throw_exception("fs::file is null"); + fmt::throw_exception("fs::file is null"); } void fs::file::xfail() const @@ -1330,7 +1330,7 @@ fs::native_handle fs::file::get_handle() const void fs::dir::xnull() const { - fmt::throw_exception("fs::dir is null"); + fmt::throw_exception("fs::dir is null"); } bool fs::dir::open(const std::string& path) diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 38d3b76e8e..8f87dca283 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -259,25 +259,13 @@ namespace fmt throw std::range_error{out}; } - // Hidden template - template void raw_throw_exception(const char* fmt, const fmt_type_info* sup, const u64* args) { std::string out; raw_append(out, fmt, sup, args); - throw T{out}; + throw std::runtime_error{out}; } - // Explicit instantiations (not exhaustive) - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - template void raw_throw_exception(const char*, const fmt_type_info*, const u64*); - struct cfmt_src; } diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 7071a69d37..205a9398df 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -291,14 +291,13 @@ namespace fmt } // Internal exception message formatting template, must be explicitly specialized or instantiated in cpp to minimize code bloat - template [[noreturn]] void raw_throw_exception(const char*, const fmt_type_info*, const u64*); // Throw exception with formatting - template + template [[noreturn]] SAFE_BUFFERS FORCE_INLINE void throw_exception(const char* fmt, const Args&... args) { static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - raw_throw_exception(fmt, type_list, fmt_args_t{fmt_unveil::get(args)...}); + raw_throw_exception(fmt, type_list, fmt_args_t{fmt_unveil::get(args)...}); } } diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 7bce8f7446..4166fe17d7 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -182,7 +182,7 @@ static u64 ppu_cache(u32 addr) const auto& table = *( g_cfg.core.ppu_decoder == ppu_decoder_type::precise ? &g_ppu_interpreter_precise.get_table() : g_cfg.core.ppu_decoder == ppu_decoder_type::fast ? &g_ppu_interpreter_fast.get_table() : - (fmt::throw_exception("Invalid PPU decoder"), nullptr)); + (fmt::throw_exception("Invalid PPU decoder"), nullptr)); const u32 value = vm::read32(addr); return (u64)value << 32 | ::narrow(reinterpret_cast(table[ppu_decode(value)])); diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index d6ae49a197..a364890be2 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -1168,7 +1168,7 @@ void spu_recompiler_base::old_interpreter(spu_thread& spu, void* ls, u8* rip) tr const auto& table = *( g_cfg.core.spu_decoder == spu_decoder_type::precise ? &g_spu_interpreter_precise.get_table() : g_cfg.core.spu_decoder == spu_decoder_type::fast ? &g_spu_interpreter_fast.get_table() : - (fmt::throw_exception("Invalid SPU decoder"), nullptr)); + (fmt::throw_exception("Invalid SPU decoder"), nullptr)); // LS pointer const auto base = static_cast(ls);