From 981d04f93ea75c85609c18a6dcdb13cce8f07e05 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 17 Nov 2023 19:37:24 +0100 Subject: [PATCH] mbrtowc, mbrtoc32, nl_langinfo, setlocale-null: Obey --disable-threads. Reported by David Edelsohn in , . * 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. --- ChangeLog | 19 +++++++++++++++++++ lib/mbrtoc32.c | 6 +++++- lib/mbrtowc.c | 6 +++++- lib/mbtowc-lock.c | 3 ++- lib/mbtowc-lock.h | 2 +- lib/nl_langinfo-lock.c | 3 ++- lib/nl_langinfo.c | 15 +++++++++++++-- lib/setlocale-lock.c | 3 ++- lib/setlocale_null.c | 15 +++++++++++++-- m4/threadlib.m4 | 6 +++++- 10 files changed, 67 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a634e81232..807b2d6e7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2023-11-17 Bruno Haible + + mbrtowc, mbrtoc32, nl_langinfo, setlocale-null: Obey --disable-threads. + Reported by David Edelsohn in + , + . + * 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 gettext: Recognize a statically built libintl on macOS and AIX. diff --git a/lib/mbrtoc32.c b/lib/mbrtoc32.c index 0933437a4b..755d092e05 100644 --- a/lib/mbrtoc32.c +++ b/lib/mbrtoc32.c @@ -41,7 +41,11 @@ 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 diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c index c1a689a270..0a061906d7 100644 --- a/lib/mbrtowc.c +++ b/lib/mbrtowc.c @@ -28,7 +28,11 @@ # include # include -# 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 diff --git a/lib/mbtowc-lock.c b/lib/mbtowc-lock.c index c4d0b088f6..9d16068263 100644 --- a/lib/mbtowc-lock.c +++ b/lib/mbtowc-lock.c @@ -18,9 +18,10 @@ #include +/* 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. */ diff --git a/lib/mbtowc-lock.h b/lib/mbtowc-lock.h index beb37722f5..b0cc80c6a6 100644 --- a/lib/mbtowc-lock.h +++ b/lib/mbtowc-lock.h @@ -32,7 +32,7 @@ mbtowc_unlocked (wchar_t *pwc, const char *p, size_t m) /* 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. */ diff --git a/lib/nl_langinfo-lock.c b/lib/nl_langinfo-lock.c index fb12299959..f4cea0c290 100644 --- a/lib/nl_langinfo-lock.c +++ b/lib/nl_langinfo-lock.c @@ -18,9 +18,10 @@ #include +/* 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. */ diff --git a/lib/nl_langinfo.c b/lib/nl_langinfo.c index f872c6d5e2..3be275510e 100644 --- a/lib/nl_langinfo.c +++ b/lib/nl_langinfo.c @@ -30,7 +30,12 @@ #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 @@ -51,6 +56,7 @@ # include # endif + #endif /* nl_langinfo() must be multithread-safe. To achieve this without using @@ -186,7 +192,12 @@ nl_langinfo_unlocked (nl_item item) /* 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); diff --git a/lib/setlocale-lock.c b/lib/setlocale-lock.c index 593f63711b..090f824abe 100644 --- a/lib/setlocale-lock.c +++ b/lib/setlocale-lock.c @@ -18,9 +18,10 @@ #include +/* 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. */ diff --git a/lib/setlocale_null.c b/lib/setlocale_null.c index 89c8a06598..9d7cb785f7 100644 --- a/lib/setlocale_null.c +++ b/lib/setlocale_null.c @@ -30,7 +30,12 @@ #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 @@ -51,6 +56,7 @@ # include # endif + #endif /* Use the system's setlocale() function, not the gnulib override, here. */ @@ -181,7 +187,12 @@ setlocale_null_unlocked (int category, char *buf, size_t bufsize) /* 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); diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 index 855e563d88..b35ad53fd8 100644 --- a/m4/threadlib.m4 +++ b/m4/threadlib.m4 @@ -1,4 +1,4 @@ -# 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, @@ -584,6 +584,10 @@ AC_DEFUN([gl_THREADLIB_BODY], ;; 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]) -- 2.39.5