On Sat, Jan 24, 2026 at 01:20:34PM +0200, Eli Zaretskii wrote:
> >  In file included from ./wctype.h:56,
> >                   from d:\usr\include\wchar.h:62,
> >                   from ./wchar.h:77,
> >                   from btowc.c:21:
> >      ./wchar.h:1135:10: error: unknown type name 'mbstate_t'

...

> > 
> > This is because the MinGW wchar.h includes wctype.h, so we include the
> > Gnulib's version of it, and that one then turns around and includes
> > wchar.h again.  But because the MinGW wchar.h was not yet completely
> > processed, mbstate_t is not yet defined.
> > 
> > I don't know how to solve this cleanly.  I hope Bruno will know.  The
> > kludge I used was not to include wchar.h from wctype.h.  The original
> > Gnulib's wctype.h includes wchar.h twice:
> > 
> > #if 1
> > /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.  */
> > # include <wchar.h>
> > #endif
> > 
> > /* Native Windows (mingw, MSVC) have declarations of towupper, towlower, and
> >    isw* functions in <ctype.h>, <wchar.h> as well as in <wctype.h>.  Include
> >    <ctype.h>, <wchar.h> in advance to avoid rpl_ prefix being added to the
> >    declarations.  */
> > #if defined _WIN32 && ! defined __CYGWIN__
> > # include <ctype.h>
> > # include <wchar.h>
> > #endif
> > 
> > I needed to remove both these lines.
> > 
> > Another Gnulib-related problem was with stdio-consolesafe.c:

...

I'm reviewing remaining issues to be worked on before the next Texinfo
pretest.  Has there been any progress on these issues?

I saw that there was a patch to fix the stdio-consolesafe.c issue:
https://lists.gnu.org/archive/html/bug-gnulib/2026-01/msg00205.html.

I saw some emails between you and Bruno on bug-gnulib, but no final
resolution of the wchar.h/wctype.h issue:
https://lists.gnu.org/archive/html/bug-gnulib/2026-01/msg00210.html

As Eli's patch showed, it appears to be unnecessary on the MinGW
system he is using to include wchar.h in the Gnulib wchar.h.

The first include is guarded by HAVE_WINT_T:

#if @HAVE_WINT_T@
/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.  */
# include <wchar.h>
#endif

Perhaps there is another condition that could be used instead that would
be limited to the Solaris 2.5 situation?

As for the second, the comment says it is for the sake of MinGW, so
it is odd that it should break the build on MinGW:

/* Native Windows (mingw, MSVC) have declarations of towupper, towlower, and
   isw* functions in <ctype.h>, <wchar.h> as well as in <wctype.h>.  Include
   <ctype.h>, <wchar.h> in advance to avoid rpl_ prefix being added to the
   declarations.  */
#if defined _WIN32 && ! defined __CYGWIN__
# include <ctype.h>
# include <wchar.h>
#endif

Perhaps Eli could advise if the problem this is supposed to solve exists
on the version of MinGW he is using?  Could there be some way to distinguish
between "old" MinGW and "new" MinGW?

Eli wrote:
> I see only one: _WCHAR_H.  But it's the idempotency guard of wchar.h,
> and will be defined once wchar.h was included for the first time, so
> I'm not sure it's what you want.

If I understand correctly, the idea is to check if we are being included
from wchar.h.  Hence the _WCHAR_H would suffice, as long as it was defined
before the include.  (If it was defined right at the end of the file, it
wouldn't work.)

If that doesn't work, another possibility to use symbols in a file included
by wchar.h before it included wctype.h (if there are any).

Another idea is, that since the problem comes about when including from
system wchar.h, that is included from Gnulib wchar.h, some symbol could
be defined in Gnulib wchar.h before including <ctype.h>.  The Gnulib
include guard symbol _GL_WCTYPE_H isn't defined until after wchar.h is
included but there could be another one.

I have limited understanding of the issues involved so apologise if
I am suggesting something that is obviously wrong.




Reply via email to