Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f9c169

Browse filesBrowse files
committed
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 9573384). 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
1 parent b7fabe8 commit 3f9c169
Copy full SHA for 3f9c169

File tree

Expand file treeCollapse file tree

8 files changed

+106
-100
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+106
-100
lines changed

‎src/interfaces/ecpg/test/expected/thread-alloc.c

Copy file name to clipboardExpand all lines: src/interfaces/ecpg/test/expected/thread-alloc.c
+21-20Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
88

99
#line 1 "alloc.pgc"
10+
#include <stdint.h>
1011
#include <stdlib.h>
1112
#include "ecpg_config.h"
1213

@@ -100,7 +101,7 @@ struct sqlca_t *ECPGget_sqlca(void);
100101

101102
#endif
102103

103-
#line 25 "alloc.pgc"
104+
#line 26 "alloc.pgc"
104105

105106

106107
#line 1 "regression.h"
@@ -110,14 +111,14 @@ struct sqlca_t *ECPGget_sqlca(void);
110111

111112

112113

113-
#line 26 "alloc.pgc"
114+
#line 27 "alloc.pgc"
114115

115116

116117
/* exec sql whenever sqlerror sqlprint ; */
117-
#line 28 "alloc.pgc"
118+
#line 29 "alloc.pgc"
118119

119120
/* exec sql whenever not found sqlprint ; */
120-
#line 29 "alloc.pgc"
121+
#line 30 "alloc.pgc"
121122

122123

123124
#ifdef WIN32
@@ -133,62 +134,62 @@ static void* fn(void* arg)
133134

134135

135136

136-
#line 40 "alloc.pgc"
137+
#line 41 "alloc.pgc"
137138
int value ;
138139

139-
#line 41 "alloc.pgc"
140+
#line 42 "alloc.pgc"
140141
char name [ 100 ] ;
141142

142-
#line 42 "alloc.pgc"
143+
#line 43 "alloc.pgc"
143144
char ** r = NULL ;
144145
/* exec sql end declare section */
145-
#line 43 "alloc.pgc"
146+
#line 44 "alloc.pgc"
146147

147148

148-
value = (long)arg;
149+
value = (intptr_t) arg;
149150
sprintf(name, "Connection: %d", value);
150151

151152
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
152-
#line 48 "alloc.pgc"
153+
#line 49 "alloc.pgc"
153154

154155
if (sqlca.sqlcode < 0) sqlprint();}
155-
#line 48 "alloc.pgc"
156+
#line 49 "alloc.pgc"
156157

157158
{ ECPGsetcommit(__LINE__, "on", NULL);
158-
#line 49 "alloc.pgc"
159+
#line 50 "alloc.pgc"
159160

160161
if (sqlca.sqlcode < 0) sqlprint();}
161-
#line 49 "alloc.pgc"
162+
#line 50 "alloc.pgc"
162163

163164
for (i = 1; i <= REPEATS; ++i)
164165
{
165166
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT,
166167
ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char),
167168
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
168-
#line 52 "alloc.pgc"
169+
#line 53 "alloc.pgc"
169170

170171
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
171-
#line 52 "alloc.pgc"
172+
#line 53 "alloc.pgc"
172173

173174
if (sqlca.sqlcode < 0) sqlprint();}
174-
#line 52 "alloc.pgc"
175+
#line 53 "alloc.pgc"
175176

176177
free(r);
177178
r = NULL;
178179
}
179180
{ ECPGdisconnect(__LINE__, name);
180-
#line 56 "alloc.pgc"
181+
#line 57 "alloc.pgc"
181182

182183
if (sqlca.sqlcode < 0) sqlprint();}
183-
#line 56 "alloc.pgc"
184+
#line 57 "alloc.pgc"
184185

185186

186187
return 0;
187188
}
188189

189190
int main ()
190191
{
191-
int i;
192+
intptr_t i;
192193
#ifdef WIN32
193194
HANDLE threads[THREADS];
194195
#else
@@ -207,7 +208,7 @@ int main ()
207208
CloseHandle(threads[i]);
208209
#else
209210
for (i = 0; i < THREADS; ++i)
210-
pthread_create(&threads[i], NULL, fn, (void *) (long) i);
211+
pthread_create(&threads[i], NULL, fn, (void *) i);
211212
for (i = 0; i < THREADS; ++i)
212213
pthread_join(threads[i], NULL);
213214
#endif

‎src/interfaces/ecpg/test/expected/thread-prep.c

Copy file name to clipboardExpand all lines: src/interfaces/ecpg/test/expected/thread-prep.c
+34-33Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
88

99
#line 1 "prep.pgc"
10+
#include <stdint.h>
1011
#include <stdlib.h>
1112
#include "ecpg_config.h"
1213

@@ -100,7 +101,7 @@ struct sqlca_t *ECPGget_sqlca(void);
100101

101102
#endif
102103

103-
#line 25 "prep.pgc"
104+
#line 26 "prep.pgc"
104105

105106

106107
#line 1 "regression.h"
@@ -110,14 +111,14 @@ struct sqlca_t *ECPGget_sqlca(void);
110111

111112

112113

113-
#line 26 "prep.pgc"
114+
#line 27 "prep.pgc"
114115

115116

116117
/* exec sql whenever sqlerror sqlprint ; */
117-
#line 28 "prep.pgc"
118+
#line 29 "prep.pgc"
118119

119120
/* exec sql whenever not found sqlprint ; */
120-
#line 29 "prep.pgc"
121+
#line 30 "prep.pgc"
121122

122123

123124
#ifdef WIN32
@@ -133,108 +134,108 @@ static void* fn(void* arg)
133134

134135

135136

136-
#line 40 "prep.pgc"
137+
#line 41 "prep.pgc"
137138
int value ;
138139

139-
#line 41 "prep.pgc"
140+
#line 42 "prep.pgc"
140141
char name [ 100 ] ;
141142

142-
#line 42 "prep.pgc"
143+
#line 43 "prep.pgc"
143144
char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ;
144145
/* exec sql end declare section */
145-
#line 43 "prep.pgc"
146+
#line 44 "prep.pgc"
146147

147148

148-
value = (long)arg;
149+
value = (intptr_t) arg;
149150
sprintf(name, "Connection: %d", value);
150151

151152
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
152-
#line 48 "prep.pgc"
153+
#line 49 "prep.pgc"
153154

154155
if (sqlca.sqlcode < 0) sqlprint();}
155-
#line 48 "prep.pgc"
156+
#line 49 "prep.pgc"
156157

