]> Savannah Git Hosting - gnulib.git/commitdiff
wctype: Work around wctype bug on mingw.
authorBruno Haible <bruno@clisp.org>
Wed, 26 Jul 2023 12:50:00 +0000 (14:50 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 26 Jul 2023 12:50:00 +0000 (14:50 +0200)
* 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.

ChangeLog
doc/posix-functions/wctype.texi
lib/iswctype.c
lib/wctype.in.h
m4/iswctype.m4
m4/wctype.m4
m4/wctype_h.m4
modules/iswctype
modules/wctype
modules/wctype-h

index 930191fd98f0d889c78e70a72d7321b259a4c687..f1e00c8b702952c3a7f47549aade0774f7c88648 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2023-07-26  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        wctype-h: Work around iswprint bug on mingw.
index a158cdd102f8901d318adc1b11e7217429e4c688..e4a2b58056c4d72358ad9908acbc2e152aa9c949 100644 (file)
@@ -15,6 +15,10 @@ Minix 3.1.8, MSVC 9.
 This function is declared in @code{<wchar.h>}, not in @code{<wctype.h>}, 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:
index 33b5ad49bf91cc2dcf7b65ad5b69cfac36a14879..e70446aef9920ea41e47a67348ea36cffa22a75c 100644 (file)
@@ -20,7 +20,7 @@
 /* Specification.  */
 #include <wctype.h>
 
-#if GNULIB_defined_wint_t
+#if GNULIB_defined_wint_t && !GNULIB_defined_wctype_t
 
 int
 iswctype (wint_t wc, wctype_t desc)
index a8649b83a155242fa5d31c6a880436a6ce8ecbea..d7f8a4b758c682e6ba8af9578de66ba1125f177f 100644 (file)
@@ -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
index e15491f58576100d8866862ac0bb036e6ad09c56..5dedaa365aa2f044b476295e519652319c6edd8c 100644 (file)
@@ -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])
 ])
index 7ab497432b25a5845ef5a8dda58c5eaf0c1bf740..c006873d1b30b371865566331735ebb347b0eb50 100644 (file)
@@ -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 <wchar.h>
+            #include <wctype.h>
+            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
 ])
index 6856a735950e36dc96e43817532573dabc5b2622..e968b09daa321738292446261966889fb211e9cd 100644 (file)
@@ -1,4 +1,4 @@
-# wctype_h.m4 serial 30
+# wctype_h.m4 serial 31
 
 dnl A placeholder for ISO C99 <wctype.h>, 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])
 ])
index eb8e68ee03d448e22fd8cc096e8ca821ace21015..7f766a72282c72f506093ce0c26f16db50bb4613 100644 (file)
@@ -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:
index 1ef8401d780b6b95f1f1404415e8108631bc0a3a..f3e449938b807e1ba51db415056022ee7403e0fe 100644 (file)
@@ -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:
index d5cc890aeec79fa720952f07f445ae99b283e389..5f3ca06e6730ba92643f01fd4a1f18b8381eb058 100644 (file)
@@ -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)' \