Bruno Haible [Wed, 14 May 2025 11:57:28 +0000 (13:57 +0200)]
spin: Add tests.
* tests/test-spin1.c: New file, based on tests/test-asyncsafe-spin1.c.
* tests/test-spin2.c: New file, based on tests/test-asyncsafe-spin2.c.
* modules/spin-tests: New file.
Bruno Haible [Wed, 14 May 2025 10:51:46 +0000 (12:51 +0200)]
spin: New module.
* lib/glthread/spin.h: New file, based on lib/glthread/lock.h and
lib/asyncsafe-spin.h.
* lib/glthread/spin.c: New file, based on lib/asyncsafe-spin.c.
* modules/spin: New file.
* doc/multithread.texi (Choosing a multithreading API): Spin locks no
longer require POSIX threads.
(Gnulib multithreading): Mention the 'spin' module.
Bruno Haible [Sun, 11 May 2025 22:42:33 +0000 (00:42 +0200)]
Silence some more gcc 15 -Wunterminated-string-initialization warnings.
* lib/uninorm/composition.c (struct composition_rule): Mark codes[] as
nonstring.
* lib/gen-uni-tables.c (output_composition_tables): Emit the same
'struct composition_rule' definition.
* lib/uninorm/composition-table.gperf: Regenerated.
Bruno Haible [Sun, 11 May 2025 00:55:11 +0000 (02:55 +0200)]
string-desc: Fixes for string literals and older GCC versions.
* lib/string-desc.h (HAVE__GENERIC, HAVE_BUILTIN_CHOOSE_EXPR,
HAVE_BUILTIN_CONSTANT_P, HAVE_RW_STRING_DESC): New macros.
Use HAVE_RW_STRING_DESC instead of HAVE_STATEMENT_EXPRESSIONS
everywhere.
(sd_new_addr): Use __builtin_choose_expr to deal with string literals.
* lib/xstring-desc.h: Use HAVE_RW_STRING_DESC instead of
HAVE_STATEMENT_EXPRESSIONS.
* lib/string-buffer.c (sb_dupfree): Construct an empty writable string
without a cast.
* lib/xstring-buffer.c (sb_xdupfree): Likewise.
* lib/string-buffer-reversed.c (sbr_dupfree): Likewise.
* lib/xstring-buffer-reversed.c (sbr_xdupfree): Likewise.
Collin Funk [Sat, 10 May 2025 23:07:57 +0000 (16:07 -0700)]
fts: Fix redefinition of __THROW.
* lib/fts_.h: Include <sys/cdefs.h> if the system has it.
(__THROW, __BEGIN_DECLS, __END_DECLS): Define properly if not previously
defined.
* m4/fts.m4 (gl_FUNC_FTS_CORE): Check for sys/cdefs.h.
Bruno Haible [Sat, 10 May 2025 15:12:28 +0000 (17:12 +0200)]
string-desc, xstring-desc: Avoid GCC attributes in function definitions.
Reported by Collin Funk in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00126.html>.
* lib/attribute.h: Clarify the allowed positions of attributes in
function definitions.
* lib/string-desc.h (_sd_char_at): Add a declaration, to hold the
gcc attrribute.
* lib/xstring-desc.h (_xsd_c): Likewise.
Paul Eggert [Sat, 10 May 2025 01:48:03 +0000 (18:48 -0700)]
acl-tests: link with $(FILE_HAS_ACL_LIB)
* modules/acl-tests (test_copy_acl_LDADD): Add
$(FILE_HAS_ACL_LIB), since qcopy-acl depends on file-has-acl.
Although this suggests that QCOPY_ACL_LIB should contain
FILE_HAS_ACL_LIB, I’m not sure whether that’s the right course of
action and anyway this is good enough for coreutils.
Bruno Haible [Sat, 10 May 2025 01:16:52 +0000 (03:16 +0200)]
string-desc: Distinguish writable strings from read-only strings.
* lib/string-desc.h (HAVE_STATEMENT_EXPRESSIONS): New macro.
(rw_string_desc_t): New type.
(string_desc_t) [HAVE_STATEMENT_EXPRESSIONS]: Change field _data from
'char *' to 'const char *'.
(sd_readonly, sd_readwrite): New inline functions.
(sd_length): Define through a macro with _Generic.
(sd_char_at): Define through a macro and an inline function.
(sd_data, sd_is_empty): Define through a macro with _Generic.
(sd_equals, sd_startswith, sd_endswith, sd_cmp, sd_c_casecmp, sd_index,
sd_last_index, sd_contains): Define through a macro.
(sd_new_addr): Define through a macro with _Generic.
(sd_substring, sd_write, sd_fwrite): Define through a macro.
(sd_new, sd_new_filled): Change parameter type.
(sd_copy): Define through a macro.
(sd_concat): Change parameter type.
(sd_c): Define through a macro.
(sd_set_char_at, sd_fill): Change parameter type.
(sd_overwrite): Define through a macro.
(sd_free): Change parameter type.
* lib/string-desc.c (_sd_equals): Renamed from sd_equals. Take scalar
parameters.
(_sd_startswith): Renamed from sd_startswith. Take scalar parameters.
(_sd_endswith): Renamed from sd_endswith. Take scalar parameters.
(_sd_cmp): Renamed from sd_cmp. Take scalar parameters.
(_sd_c_casecmp): Renamed from sd_c_casecmp. Take scalar parameters.
(_sd_index): Renamed from sd_index. Take scalar parameters.
(_sd_last_index): Renamed from sd_last_index. Take scalar parameters.
(_sd_new_addr, _rwsd_new_addr): Renamed from sd_new_addr.
(sd_substring): Remove function.
(_sd_write): Renamed from sd_write. Take scalar parameters.
(_sd_fwrite): Renamed from sd_fwrite. Take scalar parameters.
(sd_new, sd_new_filled): Change parameter type.
(_sd_copy): Renamed from sd_copy. Change parameter type. Take scalar
parameters.
(sd_concat): Change parameter type.
(_sd_c): Renamed from sd_c. Take scalar parameters.
(sd_set_char_at, sd_fill): Change parameter type.
(_sd_overwrite): Renamed from sd_overwrite. Change parameter type. Take
scalar parameters.
(sd_free): Change parameter type.
* lib/string-desc-contains.c (_sd_contains): Renamed from sd_contains.
Take scalar parameters.
* lib/xstring-desc.h (xsd_new, xsd_new_filled, xsd_copy, xsd_concat):
Change return type to rw_string_desc_t.
(xsd_c): Define through a macro.
* lib/xstring-desc.c (xsd_concat): Change return type to
rw_string_desc_t.
* doc/string-desc.texi (Handling strings with NUL characters): Mention
rw_string_desc_t and the sd_readonly() function.
* lib/string-buffer.h (sb_dupfree, sb_xdupfree): Change return type to
rw_string_desc_t.
* lib/string-buffer.c (sb_contents): Add a cast to 'const char *'.
(sb_dupfree): Change return type to rw_string_desc_t.
* lib/xstring-buffer.c (sb_xdupfree): Change return type to
rw_string_desc_t.
* lib/string-buffer-reversed.h (sbr_dupfree, sbr_xdupfree): Change
return type to rw_string_desc_t.
* lib/string-buffer-reversed.c (sbr_contents): Add a cast to
'const char *'.
(sbr_dupfree): Change return type to rw_string_desc_t.
* lib/xstring-buffer-reversed.c (sbr_xdupfree): Change return type to
rw_string_desc_t.
* tests/test-string-desc.c (main): Use type rw_string_desc_t as
appropriate.
* tests/test-xstring-desc.c (main): Likewise.
* tests/test-sf-istream.c (main): Remove cast in sd_new_addr argument.
* tests/test-sfl-istream.c (main): Likewise.
* NEWS: Mention the change.
Paul Eggert [Sat, 10 May 2025 01:02:29 +0000 (18:02 -0700)]
qcopy-acl: port better to NFSv4 on GNU/Linux
Problem reported by Ian Dall in <https://bugs.gnu.org/78328>
and by Thomas Clark in <https://bugzilla.redhat.com/2363149>.
* lib/file-has-acl.c (smack_new_label_from_file) [!HAVE_SMACK]:
New dummy function.
(has_xattr, get_aclinfo): New arg FD. All callers changed.
Remove some unnecessary MAYBE_UNUSEDs.
(acl_get_fd_np): Fall back on acl_get_fd if this function is
needed but not available.
(acl_get_fdfile): New function, if needed.
(file_has_aclinfo): Reimplement in terms of ...
(fdfile_has_aclinfo): ... this new function,
which also has an FD argument.
* lib/qcopy-acl.c [USE_XATTR]: Include dirent.h, for DT_DIR etc.
(qcopy_acl): If attr_copy_file or attr_copy_fd fail with EOPNOTSUPP,
don’t fail if the source has a trivial ACL (this is the part
that fixes the bug; the rest is optimization).
* modules/qcopy-acl (Depends-on): Depend on dirent-h and
file-has-acl if $use_xattr. Also, depend on acl-permissions
unconditionally, since qcopy-acl.c includes acl.h unconditionally.
Bruno Haible [Thu, 8 May 2025 13:03:44 +0000 (15:03 +0200)]
nstrftime: Fix a link error on Android API level ≥ 35.
Reported by Po Lu <luangruo@yahoo.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00069.html>.
* lib/strftime.c (HAVE_ONLY_C_LOCALE): New macro.
(REQUIRE_GNUISH_STRFTIME_AM_PM): Set to false if HAVE_ONLY_C_LOCALE
is 1.
(TOUPPER): Use c_toupper if HAVE_ONLY_C_LOCALE is 1.
(c_locale_cache, c_locale): Don't define if HAVE_ONLY_C_LOCALE
&& HAVE_STRUCT_TM_TM_ZONE.
(utc_timezone_cache, utc_timezone): Don't define if
(HAVE_ONLY_C_LOCALE || (USE_C_LOCALE && !HAVE_STRFTIME_L))
&& HAVE_STRUCT_TM_TM_ZONE.
(c_weekday_names, c_month_names): Define also if HAVE_ONLY_C_LOCALE
is 1.
(underlying_strftime): Don't define if
HAVE_ONLY_C_LOCALE && HAVE_STRUCT_TM_TM_ZONE
&& !(USE_C_LOCALE && !HAVE_STRFTIME_L).
(get_tm_zone): On Android, don't return NULL.
(__strftime_internal): If HAVE_ONLY_C_LOCALE is 1, don't invoke
underlying_strftime.
* modules/nstrftime (Depends-on): Add c-ctype.
Paul Eggert [Wed, 7 May 2025 19:03:29 +0000 (12:03 -0700)]
obstack: avoid undefined pointer comparison
* lib/obstack.in.h (_OBSTACK_CPTR): New macro.
(obstack_free): Use it instead of comparing pointers directly,
when the pointers might not point into the same object.
Paul Eggert [Wed, 7 May 2025 18:20:40 +0000 (11:20 -0700)]
obstack: check def before use in macros
* lib/obstack.in.h (__attribute_noreturn__, __extension__):
Be more careful about checking whether a macro is defined before
using it, as some compilers complain otherwise.
Simplify the logic for __extension__.
Bruno Haible [Wed, 7 May 2025 06:57:31 +0000 (08:57 +0200)]
Fix "make sc_prohibit_leading_TABs" failures.
* Makefile (exclude_file_name_regexp--sc_prohibit_leading_TABs): New
variable.
(sc_prohibit_leading_TABs): Use it.
* lib/crc-x86_64-pclmul.c: Untabify.
* tests/test-crc.c: Untabify.
* tests/test-parse-duration.sh: Remove leading tabs from here documents.
Paul Eggert [Tue, 6 May 2025 22:09:02 +0000 (15:09 -0700)]
obstack: let glibc user #define __obstack_free
* lib/obstack.in.h (__obstack_free)
[! (__GL_GNULIB_HEADER && __GL_REPLACE_OBSTACK__)]:
Allow glibc user to #define __obstack_free. Although this
vestigial feature is not useful any more, it is one less change to
current glibc usage and so should make it a bit easier to merge
with glibc.
Paul Eggert [Tue, 6 May 2025 21:57:40 +0000 (14:57 -0700)]
obstack: don’t assume INT_MAX < SIZE_MAX
This for clarity and to document the overflow checking better;
I think no current Gnulib or glibc targets have SIZE_MAX <= INTMAX,
so it shouldn’t change behavior on current targets.
* lib/obstack.c: Include stdckdint.h, not limits.h.
Remove no-longer needed ! (SIZE_MAX <= INT_MAX) check.
(align_chunk_size_up): Rename from align_size_up,
and change API to detect overflow directly. All callers changed.
(align_chunk_size_up, _obstack_newchunk): Use ckd_add instead of
checking overflow by hand in a way that assumed INT_MAX < SIZE_MAX.
(call_chunkfun, _obstack_begin_worker, _obstack_newchunk):
Accept and use _OBSTACK_CHUNK_SIZE_T not size_t. This affects
only glibc, since the two types are the same in Gnulib. All
callers changed.
* modules/obstack (Depends-on): Add stdckdint-h.
* lib/obstack.in.h (__obstack_free): Define to _obstack_free, not
obstack_free, within glibc and in gnulib on systems without glibc.
* lib/obstack.c (obstack_free): Undefine only for the strong_alias.
(obstack_free): Define as an alias of _obstack_free, not vice versa.
Paul Eggert [Mon, 5 May 2025 21:02:21 +0000 (14:02 -0700)]
obstack: match obstack.c with glibc
Make this file easier to compare with glibc obstack.c.
* lib/obstack.c: Include shlib-compat.h or libc-config.h.
Move some !_OBSTACK_NO_ERROR_HANDLER declarations up.
Add _LIBC-only compatibility decls.
* modules/obstack (Depends-on): Add libc-config.
Paul Eggert [Mon, 5 May 2025 21:02:21 +0000 (14:02 -0700)]
obstack: simplify default size, alignment
* lib/obstack.c (MAX, DEFAULT_ALIGNMENT, DEFAULT_ROUNDING): Remove.
(_obstack_begin_worker): Use __alignof__ (max_align_t)
instead of calculating it by hand, possibly incorrectly
on oddball platforms. Estimate a good size of 4000 bytes
rather than using a no-longer-valid value.
* modules/obstack (Depends-on): Add stddef-h, for max_align_t.
Paul Eggert [Mon, 5 May 2025 21:02:19 +0000 (14:02 -0700)]
obstack: fix undefined behavior if big alignment
* lib/obstack.c: Include stddef.h, for offsetof.
(align_size_up): New static function.
(_obstack_begin_worker, _obstack_newchunk):
Ensure that the chunk limit is aligned, too.
(_obstack_begin_worker): Don’t assume that 4096 is large enough,
as the alignment could be larger.
* lib/obstack.in.h (obstack_finish): Remove code that could have
set next_free outside the limits of the allocated storage, which
had undefined behavior. This code is no longer needed now that
chunk_limit has proper alignment.
Paul Eggert [Mon, 5 May 2025 21:02:17 +0000 (14:02 -0700)]
obstack: be more like glibc in return values
This partly reverts commit d15b2da0ac25e085ce30a9e2672624999ce910a6
dated 2014-11-03. It keeps the part of that commit that fixed the
return type of non-gcc versions of obstack_make_room,
obstack_grow, obstack_grow0, obstack_1grow, obstack_ptr_grow_fast,
obstack_int_grow_fast, obstack_blank so that they agree with gcc
versions.
* lib/obstack.in.h (obstack_next_free, obstack_chunkfun)
(obstack_freefun, obstack_1grow_fast, obstack_blank_fast):
Go back to returning a value instead of void,
to allay any glibc concerns about compatibility.
(obstack_1grow, obstack_blank): Explicitly return void,
since callees no longer do so.
Paul Eggert [Mon, 5 May 2025 21:02:17 +0000 (14:02 -0700)]
obstack: _obstack_free → __obstack_free
* lib/obstack.in.h (__obstack_free): Rename back from _obstack_free.
This is for compatibility with glibc, which in turn is for
compatibility with old Gnulib. All uses changed.
Paul Eggert [Mon, 5 May 2025 21:02:16 +0000 (14:02 -0700)]
obstack: use glibc’s temp slot names
* lib/obstack.in.h (struct obstack): Rename temp fields back to
what glibc uses, to avoid any glibc concerns about source code
compatibility. All uses changed back. This affect only
non-GNU-compatible compilers.
Paul Eggert [Mon, 5 May 2025 21:02:15 +0000 (14:02 -0700)]
obstack: size_t → _OBSTACK_CHUNK_SIZE_T
* lib/obstack.c (_obstack_begin, _obstack_begin_1):
* lib/obstack.in.h (struct obstack, obstack_init, obstack_begin)
(obstack_specify_allocation)
(obstack_specify_allocation_with_arg, obstack_chunkfun):
Use _OBSTACK_CHUNK_SIZE_T instead of size_t in places where
glibc uses unsigned long rather than size_t. This makes
no difference with Gnulib, but should help allay any concerns
that merging Gnulib with glibc might change glibc’s ABI
on obsolescent glibc platforms where size_t is unsigned int.
Paul Eggert [Mon, 5 May 2025 21:02:14 +0000 (14:02 -0700)]
obstack: use int where glibc does
Make it easier to merge with glibc, by using int where
the glibc API uses int, when compiling for glibc.
This does not affect Gnulib behavior.
* lib/obstack.in.h (_OBSTACK_INDEX_T): New macro.
* lib/obstack.in.h (struct obstack):
* lib/obstack.c (_obstack_begin_worker, obstack_begin)
(_obstack_begin_1, _obstack_newchunk, _obstack_memory_used):
Use _OBSTACK_INDEX_T, not _OBSTACK_SIZE_T, for API components
where glibc uses int.
Paul Eggert [Mon, 5 May 2025 21:02:13 +0000 (14:02 -0700)]
obstack: use presence of uintptr_t
The code depends on the presence of uintptr_t,
not on whether ptrdiff_t is narrower than a pointer,
so use C macros that reflect this.
Also, clean up the namespace in the typical GCC-like case
* lib/obstack.in.h (_OBSTACK_UINTPTR_TYPE): New macro.
Include <stdint.h> only if needed (i.e., not GCC-like).
(__PTR_ALIGN): Use new macro instead of relying on
__GL_SMALL_PTRDIFF_T__ and directly on uintptr_t.
* m4/obstack.m4 (gl_FUNC_OBSTACK): Simplify by removing
__GL_SMALL_PTRDIFF_T__.
Paul Eggert [Mon, 5 May 2025 21:02:13 +0000 (14:02 -0700)]
obstack: define PTR_INT_TYPE
* lib/obstack.in.h (PTR_INT_TYPE): Define, for compatibility
with glibc even though we don’t need the type for anything
other than compatibility. Include stddef.h only if needed,
like glibc obstack.h does.
Paul Eggert [Mon, 5 May 2025 21:02:12 +0000 (14:02 -0700)]
obstack: merge better with glibc
When compiled for glibc, keep the fake array content size at 4,
for API compatibility with older glibc.
* lib/obstack.in.h (__FLEXIBLE_ARRAY_MEMBER): Remove.
(_OBSTACK_CHUNK_CONTENTS_SIZE): New macro.
(struct _obstack_chunk): Use it for contents size.
* modules/obstack (Depends-on): Add flexmember.
Paul Eggert [Mon, 5 May 2025 21:01:54 +0000 (14:01 -0700)]
obstack: stop depending on alignof
* lib/obstack.c (__alignof__) [!__GNUC__]:
Default to alignof, not to alignof_type.
* modules/obstack (Depends-on): Depend on alignasof directly,
not indirectly via alignof.
Paul Eggert [Mon, 5 May 2025 21:00:32 +0000 (14:00 -0700)]
obstack: fix unlikely buffer overrun in glibc
This bug is not plausible on any Gnulib platform,
but it could happen in glibc if the requested size is UINT_MAX.
* lib/obstack.c (_obstack_newchunk): Fail if requested size is 0.
* lib/obstack.in.h (obstack_grow0): Check for room <= len,
not room <= len + 1 where len + 1 could overflow.
Bruno Haible [Mon, 5 May 2025 09:37:16 +0000 (11:37 +0200)]
New module windows-cygpath.
* lib/windows-cygpath.h: New file, based on lib/cygpath.h.
* lib/windows-cygpath.c: New file, based on lib/cygpath.c.
* modules/windows-cygpath: New file.
Bruno Haible [Mon, 5 May 2025 09:32:23 +0000 (11:32 +0200)]
obstack: Relicense under LGPLv2+.
Alan Modra's permission is at
<https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00042.html>.
Paul Eggert's permission is at
<https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00041.html>.
Collin Funk [Sat, 3 May 2025 03:33:56 +0000 (20:33 -0700)]
doc: Update documentation for 'open' errno discrepancies.
* doc/posix-functions/open.texi: Document that NetBSD 10.0 and FreeBSD
14.2 set errno differently than POSIX specifies for
'open ("symlink", O_NOFOLLOW ...)'.
Bruno Haible [Fri, 2 May 2025 10:09:40 +0000 (12:09 +0200)]
vc-mtime: Make it work with git versions < 2.28.
* lib/vc-mtime.c (git_version): New variable.
(is_git_present): Read the output of "git --version", and set
git_version.
(max_vc_mtime): Don't pass option --no-relative if the git version
is < 2.28.
Bruno Haible [Wed, 30 Apr 2025 09:57:34 +0000 (11:57 +0200)]
obstack: Make it easier to sync back with glibc.
* lib/obstack.in.h: Use __GL_GNULIB_HEADER to delimit sections that are
for Gnulib usage.
Test __GL_SMALL_PTRDIFF_T__ instead of @SMALL_PTRDIFF_T@.
Test __GL_REPLACE_OBSTACK__ instead of @REPLACE_OBSTACK@.
* modules/obstack (Makefile.am): Substitute __GL_GNULIB_HEADER.
Substitute __GL_SMALL_PTRDIFF_T__ instead of @SMALL_PTRDIFF_T@.
Substitute __GL_REPLACE_OBSTACK__ instead of @REPLACE_OBSTACK@.
Bruno Haible [Wed, 30 Apr 2025 01:19:10 +0000 (03:19 +0200)]
New module mem-hash-map.
* lib/mem-hash-map.h: New file, from GNU gettext.
* lib/mem-hash-map.c: New file, from GNU gettext.
* modules/mem-hash-map: New file, from GNU gettext.
Bruno Haible [Tue, 29 Apr 2025 23:52:17 +0000 (01:52 +0200)]
New module next-prime.
* lib/next-prime.h: New file, based on lib/hash.c.
* lib/next-prime.c: New file, based on lib/hash.c.
* modules/next-prime: New file.
* lib/hash.c: Include next-prime.h.
(is_prime, next_prime): Remove functions.
* modules/hash (Depends-on): Add next-prime.
Bruno Haible [Tue, 29 Apr 2025 23:20:17 +0000 (01:20 +0200)]
New module hashkey-string.
* lib/hashkey-string.h: New file.
* lib/hashkey-string.c: New file, based on lib/clean-temp-simple.c.
* modules/hashkey-string: New file.
* lib/clean-temp-simple.c: Include hashkey-string.h. Don't include
<limits.h>.
(clean_temp_string_equals, clean_temp_string_hash): Remove functions.
(SIZE_BITS): Remove macro.
(register_temporary_file): Use hashkey_string_equals and
hashkey_string_hash.
* modules/clean-temp-simple (Depends-on): Add hashkey-string.