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.
+ * 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
static 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. */
return MB_CUR_MAX + (MB_CUR_MAX == 3);
+# endif
}
# undef MB_CUR_MAX
# define MB_CUR_MAX gl_MB_CUR_MAX ()
-# stdlib_h.m4 serial 76
+# stdlib_h.m4 serial 76.1
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_FR_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
- dnl is present.
+ [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.
- solaris*) gl_cv_macro_MB_CUR_MAX_good="guessing no" ;;
- # Guess yes otherwise.
- *) gl_cv_macro_MB_CUR_MAX_good="guessing yes" ;;
- esac
+ case "$host_os" in
+ # Guess no on Solaris.
+ solaris*) gl_cv_macro_MB_CUR_MAX_good="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_macro_MB_CUR_MAX_good="guessing yes" ;;
+ esac
changequote([,])dnl
- if test $LOCALE_FR_UTF8 != none; then
- AC_RUN_IFELSE(
- [AC_LANG_SOURCE([[
+ if test $LOCALE_FR_UTF8 != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
#include <locale.h>
#include <stdlib.h>
int main ()
}
return result;
}]])],
- [gl_cv_macro_MB_CUR_MAX_good=yes],
- [gl_cv_macro_MB_CUR_MAX_good=no],
- [:])
- fi
+ [gl_cv_macro_MB_CUR_MAX_good=yes],
+ [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 ;;
+ "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)" ;;
esac
AC_CHECK_DECLS_ONCE([ecvt])