Skip to content

Commit 5d3587d

Browse files
committed
Fix most -Wundef warnings
In some cases #if was used instead of #ifdef in an inconsistent style. Cleaning this up also helps when analyzing cases like 38d8dce where this makes a difference. There are no behavior changes here, but the change in pg_bswap.h would prevent possible accidental misuse by third-party code. Discussion: https://www.postgresql.org/message-id/flat/3b615ca5-c595-3f1d-fdf7-a429e564f614%402ndquadrant.com
1 parent 48cc59e commit 5d3587d

File tree

11 files changed

+27
-19
lines changed

11 files changed

+27
-19
lines changed

contrib/hstore/hstore_compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ hstoreUpgrade(Datum orig)
299299

300300
if (valid_new)
301301
{
302-
#if HSTORE_IS_HSTORE_NEW
302+
#ifdef HSTORE_IS_HSTORE_NEW
303303
elog(WARNING, "ambiguous hstore value resolved as hstore-new");
304304

305305
/*

contrib/pg_standby/pg_standby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ CustomizableInitialize(void)
145145
switch (restoreCommandType)
146146
{
147147
case RESTORE_COMMAND_LINK:
148-
#if HAVE_WORKING_LINK
148+
#ifdef HAVE_WORKING_LINK
149149
SET_RESTORE_COMMAND("ln -s -f", WALFilePath, xlogFilePath);
150150
break;
151151
#endif

contrib/pgcrypto/imath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,12 +2361,12 @@ s_ucmp(mp_int a, mp_int b)
23612361
static int
23622362
s_vcmp(mp_int a, mp_small v)
23632363
{
2364-
#if _MSC_VER
2364+
#ifdef _MSC_VER
23652365
#pragma warning(push)
23662366
#pragma warning(disable: 4146)
23672367
#endif
23682368
mp_usmall uv = (v < 0) ? -(mp_usmall) v : (mp_usmall) v;
2369-
#if _MSC_VER
2369+
#ifdef _MSC_VER
23702370
#pragma warning(pop)
23712371
#endif
23722372

src/backend/libpq/be-fsstubs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ be_lo_open(PG_FUNCTION_ARGS)
9595
LargeObjectDesc *lobjDesc;
9696
int fd;
9797

98-
#if FSDB
98+
#ifdef FSDB
9999
elog(DEBUG4, "lo_open(%u,%d)", lobjId, mode);
100100
#endif
101101

@@ -118,7 +118,7 @@ be_lo_close(PG_FUNCTION_ARGS)
118118
(errcode(ERRCODE_UNDEFINED_OBJECT),
119119
errmsg("invalid large-object descriptor: %d", fd)));
120120

121-
#if FSDB
121+
#ifdef FSDB
122122
elog(DEBUG4, "lo_close(%d)", fd);
123123
#endif
124124

src/backend/replication/logical/reorderbuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ typedef struct RewriteMappingFile
32473247
char fname[MAXPGPATH];
32483248
} RewriteMappingFile;
32493249

3250-
#if NOT_USED
3250+
#ifdef NOT_USED
32513251
static void
32523252
DisplayMapping(HTAB *tuplecid_data)
32533253
{

src/backend/storage/file/fd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ durable_link_or_rename(const char *oldfile, const char *newfile, int elevel)
738738
if (fsync_fname_ext(oldfile, false, false, elevel) != 0)
739739
return -1;
740740

741-
#if HAVE_WORKING_LINK
741+
#ifdef HAVE_WORKING_LINK
742742
if (link(oldfile, newfile) < 0)
743743
{
744744
ereport(elevel,

src/backend/utils/hash/dynahash.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ struct HTAB
243243
*/
244244
#define MOD(x,y) ((x) & ((y)-1))
245245

246-
#if HASH_STATISTICS
246+
#ifdef HASH_STATISTICS
247247
static long hash_accesses,
248248
hash_collisions,
249249
hash_expansions;
@@ -706,7 +706,7 @@ init_htab(HTAB *hashp, long nelem)
706706
/* Choose number of entries to allocate at a time */
707707
hctl->nelem_alloc = choose_nelem_alloc(hctl->entrysize);
708708

709-
#if HASH_DEBUG
709+
#ifdef HASH_DEBUG
710710
fprintf(stderr, "init_htab:\n%s%p\n%s%ld\n%s%ld\n%s%d\n%s%ld\n%s%u\n%s%x\n%s%x\n%s%ld\n",
711711
"TABLE POINTER ", hashp,
712712
"DIRECTORY SIZE ", hctl->dsize,
@@ -832,7 +832,7 @@ hash_destroy(HTAB *hashp)
832832
void
833833
hash_stats(const char *where, HTAB *hashp)
834834
{
835-
#if HASH_STATISTICS
835+
#ifdef HASH_STATISTICS
836836
fprintf(stderr, "%s: this HTAB -- accesses %ld collisions %ld\n",
837837
where, hashp->hctl->accesses, hashp->hctl->collisions);
838838

@@ -933,7 +933,7 @@ hash_search_with_hash_value(HTAB *hashp,
933933
HASHBUCKET *prevBucketPtr;
934934
HashCompareFunc match;
935935

936-
#if HASH_STATISTICS
936+
#ifdef HASH_STATISTICS
937937
hash_accesses++;
938938
hctl->accesses++;
939939
#endif
@@ -988,7 +988,7 @@ hash_search_with_hash_value(HTAB *hashp,
988988
break;
989989
prevBucketPtr = &(currBucket->link);
990990
currBucket = *prevBucketPtr;
991-
#if HASH_STATISTICS
991+
#ifdef HASH_STATISTICS
992992
hash_collisions++;
993993
hctl->collisions++;
994994
#endif
@@ -1130,7 +1130,7 @@ hash_update_hash_key(HTAB *hashp,
11301130
HASHBUCKET *oldPrevPtr;
11311131
HashCompareFunc match;
11321132

1133-
#if HASH_STATISTICS
1133+
#ifdef HASH_STATISTICS
11341134
hash_accesses++;
11351135
hctl->accesses++;
11361136
#endif
@@ -1204,7 +1204,7 @@ hash_update_hash_key(HTAB *hashp,
12041204
break;
12051205
prevBucketPtr = &(currBucket->link);
12061206
currBucket = *prevBucketPtr;
1207-
#if HASH_STATISTICS
1207+
#ifdef HASH_STATISTICS
12081208
hash_collisions++;
12091209
hctl->collisions++;
12101210
#endif

src/backend/utils/mmgr/freepage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void FreePagePushSpanLeader(FreePageManager *fpm, Size first_page,
164164
static Size FreePageManagerLargestContiguous(FreePageManager *fpm);
165165
static void FreePageManagerUpdateLargest(FreePageManager *fpm);
166166

167-
#if FPM_EXTRA_ASSERTS
167+
#ifdef FPM_EXTRA_ASSERTS
168168
static Size sum_free_pages(FreePageManager *fpm);
169169
#endif
170170

src/include/port/pg_bswap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,14 @@ pg_bswap64(uint64 x)
139139
* the same result as a memcmp() of the corresponding original Datums, but can
140140
* be much cheaper. It's generally safe to do this on big-endian systems
141141
* without any special transformation occurring first.
142+
*
143+
* If SIZEOF_DATUM is not defined, then postgres.h wasn't included and these
144+
* macros probably shouldn't be used, so we define nothing. Note that
145+
* SIZEOF_DATUM == 8 would evaluate as 0 == 8 in that case, potentially
146+
* leading to the wrong implementation being selected and confusing errors, so
147+
* defining nothing is safest.
142148
*/
149+
#ifdef SIZEOF_DATUM
143150
#ifdef WORDS_BIGENDIAN
144151
#define DatumBigEndianToNative(x) (x)
145152
#else /* !WORDS_BIGENDIAN */
@@ -149,5 +156,6 @@ pg_bswap64(uint64 x)
149156
#define DatumBigEndianToNative(x) pg_bswap32(x)
150157
#endif /* SIZEOF_DATUM == 8 */
151158
#endif /* WORDS_BIGENDIAN */
159+
#endif /* SIZEOF_DATUM */
152160

153161
#endif /* PG_BSWAP_H */

src/port/snprintf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ fmtint(long long value, char type, int forcesign, int leftjust,
10521052
}
10531053

10541054
/* disable MSVC warning about applying unary minus to an unsigned value */
1055-
#if _MSC_VER
1055+
#ifdef _MSC_VER
10561056
#pragma warning(push)
10571057
#pragma warning(disable: 4146)
10581058
#endif
@@ -1061,7 +1061,7 @@ fmtint(long long value, char type, int forcesign, int leftjust,
10611061
uvalue = -(unsigned long long) value;
10621062
else
10631063
uvalue = (unsigned long long) value;
1064-
#if _MSC_VER
1064+
#ifdef _MSC_VER
10651065
#pragma warning(pop)
10661066
#endif
10671067

src/port/win32error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ _dosmaperr(unsigned long e)
188188
ereport(DEBUG5,
189189
(errmsg_internal("mapped win32 error code %lu to %d",
190190
e, doserr)));
191-
#elif FRONTEND_DEBUG
191+
#elif defined(FRONTEND_DEBUG)
192192
fprintf(stderr, "mapped win32 error code %lu to %d", e, doserr);
193193
#endif
194194
errno = doserr;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy