summaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorPeter Eisentraut2022-12-08 13:30:01 +0000
committerPeter Eisentraut2022-12-15 09:10:32 +0000
commit75f49221c22286104f032827359783aa5f4e6646 (patch)
treeb4ac92eb6c557b4fd1ef6eda35ce9943564aba11 /src/backend/access
parent2613dec4ed67c4a963d987cbd29284e0634b65c9 (diff)
Static assertions cleanup
Because we added StaticAssertStmt() first before StaticAssertDecl(), some uses as well as the instructions in c.h are now a bit backwards from the "native" way static assertions are meant to be used in C. This updates the guidance and moves some static assertions to better places. Specifically, since the addition of StaticAssertDecl(), we can put static assertions at the file level. This moves a number of static assertions out of function bodies, where they might have been stuck out of necessity, to perhaps better places at the file level or in header files. Also, when the static assertion appears in a position where a declaration is allowed, then using StaticAssertDecl() is more native than StaticAssertStmt(). Reviewed-by: John Naylor <john.naylor@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/941a04e7-dd6f-c0e4-8cdf-a33b3338cbda%40enterprisedb.com
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/heap/heapam.c6
-rw-r--r--src/backend/access/nbtree/nbtutils.c7
-rw-r--r--src/backend/access/transam/clog.c2
-rw-r--r--src/backend/access/transam/xlog.c9
4 files changed, 2 insertions, 22 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 747db503761..42756a9e6df 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -5783,10 +5783,6 @@ heap_finish_speculative(Relation relation, ItemPointer tid)
htup = (HeapTupleHeader) PageGetItem(page, lp);
- /* SpecTokenOffsetNumber should be distinguishable from any real offset */
- StaticAssertStmt(MaxOffsetNumber < SpecTokenOffsetNumber,
- "invalid speculative token constant");
-
/* NO EREPORT(ERROR) from here till changes are logged */
START_CRIT_SECTION();
@@ -7921,7 +7917,7 @@ index_delete_sort(TM_IndexDeleteOp *delstate)
const int gaps[9] = {1968, 861, 336, 112, 48, 21, 7, 3, 1};
/* Think carefully before changing anything here -- keep swaps cheap */
- StaticAssertStmt(sizeof(TM_IndexDelete) <= 8,
+ StaticAssertDecl(sizeof(TM_IndexDelete) <= 8,
"element size exceeds 8 bytes");
for (int g = 0; g < lengthof(gaps); g++)
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index ff260c393ab..10f13e6d415 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -2486,13 +2486,6 @@ _bt_check_natts(Relation rel, bool heapkeyspace, Page page, OffsetNumber offnum)
Assert(offnum >= FirstOffsetNumber &&
offnum <= PageGetMaxOffsetNumber(page));
- /*
- * Mask allocated for number of keys in index tuple must be able to fit
- * maximum possible number of index attributes
- */
- StaticAssertStmt(BT_OFFSET_MASK >= INDEX_MAX_KEYS,
- "BT_OFFSET_MASK can't fit INDEX_MAX_KEYS");
-
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
tupnatts = BTreeTupleGetNAtts(itup, rel);
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index 77d9894dab3..8832efc7c11 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -275,7 +275,7 @@ TransactionIdSetPageStatus(TransactionId xid, int nsubxids,
bool all_xact_same_page)
{
/* Can't use group update when PGPROC overflows. */
- StaticAssertStmt(THRESHOLD_SUBTRANS_CLOG_OPT <= PGPROC_MAX_CACHED_SUBXIDS,
+ StaticAssertDecl(THRESHOLD_SUBTRANS_CLOG_OPT <= PGPROC_MAX_CACHED_SUBXIDS,
"group clog threshold less than PGPROC cached subxids");
/*
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a31fbbff78d..91473b00d90 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -3884,15 +3884,6 @@ WriteControlFile(void)
char buffer[PG_CONTROL_FILE_SIZE]; /* need not be aligned */
/*
- * Ensure that the size of the pg_control data structure is sane. See the
- * comments for these symbols in pg_control.h.
- */
- StaticAssertStmt(sizeof(ControlFileData) <= PG_CONTROL_MAX_SAFE_SIZE,
- "pg_control is too large for atomic disk writes");
- StaticAssertStmt(sizeof(ControlFileData) <= PG_CONTROL_FILE_SIZE,
- "sizeof(ControlFileData) exceeds PG_CONTROL_FILE_SIZE");
-
- /*
* Initialize version and compatibility-check fields
*/
ControlFile->pg_control_version = PG_CONTROL_VERSION;