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.

This change is simplified by having made stdint.h required (commit
957338418b).  Before this it would have
been more complicated because the ecpg test source files don't use the
full pg_config.h.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/5d398bbb-262a-5fed-d839-d0e5cff3c0d7%402ndquadrant.com
This commit is contained in:
Peter Eisentraut 2020-02-21 19:49:44 +01:00
parent b7fabe80df
commit 3f9c1697dc
8 changed files with 109 additions and 103 deletions

View File

@ -7,6 +7,7 @@
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
#line 1 "alloc.pgc"
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -100,7 +101,7 @@ struct sqlca_t *ECPGget_sqlca(void);
#endif
#line 25 "alloc.pgc"
#line 26 "alloc.pgc"
#line 1 "regression.h"
@ -110,14 +111,14 @@ struct sqlca_t *ECPGget_sqlca(void);
#line 26 "alloc.pgc"
#line 27 "alloc.pgc"
/* exec sql whenever sqlerror sqlprint ; */
#line 28 "alloc.pgc"
#line 29 "alloc.pgc"
/* exec sql whenever not found sqlprint ; */
#line 29 "alloc.pgc"
#line 30 "alloc.pgc"
#ifdef WIN32
@ -133,54 +134,54 @@ static void* fn(void* arg)
#line 40 "alloc.pgc"
#line 41 "alloc.pgc"
int value ;
#line 41 "alloc.pgc"
#line 42 "alloc.pgc"
char name [ 100 ] ;
#line 42 "alloc.pgc"
#line 43 "alloc.pgc"
char ** r = NULL ;
/* exec sql end declare section */
#line 43 "alloc.pgc"
#line 44 "alloc.pgc"
value = (long)arg;
value = (intptr_t) arg;
sprintf(name, "Connection: %d", value);
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
#line 48 "alloc.pgc"
#line 49 "alloc.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 48 "alloc.pgc"
#line 49 "alloc.pgc"
{ ECPGsetcommit(__LINE__, "on", NULL);
#line 49 "alloc.pgc"
#line 50 "alloc.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 49 "alloc.pgc"
#line 50 "alloc.pgc"
for (i = 1; i <= REPEATS; ++i)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT,
ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 52 "alloc.pgc"
#line 53 "alloc.pgc"
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
#line 52 "alloc.pgc"
#line 53 "alloc.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 52 "alloc.pgc"
#line 53 "alloc.pgc"
free(r);
r = NULL;
}
{ ECPGdisconnect(__LINE__, name);
#line 56 "alloc.pgc"
#line 57 "alloc.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 56 "alloc.pgc"
#line 57 "alloc.pgc"
return 0;
@ -188,7 +189,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
int main ()
{
int i;
intptr_t i;
#ifdef WIN32
HANDLE threads[THREADS];
#else
@ -207,7 +208,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

View File

@ -7,6 +7,7 @@
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
#line 1 "prep.pgc"
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -100,7 +101,7 @@ struct sqlca_t *ECPGget_sqlca(void);
#endif
#line 25 "prep.pgc"
#line 26 "prep.pgc"
#line 1 "regression.h"
@ -110,14 +111,14 @@ struct sqlca_t *ECPGget_sqlca(void);
#line 26 "prep.pgc"
#line 27 "prep.pgc"
/* exec sql whenever sqlerror sqlprint ; */
#line 28 "prep.pgc"
#line 29 "prep.pgc"
/* exec sql whenever not found sqlprint ; */
#line 29 "prep.pgc"
#line 30 "prep.pgc"
#ifdef WIN32
@ -133,64 +134,64 @@ static void* fn(void* arg)
#line 40 "prep.pgc"
#line 41 "prep.pgc"
int value ;
#line 41 "prep.pgc"
#line 42 "prep.pgc"
char name [ 100 ] ;
#line 42 "prep.pgc"
#line 43 "prep.pgc"
char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ;
/* exec sql end declare section */
#line 43 "prep.pgc"
#line 44 "prep.pgc"
value = (long)arg;
value = (intptr_t) arg;
sprintf(name, "Connection: %d", value);
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
#line 48 "prep.pgc"
#line 49 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 48 "prep.pgc"
#line 49 "prep.pgc"
{ ECPGsetcommit(__LINE__, "on", NULL);
#line 49 "prep.pgc"
#line 50 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 49 "prep.pgc"
#line 50 "prep.pgc"
for (i = 1; i <= REPEATS; ++i)
{
{ ECPGprepare(__LINE__, NULL, 0, "i", query);
#line 52 "prep.pgc"
#line 53 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 52 "prep.pgc"
#line 53 "prep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 53 "prep.pgc"
#line 54 "prep.pgc"
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
#line 53 "prep.pgc"
#line 54 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 53 "prep.pgc"
#line 54 "prep.pgc"
}
{ ECPGdeallocate(__LINE__, 0, NULL, "i");
#line 55 "prep.pgc"
#line 56 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 55 "prep.pgc"
#line 56 "prep.pgc"
{ ECPGdisconnect(__LINE__, name);
#line 56 "prep.pgc"
#line 57 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 56 "prep.pgc"
#line 57 "prep.pgc"
return 0;
@ -198,7 +199,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
int main ()
{
int i;
intptr_t i;
#ifdef WIN32
HANDLE threads[THREADS];
#else
@ -206,34 +207,34 @@ int main ()
#endif
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
#line 70 "prep.pgc"
#line 71 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 70 "prep.pgc"
#line 71 "prep.pgc"
{ ECPGsetcommit(__LINE__, "on", NULL);
#line 71 "prep.pgc"
#line 72 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 71 "prep.pgc"
#line 72 "prep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
#line 72 "prep.pgc"
#line 73 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 72 "prep.pgc"
#line 73 "prep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
#line 73 "prep.pgc"
#line 74 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 73 "prep.pgc"
#line 74 "prep.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");
#line 74 "prep.pgc"
#line 75 "prep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 74 "prep.pgc"
#line 75 "prep.pgc"
#ifdef WIN32
@ -248,7 +249,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

View File

@ -11,6 +11,7 @@
* Thread test program
* by Philip Yarra & Lee Kindness.
*/
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -37,7 +38,7 @@ main(void)
#line 23 "thread.pgc"
#line 24 "thread.pgc"
void *test_thread(void *arg);
@ -52,14 +53,14 @@ int main()
#else
HANDLE *threads;
#endif
int n;
intptr_t n;
/* exec sql begin declare section */
#line 39 "thread.pgc"
#line 40 "thread.pgc"
int l_rows ;
/* exec sql end declare section */
#line 40 "thread.pgc"
#line 41 "thread.pgc"
/* Do not switch on debug output for regression tests. The threads get executed in
@ -68,23 +69,23 @@ int main()
/* setup test_thread table */
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
#line 47 "thread.pgc"
#line 48 "thread.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test_thread", ECPGt_EOIT, ECPGt_EORT);}
#line 48 "thread.pgc"
#line 49 "thread.pgc"
/* DROP might fail */
{ ECPGtrans(__LINE__, NULL, "commit");}
#line 49 "thread.pgc"
#line 50 "thread.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test_thread ( tstamp timestamp not null default cast ( timeofday ( ) as timestamp ) , thread text not null , iteration integer not null , primary key ( thread , iteration ) )", ECPGt_EOIT, ECPGt_EORT);}
#line 54 "thread.pgc"
{ ECPGtrans(__LINE__, NULL, "commit");}
#line 55 "thread.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");}
{ ECPGtrans(__LINE__, NULL, "commit");}
#line 56 "thread.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");}
#line 57 "thread.pgc"
/* create, and start, threads */
threads = calloc(nthreads, sizeof(threads[0]));
@ -96,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
@ -115,19 +116,19 @@ int main()
/* and check results */
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
#line 86 "thread.pgc"
#line 87 "thread.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) from test_thread", ECPGt_EOIT,
ECPGt_int,&(l_rows),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
#line 87 "thread.pgc"
{ ECPGtrans(__LINE__, NULL, "commit");}
#line 88 "thread.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");}
{ ECPGtrans(__LINE__, NULL, "commit");}
#line 89 "thread.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");}
#line 90 "thread.pgc"
if( l_rows == (nthreads * iterations) )
printf("Success.\n");
else
@ -138,19 +139,19 @@ int main()
void *test_thread(void *arg)
{
long threadnum = (long)arg;
long threadnum = (intptr_t) arg;
/* exec sql begin declare section */
#line 103 "thread.pgc"
#line 104 "thread.pgc"
int l_i ;
#line 104 "thread.pgc"
#line 105 "thread.pgc"
char l_connection [ 128 ] ;
/* exec sql end declare section */
#line 105 "thread.pgc"
#line 106 "thread.pgc"
/* build up connection name, and connect to database */
@ -160,13 +161,13 @@ void *test_thread(void *arg)
_snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum);
#endif
/* exec sql whenever sqlerror sqlprint ; */
#line 113 "thread.pgc"
#line 114 "thread.pgc"
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , l_connection, 0);
#line 114 "thread.pgc"
#line 115 "thread.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 114 "thread.pgc"
#line 115 "thread.pgc"
if( sqlca.sqlcode != 0 )
{
@ -174,10 +175,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
return NULL;
}
{ ECPGtrans(__LINE__, l_connection, "begin");
#line 120 "thread.pgc"
#line 121 "thread.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 120 "thread.pgc"
#line 121 "thread.pgc"
/* insert into test_thread table */
@ -188,10 +189,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_int,&(l_i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 125 "thread.pgc"
#line 126 "thread.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 125 "thread.pgc"
#line 126 "thread.pgc"
if( sqlca.sqlcode != 0 )
printf("%s: ERROR: insert failed!\n", l_connection);
@ -199,16 +200,16 @@ if (sqlca.sqlcode < 0) sqlprint();}
/* all done */
{ ECPGtrans(__LINE__, l_connection, "commit");
#line 131 "thread.pgc"
#line 132 "thread.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 131 "thread.pgc"
#line 132 "thread.pgc"
{ ECPGdisconnect(__LINE__, l_connection);
#line 132 "thread.pgc"
#line 133 "thread.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 132 "thread.pgc"
#line 133 "thread.pgc"
return NULL;
}

View File

@ -11,7 +11,7 @@
* Thread test program
* by Lee Kindness.
*/
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -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 */

View File

@ -1,3 +1,4 @@
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -42,7 +43,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 +61,7 @@ static void* fn(void* arg)
int main ()
{
int i;
intptr_t i;
#ifdef WIN32
HANDLE threads[THREADS];
#else
@ -79,7 +80,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

View File

@ -1,3 +1,4 @@
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -42,7 +43,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 +61,7 @@ static void* fn(void* arg)
int main ()
{
int i;
intptr_t i;
#ifdef WIN32
HANDLE threads[THREADS];
#else
@ -85,7 +86,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

View File

@ -2,6 +2,7 @@
* Thread test program
* by Philip Yarra & Lee Kindness.
*/
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -34,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;
@ -65,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
@ -97,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;

View File

@ -2,7 +2,7 @@
* Thread test program
* by Lee Kindness.
*/
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
@ -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;