From: Bruno Haible Date: Wed, 26 Jul 2023 12:50:00 +0000 (+0200) Subject: wctype: Work around wctype bug on mingw. X-Git-Tag: v1.0~1029 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f4ad51ee78a99f86110a6fe0fc8e319b7500f645;p=gnulib.git wctype: Work around wctype bug on mingw. * lib/wctype.in.h (rpl_wctype_t, wctype_t, GNULIB_defined_wctype_t): Define if REPLACE_WCTYPE is 1. (wctype): Consider REPLACE_WCTYPE. (iswctype): Override also if REPLACE_WCTYPE is 1. * lib/iswctype.c: If GNULIB_defined_wctype_t is defined, use the function-pointer based implementation. * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_WCTYPE. * m4/wctype.m4 (gl_FUNC_WCTYPE): Define through AC_DEFUN_ONCE. Test whether wctype supports the "blank" character class. Set REPLACE_WCTYPE if not. * m4/iswctype.m4 (gl_FUNC_ISWCTYPE): Require gl_FUNC_WCTYPE. * modules/wctype (Status, Notice): Remove. (Depends-on): Add iswctype. Consider REPLACE_WCTYPE. (configure.ac): Consider REPLACE_WCTYPE. * modules/iswctype (Status, Notice): Remove. (Files): Add m4/wctype.m4. (configure.ac): Override also if REPLACE_WCTYPE is 1. * modules/wctype-h (Makefile.am): Substitute REPLACE_WCTYPE. * doc/posix-functions/wctype.texi: Mention the mingw bug. --- diff --git a/ChangeLog b/ChangeLog index 930191fd98..f1e00c8b70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2023-07-26 Bruno Haible + + wctype: Work around wctype bug on mingw. + * lib/wctype.in.h (rpl_wctype_t, wctype_t, GNULIB_defined_wctype_t): + Define if REPLACE_WCTYPE is 1. + (wctype): Consider REPLACE_WCTYPE. + (iswctype): Override also if REPLACE_WCTYPE is 1. + * lib/iswctype.c: If GNULIB_defined_wctype_t is defined, use the + function-pointer based implementation. + * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_WCTYPE. + * m4/wctype.m4 (gl_FUNC_WCTYPE): Define through AC_DEFUN_ONCE. Test + whether wctype supports the "blank" character class. Set REPLACE_WCTYPE + if not. + * m4/iswctype.m4 (gl_FUNC_ISWCTYPE): Require gl_FUNC_WCTYPE. + * modules/wctype (Status, Notice): Remove. + (Depends-on): Add iswctype. Consider REPLACE_WCTYPE. + (configure.ac): Consider REPLACE_WCTYPE. + * modules/iswctype (Status, Notice): Remove. + (Files): Add m4/wctype.m4. + (configure.ac): Override also if REPLACE_WCTYPE is 1. + * modules/wctype-h (Makefile.am): Substitute REPLACE_WCTYPE. + * doc/posix-functions/wctype.texi: Mention the mingw bug. + 2023-07-26 Bruno Haible wctype-h: Work around iswprint bug on mingw. diff --git a/doc/posix-functions/wctype.texi b/doc/posix-functions/wctype.texi index a158cdd102..e4a2b58056 100644 --- a/doc/posix-functions/wctype.texi +++ b/doc/posix-functions/wctype.texi @@ -15,6 +15,10 @@ Minix 3.1.8, MSVC 9. This function is declared in @code{}, not in @code{}, on some platforms: HP-UX 11.00. +@item +This function does not support the @code{"blank"} character class +on some platforms: +mingw. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/iswctype.c b/lib/iswctype.c index 33b5ad49bf..e70446aef9 100644 --- a/lib/iswctype.c +++ b/lib/iswctype.c @@ -20,7 +20,7 @@ /* Specification. */ #include -#if GNULIB_defined_wint_t +#if GNULIB_defined_wint_t && !GNULIB_defined_wctype_t int iswctype (wint_t wc, wctype_t desc) diff --git a/lib/wctype.in.h b/lib/wctype.in.h index a8649b83a1..d7f8a4b758 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -633,15 +633,32 @@ _GL_CXXALIASWARN (iswblank); typedef void * wctype_t; # define GNULIB_defined_wctype_t 1 # endif +#elif @REPLACE_WCTYPE@ +# if !GNULIB_defined_wctype_t +typedef void *rpl_wctype_t; +# undef wctype_t +# define wctype_t rpl_wctype_t +# define GNULIB_defined_wctype_t 1 +# endif #endif /* Get a descriptor for a wide character property. */ #if @GNULIB_WCTYPE@ -# if !@HAVE_WCTYPE_T@ +# if @REPLACE_WCTYPE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wctype +# define wctype rpl_wctype +# endif +_GL_FUNCDECL_RPL (wctype, wctype_t, (const char *name) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (wctype, wctype_t, (const char *name)); +# else +# if !@HAVE_WCTYPE_T@ _GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name) _GL_ARG_NONNULL ((1))); -# endif +# endif _GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name)); +# endif # if __GLIBC__ >= 2 _GL_CXXALIASWARN (wctype); # endif @@ -657,7 +674,7 @@ _GL_WARN_ON_USE (wctype, "wctype is unportable - " The argument WC must be either a wchar_t value or WEOF. The argument DESC must have been returned by the wctype() function. */ #if @GNULIB_ISWCTYPE@ -# if @GNULIBHEADERS_OVERRIDE_WINT_T@ +# if @GNULIBHEADERS_OVERRIDE_WINT_T@ || @REPLACE_WCTYPE@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # undef iswctype # define iswctype rpl_iswctype diff --git a/m4/iswctype.m4 b/m4/iswctype.m4 index e15491f585..5dedaa365a 100644 --- a/m4/iswctype.m4 +++ b/m4/iswctype.m4 @@ -1,4 +1,4 @@ -# iswctype.m4 serial 2 +# iswctype.m4 serial 3 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,4 +8,6 @@ AC_DEFUN([gl_FUNC_ISWCTYPE], [ AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) AC_REQUIRE([gl_WCTYPE_H]) + dnl Determine REPLACE_WCTYPE. + AC_REQUIRE([gl_FUNC_WCTYPE]) ]) diff --git a/m4/wctype.m4 b/m4/wctype.m4 index 7ab497432b..c006873d1b 100644 --- a/m4/wctype.m4 +++ b/m4/wctype.m4 @@ -1,12 +1,43 @@ -# wctype.m4 serial 2 +# wctype.m4 serial 3 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -AC_DEFUN([gl_FUNC_WCTYPE], +AC_DEFUN_ONCE([gl_FUNC_WCTYPE], [ AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) AC_REQUIRE([gl_WCTYPE_H]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles HAVE_WCTYPE=$HAVE_WCTYPE_T + if test $HAVE_WCTYPE = 1; then + AC_CACHE_CHECK([whether wctype supports the "blank" character class], + [gl_cv_func_wctype_works], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ + #include + #include + int main () { return wctype ("blank") == (wctype_t)0; } + ]])], + [gl_cv_func_wctype_works=yes], [gl_cv_func_wctype_works=no], + [case "$host_os" in + # Guess no on mingw. + mingw*) AC_EGREP_CPP([Problem], [ +#ifdef __MINGW32__ + Problem +#endif + ], + [gl_cv_func_wctype_works="guessing no"], + [gl_cv_func_wctype_works="guessing yes"]) + ;; + # Guess yes otherwise. + *) gl_cv_func_wctype_works="guessing yes" ;; + esac + ]) + ]) + case "$gl_cv_func_wctype_works" in + *yes) ;; + *) REPLACE_WCTYPE=1 ;; + esac + fi ]) diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4 index 6856a73595..e968b09daa 100644 --- a/m4/wctype_h.m4 +++ b/m4/wctype_h.m4 @@ -1,4 +1,4 @@ -# wctype_h.m4 serial 30 +# wctype_h.m4 serial 31 dnl A placeholder for ISO C99 , for platforms that lack it. @@ -197,4 +197,5 @@ AC_DEFUN([gl_WCTYPE_H_DEFAULTS], REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK]) REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT]) REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT]) + REPLACE_WCTYPE=0; AC_SUBST([REPLACE_WCTYPE]) ]) diff --git a/modules/iswctype b/modules/iswctype index eb8e68ee03..7f766a7228 100644 --- a/modules/iswctype +++ b/modules/iswctype @@ -1,16 +1,11 @@ Description: iswctype() function: test whether a wide character has a given property. -Status: -obsolete - -Notice: -This module is obsolete. - Files: lib/iswctype.c lib/iswctype-impl.h m4/iswctype.m4 +m4/wctype.m4 Depends-on: wctype-h @@ -18,7 +13,7 @@ wctype-h configure.ac: gl_FUNC_ISWCTYPE gl_CONDITIONAL([GL_COND_OBJ_ISWCTYPE], - [test $HAVE_WCTYPE_T = 0 || test $GNULIBHEADERS_OVERRIDE_WINT_T = 1]) + [test $HAVE_WCTYPE_T = 0 || test $GNULIBHEADERS_OVERRIDE_WINT_T = 1 || test $REPLACE_WCTYPE = 1]) gl_WCTYPE_MODULE_INDICATOR([iswctype]) Makefile.am: diff --git a/modules/wctype b/modules/wctype index 1ef8401d78..f3e449938b 100644 --- a/modules/wctype +++ b/modules/wctype @@ -1,12 +1,6 @@ Description: wctype() function: get descriptor for a wide character property. -Status: -obsolete - -Notice: -This module is obsolete. - Files: lib/wctype.c lib/wctype-impl.h @@ -14,13 +8,15 @@ m4/wctype.m4 Depends-on: wctype-h -iswblank [test $HAVE_WCTYPE = 0] -iswdigit [test $HAVE_WCTYPE = 0] -iswxdigit [test $HAVE_WCTYPE = 0] +iswblank [test $HAVE_WCTYPE = 0 || test $REPLACE_WCTYPE = 1] +iswdigit [test $HAVE_WCTYPE = 0 || test $REPLACE_WCTYPE = 1] +iswxdigit [test $HAVE_WCTYPE = 0 || test $REPLACE_WCTYPE = 1] +# When we override wctype_t, we also need to override iswctype(). +iswctype [test $REPLACE_WCTYPE = 1] configure.ac: gl_FUNC_WCTYPE -gl_CONDITIONAL([GL_COND_OBJ_WCTYPE], [test $HAVE_WCTYPE = 0]) +gl_CONDITIONAL([GL_COND_OBJ_WCTYPE], [test $HAVE_WCTYPE = 0 || test $REPLACE_WCTYPE = 1]) gl_WCTYPE_MODULE_INDICATOR([wctype]) Makefile.am: diff --git a/modules/wctype-h b/modules/wctype-h index d5cc890aee..5f3ca06e67 100644 --- a/modules/wctype-h +++ b/modules/wctype-h @@ -54,6 +54,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''REPLACE_ISWXDIGIT''@/$(REPLACE_ISWXDIGIT)/g' \ -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \ + -e 's/@''REPLACE_WCTYPE''@/$(REPLACE_WCTYPE)/g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \