Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2023-02-06 13:27:44 +0300
committerCorinna Vinschen <corinna@vinschen.de>2023-02-06 18:04:33 +0300
commit23e49b18ce39bff5693a6dc8edbacfa59df79dab (patch)
treefe9783a59c12a6a045710fd350790656a94d14de /newlib/libc/locale
parentc6e601de84ea9f2be2b026c609cc3c1fe82a3103 (diff)
setlocale: create LC_ALL string when changing locale
This patch is for the sake of gnulib. gnulib implements some form of a thread-safe setlocale variant called setlocale_null_r, which is supposed to return the locale strings in a thread-safe manner. This only succeeds if the system's setlocale already handles this thread-safe, otherwise gnulib adds some locking on its own. Newlib's setlocale always writes the global string array holding the LC_ALL value anew on each invocation of setlocale(LC_ALL, NULL). Since that doesn't allow to call setlocale(LC_ALL, NULL) in a thread-safe manner, so locking in gnulib is required. And here's the problem... The lock is decorated as dllexport when building for Cygwin. This collides with the default behaviour of ld to export all symbols. If it finds one decorated symbol, it will only export this symbol to the DLL import lib. Change setlocale so that it writes the global string array holding the LC_ALL value at the time the locale gets changed. On setlocale(LC_ALL, NULL), just return the pointer to the global LC_ALL string array, just as in GLibc. The burden of doing so is negligibly for all targets, but adds thread-safety for gnulib's setlocal_null_r() function, and gnulib can drop the lock entirely when building for Cygwin. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'newlib/libc/locale')
-rw-r--r--newlib/libc/locale/locale.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index 65e2b1833..b0f6314ff 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -289,7 +289,8 @@ struct __locale_t __global_locale =
/* Renamed from current_locale_string to make clear this is only the
*global* string for setlocale (LC_ALL, NULL). There's no equivalent
functionality for uselocale. */
-static char global_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
+static char global_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]
+ = "C";
static char *currentlocale (void);
#endif /* _MB_CAPABLE */
@@ -312,6 +313,7 @@ _setlocale_r (struct _reent *p,
static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
int i, j, len, saverr;
const char *env, *r;
+ char *ret;
if (category < LC_ALL || category >= _LC_LAST)
{
@@ -321,7 +323,7 @@ _setlocale_r (struct _reent *p,
if (locale == NULL)
return category != LC_ALL ? __get_global_locale ()->categories[category]
- : currentlocale();
+ : global_locale_string;
/*
* Default to the current locale for everything.
@@ -415,8 +417,12 @@ _setlocale_r (struct _reent *p,
}
if (category != LC_ALL)
- return __loadlocale (__get_global_locale (), category,
- new_categories[category]);
+ {
+ ret = __loadlocale (__get_global_locale (), category,
+ new_categories[category]);
+ currentlocale ();
+ return ret;
+ }
for (i = 1; i < _LC_LAST; ++i)
{