Paul Eggert [Tue, 26 May 2026 00:08:48 +0000 (17:08 -0700)]
quotearg: be nicer on macOS etc
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-05/msg00150.html
* lib/quotearg.c (C_LOCALE_MIGHT_BE_MULTIBYTE): New macro.
(wch, mbstate, mbs_clear, mbrtowch, chisprint, wchisprint
(quotearg_buffer_restyled): Fall back on <wchar.h> and <wctype.h>
functions if USE_C_LOCALE and C_LOCALE_MIGHT_BE_MULTIBYTE.
Bruno Haible [Mon, 25 May 2026 23:29:29 +0000 (01:29 +0200)]
mbuiterf: Implement multi-byte per encoding error (MEE) consistently.
* lib/mbuiterf.h: Include mbiter-aux.h.
(struct mbuif_state): Add field is_utf8.
(mbuiterf_next): Invoke mbiter_is_utf8, mbiter_utf8_maximal_subpart.
(mbuif_init): Initialize the field is_utf8.
* modules/mbuiterf (Depends-on): Add mbiter-aux.
* tests/test-mbslen.c (OR): New macro, copied from
tests/test-mbsnlen.c.
(main): Add more test cases with incomplete characters.
* tests/test-mbschr2.sh: Renamed from tests/test-mbschr.sh.
* tests/test-mbschr2.c: Renamed from tests/test-mbschr.c.
* tests/test-mbschr1.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* tests/test-mbschr1.c: New file.
* modules/mbschr-tests (Files): Update accordingly. Add locale-en.m4,
locale-fr.m4.
(configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
(Makefile.am): Arrange to compile test-mbschr1 and test-mbschr2 and to
run test-mbschr1.sh, test-mbschr2.sh.
* tests/test-mbsrchr2.sh: Renamed from tests/test-mbsrchr.sh.
* tests/test-mbsrchr2.c: Renamed from tests/test-mbsrchr.c.
* tests/test-mbsrchr1.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* tests/test-mbsrchr1.c: New file.
* modules/mbsrchr-tests (Files): Update accordingly. Add locale-en.m4,
locale-fr.m4.
(configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
(Makefile.am): Arrange to compile test-mbsrchr1 and test-mbsrchr2 and to
run test-mbsrchr1.sh, test-mbsrchr2.sh.
* tests/test-mbscspn.c (OR): New macro, copied from
tests/test-mbsnlen.c.
(main): Add test cases with incomplete characters.
* tests/test-mbspbrk.c (OR): New macro, copied from
tests/test-mbsnlen.c.
(main): Add test cases with incomplete characters.
* tests/test-mbsspn.c (OR): New macro, copied from
tests/test-mbsnlen.c.
(main): Add test cases with incomplete characters.
Bruno Haible [Mon, 25 May 2026 22:42:39 +0000 (00:42 +0200)]
mbiterf: Implement multi-byte per encoding error (MEE) consistently.
* lib/mbiterf.h: Include mbiter-aux.h.
(struct mbif_state): Add field is_utf8.
(mbiterf_next): Invoke mbiter_is_utf8, mbiter_utf8_maximal_subpart.
(mbif_init): Initialize the field is_utf8.
* modules/mbiterf (Depends-on): Add mbiter-aux.
* tests/test-mbsnlen.c (main): Add test cases with incomplete characters
not at the end of the string.
Bruno Haible [Mon, 25 May 2026 17:06:55 +0000 (19:06 +0200)]
mbiter: Implement multi-byte per encoding error consistently.
* lib/mbiter.h: Include mbiter-aux.h.
(struct mbiter_multi): Add field is_utf8.
(mbiter_multi_next): Invoke mbiter_is_utf8, mbiter_utf8_maximal_subpart.
(mbi_init): Initialize the field is_utf8.
* modules/mbiter (Depends-on): Add mbiter-aux.
* tests/test-mbs_startswith2.c (main): Add test cases with incomplete
characters not at the end of the string.
* tests/test-mbs_endswith2.c (OR): New macro, copied from
tests/test-mbsnlen.c.
(main): Add test cases with incomplete characters not at the end of the
string.
Paul Eggert [Mon, 25 May 2026 21:30:05 +0000 (14:30 -0700)]
quotearg: support USE_C_LOCALE variant
This is for gzip, which does not use setlocale,
but does need to quote file names.
* lib/quotearg.c (USE_C_LOCALE): Default to 0. If set, include
c-ctype.h instead of ctype.h, gettext.h, uchar.h, wchar.h; and
define _ to be an identity macro.
(wch, mbstate): New types.
(mbs_clear, mbrtowch, wchisprint, chisprint): New functions.
(gettext_quote, quotearg_buffer_restyled): Use them.
Paul Eggert [Mon, 25 May 2026 18:32:32 +0000 (11:32 -0700)]
quotearg: lessen dependencies
* lib/quotearg.c: Do not include c-strcaseeq.h, as its
macros are no longer used here.
* modules/quotearg (Depends-on): Remove c-strcaseeq.
Also remove memcmp, since the code no longer uses memcmp.
Bruno Haible [Mon, 25 May 2026 16:32:18 +0000 (18:32 +0200)]
mbspcasecmp tests: Enhance tests.
* tests/test-mbspcasecmp.c (test_ascii): New function, extracted from
main.
(test_utf_8): Likewise. Add test cases with incomplete characters.
(main): Invoke them. Accept a numeric argument.
* tests/test-mbspcasecmp-4.sh: Renamed from tests/test-mbspcasecmp.sh.
* tests/test-mbspcasecmp-3.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* modules/mbspcasecmp-tests (Files): Update after rename. Add
locale-en.m4, locale-fr.m4.
(configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
(Makefile.am): Arrange to run test-mbspcasecmp-3.sh,
test-mbspcasecmp-4.sh, instead of test-mbspcasecmp.sh.
Bruno Haible [Mon, 25 May 2026 16:27:18 +0000 (18:27 +0200)]
mbsncasecmp tests: Enhance tests.
* tests/test-mbsncasecmp.c (test_ascii): New function, extracted from
main.
(test_utf_8): Likewise. Add test cases with incomplete characters.
(main): Invoke them. Accept a numeric argument.
* tests/test-mbsncasecmp-4.sh: Renamed from tests/test-mbsncasecmp.sh.
* tests/test-mbsncasecmp-3.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* modules/mbsncasecmp-tests (Files): Update after rename. Add
locale-en.m4, locale-fr.m4.
(configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
(Makefile.am): Arrange to run test-mbsncasecmp-3.sh,
test-mbsncasecmp-4.sh, instead of test-mbsncasecmp.sh.
Bruno Haible [Mon, 25 May 2026 16:20:40 +0000 (18:20 +0200)]
mbscasecmp tests: Enhance tests.
* tests/test-mbscasecmp.c (test_ascii): New function, extracted from
main.
(test_utf_8): Likewise. Add test cases with incomplete characters.
(main): Invoke them. Accept a numeric argument.
* tests/test-mbscasecmp-4.sh: Renamed from tests/test-mbscasecmp.sh.
* tests/test-mbscasecmp-3.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* modules/mbscasecmp-tests (Files): Update after rename. Add
locale-en.m4, locale-fr.m4.
(configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
(Makefile.am): Arrange to run test-mbscasecmp-3.sh,
test-mbscasecmp-4.sh, instead of test-mbscasecmp.sh.
Bruno Haible [Mon, 25 May 2026 15:55:56 +0000 (17:55 +0200)]
mbs_startswith tests: Enhance tests.
* tests/test-mbs_startswith2.c (OR): New macro, copied from
tests/test-mbsnlen.c.
(main): Add more test cases. Add more comments.
* tests/test-mbs_startswith1.c: Update comments.
* tests/test-mbs_startswith3.c: Likewise.
Paul Eggert [Sun, 24 May 2026 17:48:54 +0000 (10:48 -0700)]
regex: pacify 16.1.1 -Wanalyzer-out-of-bounds
* lib/regex_internal.c (re_node_set_insert): Add a DEBUG_ASSERT.
Needed for gcc 16.1.1 20260515 (Red Hat 16.1.1-2) on x86-64 when
_REGEX_AVOID_UCHAR_H is defined.
Paul Eggert [Sun, 24 May 2026 17:44:42 +0000 (10:44 -0700)]
regex: new _REGEX_AVOID_UCHAR_H option
This is for GNU Emacs, where the regex code is only auxiliary,
probably not enough to justify the hassle of incorporating
Gnulib’s uchar-h module and its dependencies.
The following changes are in effect only if _REGEX_AVOID_UCHAR_H,
and cause the code to avoid the need for Gnulib’s uchar-h module.
* lib/regcomp.c: Don’t include localeinfo.h.
(re_set_fastmap_icase): Don’t use localeinfo.h functions,
as they rely on char32_t.
* lib/regex_internal.h: Just use of wchar_t, wctype_t and related
functions, instead of using char32_t and related functions.
Bruno Haible [Tue, 19 May 2026 00:17:49 +0000 (02:17 +0200)]
thread-optim: Add some optional rudimentary logging.
* lib/thread-optim.c (DEBUG_ELF, dbg_printf): New macros.
(inspect_one_GOT): Log the return value through dbg_printf.
(gl_multithreaded): Log the override through dbg_printf.
Bruno Haible [Mon, 18 May 2026 23:52:40 +0000 (01:52 +0200)]
term-style-control: Make multithread-safe, part 6: Link dependencies.
* m4/pthread_kill.m4: New file.
* modules/term-style-control (Files): Add it.
(configure.ac): Invoke gl_FUNC_PTHREAD_KILL.
(Link): Add $(PTHREAD_SIGMASK_LIB) and $(PTHREAD_KILL_LIB).
* modules/term-style-control-tests (Makefile.am): Link
test-term-style-control-hello and test-term-style-control-yes with
$(PTHREAD_SIGMASK_LIB) and $(PTHREAD_KILL_LIB).
Bruno Haible [Mon, 18 May 2026 08:40:20 +0000 (10:40 +0200)]
term-style-control: Make multithread-safe, part 5: SIGCONT handler.
* lib/term-style-control.c (stopped_controller, stopped_user_data,
stopped_signal_handler_needs_reinstall): New variables.
(stopping_signal_handler): Set these variables.
(continuing_signal_handler): Use these variables instead of
active_controller and active_control_data, that may already be NULL
at this point.
(activate_term_style_controller): Initialize
stopped_signal_handler_needs_reinstall.
Bruno Haible [Mon, 18 May 2026 08:33:54 +0000 (10:33 +0200)]
term-style-control: Make multithread-safe, part 4: Redirect signals.
* lib/term-style-control.c (active_thread): New variable.
(fatal_signal_handler, stopping_signal_handler): Redirect the signal
from the current thread to the active_thread.
(activate_term_non_default_mode): Initialize active_thread.
(deactivate_term_non_default_mode): Reset active_thread to NULL.
Bruno Haible [Mon, 18 May 2026 07:58:41 +0000 (09:58 +0200)]
term-style-control: Make multithread-safe, part 2: Improve logging.
* lib/term-style-control.c: Include <stdint.h>, <pthread.h>.
(HAVE_POSIX_THREADS): New macro.
(log_message): Preserve errno.
(sprintf_integer_hex): New function.
(log_signal_handler_called): Show also the current thread ID.
(fatal_or_stopping_signal_handler): Add log_message invocations to show
the taken code path.
* modules/term-style-control (Depends-on): Add stdint-h.
(configure.ac): Test for <pthread.h>.
Bruno Haible [Mon, 18 May 2026 07:43:37 +0000 (09:43 +0200)]
term-style-control tests: Add a test with multithreading.
* tests/test-term-style-control-yes.h: New file, based on
tests/test-term-style-control-yes.c.
* tests/test-term-style-control-yes.c: Move most definitions to
tests/test-term-style-control-yes.h.
Include test-term-style-control-yes.h.
(main): Just invoke styled_yes_loop.
* tests/test-term-style-control-yes-mt.c: New file.
* modules/term-style-control-tests (Files): Add
tests/test-term-style-control-yes.h,
tests/test-term-style-control-yes-mt.c.
(Depends-on): Add thread, nanosleep.
(Makefile.am): Arrange to build test-term-style-control-yes-mt.
Bruno Haible [Sat, 16 May 2026 21:36:09 +0000 (23:36 +0200)]
fatal-signal: Make really multithread-safe.
* lib/fatal-signal.h (block_fatal_signals): Document a constraint
regarding thread creation.
* lib/fatal-signal.c: Include sigdelay.h.
(fatal_signals_block_initially_mt): New variable.
(block_fatal_signals, unblock_fatal_signals): In a multithreaded
process, use sigdelay instead of pthread_sigmask.
* modules/fatal-signal (Depends-on): Add sigdelay.
Bruno Haible [Sat, 16 May 2026 10:41:01 +0000 (12:41 +0200)]
thread-optim: Port to older glibc, musl libc, *BSD, Solaris, Android.
* lib/thread-optim.h: Include <stdbool.h>.
(gl_multithreaded): Define differently on ELF platforms.
(_GL_MULTITHREADED_ALWAYS_TRUE, _GL_MULTITHREADED_VIA_ELF): New macros.
(gl_set_multithreaded): New declaration.
* lib/thread-optim.c: New file.
* lib/thread-creators.gperf: New file.
* lib/thread-optim-proto.c: New file.
* modules/thread-optim (Files): Add these files.
(Depends-on): Add gperf, bool, stdint-h.
(configure.ac): Test for <link.h>, dl_iterate_phdr.
(Makefile.am): Compile thread-optim.c. Create thread-creators.h through
gperf.
Bruno Haible [Wed, 13 May 2026 10:51:40 +0000 (12:51 +0200)]
intprops: Fix compilation error in MSVC.
* lib/intprops.h (TYPE_IS_INTEGER, TYPE_MINIMUM, TYPE_MAXIMUM): Don't
use _Generic to distinguish between 'char' and 'signed char' with MSVC
before version 14.44.
* lib/intprops-internal.h (_GL_TYPE_SIGNED): Likewise.
Bruno Haible [Tue, 12 May 2026 08:49:49 +0000 (10:49 +0200)]
stdc_bit_floor, stdc_bit_ceil: Work around Solaris 11 OpenIndiana bug.
* lib/stdbit.in.h (stdc_bit_floor, stdc_bit_ceil): Override the macro
definition from Solaris 11.
* doc/posix-functions/stdc_bit_floor.texi: Mention the Solaris 11
OpenIndiana bug.
* doc/posix-functions/stdc_bit_ceil.texi: Likewise.
Bruno Haible [Mon, 11 May 2026 19:15:44 +0000 (21:15 +0200)]
gettext-h: Ensure no warnings with --disable-nls and -Wformat=2.
* lib/gettext.h (gettext, dgettext, dcgettext): Define differently for
clang.
(ngettext, dngettext, dcngettext): Define differently for gcc and clang.
With gcc in C mode, silence -Wuseless-cast warnings.
Paul Eggert [Mon, 11 May 2026 17:20:45 +0000 (10:20 -0700)]
careadlinkat: pacify GCC 12+ -Wreturn-local-addr more simply
* lib/careadlinkat.c (readlink_stk):
Now also noinline when _GL_GNUC_PREREQ (12, 1) && !USING_LTO.
The small inlining performance improvement for GCC 12+ was not worth
the hassle of documenting or autoconfiguring USING_LTO.
This change removes the need for USING_LTO.
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-05/msg00103.html
Paul Eggert [Mon, 11 May 2026 03:55:24 +0000 (20:55 -0700)]
intprops: ignore -Wuseless-cast less often
Using _Generic instead of casting should help includers of
<intprops.h> to avoid suppression of -Wuseless-cast diagnostics.
* lib/intprops-internal.h: Ignore -Wuseless-cast only
if (__STDC_VERSION__ < 201112 && 14 <= __GNUC__).
(_GL__GENERIC_BOGUS): Move definition up.
* lib/intprops-internal.h (_GL_TYPE_SIGNED):
* lib/intprops.h (TYPE_IS_INTEGER, TYPE_MINIMUM, TYPE_MAXIMUM):
Use _Generic if this should work, to avoid the need for casts.
* lib/intprops-internal.h (_GL_INT_NEGATE_OVERFLOW):
* lib/intprops.h (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW)
(_GL_MULTIPLY_OVERFLOW): When _GL_HAS_BUILTIN_OVERFLOW_P, use
_GL_INT_CONVERT to avoid the need for a cast.
Paul Eggert [Mon, 11 May 2026 01:44:40 +0000 (18:44 -0700)]
regex: omit useless casts
* lib/regex_internal.c (build_wcs_upper_buffer):
Omit cast from char * to char *.
* lib/regex_internal.h (re_string_wchar_at):
Omit casts to wint_t in a context that will already convert to wint_t.
Paul Eggert [Sun, 10 May 2026 20:52:28 +0000 (13:52 -0700)]
manywarnings: add -Wstringop-overflow=4
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C)): Add
-Wstringop-overflow=4. This option, when used with GCC 16, works
with current Gnulib and with coreutils, so it seems like a good
thing to add to the default list.
Paul Eggert [Sun, 10 May 2026 20:09:27 +0000 (13:09 -0700)]
careadlinkat: pacify GCC 16 -flto
Use a simpler scheme to pacify GCC.
* lib/careadlinkat.c (readlink_stk): With GCC 12+,
do not ignore -Wreturn-local-addr if -flto is being used,
as this does not work with current coreutils and with
gcc 16.1.1 20260501 (Red Hat 16.1.1-1) x86-64.
Instead, fall back on __attribute__ ((__noinline__)).
(GCC_BOGUS_WRETURN_LOCAL_ADDR): Remove. Do not bother
with this as it complicates maintenance and is present only
for better diagnostics in older compilers.
Just use __attribute__ ((__noinline__)) instead.
All uses removed.
Paul Eggert [Sun, 10 May 2026 18:23:37 +0000 (11:23 -0700)]
chown: use AC_CHECK_HEADERS_ONCE on standard headers
* m4/chown.m4 (AC_FUNC_CHOWN):
* m4/size_max.m4 (gl_SIZE_MAX):
* m4/xsize.m4 (gl_XSIZE): Prefer AC_CHECK_HEADERS_ONCE to
AC_CHECK_HEADERS for standard headers that Autoconf will use
AC_CHECK_HEADERS_ONCE on anyway.
Paul Eggert [Sun, 10 May 2026 18:20:07 +0000 (11:20 -0700)]
canonicalize: use stdckdint.h not intprops.h
canonicalize: use stdckdint.h not intprops.h
<stdckdint.h> is standard, so prefer that to the pre-standard
intprops.h.
* lib/canonicalize.c: Include stdckdint.h, not intprops.h.
(canonicalize_filename_mode_stk): Use ckd_add, not INT_ADD_OVERFLOW.
* modules/canonicalize (Depends-on): Remove intprops.
Add stdckdint-h. Sort.
Paul Eggert [Sun, 10 May 2026 17:35:50 +0000 (10:35 -0700)]
canonicalize: pacify -Wmaybe-uninitialized without ignoring
* lib/canonicalize.c: Do not ignore -Wmaybe-uninitialized.
(IF_LINT): Remove; no longer used.
(canonicalize_filename_mode_stk): Use a single local rather than two.
Ordinarily portmanteau variables are iffy, but this one is a win.
Bruno Haible [Sun, 10 May 2026 22:10:44 +0000 (00:10 +0200)]
Revisit some -Wuseless-cast changes.
* lib/fstrcmp.c (fstrcmp_free_resources, fstrcmp_bounded): Use a
compound literal to convert to uintptr_t.
* lib/wait-process.c (wait_subprocess): Use a compound literal to
convert to int.
* lib/sigsegv.c: Revert last change. Instead, disable -Wuseless-cast
in this compilation unit.
* tests/jit/test-cache.c: Likewise.
* tests/test-limits-h.c: Disable -Wuseless-cast warnings also for
gcc 14, 15.
Paul Eggert [Sat, 9 May 2026 05:57:46 +0000 (22:57 -0700)]
u64: go back to casts for u64init
* lib/u64.h (u64init) [INT_MAX < UINT64_MAX]: Don’t use a compound
literal here, as u64init is intended for use in static
initializers. Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-05/msg00063.html
Paul Eggert [Fri, 8 May 2026 22:35:18 +0000 (15:35 -0700)]
Avoid string literal type confusion
Instead of ‘... (char *) "abc" ...’, which is a bit confusing as
"abc" is already of type char *, use ‘static char const s[] =
"abc"; ... (char *) s .... This pacifices -Wuseless-cast.
* lib/boot-time.c (get_boot_time_uncached):
* lib/time_rz.c (save_abbr):
* tests/test-posix_spawn-chdir.c (test):
* tests/test-posix_spawn-fchdir.c (test):
* tests/test-unsetenv.c (main):
Redo with named string as described above.
Paul Eggert [Fri, 8 May 2026 22:17:06 +0000 (15:17 -0700)]
times-tests: pacify -Wuseless-cast
* tests/test-times.c (tms2ms): New function.
(main): Use it to simplify printing and avoid need for casts.
Pacify -Wuseless-cast via compound literals.
Paul Eggert [Fri, 8 May 2026 22:15:31 +0000 (15:15 -0700)]
strncat-tests: omit confusing casts
* tests/test-strncpy.c (check): Omit no-op cast.
* tests/unistr/test-strncat.h (check): Use better type for
page_boundary, removing the need for a cast.
Paul Eggert [Fri, 8 May 2026 21:28:51 +0000 (14:28 -0700)]
Avoid useless casts in m4/*.m4.
This is mostly for consistency. In theory it could help
if someone mistakenly configures with -Wuseless-cast in CFLAGS.
* m4/c32rtomb.m4 (gl_C32RTOMB_SANITYCHECK):
* m4/iswdigit.m4 (gl_FUNC_ISWDIGIT):
* m4/iswxdigit.m4 (gl_FUNC_ISWXDIGIT):
* m4/mbrtoc32.m4 (gl_MBRTOC32_SANITYCHECK):
* m4/mbrtowc.m4 (gl_MBRTOWC_NULL_ARG1)
(gl_MBRTOWC_STORES_INCOMPLETE):
* m4/mbsnrtowcs.m4 (gl_MBSNRTOWCS_WORKS_IN_TRADITIONAL_LOCALE):
* m4/wcrtomb.m4 (gl_FUNC_WCRTOMB):
Do not cast to wchar_t when the context is already wchar_t.
Paul Eggert [Fri, 8 May 2026 21:22:56 +0000 (14:22 -0700)]
Suppress -Wuseless-cast when calling mmap
I assume the void * casts for mmap are for ancient systems
where mmap returned char *, though Gnulib no longer ports to those.
For now, simply suppress the warning in the few places that use
mmap directly.
* lib/stackvma.c, lib/vma-iter.c, tests/mmap-anon-util.h:
Ignore -Wuseless-cast.
Paul Eggert [Fri, 8 May 2026 21:19:03 +0000 (14:19 -0700)]
sigsegv: pacify -Wuseless-cast
This also makes the code a bit less confusing.
* lib/sigsegv.c (SIGSEGV_FAULT_ADDRESS): Now of type void *.
Change the Hurd implementation to guarantee this.
(sigsegv_handler): Omit no-longer needed cast to void *.
Omit function pointer cast when SIGSEGV_FAULT_ADDRESS_FROM_SIGINFO,
as it’s not needed in that case.