Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd78d452

Browse files
committed
Improve Assert output
If an assertion expression contained a macro, the failed assertionmessage would print the expanded macro, which is usually unhelpful andconfusing. Restructure the Assert macros to not expand any macroswhen constructing the failure message.This also fixes that the existing output for Assert et al. showsthe *inverted* condition, which is also confusing and not howassertions usually work.Discussion:https://www.postgresql.org/message-id/flat/6c68efe3-117a-dcc1-73d4-18ba1ec532e2%402ndquadrant.com
1 parentf7db0ac commitd78d452

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

‎src/include/c.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ typedef NameData *Name;
755755
#defineTrap(condition,errorType) \
756756
do { \
757757
if (condition) \
758-
ExceptionalCondition(CppAsString(condition), (errorType), \
758+
ExceptionalCondition(#condition, (errorType), \
759759
__FILE__, __LINE__); \
760760
} while (0)
761761

@@ -768,20 +768,34 @@ typedef NameData *Name;
768768
*/
769769
#defineTrapMacro(condition,errorType) \
770770
((bool) (! (condition) || \
771-
(ExceptionalCondition(CppAsString(condition), (errorType), \
771+
(ExceptionalCondition(#condition, (errorType), \
772772
__FILE__, __LINE__), 0)))
773773

774774
#defineAssert(condition) \
775-
Trap(!(condition), "FailedAssertion")
775+
do { \
776+
if (!(condition)) \
777+
ExceptionalCondition(#condition, "FailedAssertion", \
778+
__FILE__, __LINE__); \
779+
} while (0)
776780

777781
#defineAssertMacro(condition) \
778-
((void) TrapMacro(!(condition), "FailedAssertion"))
782+
((void) ((condition) || \
783+
(ExceptionalCondition(#condition, "FailedAssertion", \
784+
__FILE__, __LINE__), 0)))
779785

780786
#defineAssertArg(condition) \
781-
Trap(!(condition), "BadArgument")
787+
do { \
788+
if (!(condition)) \
789+
ExceptionalCondition(#condition, "BadArgument", \
790+
__FILE__, __LINE__); \
791+
} while (0)
782792

783793
#defineAssertState(condition) \
784-
Trap(!(condition), "BadState")
794+
do { \
795+
if (!(condition)) \
796+
ExceptionalCondition(#condition, "BadState", \
797+
__FILE__, __LINE__); \
798+
} while (0)
785799

786800
/*
787801
* Check that `ptr' is `bndr' aligned.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp