Skip to content

Commit

Permalink
Add the old way of asserting in case if messaging is not build
Browse files Browse the repository at this point in the history
  • Loading branch information
VeithMetro committed Jan 17, 2025
1 parent d0daf0a commit 6066ae1
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Source/core/Trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Core {

return (ss.str());
}
#ifdef __WINDOWS__
#if defined(__CORE_MESSAGING__) && defined(__WINDOWS__)
const std::string& GetProgramName()
{
static std::string programName;
Expand Down
145 changes: 88 additions & 57 deletions Source/core/Trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,68 +159,99 @@ namespace Thunder {

#if defined(__DEBUG__) || defined(_THUNDER_PRODUCTION)

#ifdef __APPLE__
#define PROGRAM_NAME getprogname()
#elif defined(__WINDOWS__)
#define PROGRAM_NAME Thunder::Core::GetProgramName()
#else
#define PROGRAM_NAME program_invocation_short_name
#endif
#ifdef __DEBUG__
#define ASSERT_ABORT abort();
#else
#define ASSERT_ABORT
#endif

#define ASSERT_METADATA \
Thunder::Core::Messaging::MessageInfo __messageInfo__( \
Thunder::Assertion::BaseAssertType::Metadata()); \
std::list<Thunder::Core::callstack_info> __entries__; \
DumpCallStack(0, __entries__); \
std::ostringstream __output__; \
for (const Thunder::Core::callstack_info& entry : __entries__) { \
__output__ << "[" << entry.module << "]:[" << entry.function << "]:[" << entry.line << "]\n"; \
} \
std::string __callstack__ = __output__.str(); \
Thunder::Core::Messaging::IStore::Assert __assertMetadata__( \
__messageInfo__, \
TRACE_PROCESS_ID, \
PROGRAM_NAME, \
__FILE__, \
__LINE__, \
__callstack__);
#ifdef __CORE_MESSAGING__

#define ASSERT_SENT \
Thunder::Assertion::AssertionUnitProxy::Instance().AssertionEvent( \
__assertMetadata__, \
__message__);
#ifdef __APPLE__
#define PROGRAM_NAME getprogname()
#elif defined(__WINDOWS__)
#define PROGRAM_NAME Thunder::Core::GetProgramName()
#else
#define PROGRAM_NAME program_invocation_short_name
#endif

#ifdef __DEBUG__
#define ASSERT_ABORT abort();
#else
#define ASSERT_ABORT
#endif
#define ASSERT_METADATA \
Thunder::Core::Messaging::MessageInfo __messageInfo__( \
Thunder::Assertion::BaseAssertType::Metadata()); \
std::list<Thunder::Core::callstack_info> __entries__; \
DumpCallStack(0, __entries__); \
std::ostringstream __output__; \
for (const Thunder::Core::callstack_info& entry : __entries__) { \
__output__ << "[" << entry.module << "]:[" << entry.function << "]:[" << entry.line << "]\n"; \
} \
std::string __callstack__ = __output__.str(); \
Thunder::Core::Messaging::IStore::Assert __assertMetadata__( \
__messageInfo__, \
TRACE_PROCESS_ID, \
PROGRAM_NAME, \
__FILE__, \
__LINE__, \
__callstack__);

#define ASSERT(expr) \
do { \
if (!(expr)) { \
if (Thunder::Assertion::BaseAssertType::IsEnabled()) { \
ASSERT_METADATA \
Thunder::Core::Messaging::TextMessage __message__(#expr); \
ASSERT_SENT \
} \
ASSERT_ABORT \
} \
} while(0)
#define ASSERT_SENT \
Thunder::Assertion::AssertionUnitProxy::Instance().AssertionEvent( \
__assertMetadata__, \
__message__);

#define ASSERT_VERBOSE(expr, format, ...) \
do { \
if (!(expr)) { \
if (Thunder::Assertion::BaseAssertType::IsEnabled()) { \
ASSERT_METADATA \
char __buffer__[256]; \
std::snprintf(__buffer__, sizeof(__buffer__), "%s: " #format, #expr, ##__VA_ARGS__); \
Thunder::Core::Messaging::TextMessage __message__(__buffer__); \
ASSERT_SENT \
} \
ASSERT_ABORT \
} \
} while(0)
#define ASSERT(expr) \
do { \
if (!(expr)) { \
if (Thunder::Assertion::BaseAssertType::IsEnabled()) { \
ASSERT_METADATA \
Thunder::Core::Messaging::TextMessage __message__(#expr); \
ASSERT_SENT \
} \
ASSERT_ABORT \
} \
} while(0)

#define ASSERT_VERBOSE(expr, format, ...) \
do { \
if (!(expr)) { \
if (Thunder::Assertion::BaseAssertType::IsEnabled()) { \
ASSERT_METADATA \
char __buffer__[256]; \
std::snprintf(__buffer__, sizeof(__buffer__), "%s: " #format, #expr, ##__VA_ARGS__); \
Thunder::Core::Messaging::TextMessage __message__(__buffer__); \
ASSERT_SENT \
} \
ASSERT_ABORT \
} \
} while(0)
#else
#define ASSERT(expr) \
do { \
if (!(expr)) { \
ASSERT_LOGGER("===== $$ [%d]: ASSERT [%s:%d] (%s)\n", TRACE_PROCESS_ID, __FILE__, __LINE__, #expr); \
std::list<Thunder::Core::callstack_info> entries; \
DumpCallStack(0, entries); \
for(const Thunder::Core::callstack_info& entry : entries) { \
fprintf(stderr, "[%s]:[%s]:[%d]\n", entry.module.c_str(), entry.function.c_str(), entry.line); \
} \
fflush(stderr); \
ASSERT_ABORT \
} \
} while(0)

#define ASSERT_VERBOSE(expr, format, ...) \
do { \
if (!(expr)) { \
ASSERT_LOGGER("===== $$ [%d]: ASSERT [%s:%d] (%s)\n " #format "\n", TRACE_PROCESS_ID, __FILE__, __LINE__, #expr, ##__VA_ARGS__); \
std::list<Thunder::Core::callstack_info> entries; \
DumpCallStack(0, entries); \
for(const Thunder::Core::callstack_info& entry : entries) { \
fprintf(stderr, "[%s]:[%s]:[%d]\n", entry.module.c_str(), entry.function.c_str(), entry.line); \
} \
fflush(stderr); \
ASSERT_ABORT \
} \
} while(0)
#endif

#define VERIFY(expr) ASSERT(expr)
#else
Expand Down

0 comments on commit 6066ae1

Please sign in to comment.