]> Savannah Git Hosting - gnulib.git/log
gnulib.git
5 months agoopenat: port lowest-fd to native MS-Windows
Paul Eggert [Tue, 12 Nov 2024 00:25:50 +0000 (16:25 -0800)]
openat: port lowest-fd to native MS-Windows

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2024-11/msg00081.html
* lib/openat.c (openat_permissive): When save_cwd allocates an FD,
allocate another one DFD and then close FD so that the later
open returns FD (the lowest available fd), as POSIX requires.

5 months agofts: Fix dependencies (regression 2024-11-06).
Bruno Haible [Mon, 11 Nov 2024 19:03:31 +0000 (20:03 +0100)]
fts: Fix dependencies (regression 2024-11-06).

* modules/fts (Depends-on): Add fcntl-safer.

5 months agomalloca: pacify CHERI clang
Paul Eggert [Mon, 11 Nov 2024 18:59:16 +0000 (10:59 -0800)]
malloca: pacify CHERI clang

* lib/malloca.c (freea) [__CHERI_PURE_CAPABILITY__]:
Add a cast as the code otherwise doesn’t conform to C.

5 months agofile-has-acl: another nofollow fix for FreeBSD
Paul Eggert [Mon, 11 Nov 2024 18:57:35 +0000 (10:57 -0800)]
file-has-acl: another nofollow fix for FreeBSD

* lib/file-has-acl.c (file_has_aclinfo): On FreeBSD, NetBSD >= 10,
if we don’t follow symlinks the first time, also don’t follow
them the second time, when it is typically a directory - so it
doesn’t matter whether symlinks are followed - but it might not be.

5 months agofile-has-acl: _GL_UNUSED → MAYBE_UNUSED
Paul Eggert [Mon, 11 Nov 2024 05:18:02 +0000 (21:18 -0800)]
file-has-acl: _GL_UNUSED → MAYBE_UNUSED

5 months agofile-has-acl: minor refactor of acl_get_link_np fix
Paul Eggert [Mon, 11 Nov 2024 15:52:32 +0000 (07:52 -0800)]
file-has-acl: minor refactor of acl_get_link_np fix

* lib/file-has-acl.c (file_has_aclinfo): Redo to avoid ‘else #endif’.

5 months agofile-has-acl: scontext even if --disable-acl
Paul Eggert [Mon, 11 Nov 2024 15:35:50 +0000 (07:35 -0800)]
file-has-acl: scontext even if --disable-acl

Be able to get the security context even if configured with
--disable-acl, as security contexts are not ACLs, and the
main reason for --disable-acl was for efficiency with GNU ls -l,
a concern that does not apply to security contexts (which are
needed only with ls -Z).  Problem reported by Pádraig Brady
<https://bugs.gnu.org/73418#52>.
* lib/acl.h (ACL_GET_SCONTEXT): New constant.
(aclinfo_free, aclinfo_scontext_free): Declare even if !USE_ACL.
* lib/file-has-acl.c (USE_LINUX_XATTR): No longer false merely
because !USE_ACL, because we need xattr to get scontext.
(get_aclinfo): Support new ACL_GET_SCONTEXT flag.

5 months agonproc: Use affinity mask even in out-of-memory situations.
Bruno Haible [Mon, 11 Nov 2024 14:40:52 +0000 (15:40 +0100)]
nproc: Use affinity mask even in out-of-memory situations.

* lib/nproc.c (num_processors_via_affinity_mask): Use a stack-allocated
cpu_set_t as fallback. Add comments.

5 months agonproc: Use affinity mask even on systems with more than 1024 CPUs.
Florian Weimer [Mon, 11 Nov 2024 13:05:53 +0000 (14:05 +0100)]
nproc: Use affinity mask even on systems with more than 1024 CPUs.

* lib/nproc.c (num_processors_via_affinity_mask): Retry
with larger affinity masks if CPU_ALLOC_SIZE is available.

5 months agoacl-permissions: Define the inline functions in this module.
Bruno Haible [Mon, 11 Nov 2024 08:53:23 +0000 (09:53 +0100)]
acl-permissions: Define the inline functions in this module.

* lib/acl-internal.c (ACL_INTERNAL_INLINE): Define here.
* lib/qset-acl.c (ACL_INTERNAL_INLINE): Don't define here.

5 months agogetpagesize: Fix use of 'extern inline' (regression 2012-11-20).
Bruno Haible [Mon, 11 Nov 2024 08:33:11 +0000 (09:33 +0100)]
getpagesize: Fix use of 'extern inline' (regression 2012-11-20).

* lib/unistd.in.h (_GL_GETPAGESIZE_INLINE): New macro.
(getpagesize): Use it.
* lib/getpagesize.c (_GL_GETPAGESIZE_INLINE): Define.
* modules/getpagesize (configure.ac): Compile getpagesize.c also when
getpagesize is missing.

5 months agorealloc-posix: Fix link error (regression 2024-11-04).
Bruno Haible [Mon, 11 Nov 2024 08:02:23 +0000 (09:02 +0100)]
realloc-posix: Fix link error (regression 2024-11-04).

