diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-01-23 22:46:45 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-01-23 22:47:18 -0500 |
commit | 7ac0e71aa623218aad30fb3845ed8771875e6a66 (patch) | |
tree | 5416cfb3d69b8c1f4b24a39c4d8e662ad21f4d4a /src/interfaces/ecpg/ecpglib/execute.c | |
parent | a5e48d1ed42940e64a5f862e319fd4ff8329edb8 (diff) | |
download | postgresql-7ac0e71aa623218aad30fb3845ed8771875e6a66.tar.gz postgresql-7ac0e71aa623218aad30fb3845ed8771875e6a66.zip |
Blind attempt to fix _configthreadlocale() failures on MinGW.
Apparently, some builds of MinGW contain a version of
_configthreadlocale() that always returns -1, indicating failure.
Rather than treating that as a curl-up-and-die condition, soldier on
as though the function didn't exist. This leaves us without thread
safety on such MinGW versions, but we didn't have it anyway.
Discussion: https://postgr.es/m/d06a16bc-52d6-9f0d-2379-21242d7dbe81@2ndQuadrant.com
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/execute.c')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 266b961eba1..790074da958 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1786,7 +1786,9 @@ 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 * database wants the standard decimal point. If available, use * uselocale() for this because it's thread-safe. Windows doesn't have - * that, but it usually does have _configthreadlocale(). + * that, but it usually does have _configthreadlocale(). In some versions + * of MinGW, _configthreadlocale() exists but always returns -1 --- so + * treat that situation as if the function doesn't exist. */ #ifdef HAVE_USELOCALE stmt->clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0); @@ -1804,11 +1806,6 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator, #else #ifdef HAVE__CONFIGTHREADLOCALE stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); - if (stmt->oldthreadlocale == -1) - { - ecpg_do_epilogue(stmt); - return false; - } #endif stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno); if (stmt->oldlocale == NULL) @@ -2025,12 +2022,17 @@ ecpg_do_epilogue(struct statement * stmt) uselocale(stmt->oldlocale); #else if (stmt->oldlocale) - { setlocale(LC_NUMERIC, stmt->oldlocale); #ifdef HAVE__CONFIGTHREADLOCALE - _configthreadlocale(stmt->oldthreadlocale); + + /* + * This is a bit trickier than it looks: if we failed partway through + * statement initialization, oldthreadlocale could still be 0. But that's + * okay because a call with 0 is defined to be a no-op. + */ + if (stmt->oldthreadlocale != -1) + (void) _configthreadlocale(stmt->oldthreadlocale); #endif - } #endif free_statement(stmt); |