+2024-05-23 Bruno Haible <bruno@clisp.org>
+
+ mbrtoc32: Work around bug in Cygwin 3.5.3.
+ * m4/mbrtoc32.m4 (gl_MBRTOC32_UTF8_LOCALE): New macro.
+ (gl_FUNC_MBRTOC32): Invoke it. If mbrtoc32 has this bug, define
+ MBRTOC32_MULTIBYTE_LOCALE_BUG and reset LOCALE_ZH_CN to 'none'.
+ * lib/mbrtoc32.c (mbrtoc32): Test MBRTOC32_MULTIBYTE_LOCALE_BUG.
+ * doc/posix-functions/mbrtoc32.texi: Mention the Cygwin bug.
+
2024-05-23 Bruno Haible <bruno@clisp.org>
c32is*, c32toupper tests: Avoid test failures on Cygwin.
/* Convert multibyte character to 32-bit wide character.
- Copyright (C) 2020-2023 Free Software Foundation, Inc.
+ Copyright (C) 2020-2024 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
if (ps == NULL)
ps = &internal_state;
-# if HAVE_WORKING_MBRTOC32
+# if HAVE_WORKING_MBRTOC32 && !MBRTOC32_MULTIBYTE_LOCALE_BUG
/* mbrtoc32() may produce different values for wc than mbrtowc(). Therefore
use mbrtoc32(). */
-# mbrtoc32.m4 serial 17
-dnl Copyright (C) 2014-2023 Free Software Foundation, Inc.
+# mbrtoc32.m4 serial 17.1
+dnl Copyright (C) 2014-2024 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.
else
gl_MBRTOC32_EMPTY_INPUT
gl_MBRTOC32_C_LOCALE
+ gl_MBRTOC32_UTF8_LOCALE
case "$gl_cv_func_mbrtoc32_empty_input" in
*yes) ;;
*) AC_DEFINE([MBRTOC32_EMPTY_INPUT_BUG], [1],
REPLACE_MBRTOC32=1
;;
esac
+ case "$gl_cv_func_mbrtoc32_utf8_locale_works" in
+ *yes) ;;
+ *) AC_DEFINE([MBRTOC32_MULTIBYTE_LOCALE_BUG], [1],
+ [Define if the mbrtoc32 function does not accept the input bytes one-by-one.])
+ REPLACE_MBRTOC32=1
+ dnl Our replacement mbrtoc32 can handle UTF-8, but not GB18030.
+ LOCALE_ZH_CN=none
+ ;;
+ esac
fi
if test $HAVE_WORKING_MBRTOC32 = 0; then
REPLACE_MBRTOC32=1
])
])
+dnl Test whether mbrtoc32 works when it's fed the bytes one-by-one in an UTF-8
+dnl locale.
+
+AC_DEFUN([gl_MBRTOC32_UTF8_LOCALE],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbrtoc32 works in an UTF-8 locale],
+ [gl_cv_func_mbrtoc32_utf8_locale_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <locale.h>
+ #ifdef __HAIKU__
+ #include <stdint.h>
+ #endif
+ #include <uchar.h>
+ ]], [[
+ char *locale = setlocale (LC_ALL, "en_US.UTF-8");
+ if (locale)
+ {
+ /* This test fails on Cygwin 3.5.3. */
+ mbstate_t state = { 0, };
+ char32_t uc = 0xDEADBEEF;
+ /* \360\237\220\203 = U+0001F403 */
+ if (mbrtoc32 (&uc, "\360", 1, &state) != (size_t)-2)
+ return 1;
+ if (mbrtoc32 (&uc, "\237", 1, &state) != (size_t)-2)
+ return 2;
+ if (mbrtoc32 (&uc, "\220", 1, &state) != (size_t)-2)
+ return 3;
+ if (mbrtoc32 (&uc, "\203", 1, &state) != 1)
+ return 4;
+ if (uc != 0x0001F403)
+ return 5;
+ }
+ return 0;
+ ]])],
+ [gl_cv_func_mbrtoc32_utf8_locale_works=yes],
+ [gl_cv_func_mbrtoc32_utf8_locale_works=no],
+ [case "$host_os" in
+ # Guess no on Cygwin.
+ cygwin*) gl_cv_func_mbrtoc32_utf8_locale_works="guessing yes" ;;
+ *) gl_cv_func_mbrtoc32_utf8_locale_works="$gl_cross_guess_normal" ;;
+ esac
+ ])
+ ])
+])
+
dnl Test whether mbrtoc32 works not worse than mbrtowc.
dnl Result is HAVE_WORKING_MBRTOC32.