From 04fbe0e4516d26de9420637f6fc90041e574b4b0 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Sat, 26 Aug 2017 19:07:25 +0200 Subject: [PATCH] Changed order of statements and added an additiona MSVC safeguard to make ecpg thread test cases work on Windows. --- .../ecpg/test/expected/thread-alloc.c | 36 ++++++----- .../ecpg/test/expected/thread-descriptor.c | 10 +-- .../ecpg/test/expected/thread-prep.c | 64 ++++++++++--------- .../ecpg/test/expected/thread-thread.c | 38 +++++------ .../test/expected/thread-thread_implicit.c | 38 +++++------ src/interfaces/ecpg/test/thread/alloc.pgc | 10 +-- .../ecpg/test/thread/descriptor.pgc | 2 + src/interfaces/ecpg/test/thread/prep.pgc | 10 +-- src/interfaces/ecpg/test/thread/thread.pgc | 10 +-- .../ecpg/test/thread/thread_implicit.pgc | 10 +-- 10 files changed, 124 insertions(+), 104 deletions(-) diff --git a/src/interfaces/ecpg/test/expected/thread-alloc.c b/src/interfaces/ecpg/test/expected/thread-alloc.c index 1a60576533..e7b69b387f 100644 --- a/src/interfaces/ecpg/test/expected/thread-alloc.c +++ b/src/interfaces/ecpg/test/expected/thread-alloc.c @@ -128,63 +128,65 @@ static void* fn(void* arg) { int i; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - /* exec sql begin declare section */ -#line 44 "alloc.pgc" +#line 40 "alloc.pgc" int value ; -#line 45 "alloc.pgc" +#line 41 "alloc.pgc" char name [ 100 ] ; -#line 46 "alloc.pgc" +#line 42 "alloc.pgc" char ** r = NULL ; /* exec sql end declare section */ -#line 47 "alloc.pgc" +#line 43 "alloc.pgc" + +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif value = (long)arg; sprintf(name, "Connection: %d", value); { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0); -#line 52 "alloc.pgc" +#line 54 "alloc.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 52 "alloc.pgc" +#line 54 "alloc.pgc" { ECPGsetcommit(__LINE__, "on", NULL); -#line 53 "alloc.pgc" +#line 55 "alloc.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 53 "alloc.pgc" +#line 55 "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 56 "alloc.pgc" +#line 58 "alloc.pgc" if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint(); -#line 56 "alloc.pgc" +#line 58 "alloc.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 56 "alloc.pgc" +#line 58 "alloc.pgc" free(r); r = NULL; } { ECPGdisconnect(__LINE__, name); -#line 60 "alloc.pgc" +#line 62 "alloc.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 60 "alloc.pgc" +#line 62 "alloc.pgc" return 0; diff --git a/src/interfaces/ecpg/test/expected/thread-descriptor.c b/src/interfaces/ecpg/test/expected/thread-descriptor.c index d1c20b147e..03cebad603 100644 --- a/src/interfaces/ecpg/test/expected/thread-descriptor.c +++ b/src/interfaces/ecpg/test/expected/thread-descriptor.c @@ -109,22 +109,24 @@ static void* fn(void* arg) int i; #ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif #endif for (i = 1; i <= REPEATS; ++i) { ECPGallocate_desc(__LINE__, "mydesc"); -#line 34 "descriptor.pgc" +#line 36 "descriptor.pgc" if (sqlca.sqlcode < 0) sqlprint(); -#line 34 "descriptor.pgc" +#line 36 "descriptor.pgc" ECPGdeallocate_desc(__LINE__, "mydesc"); -#line 35 "descriptor.pgc" +#line 37 "descriptor.pgc" if (sqlca.sqlcode < 0) sqlprint(); -#line 35 "descriptor.pgc" +#line 37 "descriptor.pgc" } diff --git a/src/interfaces/ecpg/test/expected/thread-prep.c b/src/interfaces/ecpg/test/expected/thread-prep.c index ff872f08b5..94e02933cd 100644 --- a/src/interfaces/ecpg/test/expected/thread-prep.c +++ b/src/interfaces/ecpg/test/expected/thread-prep.c @@ -128,73 +128,75 @@ static void* fn(void* arg) { int i; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - /* exec sql begin declare section */ -#line 44 "prep.pgc" +#line 40 "prep.pgc" int value ; -#line 45 "prep.pgc" +#line 41 "prep.pgc" char name [ 100 ] ; -#line 46 "prep.pgc" +#line 42 "prep.pgc" char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ; /* exec sql end declare section */ -#line 47 "prep.pgc" +#line 43 "prep.pgc" +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif + value = (long)arg; sprintf(name, "Connection: %d", value); { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0); -#line 52 "prep.pgc" +#line 54 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 52 "prep.pgc" +#line 54 "prep.pgc" { ECPGsetcommit(__LINE__, "on", NULL); -#line 53 "prep.pgc" +#line 55 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 53 "prep.pgc" +#line 55 "prep.pgc" for (i = 1; i <= REPEATS; ++i) { { ECPGprepare(__LINE__, NULL, 0, "i", query); -#line 56 "prep.pgc" +#line 58 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 56 "prep.pgc" +#line 58 "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 57 "prep.pgc" +#line 59 "prep.pgc" if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint(); -#line 57 "prep.pgc" +#line 59 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 57 "prep.pgc" +#line 59 "prep.pgc" } { ECPGdeallocate(__LINE__, 0, NULL, "i"); -#line 59 "prep.pgc" +#line 61 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 59 "prep.pgc" +#line 61 "prep.pgc" { ECPGdisconnect(__LINE__, name); -#line 60 "prep.pgc" +#line 62 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 60 "prep.pgc" +#line 62 "prep.pgc" return 0; @@ -210,34 +212,34 @@ int main () #endif { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); -#line 74 "prep.pgc" +#line 76 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 74 "prep.pgc" +#line 76 "prep.pgc" { ECPGsetcommit(__LINE__, "on", NULL); -#line 75 "prep.pgc" +#line 77 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 75 "prep.pgc" +#line 77 "prep.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT); -#line 76 "prep.pgc" +#line 78 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 76 "prep.pgc" +#line 78 "prep.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT); -#line 77 "prep.pgc" +#line 79 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 77 "prep.pgc" +#line 79 "prep.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); -#line 78 "prep.pgc" +#line 80 "prep.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 78 "prep.pgc" +#line 80 "prep.pgc" #ifdef WIN32 diff --git a/src/interfaces/ecpg/test/expected/thread-thread.c b/src/interfaces/ecpg/test/expected/thread-thread.c index 470fbb252d..6e809d60fb 100644 --- a/src/interfaces/ecpg/test/expected/thread-thread.c +++ b/src/interfaces/ecpg/test/expected/thread-thread.c @@ -140,22 +140,24 @@ void *test_thread(void *arg) { long threadnum = (long)arg; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - /* exec sql begin declare section */ -#line 107 "thread.pgc" +#line 103 "thread.pgc" int l_i ; -#line 108 "thread.pgc" +#line 104 "thread.pgc" char l_connection [ 128 ] ; /* exec sql end declare section */ -#line 109 "thread.pgc" +#line 105 "thread.pgc" + +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif /* build up connection name, and connect to database */ #ifndef _MSC_VER @@ -164,13 +166,13 @@ void *test_thread(void *arg) _snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum); #endif /* exec sql whenever sqlerror sqlprint ; */ -#line 117 "thread.pgc" +#line 119 "thread.pgc" { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , l_connection, 0); -#line 118 "thread.pgc" +#line 120 "thread.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 118 "thread.pgc" +#line 120 "thread.pgc" if( sqlca.sqlcode != 0 ) { @@ -178,10 +180,10 @@ if (sqlca.sqlcode < 0) sqlprint();} return( NULL ); } { ECPGtrans(__LINE__, l_connection, "begin"); -#line 124 "thread.pgc" +#line 126 "thread.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 124 "thread.pgc" +#line 126 "thread.pgc" /* insert into test_thread table */ @@ -192,10 +194,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 129 "thread.pgc" +#line 131 "thread.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 129 "thread.pgc" +#line 131 "thread.pgc" if( sqlca.sqlcode != 0 ) printf("%s: ERROR: insert failed!\n", l_connection); @@ -203,16 +205,16 @@ if (sqlca.sqlcode < 0) sqlprint();} /* all done */ { ECPGtrans(__LINE__, l_connection, "commit"); -#line 135 "thread.pgc" +#line 137 "thread.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 135 "thread.pgc" +#line 137 "thread.pgc" { ECPGdisconnect(__LINE__, l_connection); -#line 136 "thread.pgc" +#line 138 "thread.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 136 "thread.pgc" +#line 138 "thread.pgc" return( NULL ); } diff --git a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c index 854549e27d..b42c556633 100644 --- a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c +++ b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c @@ -141,22 +141,24 @@ void *test_thread(void *arg) { long threadnum = (long)arg; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - /* exec sql begin declare section */ -#line 108 "thread_implicit.pgc" +#line 104 "thread_implicit.pgc" int l_i ; -#line 109 "thread_implicit.pgc" +#line 105 "thread_implicit.pgc" char l_connection [ 128 ] ; /* exec sql end declare section */ -#line 110 "thread_implicit.pgc" +#line 106 "thread_implicit.pgc" + +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif /* build up connection name, and connect to database */ #ifndef _MSC_VER @@ -165,13 +167,13 @@ void *test_thread(void *arg) _snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum); #endif /* exec sql whenever sqlerror sqlprint ; */ -#line 118 "thread_implicit.pgc" +#line 120 "thread_implicit.pgc" { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , l_connection, 0); -#line 119 "thread_implicit.pgc" +#line 121 "thread_implicit.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 119 "thread_implicit.pgc" +#line 121 "thread_implicit.pgc" if( sqlca.sqlcode != 0 ) { @@ -179,10 +181,10 @@ if (sqlca.sqlcode < 0) sqlprint();} return( NULL ); } { ECPGtrans(__LINE__, NULL, "begin"); -#line 125 "thread_implicit.pgc" +#line 127 "thread_implicit.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 125 "thread_implicit.pgc" +#line 127 "thread_implicit.pgc" /* insert into test_thread table */ @@ -193,10 +195,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 130 "thread_implicit.pgc" +#line 132 "thread_implicit.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 130 "thread_implicit.pgc" +#line 132 "thread_implicit.pgc" if( sqlca.sqlcode != 0 ) printf("%s: ERROR: insert failed!\n", l_connection); @@ -204,16 +206,16 @@ if (sqlca.sqlcode < 0) sqlprint();} /* all done */ { ECPGtrans(__LINE__, NULL, "commit"); -#line 136 "thread_implicit.pgc" +#line 138 "thread_implicit.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 136 "thread_implicit.pgc" +#line 138 "thread_implicit.pgc" { ECPGdisconnect(__LINE__, l_connection); -#line 137 "thread_implicit.pgc" +#line 139 "thread_implicit.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 137 "thread_implicit.pgc" +#line 139 "thread_implicit.pgc" return( NULL ); } diff --git a/src/interfaces/ecpg/test/thread/alloc.pgc b/src/interfaces/ecpg/test/thread/alloc.pgc index 8e6d042d89..b13bcb860b 100644 --- a/src/interfaces/ecpg/test/thread/alloc.pgc +++ b/src/interfaces/ecpg/test/thread/alloc.pgc @@ -36,16 +36,18 @@ static void* fn(void* arg) { int i; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - EXEC SQL BEGIN DECLARE SECTION; int value; char name[100]; char **r = NULL; EXEC SQL END DECLARE SECTION; +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif + value = (long)arg; sprintf(name, "Connection: %d", value); diff --git a/src/interfaces/ecpg/test/thread/descriptor.pgc b/src/interfaces/ecpg/test/thread/descriptor.pgc index c88c05a8a5..3f28c6d329 100644 --- a/src/interfaces/ecpg/test/thread/descriptor.pgc +++ b/src/interfaces/ecpg/test/thread/descriptor.pgc @@ -26,7 +26,9 @@ static void* fn(void* arg) int i; #ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif #endif for (i = 1; i <= REPEATS; ++i) diff --git a/src/interfaces/ecpg/test/thread/prep.pgc b/src/interfaces/ecpg/test/thread/prep.pgc index 1ec96767af..3a2467c9ab 100644 --- a/src/interfaces/ecpg/test/thread/prep.pgc +++ b/src/interfaces/ecpg/test/thread/prep.pgc @@ -36,16 +36,18 @@ static void* fn(void* arg) { int i; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - EXEC SQL BEGIN DECLARE SECTION; int value; char name[100]; char query[256] = "INSERT INTO T VALUES ( ? )"; EXEC SQL END DECLARE SECTION; +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif + value = (long)arg; sprintf(name, "Connection: %d", value); diff --git a/src/interfaces/ecpg/test/thread/thread.pgc b/src/interfaces/ecpg/test/thread/thread.pgc index f08aacdee5..c5fbe928d9 100644 --- a/src/interfaces/ecpg/test/thread/thread.pgc +++ b/src/interfaces/ecpg/test/thread/thread.pgc @@ -99,15 +99,17 @@ void *test_thread(void *arg) { long threadnum = (long)arg; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - EXEC SQL BEGIN DECLARE SECTION; int l_i; char l_connection[128]; EXEC SQL END DECLARE SECTION; +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif + /* build up connection name, and connect to database */ #ifndef _MSC_VER snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum); diff --git a/src/interfaces/ecpg/test/thread/thread_implicit.pgc b/src/interfaces/ecpg/test/thread/thread_implicit.pgc index aab758ed92..d65f17c073 100644 --- a/src/interfaces/ecpg/test/thread/thread_implicit.pgc +++ b/src/interfaces/ecpg/test/thread/thread_implicit.pgc @@ -100,15 +100,17 @@ void *test_thread(void *arg) { long threadnum = (long)arg; -#ifdef WIN32 - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); -#endif - EXEC SQL BEGIN DECLARE SECTION; int l_i; char l_connection[128]; EXEC SQL END DECLARE SECTION; +#ifdef WIN32 +#ifdef _MSC_VER /* requires MSVC */ + _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif +#endif + /* build up connection name, and connect to database */ #ifndef _MSC_VER snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum); -- 2.40.0