LIU Hao wrote:
> 在 2026-2-12 14:12, Kirill Makurin 写道:
>> Hello,
>>
>> When Pali sent patches which added __mingw_isleadbyte_cp, I suggested we use
>> it in __mingw_mbrtowc_cp instead of CRT's isleadbyte. These two patches do
>> it.
>>
>> Second patch moves __mingw_mbrtowc_cp and __mingw_wcrtomb_cp from import
>> libraries to libmingwx, which I think is a good idea. This allows us to use
>> them in any mingw-w64 code; their primary limitation right now is that they
>> only handles conversions using SBCS and DBCS code pages.
>
> UCRT `mbstate_t` is quite different from MSVCRT one.
This is true. MSVCRT's `mbstate_t` is just an `int`, but UCRT's is `struct
{long; short; short}`. However, __mingw_{mbrtowc,wcrtomb}_cp access `mbstate_t`
as an `int` and they should work find with properly initialized UCRT's
`mbstate_t`.
> For UCRT, if these functions do not operate on
> `mbstate_t` in the same way as Microsoft functions, then it's just a world of
> unspecified behavior.
Both __mingw_{mbrtowc,wcrtomb}_cp are mingw-w64's private functions, so there
is no need to use `mbstate_t` the same way as CRT does. On top of that, UCRT
uses `long` member of `mbstate_t` the same way as MSVCRT uses `mbstate_t` as
whole with SBCS/DBCS code pages; both `short` members in UCRT's `mbstate_t` are
only used when converting UTF-8.
> If `__mingw_mbrtowc_cp()` would be useful for UCRT, it had better be
> implemented separately. (However I
> know it would be rather insufficient.)
It is something that is possible, but I'm not sure if it's worth the trouble.
In posix32, I have implementation of uchar.h functions (including mbrtoc8 and
c8rtomb) which work even with MSVCRT's `mbstate_t`. However, it would be a lot
of work to adopt the implementation to work with mingw-w64.
- Kirill Makurin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public