From: Bernhard Übelacker bernhardu@mailbox.org
This attempts to initialize the thread data more like in the mainthread, which does in msvcrt_init_locale a call to _setmbcp, which finally fills the cached_locale member of the thread data.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57250 --- dlls/msvcrt/tests/locale.c | 25 +++++++++++++++++++++++++ dlls/msvcrt/thread.c | 2 ++ 2 files changed, 27 insertions(+)
diff --git a/dlls/msvcrt/tests/locale.c b/dlls/msvcrt/tests/locale.c index cb56fe39754..1bc8d2270d4 100644 --- a/dlls/msvcrt/tests/locale.c +++ b/dlls/msvcrt/tests/locale.c @@ -19,6 +19,7 @@ */
#include <locale.h> +#include <process.h>
#include "wine/test.h" #include "winnls.h" @@ -845,6 +846,29 @@ static void test__wcsicmp_l(void) } }
+static unsigned __stdcall test_thread_setlocale_func(void *arg) +{ + char *ret; + + ret = setlocale(LC_ALL, NULL); + ok(!strcmp(ret, "C"), "expected ret=C, but received ret=%s\n", ret); + + ret = setlocale(LC_ALL, ""); + ok(strcmp(ret, "Invariant Language_Invariant Country.0"), "expected valid locale\n"); + + return 0; +} + +static void test_thread_setlocale(void) +{ + HANDLE hThread; + + hThread = (HANDLE)_beginthreadex(NULL, 0, test_thread_setlocale_func, NULL, 0, NULL); + ok(hThread != INVALID_HANDLE_VALUE, "_beginthread failed (%d)\n", errno); + WaitForSingleObject(hThread, 5000); + CloseHandle(hThread); +} + START_TEST(locale) { init(); @@ -854,4 +878,5 @@ START_TEST(locale) test__Gettnames(); test___mb_cur_max_func(); test__wcsicmp_l(); + test_thread_setlocale(); } diff --git a/dlls/msvcrt/thread.c b/dlls/msvcrt/thread.c index 6aad9a22d47..2a8a99b847b 100644 --- a/dlls/msvcrt/thread.c +++ b/dlls/msvcrt/thread.c @@ -57,6 +57,8 @@ thread_data_t *CDECL msvcrt_get_thread_data(void) ptr->random_seed = 1; ptr->locinfo = MSVCRT_locale->locinfo; ptr->mbcinfo = MSVCRT_locale->mbcinfo; + ptr->cached_locale[0] = 'C'; + ptr->cached_locale[1] = 0; #if _MSVCR_VER >= 140 ptr->module = NULL; #endif