Bruno Haible [Fri, 10 Apr 2026 15:22:07 +0000 (17:22 +0200)]
sigprocmask: Support multithreaded applications on native Windows.
* lib/signal.in.h (WIN_PTHREADS_SIGNAL_H): New macro.
* lib/sigprocmask.c: Include windows-spin.h.
(thread_local): New macro.
(blocked_set, pending_array): Mark as thread-local.
(blocked_handler): Remove function.
(struct override): New type.
(overrides, overrides_lock): New variables.
(override_handler): New function.
(pthread_sigmask): New function, borrowing from the previous sigprocmask
definition.
(sigprocmask): Now a wrapper around pthread_sigmask.
(rpl_signal): Use the overrides_lock to make it multithread-safe.
(_gl_raise_SIGPIPE): Add comments.
* modules/sigprocmask (Depends-on): Add windows-spin.
* lib/pthread_sigmask.c: Revert last change. On native Windows, don't
define pthread_sigmask here.
* modules/pthread_sigmask (Depends-on): Remove lock.
* NEWS: Remove the last entry.
Paul Eggert [Sun, 5 Apr 2026 18:29:48 +0000 (11:29 -0700)]
term-style-control: use pthread_sigmask
* lib/term-style-control.c (block_relevant_signals)
(unblock_relevant_signals): Prefer pthread_sigmask to sigprocmask.
* modules/term-style-control (Depends-on):
Depend on pthread_sigmask, not on sigprocmask.
Paul Eggert [Sun, 5 Apr 2026 18:28:19 +0000 (11:28 -0700)]
fatal-signal: use pthread_sigmask
* lib/fatal-signal.c (block_fatal_signals)
(unblock_fatal_signals): Prefer pthread_sigmask to sigprocmask.
* modules/fatal-signal (Depends-on):
Depend on pthread_sigmask, not on sigprocmask.
Paul Eggert [Sun, 5 Apr 2026 18:26:56 +0000 (11:26 -0700)]
sigaction: use pthread_sigmask
* lib/sigaction.c (sigaction_handler, sigaction):
Use pthread_sigmask, not sigprocmask.
* modules/sigaction (Depends-on):
Depend on pthread_sigmask, not on sigprocmask.
Paul Eggert [Sun, 5 Apr 2026 18:25:05 +0000 (11:25 -0700)]
pthread_sigmask: lock here, not in sigprocmask
Since sigprocmask should now be used only in single-threaded processes,
move the locking from lib/sigprocmask.c to lib/pthread_sigmask.c.
* lib/pthread_sigmask.c: If !HAVE_SIGPROCMASK &&
!GNULIB_PTHREAD_SIGMASK_SINGLE_THREAD, replace Gnulib sigprocmask
with a thread-safe subsitute sigprocmask_r.
Include glthread/lock.h to implement this.
* lib/sigprocmask.c (gl_lock_define_initialized, gl_lock_lock)
(gl_lock_unlock, sig_lock): Remove. All uses removed.
Do not include glthread/lock.h.
* m4/signalblocking.m4 (gl_SIGNALBLOCKING):
Define HAVE_SIGPROCMASK, for the benefit of pthread_sigmask.c.
* modules/pthread_sigmask (Depends-on): Add ‘lock’.
* modules/sigprocmask (Depends-on): Remove ‘lock’.
This is a performance win on GLIBC,
as tested on the coreutils multi-byte update to cut(1):
$ yes $(yes éééááé | head -n9 | paste -s -d,) |
head -n1M > mb.in
$ time LC_ALL=C.UTF-8 src/cut-before -c1 mb.in >/dev/null
real 0m1.582s
$ time LC_ALL=C.UTF-8 src/cut-after -c1 mb.in >/dev/null
real 0m0.592s
* lib/mcel.h: While GLIBC's mbrtoc32 is functional for mcel,
it is seen to be 2.6x slower than gnulib's implementation
due to GLIBC's per call locale handling.
Bruno Haible [Sat, 4 Apr 2026 20:44:10 +0000 (22:44 +0200)]
asyncsafe-spin: Prefer pthread_sigmask over sigprocmask.
Suggested by Paul Eggert.
* lib/asyncsafe-spin.c (asyncsafe_spin_lock, asyncsafe_spin_unlock): Use
pthread_sigmask instead of sigprocmask.
* modules/asyncsafe-spin (Depends-on): Add pthread_sigmask. Remove
sigprocmask.
(Link): New section.
* modules/asyncsafe-spin-tests (Makefile.am): Link test-asyncsafe-spin1
with $(PTHREAD_SIGMASK_LIB).
* modules/jit/cache-tests (Makefile.am): Link test-cache with
$(PTHREAD_SIGMASK_LIB).
Bruno Haible [Sat, 4 Apr 2026 13:16:44 +0000 (15:16 +0200)]
pthread_sigmask: Make it usable without -lpthread on most platforms.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Define
PTHREAD_SIGMASK_LIB to empty, except on AIX. Define
PTHREAD_SIGMASK_NOT_IN_LIBC if a workaround is needed.
* lib/pthread_sigmask.c (pthread_sigmask): If
PTHREAD_SIGMASK_NOT_IN_LIBC, just use sigprocmask.
* doc/posix-functions/pthread_sigmask.texi: Mention the dropped link
requirement. Mention that the NetBSD 9 bug is fixed.
* doc/posix-functions/sigprocmask.texi: Update note relating to
pthread_sigmask.
Paul Eggert [Sat, 4 Apr 2026 02:55:48 +0000 (19:55 -0700)]
sigprocmask: document race bugs on macOS
In documentation and comments, mention macOS sigprocmask
incompatibility with GNU and most other systems, and note Gnulib
uses of sigprocmask that can cause subtle race condition bugs on
macOS. Although an obvious fix is to switch to pthread_sigmask as
POSIX suggests, that will require some changing to linking
instructions, and the first step is documentation.
Bruno Haible [Thu, 2 Apr 2026 19:59:58 +0000 (21:59 +0200)]
mbrtoc32: Optimize single-locale case on glibc systems.
Suggested by Pádraig Brady.
* lib/mbrtoc32.c (is_locale_utf8, cached_is_locale_utf8,
is_locale_utf8_cached): New functions/variable, copied from
lib/wcwidth.c.
(mbrtoc32): If GNULIB_WCHAR_SINGLE_LOCALE is defined, optimize the
frequent case of an UTF-8 locale on glibc systems.
Bruno Haible [Thu, 2 Apr 2026 19:58:36 +0000 (21:58 +0200)]
mbrtowc: Optimize single-locale case on glibc systems.
Suggested by Pádraig Brady.
* lib/mbrtowc.c (is_locale_utf8, cached_is_locale_utf8,
is_locale_utf8_cached): New functions/variable, copied from
lib/wcwidth.c.
(rpl_mbrtowc): If GNULIB_WCHAR_SINGLE_LOCALE is defined, optimize the
frequent case of an UTF-8 locale on glibc systems.
Bruno Haible [Wed, 1 Apr 2026 20:45:55 +0000 (22:45 +0200)]
sigprocmask: Allow single-thread optimization in a more reliable way.
* modules/sigprocmask: Revert last change.
* lib/sigprocmask.c: Test GNULIB_SIGPROCMASK_SINGLE_THREAD before
including glthread/lock.h.
* doc/multithread.texi: Document GNULIB_SIGPROCMASK_SINGLE_THREAD.
Paul Eggert [Wed, 1 Apr 2026 18:34:42 +0000 (11:34 -0700)]
yesno: treat unlocking similarly if !ENABLE_NLS
If the application is using unlocked-io, do that in the
!ENABLE_NLS case too. This is more for consistency than for
performance in the typical case.
* lib/yesno.c [USE_UNLOCKED_IO]: Include unlocked-io.h.
Paul Eggert [Wed, 1 Apr 2026 02:54:46 +0000 (19:54 -0700)]
sigprocmask: allow --avoid=lock
* modules/sigprocmask (Files): Add lib/glthread/lock.h,
so that this module works even if the lock module is avoided.
This is useful for gzip, which does not use multithreading.
Paul Eggert [Wed, 1 Apr 2026 02:51:36 +0000 (19:51 -0700)]
thread: lessen glthread namespace pollution
In lib/glthread/*.h, avoid including files if it’s easy, and if
the files are not needed in the .h file to implement the module.
* lib/glthread/cond.h: Include glthread/lock.h only if needed.
* lib/glthread/lock.c, lib/glthread/once.c: Include <errno.h> here ...
* lib/glthread/lock.h, lib/glthread/once.h: ... instead of here.
* lib/glthread/lock.h: Include glthread/once.h only if needed.
* lib/glthread/yield.h: Don’t include <errno.h>.
Paul Eggert [Tue, 31 Mar 2026 23:38:47 +0000 (16:38 -0700)]
gettext-h: don’t depend on locale-h
This is useful for apps like gzip.h that stay in the C locale
and don’t need all the the locale-h machinery.
* lib/gettext.h: Include <locale.h> only if !ENABLE_NLS && __sun.
(pgettext, dpgettext, npgettext, dnpgettext, pgettext_expr)
(npgettext_expr): Use _GL_LC_MESSAGES, not LC_MESSAGES.
* m4/gettext_h.m4 (gl_GETTEXT_H): Define _GL_LC_MESSAGES.
* modules/gettext-h (Depends-on): Remove locale-h.
Collin Funk [Fri, 27 Mar 2026 02:59:19 +0000 (19:59 -0700)]
gnu-web-doc-update: Add an environment variable for the CVS username
* build-aux/gnu-web-doc-update (help): Mention the SAVANNAH_CVS_USER
environment variable.
($cvs_user): Use the SAVANNAH_CVS_USER environment variable and fallback
to USER if it is unset or empty.
Collin Funk [Wed, 25 Mar 2026 03:11:36 +0000 (20:11 -0700)]
doc: Mention a Solaris 11.4 bug.
* doc/posix-functions/open.texi: Mention that Solaris 11.4 sets errno to
EINVAL instead of EISDIR when open is called on a directory with
O_CREAT.
* doc/posix-functions/openat.texi: Likewise.
Paul Eggert [Mon, 16 Mar 2026 22:17:26 +0000 (15:17 -0700)]
stdbit-h: don’t generate some dummy .o files
On recent GNU and other C23ish platforms, do not compile files
like lib/stdc_bit_ceil.c, as the corresponding .o files contain
nothing useful.
* m4/stdbit_h.m4 (gl_STDBIT_H):
Define the Automake condition GL_HAVE_STDBIT_H.
Quote cache variables in case the cache is bad.
* modules/stdc_bit_ceil, modules/stdc_bit_floor:
* modules/stdc_bit_width, modules/stdc_count_ones:
* modules/stdc_count_zeros, modules/stdc_first_leading_one:
* modules/stdc_first_leading_zero:
* modules/stdc_first_trailing_one:
* modules/stdc_first_trailing_zero, modules/stdc_has_single_bit:
* modules/stdc_leading_ones, modules/stdc_leading_zeros:
* modules/stdc_trailing_ones, modules/stdc_trailing_zeros:
Generate if !GL_HAVE_STDBIT_H, not if GL_GENERATE_STDBIT_H.
Paul Eggert [Mon, 16 Mar 2026 19:18:23 +0000 (12:18 -0700)]
stdbit-h: don’t memcpy on oddball hosts
Mostly-theoretical problem reported by Lasse Collin in:
https://lists.gnu.org/r/bug-gnulib/2026-03/msg00135.html
* lib/stdbit.in.h (_GL_STDBIT_OPTIMIZE_VIA_MEMCPY):
Do not define to 1 on oddball hosts.
Paul Eggert [Mon, 16 Mar 2026 16:10:00 +0000 (09:10 -0700)]
stdbit-h: be clearer about castless conversion
* lib/stdbit.in.h (stdc_load8_beu16, stdc_load8_beu32)
(stdc_load8_beu64, stdc_load8_leu16, stdc_load8_leu32)
(stdc_load8_leu64): Assign to temporaries rather than ORing to zero.
Bruno Haible [Mon, 16 Mar 2026 09:12:46 +0000 (10:12 +0100)]
stdbit-h: Reorder definitions.
* lib/stdbit.in.h: Move private helper macros and functions to the
section conditionalized by @GNULIB_STDC_LEADING_ZEROS@,
@GNULIB_STDC_TRAILING_ZEROS@, @GNULIB_STDC_COUNT_ONES@, respectively.
Paul Eggert [Mon, 16 Mar 2026 06:54:59 +0000 (23:54 -0700)]
stdbit-h: remove stdbit.c
lib/stdbit.c was present only to define private helper functions.
Move them into lib/stdc_leading_zeros.c and
lib/stdc_trailing_zeros.c, depending on what they help.
The latter now might use the former, since the
_gl_stdbit_ctz family calls the _gl_stdbit_clz family
when !defined _GL_STDBIT_HAS_BUILTIN_CTZ && !defined _MSC_VER,
so stdc_trailing_zeros now depends on stdc_leading_zeros.
* lib/stdbit.c: Remove file.
* lib/stdbit.in.h (_GL_STDBIT_INLINE): Remove.
All uses replaced by _GL_STDC_LEADING_ZEROS_INLINE
or _GL_STDC_TRAILING_ZEROS_INLINE.
* modules/stdbit-h (Files, lib_SOURCES): Remove lib/stdbit.c.
* modules/stdc_trailing_zeros (Depends-on): Add stdc_leading_zeros.
Paul Eggert [Mon, 16 Mar 2026 06:54:58 +0000 (23:54 -0700)]
stdbit-h: test without <stdint.h>
Improve the <stdbit.h> tests so that they check
that <stdbit.h> works even if <stdint.h> is not included.
* modules/stdc_bit_ceil-tests, modules/stdc_bit_floor-tests:
* modules/stdc_bit_width-tests, modules/stdc_count_ones-tests:
* modules/stdc_count_zeros-tests:
* modules/stdc_first_leading_one-tests:
* modules/stdc_first_leading_zero-tests:
* modules/stdc_first_trailing_one-tests:
* modules/stdc_first_trailing_zero-tests:
* modules/stdc_has_single_bit-tests:
* modules/stdc_leading_ones-tests:
* modules/stdc_leading_zeros-tests:
* modules/stdc_trailing_ones-tests:
* modules/stdc_trailing_zeros-tests:
(Depends-on): Remove stdint-h.
* tests/from-glibc/tst-stdbit.h [GNULIB_TEST_STDBIT]:
Do not include <stdint.h>.
Paul Eggert [Mon, 16 Mar 2026 06:54:58 +0000 (23:54 -0700)]
stdbit-h: don’t depend on stdint-h
* modules/stdc_load8, modules/stdc_load8_aligned:
* modules/stdc_store8, modules/stdc_store8_aligned:
* modules/stdc_memreverse8u:
(Depends-on): Remove stdint-h, as Gnulib should be able to assume
the small subset of C99 <stdint.h> that stdbit.in.h uses.
Paul Eggert [Mon, 16 Mar 2026 06:54:58 +0000 (23:54 -0700)]
stdbit-h: namespace cleanup on recent GNU
* lib/stdbit.in.h: Include <stddef.h> if !@HAVE_STDBIT_H@, good on
all known Gnulib targets, not if @GNULIB_STDC_MEMREVERSE8@, which
is not quite right because C23 requires that stdbit.h define
size_t even if stdc_memreverse8 is not used.
Do not include <stdint.h> if @HAVE_STDBIT_H@ && defined
__UINT_FAST64_TYPE__, as it is no longer needed.
(_GL_STDBIT_UINT_FAST16, _GL_STDBIT_UINT_FAST32)
(_GL_STDBIT_UINT_FAST64): New macros. Use them instead of
uint_fast16_t etc., to avoid namespace pollution.
(stdc_load8_beu16, stdc_load8_beu32, stdc_load8_beu64)
(stdc_load8_leu16, stdc_load8_leu32, stdc_load8_leu64):
Use them instead of casting to the relevant types,
to avoid the need for casts.
Bruno Haible [Sun, 15 Mar 2026 20:58:34 +0000 (21:58 +0100)]
posix_spawn-internal: Move private Gnulib functions to _gl_* namespace.
* lib/spawn_int.h (_gl_posix_spawn_file_actions_realloc): Renamed from
gl_posix_spawn_file_actions_realloc.
(_gl_posix_spawn_internal): Renamed from gl_posix_spawn_internal.
Bruno Haible [Sun, 15 Mar 2026 18:42:36 +0000 (19:42 +0100)]
float-h: Move private Gnulib data to _gl_* namespace.
* lib/float.in.h (_gl_LDBL_MAX): Renamed from gl_LDBL_MAX.
(_gl_LDBL_TRUE_MIN): Renamed from gl_LDBL_TRUE_MIN.
(_gl_FLT_SNAN): Renamed from gl_FLT_SNAN.
(_gl_DBL_SNAN): Renamed from gl_DBL_SNAN.
(_gl_LDBL_SNAN): Renamed from gl_LDBL_SNAN.
* lib/float.c: Update.
Bruno Haible [Sun, 15 Mar 2026 13:35:48 +0000 (14:35 +0100)]
stdc_memreverse8: New module.
* lib/stdbit.in.h: Include <stddef.h>.
(_GL_STDC_MEMREVERSE8_INLINE): New macro.
(stdc_memreverse8): New function.
* lib/stdc_memreverse8.c: New file.
* m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
GNULIB_STDC_MEMREVERSE8.
* modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_MEMREVERSE8.
* modules/stdc_memreverse8: New file.
* doc/posix-functions/stdc_memreverse8.texi: Mention the new module.
Bruno Haible [Sun, 15 Mar 2026 09:01:57 +0000 (10:01 +0100)]
count-*: Fix module status (regression yesterday).
* modules/count-leading-zeros: Mark as deprecated, not obsolete.
Recommend module 'stdc_leading_zeros' instead of 'stdbit'.
* modules/count-trailing-zeros: Mark as deprecated, not obsolete.
Recommend module 'stdc_trailing_zeros' instead of 'stdbit'.
* modules/count-one-bits: Mark as deprecated, not obsolete. Recommend
module 'stdc_count_ones' instead of 'stdbit'.
* NEWS: Update.
Prefer the usual pattern for checking for builtins:
allow __has_builtin for compilers that are not Clang or GCC
where we already have something.
* lib/stdbit.in.h (_GL_HAS_BUILTIN_ASSUME_ALIGNED): New macro.
(_GL_STDBIT_ASSUME_ALIGNED): Use it.
Paul Eggert [Sat, 14 Mar 2026 00:44:06 +0000 (17:44 -0700)]
stdbit-h: restore optimization for RISC-V etc
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-03/msg00098.html
This patch does the optimization in a different way,
preferring plain ‘if’ to ‘#if’ if either will do.
* lib/stdbit.in.h: Bring back includes for byteswap.h, string.h.
(_GL_STDBIT_OPTIMIZE_VIA_MEMCPY, _GL_STDBIT_ASSUME_ALIGNED)
(_GL_STDBIT_BIGENDIAN): New macros.
(stdc_load8_beu16, stdc_load8_leu16):
Bring back casts to uint_fast16_t.
(stdc_load8_aligned_beu16, stdc_load8_aligned_beu32)
(stdc_load8_aligned_beu64, stdc_load8_aligned_leu16)
(stdc_load8_aligned_leu32, stdc_load8_aligned_leu64)
(stdc_load8_aligned_bes8, stdc_load8_aligned_bes16)
(stdc_load8_aligned_bes32, stdc_load8_aligned_bes64)
(stdc_load8_aligned_les8, stdc_load8_aligned_les16)
(stdc_load8_aligned_les32, stdc_load8_aligned_les64)
(stdc_store8_aligned_beu16, stdc_store8_aligned_beu32)
(stdc_store8_aligned_beu64, stdc_store8_aligned_leu16)
(stdc_store8_aligned_leu32, stdc_store8_aligned_leu64)
(stdc_store8_aligned_bes8, stdc_store8_aligned_bes16)
(stdc_store8_aligned_bes32, stdc_store8_aligned_bes64)
(stdc_store8_aligned_les8, stdc_store8_aligned_les16)
(stdc_store8_aligned_les32, stdc_store8_aligned_les64):
Bring back the memcpy optimization if _GL_STDBIT_OPTIMIZE_VIA_MEMCPY.
* modules/stdc_load8_aligned (Depends-on):
* modules/stdc_store8_aligned (Depends-on):
Go back to depending on byteswap.
Paul Eggert [Fri, 13 Mar 2026 18:43:49 +0000 (11:43 -0700)]
stdbit-h: add test for recent aligned issue.
Adapted from test by Lasse Collin <lasse.collin@tukaani.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-03/msg00094.html>.
* modules/stdc_store8_aligned-tests (Depends-on):
Depend on stdc_load8_aligned.
* tests/test-stdc_store8_aligned.c (test_strict_aliasing): New test.
(main): Use it.