From 042a7042ac582e86693326943979b737c237a214 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 26 Jul 2023 16:32:48 +0200 Subject: [PATCH] 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. --- ChangeLog | 19 ++++++++++++++++++ doc/posix-functions/wctrans.texi | 7 +++++++ lib/wctype.in.h | 34 ++++++++++++++++++++++++++++---- m4/towctrans.m4 | 4 +++- m4/wctrans.m4 | 32 ++++++++++++++++++++++++++++-- m4/wctype_h.m4 | 3 ++- modules/towctrans | 3 ++- modules/wctrans | 4 +++- modules/wctype-h | 1 + 9 files changed, 97 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3da611199f..f7e4613937 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2023-07-26 Bruno Haible + + 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 towctrans: Add tests. diff --git a/doc/posix-functions/wctrans.texi b/doc/posix-functions/wctrans.texi index b48ac9658c..973279a823 100644 --- a/doc/posix-functions/wctrans.texi +++ b/doc/posix-functions/wctrans.texi @@ -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: diff --git a/lib/wctype.in.h b/lib/wctype.in.h index d7f8a4b758..fd52715a8a 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -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 diff --git a/m4/towctrans.m4 b/m4/towctrans.m4 index 6dd8efb93b..82c81788f4 100644 --- a/m4/towctrans.m4 +++ b/m4/towctrans.m4 @@ -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]) ]) diff --git a/m4/wctrans.m4 b/m4/wctrans.m4 index 14eeb53012..5caee9a7f9 100644 --- a/m4/wctrans.m4 +++ b/m4/wctrans.m4 @@ -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 + #include + 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 ]) diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4 index e968b09daa..43a2d9cf10 100644 --- a/m4/wctype_h.m4 +++ b/m4/wctype_h.m4 @@ -1,4 +1,4 @@ -# wctype_h.m4 serial 31 +# wctype_h.m4 serial 32 dnl A placeholder for ISO C99 , 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]) ]) diff --git a/modules/towctrans b/modules/towctrans index 1d61efe8ee..e2eedb81d0 100644 --- a/modules/towctrans +++ b/modules/towctrans @@ -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: diff --git a/modules/wctrans b/modules/wctrans index 99e95013b7..3412903161 100644 --- a/modules/wctrans +++ b/modules/wctrans @@ -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: diff --git a/modules/wctype-h b/modules/wctype-h index 5f3ca06e67..99aba62d90 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_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)' \ -- 2.39.5