Skip to content

Commit 2a9ab84

Browse files
committed
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.
1 parent 86665b0 commit 2a9ab84

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

locale.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,14 +2609,18 @@ S_wrap_wsetlocale(pTHX_ const int category, const char *locale)
26092609
}
26102610
}
26112611

2612+
WSETLOCALE_LOCK;
26122613
const wchar_t * wresult = _wsetlocale(category, wlocale);
26132614
Safefree(wlocale);
26142615

26152616
if (! wresult) {
2617+
WSETLOCALE_UNLOCK;
26162618
return NULL;
26172619
}
26182620

26192621
const char * result = Win_wstring_to_utf8_string(wresult);
2622+
WSETLOCALE_UNLOCK;
2623+
26202624
SAVEFREEPV(result); /* is there something better we can do here? */
26212625

26222626
return result;

perl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7128,6 +7128,10 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
71287128
# define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK
71297129
#endif
71307130

7131+
/* It handles _wsetlocale() as well */
7132+
#define WSETLOCALE_LOCK POSIX_SETLOCALE_LOCK
7133+
#define WSETLOCALE_UNLOCK POSIX_SETLOCALE_UNLOCK
7134+
71317135
/* Similar to gwLOCALE_LOCK, there are functions that require both the locale
71327136
* and environment to be constant during their execution, and don't change
71337137
* either of those things, but do write to some sort of shared global space.

0 commit comments

Comments
 (0)