[winpr,assert] add WINPR_ASSERT_AT
Add a version of assert that allows setting the location (useful for macros or static functions wrapping something where the location of the call is more significant than the function the macro was used in)
This commit is contained in:
parent
780f6dddce
commit
3c8cd7fb7e
@ -30,29 +30,17 @@
|
||||
#include <winpr/debug.h>
|
||||
|
||||
#if defined(WITH_VERBOSE_WINPR_ASSERT) && (WITH_VERBOSE_WINPR_ASSERT != 0)
|
||||
#define winpr_internal_assert(cond, file, fkt, line) \
|
||||
do \
|
||||
{ \
|
||||
if (!(cond)) \
|
||||
winpr_int_assert(#cond, (file), (fkt), (line)); \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#define WINPR_ASSERT(cond) \
|
||||
do \
|
||||
{ \
|
||||
WINPR_PRAGMA_DIAG_PUSH \
|
||||
WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
|
||||
WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
|
||||
WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
|
||||
WINPR_DO_PRAGMA(coverity compliance block \x28 deviate "CONSTANT_EXPRESSION_RESULT" \
|
||||
"WINPR_ASSERT" \x29 \
|
||||
\x28 deviate "NO_EFFECT" \
|
||||
"WINPR_ASSERT" \x29) \
|
||||
\
|
||||
if (!(cond)) \
|
||||
winpr_int_assert(#cond, __FILE__, __func__, __LINE__); \
|
||||
\
|
||||
WINPR_DO_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \
|
||||
"NO_EFFECT") \
|
||||
WINPR_PRAGMA_DIAG_POP \
|
||||
} while (0)
|
||||
|
||||
static INLINE WINPR_NORETURN(void winpr_int_assert(const char* condstr, const char* file,
|
||||
const char* fkt, size_t line))
|
||||
@ -68,25 +56,29 @@ extern "C"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define WINPR_ASSERT(cond) \
|
||||
do \
|
||||
{ \
|
||||
WINPR_PRAGMA_DIAG_PUSH \
|
||||
WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
|
||||
WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
|
||||
WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
|
||||
WINPR_DO_PRAGMA(coverity compliance block \x28 deviate "CONSTANT_EXPRESSION_RESULT" \
|
||||
"WINPR_ASSERT" \x29 \
|
||||
\x28 deviate "NO_EFFECT" \
|
||||
"WINPR_ASSERT" \x29) \
|
||||
assert(cond); \
|
||||
\
|
||||
WINPR_DO_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \
|
||||
"NO_EFFECT") \
|
||||
WINPR_PRAGMA_DIAG_POP \
|
||||
} while (0)
|
||||
#define winpr_internal_assert(cond, file, fkt, line) assert(cond)
|
||||
#endif
|
||||
|
||||
#define WINPR_ASSERT_AT(cond, file, fkt, line) \
|
||||
do \
|
||||
{ \
|
||||
WINPR_PRAGMA_DIAG_PUSH \
|
||||
WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
|
||||
WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
|
||||
WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
|
||||
WINPR_DO_COVERITY_PRAGMA(coverity compliance block \(deviate "CONSTANT_EXPRESSION_RESULT" \
|
||||
"WINPR_ASSERT" \) \
|
||||
\(deviate "NO_EFFECT" \
|
||||
"WINPR_ASSERT" \)) \
|
||||
\
|
||||
winpr_internal_assert((cond), (file), (fkt), (line)); \
|
||||
\
|
||||
WINPR_DO_COVERITY_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \
|
||||
"NO_EFFECT") \
|
||||
WINPR_PRAGMA_DIAG_POP \
|
||||
} while (0)
|
||||
#define WINPR_ASSERT(cond) WINPR_ASSERT_AT((cond), __FILE__, __func__, __LINE__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
@ -32,6 +32,12 @@
|
||||
#define WINPR_DO_PRAGMA(x) __pragma(#x)
|
||||
#endif
|
||||
|
||||
#if !defined(__COVERITY__)
|
||||
#define WINPR_DO_COVERITY_PRAGMA(x)
|
||||
#else
|
||||
#define WINPR_DO_COVERITY_PRAGMA(x) WINPR_DO_PRAGMA(x)
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(GCC warning #msg)
|
||||
#elif defined(__clang__)
|
||||
|
Loading…
Reference in New Issue
Block a user