mirror of
https://github.com/postgres/postgres.git
synced 2025-12-13 14:22:43 +03:00
Replace most StaticAssertStmt() with StaticAssertDecl()
Similar to commit 75f49221c2, it is preferable to use
StaticAssertDecl() instead of StaticAssertStmt() when possible.
Discussion: https://www.postgresql.org/message-id/flat/CA%2BhUKGKvr0x_oGmQTUkx%3DODgSksT2EtgCA6LmGx_jQFG%3DsDUpg%40mail.gmail.com
This commit is contained in:
@@ -94,7 +94,7 @@
|
|||||||
* etc. are compatible.
|
* etc. are compatible.
|
||||||
*
|
*
|
||||||
* If the above statement isn't true on some bizarre platform, we're
|
* If the above statement isn't true on some bizarre platform, we're
|
||||||
* a bit hosed (see StaticAssertStmt in hstoreValidOldFormat).
|
* a bit hosed.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -105,6 +105,9 @@ typedef struct
|
|||||||
pos:31;
|
pos:31;
|
||||||
} HOldEntry;
|
} HOldEntry;
|
||||||
|
|
||||||
|
StaticAssertDecl(sizeof(HOldEntry) == 2 * sizeof(HEntry),
|
||||||
|
"old hstore format is not upward-compatible");
|
||||||
|
|
||||||
static int hstoreValidNewFormat(HStore *hs);
|
static int hstoreValidNewFormat(HStore *hs);
|
||||||
static int hstoreValidOldFormat(HStore *hs);
|
static int hstoreValidOldFormat(HStore *hs);
|
||||||
|
|
||||||
@@ -179,10 +182,6 @@ hstoreValidOldFormat(HStore *hs)
|
|||||||
if (hs->size_ & HS_FLAG_NEWVERSION)
|
if (hs->size_ & HS_FLAG_NEWVERSION)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* New format uses an HEntry for key and another for value */
|
|
||||||
StaticAssertStmt(sizeof(HOldEntry) == 2 * sizeof(HEntry),
|
|
||||||
"old hstore format is not upward-compatible");
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
|
|||||||
@@ -3388,6 +3388,9 @@ lazy_truncate_heap(LVRelState *vacrel)
|
|||||||
static BlockNumber
|
static BlockNumber
|
||||||
count_nondeletable_pages(LVRelState *vacrel, bool *lock_waiter_detected)
|
count_nondeletable_pages(LVRelState *vacrel, bool *lock_waiter_detected)
|
||||||
{
|
{
|
||||||
|
StaticAssertDecl((PREFETCH_SIZE & (PREFETCH_SIZE - 1)) == 0,
|
||||||
|
"prefetch size must be power of 2");
|
||||||
|
|
||||||
BlockNumber blkno;
|
BlockNumber blkno;
|
||||||
BlockNumber prefetchedUntil;
|
BlockNumber prefetchedUntil;
|
||||||
instr_time starttime;
|
instr_time starttime;
|
||||||
@@ -3402,8 +3405,6 @@ count_nondeletable_pages(LVRelState *vacrel, bool *lock_waiter_detected)
|
|||||||
* in forward direction, so that OS-level readahead can kick in.
|
* in forward direction, so that OS-level readahead can kick in.
|
||||||
*/
|
*/
|
||||||
blkno = vacrel->rel_pages;
|
blkno = vacrel->rel_pages;
|
||||||
StaticAssertStmt((PREFETCH_SIZE & (PREFETCH_SIZE - 1)) == 0,
|
|
||||||
"prefetch size must be power of 2");
|
|
||||||
prefetchedUntil = InvalidBlockNumber;
|
prefetchedUntil = InvalidBlockNumber;
|
||||||
while (blkno > vacrel->nonempty_pages)
|
while (blkno > vacrel->nonempty_pages)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -462,15 +462,15 @@ table_block_parallelscan_startblock_init(Relation rel,
|
|||||||
BlockNumber startblock,
|
BlockNumber startblock,
|
||||||
BlockNumber numblocks)
|
BlockNumber numblocks)
|
||||||
{
|
{
|
||||||
|
StaticAssertDecl(MaxBlockNumber <= 0xFFFFFFFE,
|
||||||
|
"pg_nextpower2_32 may be too small for non-standard BlockNumber width");
|
||||||
|
|
||||||
BlockNumber sync_startpage = InvalidBlockNumber;
|
BlockNumber sync_startpage = InvalidBlockNumber;
|
||||||
BlockNumber scan_nblocks;
|
BlockNumber scan_nblocks;
|
||||||
|
|
||||||
/* Reset the state we use for controlling allocation size. */
|
/* Reset the state we use for controlling allocation size. */
|
||||||
memset(pbscanwork, 0, sizeof(*pbscanwork));
|
memset(pbscanwork, 0, sizeof(*pbscanwork));
|
||||||
|
|
||||||
StaticAssertStmt(MaxBlockNumber <= 0xFFFFFFFE,
|
|
||||||
"pg_nextpower2_32 may be too small for non-standard BlockNumber width");
|
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
/* Grab the spinlock. */
|
/* Grab the spinlock. */
|
||||||
SpinLockAcquire(&pbscan->phs_mutex);
|
SpinLockAcquire(&pbscan->phs_mutex);
|
||||||
|
|||||||
@@ -266,6 +266,10 @@ InitializeParallelDSM(ParallelContext *pcxt)
|
|||||||
|
|
||||||
if (pcxt->nworkers > 0)
|
if (pcxt->nworkers > 0)
|
||||||
{
|
{
|
||||||
|
StaticAssertDecl(BUFFERALIGN(PARALLEL_ERROR_QUEUE_SIZE) ==
|
||||||
|
PARALLEL_ERROR_QUEUE_SIZE,
|
||||||
|
"parallel error queue size not buffer-aligned");
|
||||||
|
|
||||||
/* Estimate space for various kinds of state sharing. */
|
/* Estimate space for various kinds of state sharing. */
|
||||||
library_len = EstimateLibraryStateSpace();
|
library_len = EstimateLibraryStateSpace();
|
||||||
shm_toc_estimate_chunk(&pcxt->estimator, library_len);
|
shm_toc_estimate_chunk(&pcxt->estimator, library_len);
|
||||||
@@ -297,9 +301,6 @@ InitializeParallelDSM(ParallelContext *pcxt)
|
|||||||
shm_toc_estimate_keys(&pcxt->estimator, 12);
|
shm_toc_estimate_keys(&pcxt->estimator, 12);
|
||||||
|
|
||||||
/* Estimate space need for error queues. */
|
/* Estimate space need for error queues. */
|
||||||
StaticAssertStmt(BUFFERALIGN(PARALLEL_ERROR_QUEUE_SIZE) ==
|
|
||||||
PARALLEL_ERROR_QUEUE_SIZE,
|
|
||||||
"parallel error queue size not buffer-aligned");
|
|
||||||
shm_toc_estimate_chunk(&pcxt->estimator,
|
shm_toc_estimate_chunk(&pcxt->estimator,
|
||||||
mul_size(PARALLEL_ERROR_QUEUE_SIZE,
|
mul_size(PARALLEL_ERROR_QUEUE_SIZE,
|
||||||
pcxt->nworkers));
|
pcxt->nworkers));
|
||||||
|
|||||||
@@ -7149,9 +7149,9 @@ buffer_readv_encode_error(PgAioResult *result,
|
|||||||
error_count > 0 ? error_count : zeroed_count;
|
error_count > 0 ? error_count : zeroed_count;
|
||||||
uint8 first_off;
|
uint8 first_off;
|
||||||
|
|
||||||
StaticAssertStmt(PG_IOV_MAX <= 1 << READV_COUNT_BITS,
|
StaticAssertDecl(PG_IOV_MAX <= 1 << READV_COUNT_BITS,
|
||||||
"PG_IOV_MAX is bigger than reserved space for error data");
|
"PG_IOV_MAX is bigger than reserved space for error data");
|
||||||
StaticAssertStmt((1 + 1 + 3 * READV_COUNT_BITS) <= PGAIO_RESULT_ERROR_BITS,
|
StaticAssertDecl((1 + 1 + 3 * READV_COUNT_BITS) <= PGAIO_RESULT_ERROR_BITS,
|
||||||
"PGAIO_RESULT_ERROR_BITS is insufficient for buffer_readv");
|
"PGAIO_RESULT_ERROR_BITS is insufficient for buffer_readv");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1111,23 +1111,6 @@ BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)
|
|||||||
|
|
||||||
tryAgain:
|
tryAgain:
|
||||||
#ifdef PG_O_DIRECT_USE_F_NOCACHE
|
#ifdef PG_O_DIRECT_USE_F_NOCACHE
|
||||||
|
|
||||||
/*
|
|
||||||
* The value we defined to stand in for O_DIRECT when simulating it with
|
|
||||||
* F_NOCACHE had better not collide with any of the standard flags.
|
|
||||||
*/
|
|
||||||
StaticAssertStmt((PG_O_DIRECT &
|
|
||||||
(O_APPEND |
|
|
||||||
O_CLOEXEC |
|
|
||||||
O_CREAT |
|
|
||||||
O_DSYNC |
|
|
||||||
O_EXCL |
|
|
||||||
O_RDWR |
|
|
||||||
O_RDONLY |
|
|
||||||
O_SYNC |
|
|
||||||
O_TRUNC |
|
|
||||||
O_WRONLY)) == 0,
|
|
||||||
"PG_O_DIRECT value collides with standard flag");
|
|
||||||
fd = open(fileName, fileFlags & ~PG_O_DIRECT, fileMode);
|
fd = open(fileName, fileFlags & ~PG_O_DIRECT, fileMode);
|
||||||
#else
|
#else
|
||||||
fd = open(fileName, fileFlags, fileMode);
|
fd = open(fileName, fileFlags, fileMode);
|
||||||
|
|||||||
@@ -462,7 +462,6 @@ CreateWaitEventSet(ResourceOwner resowner, int nevents)
|
|||||||
* pending signals are serviced.
|
* pending signals are serviced.
|
||||||
*/
|
*/
|
||||||
set->handles[0] = pgwin32_signal_event;
|
set->handles[0] = pgwin32_signal_event;
|
||||||
StaticAssertStmt(WSA_INVALID_EVENT == NULL, "");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
@@ -979,6 +978,8 @@ WaitEventAdjustKqueue(WaitEventSet *set, WaitEvent *event, int old_events)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WAIT_USE_WIN32)
|
#if defined(WAIT_USE_WIN32)
|
||||||
|
StaticAssertDecl(WSA_INVALID_EVENT == NULL, "");
|
||||||
|
|
||||||
static void
|
static void
|
||||||
WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event)
|
WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ macaddr_abbrev_convert(Datum original, SortSupport ssup)
|
|||||||
* There will be two bytes of zero padding on the end of the least
|
* There will be two bytes of zero padding on the end of the least
|
||||||
* significant bits.
|
* significant bits.
|
||||||
*/
|
*/
|
||||||
StaticAssertStmt(sizeof(res) >= sizeof(macaddr),
|
StaticAssertDecl(sizeof(res) >= sizeof(macaddr),
|
||||||
"Datum is too small for macaddr");
|
"Datum is too small for macaddr");
|
||||||
memset(&res, 0, sizeof(res));
|
memset(&res, 0, sizeof(res));
|
||||||
memcpy(&res, authoritative, sizeof(macaddr));
|
memcpy(&res, authoritative, sizeof(macaddr));
|
||||||
|
|||||||
2
src/backend/utils/cache/inval.c
vendored
2
src/backend/utils/cache/inval.c
vendored
@@ -1753,7 +1753,7 @@ CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
|
|||||||
SharedInvalidationMessage msg;
|
SharedInvalidationMessage msg;
|
||||||
|
|
||||||
/* verify optimization stated above stays valid */
|
/* verify optimization stated above stays valid */
|
||||||
StaticAssertStmt(MAX_BACKENDS_BITS <= 23,
|
StaticAssertDecl(MAX_BACKENDS_BITS <= 23,
|
||||||
"MAX_BACKENDS_BITS is too big for inval.c");
|
"MAX_BACKENDS_BITS is too big for inval.c");
|
||||||
|
|
||||||
msg.sm.id = SHAREDINVALSMGR_ID;
|
msg.sm.id = SHAREDINVALSMGR_ID;
|
||||||
|
|||||||
@@ -92,6 +92,22 @@ extern PGDLLIMPORT int max_safe_fds;
|
|||||||
#elif defined(F_NOCACHE)
|
#elif defined(F_NOCACHE)
|
||||||
#define PG_O_DIRECT 0x80000000
|
#define PG_O_DIRECT 0x80000000
|
||||||
#define PG_O_DIRECT_USE_F_NOCACHE
|
#define PG_O_DIRECT_USE_F_NOCACHE
|
||||||
|
/*
|
||||||
|
* The value we defined to stand in for O_DIRECT when simulating it with
|
||||||
|
* F_NOCACHE had better not collide with any of the standard flags.
|
||||||
|
*/
|
||||||
|
StaticAssertDecl((PG_O_DIRECT &
|
||||||
|
(O_APPEND |
|
||||||
|
O_CLOEXEC |
|
||||||
|
O_CREAT |
|
||||||
|
O_DSYNC |
|
||||||
|
O_EXCL |
|
||||||
|
O_RDWR |
|
||||||
|
O_RDONLY |
|
||||||
|
O_SYNC |
|
||||||
|
O_TRUNC |
|
||||||
|
O_WRONLY)) == 0,
|
||||||
|
"PG_O_DIRECT value collides with standard flag");
|
||||||
#else
|
#else
|
||||||
#define PG_O_DIRECT 0
|
#define PG_O_DIRECT 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user