Akim Demaille [Tue, 2 Oct 2018 04:19:19 +0000 (06:19 +0200)]
timevar: rely on gnulib modules for time portability.
* modules/timevar (Depends-on): Add sys_time, sys_times, and times.
* m4/timevar.m4: Don't check for clock_t and struct tms,
guaranteed by gnulib.
* lib/timevar.h: Use extern "C" protection.
Include <stdio.h> for FILE.
* lib/timevar.c: Include sys/time.h, sys/times.h unconditionally,
they are guaranteed by gnulib.
Remove uses of clock as (now useless) fallback.
Bruno Haible [Thu, 4 Oct 2018 22:22:57 +0000 (00:22 +0200)]
fcntl: Make it possible to namespace the defined symbol.
* lib/fcntl.c (fcntl): Undefine only after the replacement function has
been defined.
(fcntl): Renamed from rpl_fcntl.
(rpl_fcntl_DUPFD, rpl_fcntl_DUPFD_CLOEXEC): New functions, extracted
from fcntl.
(klibc_fcntl): Move to the end of the compilation unit.
Tom Tromey [Mon, 1 Oct 2018 20:57:45 +0000 (14:57 -0600)]
mkostemp, mkostemps: Fix compilation error in C++ mode on Mac OS X.
Attempting to use the mkostemp module in gdb caused a build failure
when using the C++ namespace feature, because mkostemp was not
declared. On OS X, mkostemp is declared in unistd.h, so this patch
extends the existing special case in stdlib.in.h to cover mkostemp and
mkostemps.
* lib/stdlib.in.h: Include <unistd.h> for mkostemp and mkostemps
on OS X.
hmac-sha512: fix hash for keys > blocksize (128 bytes)
* lib/hmac-sha512.c (hmac_sha512): Set the computed/shortened
key length to that output by sha512, not the blocksize.
Otherwise uninitialized data from the stack
is used when computing the hash.
* tests/test-hmac-sha512.c: Add a shortened key test case.
Reported at https://github.com/coreutils/gnulib/pull/5
Bruno Haible [Sun, 30 Sep 2018 17:27:56 +0000 (19:27 +0200)]
timevar: Include documentation in gnulib manual.
* doc/timevar.texi: Change node and section name to 'Profiling of
program phases'.
In the code snippets, tweak the #includes and use GNU coding style.
* doc/gnulib.texi: Include timevar.texi.
Paul Eggert [Wed, 19 Sep 2018 02:05:26 +0000 (19:05 -0700)]
dfa: tweak allocation performance
* lib/dfa.c (merge_nfa_state, dfaoptimize):
Prefer ptrdiff_t for indexes some more.
Use char for flags, as it’s wide enough.
Allocate queue and flags together, with one malloc call.
No need to use xnmalloc since the multiplication and
addition cannot overflow (it’s already been checked by
earlier allocation). Prefer memset to open-coding.
Paul Eggert [Wed, 19 Sep 2018 01:24:27 +0000 (18:24 -0700)]
dfa: prune states as we go
* lib/dfa.c (prune): Remove.
(merge_nfa_state): Prune as we go instead of at the end.
Prefer ptrdiff_t for indexes, as this helps the compiler a bit.
Simplify constraint checking a bit.
Paul Eggert [Tue, 18 Sep 2018 22:25:51 +0000 (15:25 -0700)]
dfa: reorder enum for efficiency
* lib/dfa.c (END): Now -1 again. Reorder other elements
of the enumeration to make it easier for GCC to generate
efficient code by using fewer comparisons to check for
ranges of values.
(atom): Take advantage of the reordering.
Even when similar states exist in alternation, the DFA treats them
as separate items, which may complicate the transition in NFA and
cause slowdown. This change assembles the states into one. For
example, ab|ac is changed into a(b|c). This change speeds-up
matching for many branched patterns. For example, grep speeds up
more than 30× in:
seq 10000 | sed 's/$/ abcdefghijklmnopqrstuvwxyz/; s/$/./' >in
time -p env LC_ALL=C grep -vf in in
* lib/dfa.c (prune): New function.
(merge_nfa_state): New function. It merges similar NFA states.
(dfaoptimize): New function. It seeks merged and removed nodes.
(dfaanalyze): Call new function.
(dfautf8noss): Change name from dfaoptimize because of addition of new
function.
(dfacomp): Update caller.
Simplifying the initial state enables easier optimization of the NFA.
* lib/dfa.c (enum token): Add new element BEG.
(prtok): Adjust due to adding element BEG.
(dfaparse): Put BEG at a head of tokens.
(state_index): Adjust due to adding element BEG.
(dfaanalyze): Concatenate BEG to other tokens, and simplify to
build initial state.
(dfamust): Adjust due to adding element BEG. DFAMUST ignores it.
Bruno Haible [Tue, 18 Sep 2018 20:58:23 +0000 (22:58 +0200)]
file-has-acl: Fix test failure on Cygwin 2.9.
* m4/acl.m4 (gl_FUNC_ACL): Update comments regarding Cygwin.
* lib/acl-internal.h: Likewise.
(HAVE_ACL_EXTENDED_FILE): Undefine on Cygwin.
* lib/acl-internal.c: Update comments regarding Cygwin.
* lib/acl_entries.c: Likewise.
* lib/file-has-acl.c: Likewise.
(file_has_acl): For Cygwin, use a different way to determine whether
the "default" ACL of a directory is nontrivial.
* lib/get-permissions.c: Update comments regarding Cygwin.
* lib/set-permissions.c: Likewise.
Paul Eggert [Tue, 18 Sep 2018 19:19:02 +0000 (12:19 -0700)]
doc: OS X 10.11 lacked ns time functions
According to <https://github.com/zeromq/libzmq/issues/2175>,
nanosecond-resolution timestamp functions were introduced
in macOS 10.12, so document the last version (OS X 10.11)
where they were absent.
Paul Eggert [Sun, 16 Sep 2018 21:41:36 +0000 (14:41 -0700)]
timespec: new function current_timespec
* lib/gettime.c (gettime): Prefer clock_gettime to nanotime,
and don’t worry about it failing on a CLOCK_REALTIME arg.
POSIX requires it to succeed and I don’t know of any
counterexamples where the fallbacks would work.
(current_timespec): New function, taken from Emacs. It is more
convenient than gettime, and can help register allocation.
* lib/timespec.h: Include arg-nonnull.h.
(current_timespec): New declaration.
(gettime, settime): Declare args to be nonnull.
* modules/timespec (Depends-on): Add snippet/arg-nonnull.
Bruno Haible [Sun, 16 Sep 2018 17:12:44 +0000 (19:12 +0200)]
setlocale: Improve locale handling on macOS 10.12 or newer.
* lib/setlocale.c: Include header files for CoreFoundation. Declare
gl_locale_name_canonicalize.
(libintl_setlocale): Try harder to set a locale for categories LC_CTYPE
and LC_MESSAGES.
* m4/setlocale.m4 (gl_PREREQ_SETLOCALE): Add comment.
Bruno Haible [Sun, 16 Sep 2018 01:15:54 +0000 (03:15 +0200)]
setlocale: Improve support for locales not supported by libc.
Reported by Dapeng Gao <peter@dpgao.cc> at
<https://savannah.gnu.org/bugs/?54479>.
* gettext-runtime/intl/setlocale.c: Include <stdio.h>.
(libintl_setlocale): Use a more error-tolerant strategy when the locale
to be set is not supported by libc: Emit warnings instead of failing.
Bruno Haible [Sat, 15 Sep 2018 10:04:03 +0000 (12:04 +0200)]
strstr, strcasestr: Add workaround against glibc-2.28 bug.
Reported by Michael Brunnbauer via Siddhesh Poyarekar and Eric Blake.
* m4/strstr.m4 (gl_FUNC_STRSTR_SIMPLE): Set
gl_cv_func_strstr_works_always to 'no' on glibc 2.28.
* m4/strcasestr.m4 (gl_FUNC_STRCASESTR_SIMPLE): Set
gl_cv_func_strcasestr_works_always to 'no' on glibc 2.28.
* doc/posix-functions/strstr.texi: Document the glibc 2.28 bug.
* doc/glibc-functions/strcasestr.texi: Likewise.
Paul Eggert [Tue, 11 Sep 2018 01:42:25 +0000 (18:42 -0700)]
timespec: fix resolution confusion
In normal usage, clock resolution is given in seconds, but the
code was mistakenly using inverse seconds and calling it
“resolution”. Fix this, partly by renaming two identifiers.
The old names will be kept for a bit, to ease transition.
* lib/timespec.h (TIMESPEC_HZ, LOG10_TIMESPEC_HZ):
New constants, replacing TIMESPEC_RESOLUTION and
LOG10_TIMESPEC_RESOLUTION, which are now obsolescent.
All uses changed.
Bruno Haible [Fri, 7 Sep 2018 21:38:53 +0000 (23:38 +0200)]
posix_spawn_file_actions_addchdir: Add tests.
* tests/test-posix_spawn_file_actions_addchdir.c: New file.
* tests/test-posix_spawn4.c: New file.
* modules/posix_spawn_file_actions_addchdir-tests: New file.
Bruno Haible [Thu, 6 Sep 2018 20:44:01 +0000 (22:44 +0200)]
stddef: Override max_align_t on NetBSD 8.0/x86.
* m4/stddef_h.m4 (gl_STDDEF_H): When testing for max_align_t, test also
the value of __alignof__ (max_align_t).
* doc/posix-headers/stddef.texi: Mention the issue.
Bruno Haible [Thu, 6 Sep 2018 12:28:38 +0000 (14:28 +0200)]
limits-h: Provide numerical limits macros.
* lib/limits.in.h (LLONG_MIN, LLONG_MAX, ULLONG_MAX): Define also for
IRIX and for GCC.
(WORD_BIT, LONG_BIT): Define.
* m4/limits-h.m4 (gl_LIMITS_H): Set LIMITS_H to non-empty also when
<limits.h> does not define LLONG_MAX or WORD_BIT.
* tests/test-limits-h.c (TYPE_SIGNED, TYPE_WIDTH, TYPE_MINIMUM,
TYPE_MAXIMUM): New macros, from intprops.h.
Add tests for CHAR_BIT, WORD_BIT, LONG_BIT, <type>_MIN, and <type>_MAX.
* doc/posix-headers/limits.texi: Document what the 'limits-h' module
provides.
Reported by Frank Busse <f.busse@imperial.ac.uk> in
<https://lists.gnu.org/archive/html/bug-gnulib/2018-09/msg00018.html>.
* lib/fcntl.c (rpl_fcntl): For actions that don't take an argument,
don't consume an argument. For actions that take an 'int' argument,
consume an 'int' argument.
Bruno Haible [Mon, 3 Sep 2018 19:19:16 +0000 (21:19 +0200)]
gnulib-tool: Fix build order when $testsbase is a subdir of $sourcebase.
Reported by Antoine Luong <antoine.luong@c-s.fr> in
<https://lists.gnu.org/archive/html/bug-gnulib/2018-09/msg00008.html>.
* gnulib-tool (func_import): For the tests, set a dotfirst flag.
(func_emit_lib_Makefile_am): Consider the dotfirst flag.
(func_emit_tests_Makefile_am): Don't consider the dotfirst flag.
Paul Eggert [Sun, 2 Sep 2018 09:53:31 +0000 (02:53 -0700)]
mktime: fix unlikely race+overflow bug
Problem reported by Alexandre Oliva in:
https://sourceware.org/bugzilla/show_bug.cgi?id=16346
* lib/mktime.c (__mktime_internal): Access *OFFSET only once,
to avoid an unlikely race if the compiler delays a load and
if this cascades into a signed integer overflow.
Paul Eggert [Sat, 1 Sep 2018 01:02:48 +0000 (18:02 -0700)]
mktime, timegm: simplify glibc time64_t
* lib/mktime.c, lib/timegm.c (mktime_offset_t) [_LIBC]:
Now long int, not time_t, since long int is the longstanding type
for this in glibc and there is no need to change it even if time_t
becomes 64 bits - even int would do, though this would be a change
to the glibc generated code. When this change is merged into
glibc, it should simplify the time_t vs time64_t situation.
Paul Eggert [Sat, 1 Sep 2018 01:02:48 +0000 (18:02 -0700)]
mktime, timegm: simplify merge to glibc
Move code around to make a merge to glibc easier to audit.
This should not change behavior.
* lib/mktime.c: Include more standard files unconditionally.
(NEED_MKTIME_INTERNAL, NEED_MKTIME_WINDOWS)
(NEED_MKTIME_WORKING): Give default values to pacify -Wundef,
which glibc uses. Default NEED_MKTIME_WORKING to DEBUG_MKTIME, to
simplify later conditionals; default the others to zero. In uses
of these conditionals, explicitly spell out how _LIBC affects
things, so it’s easier to review from a glibc viewpoint.
(my_tzset, __tzset) [!_LIBC]: New function and macro, to better
compartmentalize tzset issues. Move system-dependent tzsettish
code here from mktime.
(mktime): Move tzsettish code to my_tzset, and move
localtime_offset to within mktime so that it doesn’t
need a separate ifdef.
* lib/mktime-internal.h (__gmtime_r, __localtime_r, __mktime_internal):
Move these macros here from lib/mktime.c and lib/gmtime.c.
Paul Eggert [Tue, 28 Aug 2018 01:31:44 +0000 (18:31 -0700)]
intprops: avoid evaluation of some expressions
This makes EXPR_SIGNED (e) easier to use, as it no longer
evaluates the expression E. Formerly, E was required to be free
of side effects.
* lib/intprops.h (_GL_INT_CONVERT, _GL_INT_NEGATE_CONVERT)
(EXPR_SIGNED, TYPE_WIDTH, _GL_INT_MINIMUM, _GL_INT_MAXIMUM)
(_GL_SIGNED_INT_MAXIMUM): Do not evaluate the expression arg.
Bruno Haible [Sun, 19 Aug 2018 12:14:17 +0000 (14:14 +0200)]
getpass: Move declaration to <unistd.h>.
* lib/unistd.in.h (getpass): New declaration.
* lib/getpass.h: Replace with a stub that just includes <unistd.h>.
* m4/getpass.m4 (gl_FUNC_GETPASS): Declare through AC_DEFUN_ONCE.
Require gl_UNISTD_H_DEFAULTS. Don't test whether getpass is declared.
(gl_FUNC_GETPASS_GNU): Require gl_UNISTD_H_DEFAULTS and gl_FUNC_GETPASS.
On glibc systems, don't set REPLACE_GETPASS to 1.
* modules/getpass (Depends-on): Add 'unistd'.
(configure.ac): Test also REPLACE_GETPASS. Define a module indicator.
(Include): Specify <unistd.h> instead of "getpass.h".
* modules/getpass-gnu (Depends-on): Merely depend on 'getpass'.
(configure.ac): Sync with the configure.ac section of modules/getpass.
(Include): Specify <unistd.h> instead of "getpass.h".
* m4/unistd_h.m4 (gl_UNISTD_H): Test whether getpass is declared.
(gl_UNISTD_H_DEFAULTS): Initialize GNULIB_GETPASS, HAVE_GETPASS,
REPLACE_GETPASS.
* modules/unistd (Makefile.am): Substitute GNULIB_GETPASS, HAVE_GETPASS,
REPLACE_GETPASS.
* tests/test-unistd-c++.cc: Test also the declaration of 'getpass'.
* doc/glibc-functions/getpass.texi: A length limit exists also on uClibc
and musl.
* NEWS: Mention the change.
Bruno Haible [Sat, 18 Aug 2018 21:26:06 +0000 (23:26 +0200)]
Avoid -Wcast-function-type warnings from casts after GetProcAddress.
Reported by Andy Moreton <andrewjmoreton@gmail.com> in
<https://lists.gnu.org/archive/html/emacs-devel/2018-08/msg00468.html>.
Solution proposed by Eli Zaretskii.
Paul Eggert [Sat, 18 Aug 2018 07:54:35 +0000 (00:54 -0700)]
glob-h: always build glob.h
This works around a problem reported by Reuben Thomas in:
http://lists.gnu.org/r/bug-gnulib/2018-08/msg00079.html
This workaround always builds glob.h, even on platforms that
do not need it; perhaps this could be improved someday.
* m4/glob_h.m4 (gl_GLOB_H): Do not set or use GLOB_H, since glob.h
is always created now.
* modules/glob-h (BUILT_SOURCES, glob.h): Always build glob.h.