A couple of tiny tweaks related to mbrtowc and mbrtoc32.
2023-06-28 Bruno Haible <br...@clisp.org> c32*: Update comment. * lib/c32is-impl.h (FUNC): Add comment regarding Android. * lib/c32to-impl.h (FUNC): Likewise. * lib/c32width.c (c32width): Likewise. 2023-06-28 Bruno Haible <br...@clisp.org> mbrtoc32: Doc tweak. * doc/posix-functions/mbrtoc32.texi: Mention that mingw and Android have the empty input bug. * m4/mbrtoc32.m4 (gl_MBRTOC32_EMPTY_INPUT): Update cross-compilation guess. 2023-06-28 Bruno Haible <br...@clisp.org> mbrtowc: Doc tweak. * doc/posix-functions/mbrtowc.texi: Mention that MSVC has the empty input bug and the return value bug. Mention that Android has the empty input bug. * m4/mbrtowc.m4 (gl_MBRTOC32_EMPTY_INPUT): Update cross-compilation guess. 2023-06-28 Bruno Haible <br...@clisp.org> mbrtowc, mbrtoc32: Simplify autoconf macros. * m4/mbrtowc.m4 (gl_MBRTOWC_EMPTY_INPUT, gl_MBRTOWC_C_LOCALE): Put cross-compilation guess at the usual place. * m4/mbrtoc32.m4 (gl_MBRTOC32_EMPTY_INPUT, gl_MBRTOC32_C_LOCALE): Likewise.
>From cd1ae3e11e81293127b40626c7f9f12f41a1e576 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 27 Jun 2023 21:19:28 +0200 Subject: [PATCH 1/4] mbrtowc, mbrtoc32: Simplify autoconf macros. * m4/mbrtowc.m4 (gl_MBRTOWC_EMPTY_INPUT, gl_MBRTOWC_C_LOCALE): Put cross-compilation guess at the usual place. * m4/mbrtoc32.m4 (gl_MBRTOC32_EMPTY_INPUT, gl_MBRTOC32_C_LOCALE): Likewise. --- ChangeLog | 8 ++++++ m4/mbrtoc32.m4 | 40 ++++++++++++----------------- m4/mbrtowc.m4 | 69 ++++++++++++++++++++++---------------------------- 3 files changed, 54 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 820285f2d9..a200f5078a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-06-28 Bruno Haible <br...@clisp.org> + + mbrtowc, mbrtoc32: Simplify autoconf macros. + * m4/mbrtowc.m4 (gl_MBRTOWC_EMPTY_INPUT, gl_MBRTOWC_C_LOCALE): Put + cross-compilation guess at the usual place. + * m4/mbrtoc32.m4 (gl_MBRTOC32_EMPTY_INPUT, gl_MBRTOC32_C_LOCALE): + Likewise. + 2023-06-27 Bruno Haible <br...@clisp.org> c32*: Optionally enforce ISO C 23 semantics of char32_t. diff --git a/m4/mbrtoc32.m4 b/m4/mbrtoc32.m4 index 52dd913f8a..f5798db4a3 100644 --- a/m4/mbrtoc32.m4 +++ b/m4/mbrtoc32.m4 @@ -1,4 +1,4 @@ -# mbrtoc32.m4 serial 15 +# mbrtoc32.m4 serial 16 dnl Copyright (C) 2014-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, @@ -87,15 +87,6 @@ AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT] AC_CACHE_CHECK([whether mbrtoc32 works on empty input], [gl_cv_func_mbrtoc32_empty_input], [ - dnl Initial guess, used when cross-compiling or when no suitable locale - dnl is present. -changequote(,)dnl - case "$host_os" in - # Guess no on glibc systems. - *-gnu* | gnu*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;; - *) gl_cv_func_mbrtoc32_empty_input="guessing yes" ;; - esac -changequote([,])dnl AC_RUN_IFELSE( [AC_LANG_SOURCE([[ #ifdef __HAIKU__ @@ -111,7 +102,12 @@ AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT] }]])], [gl_cv_func_mbrtoc32_empty_input=yes], [gl_cv_func_mbrtoc32_empty_input=no], - [:]) + [case "$host_os" in + # Guess no on glibc systems. + *-gnu* | gnu*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;; + *) gl_cv_func_mbrtoc32_empty_input="guessing yes" ;; + esac + ]) ]) ]) @@ -125,12 +121,7 @@ AC_DEFUN([gl_MBRTOC32_C_LOCALE] AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_CACHE_CHECK([whether the C locale is free of encoding errors], [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ], - [ - dnl Initial guess, used when cross-compiling or when no suitable locale - dnl is present. - gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="$gl_cross_guess_normal" - - AC_RUN_IFELSE( + [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#include <limits.h> #include <locale.h> @@ -154,13 +145,14 @@ AC_DEFUN([gl_MBRTOC32_C_LOCALE] } return 0; ]])], - [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=yes], - [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=no], - [case "$host_os" in - # Guess yes on native Windows. - mingw*) gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="guessing yes" ;; - esac - ]) + [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=yes], + [gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ=no], + [case "$host_os" in + # Guess yes on native Windows. + mingw*) gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="guessing yes" ;; + *) gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="$gl_cross_guess_normal" ;; + esac + ]) ]) ]) diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4 index 6173ded2ff..04e282d24a 100644 --- a/m4/mbrtowc.m4 +++ b/m4/mbrtowc.m4 @@ -1,4 +1,4 @@ -# mbrtowc.m4 serial 41 -*- coding: utf-8 -*- +# mbrtowc.m4 serial 42 -*- coding: utf-8 -*- dnl Copyright (C) 2001-2002, 2004-2005, 2008-2023 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -682,31 +682,26 @@ AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT] AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_CACHE_CHECK([whether mbrtowc works on empty input], [gl_cv_func_mbrtowc_empty_input], - [ - dnl Initial guess, used when cross-compiling or when no suitable locale - dnl is present. -changequote(,)dnl - case "$host_os" in - # Guess no on AIX and glibc systems. - aix* | *-gnu* | gnu*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; - # Guess yes on native Windows. - mingw*) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; - *) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; - esac -changequote([,])dnl - AC_RUN_IFELSE( - [AC_LANG_SOURCE([[ - #include <wchar.h> - static wchar_t wc; - static mbstate_t mbs; - int - main (void) - { - return mbrtowc (&wc, "", 0, &mbs) != (size_t) -2; - }]])], - [gl_cv_func_mbrtowc_empty_input=yes], - [gl_cv_func_mbrtowc_empty_input=no], - [:]) + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ + #include <wchar.h> + static wchar_t wc; + static mbstate_t mbs; + int + main (void) + { + return mbrtowc (&wc, "", 0, &mbs) != (size_t) -2; + }]])], + [gl_cv_func_mbrtowc_empty_input=yes], + [gl_cv_func_mbrtowc_empty_input=no], + [case "$host_os" in + # Guess no on AIX and glibc systems. + aix* | *-gnu* | gnu*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; + # Guess yes on native Windows. + mingw*) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; + *) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; + esac + ]) ]) ]) @@ -724,12 +719,7 @@ AC_DEFUN([gl_MBRTOWC_C_LOCALE] AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_CACHE_CHECK([whether the C locale is free of encoding errors], [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ], - [ - dnl Initial guess, used when cross-compiling or when no suitable locale - dnl is present. - gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="$gl_cross_guess_normal" - - AC_RUN_IFELSE( + [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#include <limits.h> #include <locale.h> @@ -750,13 +740,14 @@ AC_DEFUN([gl_MBRTOWC_C_LOCALE] } return 0; ]])], - [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=yes], - [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=no], - [case "$host_os" in - # Guess yes on native Windows. - mingw*) gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="guessing yes" ;; - esac - ]) + [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=yes], + [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=no], + [case "$host_os" in + # Guess yes on native Windows. + mingw*) gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="guessing yes" ;; + *) gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="$gl_cross_guess_normal" ;; + esac + ]) ]) ]) -- 2.34.1
>From 79ad2a8d02a7888d845ea4eda716f884ad53093c Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 28 Jun 2023 15:01:33 +0200 Subject: [PATCH 2/4] mbrtowc: Doc tweak. * doc/posix-functions/mbrtowc.texi: Mention that MSVC has the empty input bug and the return value bug. Mention that Android has the empty input bug. * m4/mbrtowc.m4 (gl_MBRTOC32_EMPTY_INPUT): Update cross-compilation guess. --- ChangeLog | 9 +++++++++ doc/posix-functions/mbrtowc.texi | 4 ++-- m4/mbrtowc.m4 | 8 +++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a200f5078a..e1d2c81d5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-06-28 Bruno Haible <br...@clisp.org> + + mbrtowc: Doc tweak. + * doc/posix-functions/mbrtowc.texi: Mention that MSVC has the empty + input bug and the return value bug. Mention that Android has the empty + input bug. + * m4/mbrtowc.m4 (gl_MBRTOC32_EMPTY_INPUT): Update cross-compilation + guess. + 2023-06-28 Bruno Haible <br...@clisp.org> mbrtowc, mbrtoc32: Simplify autoconf macros. diff --git a/doc/posix-functions/mbrtowc.texi b/doc/posix-functions/mbrtowc.texi index 163a374ea2..52471978fc 100644 --- a/doc/posix-functions/mbrtowc.texi +++ b/doc/posix-functions/mbrtowc.texi @@ -18,7 +18,7 @@ @item This function returns 0 instead of @code{(size_t) -2} when the input is empty: -glibc 2.19. +glibc 2.19, MSVC 14, Android 11. @item This function returns @code{(size_t) -1} instead of @code{(size_t) -2} when the input is empty: @@ -35,7 +35,7 @@ This function returns the total number of bytes that make up the multibyte character, not the number of bytes that were needed to complete the multibyte character, on some platforms: -HP-UX 11.11, Solaris 11 2010-11, mingw, possibly MSVC 14. +HP-UX 11.11, Solaris 11 2010-11, mingw, MSVC 14. @item This function may not return 0 when parsing the NUL character on some platforms: Solaris 9. diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4 index 04e282d24a..430e9ad832 100644 --- a/m4/mbrtowc.m4 +++ b/m4/mbrtowc.m4 @@ -1,4 +1,4 @@ -# mbrtowc.m4 serial 42 -*- coding: utf-8 -*- +# mbrtowc.m4 serial 43 -*- coding: utf-8 -*- dnl Copyright (C) 2001-2002, 2004-2005, 2008-2023 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -697,8 +697,10 @@ AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT] [case "$host_os" in # Guess no on AIX and glibc systems. aix* | *-gnu* | gnu*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; - # Guess yes on native Windows. - mingw*) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; + # Guess no on Android. + linux*-android*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; + # Guess no on native Windows. + mingw*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; *) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; esac ]) -- 2.34.1
>From 489c6dc7baf1671c356a04473db7ebe160d3d7aa Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 28 Jun 2023 12:35:21 +0200 Subject: [PATCH 3/4] mbrtoc32: Doc tweak. * doc/posix-functions/mbrtoc32.texi: Mention that mingw and Android have the empty input bug. * m4/mbrtoc32.m4 (gl_MBRTOC32_EMPTY_INPUT): Update cross-compilation guess. --- ChangeLog | 8 ++++++++ doc/posix-functions/mbrtoc32.texi | 4 +++- m4/mbrtoc32.m4 | 14 ++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1d2c81d5f..44e3f9a6da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-06-28 Bruno Haible <br...@clisp.org> + + mbrtoc32: Doc tweak. + * doc/posix-functions/mbrtoc32.texi: Mention that mingw and Android have + the empty input bug. + * m4/mbrtoc32.m4 (gl_MBRTOC32_EMPTY_INPUT): Update cross-compilation + guess. + 2023-06-28 Bruno Haible <br...@clisp.org> mbrtowc: Doc tweak. diff --git a/doc/posix-functions/mbrtoc32.texi b/doc/posix-functions/mbrtoc32.texi index 91f88bf86f..8792a7b11b 100644 --- a/doc/posix-functions/mbrtoc32.texi +++ b/doc/posix-functions/mbrtoc32.texi @@ -16,13 +16,15 @@ @item This function returns 0 instead of @code{(size_t) -2} when the input is empty: -glibc 2.19, +glibc 2.19, mingw, Android 11, @c https://dev.haiku-os.org/ticket/18350 Haiku. @item This function does not recognize multibyte sequences that @code{mbrtowc} recognizes on some platforms: FreeBSD 13.0, Solaris 11.4, mingw, MSVC 14. +@c For MSVC this is because it assumes that the input is always UTF-8 encoded. +@c See https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/mbrtoc16-mbrtoc323 @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/mbrtoc32.m4 b/m4/mbrtoc32.m4 index f5798db4a3..25196039bb 100644 --- a/m4/mbrtoc32.m4 +++ b/m4/mbrtoc32.m4 @@ -1,4 +1,4 @@ -# mbrtoc32.m4 serial 16 +# mbrtoc32.m4 serial 17 dnl Copyright (C) 2014-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, @@ -80,6 +80,8 @@ AC_DEFUN([gl_CHECK_FUNC_MBRTOC32] fi ]) +dnl Test whether mbrtoc32 returns the correct value on empty input. + AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT], [ AC_REQUIRE([AC_PROG_CC]) @@ -103,9 +105,13 @@ AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT] [gl_cv_func_mbrtoc32_empty_input=yes], [gl_cv_func_mbrtoc32_empty_input=no], [case "$host_os" in - # Guess no on glibc systems. - *-gnu* | gnu*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;; - *) gl_cv_func_mbrtoc32_empty_input="guessing yes" ;; + # Guess no on glibc systems. + *-gnu* | gnu*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;; + # Guess no on Android. + linux*-android*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;; + # Guess no on native Windows. + mingw*) gl_cv_func_mbrtoc32_empty_input="guessing no" ;; + *) gl_cv_func_mbrtoc32_empty_input="guessing yes" ;; esac ]) ]) -- 2.34.1
>From efea5d928393f4a9e08ca00b95898e3b8d4e8ddf Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 28 Jun 2023 15:27:18 +0200 Subject: [PATCH 4/4] c32*: Update comment. * lib/c32is-impl.h (FUNC): Add comment regarding Android. * lib/c32to-impl.h (FUNC): Likewise. * lib/c32width.c (c32width): Likewise. --- ChangeLog | 7 +++++++ lib/c32is-impl.h | 2 +- lib/c32to-impl.h | 2 +- lib/c32width.c | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44e3f9a6da..878e99cfcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-06-28 Bruno Haible <br...@clisp.org> + + c32*: Update comment. + * lib/c32is-impl.h (FUNC): Add comment regarding Android. + * lib/c32to-impl.h (FUNC): Likewise. + * lib/c32width.c (c32width): Likewise. + 2023-06-28 Bruno Haible <br...@clisp.org> mbrtoc32: Doc tweak. diff --git a/lib/c32is-impl.h b/lib/c32is-impl.h index aadc1bc7bd..fd916341ee 100644 --- a/lib/c32is-impl.h +++ b/lib/c32is-impl.h @@ -57,7 +57,7 @@ FUNC (wint_t wc) else return 0; -#elif HAVE_WORKING_MBRTOC32 /* glibc */ +#elif HAVE_WORKING_MBRTOC32 /* glibc, Android */ /* mbrtoc32() is essentially defined by the system libc. */ # if _GL_WCHAR_T_IS_UCS4 diff --git a/lib/c32to-impl.h b/lib/c32to-impl.h index e3e6ad1631..94ca7bdfb5 100644 --- a/lib/c32to-impl.h +++ b/lib/c32to-impl.h @@ -53,7 +53,7 @@ FUNC (wint_t wc) else return wc; -#elif HAVE_WORKING_MBRTOC32 /* glibc */ +#elif HAVE_WORKING_MBRTOC32 /* glibc, Android */ /* mbrtoc32() is essentially defined by the system libc. */ # if _GL_WCHAR_T_IS_UCS4 diff --git a/lib/c32width.c b/lib/c32width.c index 16ed595278..1bea29dfba 100644 --- a/lib/c32width.c +++ b/lib/c32width.c @@ -58,7 +58,7 @@ c32width (char32_t wc) else return wcwidth (wc); -#elif HAVE_WORKING_MBRTOC32 /* glibc */ +#elif HAVE_WORKING_MBRTOC32 /* glibc, Android */ /* mbrtoc32() is essentially defined by the system libc. */ # if _GL_WCHAR_T_IS_UCS4 -- 2.34.1