+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.
@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:
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
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
-# 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,
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])
])
-# 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
])
-# wctype_h.m4 serial 31
+# wctype_h.m4 serial 32
dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
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])
])
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:
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:
-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)' \