+2023-11-17 Bruno Haible <bruno@clisp.org>
+
+ mbrtowc, mbrtoc32, nl_langinfo, setlocale-null: Obey --disable-threads.
+ Reported by David Edelsohn <dje.gcc@gmail.com> in
+ <https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636830.html>,
+ <https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636843.html>.
+ * m4/threadlib.m4 (gl_THREADLIB_BODY): If --disable-threads was
+ specified, define AVOID_ANY_THREADS to 1.
+ * lib/mbtowc-lock.c: Omit all code if --disable-threads was specified.
+ * lib/nl_langinfo-lock.c: Likewise.
+ * lib/setlocale-lock.c: Likewise.
+ * lib/mbtowc-lock.h: Omit locking code if --disable-threads was
+ specified.
+ * lib/nl_langinfo.c: Likewise.
+ * lib/setlocale_null.c: Likewise.
+ * lib/mbrtowc.c: Don't include any multithreading headers if
+ --disable-threads was specified.
+ * lib/mbrtoc32.c: Likewise.
+
2023-11-17 Bruno Haible <bruno@clisp.org>
gettext: Recognize a statically built libintl on macOS and AIX.
branch below.
They are equivalent. */
-# if defined _WIN32 && !defined __CYGWIN__
+# if AVOID_ANY_THREADS
+
+/* The option '--disable-threads' explicitly requests no locking. */
+
+# elif defined _WIN32 && !defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
# include <stdint.h>
# include <stdlib.h>
-# if defined _WIN32 && !defined __CYGWIN__
+# if AVOID_ANY_THREADS
+
+/* The option '--disable-threads' explicitly requests no locking. */
+
+# elif defined _WIN32 && !defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
#include <config.h>
+/* The option '--disable-threads' explicitly requests no locking. */
/* When it is known that the gl_get_mbtowc_lock function is defined
by a dependency library, it should not be defined here. */
-#if OMIT_MBTOWC_LOCK
+#if AVOID_ANY_THREADS || OMIT_MBTOWC_LOCK
/* This declaration is solely to ensure that after preprocessing
this file is never empty. */
/* Prohibit renaming this symbol. */
#undef gl_get_mbtowc_lock
-#if GNULIB_MBRTOWC_SINGLE_THREAD
+#if AVOID_ANY_THREADS || GNULIB_MBRTOWC_SINGLE_THREAD
/* All uses of this function are in a single thread. No locking needed. */
#include <config.h>
+/* The option '--disable-threads' explicitly requests no locking. */
/* When it is known that the gl_get_nl_langinfo_lock function is defined
by a dependency library, it should not be defined here. */
-#if OMIT_NL_LANGINFO_LOCK
+#if AVOID_ANY_THREADS || OMIT_NL_LANGINFO_LOCK
/* This declaration is solely to ensure that after preprocessing
this file is never empty. */
#endif
#if REPLACE_NL_LANGINFO && !NL_LANGINFO_MTSAFE
-# if defined _WIN32 && !defined __CYGWIN__
+
+# if AVOID_ANY_THREADS
+
+/* The option '--disable-threads' explicitly requests no locking. */
+
+# elif defined _WIN32 && !defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
# include <threads.h>
# endif
+
#endif
/* nl_langinfo() must be multithread-safe. To achieve this without using
/* Prohibit renaming this symbol. */
# undef gl_get_nl_langinfo_lock
-# if defined _WIN32 && !defined __CYGWIN__
+# if AVOID_ANY_THREADS
+
+/* The option '--disable-threads' explicitly requests no locking. */
+# define nl_langinfo_with_lock nl_langinfo_unlocked
+
+# elif defined _WIN32 && !defined __CYGWIN__
extern __declspec(dllimport) CRITICAL_SECTION *gl_get_nl_langinfo_lock (void);
#include <config.h>
+/* The option '--disable-threads' explicitly requests no locking. */
/* When it is known that the gl_get_setlocale_null_lock function is defined
by a dependency library, it should not be defined here. */
-#if OMIT_SETLOCALE_LOCK
+#if AVOID_ANY_THREADS || OMIT_SETLOCALE_LOCK
/* This declaration is solely to ensure that after preprocessing
this file is never empty. */
#endif
#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE)
-# if defined _WIN32 && !defined __CYGWIN__
+
+# if AVOID_ANY_THREADS
+
+/* The option '--disable-threads' explicitly requests no locking. */
+
+# elif defined _WIN32 && !defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
# include <threads.h>
# endif
+
#endif
/* Use the system's setlocale() function, not the gnulib override, here. */
/* Prohibit renaming this symbol. */
# undef gl_get_setlocale_null_lock
-# if defined _WIN32 && !defined __CYGWIN__
+# if AVOID_ANY_THREADS
+
+/* The option '--disable-threads' explicitly requests no locking. */
+# define setlocale_null_with_lock setlocale_null_unlocked
+
+# elif defined _WIN32 && !defined __CYGWIN__
extern __declspec(dllimport) CRITICAL_SECTION *gl_get_setlocale_null_lock (void);
-# threadlib.m4 serial 40
+# threadlib.m4 serial 41
dnl Copyright (C) 2005-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,
;;
esac
fi
+ else
+ dnl "$gl_use_threads" is "no".
+ AC_DEFINE([AVOID_ANY_THREADS], [1],
+ [Define if no multithread safety and no multithreading is desired.])
fi
AC_MSG_CHECKING([for multithread API to use])
AC_MSG_RESULT([$gl_threads_api])