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.
Bruno Haible [Tue, 14 Aug 2018 00:00:05 +0000 (02:00 +0200)]
fnmatch, fnmatch-gnu: Fix compilation error on Mac OS X.
Reported by Jeroen Meijer <jjgmeijer@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2018-08/msg00046.html>
and by Paul J. Lucas <paul@lucasmail.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2018-08/msg00069.html>.
* m4/fnmatch_h.m4 (gl_FNMATCH_H): Define through AC_DEFUN_ONCE.
(gl_FNMATCH_H_GNU): New macro.
* m4/fnmatch.m4 (gl_FUNC_FNMATCH_GNU): Require gl_FNMATCH_H_GNU.
Bruno Haible [Tue, 7 Aug 2018 08:54:41 +0000 (10:54 +0200)]
glob-h: Add tests.
* tests/test-glob-h.c: New file, partially based on tests/test-glob.c.
* tests/test-glob.c: Reorder #includes. Remove tests that are moved to
tests/test-glob-h.c.
* modules/glob-h-tests: New file.
* tests/test-glob-h-c++.cc: Renamed from tests/test-glob-c++.cc. Add
conditions.
* modules/glob-h-c++-tests: Renamed from modules/glob-c++-tests.
* modules/glob-tests (Depends-on): Remove glob-c++-tests.
Bruno Haible [Tue, 7 Aug 2018 08:43:06 +0000 (10:43 +0200)]
glob-h: New module.
* lib/glob.in.h: Use nearly the usual gnulib idioms for header file
replacements.
* lib/glob.c: Include <config.h>.
* m4/glob_h.m4: New file.
* m4/glob.m4 (gl_GLOB): Require gl_GLOB_H. Remove code that is moved to
glob_h.m4. Set HAVE_GLOB, REPLACE_GLOB, HAVE_GLOB_PATTERN_P,
REPLACE_GLOB_PATTERN_P as appropriate.
(gl_PREREQ_GLOB): Don't require AC_C_RESTRICT and
AC_USE_SYSTEM_EXTENSIONS, now done through module 'glob-h'.
* modules/glob-h: New file.
* modules/glob (Files): Remove lib/glob.in.h, lib/glob-libc.h.
(Dependencies): Add glob-h. Remove extensions, snippet/*, libc-config,
lstat, sys_stat. Change conditions.
(configure.ac): Test HAVE_GLOB, REPLACE_GLOB, HAVE_GLOB_PATTERN_P,
REPLACE_GLOB_PATTERN_P. Set module indicator.
(Makefile.am): Remove code that is moved to glob-h.
* doc/posix-headers/glob.texi: Mention the 'glob-h' module.
* modules/posixcheck (Depends-on): Add glob-h.
Bruno Haible [Tue, 7 Aug 2018 00:00:37 +0000 (02:00 +0200)]
Force generation of substitute .h file when C++ support is enabled.
* m4/ansi-c++.m4 (gl_ANSI_CXX): New macro.
* modules/ansi-c++-opt (configure.ac): Just require gl_ANSI_CXX.
* m4/fnmatch_h.m4 (gl_FNMATCH_H): If C++ support is enabled, set
FNMATCH_H to non-empty.
* m4/iconv_h.m4 (gl_ICONV_H_DEFAULTS): If C++ support is enabled, set
ICONV_H to non-empty.
* m4/monetary_h.m4 (gl_MONETARY_H_BODY): If C++ support is enabled, set
MONETARY_H to non-empty.
* m4/utime_h.m4 (gl_UTIME_H): If C++ support is enabled, set UTIME_H to
non-empty.
Bruno Haible [Mon, 6 Aug 2018 13:07:30 +0000 (15:07 +0200)]
fnmatch-h: Add tests.
* tests/test-fnmatch-h.c: New file.
* modules/fnmatch-h-tests: New file.
* tests/test-fnmatch-h-c++.cc: New file.
* modules/fnmatch-h-c++-tests: New file.
Bruno Haible [Mon, 6 Aug 2018 13:00:38 +0000 (15:00 +0200)]
fnmatch-h: New module.
* lib/fnmatch.in.h: Use the usual gnulib idioms for header file
replacements.
(FNM_*): Don't redefine if fnmatch exists and we are not overriding it.
(fnmatch): Use the usual gnulib idiom for function declarations. Enable
'posixcheck' warning.
* m4/fnmatch_h.m4: New file.
* m4/fnmatch.m4 (gl_FUNC_FNMATCH_POSIX): Require gl_FNMATCH_H. Remove
code that is moved to fnmatch_h.m4. When fnmatch does not exist, don't
bother testing whether it is working. Set HAVE_FNMATCH, REPLACE_FNMATCH
as appropriate.
* modules/fnmatch-h: New file.
* modules/fnmatch (Files): Remove lib/fnmatch.in.h.
(Dependencies): Add fnmatch-h. Remove extensions, snippet/*. Change
conditions.
(configure.ac): Test HAVE_FNMATCH and REPLACE_FNMATCH. Set module
indicator.
(Makefile.am): Remove code that is moved to fnmatch-h.
* modules/fnmatch-gnu (configure.ac): Test HAVE_FNMATCH and
REPLACE_FNMATCH.
* doc/posix-headers/fnmatch.texi: Mention the 'fnmatch-h' module.
* modules/posixcheck (Depends-on): Add fnmatch-h.
Bruno Haible [Sun, 5 Aug 2018 12:06:08 +0000 (14:06 +0200)]
Fix link error regarding 'rpl_environ' (regression from 2012-11-21).
* m4/extern-inline.m4: Add more comments.
* lib/warn-on-use.h (_GL_WARN_ON_USE_ATTRIBUTE): New macro.
* lib/unistd.in.h (rpl_environ): Use it instead of _GL_WARN_ON_USE.
* lib/math.in.h (_GL_WARN_REAL_FLOATING_DECL): Likewise.
Bruno Haible [Sat, 4 Aug 2018 15:25:57 +0000 (17:25 +0200)]
New module 'posixcheck'.
* modules/posixcheck: New file.
* m4/posixcheck.m4: New file.
* doc/gnulib-tool.texi (Finding POSIX substitutes): New section.
(Which modules?): Reference it.