On Sat, 14 Dec 2019, Martin Storsjö wrote:

On Sat, 14 Dec 2019, Liu Hao wrote:

在 2019/12/14 4:17, Martin Storsjö 写道:
For some reason, gnulib tries to provide its own function mbsinit (which
is used for checking if an mbstate_t is initialized or not), even if one
is provided. (I guess the reason for this misdetection, is that in UCRT
mode, mbsinit is purely available as an inline function, there's no
function available in the UCRT dll, and the gnulib check might only test
linking without using the right header.)

Perhaps we should provide a custom mbsinit function in the UCRT import
libraries - that should hopefully make gnulib realize the function
exists, and avoid trying to provide it.


Referring to the file 'mbsinit.m4' in GnuLib I get this:

```m4
   if test $REPLACE_MBSTATE_T = 1; then
     REPLACE_MBSINIT=1
   else
     dnl On mingw, mbsinit() always returns 1, which is inappropriate for
     dnl states produced by mbrtowc() for an incomplete multibyte character
     dnl in multibyte locales.
     case "$host_os" in
       mingw*) REPLACE_MBSINIT=1 ;;
     esac
   fi
```

Thus I presume that providing an out-of-line `mbsinit()` will not fix
the issue, as it is replaced unconditionally if the triplet matches
`*-*-mingw*`.

Ah, yes, indeed.

But there's another plot twist. If mbsinit is deemed to be missing (as it is with ucrt right now), gnulib also replaces the definition of mbstate_t like this:

typedef int rpl_mbstate_t;
#undef mbstate_t
#define mbstate_t rpl_mbstate_t

That's why the gnulib-provided mbsinit has built fine for me - but if actually providing mbsinit, it breaks as gnulib still tries to build its own mbsinit, but using the system's mbstate_t type.

This issue is now fixed in upstream gnulib, in https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=f61573abd91da7f722b8b4a1dc97bea9b81b17a3.

After some amount of time, when this version of gnulib hopefully has propagated into more source packages, we can probably go ahead with the proper ucrt mbsinit function, see further discussion at https://savannah.gnu.org/bugs/?57406.

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to