]> granicus.if.org Git - postgresql/commitdiff
Fix most -Wundef warnings
authorPeter Eisentraut <peter@eisentraut.org>
Sat, 19 Oct 2019 16:21:58 +0000 (18:21 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sat, 19 Oct 2019 16:31:38 +0000 (18:31 +0200)
In some cases #if was used instead of #ifdef in an inconsistent style.
Cleaning this up also helps when analyzing cases like
38d8dce61fff09daae0edb6bcdd42b0c7f10ebcd 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

contrib/hstore/hstore_compat.c
contrib/pg_standby/pg_standby.c
contrib/pgcrypto/imath.c
src/backend/libpq/be-fsstubs.c
src/backend/replication/logical/reorderbuffer.c
src/backend/storage/file/fd.c
src/backend/utils/hash/dynahash.c
src/backend/utils/mmgr/freepage.c
src/include/port/pg_bswap.h
src/port/snprintf.c
src/port/win32error.c

index 1d4e7484e4d95877fefe18dad24e20177168491a..d75e9cb23f5cdc4801fe777d0d52c53d16b87c11 100644 (file)
@@ -299,7 +299,7 @@ hstoreUpgrade(Datum orig)
 
        if (valid_new)
        {
-#if HSTORE_IS_HSTORE_NEW
+#ifdef HSTORE_IS_HSTORE_NEW
                elog(WARNING, "ambiguous hstore value resolved as hstore-new");
 
                /*
index 031b1b5cd5846263e7fbb28f52cec7308c9bdf39..9fae146dd6419d3a30c4190803655a4cee8cd08d 100644 (file)
@@ -145,7 +145,7 @@ CustomizableInitialize(void)
        switch (restoreCommandType)
        {
                case RESTORE_COMMAND_LINK:
-#if HAVE_WORKING_LINK
+#ifdef HAVE_WORKING_LINK
                        SET_RESTORE_COMMAND("ln -s -f", WALFilePath, xlogFilePath);
                        break;
 #endif
index 6936d2cdcaf04e004f0c8bcfe9bdf41db99a6a10..545f148a76a7a091d3c335083bec079042c30610 100644 (file)
@@ -2361,12 +2361,12 @@ s_ucmp(mp_int a, mp_int b)
 static int
 s_vcmp(mp_int a, mp_small v)
 {
-#if _MSC_VER
+#ifdef _MSC_VER
 #pragma warning(push)
 #pragma warning(disable: 4146)
 #endif
        mp_usmall       uv = (v < 0) ? -(mp_usmall) v : (mp_usmall) v;
-#if _MSC_VER
+#ifdef _MSC_VER
 #pragma warning(pop)
 #endif
 
index a750f921fa157a0ec41733c28da5f97ba51fcf34..b0ece7ec25752a124d3e75ed31f057e8cd6543a2 100644 (file)
@@ -95,7 +95,7 @@ be_lo_open(PG_FUNCTION_ARGS)
        LargeObjectDesc *lobjDesc;
        int                     fd;
 
-#if FSDB
+#ifdef FSDB
        elog(DEBUG4, "lo_open(%u,%d)", lobjId, mode);
 #endif
 
@@ -118,7 +118,7 @@ be_lo_close(PG_FUNCTION_ARGS)
                                (errcode(ERRCODE_UNDEFINED_OBJECT),
                                 errmsg("invalid large-object descriptor: %d", fd)));
 
-#if FSDB
+#ifdef FSDB
        elog(DEBUG4, "lo_close(%d)", fd);
 #endif
 
index 8ce28ad6297410b19f96dc870d4c722e2d150daf..62e54240ec1a74c011050895a1e171673f6e654c 100644 (file)
@@ -3247,7 +3247,7 @@ typedef struct RewriteMappingFile
        char            fname[MAXPGPATH];
 } RewriteMappingFile;
 
-#if NOT_USED
+#ifdef NOT_USED
 static void
 DisplayMapping(HTAB *tuplecid_data)
 {
index 94be62fa6ece838a48de9de36f408ea4753fc993..fe2bb8f8596f97401a28b4eeb8e8ecbdf3d28cc7 100644 (file)
@@ -738,7 +738,7 @@ durable_link_or_rename(const char *oldfile, const char *newfile, int elevel)
        if (fsync_fname_ext(oldfile, false, false, elevel) != 0)
                return -1;
 
-#if HAVE_WORKING_LINK
+#ifdef HAVE_WORKING_LINK
        if (link(oldfile, newfile) < 0)
        {
                ereport(elevel,
index 0dfbec8e3ecf246a406766dc887f027525261a9e..de16adef17e40b33c11dd5fef73b2db310c80ca5 100644 (file)
@@ -243,7 +243,7 @@ struct HTAB
  */
 #define MOD(x,y)                          ((x) & ((y)-1))
 
-#if HASH_STATISTICS
+#ifdef HASH_STATISTICS
 static long hash_accesses,
                        hash_collisions,
                        hash_expansions;
@@ -706,7 +706,7 @@ init_htab(HTAB *hashp, long nelem)
        /* Choose number of entries to allocate at a time */
        hctl->nelem_alloc = choose_nelem_alloc(hctl->entrysize);
 
-#if HASH_DEBUG
+#ifdef HASH_DEBUG
        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",
                        "TABLE POINTER   ", hashp,
                        "DIRECTORY SIZE  ", hctl->dsize,
@@ -832,7 +832,7 @@ hash_destroy(HTAB *hashp)
 void
 hash_stats(const char *where, HTAB *hashp)
 {
-#if HASH_STATISTICS
+#ifdef HASH_STATISTICS
        fprintf(stderr, "%s: this HTAB -- accesses %ld collisions %ld\n",
                        where, hashp->hctl->accesses, hashp->hctl->collisions);
 
@@ -933,7 +933,7 @@ hash_search_with_hash_value(HTAB *hashp,
        HASHBUCKET *prevBucketPtr;
        HashCompareFunc match;
 
-#if HASH_STATISTICS
+#ifdef HASH_STATISTICS
        hash_accesses++;
        hctl->accesses++;
 #endif
@@ -988,7 +988,7 @@ hash_search_with_hash_value(HTAB *hashp,
                        break;
                prevBucketPtr = &(currBucket->link);
                currBucket = *prevBucketPtr;
-#if HASH_STATISTICS
+#ifdef HASH_STATISTICS
                hash_collisions++;
                hctl->collisions++;
 #endif
@@ -1130,7 +1130,7 @@ hash_update_hash_key(HTAB *hashp,
        HASHBUCKET *oldPrevPtr;
        HashCompareFunc match;
 
-#if HASH_STATISTICS
+#ifdef HASH_STATISTICS
        hash_accesses++;
        hctl->accesses++;
 #endif
@@ -1204,7 +1204,7 @@ hash_update_hash_key(HTAB *hashp,
                        break;
                prevBucketPtr = &(currBucket->link);
                currBucket = *prevBucketPtr;
-#if HASH_STATISTICS
+#ifdef HASH_STATISTICS
                hash_collisions++;
                hctl->collisions++;
 #endif
index ba3bc20ef1784d3e0efbedab8075a843a3531a08..faf5d10158bfa0420b77259776883b13455ed1ef 100644 (file)
@@ -164,7 +164,7 @@ static void FreePagePushSpanLeader(FreePageManager *fpm, Size first_page,
 static Size FreePageManagerLargestContiguous(FreePageManager *fpm);
 static void FreePageManagerUpdateLargest(FreePageManager *fpm);
 
-#if FPM_EXTRA_ASSERTS
+#ifdef FPM_EXTRA_ASSERTS
 static Size sum_free_pages(FreePageManager *fpm);
 #endif
 
index dbf9df615592c0d61aeee85e3f94766633479bbd..d2e0605a6626e48e6125062a77d95fdce418da7d 100644 (file)
@@ -139,7 +139,14 @@ pg_bswap64(uint64 x)
  * the same result as a memcmp() of the corresponding original Datums, but can
  * be much cheaper.  It's generally safe to do this on big-endian systems
  * without any special transformation occurring first.
+ *
+ * If SIZEOF_DATUM is not defined, then postgres.h wasn't included and these
+ * macros probably shouldn't be used, so we define nothing.  Note that
+ * SIZEOF_DATUM == 8 would evaluate as 0 == 8 in that case, potentially
+ * leading to the wrong implementation being selected and confusing errors, so
+ * defining nothing is safest.
  */
+#ifdef SIZEOF_DATUM
 #ifdef WORDS_BIGENDIAN
 #define                DatumBigEndianToNative(x)       (x)
 #else                                                  /* !WORDS_BIGENDIAN */
@@ -149,5 +156,6 @@ pg_bswap64(uint64 x)
 #define                DatumBigEndianToNative(x)       pg_bswap32(x)
 #endif                                                 /* SIZEOF_DATUM == 8 */
 #endif                                                 /* WORDS_BIGENDIAN */
+#endif                                                 /* SIZEOF_DATUM */
 
 #endif                                                 /* PG_BSWAP_H */
index 8fd997553eb567b24f6913c360d0aa6c0f350baf..e4bb15dfec1879cdc17e47aa46d846a85276151c 100644 (file)
@@ -1052,7 +1052,7 @@ fmtint(long long value, char type, int forcesign, int leftjust,
        }
 
        /* disable MSVC warning about applying unary minus to an unsigned value */
-#if _MSC_VER
+#ifdef _MSC_VER
 #pragma warning(push)
 #pragma warning(disable: 4146)
 #endif
@@ -1061,7 +1061,7 @@ fmtint(long long value, char type, int forcesign, int leftjust,
                uvalue = -(unsigned long long) value;
        else
                uvalue = (unsigned long long) value;
-#if _MSC_VER
+#ifdef _MSC_VER
 #pragma warning(pop)
 #endif
 
index 7fd29eab3771d2bf3cfeb5bb3538bb6ff9724375..f0582c8dad4e46790ef7d37517333bdb172067de 100644 (file)
@@ -188,7 +188,7 @@ _dosmaperr(unsigned long e)
                        ereport(DEBUG5,
                                        (errmsg_internal("mapped win32 error code %lu to %d",
                                                                         e, doserr)));
-#elif FRONTEND_DEBUG
+#elif defined(FRONTEND_DEBUG)
                        fprintf(stderr, "mapped win32 error code %lu to %d", e, doserr);
 #endif
                        errno = doserr;