Add static, runtime and debug assert utilities
This commit is contained in:
27
src/common/assert/assert.h
Normal file
27
src/common/assert/assert.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
#include "../aliases/aliases.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1]
|
||||
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
|
||||
|
||||
#ifdef WAPP_DEBUG_ASSERT
|
||||
#define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG)
|
||||
#else
|
||||
#define wapp_debug_assert(EXPR, MSG)
|
||||
#endif
|
||||
|
||||
#define __wapp_runtime_assert(EXPR, MSG) do { \
|
||||
if (!(EXPR)) { \
|
||||
fprintf( \
|
||||
stderr, \
|
||||
"%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \
|
||||
__FILE__, __LINE__, __func__, \
|
||||
EXPR, MSG \
|
||||
); \
|
||||
abort(); \
|
||||
} \
|
||||
} while(false)
|
Reference in New Issue
Block a user