Core/Debugging: Extended ASSERT macro to allow passing additional formatted string

This commit is contained in:
Shauren
2014-09-26 20:47:48 +02:00
parent 7b72342658
commit 71644043d2
2 changed files with 18 additions and 2 deletions

View File

@@ -21,6 +21,7 @@
#include <cstdio>
#include <cstdlib>
#include <thread>
#include <cstdarg>
namespace Trinity {
@@ -32,6 +33,21 @@ void Assert(char const* file, int line, char const* function, char const* messag
exit(1);
}
void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s ", file, line, function, message);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
fflush(stderr);
va_end(args);
*((volatile int*)NULL) = 0;
exit(1);
}
void Fatal(char const* file, int line, char const* function, char const* message)
{
fprintf(stderr, "\n%s:%i in %s FATAL ERROR:\n %s\n",

View File

@@ -23,8 +23,8 @@
namespace Trinity
{
DECLSPEC_NORETURN void Assert(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...) ATTR_NORETURN ATTR_PRINTF(5, 6);
DECLSPEC_NORETURN void Fatal(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
@@ -42,7 +42,7 @@ namespace Trinity
#define ASSERT_END
#endif
#define WPAssert(cond) ASSERT_BEGIN do { if (!(cond)) Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond); } while(0) ASSERT_END
#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, __VA_ARGS__); } while(0) ASSERT_END
#define WPFatal(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END