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
-- v3: msvcrt: Initialize locale data in new threads.
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
v3: - Changed in test error message to "expected valid locale\n". - Removed _endthread from thread function. - Just initialize ptr->cached_locale instead of calling _setmbcp. - Using _beginthreadex instead of _beginthread. - Removed `__attribute__((unused))`.
On Fri Oct 11 05:08:49 2024 +0000, Bernhard Übelacker wrote:
changed this line in [version 3 of the diff](/wine/wine/-/merge_requests/6644/diffs?diff_id=137535&start_sha=4c3b50c6a53977ea7b0385a4d66b94be009e4fd6#ece23f8c6547d5be996ffa4d8cba691372d92571_857_857)
Done.
The patch looks good for me. Is it intentionally marked as draft?
On Fri Oct 11 15:20:25 2024 +0000, Piotr Caban wrote:
The patch looks good for me. Is it intentionally marked as draft?
Sorry, this was because I was not sure about the `_setmbcp`. But this is got replaced by your proposal.
This merge request was approved by Piotr Caban.