From 0b5a2f7a8fa0f0385262e2ec0c71fe9113361077 Mon Sep 17 00:00:00 2001 From: GranMinigun <11149380+GranMinigun@users.noreply.github.com> Date: Wed, 6 Dec 2023 15:37:25 +0500 Subject: [PATCH] Revert "Catch fmt::print throwing std::system_error when it cannot write to STDOUT (fixes #301)" This reverts commit ff8f402e58061a338690703b22dc7d0979cd164b. --- src/nba/CMakeLists.txt | 1 - src/nba/include/nba/log.hpp | 3 +-- src/nba/include/nba/print.hpp | 26 -------------------------- src/nba/src/bus/io.cpp | 2 +- 4 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 src/nba/include/nba/print.hpp diff --git a/src/nba/CMakeLists.txt b/src/nba/CMakeLists.txt index 692c71d6e..ce145f93f 100644 --- a/src/nba/CMakeLists.txt +++ b/src/nba/CMakeLists.txt @@ -114,7 +114,6 @@ set(HEADERS_PUBLIC include/nba/core.hpp include/nba/integer.hpp include/nba/log.hpp - include/nba/print.hpp include/nba/save_state.hpp include/nba/scheduler.hpp ) diff --git a/src/nba/include/nba/log.hpp b/src/nba/include/nba/log.hpp index 4f2f90ce5..c06e68dfb 100644 --- a/src/nba/include/nba/log.hpp +++ b/src/nba/include/nba/log.hpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace nba { @@ -48,7 +47,7 @@ inline void Log(std::string_view format, Args&&... args) { if constexpr(level == Error) prefix = "\e[35m[E]"; if constexpr(level == Fatal) prefix = "\e[31m[F]"; - nba::print("{} {}\n", prefix, fmt::format(format, std::forward(args)...)); + fmt::print("{} {}\n", prefix, fmt::format(format, std::forward(args)...)); } } diff --git a/src/nba/include/nba/print.hpp b/src/nba/include/nba/print.hpp deleted file mode 100644 index d4d1cf3f2..000000000 --- a/src/nba/include/nba/print.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2023 fleroviux - * - * Licensed under GPLv3 or any later version. - * Refer to the included LICENSE file. - */ - -#pragma once - -#include -#include - -namespace nba { - - template - void print(Args&&... args) { - // {fmt} throws an exception if it cannot write to stdout. - // This unfortunately is the case when running as a windowed application with no console attached. - // See: https://github.com/fmtlib/fmt/issues/1176 - try { - fmt::print(std::forward(args)...); - } catch(const fmt::system_error& _) { - } - } - -} // namespace nba diff --git a/src/nba/src/bus/io.cpp b/src/nba/src/bus/io.cpp index e415ec6f0..da9a4004b 100644 --- a/src/nba/src/bus/io.cpp +++ b/src/nba/src/bus/io.cpp @@ -633,7 +633,7 @@ void Bus::Hardware::WriteHalf(u32 address, u16 value) { case MGBA_LOG_SEND: { if(mgba_log.enable && (value & 0x100) != 0) { - nba::print("mGBA log: {}\n", mgba_log.message.data()); + fmt::print("mGBA log: {}\n", mgba_log.message.data()); std::fflush(stdout); mgba_log.message.fill(0); }