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.
Paul Eggert [Thu, 12 Dec 2019 22:11:06 +0000 (14:11 -0800)]
dfa: prefer ptrdiff_t for API, too
Also, use ‘idx_t’ for ptrdiff_t values that must be nonnegative,
but do this only for internal use for now.
* NEWS: Mention the API change.
* lib/dfa.c (idx_t, IDX_MAX): New type and max value, for internal
use for now. Use them instead of ptrdiff_t and PTRDIFF_MAX for
values known to be nonnegative.
(dfaparse, dfaexec_mb, dfaexec_sb, dfaexec_noop, dfaexec):
Prefer idx_t or ptrdiff_t to size_t for API.
* lib/dfa.h (dfaparse, dfacomp, dfaexec):
Prefer ptrdiff_t to size_t for API.
Paul Eggert [Thu, 12 Dec 2019 18:16:13 +0000 (10:16 -0800)]
stdalign: port to xlclang 16.01
Problem reportd by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00064.html
* lib/stdalign.in.h (_Alignas): Do not use __attribute__
((__aligned__ (...))) with xlclang, as a top-level
‘char __attribute__ ((__aligned__ (8))) c;’ does not work with
xlclang version 16.01.0000.0001; the alignment directive is ignored.
Bruno Haible [Thu, 12 Dec 2019 10:07:49 +0000 (11:07 +0100)]
strtold: Work around Cygwin bug.
* m4/strtold.m4 (gl_FUNC_STRTOLD): Add test for the underflow problem.
If it is present, define STRTOLD_HAS_UNDERFLOW_BUG.
* lib/strtod.c (HAVE_UNDERLYING_STRTOD): Set to 0 if
STRTOLD_HAS_UNDERFLOW_BUG is defined.
* doc/posix-functions/strtold.texi: Mention the Cygwin bug.
Bruno Haible [Thu, 12 Dec 2019 01:52:11 +0000 (02:52 +0100)]
fsync tests: Skip test that is known to fail.
* doc/posix-functions/fsync.texi: Update list of platforms.
* tests/test-fsync.c (main): Skip test with read-only file descriptors
that is known to fail on AIX and Cygwin.
Bruno Haible [Thu, 12 Dec 2019 01:43:07 +0000 (02:43 +0100)]
getaddrinfo: Fix calling convention in 32-bit mode on native Windows.
* m4/getaddrinfo.m4 (gl_GETADDRINFO): Test whether getaddrinfo has a
non-POSIX signature. If so, set REPLACE_GETADDRINFO. Define
HAVE_GETADDRINFO as a C macro.
* lib/netdb.in.h (getaddrinfo, freeaddrinfo): If REPLACE_GETADDRINFO,
declare as replacement functions.
* lib/getaddrinfo.c (getaddrinfo, freeaddrinfo): If HAVE_GETADDRINFO,
define as no-op overrides.
* m4/netdb_h.m4 (gl_NETDB_H_DEFAULTS): Initialize REPLACE_GETADDRINFO.
* modules/netdb (Makefile.am): Substitute REPLACE_GETADDRINFO.
* modules/getaddrinfo (Depends-on, configure.ac): Test
REPLACE_GETADDRINFO.
* doc/posix-functions/getaddrinfo.texi: Mention calling convention
problem.
* doc/posix-functions/freeaddrinfo.texi: Mention header file and calling
convention problems.
Paul Eggert [Wed, 11 Dec 2019 23:08:35 +0000 (15:08 -0800)]
dfa: prefer signed integers for internals
Signed integers can be checked more easily for integer overflow.
* lib/dfa.c (position, struct lexer_state, struct parser_state)
(struct dfa, mbs_to_wchar, fetch_wc, parse_bracket_exp)
(struct lexptr, lex, addtok_mb, add_utf8_anychar, atom)
(nsubtoks, copytoks, closure, alloc_position_set, delete)
(replace, state_index, epsclosure, charclass_context)
(state_separate_contexts, merge_nfa_state, dfaoptimize)
(dfaanalyze, build_state, dfaexec_main, dfa_supported)
(maybe_disable_superset_dfa, dfassbuild, dfafree, enlist)
(comsubs, inboth, allocmust):
Prefer a signed to an unsigned integer when calculating indexes,
unless the integer is part of the external API (a bigger deal,
and to be done later).
Norihiro Tanaka [Wed, 11 Dec 2019 20:53:09 +0000 (12:53 -0800)]
dfa: separate parse and compile phase
‘dfamust’ must be called after parsing and before tokens are
reordered, but both are executed in the compilation phase.
Token reordering was introduced in Gnulib commit
2018-10-22T15:01:08Z!noritnk@kcn.ne.jp
(5c7a0371823876cca7a1347fa09ca26bbbff0c98).
* lib/dfa.c (dfaparse): Change it to global function.
(dfacomp): If first argument is NULL, skip parse.
* lib/dfa.h: (dfaparse): Add a prototype.
Bruno Haible [Sat, 7 Dec 2019 14:13:57 +0000 (15:13 +0100)]
Fix compilation errors in C++ mode on Solaris 10.
* m4/stdbool.m4 (AM_STDBOOL_H): Require AC_CANONICAL_HOST. Set STDBOOL_H
to non-empty on Solaris with a non-GCC compiler.
* doc/posix-headers/stdbool.texi: Mention the Solaris issue.
Pino Toscano [Thu, 5 Dec 2019 15:18:35 +0000 (16:18 +0100)]
Move xstrtol_fatal to a new xstrtol-error module
The xstrtol module provides a xstrtol_fatal function which uses other
modules suitable mostly for command line handling (e.g. gettext,
getopt), and that are completely unused when using only xstrto*
functions. Furthermore, xstrtol_fatal is used only in the xstrtol-tests
(within gnulib itself).
As solution, move the xstrtol_fatal to a new xstrtol-error module,
making xstrtol-tests depend on it. Since the prototype of xstrtol_fatal
is automatically provided by xstrtol.h, it is very difficult to know
whether anyone is actually using it, so add a note about this in NEWS.
* lib/xstrtol.h: Stop including <getopt.h>.
(xstrtol_fatal): Move ...
* lib/xstrtol-error.h: ... here. New file.
* lib/xstrtol-error.c: Include xstrtol-error.h instead of xstrtol.h.
* tests/test-xstrtol.c: Likewise.
* modules/xstrtol (Files): Remove lib/xstrtol-error.c.
(Depends-on): Remove exitfail, error, getopt-gnu, and gettext-h.
(Makefile.am): Remove xstrtol-error.c from lib_SOURCES.
* modules/xstrtol-error: New file.
* modules/xstrtol-tests (Depends-on): Add xstrtol-error.
* MODULES.html.sh: Add xstrtol-error.
* NEWS: Document the change.
Paul Eggert [Fri, 6 Dec 2019 22:48:04 +0000 (14:48 -0800)]
nstrftime: better width support for %N, %z
* lib/nstrftime.c (width_add, width_add1, width_cpy):
New macros, which generalize ‘add’, ‘add1’, ‘cpy’ by adding
a new WIDTH parameter.
(add, add1, cpy): Use these macros.
(width_add): Do not treat digits == 0 as a special case,
do not pad if padding is ‘-’, and do not use a negative width.
(__strftime_internal): Redo formatting of nanoseconds and numeric
timezones to avoid buffer misuse in unusual cases, and so that
widths make more sense. Add support for widths greater than 9 to
the %N format; they are zero filled on the right.
* tests/test-nstrftime.c (posixtm_test): Add a %12N test.
Bruno Haible [Thu, 5 Dec 2019 21:25:04 +0000 (22:25 +0100)]
Fix compilation errors in C++ mode on Solaris 10 and Solaris 11.
* m4/isfinite.m4 (gl_ISFINITE): Require AC_CANONICAL_HOST. On Solaris,
set REPLACE_ISFINITE to 1.
* m4/isinf.m4 (gl_ISINF): Require AC_CANONICAL_HOST. On Solaris, set
REPLACE_ISINF to 1.
* m4/signbit.m4 (gl_SIGNBIT): On Solaris, set REPLACE_SIGNBIT to 1.
* lib/pthread.in.h (pthread_create, pthread_once, pthread_key_create):
Use _GL_CXXALIAS_SYS_CAST instead of _GL_CXXALIAS_SYS.
* lib/threads.in.h (call_once): Likewise.
* lib/iconv.in.h (iconv): Likewise.
Bruno Haible [Thu, 5 Dec 2019 08:11:45 +0000 (09:11 +0100)]
Add more C++ tests.
assert-h: Add C++ tests.
* tests/test-assert-h-c++.cc: New file.
* tests/test-assert-h-c++2.cc: New file.
* modules/assert-h-c++-tests: New file.
* modules/assert-h-tests: New file.
ctype: Add C++ tests.
* tests/test-ctype-c++.cc: New file.
* tests/test-ctype-c++2.cc: New file.
* modules/ctype-c++-tests: New file.
* modules/ctype-tests (Depends-on): Add ctype-c++-tests.
errno: Add C++ tests.
* tests/test-errno-c++.cc: New file.
* tests/test-errno-c++2.cc: New file.
* modules/errno-c++-tests: New file.
* modules/errno-tests (Depends-on): Add errno-c++-tests.
float: Add C++ tests.
* tests/test-float-c++.cc: New file.
* tests/test-float-c++2.cc: New file.
* modules/float-c++-tests: New file.
* modules/float-tests (Depends-on): Add float-c++-tests.
inttypes: Add more C++ tests.
* tests/test-inttypes-c++2.cc: New file.
* modules/inttypes-c++-tests (Files): Add it.
(Makefile.am): Compile it.
limits-h: Add C++ tests.
* tests/test-limits-h-c++.cc: New file.
* tests/test-limits-h-c++2.cc: New file.
* modules/limits-h-c++-tests: New file.
* modules/limits-h-tests (Depends-on): Add limits-h-c++-tests.
stdarg: Add C++ tests.
* tests/test-stdarg-c++.cc: New file.
* tests/test-stdarg-c++2.cc: New file.
* modules/stdarg-c++-tests: New file.
* modules/stdarg-tests: New file.
stdbool: Add C++ tests.
* tests/test-stdbool-c++.cc: New file.
* tests/test-stdbool-c++2.cc: New file.
* modules/stdbool-c++-tests: New file.
* modules/stdbool-tests (Depends-on): Add stdbool-c++-tests.
stddef: Add C++ tests.
* tests/test-stddef-c++.cc: New file.
* tests/test-stddef-c++2.cc: New file.
* modules/stddef-c++-tests: New file.
* modules/stddef-tests (Depends-on): Add stddef-c++-tests.
stdint: Add C++ tests.
* tests/test-stdint-c++.cc: New file.
* tests/test-stdint-c++2.cc: New file.
* modules/stdint-c++-tests: New file.
* modules/stdint-tests (Depends-on): Add stdint-c++-tests.
wchar: Add more C++ tests.
* tests/test-wchar-c++2.cc: New file.
* modules/wchar-c++-tests (Files): Add it.
(Makefile.am): Compile it.
wctype-h: Add more C++ tests.
* tests/test-wctype-h-c++2.cc: New file.
* modules/wctype-h-c++-tests (Files): Add it.
(Makefile.am): Compile it.
Bruno Haible [Thu, 5 Dec 2019 02:18:42 +0000 (03:18 +0100)]
Fix compilation errors in C++ mode with xlclang++ on AIX.
* lib/math.in.h (expm1l, fmal, remainderl, roundl): Don't redeclare in
C++ mode on AIX.
(isfinite, signbit): In C++ mode on AIX with clang, use the approach
without C preprocessor macro.
* lib/pthread.in.h (pthread_exit): Use _GL_CXXALIAS_SYS_CAST instead of
_GL_CXXALIAS_SYS.
* lib/threads.in.h (thrd_exit): Likewise.