Improve Assert output
If an assertion expression contained a macro, the failed assertion message would print the expanded macro, which is usually unhelpful and confusing. Restructure the Assert macros to not expand any macros when constructing the failure message. This also fixes that the existing output for Assert et al. shows the *inverted* condition, which is also confusing and not how assertions usually work. Discussion: https://www.postgresql.org/message-id/flat/6c68efe3-117a-dcc1-73d4-18ba1ec532e2%402ndquadrant.com
This commit is contained in:
parent
f7db0ac7d5
commit
d78d452bc5
@ -755,7 +755,7 @@ typedef NameData *Name;
|
|||||||
#define Trap(condition, errorType) \
|
#define Trap(condition, errorType) \
|
||||||
do { \
|
do { \
|
||||||
if (condition) \
|
if (condition) \
|
||||||
ExceptionalCondition(CppAsString(condition), (errorType), \
|
ExceptionalCondition(#condition, (errorType), \
|
||||||
__FILE__, __LINE__); \
|
__FILE__, __LINE__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -768,20 +768,34 @@ typedef NameData *Name;
|
|||||||
*/
|
*/
|
||||||
#define TrapMacro(condition, errorType) \
|
#define TrapMacro(condition, errorType) \
|
||||||
((bool) (! (condition) || \
|
((bool) (! (condition) || \
|
||||||
(ExceptionalCondition(CppAsString(condition), (errorType), \
|
(ExceptionalCondition(#condition, (errorType), \
|
||||||
__FILE__, __LINE__), 0)))
|
__FILE__, __LINE__), 0)))
|
||||||
|
|
||||||
#define Assert(condition) \
|
#define Assert(condition) \
|
||||||
Trap(!(condition), "FailedAssertion")
|
do { \
|
||||||
|
if (!(condition)) \
|
||||||
|
ExceptionalCondition(#condition, "FailedAssertion", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define AssertMacro(condition) \
|
#define AssertMacro(condition) \
|
||||||
((void) TrapMacro(!(condition), "FailedAssertion"))
|
((void) ((condition) || \
|
||||||
|
(ExceptionalCondition(#condition, "FailedAssertion", \
|
||||||
|
__FILE__, __LINE__), 0)))
|
||||||
|
|
||||||
#define AssertArg(condition) \
|
#define AssertArg(condition) \
|
||||||
Trap(!(condition), "BadArgument")
|
do { \
|
||||||
|
if (!(condition)) \
|
||||||
|
ExceptionalCondition(#condition, "BadArgument", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define AssertState(condition) \
|
#define AssertState(condition) \
|
||||||
Trap(!(condition), "BadState")
|
do { \
|
||||||
|
if (!(condition)) \
|
||||||
|
ExceptionalCondition(#condition, "BadState", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check that `ptr' is `bndr' aligned.
|
* Check that `ptr' is `bndr' aligned.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user