Paul Eggert [Sat, 9 Jan 2021 01:17:32 +0000 (17:17 -0800)]
regex: stop using alloca
* lib/regex_internal.h: Do not include <alloca.h> or define
__libc_use_alloca or alloca. Patch written by Adhemerval Zanella:
https://sourceware.org/pipermail/libc-alpha/2021-January/121374.html
* modules/regex (Depends-on): Remove alloca-opt.
Paul Eggert [Fri, 8 Jan 2021 22:22:15 +0000 (14:22 -0800)]
regexec: remove alloca usage in build_trtable
Prompted by this different change proposed by Adhemerval Zanella:
https://sourceware.org/pipermail/libc-alpha/2021-January/121373.html
* lib/regexec.c (build_trtable): Prevent inlining,
so that it doesn’t bloat the caller’s stack.
Use auto variables instead of alloca/malloc.
After these changes, build_trtable’s total stack allocation is
only 20 KiB on a 64-bit machine, and this is less than glibc’s 64
KiB cutoff so there’s little point to using alloca to shrink it.
Although Gnulib traditionally has used a 4 KiB cutoff, going to 20
KiB here should not be a significant problem in practice;
Gnulib-using packages concerned about overflow of tiny stacks can
compile with something like gcc -fstack-clash-protection.
* config/srclist.txt: Comment out regexec.c for now.
Paul Eggert [Fri, 8 Jan 2021 20:00:09 +0000 (12:00 -0800)]
regex: remove alloca usage on regex set_regs
Derived from this patch by Adhemerval Zanella:
https://sourceware.org/pipermail/libc-alpha/2021-January/121372.html
* lib/regex_internal.h: Include dynarray.h, for Gnulib.
* lib/regexec.c (DYNARRAY_STRUCT, DYNARRAY_ELEMENT)
(DYNARRAY_PREFIX): New macros.
Include malloc/dynarray-skeleton.c.
(set_regs): Use dynarray rather than alloca.
* modules/regex (Depends-on): Add dynarray.
Paul Eggert [Fri, 8 Jan 2021 19:44:19 +0000 (11:44 -0800)]
dynarray: new module
* config/srclist.txt: Mention the new files.
* lib/cdefs.h (__attribute_maybe_unused__): New macro,
like Gnulib’s _GL_ATTRIBUTE_MAYBE_UNUSED but with glibc
naming conventions.
* lib/libc-config.h: Use it instead of __glibc_likely.
* lib/dynarray.h, modules/dynarray: New files.
* lib/malloc/dynarray-skeleton.c, lib/malloc/dynarray.h:
* lib/malloc/dynarray_at_failure.c:
* lib/malloc/dynarray_emplace_enlarge.c:
* lib/malloc/dynarray_finalize.c, lib/malloc/dynarray_resize.c:
* lib/malloc/dynarray_resize_clear.c, modules/dynarray:
New files, from glibc with the following changes needed for
portability to compilers that are not recent-enough GCC.
* lib/malloc/dynarray_at_failure.c: Include stdlib.h, for abort.
(__libc_dynarray_at_failure) [!_LIBC]: Simply abort.
* lib/malloc/dynarray_emplace_enlarge.c:
* lib/malloc/dynarray_resize.c:
Include intprops.h, and use INT_MULTIPLY_WRAPV instead
of __builtin_mul_overflow.
* lib/malloc/dynarray.h (__libc_dynarray_at_failure):
Use _Noreturn instead of __attribute__ ((noreturn)).
* lib/malloc/dynarray_resize_clear.c: Do not include stdlib.h;
it’s not needed.
(__libc_dynarray_resize_clear): Do not do arithmetic on void *.
* lib/malloc/dynarray-skeleton.c (struct DYNARRAY_STRUCT):
Do not use anonymous unions, as they are not in C99. All uses changed.
Use __nonnull (X) instead of __attribute__ ((nonnull X)),
and __attribute_maybe_unused__ instead of __attribute__ ((unused)).
Paul Eggert [Wed, 6 Jan 2021 18:02:33 +0000 (10:02 -0800)]
libc-config: simplify clang __has_* macros
cdefs.h sometimes used names like __glibc_clang_has_attribute and
sometimes __glibc_has_attribute. There is no need in glibc or
Gnulib to distinguish clang from other compilers here, so be
consistent and use the simpler names.
* lib/cdefs.h (__glibc_has_builtin, __glibc_has_extension):
Rename from __glibc_clang_has_builtin, __glibc_clang_has_extension.
All uses changed.
(__glibc_clang_has_attribute): Remove. All uses replaced
by __glibc_has_attribute.
* lib/libc-config.h [!__glibc_likely]: Undef them here too.
This fixes a problem where __glibc_has_attribute was not undeffed.
Bruno Haible [Wed, 6 Jan 2021 05:16:22 +0000 (06:16 +0100)]
utimens, utimensat, fdutimensat: Avoid test failures on AIX 7.2.
* lib/utimecmp.c (utimecmpat): On AIX, declare equality when the two
times differ by less than 0.01 seconds.
* tests/test-futimens.h (test_futimens): Pass UTIMECMP_TRUNCATE_SOURCE
flag.
Bruno Haible [Wed, 6 Jan 2021 01:08:41 +0000 (02:08 +0100)]
utimensat: Work around trailing slash bug in utimensat() on AIX 7.2.
* m4/utimensat.m4 (gl_FUNC_UTIMENSAT): Require AC_CANONICAL_HOST. Add a
test for trailing slash handling. Improve cross-compilation guesses.
Conditionally define HAVE_NEARLY_WORKING_UTIMENSAT.
* lib/utimensat.c (rpl_utimensat): Add alternative implementation when
HAVE_NEARLY_WORKING_UTIMENSAT is defined.
* lib/utimens.c: Use the overridden utimensat when
HAVE_NEARLY_WORKING_UTIMENSAT is defined.
* doc/posix-functions/utimensat.texi: Mention the AIX bug.
Bruno Haible [Tue, 5 Jan 2021 21:39:48 +0000 (22:39 +0100)]
ptsname_r, ptsname: Avoid test failures on AIX 7.2.
* tests/test-ptsname_r.c (main): On AIX, set a 20-seconds timer.
* tests/test-ptsname.c (main): Likewise. On AIX, open a pty through
/dev/ptc and don't test the BSD ptys.
Paul Eggert [Tue, 5 Jan 2021 21:12:39 +0000 (13:12 -0800)]
libc-config: merge from glibc
Use a better way of keeping glibc <sys/cdefs.h> and gnulib
lib/cdefs.h mostly in sync, by using lib/cdefs.h only on platforms
where <sys/cdefs.h> does not work well enough for Gnulib.
* lib/cdefs.h: Go back to using _SYS_CDEFS_H rather than
_GL_DEFS_H as an include guard.
(__THROW, __THROWNL, __NTH, __NTHNL):
Define to noexcept for C++11 and later.
(__glibc_objsize, __glibc_objsize0): New, for _FORTIFY_SOURCE=3.
(__warndecl): Remove.
(__attribute_copy__): New macro, for GCC 9 support.
(__LDBL_REDIR, __LDBL_REDIR_DECL, __LDBL_REDIR1)
(__LDBL_REDIR1_DECL, __LDBL_REDIR1_NTH, __REDIRECT_NTH_LDBL)
(__REDIRECT_LDBL, __LDBL_REDIR_NTH):
Redirections for IEEE long double on powerpc64le.
(__LDBL_REDIR2_DECL): New macro.
(__attr_access): New macro, for GCC 10 bounds checking.
(__attribute_returns_twice__): New macro, for setjmp etc.
* lib/libc-config.h: Include <cdefs.h> only if __glibc_likely is
undefined. The following changes apply only if __glibc_likely
is not defined.
(__LDBL_REDIR2_DECL, __attr_access, __attribute_returns_twice__)
(__glibc_clang_has_attribute, __glibc_clang_has_extension)
(__glibc_objsize, __glibc_objsize0):
Undef these new (or newer) <cdefs.h> macros.
(__P, __PMT, __always_inline): Do not undef, since cdefs.h does that.
(__glibc_likely): Do not undef, since this is inside
ifndef __glibc_likely.
(__warndecl): Do not undef; no longer defined.
Paul Eggert [Tue, 5 Jan 2021 20:03:00 +0000 (12:03 -0800)]
maint: note syncs to glibc
* config/srclist.txt: filename.h, idx.h, scratch_buffer.h and
scratch_buffer_dupfree.c are now identical to glibc. Add
commentary about some other syncs we’d like.
Bruno Haible [Tue, 5 Jan 2021 06:55:01 +0000 (07:55 +0100)]
truncate: Work around trailing slash bug in truncate() on AIX 7.2.
* m4/truncate.m4 (gl_FUNC_TRUNCATE): Add a test whether truncate
rejects trailing slashes. Set REPLACE_TRUNCATE and define
TRUNCATE_TRAILING_SLASH_BUG if not.
* lib/truncate.c (orig_truncate): New function.
(truncate): Add alternative implementation when
TRUNCATE_TRAILING_SLASH_BUG is defined.
* modules/truncate (Depends-on): Add sys_stat, stat.
Bruno Haible [Mon, 4 Jan 2021 21:39:23 +0000 (22:39 +0100)]
nstrftime, time_rz: Avoid using an obsolete Autoconf macro.
Reported by Mike Gran <spk121@yahoo.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00067.html>.
* lib/time-internal.h: Test HAVE_STRUCT_TM_TM_ZONE, not HAVE_TM_ZONE.
* lib/time_rz.c: Likewise.
* lib/nstrftime.c: Set and test HAVE_STRUCT_TM_TM_ZONE, not
HAVE_TM_ZONE.
* m4/nstrftime.m4 (gl_FUNC_GNU_STRFTIME): Update comments.
Bruno Haible [Mon, 4 Jan 2021 21:27:47 +0000 (22:27 +0100)]
expm1f-ieee: Work around AIX 7.2 bug.
* m4/expm1f.m4 (gl_FUNC_EXPM1F): Initialize gl_expm1f_required. If
module 'expm1f-ieee' is in use, check whether expm1f works according to
IEEE.
* m4/expm1f-ieee.m4: New file.
* modules/expm1f-ieee (Files): Add it.
(Depends-on): Update conditions.
(configure.ac): Invoke gl_FUNC_EXPM1F_IEEE.
* doc/posix-functions/expm1f.texi: Mention the AIX bug.
Bruno Haible [Mon, 4 Jan 2021 07:02:18 +0000 (08:02 +0100)]
ffsl, ffsll: Work around AIX 7.2 problem.
* lib/string.in.h: On AIX, include <strings.h> for the declarations of
ffsl and ffsll.
* doc/glibc-functions/ffsl.texi: Document the AIX 7.2 problem.
* doc/glibc-functions/ffsll.texi: Likewise.
Bruno Haible [Sun, 3 Jan 2021 12:38:03 +0000 (13:38 +0100)]
stddef: Override wrong max_align_t on AIX 7 with xlc in 64-bit mode.
* m4/stddef_h.m4 (gl_STDDEF_H): Make check for good max_align_t
stricter: Add tests for offsetof-based alignof.
* lib/stddef.in.h (max_align_t): Override on AIX in 64-bit mode.
* doc/posix-headers/stddef.texi: Document the AIX max_align_t bug.
Bruno Haible [Sun, 3 Jan 2021 01:14:16 +0000 (02:14 +0100)]
valgrind-tests: Disable valgrind if it would cause all tests to fail.
Suggested by Simon Josefsson <simon@josefsson.org> in
<https://lists.gnu.org/archive/html/help-gsasl/2021-01/msg00004.html>.
* m4/valgrind-tests.m4 (gl_VALGRIND_TESTS): Test $VALGRIND on an
executable produced by the current compiler. Set VALGRIND to empty if it
does not work. Don't set VALGRIND to empty if it merely does not accept
the --error-exitcode=1 --leak-check=full options.
Bruno Haible [Sat, 2 Jan 2021 18:31:45 +0000 (19:31 +0100)]
utimensat: Fix test failures on macOS 10.13.
* lib/utimensat.c: Include <string.h>, <sys/stat.h>.
(rpl_utimensat): Check against invalid tv_nsec values. Before calling
utimensat, recognize a filename ending in a slash that does not point
to a directory.
Bruno Haible [Sat, 2 Jan 2021 17:57:10 +0000 (18:57 +0100)]
utimens: Avoid test failures on macOS 10.13.
Reported by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
* tests/test-utimens-common.h (check_ctime): Define to -1 on macOS.
* tests/test-utimens.h (test_utimens): Don't expect a ctime change when
only the atime is requested to change.
* tests/test-futimens.h (test_futimens): Likewise.
* tests/test-lutimens.h (test_lutimens): Likewise.
Bruno Haible [Sat, 2 Jan 2021 15:54:21 +0000 (16:54 +0100)]
renameatu: Fix test failures on macOS.
Reported by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
* lib/renameatu.c (renameatu): Don't call renameatx_np right away.
Instead, treat it as a variant of renameat, with all possible bugs that
renameat might have.
Bruno Haible [Fri, 1 Jan 2021 23:14:05 +0000 (00:14 +0100)]
time: Define TIME_UTC.
* lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros.
* m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC.
* modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC.
* tests/test-time.c: Check that TIME_UTC is defined and a positive
integer.
* doc/posix-headers/time.texi: Mention TIME_UTC.
* lib/canonicalize-lgpl.c, lib/canonicalize.c (NARROW_ADDRESSES):
Remove, and remove all uses, as the optimization is arguably not
worth the extra complexity. Suggested by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121203.html
Paul Eggert [Fri, 1 Jan 2021 17:27:54 +0000 (09:27 -0800)]
libc-config: port to Sun C 5.9
* lib/libc-config.h (libc_hidden_proto): Omit ", ..." in macro
definition. It’s not needed for Gnulib and elicits a diagnostic
from Sun C 5.9 Patch 124867-12 2009/11/22.
Bruno Haible [Fri, 1 Jan 2021 14:00:48 +0000 (15:00 +0100)]
quotearg tests: Avoid test failures on Solaris 11.
* modules/quotearg-tests (Makefile.am): Set host_os in
TESTS_ENVIRONMENT.
* tests/test-quotearg.sh: On Solaris 11 systems, make a copy of the fr/
directory that contains the .mo file.
Paul Eggert [Thu, 31 Dec 2020 21:35:53 +0000 (13:35 -0800)]
fnmatch: merge from glibc + proposal
This merges the change proposed by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121212.html
which fixes a Gnulib bug that led to a failed assert.
* lib/fnmatch_loop.c (EXT): Use signed level, not unsigned, and
check that it stays nonnegative. Use __flexarr instead of
FLEXIBLE_ARRAY_MEMBER, to port better to glibc.
* tests/test-fnmatch.c (main): New test cases, taken from glibc.
Bruno Haible [Thu, 31 Dec 2020 21:16:52 +0000 (22:16 +0100)]
malloc-h: New module.
* lib/malloc.in.h: New file.
* m4/malloc_h.m4: New file.
* modules/malloc-h: New file.
* doc/glibc-headers/malloc.texi: New file.
* doc/gnulib.texi (Glibc Header File Substitutes): Include it.
Jim Meyering [Wed, 30 Dec 2020 04:00:36 +0000 (20:00 -0800)]
regex-tests: tweak to avoid a clang-10 warning
* tests/test-regex.c: Compare with explicit zero, rather than
as boolean to avoid this from clang-10:
test-regex.c:315:9: error: converting the result of '<<' to a \
boolean always evaluates to true \
[-Werror,-Wtautological-constant-compare]
if (! REG_STARTEND)
Jim Meyering [Wed, 30 Dec 2020 03:34:55 +0000 (19:34 -0800)]
hash: add casts-to-float to avoid clang-10 warnings
* lib/hash.c (compute_bucket_size): Cast SIZE_MAX to float
to avoid this warning from clang-10 (for use in grep):
hash.c:501:11: error: implicit conversion from 'unsigned long' \
to 'float' changes value from 18446744073709551615 to \ 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
if (SIZE_MAX <= new_candidate)
(hash_insert_if_absent): Likewise.
Paul Eggert [Wed, 30 Dec 2020 03:34:59 +0000 (19:34 -0800)]
canonicalize: fix size overflow treatment
This also has some minor cleanups.
* lib/canonicalize-lgpl.c, lib/canonicalize.c: No need to include
stddef.h, since the code no longer refers directly to ptrdiff_t.
* lib/canonicalize-lgpl.c (realpath_stk):
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Treat size overflow like other out-of-memory.
* lib/canonicalize.c: No need to include stdlib.h, since
the code no longer refers to stdlib.h functions (other
than those that canonicalize.h must declare).
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Do not bother terminating the string result on error.
Paul Eggert [Wed, 30 Dec 2020 01:08:11 +0000 (17:08 -0800)]
canonicalize: fix ptrdiff_t overflow bug
Problem reported by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121182.html
* lib/canonicalize-lgpl.c, lib/canonicalize.c:
Include intprops.h.
(NARROW_ADDRESSES): New constant.
* lib/canonicalize-lgpl.c (realpath_stk):m
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Work even if strlen (END) does not fit in idx_t, or if adding
N to it overflows.
* modules/canonicalize, modules/canonicalize-lgpl (Depends-on):
Add intprops.