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.
Bruno Haible [Tue, 3 Dec 2019 01:04:23 +0000 (02:04 +0100)]
Fix link errors with --enable-threads=posix on AIX.
* modules/string-c++-tests (Makefile.am): Link the test-string-c++
program with $(LIBTHREAD).
* modules/wchar-c++-tests (Makefile.am): Link the test-wchar-c++
program with $(LIBTHREAD).
Tim Rühsen [Sat, 30 Nov 2019 12:04:28 +0000 (13:04 +0100)]
gnulib-tool.py: Fix libgnu_la_LDFLAGS section in generated Makefile.am.
Reported by Dagobert Michelsen <dam@opencsw.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00086.html>.
* pygnulib/GLModuleSystem.py (getLink): Don't join the parts. Return a
list of strings instead of one string.
* pygnulib/GLEmiter.py (lib_Makefile_am): Adapt accordingly.
* pygnulib/GLImport.py (execute): Likewise.
Bruno Haible [Wed, 27 Nov 2019 23:34:34 +0000 (00:34 +0100)]
openpty, forkpty: Fix build error on Solaris 11.4.
* m4/pty_h.m4 (gl_PTY_H): Test for termios.h. Look for the declarations
also in <termios.h>.
* m4/pty.m4 (gl_FUNC_FORKPTY, gl_FUNC_OPENPTY): Look for the declaration
of the function also in <termios.h>.
* doc/glibc-functions/openpty.texi: Mention the Solaris 11.4 problems.
* doc/glibc-functions/forkpty.texi: Likewise.
Bruno Haible [Wed, 27 Nov 2019 05:03:21 +0000 (06:03 +0100)]
New options --enable-threads=isoc and --enable-threads=isoc+posix.
* m4/threadlib.m4 (gl_THREADLIB_EARLY_BODY): Accept the options
--enable-threads=isoc and --enable-threads=isoc+posix.
(gl_THREADLIB_BODY): Test whether the ISO C threads API is available.
When both the ISO C and the POSIX threads API are available, choose
USE_ISOC_AND_POSIX_THREADS instead of USE_POSIX_THREADS if
--enable-threads=isoc+posix was specified. When only the ISO C threads
API is available and --enable-threads=iso was specified, choose
USE_ISOC_THREADS.
* lib/glthread/lock.h: Add new code for USE_ISOC_THREADS ||
USE_ISOC_AND_POSIX_THREADS.
* lib/glthread/lock.c: Likewise.
* lib/glthread/cond.h: Likewise.
* lib/glthread/cond.c: Likewise.
* lib/glthread/tls.h: Likewise.
* lib/glthread/tls.c: Likewise.
* lib/glthread/yield.h: Likewise.
* lib/glthread/thread.h: Add new code for USE_ISOC_THREADS. Treat
USE_ISOC_AND_POSIX_THREADS like USE_POSIX_THREADS.
* lib/glthread/thread.c: Likewise.
* lib/glthread/threadlib.c: Likewise.
* tests/test-lock.c: Save and restore the values of USE_ISOC_THREADS and
USE_ISOC_AND_POSIX_THREADS.
* tests/test-cond.c: Consider USE_ISOC_THREADS and
USE_ISOC_AND_POSIX_THREADS.
* tests/test-tls.c: Likewise.
* tests/test-thread_create.c (main): Likewise.
* tests/test-pthread-cond.c: Likewise.
* tests/test-pthread-mutex.c: Likewise.
* tests/test-pthread-once2.c: Likewise.
* tests/test-pthread-rwlock.c: Likewise.
* tests/test-pthread-tss.c: Likewise.
* tests/test-pthread_sigmask2.c: Treat USE_ISOC_AND_POSIX_THREADS like
USE_POSIX_THREADS.
Bruno Haible [Sun, 24 Nov 2019 19:31:50 +0000 (20:31 +0100)]
mbrtowc: Modernize autoconf test.
* m4/mbrtowc.m4 (gl_MBRTOWC_INCOMPLETE_STATE): Require
gt_LOCALE_FR_UTF8. If a traditional Japanese locale is not available,
try a UTF-8 locale.
* doc/posix-functions/mbrtowc.texi: Update info about AIX.
Bruno Haible [Sun, 24 Nov 2019 19:11:28 +0000 (20:11 +0100)]
sys_time: Fix errors in C++ mode on mingw.
* lib/sys_time.in.h (timeval): Restore the redirection
'#define timeval rpl_timeval', for when the symbol timeval is being used
outside the 'gnulib' namespace.
* lib/sys_select.in.h (select): In C++, write 'timeval', not
'struct timeval'.
Bruno Haible [Sun, 24 Nov 2019 19:10:56 +0000 (20:10 +0100)]
iswctype: Fix errors in C++ mode on mingw.
* lib/wctype.in.h (rpl_iswctype): Override if GNULIB_OVERRIDES_WINT_T
is 1.
* lib/iswctype.c (iswctype): Add another implementation, for the
GNULIB_defined_wint_t case.
* modules/iswctype (configure.ac): Compile iswctype.c also if
GNULIB_OVERRIDES_WINT_T is 1.
Bruno Haible [Thu, 21 Nov 2019 10:44:05 +0000 (11:44 +0100)]
pthread-spin: Fix errors in C++ mode.
* m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Mark the pthread_spin_*
functions as nonexistent when <pthread.h> exists but does not define
the pthread_spinlock_t type.
Bruno Haible [Thu, 21 Nov 2019 10:44:01 +0000 (11:44 +0100)]
pthread-mutex: Fix errors in C++ mode.
* m4/pthread-mutex.m4 (gl_PTHREAD_MUTEX): Test whether
pthread_mutexattr_getrobust exists. If not, define
PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED.
* lib/pthread-mutex.c (pthread_mutexattr_getrobust,
pthread_mutexattr_setrobust): Define also if <pthread.h> exists but
PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED.
* modules/pthread-mutex (configure.ac): Compile pthread-mutex.c also
when <pthread.h> exists but pthread_mutexattr_getrobust needs a gnulib
definition.
Paul Eggert [Tue, 19 Nov 2019 01:57:53 +0000 (17:57 -0800)]
glob: get closer to glibc glob.c
Omit differences from glibc when the differences don’t matter.
* lib/glob.c [_LIBC]: Include shlib-compat.h.
(__glob) [!_LIBC]: New macro. All uses of glob changed to __glob.
(glob_lstat): New function.
(glob_in_dir): Use it.
(GLOB_ATTRIBUTE): Define to empty if not already defined.
Use changed.
Bruno Haible [Mon, 18 Nov 2019 21:41:09 +0000 (22:41 +0100)]
stdint: Define [u]intptr_t correctly on 64-bit native Windows.
* lib/stdint.in.h (gl_intptr_t, gl_uintptr_t, INTPTR_MIN, INTPTR_MAX,
UINTPTR_MAX): Consider _WIN64.
* tests/test-stdint.c: Verify that [u]intptr_t is large enough to hold
a pointer.