Commit ee27584c authored by Tom Lane's avatar Tom Lane

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
parent 527114e5
...@@ -15942,6 +15942,17 @@ fi ...@@ -15942,6 +15942,17 @@ fi
# Win32 (really MinGW) support # Win32 (really MinGW) support
if test "$PORTNAME" = "win32"; then if test "$PORTNAME" = "win32"; then
for ac_func in _configthreadlocale
do :
ac_fn_c_check_func "$LINENO" "_configthreadlocale" "ac_cv_func__configthreadlocale"
if test "x$ac_cv_func__configthreadlocale" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE__CONFIGTHREADLOCALE 1
_ACEOF
fi
done
ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday" ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday"
if test "x$ac_cv_func_gettimeofday" = xyes; then : if test "x$ac_cv_func_gettimeofday" = xyes; then :
$as_echo "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h $as_echo "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h
......
...@@ -1754,6 +1754,7 @@ fi ...@@ -1754,6 +1754,7 @@ fi
# Win32 (really MinGW) support # Win32 (really MinGW) support
if test "$PORTNAME" = "win32"; then if test "$PORTNAME" = "win32"; then
AC_CHECK_FUNCS(_configthreadlocale)
AC_REPLACE_FUNCS(gettimeofday) AC_REPLACE_FUNCS(gettimeofday)
AC_LIBOBJ(dirmod) AC_LIBOBJ(dirmod)
AC_LIBOBJ(kill) AC_LIBOBJ(kill)
......
...@@ -757,6 +757,9 @@ ...@@ -757,6 +757,9 @@
/* Define to 1 if your compiler understands __builtin_unreachable. */ /* Define to 1 if your compiler understands __builtin_unreachable. */
#undef HAVE__BUILTIN_UNREACHABLE #undef HAVE__BUILTIN_UNREACHABLE
/* Define to 1 if you have the `_configthreadlocale' function. */
#undef HAVE__CONFIGTHREADLOCALE
/* Define to 1 if you have __cpuid. */ /* Define to 1 if you have __cpuid. */
#undef HAVE__CPUID #undef HAVE__CPUID
......
...@@ -596,6 +596,9 @@ ...@@ -596,6 +596,9 @@
/* Define to 1 if your compiler understands __builtin_unreachable. */ /* Define to 1 if your compiler understands __builtin_unreachable. */
/* #undef HAVE__BUILTIN_UNREACHABLE */ /* #undef HAVE__BUILTIN_UNREACHABLE */
/* Define to 1 if you have the `_configthreadlocale' function. */
#define HAVE__CONFIGTHREADLOCALE 1
/* Define to 1 if you have __cpuid. */ /* Define to 1 if you have __cpuid. */
#define HAVE__CPUID 1 #define HAVE__CPUID 1
......
...@@ -495,7 +495,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...) ...@@ -495,7 +495,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
if (stmt.clocale != (locale_t) 0) if (stmt.clocale != (locale_t) 0)
stmt.oldlocale = uselocale(stmt.clocale); stmt.oldlocale = uselocale(stmt.clocale);
#else #else
#ifdef WIN32 #ifdef HAVE__CONFIGTHREADLOCALE
stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
#endif #endif
stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno); stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
...@@ -517,7 +517,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...) ...@@ -517,7 +517,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
setlocale(LC_NUMERIC, stmt.oldlocale); setlocale(LC_NUMERIC, stmt.oldlocale);
ecpg_free(stmt.oldlocale); ecpg_free(stmt.oldlocale);
} }
#ifdef WIN32 #ifdef HAVE__CONFIGTHREADLOCALE
if (stmt.oldthreadlocale != -1) if (stmt.oldthreadlocale != -1)
_configthreadlocale(stmt.oldthreadlocale); _configthreadlocale(stmt.oldthreadlocale);
#endif #endif
......
...@@ -69,7 +69,7 @@ struct statement ...@@ -69,7 +69,7 @@ struct statement
locale_t oldlocale; locale_t oldlocale;
#else #else
char *oldlocale; char *oldlocale;
#ifdef WIN32 #ifdef HAVE__CONFIGTHREADLOCALE
int oldthreadlocale; int oldthreadlocale;
#endif #endif
#endif #endif
......
...@@ -1778,7 +1778,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator, ...@@ -1778,7 +1778,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
* Make sure we do NOT honor the locale for numeric input/output since the * Make sure we do NOT honor the locale for numeric input/output since the
* database wants the standard decimal point. If available, use * database wants the standard decimal point. If available, use
* uselocale() for this because it's thread-safe. Windows doesn't have * uselocale() for this because it's thread-safe. Windows doesn't have
* that, but it does have _configthreadlocale(). * that, but it usually does have _configthreadlocale().
*/ */
#ifdef HAVE_USELOCALE #ifdef HAVE_USELOCALE
stmt->clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0); 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, ...@@ -1794,7 +1794,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
return false; return false;
} }
#else #else
#ifdef WIN32 #ifdef HAVE__CONFIGTHREADLOCALE
stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
if (stmt->oldthreadlocale == -1) if (stmt->oldthreadlocale == -1)
{ {
...@@ -2019,7 +2019,7 @@ ecpg_do_epilogue(struct statement *stmt) ...@@ -2019,7 +2019,7 @@ ecpg_do_epilogue(struct statement *stmt)
if (stmt->oldlocale) if (stmt->oldlocale)
{ {
setlocale(LC_NUMERIC, stmt->oldlocale); setlocale(LC_NUMERIC, stmt->oldlocale);
#ifdef WIN32 #ifdef HAVE__CONFIGTHREADLOCALE
_configthreadlocale(stmt->oldthreadlocale); _configthreadlocale(stmt->oldthreadlocale);
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment