mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
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
This commit is contained in:
@@ -108,6 +108,9 @@ extern slock_t *ShmemLock;
|
||||
/* Must be greater than MAX_BACKENDS - which is 2^23-1, so we're fine. */
|
||||
#define LW_SHARED_MASK ((uint32) ((1 << 24)-1))
|
||||
|
||||
StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
|
||||
"MAX_BACKENDS too big for lwlock.c");
|
||||
|
||||
/*
|
||||
* There are three sorts of LWLock "tranches":
|
||||
*
|
||||
@@ -466,12 +469,6 @@ LWLockShmemSize(void)
|
||||
void
|
||||
CreateLWLocks(void)
|
||||
{
|
||||
StaticAssertStmt(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
|
||||
"MAX_BACKENDS too big for lwlock.c");
|
||||
|
||||
StaticAssertStmt(sizeof(LWLock) <= LWLOCK_PADDED_SIZE,
|
||||
"Miscalculated LWLock padding");
|
||||
|
||||
if (!IsUnderPostmaster)
|
||||
{
|
||||
Size spaceLocks = LWLockShmemSize();
|
||||
|
@@ -17,6 +17,12 @@
|
||||
#include "storage/itemptr.h"
|
||||
|
||||
|
||||
/*
|
||||
* We really want ItemPointerData to be exactly 6 bytes.
|
||||
*/
|
||||
StaticAssertDecl(sizeof(ItemPointerData) == 3 * sizeof(uint16),
|
||||
"ItemPointerData struct is improperly padded");
|
||||
|
||||
/*
|
||||
* ItemPointerEquals
|
||||
* Returns true if both item pointers point to the same item,
|
||||
@@ -28,13 +34,6 @@
|
||||
bool
|
||||
ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
|
||||
{
|
||||
/*
|
||||
* We really want ItemPointerData to be exactly 6 bytes. This is rather a
|
||||
* random place to check, but there is no better place.
|
||||
*/
|
||||
StaticAssertStmt(sizeof(ItemPointerData) == 3 * sizeof(uint16),
|
||||
"ItemPointerData struct is improperly padded");
|
||||
|
||||
if (ItemPointerGetBlockNumber(pointer1) ==
|
||||
ItemPointerGetBlockNumber(pointer2) &&
|
||||
ItemPointerGetOffsetNumber(pointer1) ==
|
||||
|
Reference in New Issue
Block a user