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

Commit ee27584

Browse files
committed
Second try at fixing ecpglib thread-safety problem.
While Windows (allegedly) has _configthreadlocale() pretty far back, it seems MinGW didn't acquire support for that till more recently. Fortunately, we can use an autoconf probe on that toolchain, instead of guessing whether it's there. (Hm, I wonder whether Cygwin will need this also.) Per buildfarm. Discussion: https://postgr.es/m/20190121193512.tdmcnic2yjxlufaw@alap3.anarazel.de
1 parent 527114e commit ee27584

File tree

7 files changed

+24
-6
lines changed

7 files changed

+24
-6
lines changed

configure

+11
Original file line numberDiff line numberDiff line change
@@ -15942,6 +15942,17 @@ fi
1594215942

1594315943
# Win32 (really MinGW) support
1594415944
if test "$PORTNAME" = "win32"; then
15945+
for ac_func in _configthreadlocale
15946+
do :
15947+
ac_fn_c_check_func "$LINENO" "_configthreadlocale" "ac_cv_func__configthreadlocale"
15948+
if test "x$ac_cv_func__configthreadlocale" = xyes; then :
15949+
cat >>confdefs.h <<_ACEOF
15950+
#define HAVE__CONFIGTHREADLOCALE 1
15951+
_ACEOF
15952+
15953+
fi
15954+
done
15955+
1594515956
ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday"
1594615957
if test "x$ac_cv_func_gettimeofday" = xyes; then :
1594715958
$as_echo "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h

configure.in

+1
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,7 @@ fi
17541754

17551755
# Win32 (really MinGW) support
17561756
if test "$PORTNAME" = "win32"; then
1757+
AC_CHECK_FUNCS(_configthreadlocale)
17571758
AC_REPLACE_FUNCS(gettimeofday)
17581759
AC_LIBOBJ(dirmod)
17591760
AC_LIBOBJ(kill)

src/include/pg_config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@
757757
/* Define to 1 if your compiler understands __builtin_unreachable. */
758758
#undef HAVE__BUILTIN_UNREACHABLE
759759

760+
/* Define to 1 if you have the `_configthreadlocale' function. */
761+
#undef HAVE__CONFIGTHREADLOCALE
762+
760763
/* Define to 1 if you have __cpuid. */
761764
#undef HAVE__CPUID
762765

src/include/pg_config.h.win32

+3
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@
596596
/* Define to 1 if your compiler understands __builtin_unreachable. */
597597
/* #undef HAVE__BUILTIN_UNREACHABLE */
598598

599+
/* Define to 1 if you have the `_configthreadlocale' function. */
600+
#define HAVE__CONFIGTHREADLOCALE 1
601+
599602
/* Define to 1 if you have __cpuid. */
600603
#define HAVE__CPUID 1
601604

src/interfaces/ecpg/ecpglib/descriptor.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
495495
if (stmt.clocale != (locale_t) 0)
496496
stmt.oldlocale = uselocale(stmt.clocale);
497497
#else
498-
#ifdef WIN32
498+
#ifdef HAVE__CONFIGTHREADLOCALE
499499
stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
500500
#endif
501501
stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
@@ -517,7 +517,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
517517
setlocale(LC_NUMERIC, stmt.oldlocale);
518518
ecpg_free(stmt.oldlocale);
519519
}
520-
#ifdef WIN32
520+
#ifdef HAVE__CONFIGTHREADLOCALE
521521
if (stmt.oldthreadlocale != -1)
522522
_configthreadlocale(stmt.oldthreadlocale);
523523
#endif

src/interfaces/ecpg/ecpglib/ecpglib_extern.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct statement
6969
locale_t oldlocale;
7070
#else
7171
char *oldlocale;
72-
#ifdef WIN32
72+
#ifdef HAVE__CONFIGTHREADLOCALE
7373
int oldthreadlocale;
7474
#endif
7575
#endif

src/interfaces/ecpg/ecpglib/execute.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
17781778
* Make sure we do NOT honor the locale for numeric input/output since the
17791779
* database wants the standard decimal point. If available, use
17801780
* uselocale() for this because it's thread-safe. Windows doesn't have
1781-
* that, but it does have _configthreadlocale().
1781+
* that, but it usually does have _configthreadlocale().
17821782
*/
17831783
#ifdef HAVE_USELOCALE
17841784
stmt->clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
@@ -1794,7 +1794,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
17941794
return false;
17951795
}
17961796
#else
1797-
#ifdef WIN32
1797+
#ifdef HAVE__CONFIGTHREADLOCALE
17981798
stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
17991799
if (stmt->oldthreadlocale == -1)
18001800
{
@@ -2019,7 +2019,7 @@ ecpg_do_epilogue(struct statement *stmt)
20192019
if (stmt->oldlocale)
20202020
{
20212021
setlocale(LC_NUMERIC, stmt->oldlocale);
2022-
#ifdef WIN32
2022+
#ifdef HAVE__CONFIGTHREADLOCALE
20232023
_configthreadlocale(stmt->oldthreadlocale);
20242024
#endif
20252025
}

0 commit comments

Comments
 (0)