On macOS 26, I see a unit test failure:

thread5 disturbed by threadN!
FAIL test-nl_langinfo-mt (exit status: 134)

This means, nl_langinfo (CRNCYSTR) is no longer multithread-safe,
unlike in earlier macOS releases.

This patch provides a workaround.

The other uses, such as nl_langinfo (CODESET), are apparently still MT-safe.
Therefore, no need to change the 'localcharset' and 'nstrftime' modules.


2025-09-20  Bruno Haible  <[email protected]>

        nl_langinfo: Work around nl_langinfo multithread-safety bug on macOS 26.
        * m4/nl_langinfo.m4 (gl_FUNC_NL_LANGINFO): Set NL_LANGINFO_MTSAFE to 0
        on macOS.
        * lib/nl_langinfo.c (ITEMS): Define appropriately on macOS.
        * doc/posix-functions/nl_langinfo.texi: Document the macOS bug.

diff --git a/doc/posix-functions/nl_langinfo.texi 
b/doc/posix-functions/nl_langinfo.texi
index d29628c12f..02ff6ebbe0 100644
--- a/doc/posix-functions/nl_langinfo.texi
+++ b/doc/posix-functions/nl_langinfo.texi
@@ -29,7 +29,7 @@
 OpenBSD 7.5.
 @item
 This function is not multithread-safe on some platforms:
-Solaris 11.3.
+macOS 26, Solaris 11.3.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/nl_langinfo.c b/lib/nl_langinfo.c
index e7a9334ec9..f575c256c6 100644
--- a/lib/nl_langinfo.c
+++ b/lib/nl_langinfo.c
@@ -154,11 +154,15 @@ ctype_codeset (void)
    "thread5 disturbed by threadN!", even when threadN invokes only
       nl_langinfo (CODESET);
       nl_langinfo (CRNCYSTR);
-   Similarly on Solaris 10.  */
+   Similarly on Solaris 10 and macOS 26.  */
 
-# if !NL_LANGINFO_MTSAFE /* Solaris */
+# if !NL_LANGINFO_MTSAFE /* macOS, Solaris */
 
-#  define ITEMS (MAXSTRMSG + 1)
+#  ifdef __sun /* Solaris */
+#   define ITEMS (MAXSTRMSG + 1)
+#  else /* macOS */
+#   define ITEMS (CRNCYSTR + 20)
+#  endif
 #  define MAX_RESULT_LEN 80
 
 static char *
diff --git a/m4/nl_langinfo.m4 b/m4/nl_langinfo.m4
index 8459fa4530..969c8ffdd1 100644
--- a/m4/nl_langinfo.m4
+++ b/m4/nl_langinfo.m4
@@ -1,5 +1,5 @@
 # nl_langinfo.m4
-# serial 13
+# serial 14
 dnl Copyright (C) 2009-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -16,10 +16,11 @@ AC_DEFUN([gl_FUNC_NL_LANGINFO]
   AC_REQUIRE([gl_PTHREADLIB])
   AC_CHECK_HEADERS_ONCE([threads.h])
   if test $ac_cv_func_nl_langinfo = yes; then
-    # On Solaris 10 and Solaris 11.3, nl_langinfo is not multithread-safe.
+    # On macOS 26, Solaris 10, and Solaris 11.3, nl_langinfo is not
+    # multithread-safe.
     case "$host_os" in
-      solaris*) NL_LANGINFO_MTSAFE=0 ;;
-      *)        NL_LANGINFO_MTSAFE=1 ;;
+      darwin* | solaris*) NL_LANGINFO_MTSAFE=0 ;;
+      *)                  NL_LANGINFO_MTSAFE=1 ;;
     esac
     AC_DEFINE_UNQUOTED([NL_LANGINFO_MTSAFE], [$NL_LANGINFO_MTSAFE],
       [Define to 1 if nl_langinfo is multithread-safe.])




Reply via email to