* doc/extern-inline.texi (extern inline): Mention that one needs a
*_INLINE macro per compilation unit.
* lib/stdlib.in.h (_GL_REALLOC_INLINE): New macro.
(rpl_realloc): Use it. Don't test IN_GNULIB_TESTS.
* lib/realloc.c (_GL_REALLOC_INLINE): Define.

5 months agoUpdate .gitignore after 2024-10-27 change.
Bruno Haible [Mon, 11 Nov 2024 08:05:12 +0000 (09:05 +0100)]
Update .gitignore after 2024-10-27 change.

5 months agofile-has-acl: Fix compilation errors on macOS et al. (regr. 2024-11-09).
Bruno Haible [Mon, 11 Nov 2024 06:25:00 +0000 (07:25 +0100)]
file-has-acl: Fix compilation errors on macOS et al. (regr. 2024-11-09).

* m4/acl.m4 (gl_FUNC_ACL): Test whether acl_get_link_np exists.
* lib/file-has-acl.c (file_has_aclinfo): Use ACL_SYMLINK_FOLLOW, not
AC_SYMLINK_FOLLOW. Don't use acl_get_link_np if this function does not
exist.

5 months agorelocatable-prog-wrapper: Fix compilation error on NetBSD 7.
Bruno Haible [Sun, 10 Nov 2024 23:56:15 +0000 (00:56 +0100)]
relocatable-prog-wrapper: Fix compilation error on NetBSD 7.

Reported by Ionut Cosmin Mihai <ionut.cosmin.mihai@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnu-libiconv/2024-11/msg00000.html>.

* lib/relocwrapper.c: Fix dependency tree.
* modules/relocatable-prog-wrapper (Files): Add lib/stat-time.h,
lib/stat-time.c.
* build-aux/install-reloc (func_create_wrapper): Compile also
stat-time.c.

5 months agofile-has-acl: avoid -Werror=unused-variable with --disable-acl
Pádraig Brady [Sun, 10 Nov 2024 12:56:10 +0000 (12:56 +0000)]
file-has-acl: avoid -Werror=unused-variable with --disable-acl

* lib/file-has-acl.c (file_has_aclinfo): Mark D_TYPE as unused
in certain configurations.

5 months agofile-has-acl: symlinks can have scontext
Paul Eggert [Sat, 9 Nov 2024 22:52:05 +0000 (14:52 -0800)]
file-has-acl: symlinks can have scontext

Problem reported by Pádraig Brady <https://bugs.gnu.org/73418#35>.
* lib/file-has-acl.c (file_has_aclinfo):
With SELinux, symbolic links can have security contexts,
so omit incorrect optimizations assuming that they lack them.
When ! (flags & AC_SYMLINK_FOLLOW), prefer acl_get_link_np to
acl_get_file on platforms that have both APIs,
as this can avoid some races.

5 months agoautoupdate
Karl Berry [Fri, 8 Nov 2024 15:38:10 +0000 (07:38 -0800)]
autoupdate

5 months agofile-has-acl: minor ENOMEM fixes
Paul Eggert [Thu, 7 Nov 2024 17:37:17 +0000 (09:37 -0800)]
file-has-acl: minor ENOMEM fixes

* lib/file-has-acl.c: Include limits.h.
(get_aclinfo): Use a saturating add rather than reporting
overflow, in the very unlikely case that the size overflows.
This is simpler and is good enough here.
Also, defend against implausible system that fails with ERANGE
even when the buffer size is SSIZE_MAX.
(file_has_aclinfo): Since we already assume elsewhere that
malloc sets errno, rely on that here too.
* modules/file-has-acl (Depends-on): Add limits.h.
Also add malloc-posix, since we rely on malloc errno.

5 months agofile-has-acl: remove __gl_acl_alloc member
Paul Eggert [Thu, 7 Nov 2024 17:25:43 +0000 (09:25 -0800)]
file-has-acl: remove __gl_acl_alloc member

It may have been needed in earlier versions of this code,
but it is no longer needed.
* lib/acl.h (struct aclinfo): Remove __gl_acl_alloc.  All uses removed.
* lib/file-has-acl.c (get_aclinfo):
Use local, not the removed struct aclinfo slot.

5 months agoopendirat: don’t depend on openat-safer
Paul Eggert [Wed, 6 Nov 2024 21:33:27 +0000 (13:33 -0800)]
opendirat: don’t depend on openat-safer

* lib/opendirat.c: Include fcntl.h.
[!GNULIB_OPENAT_SAFER]: Don’t include fcntl--.h.
* modules/opendirat (Depends-on): Depend on openat, not openat-safer.

5 months agogetusershell: don’t depend on fopen-safer
Paul Eggert [Wed, 6 Nov 2024 21:27:08 +0000 (13:27 -0800)]
getusershell: don’t depend on fopen-safer

* lib/getusershell.c: Include stdio.h.
[!GNULIB_FOPEN_SAFER]: Don’t include stdio--.h.
* modules/getusershell (Depends-on): Depend on fopen, not fopen-safer.

5 months agosavewd: don’t depend on fcntl-safer
Paul Eggert [Wed, 6 Nov 2024 21:22:32 +0000 (13:22 -0800)]
savewd: don’t depend on fcntl-safer

