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

Commit235eb4d

Browse files
committed
Simplify our Assert infrastructure a little.
Remove the Trap and TrapMacro macros, which were nearly unusedand confusingly had the opposite condition polarity from theotherwise-functionally-equivalent Assert macros.Having done that, it's very hard to justify carrying the errorTypeargument of ExceptionalCondition, so drop that too, and justlet it assume everything's an Assert. This saves about 64Kof code space as of current HEAD.Discussion:https://postgr.es/m/3928703.1665345117@sss.pgh.pa.us
1 parent6291b25 commit235eb4d

File tree

5 files changed

+22
-51
lines changed

5 files changed

+22
-51
lines changed

‎contrib/amcheck/verify_heapam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ check_tuple_attribute(HeapCheckContext *ctx)
13191319
*/
13201320

13211321
/*
1322-
* Check that VARTAG_SIZE won't hita TrapMacro on a corrupt va_tag before
1322+
* Check that VARTAG_SIZE won't hitan Assert on a corrupt va_tag before
13231323
* risking a call into att_addlength_pointer
13241324
*/
13251325
if (VARATT_IS_EXTERNAL(tp+ctx->offset))

‎src/backend/utils/error/assert.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@
2828
*/
2929
void
3030
ExceptionalCondition(constchar*conditionName,
31-
constchar*errorType,
3231
constchar*fileName,
3332
intlineNumber)
3433
{
3534
/* Report the failure on stderr (or local equivalent) */
3635
if (!PointerIsValid(conditionName)
37-
|| !PointerIsValid(fileName)
38-
|| !PointerIsValid(errorType))
36+
|| !PointerIsValid(fileName))
3937
write_stderr("TRAP: ExceptionalCondition: bad arguments in PID %d\n",
4038
(int)getpid());
4139
else
42-
write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d, PID: %d)\n",
43-
errorType,conditionName,
44-
fileName,lineNumber, (int)getpid());
40+
write_stderr("TRAP: failed Assert(\"%s\"), File: \"%s\", Line: %d, PID: %d\n",
41+
conditionName,fileName,lineNumber, (int)getpid());
4542

4643
/* Usually this shouldn't be needed, but make sure the msg went out */
4744
fflush(stderr);

‎src/backend/utils/error/elog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,8 +1832,7 @@ pg_re_throw(void)
18321832
}
18331833

18341834
/* Doesn't return ... */
1835-
ExceptionalCondition("pg_re_throw tried to return","FailedAssertion",
1836-
__FILE__,__LINE__);
1835+
ExceptionalCondition("pg_re_throw tried to return",__FILE__,__LINE__);
18371836
}
18381837

18391838

‎src/include/c.h

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,6 @@ typedef NameData *Name;
796796
#defineAssertArg(condition)((void)true)
797797
#defineAssertState(condition)((void)true)
798798
#defineAssertPointerAlignment(ptr,bndr)((void)true)
799-
#defineTrap(condition,errorType)((void)true)
800-
#defineTrapMacro(condition,errorType) (true)
801799

802800
#elif defined(FRONTEND)
803801

@@ -811,60 +809,38 @@ typedef NameData *Name;
811809
#else/* USE_ASSERT_CHECKING && !FRONTEND */
812810

813811
/*
814-
*Trap
815-
*Generatesanexception if the given condition istrue.
812+
*Assert
813+
*Generatesa fatalexception if the given condition isfalse.
816814
*/
817-
#defineTrap(condition,errorType) \
815+
#defineAssert(condition) \
818816
do { \
819-
if (condition) \
820-
ExceptionalCondition(#condition, (errorType), \
821-
__FILE__, __LINE__); \
817+
if (!(condition)) \
818+
ExceptionalCondition(#condition, __FILE__, __LINE__); \
822819
} while (0)
823820

824821
/*
825-
*TrapMacro is the same as Trap but it's intended for use in macros:
822+
* AssertMacro is the same as Assert but it's suitable for use in
823+
* expression-like macros, for example:
826824
*
827825
*#define foo(x) (AssertMacro(x != 0), bar(x))
828-
*
829-
*Isn't CPP fun?
830826
*/
831-
#defineTrapMacro(condition,errorType) \
832-
((bool) (! (condition) || \
833-
(ExceptionalCondition(#condition, (errorType), \
834-
__FILE__, __LINE__), 0)))
835-
836-
#defineAssert(condition) \
837-
do { \
838-
if (!(condition)) \
839-
ExceptionalCondition(#condition, "FailedAssertion", \
840-
__FILE__, __LINE__); \
841-
} while (0)
842-
843827
#defineAssertMacro(condition) \
844828
((void) ((condition) || \
845-
(ExceptionalCondition(#condition, "FailedAssertion", \
846-
__FILE__, __LINE__), 0)))
829+
(ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
847830

848-
#defineAssertArg(condition) \
849-
do { \
850-
if (!(condition)) \
851-
ExceptionalCondition(#condition, "BadArgument", \
852-
__FILE__, __LINE__); \
853-
} while (0)
854-
855-
#defineAssertState(condition) \
856-
do { \
857-
if (!(condition)) \
858-
ExceptionalCondition(#condition, "BadState", \
859-
__FILE__, __LINE__); \
860-
} while (0)
831+
/*
832+
* AssertArg and AssertState are identical to Assert. Some places use them
833+
* to indicate that the complaint is specifically about a bad argument or
834+
* unexpected state, but this usage is largely obsolescent.
835+
*/
836+
#defineAssertArg(condition) Assert(condition)
837+
#defineAssertState(condition) Assert(condition)
861838

862839
/*
863840
* Check that `ptr' is `bndr' aligned.
864841
*/
865842
#defineAssertPointerAlignment(ptr,bndr) \
866-
Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \
867-
"UnalignedPointer")
843+
Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
868844

869845
#endif/* USE_ASSERT_CHECKING && !FRONTEND */
870846

@@ -876,7 +852,6 @@ typedef NameData *Name;
876852
*/
877853
#ifndefFRONTEND
878854
externvoidExceptionalCondition(constchar*conditionName,
879-
constchar*errorType,
880855
constchar*fileName,intlineNumber)pg_attribute_noreturn();
881856
#endif
882857

‎src/include/postgres.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ typedef enum vartag_external
135135
((tag) == VARTAG_INDIRECT ? sizeof(varatt_indirect) : \
136136
VARTAG_IS_EXPANDED(tag) ? sizeof(varatt_expanded) : \
137137
(tag) == VARTAG_ONDISK ? sizeof(varatt_external) : \
138-
TrapMacro(true, "unrecognized TOAST vartag"))
138+
(AssertMacro(false), 0))
139139

140140
/*
141141
* These structs describe the header of a varlena object that may have been

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp