diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-10-28 13:43:16 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-10-28 13:43:16 +0100 |
| commit | 9646bdddafc8645dfd559646a74f317ad34815b4 (patch) | |
| tree | cbec2908ae0e793ffc289ca26a6d1241203a9ac9 /src/common/Debugging/Errors.h | |
| parent | 59a320e2d77a599581876acf424c108fb29aa5dd (diff) | |
Core/Miscc: Add file/line/function information to ASSERT_NOTNULL
Diffstat (limited to 'src/common/Debugging/Errors.h')
| -rw-r--r-- | src/common/Debugging/Errors.h | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/common/Debugging/Errors.h b/src/common/Debugging/Errors.h index 8cceacf7e71..913b4898b4f 100644 --- a/src/common/Debugging/Errors.h +++ b/src/common/Debugging/Errors.h @@ -21,25 +21,36 @@ #include "Define.h" #include <string> +TC_COMMON_API std::string GetDebugInfo(); + namespace Trinity { - [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, std::string debugInfo, char const* message); - [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, std::string debugInfo, char const* message, char const* format, ...) ATTR_PRINTF(6, 7); + [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message, std::string debugInfo) noexcept; + [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message, std::string debugInfo, char const* format, ...) noexcept ATTR_PRINTF(6, 7); - [[noreturn]] TC_COMMON_API void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_PRINTF(4, 5); + [[noreturn]] TC_COMMON_API void Fatal(char const* file, int line, char const* function, char const* message, ...) noexcept ATTR_PRINTF(4, 5); - [[noreturn]] TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message); + [[noreturn]] TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message) noexcept; - [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function); - [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function, char const* message, ...); + [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function) noexcept; + [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function, char const* message, ...) noexcept; - TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message); + TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message) noexcept; - [[noreturn]] TC_COMMON_API void AbortHandler(int sigval); + [[noreturn]] TC_COMMON_API void AbortHandler(int sigval) noexcept; -} // namespace Trinity + namespace Impl + { + template <typename T> + inline T* AssertNotNull(T* pointer, char const* file, int line, char const* function, char const* message) noexcept + { + if (pointer) [[likely]] + return pointer; -TC_COMMON_API std::string GetDebugInfo(); + Assert(file, line, function, message, ::GetDebugInfo()); + } + } +} // namespace Trinity #if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT #define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127)) @@ -53,8 +64,8 @@ TC_COMMON_API std::string GetDebugInfo(); #define EXCEPTION_ASSERTION_FAILURE 0xC0000420L #endif -#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, GetDebugInfo(), #cond, ##__VA_ARGS__); } while(0) ASSERT_END -#define WPAssert_NODEBUGINFO(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, "", #cond, ##__VA_ARGS__); } while(0) ASSERT_END +#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, GetDebugInfo(), ##__VA_ARGS__); } while(0) ASSERT_END +#define WPAssert_NODEBUGINFO(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, ::GetDebugInfo(), ##__VA_ARGS__); } while(0) ASSERT_END #define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END #define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END #define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END @@ -64,9 +75,11 @@ TC_COMMON_API std::string GetDebugInfo(); #ifdef PERFORMANCE_PROFILING #define ASSERT(cond, ...) ((void)0) #define ASSERT_NODEBUGINFO(cond, ...) ((void)0) +#define ASSERT_NOTNULL(pointer) (pointer) #else #define ASSERT WPAssert #define ASSERT_NODEBUGINFO WPAssert_NODEBUGINFO +#define ASSERT_NOTNULL(pointer) Trinity::Impl::AssertNotNull(pointer, __FILE__, __LINE__, __FUNCTION__, #pointer) #endif #define ASSERT_WITH_SIDE_EFFECTS WPAssert @@ -74,13 +87,4 @@ TC_COMMON_API std::string GetDebugInfo(); #define ABORT WPAbort #define ABORT_MSG WPAbort_MSG -template <typename T> -inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr) -{ - ASSERT(pointer, "%s", expr); - return pointer; -} - -#define ASSERT_NOTNULL(pointer) ASSERT_NOTNULL_IMPL(pointer, #pointer) - #endif |
