``` The new testcases don't build in UCRT mode - see https://github.com/mstorsjo/mingw-w64/actions/runs/16238894867/job/45852642223#step:5:4386 ```
Right... I forgot that UCRT's mbstate_t is a structure when was writing the tests initially. I noticed and fixed this issue in my project (from which I based both implementation and tests), but forgot to mirror the fix in sent patches. I attached a patch which should fix it. I am only unsure whether it is OK to check for _UCRT, maybe checking __MSVCRT_VERSION__ would be better? - Kirill Makurin ________________________________ From: Martin Storsjö <[email protected]> Sent: Sunday, July 13, 2025 5:19 AM To: mingw-w64-public <[email protected]> Cc: Kirill Makurin <[email protected]> Subject: Re: [Mingw-w64-public] New implementation for C95 conversion functions On Sat, 12 Jul 2025, LIU Hao wrote: > 在 2025-7-9 21:09, Kirill Makurin 写道: >> Here's the updated patches. They passed all tests[1]. >> >> The reason was that when misc/btowc.c and misc/wctob.c were compiled >> for UCRT, they were using msvcr*.dll's mbstate_t which has different >> size. I added new misc/ucrt_btowc.c and misc/ucrt_wctob.c for UCRT >> compilation. >> >> I also discovered one case when wcrtomb would return incorrect value. >> The fix is included. > > I think this series of patches now look fine, so I pushed them. There > were some typos in the second one ('valie' => 'value') which I fixed. > Thanks for the work. The new testcases don't build in UCRT mode - see https://github.com/mstorsjo/mingw-w64/actions/runs/16238894867/job/45852642223#step:5:4386. (We don't have them hooked up in CI in git master yet, as I'm not very satisfied with the way of fixing building the testcases to not use the same CFLAGS as the rest of mingw-w64-crt.) Some of the errors seem to be: ../testcases/t_mbrlen.c:48:9: error: assigning to 'mbstate_t' (aka 'struct _Mbstatet') from incompatible type 'char' 48 | state = Ascii[0]; | ^ ~~~~~~~~ ../testcases/t_wcrtomb.c:45:9: error: assigning to 'mbstate_t' (aka 'struct _Mbstatet') from incompatible type 'int' 45 | state = 1; | ^ ~ // Martin
From 738ede3e5fb3b13c2d12655a947ec9d84dbbfd7d Mon Sep 17 00:00:00 2001 From: Kirill Makurin <[email protected]> Date: Sun, 13 Jul 2025 06:30:06 +0900 Subject: [PATCH 1/1] crt: fix compilation of tests for mbrlen, mbrtowc and wcrtomb funtions Compilation of tests for mbrlen, mbrtowc and wcrtomb fails with UCRT. UCRT's mbstate_t is a structure and cannot be directly assigned a value. To fix this, define a function to set mbstate_t's conversion state. Signed-off-by: Kirill Makurin <[email protected]> --- mingw-w64-crt/testcases/t_mbrlen.c | 10 +++++++++- mingw-w64-crt/testcases/t_mbrtowc.c | 10 +++++++++- mingw-w64-crt/testcases/t_wcrtomb.c | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mingw-w64-crt/testcases/t_mbrlen.c b/mingw-w64-crt/testcases/t_mbrlen.c index 0cf6b1836..4d297e3b7 100644 --- a/mingw-w64-crt/testcases/t_mbrlen.c +++ b/mingw-w64-crt/testcases/t_mbrlen.c @@ -9,6 +9,14 @@ #include <stdlib.h> #include <wchar.h> +static void set_conversion_state (mbstate_t *state, int bytes) { +#ifdef _UCRT + state->_Wchar = bytes; +#else + *state = bytes; +#endif +} + char Ascii[] = {'a'}; char NonAscii[] = {(char) 0x80}; char Multibyte[] = {(char) 0x81, (char) 0x81}; @@ -45,7 +53,7 @@ int main (void) { * NOTE: this is optional error condition specified in POSIX. * This check fails with CRT's mbrlen. */ - state = Ascii[0]; + set_conversion_state (&state, Ascii[0]); assert (mbrlen ((char *) &Ascii, MB_CUR_MAX, &state) == (size_t) -1); assert (!mbsinit (&state)); diff --git a/mingw-w64-crt/testcases/t_mbrtowc.c b/mingw-w64-crt/testcases/t_mbrtowc.c index fd2fcb7de..1b94207ca 100644 --- a/mingw-w64-crt/testcases/t_mbrtowc.c +++ b/mingw-w64-crt/testcases/t_mbrtowc.c @@ -9,6 +9,14 @@ #include <stdlib.h> #include <wchar.h> +static void set_conversion_state (mbstate_t *state, int bytes) { +#ifdef _UCRT + state->_Wchar = bytes; +#else + *state = bytes; +#endif +} + char Ascii[] = {'a'}; char NonAscii[] = {(char) 0x80}; char Multibyte[] = {(char) 0x81, (char) 0x81}; @@ -47,7 +55,7 @@ int main (void) { * NOTE: this is optional error condition specified in POSIX. * This check fails with CRT's mbrtowc. */ - state = Ascii[0]; + set_conversion_state (&state, Ascii[0]); wc = WEOF; assert (mbrtowc (&wc, (char *) &Ascii, MB_CUR_MAX, &state) == (size_t) -1); diff --git a/mingw-w64-crt/testcases/t_wcrtomb.c b/mingw-w64-crt/testcases/t_wcrtomb.c index 76d8ca02f..f6e44f410 100644 --- a/mingw-w64-crt/testcases/t_wcrtomb.c +++ b/mingw-w64-crt/testcases/t_wcrtomb.c @@ -12,6 +12,14 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> +static void set_conversion_state (mbstate_t *state, int bytes) { +#ifdef _UCRT + state->_Wchar = bytes; +#else + *state = bytes; +#endif +} + int main (void) { #if __MSVCRT_VERSION__ >= 0x0800 return 77; @@ -42,7 +50,7 @@ int main (void) { * NOTE: this is optional error condition specified in POSIX. * This check fails with CRT's wcrtomb. */ - state = 1; + set_conversion_state (&state, 1); if (1) { char c = EOF; -- 2.50.0.windows.2
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