* lib/savewd.c: Don’t include fcntl-safer.
[GNULIB_FCNTL_SAFER]: Include fcntl--.h.
(savewd_save): Use open, not open_safer.
* modules/savewd (Depends-on): Remove fcntl-safer.

5 months agosavedir: don’t depend on dirent-safer
Paul Eggert [Wed, 6 Nov 2024 21:03:19 +0000 (13:03 -0800)]
savedir: don’t depend on dirent-safer

* lib/savedir.c [!GNULIB_DIRENT_SAFER]: Don't include dirent--.h.
* modules/savedir (Depends-on): Depend on dirent, not dirent-safer.

5 months agosave-cwd: don’t depend on fd-safer-flag, unistd-safer
Paul Eggert [Wed, 6 Nov 2024 21:00:52 +0000 (13:00 -0800)]
save-cwd: don’t depend on fd-safer-flag, unistd-safer

They aren’t needed in packages that use xstdopen
* lib/save-cwd.c: Do not include unistd--.h.
(GNULIB_FCNTL_SAFER): Do not define.
(save_cwd): Do not use fd_safer_flag, as the package should use
either fcntl-safer+unistd-safer or xstdopen if it cares about
closed stdin.
* modules/save-cwd (Depends-on): Remove fd-safer-flag, unistd-safer.

5 months agoerror: tune a bit for xstdopen
Paul Eggert [Wed, 6 Nov 2024 20:51:38 +0000 (12:51 -0800)]
error: tune a bit for xstdopen

* lib/error.c (flush_stdout): Also optimize if GNULIB_XSTDOPEN.

5 months agounistd-safer indicate presence
Paul Eggert [Wed, 6 Nov 2024 20:48:38 +0000 (12:48 -0800)]
unistd-safer indicate presence

modules/unistd-safer (configure.ac): Add module indicator.

5 months agoxstdopen: indicate presence
Paul Eggert [Wed, 6 Nov 2024 20:43:26 +0000 (12:43 -0800)]
xstdopen: indicate presence

* modules/xstdopen (configure.ac): Add module indicator.

5 months agoDocument xstdopen vs *-safer better
Paul Eggert [Wed, 6 Nov 2024 20:32:27 +0000 (12:32 -0800)]
Document xstdopen vs *-safer better

5 months agomemset_explicit: Guarantee N3322 functionality.
Bruno Haible [Wed, 6 Nov 2024 12:02:09 +0000 (13:02 +0100)]
memset_explicit: Guarantee N3322 functionality.

* m4/memset_explicit.m4 (gl_PREREQ_MEMSET_EXPLICIT): Require
AC_CANONICAL_HOST. Test whether memset_s supports zero-length
operations.
* lib/memset_explicit.c (memset_explicit): Don't invoke memset_s with
argument 0 if memset_s does not support this.

5 months agowcsncat: Fix configure test.
Bruno Haible [Wed, 6 Nov 2024 11:44:26 +0000 (12:44 +0100)]
wcsncat: Fix configure test.

* m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Fix wrong cache variable name.

5 months agostrncat, wcsncat tests: Fix test.
Bruno Haible [Wed, 6 Nov 2024 11:34:18 +0000 (12:34 +0100)]
strncat, wcsncat tests: Fix test.

* tests/test-strncat.c (main): Change y to a valid string.
* tests/test-wcsncat.c (main): Change y to a valid wide string.

5 months agoeealloc: deprecate
Paul Eggert [Wed, 6 Nov 2024 07:07:09 +0000 (23:07 -0800)]
eealloc: deprecate

Now that malloc-gnu and realloc-posix arrange for the
various memory allocators to return non-null on success,
should be no need for the eealloc module.
* NEWS, modules/eealloc: Mention this.

5 months agorelocatable-prog-wrapper: remove eealloc.m4
Paul Eggert [Wed, 6 Nov 2024 06:48:53 +0000 (22:48 -0800)]
relocatable-prog-wrapper: remove eealloc.m4

* modules/relocatable-prog-wrapper (Files): Remove m4/eealloc.m4.
It wasn’t being used and evidently was listed only because
a previous version needed it.

5 months agoregex: port better to AIX extensions
Paul Eggert [Wed, 6 Nov 2024 06:20:45 +0000 (22:20 -0800)]
regex: port better to AIX extensions

Also, switch from eealloc.m4 to malloc.m4 to determine
whether malloc (0) returns nonnull.
* lib/regex_internal.c (re_node_set_alloc):
Remove special case for malloc (0).
* lib/regex_internal.h (MALLOC_0_IS_NONNULL): Remove.
* m4/regex.m4 (gl_PREREQ_REGEX): Do not require gl_EEMALLOC.
* modules/regex (Files): Remove m4/eealloc.m4, m4/malloc.m4.
(Depends-on): Add malloc-gnu.

5 months agomalloca: port better to AIX extensions
Paul Eggert [Wed, 6 Nov 2024 06:06:54 +0000 (22:06 -0800)]
malloca: port better to AIX extensions

