summaryrefslogtreecommitdiff
path: root/src/include/access
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-12-08 14:30:01 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-12-15 10:10:32 +0100
commit75f49221c22286104f032827359783aa5f4e6646 (patch)
treeb4ac92eb6c557b4fd1ef6eda35ce9943564aba11 /src/include/access
parent2613dec4ed67c4a963d987cbd29284e0634b65c9 (diff)
downloadpostgresql-75f49221c22286104f032827359783aa5f4e6646.tar.gz
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/include/access')
-rw-r--r--src/include/access/gin.h3
-rw-r--r--src/include/access/htup_details.h3
-rw-r--r--src/include/access/nbtree.h7
3 files changed, 13 insertions, 0 deletions
diff --git a/src/include/access/gin.h b/src/include/access/gin.h
index fff861e219..119ed685bb 100644
--- a/src/include/access/gin.h
+++ b/src/include/access/gin.h
@@ -57,6 +57,9 @@ typedef struct GinStatsData
*/
typedef char GinTernaryValue;
+StaticAssertDecl(sizeof(GinTernaryValue) == sizeof(bool),
+ "sizes of GinTernaryValue and bool are not equal");
+
#define GIN_FALSE 0 /* item is not present / does not match */
#define GIN_TRUE 1 /* item is present / matches */
#define GIN_MAYBE 2 /* don't know if item is present / don't know
diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h
index 9561c835f2..c1af814e8d 100644
--- a/src/include/access/htup_details.h
+++ b/src/include/access/htup_details.h
@@ -426,6 +426,9 @@ do { \
(tup)->t_choice.t_heap.t_field3.t_xvac = (xid); \
} while (0)
+StaticAssertDecl(MaxOffsetNumber < SpecTokenOffsetNumber,
+ "invalid speculative token constant");
+
#define HeapTupleHeaderIsSpeculative(tup) \
( \
(ItemPointerGetOffsetNumberNoCheck(&(tup)->t_ctid) == SpecTokenOffsetNumber) \
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 8e4f6864e5..7d5a6fa558 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -467,6 +467,13 @@ typedef struct BTVacState
#define BT_IS_POSTING 0x2000
/*
+ * Mask allocated for number of keys in index tuple must be able to fit
+ * maximum possible number of index attributes
+ */
+StaticAssertDecl(BT_OFFSET_MASK >= INDEX_MAX_KEYS,
+ "BT_OFFSET_MASK can't fit INDEX_MAX_KEYS");
+
+/*
* Note: BTreeTupleIsPivot() can have false negatives (but not false
* positives) when used with !heapkeyspace indexes
*/