summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-01-21 12:07:02 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-01-21 12:07:02 -0500
commit8eb4a9312c95be56cdb31f5411eddc2cb2ba89be (patch)
tree1cfab525b41d18d3bb8a223d44afa6a366b2bd17 /src/interfaces/ecpg/ecpglib/ecpglib_extern.h
parentf4593bd2ff0376fbc56dd1b384c7d51e1a7062f0 (diff)
Avoid thread-safety problem in ecpglib.
ecpglib attempts to force the LC_NUMERIC locale to "C" while reading server output, to avoid problems with strtod() and related functions. Historically it's just issued setlocale() calls to do that, but that has major problems if we're in a threaded application. setlocale() itself is not required by POSIX to be thread-safe (and indeed is not, on recent OpenBSD). Moreover, its effects are process-wide, so that we could cause unexpected results in other threads, or another thread could change our setting. On platforms having uselocale(), which is required by POSIX:2008, we can avoid these problems by using uselocale() instead. Windows goes its own way as usual, but we can make it safe by using _configthreadlocale(). Platforms having neither continue to use the old code, but that should be pretty much nobody among current systems. This should get back-patched, but let's see what the buildfarm thinks of it first. Michael Meskes and Tom Lane; thanks also to Takayuki Tsunakawa. Discussion: https://postgr.es/m/31420.1547783697@sss.pgh.pa.us
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/ecpglib_extern.h')
-rw-r--r--src/interfaces/ecpg/ecpglib/ecpglib_extern.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
index 1c9bce1456d..41851d59007 100644
--- a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
+++ b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
@@ -12,6 +12,9 @@
#ifndef CHAR_BIT
#include <limits.h>
#endif
+#ifdef LOCALE_T_IN_XLOCALE
+#include <xlocale.h>
+#endif
enum COMPAT_MODE
{
@@ -61,7 +64,15 @@ struct statement
bool questionmarks;
struct variable *inlist;
struct variable *outlist;
+#ifdef HAVE_USELOCALE
+ locale_t clocale;
+ locale_t oldlocale;
+#else
char *oldlocale;
+#ifdef WIN32
+ int oldthreadlocale;
+#endif
+#endif
int nparams;
char **paramvalues;
PGresult *results;