diff options
author | Karl Williamson <khw@cpan.org> | 2022-12-01 10:44:08 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2022-12-05 11:54:43 -0700 |
commit | 2a9ab842f968d5b791dda641c9aff2396fd1f024 (patch) | |
tree | 41ee9e4820cce0fe34e25eb02fb0dc2285fbf9e3 | |
parent | 86665b00d95547847396212c376467ff98778ef2 (diff) | |
download | perl-2a9ab842f968d5b791dda641c9aff2396fd1f024.tar.gz |
locale.c: Add mutex lock around _wsetlocale() call
The lock expands to nothing if unthreaded, or thread-local storage is in
effect. But otherwise protects a global value from being clobbered by
another thread.
-rw-r--r-- | locale.c | 4 | ||||
-rw-r--r-- | perl.h | 4 |
2 files changed, 8 insertions, 0 deletions
@@ -2609,14 +2609,18 @@ S_wrap_wsetlocale(pTHX_ const int category, const char *locale) } } + WSETLOCALE_LOCK; const wchar_t * wresult = _wsetlocale(category, wlocale); Safefree(wlocale); if (! wresult) { + WSETLOCALE_UNLOCK; return NULL; } const char * result = Win_wstring_to_utf8_string(wresult); + WSETLOCALE_UNLOCK; + SAVEFREEPV(result); /* is there something better we can do here? */ return result; @@ -7128,6 +7128,10 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect. # define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK #endif +/* It handles _wsetlocale() as well */ +#define WSETLOCALE_LOCK POSIX_SETLOCALE_LOCK +#define WSETLOCALE_UNLOCK POSIX_SETLOCALE_UNLOCK + /* Similar to gwLOCALE_LOCK, there are functions that require both the locale * and environment to be constant during their execution, and don't change * either of those things, but do write to some sort of shared global space. |