Paul Eggert [Wed, 1 Jan 2020 01:33:19 +0000 (17:33 -0800)]
maint: update copyright notices
Before doing the following changes done by hand, I also ran ‘make
update-copyright’ and ‘config/srclist-update <config/srclist.txt’
to do most of the copyright years automatically. A few upstream
sources are still in 2019 but these should eventually be changed
automatically too.
* build-aux/declared.sh (func_version):
* build-aux/libtool-next-version (func_version):
* build-aux/run-test (func_version):
Update these notices by hand. Put just the last year
in output of programs, as per GNU coding standards.
Jim Meyering [Tue, 31 Dec 2019 07:23:42 +0000 (23:23 -0800)]
localeinfo: ->simple would be wrong for LC_ALL=C
That would lead to using unnecessary and expensive code paths in dfa.c.
* lib/localeinfo.c (using_simple_locale): Fix recently-introduced logic
error that would have made grep many times slower in the C locale.
With this change, and a file created like this:
yes 00 | head -10000000 > in
Running grep as follows becomes more than 40 times faster:
LC_ALL=C grep -Fw 0 in
Paul Eggert [Thu, 26 Dec 2019 08:50:12 +0000 (00:50 -0800)]
mbrtowc: port better to narrow-wchar_t platforms
* lib/mbrtowc.c (mbrtowc): On platforms like AIX 7.2, where
wchar_t is too narrow to represent all the Unicode characters,
consider a byte sequence for an out-of-wchar_t-range character to
be an encoding error. This fixes grep’s surrogate-pair test
failure on AIX 7.2.
Bruno Haible [Tue, 24 Dec 2019 20:27:36 +0000 (21:27 +0100)]
lock tests: Fix link error on HP-UX/hppa (regression from 2019-12-21).
* m4/semaphore.m4: New file.
* modules/lock-tests (Files): Add it.
(configure.ac): Require gl_SEMAPHORE.
(Makefile.am): Link test-lock with $(LIB_SEMAPHORE).
Paul Eggert [Tue, 24 Dec 2019 18:31:42 +0000 (10:31 -0800)]
strptime: fix typo in previous patch
Problem and fix reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00202.html
* lib/strptime.c (day_of_the_week): Fix paren bug.
Paul Eggert [Tue, 24 Dec 2019 03:04:50 +0000 (19:04 -0800)]
gethrxtime: improve xtime_sec performance
Performanced analyzed by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00200.html
* lib/xtime.h (xtime_sec): Redo with neither ‘%’ nor conditional
branches.
Paul Eggert [Sun, 22 Dec 2019 20:32:31 +0000 (12:32 -0800)]
gethrxtime: fix rounding bug with negative args
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00192.html
* lib/xtime.h (xtime_sec): Simplify calculation and correct bug
with negative rounding. Common platforms can compute / and % with
a single instruction, so the simplified code should be shorter and
faster on these platforms anyway.
Paul Eggert [Sun, 22 Dec 2019 20:38:22 +0000 (12:38 -0800)]
gethrxtime: remove incorrect overflow detection
This is part of a patch written by Bruno Haible:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00192.html
* lib/xtime.h (xtime_make): Remove attempt to prevent internal
integer overflow, as it didn’t suffice. This reverts the xtime.h
part of 2018-10-12T04:46:09Z!akim.demaille@gmail.com, which I
cannot now see the need for anyway (even in cases where it works),
as the patch is helpful only when the signs of S and NS disagree,
and all callers pass nonnegative values for S and NS.
Instead, add a comment saying args should be nonnegative.
Bruno Haible [Sat, 21 Dec 2019 17:22:38 +0000 (18:22 +0100)]
pthread_sigmask: Avoid test failure on NetBSD 8.0.
* tests/test-pthread_sigmask2.c (main): Skip the error handling test on
NetBSD.
* doc/posix-functions/pthread_sigmask.texi: Mention the NetBSD problem.
Bruno Haible [Sat, 21 Dec 2019 12:53:31 +0000 (13:53 +0100)]
threadlib: Fix LIBMULTITHREAD on FreeBSD with --enable-threads=isoc.
* m4/threadlib.m4 (gl_STDTHREADLIB_BODY): New macro (some code moved
here from m4/threads.m4).
(gl_THREADLIB_BODY): Don't test whether mtx_lock and cnd_timedwait exist
in libc. Instead, rely on gl_STDTHREADLIB_BODY.
(gl_STDTHREADLIB): New macro.
* m4/threads.m4 (gl_THREADS_H): Require gl_STDTHREADLIB instead of
gl_THREADLIB_BODY and gl_YIELD. Don't set LIBSTDTHREAD here.
Bruno Haible [Sat, 21 Dec 2019 05:29:11 +0000 (06:29 +0100)]
pthread-thread, lock: On z/OS, use PTHREAD_RWLOCK_INITIALIZER_NP.
Reported by Daniel Richard G. in
<https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00001.html>
<https://lists.gnu.org/archive/html/bug-gnulib/2019-12/msg00167.html>
* lib/pthread.in.h (PTHREAD_RWLOCK_INITIALIZER): Define to
PTHREAD_RWLOCK_INITIALIZER_NP when possible.
* lib/glthread/lock.h: Allow PTHREAD_RWLOCK_INITIALIZER_NP as an
alternative to PTHREAD_RWLOCK_INITIALIZER.
* lib/glthread/lock.c: Likewise.
Bruno Haible [Fri, 20 Dec 2019 08:12:37 +0000 (09:12 +0100)]
iconv_open: Add support for z/OS encoding names.
Reported by Daniel Richard G. in
<https://lists.gnu.org/archive/html/bug-gnulib/2019-12/msg00172.html>.
* lib/iconv_open-zos.gperf: New file.
* modules/iconv_open (Files): Add iconv_open-zos.gperf.
(Makefile.am): Add rules for generating iconv_open-zos.h from it.
* lib/iconv_open.c (ICONV_FLAVOR_ZOS): New macro.
* m4/iconv_open.m4 (gl_FUNC_ICONV_OPEN): On z/OS, use ICONV_FLAVOR_ZOS.
* doc/posix-functions/iconv_open.texi: Mention z/OS.
Paul Eggert [Thu, 19 Dec 2019 22:35:59 +0000 (14:35 -0800)]
dfa: struct dfamust now uses flexible array
* lib/dfa.c: Include flexmember.h.
(dfamust, dfamustfree): Adjust to struct dfamust change.
This saves a call to malloc+free.
* lib/dfa.h (struct dfamust): Make the final member a
flexible array member.
* modules/dfa (Depends-on): Add flexmember.
Paul Eggert [Thu, 19 Dec 2019 21:37:45 +0000 (13:37 -0800)]
dfa: fast->small for array elements
* lib/dfa.c (charclass_word): Use uint_least64_t not uint_fast64_t,
since this type is used in arrays. This change is more for
documentation than for any practical effect, since the two types
are the same on all known platforms.
Paul Eggert [Thu, 19 Dec 2019 01:05:02 +0000 (17:05 -0800)]
Improve port of AC_C_RESTRICT to Oracle C++
Problem reported by Christian Biesinger in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00159.html
* m4/gnulib-common.m4 (AC_C_RESTRICT): Port better to
Oracle Developer Studio C++ 12.5 or later.
Bruno Haible [Wed, 18 Dec 2019 15:30:09 +0000 (16:30 +0100)]
setlocale-null: Make API more useful.
* lib/locale.in.h (setlocale_null_r): Renamed from setlocale_null. All
callers changed.
(setlocale_null): New declaration.
* lib/setlocale_null.c (setlocale_null_androidfix): New function,
extracted from setlocale_null_unlocked.
(setlocale_null_unlocked): Invoke it.
(setlocale_null_r): Renamed from setlocale_null.
(setlocale_null): New function, extracted from setlocale_mtsafe in
setlocale.c.
* lib/setlocale.c: Don't include <errno.h>.
(setlocale_mtsafe): Invoke setlocale_null.
* lib/setlocale-lock.c: Update comments.
* doc/posix-functions/setlocale.texi: Mention both functions.
Bruno Haible [Wed, 18 Dec 2019 10:42:21 +0000 (11:42 +0100)]
hard-locale: Make multithread-safe.
* lib/hard-locale.h (hard_locale): Move documentation to here.
* lib/hard-locale.c: Don't include <stdlib.h>.
(GLIBC_VERSION): Remove macro.
(hard_locale): Assume that all systems name the "C" and "POSIX" locales
"C" or "POSIX". Invoke setlocale_null instead of setlocale.
* modules/hard-locale (Depends-on): Remove strdup. Add setlocale-null.
(configure.ac): Require gl_FUNC_SETLOCALE_NULL. Set LIB_HARD_LOCALE.
(Link): New section.
* modules/hard-locale-tests (Makefile.am): Link test-hard-locale against
$(LIB_HARD_LOCALE).
Paul Eggert [Wed, 18 Dec 2019 05:41:27 +0000 (21:41 -0800)]
dfa: do not match invalid UTF-8
* lib/dfa.c (struct dfa): Grow utf8_anychar_classes member array
from 5 to 9 tokens; this is needed due to the changes to
add_utf8_anychar.
(charclass_index): 2nd arg is now pointer-to-const.
(add_utf8_anychar): Match only valid UTF-8 byte sequences
instead of allowing overlong encodings or surrogate halves.
Paul Eggert [Tue, 17 Dec 2019 22:08:33 +0000 (14:08 -0800)]
dfa: simplify charclass by assuming C99
* lib/dfa.c (CHARCLASS_WORD_BITS): Now always 64.
(charclass_word): Now always uint_fast64_t.
(CHARCLASS_PAIR): Remove.
(CHARCLASS_INIT): Take 4 arguments instead of 8. All uses changed.
Bruno Haible [Tue, 17 Dec 2019 14:29:15 +0000 (15:29 +0100)]
localcharset: Fix multithread-safety bug on Windows and OS/2.
* lib/localcharset.h (locale_charset): Clarify when the result becomes
invalid.
* lib/localcharset.c (locale_charset): Use a stack-allocated buffer to
assemble the result.
Bruno Haible [Tue, 17 Dec 2019 13:00:59 +0000 (14:00 +0100)]
nl_langinfo: Fix multithread-safety bug on mingw and MSVC.
* lib/nl_langinfo.c (ctype_codeset, rpl_nl_langinfo): Use a
stack-allocated buffer to assemble each result and different static
buffers to return it.
* tests/test-nl_langinfo-mt.c: New file.
* modules/nl_langinfo-tests (Files): Add it.
(Depends-on): Add thread, nanosleep.
(Makefile.am): Build test-nl_langinfo-mt test.
Paul Eggert [Tue, 17 Dec 2019 08:49:54 +0000 (00:49 -0800)]
xalloc: tune xzalloc for fresh allocations
* lib/xmalloc.c (xzalloc): Use xcalloc rather than xmalloc+memset,
because when the memory is freshly allocated from the OS via sbrk
or mmap, calloc can avoid doing the memset.
Paul Eggert [Tue, 17 Dec 2019 08:20:53 +0000 (00:20 -0800)]
dfa: new function dfacopysyntax
* lib/dfa.c (struct dfa): Move syntax member later so
that dfacopysyntax can easily clear earlier members.
(dfacopysyntax): New function, used by Gawk.
Bruno Haible [Mon, 16 Dec 2019 09:38:37 +0000 (10:38 +0100)]
setlocale-null: Remove need for -lpthread on musl libc, *BSD, Haiku.
Reported by Arnold Robbins <arnold@skeeve.com>.
* lib/setlocale_null.c (c11_threads_in_use, pthread_in_use): New macros,
copied from lib/glthread/lock.h.
(pthread_mutex_lock, pthread_mutex_unlock): Mark as weak.
(setlocale_null_with_lock): If pthread_in_use() is false, use
setlocale_null_unlocked directly.
* m4/threadlib.m4 (gl_WEAK_SYMBOLS): New macro, extracted from
gl_THREADLIB_BODY. Define HAVE_WEAK_SYMBOLS.
(gl_THREADLIB_BODY): Invoke gl_WEAK_SYMBOLS.
* m4/setlocale_null.m4 (gl_FUNC_SETLOCALE_NULL): Invoke gl_WEAK_SYMBOLS.
Set LIB_SETLOCALE_NULL to empty if weak symbols are supported.
* m4/duplocale.m4 (gl_FUNC_DUPLOCALE): Add comment.
Paul Eggert [Mon, 16 Dec 2019 08:32:01 +0000 (00:32 -0800)]
dfa: make dfasyntax thread-safe
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00099.html
* lib/dfa.c: Do not include locale.h.
(struct dfa): Remove simple_locale member.
All uses replaced by localeinfo.simple.
(using_simple_locale): Remove; now present (with some
changes) in localeinfo.c.
(dfasyntax): No need to initialize removed member.
Paul Eggert [Mon, 16 Dec 2019 08:27:15 +0000 (00:27 -0800)]
localeinfo: record whether locale is simple
* lib/localeinfo.c (using_simple_locale): New function,
copied here from lib/dfa.c but with a change: it uses
strcoll for its heuristic, instead of using setlocale.
This lets it be thread-safe.
* lib/localeinfo.h (struct localeinfo): New member ‘simple’.
Bruno Haible [Sun, 15 Dec 2019 20:48:05 +0000 (21:48 +0100)]
setlocale-null: Add tests.
* tests/test-setlocale_null.c: New file.
* tests/test-setlocale_null-one.c: New file.
* tests/test-setlocale_null-all.c: New file.
* modules/setlocale-null-tests: New file.