Fix compiler warnings on 64-bit Windows

Started by Peter Eisentrautalmost 6 years ago10 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com
1 attachment(s)

GCC reports various instances of

warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]

and MSVC equivalently

warning C4312: 'type cast': conversion from 'int' to 'void *' of
greater size
warning C4311: 'type cast': pointer truncation from 'void *' to 'long'

in ECPG test files. This is because void* and long are cast back and
forth, but on 64-bit Windows, these have different sizes. Fix by
using intptr_t instead.

The code actually worked fine because the integer values in use are
all small. So this is just to get the test code to compile warning-free.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Fix-compiler-warnings-on-64-bit-Windows.patchtext/plain; charset=UTF-8; name=0001-Fix-compiler-warnings-on-64-bit-Windows.patch; x-mac-creator=0; x-mac-type=0Download
From 9adfcbc45cbe968d1a1230bce7a2891e75038d84 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 13 Feb 2020 15:02:45 +0100
Subject: [PATCH] Fix compiler warnings on 64-bit Windows

GCC reports various instances of

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

and MSVC equivalently

warning C4312: 'type cast': conversion from 'int' to 'void *' of greater size
warning C4311: 'type cast': pointer truncation from 'void *' to 'long'

in ECPG test files.  This is because void* and long are cast back and
forth, but on 64-bit Windows, these have different sizes.  Fix by
using intptr_t instead.

The code actually worked fine because the integer values in use are
all small.  So this is just to get the test code to compile warning-free.
---
 src/interfaces/ecpg/test/expected/thread-alloc.c          | 8 ++++----
 src/interfaces/ecpg/test/expected/thread-prep.c           | 8 ++++----
 src/interfaces/ecpg/test/expected/thread-thread.c         | 8 ++++----
 .../ecpg/test/expected/thread-thread_implicit.c           | 8 ++++----
 src/interfaces/ecpg/test/thread/alloc.pgc                 | 8 ++++----
 src/interfaces/ecpg/test/thread/prep.pgc                  | 8 ++++----
 src/interfaces/ecpg/test/thread/thread.pgc                | 8 ++++----
 src/interfaces/ecpg/test/thread/thread_implicit.pgc       | 8 ++++----
 8 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/interfaces/ecpg/test/expected/thread-alloc.c b/src/interfaces/ecpg/test/expected/thread-alloc.c
index 9678ebe6fd..fdf06fe8e2 100644
--- a/src/interfaces/ecpg/test/expected/thread-alloc.c
+++ b/src/interfaces/ecpg/test/expected/thread-alloc.c
@@ -8,7 +8,7 @@
 
 #line 1 "alloc.pgc"
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -145,7 +145,7 @@ static void* fn(void* arg)
 #line 43 "alloc.pgc"
 
 
-	value = (long)arg;
+	value = (intptr_t) arg;
 	sprintf(name, "Connection: %d", value);
 
 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0); 
@@ -188,7 +188,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 int main ()
 {
-	int i;
+	intptr_t i;
 #ifdef WIN32
 	HANDLE threads[THREADS];
 #else
@@ -207,7 +207,7 @@ int main ()
 		CloseHandle(threads[i]);
 #else
 	for (i = 0; i < THREADS; ++i)
-		pthread_create(&threads[i], NULL, fn, (void *) (long) i);
+		pthread_create(&threads[i], NULL, fn, (void *) i);
 	for (i = 0; i < THREADS; ++i)
 		pthread_join(threads[i], NULL);
 #endif
diff --git a/src/interfaces/ecpg/test/expected/thread-prep.c b/src/interfaces/ecpg/test/expected/thread-prep.c
index 98861d36f0..988b3fc408 100644
--- a/src/interfaces/ecpg/test/expected/thread-prep.c
+++ b/src/interfaces/ecpg/test/expected/thread-prep.c
@@ -8,7 +8,7 @@
 
 #line 1 "prep.pgc"
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -145,7 +145,7 @@ static void* fn(void* arg)
 #line 43 "prep.pgc"
 
 
-	value = (long)arg;
+	value = (intptr_t) arg;
 	sprintf(name, "Connection: %d", value);
 
 	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0); 
