summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorPeter Eisentraut2025-03-28 20:27:37 +0000
committerPeter Eisentraut2025-03-28 20:27:37 +0000
commit3c8e463b0d885e0d976f6a13a1fb78187b25c86f (patch)
tree081e2a55ca02580aa2b069fb0ede573392e98a0d /src/port
parent6be53c27673a5fca64a00a684c36c29db6ca33a5 (diff)
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/port')
-rw-r--r--src/port/Makefile1
-rw-r--r--src/port/locale.c84
-rw-r--r--src/port/meson.build1
-rw-r--r--src/port/snprintf.c55
4 files changed, 0 insertions, 141 deletions
diff --git a/src/port/Makefile b/src/port/Makefile
index 3e51bf1bd65..f11896440d5 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -41,7 +41,6 @@ OBJS = \
bsearch_arg.o \
chklocale.o \
inet_net_ntop.o \
- locale.o \
noblock.o \
path.o \
pg_bitutils.o \
diff --git a/src/port/locale.c b/src/port/locale.c
deleted file mode 100644
index b3d48628915..00000000000
--- a/src/port/locale.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * locale.c
- * Helper routines for thread-safe system locale usage.
- *
- *
- * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * src/port/locale.c
- *
- *-------------------------------------------------------------------------
- */
-
-#include "c.h"
-
-#ifndef LC_C_LOCALE
-
-#ifndef WIN32
-#include <pthread.h>
-#else
-#include <synchapi.h>
-#endif
-
-/* A process-lifetime singleton, allocated on first need. */
-static locale_t c_locale;
-
-#ifndef WIN32
-static void
-init_c_locale_once(void)
-{
- c_locale = newlocale(LC_ALL, "C", NULL);
-}
-#else
-static BOOL
-init_c_locale_once(PINIT_ONCE once, PVOID parameter, PVOID *context)
-{
- c_locale = _create_locale(LC_ALL, "C");
- return true;
-}
-#endif
-
-/*
- * Access a process-lifetime singleton locale_t object. Use the macro
- * PG_C_LOCALE instead of calling this directly, as it can skip the function
- * call on some systems.
- */
-locale_t
-pg_get_c_locale(void)
-{
- /*
- * Fast path if already initialized. This assumes that we can read a
- * locale_t (in practice, a pointer) without tearing in a multi-threaded
- * program.
- */
- if (c_locale != (locale_t) 0)
- return c_locale;
-
- /* Make a locale_t. It will live until process exit. */
- {
-#ifndef WIN32
- static pthread_once_t once = PTHREAD_ONCE_INIT;
-
- pthread_once(&once, init_c_locale_once);
-#else
- static INIT_ONCE once;
- InitOnceExecuteOnce(&once, init_c_locale_once, NULL, NULL);
-#endif
- }
-
- /*
- * It's possible that the allocation of the locale failed due to low
- * memory, and then (locale_t) 0 will be returned. Users of PG_C_LOCALE
- * should defend against that by checking pg_ensure_c_locale() at a
- * convenient time, so that they can treat it as a simple constant after
- * that.
- */
-
- return c_locale;
-}
-
-#endif /* not LC_C_LOCALE */
diff --git a/src/port/meson.build b/src/port/meson.build
index 45954dd2808..cf7f07644b9 100644
--- a/src/port/meson.build
+++ b/src/port/meson.build
@@ -4,7 +4,6 @@ pgport_sources = [
'bsearch_arg.c',
'chklocale.c',
'inet_net_ntop.c',
- 'locale.c',
'noblock.c',
'path.c',
'pg_bitutils.c',
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index 376d5c906a0..f8f2018ea0c 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -109,36 +109,6 @@
#undef vprintf
#undef printf
-#if defined(FRONTEND)
-/*
- * Frontend code might be multi-threaded. When calling the system snprintf()
- * for floats, we have to use either the non-standard snprintf_l() variant, or
- * save-and-restore the calling thread's locale using uselocale(), depending on
- * availability.
- */
-#if defined(HAVE_SNPRINTF_L)
-/* At least macOS and the BSDs have the snprintf_l() extension. */
-#define USE_SNPRINTF_L
-#elif defined(WIN32)
-/* Windows has a version with a different name and argument order. */
-#define snprintf_l(str, size, loc, format, ...) _snprintf_l(str, size, format, loc, __VA_ARGS__)
-#define USE_SNPRINTF_L
-#else
-/* We have to do a thread-safe save-and-restore around snprintf(). */
-#define NEED_USE_LOCALE
-#endif
-#else
-/*
- * Backend code doesn't need to worry about locales here, because LC_NUMERIC is
- * set to "C" in main() and doesn't change. Plain old snprintf() is always OK
- * without uselocale().
- *
- * XXX If the backend were multithreaded, we would have to be 100% certain that
- * no one is calling setlocale() concurrently, even transiently, to be able to
- * keep this small optimization.
- */
-#endif
-
/*
* Info about where the formatted output is going.
*
@@ -1250,9 +1220,6 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
* according to == but not according to memcmp.
*/
static const double dzero = 0.0;
-#ifdef NEED_USE_LOCALE
- locale_t save_locale = uselocale(PG_C_LOCALE);
-#endif
if (adjust_sign((value < 0.0 ||
(value == 0.0 &&
@@ -1274,11 +1241,7 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
fmt[2] = '*';
fmt[3] = type;
fmt[4] = '\0';
-#ifdef USE_SNPRINTF_L
- vallen = snprintf_l(convert, sizeof(convert), PG_C_LOCALE, fmt, prec, value);
-#else
vallen = snprintf(convert, sizeof(convert), fmt, prec, value);
-#endif
}
else
{
@@ -1287,11 +1250,6 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
fmt[2] = '\0';
vallen = snprintf(convert, sizeof(convert), fmt, value);
}
-
-#ifdef NEED_USE_LOCALE
- uselocale(save_locale);
-#endif
-
if (vallen < 0)
goto fail;
@@ -1414,25 +1372,12 @@ pg_strfromd(char *str, size_t count, int precision, double value)
}
else
{
-#ifdef NEED_USE_LOCALE
- locale_t save_locale = uselocale(PG_C_LOCALE);
-#endif
-
fmt[0] = '%';
fmt[1] = '.';
fmt[2] = '*';
fmt[3] = 'g';
fmt[4] = '\0';
-#ifdef USE_SNPRINTF_L
- vallen = snprintf_l(convert, sizeof(convert), PG_C_LOCALE, fmt, precision, value);
-#else
vallen = snprintf(convert, sizeof(convert), fmt, precision, value);
-#endif
-
-#ifdef NEED_USE_LOCALE
- uselocale(save_locale);
-#endif
-
if (vallen < 0)
{
target.failed = true;