aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/execute.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2025-03-28 21:27:37 +0100
committerPeter Eisentraut <peter@eisentraut.org>2025-03-28 21:27:37 +0100
commit3c8e463b0d885e0d976f6a13a1fb78187b25c86f (patch)
tree081e2a55ca02580aa2b069fb0ede573392e98a0d /src/interfaces/ecpg/ecpglib/execute.c
parent6be53c27673a5fca64a00a684c36c29db6ca33a5 (diff)
downloadpostgresql-3c8e463b0d885e0d976f6a13a1fb78187b25c86f.tar.gz
postgresql-3c8e463b0d885e0d976f6a13a1fb78187b25c86f.zip
Revert "Tidy up locale thread safety in ECPG library."
This reverts commit 8e993bff5326b00ced137c837fce7cd1e0ecae14. It causes various build failures on the buildfarm, to be investigated. Discussion: https://postgr.es/m/CWZBBRR6YA8D.8EHMDRGLCKCD%40neon.tech
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/execute.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 2bbd8522ef2..f52da06de9a 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -101,6 +101,9 @@ free_statement(struct statement *stmt)
free_variable(stmt->outlist);
ecpg_free(stmt->command);
ecpg_free(stmt->name);
+#ifndef HAVE_USELOCALE
+ ecpg_free(stmt->oldlocale);
+#endif
ecpg_free(stmt);
}
@@ -1971,6 +1974,43 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
return false;
/*
+ * 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 does have _configthreadlocale().
+ */
+#ifdef HAVE_USELOCALE
+
+ /*
+ * Since ecpg_init() succeeded, we have a connection. Any successful
+ * connection initializes ecpg_clocale.
+ */
+ Assert(ecpg_clocale);
+ stmt->oldlocale = uselocale(ecpg_clocale);
+ if (stmt->oldlocale == (locale_t) 0)
+ {
+ ecpg_do_epilogue(stmt);
+ return false;
+ }
+#else
+#ifdef WIN32
+ 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)
+ {
+ ecpg_do_epilogue(stmt);
+ return false;
+ }
+ setlocale(LC_NUMERIC, "C");
+#endif
+
+ /*
* If statement type is ECPGst_prepnormal we are supposed to prepare the
* statement before executing them
*/
@@ -2176,6 +2216,19 @@ ecpg_do_epilogue(struct statement *stmt)
if (stmt == NULL)
return;
+#ifdef HAVE_USELOCALE
+ if (stmt->oldlocale != (locale_t) 0)
+ uselocale(stmt->oldlocale);
+#else
+ if (stmt->oldlocale)
+ {
+ setlocale(LC_NUMERIC, stmt->oldlocale);
+#ifdef WIN32
+ _configthreadlocale(stmt->oldthreadlocale);
+#endif
+ }
+#endif
+
free_statement(stmt);
}