2024-12-23 Paul Eggert <eggert@cs.ucla.edu>
+ stdlib: fix MB_CUR_MAX on older Android
+ Android NDK r16 MB_CUR_MAX doesn’t link when compiling C.
+ Problem found in GNU Emacs, which worked around it this way:
+ https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=39a7e6b79fdeafc539a36f6831d922a2622cb679
+ ... but this ran afoul of the recent Gnulib change that
+ added lib/stdlib.c.
+ * lib/stdlib.in.h (gl_MB_CUR_MAX): If @REPLACE_MB_CUR_MAX@
+ is positive, use its value directly.
+ * m4/stdlib_h.m4 (gl_STDLIB_H): Set REPLACE_MB_CUR_MAX to (-1)
+ if the Solaris bug, and to 4 if the Android bug. Use AS_CASE
+ so that Emacs can navigate this code better.
+ * tests/test-stdlib.c (main): Check that MB_CUR_MAX compiles
+ and is nonzero.
+
stdlib: MB_CUR_MAX is type size_t
* lib/stdlib.in.h (gl_MB_CUR_MAX): Return size_t, not int,
to conform to POSIX.
# endif
#endif
-/* Return maximum number of bytes of a multibyte character. */
+/* Return maximum number of bytes in a multibyte character in the
+ current locale. */
#if @REPLACE_MB_CUR_MAX@
# if !GNULIB_defined_MB_CUR_MAX
_GL_STDLIB_INLINE size_t
gl_MB_CUR_MAX (void)
{
+# if 0 < @REPLACE_MB_CUR_MAX@
+ return @REPLACE_MB_CUR_MAX@;
+# else
/* Turn the value 3 to the value 4, as needed for the UTF-8 encoding. */
int gl_mb_cur_max = MB_CUR_MAX;
return gl_mb_cur_max == 3 ? 4 : gl_mb_cur_max;
+# endif
}
# undef MB_CUR_MAX
# define MB_CUR_MAX gl_MB_CUR_MAX ()
# stdlib_h.m4
-# serial 82
+# serial 83
dnl Copyright (C) 2007-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,
AC_REQUIRE([gt_LOCALE_EN_UTF8])
AC_CACHE_CHECK([whether MB_CUR_MAX is correct],
[gl_cv_macro_MB_CUR_MAX_good],
- [
- dnl Initial guess, used when cross-compiling or when no suitable locale
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[#include <stdlib.h>
+ ]],
+ [[return !!MB_CUR_MAX;]])],
+ [dnl Initial guess, used when cross-compiling or when no suitable locale
dnl is present.
-changequote(,)dnl
- case "$host_os" in
- # Guess no on Solaris and Haiku.
- solaris* | haiku*) gl_cv_macro_MB_CUR_MAX_good="guessing no" ;;
- # Guess yes otherwise.
- *) gl_cv_macro_MB_CUR_MAX_good="guessing yes" ;;
- esac
-changequote([,])dnl
+ # Guess no on Solaris and Haiku, yes otherwise.
+ AS_CASE([$host_os],
+ [solaris* | haiku*],
+ [gl_cv_macro_MB_CUR_MAX_good="guessing no"],
+ [gl_cv_macro_MB_CUR_MAX_good="guessing yes"])
if test "$LOCALE_EN_UTF8" != none; then
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
[gl_cv_macro_MB_CUR_MAX_good=no],
[:])
fi
+ ],
+ [gl_cv_macro_MB_CUR_MAX_good="link failed - so no"])
])
- case "$gl_cv_macro_MB_CUR_MAX_good" in
- *yes) ;;
- *) REPLACE_MB_CUR_MAX=1 ;;
- esac
+ AS_CASE([$gl_cv_macro_MB_CUR_MAX_good],
+ [*yes],
+ [],
+ ["link failed - so no"],
+ [# 4 suffices as a workaround in Android NDK 16,
+ # the only known platform with the bug.
+ REPLACE_MB_CUR_MAX=4],
+ [REPLACE_MB_CUR_MAX="(-1)"])
AC_CHECK_DECLS_ONCE([ecvt])
if test $ac_cv_have_decl_ecvt = no; then