From 9adfcbc45cbe968d1a1230bce7a2891e75038d84 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut 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 -#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 -#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 -#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 -#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 -#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 -#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 -#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 -#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