Building diffutils from git with the newest gnulib, I see a test failure on
systems with recent-enough glibc (Ubuntu 22.04, CentOS 8, Alma Linux 9):


FAIL: test-mbrtoc32-regular
===========================

../../gnulib-tests/test-mbrtoc32-regular.c:65: assertion 'mbsinit (&state)' 
failed
FAIL test-mbrtoc32-regular (exit status: 134)


What triggers this test failure is a combination of:
  1) regex now depends on mbrtoc32-regular since 2026-04-24, therefore
     this test gets included. (It was absent before.)
  2) diffutils/configure.ac has
       gl_cv_func_mbrtoc32_C_locale_sans_EILSEQ="guessing yes"
     which has the effect that on recent glibc versions (CentOS 8, Alma 9, etc.)
     REPLACE_MBRTOC32=0.
  3) There is no explicit configure test for whether mbrtoc32 is regular.
     The assumption was that on glibc systems, REPLACE_MBRTOC32 would be 1,
     but 2) prevents this.

This patch fixes it.


2026-04-29  Bruno Haible  <[email protected]>

        mbrtoc32-regular: Strengthen the configure test.
        * m4/mbrtoc32-regular.m4: New file.
        * modules/mbrtoc32-regular (Files): Add it.
        (configure.ac): Invoke gl_FUNC_MBRTOC32_REGULAR.
        * m4/mbrtoc32.m4 (gl_FUNC_MBRTOC32): Set gl_cv_func_mbrtoc32_regular.
        If it's "no" or "guessing no", set REPLACE_MBRTOC32=1.

diff --git a/m4/mbrtoc32-regular.m4 b/m4/mbrtoc32-regular.m4
new file mode 100644
index 0000000000..d14db66fab
--- /dev/null
+++ b/m4/mbrtoc32-regular.m4
@@ -0,0 +1,9 @@
+# mbrtoc32-regular.m4
+# serial 1
+dnl Copyright (C) 2026 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.
+dnl This file is offered as-is, without any warranty.
+
+AC_DEFUN([gl_FUNC_MBRTOC32_REGULAR], [:])
diff --git a/m4/mbrtoc32.m4 b/m4/mbrtoc32.m4
index d1690fb4c9..926da0e6c9 100644
--- a/m4/mbrtoc32.m4
+++ b/m4/mbrtoc32.m4
@@ -1,5 +1,5 @@
 # mbrtoc32.m4
-# serial 21
+# serial 22
 dnl Copyright (C) 2014-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -52,6 +52,36 @@ AC_DEFUN([gl_FUNC_MBRTOC32]
            LOCALE_ZH_CN=none
            ;;
       esac
+      m4_ifdef([gl_FUNC_MBRTOC32_REGULAR], [
+        dnl The package requests a regular mbrtoc32 function.
+        dnl glibc's mbrtoc32 function is not regular,
+        dnl due to the zh_HK.BIG5-HKSCS locale, see
+        dnl https://sourceware.org/bugzilla/show_bug.cgi?id=25734
+        dnl https://sourceware.org/bugzilla/show_bug.cgi?id=30611
+        AC_CACHE_CHECK([whether mbrtoc32 is regular],
+          [gl_cv_func_mbrtoc32_regular],
+          [AC_REQUIRE([AC_CANONICAL_HOST])
+           gl_cv_func_mbrtoc32_regular="guessing yes"
+           case "$host_os" in
+             *-gnu* | gnu*)
+               AC_EGREP_CPP([Unlucky], [
+                 #include <features.h>
+                 #if defined __GNU_LIBRARY__ && __GLIBC__ >= 2
+                   Unlucky GNU user
+                 #endif
+                 ],
+                 [gl_cv_func_mbrtoc32_regular="guessing no"],
+                 [])
+               ;;
+           esac
+          ])
+      ], [
+        dnl The package does not request a regular mbrtoc32 function.
+        gl_cv_func_mbrtoc32_regular=irrelevant
+      ])
+      case "$gl_cv_func_mbrtoc32_regular" in
+        *no) REPLACE_MBRTOC32=1 ;;
+      esac
     fi
     if test $HAVE_WORKING_MBRTOC32 = 0; then
       REPLACE_MBRTOC32=1
diff --git a/modules/mbrtoc32-regular b/modules/mbrtoc32-regular
index e8ae236fc5..4e8af3d4e5 100644
--- a/modules/mbrtoc32-regular
+++ b/modules/mbrtoc32-regular
@@ -3,11 +3,13 @@ mbrtoc32() function that maps each multibyte character to 
exactly one Unicode
 character and thus never returns (size_t)(-3).
 
 Files:
+m4/mbrtoc32-regular.m4
 
 Depends-on:
 mbrtoc32
 
 configure.ac:
+gl_FUNC_MBRTOC32_REGULAR
 gl_MODULE_INDICATOR([mbrtoc32-regular])
 
 Makefile.am:




Reply via email to