@@ -198,7 +198,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 int main ()
 {
-	int i;
+	intptr_t i;
 #ifdef WIN32
 	HANDLE threads[THREADS];
 #else
@@ -248,7 +248,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 		CloseHandle(threads[i]);
 #else
 	for (i = 0; i < THREADS; ++i)
-		pthread_create(&threads[i], NULL, fn, (void *) (long) i);
+		pthread_create(&threads[i], NULL, fn, (void *) i);
 	for (i = 0; i < THREADS; ++i)
 		pthread_join(threads[i], NULL);
 #endif
diff --git a/src/interfaces/ecpg/test/expected/thread-thread.c b/src/interfaces/ecpg/test/expected/thread-thread.c
index 68f153e57c..2516c9f67a 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread.c
+++ b/src/interfaces/ecpg/test/expected/thread-thread.c
@@ -12,7 +12,7 @@
  *	by Philip Yarra & Lee Kindness.
  */
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -52,7 +52,7 @@ int main()
 #else
   HANDLE *threads;
 #endif
-  int n;
+  intptr_t n;
   /* exec sql begin declare section */
    
   
@@ -96,7 +96,7 @@ int main()
   for( n = 0; n < nthreads; n++ )
     {
 #ifndef WIN32
-      pthread_create(&threads[n], NULL, test_thread, (void *) (long) (n + 1));
+      pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
 #else
       threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_thread, (void *) (n + 1), 0, NULL);
 #endif
@@ -138,7 +138,7 @@ int main()
 
 void *test_thread(void *arg)
 {
-  long threadnum = (long)arg;
+  long threadnum = (intptr_t) arg;
 
   /* exec sql begin declare section */
     
diff --git a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
index d035276548..9c5b1deb57 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
+++ b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
@@ -13,7 +13,7 @@
  */
 
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -53,7 +53,7 @@ int main()
 #else
   HANDLE *threads;
 #endif
-  int n;
+  intptr_t n;
   /* exec sql begin declare section */
    
   
@@ -97,7 +97,7 @@ int main()
   for( n = 0; n < nthreads; n++ )
     {
 #ifndef WIN32
-      pthread_create(&threads[n], NULL, test_thread, (void *) (long) (n + 1));
+      pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
 #else
       threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_thread, (void *) (n+1), 0, NULL);
 #endif
@@ -139,7 +139,7 @@ int main()
 
 void *test_thread(void *arg)
 {
-  long threadnum = (long)arg;
+  long threadnum = (intptr_t) arg;
 
   /* exec sql begin declare section */
     
diff --git a/src/interfaces/ecpg/test/thread/alloc.pgc b/src/interfaces/ecpg/test/thread/alloc.pgc
index c44bc91d78..bc20033f01 100644
--- a/src/interfaces/ecpg/test/thread/alloc.pgc
+++ b/src/interfaces/ecpg/test/thread/alloc.pgc
@@ -1,5 +1,5 @@
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -42,7 +42,7 @@ static void* fn(void* arg)
 	char **r = NULL;
 	EXEC SQL END DECLARE SECTION;
 
-	value = (long)arg;
+	value = (intptr_t) arg;
 	sprintf(name, "Connection: %d", value);
 
 	EXEC SQL CONNECT TO REGRESSDB1 AS :name;
@@ -60,7 +60,7 @@ static void* fn(void* arg)
 
 int main ()
 {
-	int i;
+	intptr_t i;
 #ifdef WIN32
 	HANDLE threads[THREADS];
 #else
@@ -79,7 +79,7 @@ int main ()
 		CloseHandle(threads[i]);
 #else
 	for (i = 0; i < THREADS; ++i)
-		pthread_create(&threads[i], NULL, fn, (void *) (long) i);
+		pthread_create(&threads[i], NULL, fn, (void *) i);
 	for (i = 0; i < THREADS; ++i)
 		pthread_join(threads[i], NULL);
 #endif
diff --git a/src/interfaces/ecpg/test/thread/prep.pgc b/src/interfaces/ecpg/test/thread/prep.pgc
index bdf27e7d5a..583114b4cc 100644
--- a/src/interfaces/ecpg/test/thread/prep.pgc
+++ b/src/interfaces/ecpg/test/thread/prep.pgc
@@ -1,5 +1,5 @@
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -42,7 +42,7 @@ static void* fn(void* arg)
 	char query[256] = "INSERT INTO T VALUES ( ? )";
 	EXEC SQL END DECLARE SECTION;
 
-	value = (long)arg;
+	value = (intptr_t) arg;
 	sprintf(name, "Connection: %d", value);
 
 	EXEC SQL CONNECT TO REGRESSDB1 AS :name;
@@ -60,7 +60,7 @@ static void* fn(void* arg)
 
 int main ()
 {
-	int i;
+	intptr_t i;
 #ifdef WIN32
 	HANDLE threads[THREADS];
 #else
@@ -85,7 +85,7 @@ int main ()
 		CloseHandle(threads[i]);
 #else
 	for (i = 0; i < THREADS; ++i)
-		pthread_create(&threads[i], NULL, fn, (void *) (long) i);
+		pthread_create(&threads[i], NULL, fn, (void *) i);
 	for (i = 0; i < THREADS; ++i)
 		pthread_join(threads[i], NULL);
 #endif
diff --git a/src/interfaces/ecpg/test/thread/thread.pgc b/src/interfaces/ecpg/test/thread/thread.pgc
index 0e3217ce63..f5d55e42f7 100644
--- a/src/interfaces/ecpg/test/thread/thread.pgc
+++ b/src/interfaces/ecpg/test/thread/thread.pgc
@@ -3,7 +3,7 @@
  *	by Philip Yarra & Lee Kindness.
  */
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -34,7 +34,7 @@ int main()
 #else
   HANDLE *threads;
 #endif
-  int n;
+  intptr_t n;
   EXEC SQL BEGIN DECLARE SECTION;
   int l_rows;
   EXEC SQL END DECLARE SECTION;
@@ -65,7 +65,7 @@ int main()
   for( n = 0; n < nthreads; n++ )
     {
 #ifndef WIN32
-      pthread_create(&threads[n], NULL, test_thread, (void *) (long) (n + 1));
+      pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
 #else
       threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_thread, (void *) (n + 1), 0, NULL);
 #endif
@@ -97,7 +97,7 @@ int main()
 
 void *test_thread(void *arg)
 {
-  long threadnum = (long)arg;
+  long threadnum = (intptr_t) arg;
 
   EXEC SQL BEGIN DECLARE SECTION;
   int  l_i;
diff --git a/src/interfaces/ecpg/test/thread/thread_implicit.pgc b/src/interfaces/ecpg/test/thread/thread_implicit.pgc
index bbc4d7783c..b7dd555348 100644
--- a/src/interfaces/ecpg/test/thread/thread_implicit.pgc
+++ b/src/interfaces/ecpg/test/thread/thread_implicit.pgc
@@ -4,7 +4,7 @@
  */
 
 #include <stdlib.h>
-#include "ecpg_config.h"
+#include "pg_config.h"
 
 #ifndef ENABLE_THREAD_SAFETY
 int
@@ -35,7 +35,7 @@ int main()
 #else
   HANDLE *threads;
 #endif
-  int n;
+  intptr_t n;
   EXEC SQL BEGIN DECLARE SECTION;
   int l_rows;
   EXEC SQL END DECLARE SECTION;
@@ -66,7 +66,7 @@ int main()
   for( n = 0; n < nthreads; n++ )
     {
 #ifndef WIN32
-      pthread_create(&threads[n], NULL, test_thread, (void *) (long) (n + 1));
+      pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
 #else
       threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_thread, (void *) (n+1), 0, NULL);
 #endif
@@ -98,7 +98,7 @@ int main()
 
 void *test_thread(void *arg)
 {
-  long threadnum = (long)arg;
+  long threadnum = (intptr_t) arg;
 
   EXEC SQL BEGIN DECLARE SECTION;
   int  l_i;
-- 
2.25.0

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: Fix compiler warnings on 64-bit Windows

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

GCC reports various instances of
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
in ECPG test files. This is because void* and long are cast back and
forth, but on 64-bit Windows, these have different sizes. Fix by
using intptr_t instead.

Hm. Silencing the warnings is a laudable goal, but I'm very dubious
of allowing these test files to depend on pg_config.h. That doesn't
correspond to real-world ECPG usage, so it seems likely that it could
come back to bite us some day.

According to C99 and POSIX, intptr_t should be provided by <stdint.h> ...
now that we're requiring C99, can we get away with just #include'ing
that directly in these test files?

regards, tom lane

#3Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#2)
Re: Fix compiler warnings on 64-bit Windows

On 2020-02-13 16:19, Tom Lane wrote:

According to C99 and POSIX, intptr_t should be provided by <stdint.h> ...
now that we're requiring C99, can we get away with just #include'ing
that directly in these test files?

I think in the past we were worried about the C library not being fully
C99. But the build farm indicates that even the trailing edge OS X and
HP-UX members have it, so I'm content to require it. Then we should
probably remove the Autoconf tests altogether.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#3)
Re: Fix compiler warnings on 64-bit Windows

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 2020-02-13 16:19, Tom Lane wrote:

According to C99 and POSIX, intptr_t should be provided by <stdint.h> ...
now that we're requiring C99, can we get away with just #include'ing
that directly in these test files?

I think in the past we were worried about the C library not being fully
C99. But the build farm indicates that even the trailing edge OS X and
HP-UX members have it, so I'm content to require it. Then we should
probably remove the Autoconf tests altogether.

Yeah, I think that the C99 requirement has obsoleted a number of configure
tests and related hackery in c.h. We just haven't got round to cleaning
that up yet.

BTW: I'm still concerned about the possibility of the C library being
less than C99. The model that was popular back then, and which still
exists on e.g. gaur, was that you could install a C99 *compiler* on
a pre-C99 system, and the compiler would bring its own standard header
files as necessary. While I don't have the machine booted up to check,
I'm pretty sure that gaur's <stdint.h> is being supplied by the gcc
installation not directly from /usr/include. On the other hand, that
compiler installation is still dependent on the vendor-supplied libc.

So the sorts of tests I think we can get away with removing have to do
with the presence of C99-required headers, macros, typedefs, etc.
Anything that is checking the presence or behavior of code in libc,
we probably need to be more careful about.

regards, tom lane

#5Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#4)
1 attachment(s)
Re: Fix compiler warnings on 64-bit Windows

On 2020-02-14 15:52, Tom Lane wrote:

Yeah, I think that the C99 requirement has obsoleted a number of configure
tests and related hackery in c.h. We just haven't got round to cleaning
that up yet.

BTW: I'm still concerned about the possibility of the C library being
less than C99. The model that was popular back then, and which still
exists on e.g. gaur, was that you could install a C99 *compiler* on
a pre-C99 system, and the compiler would bring its own standard header
files as necessary. While I don't have the machine booted up to check,
I'm pretty sure that gaur's <stdint.h> is being supplied by the gcc
installation not directly from /usr/include. On the other hand, that
compiler installation is still dependent on the vendor-supplied libc.

Yeah, stdint.h belongs to the compiler, whereas intttypes.h belongs to
the C library. So if we require a C99 compiler we can get rid of all
tests and workarounds for stdint.h missing. Patch attached.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Require-stdint.h.patchtext/plain; charset=UTF-8; name=0001-Require-stdint.h.patch; x-mac-creator=0; x-mac-type=0Download
From 52659310edbcd0f52c676ae80dd12d682c0ca2cd Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 17 Feb 2020 09:05:30 +0100
Subject: [PATCH] Require stdint.h

stdint.h belongs to the compiler (as opposed to inttypes.h), so by
requiring a C99 compiler we can also require stdint.h
unconditionally.  Remove configure checks and other workarounds for
it.
---
 configure                  | 73 --------------------------------------
 configure.in               |  2 --
 src/include/c.h            | 15 ++------
 src/include/pg_config.h.in | 14 --------
 src/timezone/README        |  6 +---
 src/tools/msvc/Solution.pm |  6 +---
 6 files changed, 4 insertions(+), 112 deletions(-)

diff --git a/configure b/configure
index 37aa82dcd4..569cd2fa91 100755
--- a/configure
+++ b/configure
@@ -14154,79 +14154,6 @@ _ACEOF
 fi
 
 
-  ac_fn_c_check_type "$LINENO" "intptr_t" "ac_cv_type_intptr_t" "$ac_includes_default"
-if test "x$ac_cv_type_intptr_t" = xyes; then :
-
-$as_echo "#define HAVE_INTPTR_T 1" >>confdefs.h
-
-else
-  for ac_type in 'int' 'long int' 'long long int'; do
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-$ac_includes_default
-int
-main ()
-{
-static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($ac_type))];
-test_array [0] = 0;
-return test_array [0];
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-
-cat >>confdefs.h <<_ACEOF
-#define intptr_t $ac_type
-_ACEOF
-
-	  ac_type=
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-       test -z "$ac_type" && break
-     done
-fi
-
-
-
-  ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default"
-if test "x$ac_cv_type_uintptr_t" = xyes; then :
-
-$as_echo "#define HAVE_UINTPTR_T 1" >>confdefs.h
-
-else
-  for ac_type in 'unsigned int' 'unsigned long int' \
-	'unsigned long long int'; do
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-$ac_includes_default
-int
-main ()
-{
-static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($ac_type))];
-test_array [0] = 0;
-return test_array [0];
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-
-cat >>confdefs.h <<_ACEOF
-#define uintptr_t $ac_type
-_ACEOF
-
-	  ac_type=
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-       test -z "$ac_type" && break
-     done
-fi
-
-
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for locale_t" >&5
 $as_echo_n "checking for locale_t... " >&6; }
 if ${pgac_cv_type_locale_t+:} false; then :
diff --git a/configure.in b/configure.in
index 8adb409558..140909091a 100644
--- a/configure.in
+++ b/configure.in
@@ -1477,8 +1477,6 @@ PGAC_STRUCT_SOCKADDR_UN
 PGAC_STRUCT_SOCKADDR_STORAGE
 PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
 PGAC_STRUCT_ADDRINFO
-AC_TYPE_INTPTR_T
-AC_TYPE_UINTPTR_T
 
 PGAC_TYPE_LOCALE_T
 
diff --git a/src/include/c.h b/src/include/c.h
index d10b9812fb..2e8b2d4e3f 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -64,9 +64,7 @@
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
-#ifdef HAVE_STDINT_H
 #include <stdint.h>
-#endif
 #include <sys/types.h>
 #include <errno.h>
 #if defined(WIN32) || defined(__CYGWIN__)
@@ -429,8 +427,8 @@ typedef unsigned PG_INT128_TYPE uint128
 #endif
 
 /*
- * stdint.h limits aren't guaranteed to be present and aren't guaranteed to
- * have compatible types with our fixed width types. So just define our own.
+ * stdint.h limits aren't guaranteed to have compatible types with our fixed
+ * width types. So just define our own.
  */
 #define PG_INT8_MIN		(-0x7F-1)
 #define PG_INT8_MAX		(0x7F)
@@ -445,15 +443,6 @@ typedef unsigned PG_INT128_TYPE uint128
 #define PG_INT64_MAX	INT64CONST(0x7FFFFFFFFFFFFFFF)
 #define PG_UINT64_MAX	UINT64CONST(0xFFFFFFFFFFFFFFFF)
 
-/* Max value of size_t might also be missing if we don't have stdint.h */
-#ifndef SIZE_MAX
-#if SIZEOF_SIZE_T == 8
-#define SIZE_MAX PG_UINT64_MAX
-#else
-#define SIZE_MAX PG_UINT32_MAX
-#endif
-#endif
-
 /*
  * We now always use int64 timestamps, but keep this symbol defined for the
  * benefit of external code that might test it.
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 60dcf42974..e7de8f3b2b 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -310,9 +310,6 @@
 /* Define to 1 if the system has the type `int8'. */
 #undef HAVE_INT8
 
-/* Define to 1 if the system has the type `intptr_t'. */
-#undef HAVE_INTPTR_T
-
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
@@ -680,9 +677,6 @@
 /* Define to 1 if the system has the type `uint8'. */
 #undef HAVE_UINT8
 
-/* Define to 1 if the system has the type `uintptr_t'. */
-#undef HAVE_UINTPTR_T
-
 /* Define to 1 if the system has the type `union semun'. */
 #undef HAVE_UNION_SEMUN
 
@@ -1006,10 +1000,6 @@
 #undef inline
 #endif
 
-/* Define to the type of a signed integer type wide enough to hold a pointer,
-   if such a type exists, and if the system does not define it. */
-#undef intptr_t
-
 /* Define to keyword to use for C99 restrict support, or to nothing if not
    supported */
 #undef pg_restrict
@@ -1033,7 +1023,3 @@
 
 /* Define to how the compiler spells `typeof'. */
 #undef typeof
-
-/* Define to the type of an unsigned integer type wide enough to hold a
-   pointer, if such a type exists, and if the system does not define it. */
-#undef uintptr_t
diff --git a/src/timezone/README b/src/timezone/README
index d3dd7b7fa6..db12af75e6 100644
--- a/src/timezone/README
+++ b/src/timezone/README
@@ -70,11 +70,7 @@ old-style function declarations to C89 style, but thank goodness they
 fixed that.)
 
 * We need the code to follow Postgres' portability conventions; this
-includes relying on configure's results rather than hand-hacked #defines,
-and not relying on <stdint.h> features that may not exist on old systems.
-(In particular this means using Postgres' definitions of the int32 and
-int64 typedefs, not int_fast32_t/int_fast64_t.  Likewise we use
-PG_INT32_MIN/MAX not INT32_MIN/MAX.)
+includes relying on configure's results rather than hand-hacked #defines.
 
 * Since Postgres is typically built on a system that has its own copy
 of the <time.h> functions, we must avoid conflicting with those.  This
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 8412ef298e..d1a4f183f3 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -275,7 +275,6 @@ sub GenerateFiles
 		HAVE_INT_TIMEZONE                           => 1,
 		HAVE_INT64                                  => undef,
 		HAVE_INT8                                   => undef,
-		HAVE_INTPTR_T                               => undef,
 		HAVE_INTTYPES_H                             => undef,
 		HAVE_INT_OPTERR                             => undef,
 		HAVE_INT_OPTRESET                           => undef,
@@ -396,7 +395,6 @@ sub GenerateFiles
 		HAVE_UCRED_H                             => undef,
 		HAVE_UINT64                              => undef,
 		HAVE_UINT8                               => undef,
-		HAVE_UINTPTR_T                           => undef,
 		HAVE_UNION_SEMUN                         => undef,
 		HAVE_UNISTD_H                            => 1,
 		HAVE_UNIX_SOCKETS                        => undef,
@@ -496,13 +494,11 @@ sub GenerateFiles
 		_LARGEFILE_SOURCE => undef,
 		_LARGE_FILES      => undef,
 		inline            => '__inline',
-		intptr_t          => undef,
 		pg_restrict       => '__restrict',
 		# not defined, because it'd conflict with __declspec(restrict)
 		restrict  => undef,
 		signed    => undef,
-		typeof    => undef,
-		uintptr_t => undef,);
+		typeof    => undef,);
 
 	if ($self->{options}->{uuid})
 	{
-- 
2.25.0

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#5)
Re: Fix compiler warnings on 64-bit Windows

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 2020-02-14 15:52, Tom Lane wrote:

BTW: I'm still concerned about the possibility of the C library being
less than C99. The model that was popular back then, and which still
exists on e.g. gaur, was that you could install a C99 *compiler* on
a pre-C99 system, and the compiler would bring its own standard header
files as necessary. While I don't have the machine booted up to check,
I'm pretty sure that gaur's <stdint.h> is being supplied by the gcc
installation not directly from /usr/include. On the other hand, that
compiler installation is still dependent on the vendor-supplied libc.

Yeah, stdint.h belongs to the compiler, whereas intttypes.h belongs to
the C library. So if we require a C99 compiler we can get rid of all
tests and workarounds for stdint.h missing. Patch attached.

I tried this on gaur's host, and got:

$ make -s
In file included from ../../src/include/postgres_fe.h:25,
from base64.c:18:
../../src/include/c.h:67:20: stdint.h: No such file or directory
make[2]: *** [base64.o] Error 1
make[1]: *** [all-common-recurse] Error 2
make: *** [all-src-recurse] Error 2

Ooops. Poking around, it looks like this version of gcc has brought its
own stdbool.h, but not stdint.h:

$ ls /usr/include/std*
/usr/include/std_space.h /usr/include/stdio.h
/usr/include/stdarg.h /usr/include/stdlib.h
/usr/include/stddef.h
$ find /opt/gcc-3.4.6 -name 'std*.h'
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/include/stdarg.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/include/stdbool.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/include/stddef.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/include/stdio.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/include/stdlib.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/install-tools/include/stdarg.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/install-tools/include/stdbool.h
/opt/gcc-3.4.6/lib/gcc/hppa2.0-hp-hpux10.20/3.4.6/install-tools/include/stddef.h

Kind of annoying. Perhaps more recent gcc versions fixed that?
Anyway, this seems like a bit of a blocker for this idea, at least
unless I update or retire this buildfarm critter.

regards, tom lane

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#6)
Re: Fix compiler warnings on 64-bit Windows

I wrote:

Ooops. Poking around, it looks like this version of gcc has brought its
own stdbool.h, but not stdint.h:
...
Kind of annoying. Perhaps more recent gcc versions fixed that?

Here we go, in the gcc 4.5.x release notes:

GCC now ensures that a C99-conforming <stdint.h> is present on most
targets, and uses information about the types in this header to
implement the Fortran bindings to those types. GCC does not ensure the
presence of such a header, and does not implement the Fortran
bindings, on the following targets: NetBSD, VxWorks, VMS, SymbianOS,
WinCE, LynxOS, Netware, QNX, Interix, TPF.

4.5 seems annoyingly recent for this purpose (barely 10 years old).
Also, I'd previously tried and failed to use 4.2.4 and 4.0.4 on that
platform --- they didn't seem to be able to cope with the old header
files. (Now I wonder if the lack of stdint.h had something to do
with it... although those versions did build, they just were buggy.)

Anyway, I'll have a go at updating gaur to use 4.5.x. There is a
sane-looking stdint.h on my second-oldest dinosaur, prairiedog.
Don't know about the situation on Windows, though. We might want
to take a close look at NetBSD, too, based on the GCC notes.

regards, tom lane

#8Juan José Santamaría Flecha
juanjo.santamaria@gmail.com
In reply to: Tom Lane (#7)
Re: Fix compiler warnings on 64-bit Windows

On Mon, Feb 17, 2020 at 4:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Anyway, I'll have a go at updating gaur to use 4.5.x. There is a
sane-looking stdint.h on my second-oldest dinosaur, prairiedog.
Don't know about the situation on Windows, though. We might want
to take a close look at NetBSD, too, based on the GCC notes.

As for Windows, stdint.h was included in VS2010, and currently Postgres
supports VS2013 to 2019.

Regards

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Juan José Santamaría Flecha (#8)
Re: Fix compiler warnings on 64-bit Windows

=?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <juanjo.santamaria@gmail.com> writes:

On Mon, Feb 17, 2020 at 4:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Anyway, I'll have a go at updating gaur to use 4.5.x. There is a
sane-looking stdint.h on my second-oldest dinosaur, prairiedog.
Don't know about the situation on Windows, though. We might want
to take a close look at NetBSD, too, based on the GCC notes.

As for Windows, stdint.h was included in VS2010, and currently Postgres
supports VS2013 to 2019.

I've now updated gaur to gcc 4.5.4 (took a little more hair-pulling
than I would have wished). I confirm that 0001-Require-stdint.h.patch
works in that environment, so I think you can go ahead and push it.

I think there is room for more extensive trimming of no-longer-useful
configure checks, but I'll start a separate thread about that.

regards, tom lane

#10Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#9)
Re: Fix compiler warnings on 64-bit Windows

On 2020-02-20 17:24, Tom Lane wrote:

=?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <juanjo.santamaria@gmail.com> writes:

On Mon, Feb 17, 2020 at 4:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Anyway, I'll have a go at updating gaur to use 4.5.x. There is a
sane-looking stdint.h on my second-oldest dinosaur, prairiedog.
Don't know about the situation on Windows, though. We might want
to take a close look at NetBSD, too, based on the GCC notes.

As for Windows, stdint.h was included in VS2010, and currently Postgres
supports VS2013 to 2019.

I've now updated gaur to gcc 4.5.4 (took a little more hair-pulling
than I would have wished). I confirm that 0001-Require-stdint.h.patch
works in that environment, so I think you can go ahead and push it.

Done, and also the appropriately reworked Windows warnings patch from
the beginning of the thread.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services