Also, switch from eealloc.m4 to malloc.m4 to determine
whether malloc (0) returns nonnull.
* lib/malloca.c (mmalloca): Use HAVE_MALLOC_0_NONNULL,
not MALLOC_0_IS_NONNULL.
* m4/malloca.m4 (gl_MALLOCA): Require gl_FUNC_MALLOC_GNU,
not gl_EEMALLOC.
* modules/malloca (Files): Remove m4/eemalloc.m4.
(Depends-on): Add extensions-aix.
* modules/relocatable-prog-wrapper:
AC_REQUIRE gl_FUNC_MALLOC_POSIX to suppress Autoconf 2.71
“warning: AC_REQUIRE: `gl_FUNC_MALLOC_POSIX' was expanded before
it was required”.

5 months agomalloc: refactor to help replace eealloc
Paul Eggert [Wed, 6 Nov 2024 06:00:01 +0000 (22:00 -0800)]
malloc: refactor to help replace eealloc

* m4/malloc.m4 (gl_FUNC_MALLOC_0_NONNULL):
New macro, split out from gl_FUNC_MALLOC_GNU.
(gl_FUNC_MALLOC_GNU): Require it.

5 months agorealloc-posix: mention _LINUX_SOURCE_COMPAT
Paul Eggert [Wed, 6 Nov 2024 05:23:40 +0000 (21:23 -0800)]
realloc-posix: mention _LINUX_SOURCE_COMPAT

* m4/realloc.m4 (gl_FUNC_REALLOC_0_NONNULL):
Add comment about _LINUX_SOURCE_COMPAT.

5 months agodoc: remove duplicate realloc-posix listing
Paul Eggert [Wed, 6 Nov 2024 00:06:11 +0000 (16:06 -0800)]
doc: remove duplicate realloc-posix listing

* MODULES.html.sh: Remove duplicate entry for realloc-posix.

5 months agoaligned_alloc tests: Fix compilation error on mingw (regr. 2024-11-04).
Bruno Haible [Wed, 6 Nov 2024 04:23:51 +0000 (05:23 +0100)]
aligned_alloc tests: Fix compilation error on mingw (regr. 2024-11-04).

* tests/test-aligned_alloc.c (aligned_alloc): Don't redefine if
aligned_alloc does not exist.

5 months agoreallocarray: Fix compilation error in C++ mode (regr. 2024-11-04).
Bruno Haible [Wed, 6 Nov 2024 04:05:26 +0000 (05:05 +0100)]
reallocarray: Fix compilation error in C++ mode (regr. 2024-11-04).

* m4/reallocarray.m4 (gl_FUNC_REALLOCARRAY): Don't use
REPLACE_REALLOC_FOR_REALLOC_POSIX here. Use gl_cv_malloc_ptrdiff
instead.

5 months agodoc: improve documentation for malloc, realloc etc
Paul Eggert [Tue, 5 Nov 2024 23:57:20 +0000 (15:57 -0800)]
doc: improve documentation for malloc, realloc etc

5 months agomalloc: sync with Autoconf
Paul Eggert [Tue, 5 Nov 2024 23:55:24 +0000 (15:55 -0800)]
malloc: sync with Autoconf

This fixes a comment problem mentioned by Bruno in:
https://lists.gnu.org/r/bug-gnulib/2024-11/msg00048.html

5 months agowmemset tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:12:14 +0000 (21:12 +0100)]
wmemset tests: Verify N3322 functionality.

* tests/test-wmemset.c: New file.
* modules/wmemset-tests: New file.

5 months agowmemchr tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:12:11 +0000 (21:12 +0100)]
wmemchr tests: Verify N3322 functionality.

* tests/test-wmemchr.c: New file.
* modules/wmemchr-tests: New file.

5 months agowmemcmp tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:12:08 +0000 (21:12 +0100)]
wmemcmp tests: Verify N3322 functionality.

* tests/test-wmemcmp.c (main): Add zero-size tests.

5 months agowcsncmp tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:12:06 +0000 (21:12 +0100)]
wcsncmp tests: Verify N3322 functionality.

* tests/test-wcsncmp.c (main): Add zero-size tests.

5 months agowcsncat tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:39 +0000 (21:11 +0100)]
wcsncat tests: Verify N3322 functionality.

* tests/test-wcsncat.c: New file.
* modules/wcsncat-tests: New file.

5 months agowcsncat: Guarantee N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:33 +0000 (21:11 +0100)]
wcsncat: Guarantee N3322 functionality.

* lib/wchar.in.h (wcsncat): Consider REPLACE_WCSNCAT.
* m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Test whether the zero-length bug is
present.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCAT.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSNCAT.
* modules/wcsncat (Status, Notice): Remove.
(configure.ac): Consider REPLACE_WCSNCAT.
* doc/posix-functions/wcsncat.texi: Mention the zero-length bug.

5 months agowmemmove tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:29 +0000 (21:11 +0100)]
wmemmove tests: Verify N3322 functionality.

* tests/test-wmemmove.c: New file.
* modules/wmemmove-tests: New file.

5 months agowmemcpy tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:25 +0000 (21:11 +0100)]
wmemcpy tests: Verify N3322 functionality.

* tests/test-wmemcpy.c: New file.
* modules/wmemcpy-tests: New file.

5 months agowcsncpy tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:22 +0000 (21:11 +0100)]
wcsncpy tests: Verify N3322 functionality.

* tests/test-wcsncpy.c: New file.
* modules/wcsncpy-tests: New file.

5 months agomemset_explicit tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:20 +0000 (21:11 +0100)]
memset_explicit tests: Verify N3322 functionality.

* tests/test-memset_explicit.c (main): Add a zero-size test.

5 months agomemset tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:17 +0000 (21:11 +0100)]
memset tests: Verify N3322 functionality.

* tests/test-memset.c: New file.
* modules/memset-tests: New file.

5 months agomemchr tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:14 +0000 (21:11 +0100)]
memchr tests: Verify N3322 functionality.

* tests/test-memchr.c (main): Add a zero-size test.

5 months agostrncmp tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:12 +0000 (21:11 +0100)]
strncmp tests: Verify N3322 functionality.

* modules/strncmp: New file.
* doc/posix-functions/strncmp.texi: Mention the new module.
* tests/test-strncmp.c: New file.
* modules/strncmp-tests: New file.

5 months agomemcmp tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:10 +0000 (21:11 +0100)]
memcmp tests: Verify N3322 functionality.

* tests/test-memcmp.c (main): Add zero-size tests.

5 months agostrncat tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:11:02 +0000 (21:11 +0100)]
strncat tests: Verify N3322 functionality.

* tests/test-strncat.c (main): Add a zero-size test.

5 months agostrndup tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:23 +0000 (21:10 +0100)]
strndup tests: Verify N3322 functionality.

* tests/test-strndup.c: New file.
* modules/strndup-tests: New file.

5 months agostrndup: Guarantee N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:20 +0000 (21:10 +0100)]
strndup: Guarantee N3322 functionality.

* m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
* doc/posix-functions/strndup.texi: Mention the AIX bug.

5 months agostrncpy tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:13 +0000 (21:10 +0100)]
strncpy tests: Verify N3322 functionality.

* modules/strncpy: New file.
* doc/posix-functions/strncpy.texi: Mention the new module.
* tests/test-strncpy.c: New file.
* modules/strncpy-tests: New file.

5 months agomemmove tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:11 +0000 (21:10 +0100)]
memmove tests: Verify N3322 functionality.

* tests/test-memmove.c: New file.
* modules/memmove-tests: New file.

5 months agomemccpy tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:08 +0000 (21:10 +0100)]
memccpy tests: Verify N3322 functionality.

* modules/memccpy: New file.
* doc/posix-functions/memccpy.texi: Mention the new module.
* tests/test-memccpy.c: New file.
* modules/memccpy-tests: New file.

5 months agomemcpy tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:05 +0000 (21:10 +0100)]
memcpy tests: Verify N3322 functionality.

* tests/test-memcpy.c: New file.
* modules/memcpy-tests: New file.

5 months agoqsort tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:10:02 +0000 (21:10 +0100)]
qsort tests: Verify N3322 functionality.

* modules/qsort: New file.
* doc/posix-functions/qsort.texi: Mention the new module.
* tests/test-qsort.c: New file.
* modules/qsort-tests: New file.

5 months agobsearch tests: Verify N3322 functionality.
Bruno Haible [Tue, 5 Nov 2024 20:09:07 +0000 (21:09 +0100)]
bsearch tests: Verify N3322 functionality.

* modules/bsearch: New file.
* doc/posix-functions/bsearch.texi: Mention the new module.
* tests/test-bsearch.c: New file.
* modules/bsearch-tests: New file.

5 months agorealloc-posix: Avoid use of AC_LIBOBJ.
Bruno Haible [Tue, 5 Nov 2024 21:18:35 +0000 (22:18 +0100)]
realloc-posix: Avoid use of AC_LIBOBJ.

* modules/realloc-posix (configure.ac): Define
GL_COND_OBJ_REALLOC_POSIX. Don't invoke AC_LIBOBJ.
(Makefile.am): Add realloc.c to lib_SOURCES instead.

5 months agorealloc-posix: Fix link error (regression yesterday).
Bruno Haible [Tue, 5 Nov 2024 21:16:12 +0000 (22:16 +0100)]
realloc-posix: Fix link error (regression yesterday).

* lib/stdlib.in.h (realloc): Don't inline rpl_realloc if IN_GNULIB_TESTS
is defined.
* modules/realloc-posix (Depends-on, configure.ac): Compile realloc.c
also if REPLACE_REALLOC_FOR_REALLOC_POSIX is 2.

5 months agostdlib: Add a copyright header.
Bruno Haible [Tue, 5 Nov 2024 15:23:41 +0000 (16:23 +0100)]
stdlib: Add a copyright header.

* lib/stdlib.c: Add a copyright header.

5 months agocalloc, malloc: Fix a comment.
Bruno Haible [Tue, 5 Nov 2024 14:53:47 +0000 (15:53 +0100)]
calloc, malloc: Fix a comment.

* m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Mention that it sets
HAVE_MALLOC_PTRDIFF.
(gl_FUNC_MALLOC_PTRDIFF): Likewise.
(gl_CHECK_MALLOC_PTRDIFF): Do not mention HAVE_MALLOC_PTRDIFF here.

5 months agocalloc: Fix configure test (regression yesterday).
Bruno Haible [Tue, 5 Nov 2024 14:30:49 +0000 (15:30 +0100)]
calloc: Fix configure test (regression yesterday).

* m4/calloc.m4 (gl_FUNC_CALLOC_IF): Fix wrong cache variable name.
Rename cache variable. Restore earlier comment.

5 months agosafe-alloc: simplify, given new reallocarray behavior
Paul Eggert [Tue, 5 Nov 2024 06:24:29 +0000 (22:24 -0800)]
safe-alloc: simplify, given new reallocarray behavior

* lib/safe-alloc.h [__CHERI_PURE_CAPABILITY__]:
Remove special cases for this, as reallocarray
now does it for us.
(safe_alloc_realloc_n): Remove.  All uses replaced by reallocarray.

5 months agoargz: defend against realloc (0, 0)
Paul Eggert [Tue, 5 Nov 2024 05:38:55 +0000 (21:38 -0800)]
argz: defend against realloc (0, 0)

* modules/argz (Depends-on): Add realloc-posix so that
argz_append doesn’t wrongly fail with ENOMEM on AIX.

5 months agorealloc-posix: update doc
Paul Eggert [Tue, 5 Nov 2024 03:09:08 +0000 (19:09 -0800)]
realloc-posix: update doc

* doc/posix-functions/realloc.texi: Update to match recent Gnulib
changes and OS discoveries, and to clarify and simplify by
coalescing behaviors (4) and (5).

5 months agodoc: mention Solaris malloc ENOMEM issues
Paul Eggert [Tue, 5 Nov 2024 02:24:07 +0000 (18:24 -0800)]
doc: mention Solaris malloc ENOMEM issues

5 months agorealloc-posix: tune for glibc-like
Paul Eggert [Tue, 5 Nov 2024 02:16:50 +0000 (18:16 -0800)]
realloc-posix: tune for glibc-like

For glibc, implementing realloc (p, s) as realloc (p, s?s:1) suffices,
and it’s probably better to do it inline to aid static checking.
* lib/realloc.c (rpl_realloc) [_GL_INLINE_RPL_REALLOC]:
Remove, replacing with inline function in stdlib.h.
* lib/stdlib.in.h (_GL_INLINE_RPL_REALLOC): New macro.
(rpl_realloc): Define as inline if _GL_INLINE_RPL_REALLOC.
* m4/realloc.m4 (gl_FUNC_REALLOC_0_NONNULL):
Set REPLACE_REALLOC_FOR_REALLOC_POSIX=2 instead of 1,
if it’s close enough to glibc that the inline optimization is valid.

5 months agorealloc-posix: use _GL_USE_STDLIB_ALLOC
Paul Eggert [Mon, 4 Nov 2024 23:31:15 +0000 (15:31 -0800)]
realloc-posix: use _GL_USE_STDLIB_ALLOC

* lib/realloc.c (_GL_USE_STDLIB_ALLOC):
New macro, which we can use now that we don’t use malloc.
(realloc): Do not undef; no longer needed.

5 months agostdlib: make MB_CUR_MAX usable from extern inline
Paul Eggert [Mon, 4 Nov 2024 19:12:21 +0000 (11:12 -0800)]
stdlib: make MB_CUR_MAX usable from extern inline

* lib/stdlib.c: New file.
* modules/stdlib (Files, lib_SOURCES): Add it.
(Depends-on): Add extern-inline.
* lib/stdlib.in.h: Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
(_GL_STDLIB_INLINE): New macro.
(gl_MB_CUR_MAX): Make it _GL_STDLIB_INLINE not static inline,
so that it can be called from extern inline functions.
Redo implementation to help GCC better optimize common expressions
like (MB_CUR_MAX == 1).

5 months agorealloc-posix: set CHERI bounds
Paul Eggert [Mon, 4 Nov 2024 07:27:52 +0000 (23:27 -0800)]
realloc-posix: set CHERI bounds

* lib/ialloc.h, lib/xmalloc.c [__CHERI_PURE_CAPABILITY__]:
Do nothing special, as realloc and reallocarray
should do this for us now.
* lib/realloc.c [__CHERI_PURE_CAPABILITY__]:
Include cheri.h, and arrange for rpl_realloc to set bounds.

5 months agorealloc-posix: realloc (..., 0) now returns nonnull
Paul Eggert [Mon, 4 Nov 2024 06:41:41 +0000 (22:41 -0800)]
realloc-posix: realloc (..., 0) now returns nonnull

* lib/realloc.c (rpl_realloc): Simplify and tune by using
HAVE_REALLOC_0_NONNULL and HAVE_MALLOC_PTRDIFF, and
by having just one call to realloc instead of two.
* lib/reallocarray.c (reallocarray): Simplify and tune
by delegating the zero case to the revised realloc.
* m4/eealloc.m4 (_AC_FUNC_REALLOC_IF): Since only eealloc uses
this macro now, move its definition here ...
* m4/realloc.m4: ... from here.
(gl_FUNC_REALLOC_0_NONNULL): Also check that realloc (p, 0)
returns nonnull.  Require gl_FUNC_REALLOC_POSIX.
Define HAVE_REALLOC_0_NONNULL.
* m4/reallocarray.m4 (gl_FUNC_REALLOCARRAY):
Also replace reallocarray if it returns a null pointer for size zero.
* modules/eealloc (Files): Remove m4/realloc.m4.
* modules/realloc-posix (Depends-on): Add extensions-aix.
* modules/reallocarray (Files): Add m4/realloc.m4.

5 months agostdlib: simplify preprocessor conditionals
Paul Eggert [Mon, 4 Nov 2024 06:02:28 +0000 (22:02 -0800)]
stdlib: simplify preprocessor conditionals

* lib/stdlib.in.h: Omit some redundant tests in conditionals.

5 months agorealloc: don’t require success for nongrowth
Paul Eggert [Mon, 4 Nov 2024 05:44:15 +0000 (21:44 -0800)]
realloc: don’t require success for nongrowth

* lib/realloc.c (rpl_realloc): Do not require realloc (p, 0) to
succeed, as apparently glibc realloc (p, n) can sometimes fail
even when the region would not grow.

5 months agocalloc, malloc: tune a bit
Paul Eggert [Mon, 4 Nov 2024 02:18:58 +0000 (18:18 -0800)]
calloc, malloc: tune a bit

This applies mostly to non-glibc platforms, or to 32-bit
glibc before glibc 2.30 (2019).
* lib/calloc.c (rpl_calloc):
* lib/malloc.c (rpl_malloc):
Optimize away some of the code if !HAVE_MALLOC_0_NONNULL or if
!HAVE_MALLOC_PTRDIFF.
* m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Define HAVE_MALLOC_0_NONNULL.
(gl_FUNC_MALLOC_PTRDIFF): Define HAVE_MALLOC_PTRDIFF.

5 months agocalloc: configure more like malloc
Paul Eggert [Sun, 3 Nov 2024 20:24:03 +0000 (12:24 -0800)]
calloc: configure more like malloc

* m4/calloc.m4 (gl_FUNC_CALLOC_IF): Rename from _AC_FUNC_CALLOC_IF
since this is not derived from Autoconf.  All uses changed.
Redo implementation so that it is more like _AC_FUNC_MALLOC_IF;
this fixes some problems with "volatile" and modernizes the known
platforms.

5 months agomalloc-gnu: depend on stdckdint not xalloc-oversized
Paul Eggert [Sun, 3 Nov 2024 20:19:33 +0000 (12:19 -0800)]
malloc-gnu: depend on stdckdint not xalloc-oversized

* lib/malloc.c: Include stdckdint.h, xalloc-oversized.h.
(rpl_malloc): Use ckd_mul instead of xalloc_oversized.
* modules/malloc-gnu, modules/malloc-posix:
(Depends-on): Depend on stdckdint, not xalloc-oversized.

5 months agocalloc: depend on stdckdint not xalloc-oversized
Paul Eggert [Sun, 3 Nov 2024 19:11:03 +0000 (11:11 -0800)]
calloc: depend on stdckdint not xalloc-oversized

* lib/calloc.c: Include stdckdint.h, xalloc-oversized.h.
(rpl_calloc): Use ckd_mul instead of xalloc_oversized.
* modules/calloc-gnu, modules/calloc-posix:
(Depends-on): Depend on stdckdint, not xalloc-oversized.

5 months agomalloc etc. tests: use volatile more consistently
Paul Eggert [Mon, 4 Nov 2024 17:38:03 +0000 (09:38 -0800)]
malloc etc. tests: use volatile more consistently

Typically it’s ineffective to use ‘void *volatile p’
when testing malloc and similar functions, as the compiler
can optimize the call to malloc before assigning the result
to the volatile pointer variable.  Instead, be more systematic
about calling malloc through a volatile function pointer
so that the compiler cannot infer that it is a malloc call.
This fix can’t be done for alloca-like functions which may not
have a function address, so continue to trust to luck there.
* tests/test-aligned-malloc.c (aligned4_malloc, aligned4_free)
(aligned8_malloc, aligned8_free, aligned16_malloc)
(aligned16_free, aligned32_malloc, aligned32_free):
* tests/test-aligned_alloc.c (aligned_alloc):
* tests/test-calloc-gnu.c (calloc):
* tests/test-free.c (free):
* tests/test-malloc-gnu.c (malloc):
* tests/test-reallocarray.c (reallocarray):
Test indirectly, by calling through a volatile pointer.
* tests/test-aligned-malloc.c, tests/test-aligned_alloc.c:
* tests/test-calloc-gnu.c, tests/test-calloc-posix.c:
* tests/test-free.c, tests/test-malloc-gnu.c:
* tests/test-malloc-posix.c, tests/test-realloc-posix.c:
* tests/test-reallocarray.c:
(main) Don’t bother making data pointers olatile, as it’s ineffective.
* tests/test-calloc-gnu.c (identity):
* tests/test-free.c (get_errno, get_errno_func):
Remove; all uses removed.

5 months agoaligned_alloc: Fix test failures on macOS, Solaris (regr. 2024-10-30).
Bruno Haible [Mon, 4 Nov 2024 16:50:09 +0000 (17:50 +0100)]
aligned_alloc: Fix test failures on macOS, Solaris (regr. 2024-10-30).

* m4/aligned_alloc.m4 (gl_FUNC_ALIGNED_ALLOC): Check for the Solaris
bug. Let the test program return a bit mask. Update cross-compilation
guesses.
* lib/aligned_alloc.c: Include <errno.h>.
(aligned_alloc): Fail if the alignment is not a power of 2. Work around
the Solaris bug.
* modules/aligned_alloc (Depends-on): Add malloc-posix.
* doc/posix-functions/aligned_alloc.texi: Mention the Solaris bug.

6 months agotests: Add comments.
Bruno Haible [Mon, 4 Nov 2024 12:49:22 +0000 (13:49 +0100)]
tests: Add comments.

* tests/test-aligned_alloc.c (main): Clarify that we test a zero size.
* tests/test-posix_memalign.c (main): Likewise.

6 months agomalloc, calloc, realloc tests: Work around clang optimization bug.
Bruno Haible [Mon, 4 Nov 2024 10:47:23 +0000 (11:47 +0100)]
malloc, calloc, realloc tests: Work around clang optimization bug.

* tests/test-malloc-posix.c (my_malloc): New variable.
* tests/test-calloc-posix.c (my_calloc): New variable.
* tests/test-realloc-posix.c (my_realloc): New variable.

6 months agocrc: Fix build rules with Automake's option 'subdir-objects'.
Bruno Haible [Sun, 3 Nov 2024 20:18:29 +0000 (21:18 +0100)]
crc: Fix build rules with Automake's option 'subdir-objects'.

Reported by Pádraig Brady in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-11/msg00011.html>.

* build-aux/prefix-gnulib-mk: Add comments.
(usage): Mark this usage as deprecated.
* modules/crc (Makefile.am): Use %reldir%. Write $(srcdir)/. instead of
$(srcdir).

6 months agoselect: Document a Haiku bug.
Bruno Haible [Fri, 1 Nov 2024 22:04:06 +0000 (23:04 +0100)]
select: Document a Haiku bug.

* doc/posix-functions/select.texi: Mention a Haiku bug.

6 months agoeealloc: Revert last change.
Bruno Haible [Fri, 1 Nov 2024 12:44:12 +0000 (13:44 +0100)]
eealloc: Revert last change.

* m4/eealloc.m4 (gl_EEMALLOC): Invoke _AC_FUNC_MALLOC_IF, not
gl_CHECK_MALLOC_POSIX.

6 months agorealloc-posix: Fix test failure on AIX (regression 2024-10-27).
Bruno Haible [Fri, 1 Nov 2024 12:26:40 +0000 (13:26 +0100)]
realloc-posix: Fix test failure on AIX (regression 2024-10-27).

* m4/realloc.m4 (gl_FUNC_REALLOC_0_NONNULL): New macro.
* modules/realloc-posix (configure.ac): Invoke it.

6 months agoeealloc: Use the same cross-compilation guess as malloc-posix.
Bruno Haible [Fri, 1 Nov 2024 11:28:05 +0000 (12:28 +0100)]
eealloc: Use the same cross-compilation guess as malloc-posix.

* m4/eealloc.m4 (gl_EEMALLOC): Invoke gl_CHECK_MALLOC_POSIX, not
_AC_FUNC_MALLOC_IF.
* modules/malloca (Files): Add m4/malloc.m4.
* modules/regex (Files): Likewise.

6 months agoImprove log output of an Autoconf test.
Bruno Haible [Fri, 1 Nov 2024 11:25:22 +0000 (12:25 +0100)]
Improve log output of an Autoconf test.

* m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): On native Windows, report
"guessing yes/no".
(gl_FUNC_MALLOC_POSIX): Update.
* m4/strdup.m4 (gl_FUNC_STRDUP_POSIX): Likewise.

6 months agomalloc, realloc: fix $3 bug
Paul Eggert [Fri, 1 Nov 2024 02:22:22 +0000 (19:22 -0700)]
malloc, realloc: fix $3 bug

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2024-10/msg00284.html
* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
Sync from bleeding-edge Autoconf again.

6 months agocrc: Support generating the tables also when cross-compiling.
Bruno Haible [Thu, 31 Oct 2024 23:17:20 +0000 (00:17 +0100)]
crc: Support generating the tables also when cross-compiling.

* m4/build-cc.m4: New file.
* modules/crc (Files): Add it.
(configure.ac): Invoke gl_BUILD_CC. Don't set GL_CROSS_COMPILING.
(Makefile.am): Use $(BUILD_CC) etc. instead of $(CC) etc.

6 months agomalloc-posix, realloc-posix: Fix incorrect expansion of AC_FUNC_MALLOC.
Bruno Haible [Thu, 31 Oct 2024 21:11:22 +0000 (22:11 +0100)]
malloc-posix, realloc-posix: Fix incorrect expansion of AC_FUNC_MALLOC.

* m4/malloc.m4 (_AC_FUNC_MALLOC_IF): Handle the case of a missing third
argument.
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF): Likewise.

6 months agomalloc-gnu, eealloc: Make code more future-proof.
Bruno Haible [Thu, 31 Oct 2024 21:04:42 +0000 (22:04 +0100)]
malloc-gnu, eealloc: Make code more future-proof.

* m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Protect evaluation of
$gl_cross_guess_normal.
* m4/eealloc.m4 (gl_EEMALLOC, gl_EEREALLOC): Likewise.