]> Savannah Git Hosting - gnulib.git/commitdiff
wctrans: Work around bug on NetBSD.
authorBruno Haible <bruno@clisp.org>
Wed, 26 Jul 2023 14:32:48 +0000 (16:32 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 26 Jul 2023 14:32:48 +0000 (16:32 +0200)
* lib/wctype.in.h (rpl_wctrans_t, wctrans_t, GNULIB_defined_wctrans_t):
Define if REPLACE_WCTRANS is 1.
(wctrans): Consider REPLACE_WCTRANS.
(towctrans): Override if REPLACE_WCTRANS is 1.
* m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_WCTRANS.
* m4/wctrans.m4 (gl_FUNC_WCTRANS): Define through AC_DEFUN_ONCE. Test
whether wctrans supports the "tolower" character mapping. Set
REPLACE_WCTRANS if not.
* m4/towctrans.m4 (gl_FUNC_TOWCTRANS): Require gl_FUNC_WCTRANS.
* modules/wctrans (Depends-on): Add towctrans.
(configure.ac): Consider REPLACE_WCTRANS.
* modules/towctrans (Files): Add m4/wctrans.m4.
(configure.ac): Override also if REPLACE_WCTRANS is 1.
* modules/wctype-h (Makefile.am): Substitute REPLACE_WCTRANS.
* doc/posix-functions/wctrans.texi: Mention the NetBSD bug.

ChangeLog
doc/posix-functions/wctrans.texi
lib/wctype.in.h
m4/towctrans.m4
m4/wctrans.m4
m4/wctype_h.m4
modules/towctrans
modules/wctrans
modules/wctype-h

index 3da611199f3aa25b563132dc65a24c9bf38a9ca1..f7e46139376568475f0bb0896f7699eb01799d36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2023-07-26  Bruno Haible  <bruno@clisp.org>
+
+       wctrans: Work around bug on NetBSD.
+       * lib/wctype.in.h (rpl_wctrans_t, wctrans_t, GNULIB_defined_wctrans_t):
+       Define if REPLACE_WCTRANS is 1.
+       (wctrans): Consider REPLACE_WCTRANS.
+       (towctrans): Override if REPLACE_WCTRANS is 1.
+       * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_WCTRANS.
+       * m4/wctrans.m4 (gl_FUNC_WCTRANS): Define through AC_DEFUN_ONCE. Test
+       whether wctrans supports the "tolower" character mapping. Set
+       REPLACE_WCTRANS if not.
+       * m4/towctrans.m4 (gl_FUNC_TOWCTRANS): Require gl_FUNC_WCTRANS.
+       * modules/wctrans (Depends-on): Add towctrans.
+       (configure.ac): Consider REPLACE_WCTRANS.
+       * modules/towctrans (Files): Add m4/wctrans.m4.
+       (configure.ac): Override also if REPLACE_WCTRANS is 1.
+       * modules/wctype-h (Makefile.am): Substitute REPLACE_WCTRANS.
+       * doc/posix-functions/wctrans.texi: Mention the NetBSD bug.
+
 2023-07-26  Bruno Haible  <bruno@clisp.org>
 
        towctrans: Add tests.
index b48ac9658c4189f4dc14dde956f06c82c031f5a7..973279a82390e3118f3ae74f0394f14056d96f05 100644 (file)
@@ -11,6 +11,13 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Minix 3.1.8, HP-UX 11.00, IRIX 6.5, mingw, MSVC 9, Android 7.1.
+@item
+This function does not support the @code{"tolower"} and @code{"toupper"}
+mappings on some platforms:
+NetBSD 9.3.
+(It returns non-null values for the arguments @code{"towlower"} and
+@code{"towupper"}, but with these values, the function @code{towctrans}
+always crashes.)
 @end itemize
 
 Portability problems not fixed by Gnulib:
index d7f8a4b758c682e6ba8af9578de66ba1125f177f..fd52715a8ac04056c2d56dd6c435375b302900fd 100644 (file)
@@ -715,15 +715,32 @@ _GL_CXXALIASWARN (towupper);
 typedef void * wctrans_t;
 #  define GNULIB_defined_wctrans_t 1
 # endif
+#elif @REPLACE_WCTRANS@
+# if !GNULIB_defined_wctrans_t
+typedef void *rpl_wctrans_t;
+#  undef wctrans_t
+#  define wctrans_t rpl_wctrans_t
+#  define GNULIB_defined_wctrans_t 1
+# endif
 #endif
 
 /* Get a descriptor for a wide character case conversion.  */
 #if @GNULIB_WCTRANS@
-# if !@HAVE_WCTRANS_T@
+# if @REPLACE_WCTRANS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wctrans
+#   define wctrans rpl_wctrans
+#  endif
+_GL_FUNCDECL_RPL (wctrans, wctrans_t, (const char *name)
+                                      _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (wctrans, wctrans_t, (const char *name));
+# else
+#  if !@HAVE_WCTRANS_T@
 _GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name)
                                       _GL_ARG_NONNULL ((1)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name));
+# endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (wctrans);
 # endif