157158
{ ECPGsetcommit(__LINE__, "on", NULL);
158-
#line 49 "prep.pgc"
159+
#line 50 "prep.pgc"
159160

160161
if (sqlca.sqlcode < 0) sqlprint();}
161-
#line 49 "prep.pgc"
162+
#line 50 "prep.pgc"
162163

163164
for (i = 1; i <= REPEATS; ++i)
164165
{
165166
{ ECPGprepare(__LINE__, NULL, 0, "i", query);
166-
#line 52 "prep.pgc"
167+
#line 53 "prep.pgc"
167168

168169
if (sqlca.sqlcode < 0) sqlprint();}
169-
#line 52 "prep.pgc"
170+
#line 53 "prep.pgc"
170171

171172
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
172173
ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
173174
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
174-
#line 53 "prep.pgc"
175+
#line 54 "prep.pgc"
175176

176177
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
177-
#line 53 "prep.pgc"
178+
#line 54 "prep.pgc"
178179

179180
if (sqlca.sqlcode < 0) sqlprint();}
180-
#line 53 "prep.pgc"
181+
#line 54 "prep.pgc"
181182

182183
}
183184
{ ECPGdeallocate(__LINE__, 0, NULL, "i");
184-
#line 55 "prep.pgc"
185+
#line 56 "prep.pgc"
185186

186187
if (sqlca.sqlcode < 0) sqlprint();}
187-
#line 55 "prep.pgc"
188+
#line 56 "prep.pgc"
188189

189190
{ ECPGdisconnect(__LINE__, name);
190-
#line 56 "prep.pgc"
191+
#line 57 "prep.pgc"
191192

192193
if (sqlca.sqlcode < 0) sqlprint();}
193-
#line 56 "prep.pgc"
194+
#line 57 "prep.pgc"
194195

195196

196197
return 0;
197198
}
198199

199200
int main ()
200201
{
201-
int i;
202+
intptr_t i;
202203
#ifdef WIN32
203204
HANDLE threads[THREADS];
204205
#else
205206
pthread_t threads[THREADS];
206207
#endif
207208

208209
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
209-
#line 70 "prep.pgc"
210-
211-
if (sqlca.sqlcode < 0) sqlprint();}
212-
#line 70 "prep.pgc"
213-
214-
{ ECPGsetcommit(__LINE__, "on", NULL);
215210
#line 71 "prep.pgc"
216211

217212
if (sqlca.sqlcode < 0) sqlprint();}
218213
#line 71 "prep.pgc"
219214

220-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
215+
{ ECPGsetcommit(__LINE__, "on", NULL);
221216
#line 72 "prep.pgc"
222217

223218
if (sqlca.sqlcode < 0) sqlprint();}
224219
#line 72 "prep.pgc"
225220

226-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
221+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
227222
#line 73 "prep.pgc"
228223

229224
if (sqlca.sqlcode < 0) sqlprint();}
230225
#line 73 "prep.pgc"
231226

232-
{ ECPGdisconnect(__LINE__, "CURRENT");
227+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
233228
#line 74 "prep.pgc"
234229

235230
if (sqlca.sqlcode < 0) sqlprint();}
236231
#line 74 "prep.pgc"
237232

233+
{ ECPGdisconnect(__LINE__, "CURRENT");
234+
#line 75 "prep.pgc"
235+
236+
if (sqlca.sqlcode < 0) sqlprint();}
237+
#line 75 "prep.pgc"
238+
238239

239240
#ifdef WIN32
240241
for (i = 0; i < THREADS; ++i)
@@ -248,7 +249,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
248249
CloseHandle(threads[i]);
249250
#else
250251
for (i = 0; i < THREADS; ++i)
251-
pthread_create(&threads[i], NULL, fn, (void *) (long) i);
252+
pthread_create(&threads[i], NULL, fn, (void *) i);
252253
for (i = 0; i < THREADS; ++i)
253254
pthread_join(threads[i], NULL);
254255
#endif

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.