Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 839ee18

Browse files
author
Michael Meskes
committed
Make setlocale in ECPG test cases thread aware on Windows.
Fix threaded test cases on Windows not to crash in setlocale() which can be global or local to a thread on Windows. Author: Christian Ullrich
1 parent e5c8d43 commit 839ee18

File tree

10 files changed

+163
-109
lines changed

10 files changed

+163
-109
lines changed

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

+22-17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ main(void)
2222
#define WIN32_LEAN_AND_MEAN
2323
#include <windows.h>
2424
#include <process.h>
25+
#include <locale.h>
2526
#else
2627
#include <pthread.h>
2728
#endif
@@ -99,7 +100,7 @@ struct sqlca_t *ECPGget_sqlca(void);
99100

100101
#endif
101102

102-
#line 24 "alloc.pgc"
103+
#line 25 "alloc.pgc"
103104

104105

105106
#line 1 "regression.h"
@@ -109,14 +110,14 @@ struct sqlca_t *ECPGget_sqlca(void);
109110

110111

111112

112-
#line 25 "alloc.pgc"
113+
#line 26 "alloc.pgc"
113114

114115

115116
/* exec sql whenever sqlerror sqlprint ; */
116-
#line 27 "alloc.pgc"
117+
#line 28 "alloc.pgc"
117118

118119
/* exec sql whenever not found sqlprint ; */
119-
#line 28 "alloc.pgc"
120+
#line 29 "alloc.pgc"
120121

121122

122123
#ifdef WIN32
@@ -127,59 +128,63 @@ static void* fn(void* arg)
127128
{
128129
int i;
129130

131+
#ifdef WIN32
132+
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
133+
#endif
134+
130135
/* exec sql begin declare section */
131136

132137

133138

134139

135-
#line 39 "alloc.pgc"
140+
#line 44 "alloc.pgc"
136141
int value ;
137142

138-
#line 40 "alloc.pgc"
143+
#line 45 "alloc.pgc"
139144
char name [ 100 ] ;
140145

141-
#line 41 "alloc.pgc"
146+
#line 46 "alloc.pgc"
142147
char ** r = NULL ;
143148
/* exec sql end declare section */
144-
#line 42 "alloc.pgc"
149+
#line 47 "alloc.pgc"
145150

146151

147152
value = (long)arg;
148153
sprintf(name, "Connection: %d", value);
149154

150155
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
151-
#line 47 "alloc.pgc"
156+
#line 52 "alloc.pgc"
152157

153158
if (sqlca.sqlcode < 0) sqlprint();}
154-
#line 47 "alloc.pgc"
159+
#line 52 "alloc.pgc"
155160

156161
{ ECPGsetcommit(__LINE__, "on", NULL);
157-
#line 48 "alloc.pgc"
162+
#line 53 "alloc.pgc"
158163

159164
if (sqlca.sqlcode < 0) sqlprint();}
160-
#line 48 "alloc.pgc"
165+
#line 53 "alloc.pgc"
161166

162167
for (i = 1; i <= REPEATS; ++i)
163168
{
164169
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT,
165170
ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char),
166171
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
167-
#line 51 "alloc.pgc"
172+
#line 56 "alloc.pgc"
168173

169174
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
170-
#line 51 "alloc.pgc"
175+
#line 56 "alloc.pgc"
171176

172177
if (sqlca.sqlcode < 0) sqlprint();}
173-
#line 51 "alloc.pgc"
178+
#line 56 "alloc.pgc"
174179

175180
free(r);
176181
r = NULL;
177182
}
178183
{ ECPGdisconnect(__LINE__, name);
179-
#line 55 "alloc.pgc"
184+
#line 60 "alloc.pgc"
180185

181186
if (sqlca.sqlcode < 0) sqlprint();}
182-
#line 55 "alloc.pgc"
187+
#line 60 "alloc.pgc"
183188

184189

185190
return 0;

src/interfaces/ecpg/test/expected/thread-descriptor.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define WIN32_LEAN_AND_MEAN
1313
#include <windows.h>
1414
#include <process.h>
15+
#include <locale.h>
1516
#else
1617
#include <pthread.h>
1718
#endif
@@ -90,13 +91,13 @@ struct sqlca_t *ECPGget_sqlca(void);
9091

9192
#endif
9293

93-
#line 15 "descriptor.pgc"
94+
#line 16 "descriptor.pgc"
9495

9596
/* exec sql whenever sqlerror sqlprint ; */
96-
#line 16 "descriptor.pgc"
97+
#line 17 "descriptor.pgc"
9798

9899
/* exec sql whenever not found sqlprint ; */
99-
#line 17 "descriptor.pgc"
100+
#line 18 "descriptor.pgc"
100101

101102

102103
#if defined(ENABLE_THREAD_SAFETY) && defined(WIN32)
@@ -107,19 +108,23 @@ static void* fn(void* arg)
107108
{
108109
int i;
109110

111+
#ifdef WIN32
112+
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
113+
#endif
114+
110115
for (i = 1; i <= REPEATS; ++i)
111116
{
112117
ECPGallocate_desc(__LINE__, "mydesc");
113-
#line 29 "descriptor.pgc"
118+
#line 34 "descriptor.pgc"
114119

115120
if (sqlca.sqlcode < 0) sqlprint();
116-
#line 29 "descriptor.pgc"
121+
#line 34 "descriptor.pgc"
117122

118123
ECPGdeallocate_desc(__LINE__, "mydesc");
119-
#line 30 "descriptor.pgc"
124+
#line 35 "descriptor.pgc"
120125

121126
if (sqlca.sqlcode < 0) sqlprint();
122-
#line 30 "descriptor.pgc"
127+
#line 35 "descriptor.pgc"
123128

124129
}
125130

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

+36-31
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ main(void)
2222
#define WIN32_LEAN_AND_MEAN
2323
#include <windows.h>
2424
#include <process.h>
25+
#include <locale.h>
2526
#else
2627
#include <pthread.h>
2728
#endif
@@ -99,7 +100,7 @@ struct sqlca_t *ECPGget_sqlca(void);
99100

100101
#endif
101102

102-
#line 24 "prep.pgc"
103+
#line 25 "prep.pgc"
103104

104105

105106
#line 1 "regression.h"
@@ -109,14 +110,14 @@ struct sqlca_t *ECPGget_sqlca(void);
109110

110111

111112

112-
#line 25 "prep.pgc"
113+
#line 26 "prep.pgc"
113114

114115

115116
/* exec sql whenever sqlerror sqlprint ; */
116-
#line 27 "prep.pgc"
117+
#line 28 "prep.pgc"
117118

118119
/* exec sql whenever not found sqlprint ; */
119-
#line 28 "prep.pgc"
120+
#line 29 "prep.pgc"
120121

121122

122123
#ifdef WIN32
@@ -127,69 +128,73 @@ static void* fn(void* arg)
127128
{
128129
int i;
129130

131+
#ifdef WIN32
132+
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
133+
#endif
134+
130135
/* exec sql begin declare section */
131136

132137

133138

134139

135-
#line 39 "prep.pgc"
140+
#line 44 "prep.pgc"
136141
int value ;
137142

138-
#line 40 "prep.pgc"
143+
#line 45 "prep.pgc"
139144
char name [ 100 ] ;
140145

141-
#line 41 "prep.pgc"
146+
#line 46 "prep.pgc"
142147
char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ;
143148
/* exec sql end declare section */
144-
#line 42 "prep.pgc"
149+
#line 47 "prep.pgc"
145150

146151

147152
value = (long)arg;
148153
sprintf(name, "Connection: %d", value);
149154

150155
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
151-
#line 47 "prep.pgc"
156+
#line 52 "prep.pgc"
152157

153158
if (sqlca.sqlcode < 0) sqlprint();}
154-
#line 47 "prep.pgc"
159+
#line 52 "prep.pgc"
155160

156161
{ ECPGsetcommit(__LINE__, "on", NULL);
157-
#line 48 "prep.pgc"
162+
#line 53 "prep.pgc"
158163

159164
if (sqlca.sqlcode < 0) sqlprint();}
160-
#line 48 "prep.pgc"
165+
#line 53 "prep.pgc"
161166

162167
for (i = 1; i <= REPEATS; ++i)
163168
{
164169
{ ECPGprepare(__LINE__, NULL, 0, "i", query);
165-
#line 51 "prep.pgc"
170+
#line 56 "prep.pgc"
166171

167172
if (sqlca.sqlcode < 0) sqlprint();}
168-
#line 51 "prep.pgc"
173+
#line 56 "prep.pgc"
169174

170175
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
171176
ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
172177
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
173-
#line 52 "prep.pgc"
178+
#line 57 "prep.pgc"
174179

175180
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
176-
#line 52 "prep.pgc"
181+
#line 57 "prep.pgc"
177182

178183
if (sqlca.sqlcode < 0) sqlprint();}
179-
#line 52 "prep.pgc"
184+
#line 57 "prep.pgc"
180185

181186
}
182187
{ ECPGdeallocate(__LINE__, 0, NULL, "i");
183-
#line 54 "prep.pgc"
188+
#line 59 "prep.pgc"
184189

185190
if (sqlca.sqlcode < 0) sqlprint();}
186-
#line 54 "prep.pgc"
191+
#line 59 "prep.pgc"
187192

188193
{ ECPGdisconnect(__LINE__, name);
189-
#line 55 "prep.pgc"
194+
#line 60 "prep.pgc"
190195

191196
if (sqlca.sqlcode < 0) sqlprint();}
192-
#line 55 "prep.pgc"
197+
#line 60 "prep.pgc"
193198

194199

195200
return 0;
@@ -205,34 +210,34 @@ int main ()
205210
#endif
206211

207212
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
208-
#line 69 "prep.pgc"
213+
#line 74 "prep.pgc"
209214

210215
if (sqlca.sqlcode < 0) sqlprint();}
211-
#line 69 "prep.pgc"
216+
#line 74 "prep.pgc"
212217

213218
{ ECPGsetcommit(__LINE__, "on", NULL);
214-
#line 70 "prep.pgc"
219+
#line 75 "prep.pgc"
215220

216221
if (sqlca.sqlcode < 0) sqlprint();}
217-
#line 70 "prep.pgc"
222+
#line 75 "prep.pgc"
218223

219224
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
220-
#line 71 "prep.pgc"
225+
#line 76 "prep.pgc"
221226

222227
if (sqlca.sqlcode < 0) sqlprint();}
223-
#line 71 "prep.pgc"
228+
#line 76 "prep.pgc"
224229

225230
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
226-
#line 72 "prep.pgc"
231+
#line 77 "prep.pgc"
227232

228233
if (sqlca.sqlcode < 0) sqlprint();}
229-
#line 72 "prep.pgc"
234+
#line 77 "prep.pgc"
230235

231236
{ ECPGdisconnect(__LINE__, "CURRENT");
232-
#line 73 "prep.pgc"
237+
#line 78 "prep.pgc"
233238

234239
if (sqlca.sqlcode < 0) sqlprint();}
235-
#line 73 "prep.pgc"
240+
#line 78 "prep.pgc"
236241

237242

238243
#ifdef WIN32

0 commit comments

Comments
 (0)