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

Commit 2cf91cc

Browse files
committed
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
1 parent ae366aa commit 2cf91cc

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/interfaces/ecpg/ecpglib/descriptor.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
519519
}
520520
#ifdef HAVE__CONFIGTHREADLOCALE
521521
if (stmt.oldthreadlocale != -1)
522-
_configthreadlocale(stmt.oldthreadlocale);
522+
(void) _configthreadlocale(stmt.oldthreadlocale);
523523
#endif
524524
#endif
525525
}

src/interfaces/ecpg/ecpglib/execute.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,9 @@ 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 usually does have _configthreadlocale().
1781+
* that, but it usually does have _configthreadlocale(). In some versions
1782+
* of MinGW, _configthreadlocale() exists but always returns -1 --- so
1783+
* treat that situation as if the function doesn't exist.
17821784
*/
17831785
#ifdef HAVE_USELOCALE
17841786
stmt->clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
@@ -1796,11 +1798,6 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
17961798
#else
17971799
#ifdef HAVE__CONFIGTHREADLOCALE
17981800
stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
1799-
if (stmt->oldthreadlocale == -1)
1800-
{
1801-
ecpg_do_epilogue(stmt);
1802-
return false;
1803-
}
18041801
#endif
18051802
stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
18061803
if (stmt->oldlocale == NULL)
@@ -2017,12 +2014,17 @@ ecpg_do_epilogue(struct statement *stmt)
20172014
uselocale(stmt->oldlocale);
20182015
#else
20192016
if (stmt->oldlocale)
2020-
{
20212017
setlocale(LC_NUMERIC, stmt->oldlocale);
20222018
#ifdef HAVE__CONFIGTHREADLOCALE
2023-
_configthreadlocale(stmt->oldthreadlocale);
2019+
2020+
/*
2021+
* This is a bit trickier than it looks: if we failed partway through
2022+
* statement initialization, oldthreadlocale could still be 0. But that's
2023+
* okay because a call with 0 is defined to be a no-op.
2024+
*/
2025+
if (stmt->oldthreadlocale != -1)
2026+
(void) _configthreadlocale(stmt->oldthreadlocale);
20242027
#endif
2025-
}
20262028
#endif
20272029

20282030
free_statement(stmt);

0 commit comments

Comments
 (0)