From 290afc00d36bbdcdc67d66a4586fd2f188734ad3 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 8 Sep 2021 14:36:20 -0400 Subject: [PATCH] common: Move error handling to error.cpp/h This allows us to avoid implicitly including every time common_funcs.h is included. --- src/common/CMakeLists.txt | 3 ++- src/common/common_funcs.h | 11 ----------- src/common/{misc.cpp => error.cpp} | 6 +++++- src/common/error.h | 21 +++++++++++++++++++++ src/common/thread.cpp | 6 +++--- src/core/network/network.cpp | 5 +++-- 6 files changed, 34 insertions(+), 18 deletions(-) rename src/common/{misc.cpp => error.cpp} (95%) create mode 100644 src/common/error.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 57922b51ce..b18a2a2f50 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -53,6 +53,8 @@ add_library(common STATIC div_ceil.h dynamic_library.cpp dynamic_library.h + error.cpp + error.h fiber.cpp fiber.h fs/file.cpp @@ -88,7 +90,6 @@ add_library(common STATIC microprofile.cpp microprofile.h microprofileui.h - misc.cpp nvidia_flags.cpp nvidia_flags.h page_table.cpp diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 53bd7da608..85f8bdd227 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -6,7 +6,6 @@ #include #include -#include #if !defined(ARCHITECTURE_x86_64) #include // for exit @@ -49,16 +48,6 @@ __declspec(dllimport) void __stdcall DebugBreak(void); #endif // _MSC_VER ndef -// Generic function to get last error message. -// Call directly after the command or use the error num. -// This function might change the error code. -// Defined in misc.cpp. -[[nodiscard]] std::string GetLastErrorMsg(); - -// Like GetLastErrorMsg(), but passing an explicit error code. -// Defined in misc.cpp. -[[nodiscard]] std::string NativeErrorToString(int e); - #define DECLARE_ENUM_FLAG_OPERATORS(type) \ [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ using T = std::underlying_type_t; \ diff --git a/src/common/misc.cpp b/src/common/error.cpp similarity index 95% rename from src/common/misc.cpp rename to src/common/error.cpp index 495385b9e3..d4455e3100 100644 --- a/src/common/misc.cpp +++ b/src/common/error.cpp @@ -10,7 +10,9 @@ #include #endif -#include "common/common_funcs.h" +#include "common/error.h" + +namespace Common { std::string NativeErrorToString(int e) { #ifdef _WIN32 @@ -50,3 +52,5 @@ std::string GetLastErrorMsg() { return NativeErrorToString(errno); #endif } + +} // namespace Common diff --git a/src/common/error.h b/src/common/error.h new file mode 100644 index 0000000000..e084d4b0f2 --- /dev/null +++ b/src/common/error.h @@ -0,0 +1,21 @@ +// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +namespace Common { + +// Generic function to get last error message. +// Call directly after the command or use the error num. +// This function might change the error code. +// Defined in error.cpp. +[[nodiscard]] std::string GetLastErrorMsg(); + +// Like GetLastErrorMsg(), but passing an explicit error code. +// Defined in error.cpp. +[[nodiscard]] std::string NativeErrorToString(int e); + +} // namespace Common diff --git a/src/common/thread.cpp b/src/common/thread.cpp index d2c1ac60de..946a1114d5 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -2,7 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "common/common_funcs.h" +#include + +#include "common/error.h" #include "common/logging/log.h" #include "common/thread.h" #ifdef __APPLE__ @@ -21,8 +23,6 @@ #include #endif -#include - #ifdef __FreeBSD__ #define cpu_set_t cpuset_t #endif diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp index 4732d44858..72eea52f03 100644 --- a/src/core/network/network.cpp +++ b/src/core/network/network.cpp @@ -7,7 +7,8 @@ #include #include #include -#include "common/common_funcs.h" + +#include "common/error.h" #ifdef _WIN32 #include @@ -223,7 +224,7 @@ Errno GetAndLogLastError() { if (err == Errno::AGAIN) { return err; } - LOG_ERROR(Network, "Socket operation error: {}", NativeErrorToString(e)); + LOG_ERROR(Network, "Socket operation error: {}", Common::NativeErrorToString(e)); return err; }