From: Bruno Haible Date: Wed, 26 Jul 2023 12:13:48 +0000 (+0200) Subject: wctype-h: Work around iswprint bug on mingw. X-Git-Tag: v1.0~1030 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=1a602613384e6dcec05eb693bc63726600520cd7;p=gnulib.git wctype-h: Work around iswprint bug on mingw. * lib/wctype.in.h (rpl_iswprint): On mingw, don't use the system's iswprint function. * tests/test-wctype-h.c (main): Verify that this character class contains the ASCII space but not tab and newline. * tests/test-c32isprint.c (main): For tab, \v, \f, expect the same value on native Windows as on other platforms. * doc/posix-functions/iswprint.texi: Mention the mingw bug. --- diff --git a/ChangeLog b/ChangeLog index 3d602638de..930191fd98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2023-07-26 Bruno Haible + + wctype-h: Work around iswprint bug on mingw. + * lib/wctype.in.h (rpl_iswprint): On mingw, don't use the system's + iswprint function. + * tests/test-wctype-h.c (main): Verify that this character class + contains the ASCII space but not tab and newline. + * tests/test-c32isprint.c (main): For tab, \v, \f, expect the same value + on native Windows as on other platforms. + * doc/posix-functions/iswprint.texi: Mention the mingw bug. + 2023-07-26 Bruno Haible iswblank tests: Add more tests. diff --git a/doc/posix-functions/iswprint.texi b/doc/posix-functions/iswprint.texi index 90ce3057e0..728baa0b7b 100644 --- a/doc/posix-functions/iswprint.texi +++ b/doc/posix-functions/iswprint.texi @@ -15,6 +15,10 @@ Minix 3.1.8. This function cannot be called from plain inline or extern inline functions on some platforms: OS X 10.8. +@item +This function returns true for the tab (@code{'\t'}) character +on some platforms: +mingw. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/wctype.in.h b/lib/wctype.in.h index 926a78d621..a8649b83a1 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -132,7 +132,8 @@ typedef unsigned int rpl_wint_t; /* FreeBSD 4.4 to 4.11 has but lacks the functions. Linux libc5 has and the functions but they are broken. mingw and MSVC have and the functions but they take a wchar_t - as argument, not an rpl_wint_t. + as argument, not an rpl_wint_t. Additionally, the mingw iswprint function + is broken. Assume all 11 functions (all isw* except iswblank) are implemented the same way, or not at all. */ # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@ @@ -184,7 +185,11 @@ rpl_iswlower (wint_t wc) _GL_WCTYPE_INLINE int rpl_iswprint (wint_t wc) { +# ifdef __MINGW32__ + return ((wchar_t) wc == wc ? wc == ' ' || iswgraph ((wchar_t) wc) : 0); +# else return ((wchar_t) wc == wc ? iswprint ((wchar_t) wc) : 0); +# endif } _GL_WCTYPE_INLINE int diff --git a/tests/test-c32isprint.c b/tests/test-c32isprint.c index b7617ee105..18ccf55677 100644 --- a/tests/test-c32isprint.c +++ b/tests/test-c32isprint.c @@ -68,9 +68,7 @@ main (int argc, char *argv[]) for (c = 0; c < 0x100; c++) switch (c) { - #if !(defined _WIN32 && !defined __CYGWIN__) case '\t': case '\v': case '\f': - #endif case ' ': case '!': case '"': case '#': case '%': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case '-': case '.': case '/': diff --git a/tests/test-wctype-h.c b/tests/test-wctype-h.c index ceee02bc7f..af02fe7eb6 100644 --- a/tests/test-wctype-h.c +++ b/tests/test-wctype-h.c @@ -62,6 +62,11 @@ main (void) ASSERT (!iswupper (e)); ASSERT (!iswxdigit (e)); + /* Sanity check for the iswprint function. */ + ASSERT (iswprint (L' ')); + ASSERT (!iswprint (L'\t')); + ASSERT (!iswprint (L'\n')); + /* Check that the tow* functions exist as functions or as macros. */ (void) towlower (0); (void) towupper (0);