@@ -739,10 +756,19 @@ _GL_WARN_ON_USE (wctrans, "wctrans is unportable - "
    The argument WC must be either a wchar_t value or WEOF.
    The argument DESC must have been returned by the wctrans() function.  */
 #if @GNULIB_TOWCTRANS@
-# if !@HAVE_WCTRANS_T@
+# if @REPLACE_WCTRANS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef towctrans
+#   define towctrans rpl_towctrans
+#  endif
+_GL_FUNCDECL_RPL (towctrans, wint_t, (wint_t wc, wctrans_t desc));
+_GL_CXXALIAS_RPL (towctrans, wint_t, (wint_t wc, wctrans_t desc));
+# else
+#  if !@HAVE_WCTRANS_T@
 _GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
+# endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (towctrans);
 # endif
index 6dd8efb93b8c317d0a4d41e9bbe92167764cd3bb..82c81788f4ffb952d9c949bf97604c8c7f3ac585 100644 (file)
@@ -1,4 +1,4 @@
-# towctrans.m4 serial 2
+# towctrans.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,
@@ -9,4 +9,6 @@ AC_DEFUN([gl_FUNC_TOWCTRANS],
   AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
   AC_REQUIRE([gl_WCTYPE_H])
   HAVE_TOWCTRANS=$HAVE_WCTRANS_T
+  dnl Determine REPLACE_WCTRANS.
+  AC_REQUIRE([gl_FUNC_WCTRANS])
 ])
index 14eeb53012f32e62d062644164e8be397f14d798..5caee9a7f95c1d23ff885fdde93371d5515a6691 100644 (file)
@@ -1,12 +1,40 @@
-# wctrans.m4 serial 2
+# wctrans.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_WCTRANS],
+AC_DEFUN_ONCE([gl_FUNC_WCTRANS],
 [
   AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
   AC_REQUIRE([gl_WCTYPE_H])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   HAVE_WCTRANS=$HAVE_WCTRANS_T
+  if test $HAVE_WCTRANS = 1; then
+    AC_CACHE_CHECK([whether wctrans works],
+      [gl_cv_func_wctrans_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_SOURCE([[
+            #include <wchar.h>
+            #include <wctype.h>
+            int main ()
+            {
+              /* This test fails on NetBSD 9.3.  */
+              return (wctrans ("tolower") == (wctrans_t)0);
+            }
+         ]])],
+         [gl_cv_func_wctrans_works=yes], [gl_cv_func_wctrans_works=no],
+         [case "$host_os" in
+                     # Guess no on NetBSD.
+            netbsd*) gl_cv_func_wctrans_works="guessing no" ;;
+                     # Guess yes otherwise.
+            *)       gl_cv_func_wctrans_works="guessing yes" ;;
+          esac
+         ])
+      ])
+    case "$gl_cv_func_wctrans_works" in
+      *yes) ;;
+      *) REPLACE_WCTRANS=1 ;;
+    esac
+  fi
 ])
index e968b09daa321738292446261966889fb211e9cd..43a2d9cf10a7497ec3a1e391ae368e83f49e9d31 100644 (file)
@@ -1,4 +1,4 @@
-# wctype_h.m4 serial 31
+# wctype_h.m4 serial 32
 
 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
 
@@ -197,5 +197,6 @@ 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_WCTRANS=0;    AC_SUBST([REPLACE_WCTRANS])
   REPLACE_WCTYPE=0;     AC_SUBST([REPLACE_WCTYPE])
 ])
index 1d61efe8ee229bf941554122fd7d58d245fc81e8..e2eedb81d0aace3a5806dbe68381d047f1e6a566 100644 (file)
@@ -5,13 +5,14 @@ Files:
 lib/towctrans.c
 lib/towctrans-impl.h
 m4/towctrans.m4
+m4/wctrans.m4
 
 Depends-on:
 wctype-h
 
 configure.ac:
 gl_FUNC_TOWCTRANS
-gl_CONDITIONAL([GL_COND_OBJ_TOWCTRANS], [test $HAVE_TOWCTRANS = 0])
+gl_CONDITIONAL([GL_COND_OBJ_TOWCTRANS], [test $HAVE_TOWCTRANS = 0 || test $REPLACE_WCTRANS = 1])
 gl_WCTYPE_MODULE_INDICATOR([towctrans])
 
 Makefile.am:
index 99e95013b7b35fec1784fda9229d184b52364197..3412903161b8b4347ff7bacf60cf1bd3538440b6 100644 (file)
@@ -8,10 +8,12 @@ m4/wctrans.m4
 
 Depends-on:
 wctype-h
+# When we override wctrans_t, we also need to override towctrans().
+towctrans       [test $REPLACE_WCTRANS = 1]
 
 configure.ac:
 gl_FUNC_WCTRANS
-gl_CONDITIONAL([GL_COND_OBJ_WCTRANS], [test $HAVE_WCTRANS = 0])
+gl_CONDITIONAL([GL_COND_OBJ_WCTRANS], [test $HAVE_WCTRANS = 0 || test $REPLACE_WCTRANS = 1])
 gl_WCTYPE_MODULE_INDICATOR([wctrans])
 
 Makefile.am:
index 5f3ca06e6730ba92643f01fd4a1f18b8381eb058..99aba62d90e5bdfb67b56e00c2b202c8c64d805b 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_WCTRANS''@/$(REPLACE_WCTRANS)/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)' \