From: Paul Eggert Date: Wed, 28 Sep 2022 07:29:09 +0000 (-0700) Subject: Update from Gnulib by running admin/merge-gnulib X-Git-Tag: emacs-29.0.90~1856^2~178 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a9b29ee4a0ffa4878d67eaf518dbeed098844b9e;p=emacs.git Update from Gnulib by running admin/merge-gnulib --- diff --git a/build-aux/config.guess b/build-aux/config.guess index 1817bdce90d..a419d8643b6 100755 --- a/build-aux/config.guess +++ b/build-aux/config.guess @@ -4,7 +4,7 @@ # shellcheck disable=SC2006,SC2268 # see below for rationale -timestamp='2022-05-25' +timestamp='2022-08-01' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -1036,7 +1036,7 @@ EOF k1om:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; - loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + loongarch32:Linux:*:* | loongarch64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; m32r*:Linux:*:*) diff --git a/build-aux/config.sub b/build-aux/config.sub index dba16e84c77..fbaa37f2352 100755 --- a/build-aux/config.sub +++ b/build-aux/config.sub @@ -4,7 +4,7 @@ # shellcheck disable=SC2006,SC2268 # see below for rationale -timestamp='2022-01-03' +timestamp='2022-08-01' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -1207,7 +1207,7 @@ case $cpu-$vendor in | k1om \ | le32 | le64 \ | lm32 \ - | loongarch32 | loongarch64 | loongarchx32 \ + | loongarch32 | loongarch64 \ | m32c | m32r | m32rle \ | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ diff --git a/doc/misc/texinfo.tex b/doc/misc/texinfo.tex index f86af0db3e5..09f2d28c2f2 100644 --- a/doc/misc/texinfo.tex +++ b/doc/misc/texinfo.tex @@ -3,7 +3,7 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2022-08-20.19} +\def\texinfoversion{2022-09-21.15} % % Copyright 1985, 1986, 1988, 1990-2022 Free Software Foundation, Inc. % @@ -241,9 +241,6 @@ % \def\finalout{\overfullrule=0pt } -\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines -\newdimen\topandbottommargin \topandbottommargin=.75in - % Output a mark which sets \thischapter, \thissection and \thiscolor. % We dump everything together because we only have one kind of mark. % This works because we only use \botmark / \topmark, not \firstmark. @@ -317,16 +314,8 @@ \newbox\footlinebox % When outputting the double column layout for indices, an output routine -% is run several times, which hides the original value of \topmark. This -% can lead to a page heading being output and duplicating the chapter heading -% of the index. Hence, save the contents of \topmark at the beginning of -% the output routine. The saved contents are valid until we actually -% \shipout a page. -% -% (We used to run a short output routine to actually set \topmark and -% \firstmark to the right values, but if this was called with an empty page -% containing whatsits for writing index entries, the whatsits would be thrown -% away and the index auxiliary file would remain empty.) +% is run several times, hiding the original value of \topmark. Hence, save +% \topmark at the beginning. % \newtoks\savedtopmark \newif\iftopmarksaved @@ -351,15 +340,9 @@ % \checkchapterpage % - % Retrieve the information for the headings from the marks in the page, - % and call Plain TeX's \makeheadline and \makefootline, which use the - % values in \headline and \footline. - % - % Common context changes for both heading and footing. - % Do this outside of the \shipout so @code etc. will be expanded in - % the headline as they should be, not taken literally (outputting ''code). + % Make the heading and footing. \makeheadline and \makefootline + % use the contents of \headline and \footline. \def\commonheadfootline{\let\hsize=\txipagewidth \texinfochars} - % \ifodd\pageno \getoddheadingmarks \else \getevenheadingmarks \fi \global\setbox\headlinebox = \vbox{\commonheadfootline \makeheadline}% \ifodd\pageno \getoddfootingmarks \else \getevenfootingmarks \fi @@ -617,21 +600,6 @@ % @? is an end-of-sentence query. \def\?{?\spacefactor=\endofsentencespacefactor\space} -% @frenchspacing on|off says whether to put extra space after punctuation. -% -\def\onword{on} -\def\offword{off} -% -\parseargdef\frenchspacing{% - \def\temp{#1}% - \ifx\temp\onword \plainfrenchspacing - \else\ifx\temp\offword \plainnonfrenchspacing - \else - \errhelp = \EMsimple - \errmessage{Unknown @frenchspacing option `\temp', must be on|off}% - \fi\fi -} - % @w prevents a word break. Without the \leavevmode, @w at the % beginning of a paragraph, when TeX is still in vertical mode, would % produce a whole line of output instead of starting the paragraph. @@ -2803,14 +2771,22 @@ end % @var unconditionally uses \sl. This gives consistency for % parameter names whether they are in @def, @table @code or a % regular paragraph. +% To get ttsl font for @var when used in code context, @set txicodevaristt. % The \null is to reset \spacefactor. \def\aftersmartic{} \def\var#1{% \let\saveaftersmartic = \aftersmartic \def\aftersmartic{\null\let\aftersmartic=\saveaftersmartic}% - {\sl #1}\smartitaliccorrection + % + \ifflagclear{txicodevaristt}% + {\def\varnext{{{\sl #1}}\smartitaliccorrection}}% + {\def\varnext{\smartslanted{#1}}}% + \varnext } +% To be removed after next release +\def\SETtxicodevaristt{}% @set txicodevaristt + \let\i=\smartitalic \let\slanted=\smartslanted \let\dfn=\smartslanted @@ -2859,6 +2835,24 @@ end \catcode`@=\other \def\endofsentencespacefactor{3000}% default +% @frenchspacing on|off says whether to put extra space after punctuation. +% +\def\onword{on} +\def\offword{off} +% +\let\frenchspacingsetting\plainnonfrenchspacing % used in output routine +\parseargdef\frenchspacing{% + \def\temp{#1}% + \ifx\temp\onword \let\frenchspacingsetting\plainfrenchspacing + \else\ifx\temp\offword \let\frenchspacingsetting\plainnonfrenchspacing + \else + \errhelp = \EMsimple + \errmessage{Unknown @frenchspacing option `\temp', must be on|off}% + \fi\fi + \frenchspacingsetting +} + + % @t, explicit typewriter. \def\t#1{% {\tt \defcharsdefault \plainfrenchspacing #1}% @@ -3450,8 +3444,13 @@ $$% % Revert to plain's \scriptsize, which is 7pt. \count255=\the\fam $\fam\count255 \scriptstyle A$% \else - % For 11pt, we can use our lllsize. - \switchtolllsize A% + \ifx\curfontsize\smallword + % For footnotes and indices + \count255=\the\fam $\fam\count255 \scriptstyle A$% + \else + % For 11pt, we can use our lllsize. + \switchtolllsize A% + \fi \fi }% \vss @@ -3459,6 +3458,7 @@ $$% \kern-.15em \TeX } +\def\smallword{small} % Some math mode symbols. Define \ensuremath to switch into math mode % unless we are already there. Expansion tricks may not be needed here, @@ -3829,15 +3829,16 @@ $$% \newtoks\oddfootline % footline on odd pages % Now make \makeheadline and \makefootline in Plain TeX use those variables -\headline={{\textfonts\rm +\headline={{\textfonts\rm\frenchspacingsetting \ifchapterpage \ifodd\pageno\the\oddchapheadline\else\the\evenchapheadline\fi \else \ifodd\pageno\the\oddheadline\else\the\evenheadline\fi \fi}} -\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline - \else \the\evenfootline \fi}\HEADINGShook} +\footline={{\textfonts\rm\frenchspacingsetting + \ifodd\pageno \the\oddfootline \else \the\evenfootline \fi}% + \HEADINGShook} \let\HEADINGShook=\relax % Commands to set those variables. @@ -3963,7 +3964,7 @@ $$% \global\oddfootline={\hfil} \global\evenheadline={\line{\folio\hfil\thistitle}} \global\oddheadline={\line{\thischapter\hfil\folio}} -\global\evenchapheadline={\line{\folio\hfil}} +\global\evenchapheadline={\line{\folio\hfil\thistitle}} \global\oddchapheadline={\line{\hfil\folio}} \global\let\contentsalignmacro = \chapoddpage } @@ -4351,8 +4352,7 @@ $$% % undo it ourselves. \def\headitemfont{\b}% for people to use in the template row; not changeable \def\headitem{% - \checkenv\multitable - \crcr + \crcr % must appear first \gdef\headitemcrhook{\nobreak}% attempt to avoid page break after headings \global\everytab={\bf}% can't use \headitemfont since the parsing differs \the\everytab % for the first item @@ -6755,6 +6755,11 @@ might help (with 'rm \jobname.?? \jobname.??s')% \ifnum\romancount=0 \global\romancount=\pagecount \fi } +% \raggedbottom in plain.tex hardcodes \topskip so override it +\catcode`\@=11 +\def\raggedbottom{\advance\topskip by 0pt plus60pt \r@ggedbottomtrue} +\catcode`\@=\other + % redefined for the two-volume lispref. We always output on % \jobname.toc even if this is redefined. % @@ -7115,7 +7120,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % collide with the section heading. \ifnum\lastpenalty>10000 \vskip\parskip \penalty\lastpenalty \fi % - \setbox\groupbox=\vbox\bgroup + \setbox\groupbox=\vtop\bgroup \baselineskip=0pt\parskip=0pt\lineskip=0pt \carttop \hbox\bgroup @@ -7801,6 +7806,8 @@ might help (with 'rm \jobname.?? \jobname.??s')% % Print arguments. Use slanted for @def*, typewriter for @deftype*. \def\defunargs#1{% \df \ifdoingtypefn \tt \else \sl \fi + \ifflagclear{txicodevaristt}{}% + {\def\var##1{{\setregularquotes \ttsl ##1}}}% #1% } @@ -9311,6 +9318,12 @@ might help (with 'rm \jobname.?? \jobname.??s')% \imagexxx #1,,,,,\finish \fi } + +% Approximate height of a line in the standard text font. +\newdimen\capheight +\setbox0=\vbox{\tenrm H} +\capheight=\ht0 + % % Arguments to @image: % #1 is (mandatory) image filename; we tack on .eps extension. @@ -9340,7 +9353,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % % Place image in a \vtop for a top page margin that is (close to) correct, % as \topskip glue is relative to the first baseline. - \vtop\bgroup\hrule height 0pt\vskip-\parskip + \vtop\bgroup \kern -\capheight \vskip-\parskip \fi % % Enter horizontal mode so that indentation from an enclosing @@ -11217,13 +11230,9 @@ directory should work if nowhere else does.} % \vsize = #1\relax \advance\vsize by \topskip - \outervsize = \vsize - \advance\outervsize by 2\topandbottommargin \txipageheight = \vsize % \hsize = #2\relax - \outerhsize = \hsize - \advance\outerhsize by 0.5in \txipagewidth = \hsize % \normaloffset = #4\relax diff --git a/lib/acl-internal.h b/lib/acl-internal.h index 93533762dd0..94553fab254 100644 --- a/lib/acl-internal.h +++ b/lib/acl-internal.h @@ -19,7 +19,6 @@ #include "acl.h" -#include #include /* All systems define the ACL related API in . */ diff --git a/lib/acl.h b/lib/acl.h index f4d0df80618..0be6ef1cea3 100644 --- a/lib/acl.h +++ b/lib/acl.h @@ -20,7 +20,6 @@ #ifndef _GL_ACL_H #define _GL_ACL_H 1 -#include #include #include diff --git a/lib/assert.in.h b/lib/assert.in.h new file mode 100644 index 00000000000..2c358ba62e7 --- /dev/null +++ b/lib/assert.in.h @@ -0,0 +1,27 @@ +/* Substitute for and wrapper around + Copyright (C) 2011-2022 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Do not guard the include, since is supposed to define + the assert macro each time it is included. */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#@INCLUDE_NEXT@ @NEXT_ASSERT_H@ + +/* The definition of static_assert is copied here. */ diff --git a/lib/c-ctype.h b/lib/c-ctype.h index 1a4f603898f..1202ff8a363 100644 --- a/lib/c-ctype.h +++ b/lib/c-ctype.h @@ -23,8 +23,6 @@ #ifndef C_CTYPE_H #define C_CTYPE_H -#include - #ifndef _GL_INLINE_HEADER_BEGIN #error "Please include config.h first." #endif diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index a7fa7feb62e..8c3d7f7cf80 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/cloexec.h b/lib/cloexec.h index 7a22d775327..15d2d5efe20 100644 --- a/lib/cloexec.h +++ b/lib/cloexec.h @@ -15,8 +15,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - /* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true, or clear the flag if VALUE is false. Return 0 on success, or -1 on error with 'errno' set. diff --git a/lib/close-stream.c b/lib/close-stream.c index 9b0e97b271d..0fdca79bf8e 100644 --- a/lib/close-stream.c +++ b/lib/close-stream.c @@ -20,7 +20,6 @@ #include "close-stream.h" #include -#include #include "fpending.h" diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 354641af0a2..4b4f5d4f9a1 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -43,13 +43,17 @@ extern "C" { # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER -# pragma intrinsic _BitScanReverse -# pragma intrinsic _BitScanReverse64 +# pragma intrinsic (_BitScanReverse) +# if defined _M_X64 +# pragma intrinsic (_BitScanReverse64) +# endif # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ do \ { \ unsigned long result; \ - return MSC_BUILTIN (&result, x) ? result : CHAR_BIT * sizeof x; \ + if (MSC_BUILTIN (&result, x)) \ + return CHAR_BIT * sizeof x - 1 - result; \ + return CHAR_BIT * sizeof x; \ } \ while (0) #else @@ -109,8 +113,18 @@ count_leading_zeros_l (unsigned long int x) COUNT_LEADING_ZEROS_INLINE int count_leading_zeros_ll (unsigned long long int x) { +#if (defined _MSC_VER && !defined __clang__) && !defined _M_X64 + /* 32-bit MSVC does not have _BitScanReverse64, only _BitScanReverse. */ + unsigned long result; + if (_BitScanReverse (&result, (unsigned long) (x >> 32))) + return CHAR_BIT * sizeof x - 1 - 32 - result; + if (_BitScanReverse (&result, (unsigned long) x)) + return CHAR_BIT * sizeof x - 1 - result; + return CHAR_BIT * sizeof x; +#else COUNT_LEADING_ZEROS (__builtin_clzll, _BitScanReverse64, unsigned long long int); +#endif } #ifdef __cplusplus diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h index 9a989a43245..61fbdf29801 100644 --- a/lib/count-trailing-zeros.h +++ b/lib/count-trailing-zeros.h @@ -43,8 +43,10 @@ extern "C" { # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER -# pragma intrinsic _BitScanForward -# pragma intrinsic _BitScanForward64 +# pragma intrinsic (_BitScanForward) +# if defined _M_X64 +# pragma intrinsic (_BitScanForward64) +# endif # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ do \ { \ @@ -101,8 +103,18 @@ count_trailing_zeros_l (unsigned long int x) COUNT_TRAILING_ZEROS_INLINE int count_trailing_zeros_ll (unsigned long long int x) { +#if (defined _MSC_VER && !defined __clang__) && !defined _M_X64 + /* 32-bit MSVC does not have _BitScanForward64, only _BitScanForward. */ + unsigned long result; + if (_BitScanForward (&result, (unsigned long) x)) + return result; + if (_BitScanForward (&result, (unsigned long) (x >> 32))) + return result + 32; + return CHAR_BIT * sizeof x; +#else COUNT_TRAILING_ZEROS (__builtin_ctzll, _BitScanForward64, unsigned long long int); +#endif } #ifdef __cplusplus diff --git a/lib/diffseq.h b/lib/diffseq.h index 0f76ea1d5ad..a8b0e7bd408 100644 --- a/lib/diffseq.h +++ b/lib/diffseq.h @@ -70,7 +70,6 @@ Before including this file, you also need to include: #include - #include #include "minmax.h" */ diff --git a/lib/filevercmp.c b/lib/filevercmp.c index 7e54793e613..844505a6bf7 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -20,11 +20,9 @@ #include #include "filevercmp.h" -#include #include #include #include -#include /* Return the length of a prefix of S that corresponds to the suffix defined by this extended regular expression in the C locale: @@ -75,7 +73,7 @@ order (char const *s, idx_t pos, idx_t len) return -2; else { - verify (UCHAR_MAX <= (INT_MAX - 1 - 2) / 2); + static_assert (UCHAR_MAX <= (INT_MAX - 1 - 2) / 2); return c + UCHAR_MAX + 1; } } diff --git a/lib/fsusage.h b/lib/fsusage.h index 0443d19f922..27085b7b41e 100644 --- a/lib/fsusage.h +++ b/lib/fsusage.h @@ -22,7 +22,6 @@ # define FSUSAGE_H_ # include -# include struct fs_usage { diff --git a/lib/getloadavg.c b/lib/getloadavg.c index 37e82808671..1fddee97afd 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c @@ -82,7 +82,6 @@ #include #include -#include #include # include diff --git a/lib/getrandom.c b/lib/getrandom.c index e1468730933..c05a48167ed 100644 --- a/lib/getrandom.c +++ b/lib/getrandom.c @@ -23,7 +23,6 @@ #include #include -#include #include #if defined _WIN32 && ! defined __CYGWIN__ diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 5bb78740d6a..7eca66a6093 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -180,6 +180,7 @@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ APPLE_UNIVERSAL_BUILD = @APPLE_UNIVERSAL_BUILD@ AR = @AR@ ARFLAGS = @ARFLAGS@ +ASSERT_H = @ASSERT_H@ AUTO_DEPEND = @AUTO_DEPEND@ AWK = @AWK@ BITSIZEOF_PTRDIFF_T = @BITSIZEOF_PTRDIFF_T@ @@ -307,6 +308,7 @@ GL_COND_OBJ_TIME_RZ_CONDITION = @GL_COND_OBJ_TIME_RZ_CONDITION@ GL_COND_OBJ_TIME_R_CONDITION = @GL_COND_OBJ_TIME_R_CONDITION@ GL_COND_OBJ_UTIMENSAT_CONDITION = @GL_COND_OBJ_UTIMENSAT_CONDITION@ GL_GENERATE_ALLOCA_H_CONDITION = @GL_GENERATE_ALLOCA_H_CONDITION@ +GL_GENERATE_ASSERT_H_CONDITION = @GL_GENERATE_ASSERT_H_CONDITION@ GL_GENERATE_BYTESWAP_H_CONDITION = @GL_GENERATE_BYTESWAP_H_CONDITION@ GL_GENERATE_ERRNO_H_CONDITION = @GL_GENERATE_ERRNO_H_CONDITION@ GL_GENERATE_EXECINFO_H_CONDITION = @GL_GENERATE_EXECINFO_H_CONDITION@ @@ -1440,6 +1442,39 @@ EXTRA_DIST += allocator.h endif ## end gnulib module allocator +## begin gnulib module assert-h +ifeq (,$(OMIT_GNULIB_MODULE_assert-h)) + +BUILT_SOURCES += $(ASSERT_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +ifneq (,$(GL_GENERATE_ASSERT_H_CONDITION)) +assert.h: assert.in.h verify.h $(top_builddir)/config.status + $(gl_V_at){ $(SED_HEADER_STDOUT) \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_ASSERT_H''@|$(NEXT_ASSERT_H)|g' \ + < $(srcdir)/assert.in.h && \ + sed -e '/@assert.h omit start@/,/@assert.h omit end@/d' \ + -e 's|_gl_verify|_gl_static_assert|g' \ + -e 's|_GL_VERIFY|_GL_STATIC_ASSERT|g' \ + -e 's|_GL\(_STATIC_ASSERT_H\)|_GL\1|g' \ + < $(srcdir)/verify.h; \ + } > $@-t + $(AM_V_at)mv $@-t $@ +else +assert.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += assert.h assert.h-t + +EXTRA_DIST += assert.in.h verify.h + +endif +## end gnulib module assert-h + ## begin gnulib module at-internal ifeq (,$(OMIT_GNULIB_MODULE_at-internal)) diff --git a/lib/malloc/dynarray.h b/lib/malloc/dynarray.h index f16fd950df6..df1aa4167dd 100644 --- a/lib/malloc/dynarray.h +++ b/lib/malloc/dynarray.h @@ -94,7 +94,6 @@ #ifndef _DYNARRAY_H #define _DYNARRAY_H -#include #include #include diff --git a/lib/md5.c b/lib/md5.c index 57489ed74c5..c16ac4a93a8 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -27,7 +27,6 @@ #endif #include "md5.h" -#include #include #include #include diff --git a/lib/mini-gmp.c b/lib/mini-gmp.c index 95f067f82d6..ea037b801dc 100644 --- a/lib/mini-gmp.c +++ b/lib/mini-gmp.c @@ -1,8 +1,9 @@ /* mini-gmp, a minimalistic implementation of a GNU GMP subset. Contributed to the GNU project by Niels Möller + Additional functionalities and improvements by Marco Bodrato. -Copyright 1991-1997, 1999-2021 Free Software Foundation, Inc. +Copyright 1991-1997, 1999-2022 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -3098,7 +3099,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m) if (en == 0) { - mpz_set_ui (r, 1); + mpz_set_ui (r, mpz_cmpabs_ui (m, 1)); return; } diff --git a/lib/nanosleep.c b/lib/nanosleep.c index 446794edc0b..55d6fa650e3 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -23,9 +23,7 @@ #include #include "intprops.h" -#include "verify.h" -#include #include #include #include @@ -59,7 +57,7 @@ nanosleep (const struct timespec *requested_delay, { /* Verify that time_t is large enough. */ - verify (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60); + static_assert (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60); const time_t limit = 24 * 24 * 60 * 60; time_t seconds = requested_delay->tv_sec; struct timespec intermediate; diff --git a/lib/nstrftime.c b/lib/nstrftime.c index c1dd5542478..37034eb9fb7 100644 --- a/lib/nstrftime.c +++ b/lib/nstrftime.c @@ -65,7 +65,6 @@ extern char *tzname[]; #include #include #include -#include #include "attribute.h" #include diff --git a/lib/openat.h b/lib/openat.h index 56919ef8dc4..c2f64ff50e2 100644 --- a/lib/openat.h +++ b/lib/openat.h @@ -24,7 +24,6 @@ #include #include #include -#include #ifndef _GL_INLINE_HEADER_BEGIN #error "Please include config.h first." diff --git a/lib/pipe2.c b/lib/pipe2.c index 400aff001a2..a3cbb7f2611 100644 --- a/lib/pipe2.c +++ b/lib/pipe2.c @@ -23,7 +23,6 @@ #include #include "binary-io.h" -#include "verify.h" #if GNULIB_defined_O_NONBLOCK # include "nonblocking.h" @@ -95,7 +94,7 @@ pipe2 (int fd[2], int flags) } # else { - verify (O_NONBLOCK == 0); + static_assert (O_NONBLOCK == 0); } # endif diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c index ea68c1bfc6a..bdd7307de4b 100644 --- a/lib/rawmemchr.c +++ b/lib/rawmemchr.c @@ -23,10 +23,8 @@ #if !HAVE_RAWMEMCHR # include -# include # include -# include "verify.h" /* Find the first occurrence of C in S. */ void * @@ -36,7 +34,7 @@ rawmemchr (const void *s, int c_in) typedef uintptr_t longword; /* If you change the "uintptr_t", you should change UINTPTR_WIDTH to match. This verifies that the type does not have padding bits. */ - verify (UINTPTR_WIDTH == UCHAR_WIDTH * sizeof (longword)); + static_assert (UINTPTR_WIDTH == UCHAR_WIDTH * sizeof (longword)); const unsigned char *char_ptr; unsigned char c = c_in; diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 57a455b1f43..784d2d45866 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #ifndef _LIBC diff --git a/lib/sha1.c b/lib/sha1.c index 79e50ba0b03..5a18213edc1 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -29,7 +29,6 @@ #endif #include "sha1.h" -#include #include #include diff --git a/lib/sha256.c b/lib/sha256.c index c9ca618c67e..60cd763612d 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -28,7 +28,6 @@ #endif #include "sha256.h" -#include #include #include diff --git a/lib/sha512.c b/lib/sha512.c index 6776bb464d8..fd17a7dc760 100644 --- a/lib/sha512.c +++ b/lib/sha512.c @@ -28,7 +28,6 @@ #endif #include "sha512.h" -#include #include #include diff --git a/lib/signal.in.h b/lib/signal.in.h index 640b5022f5f..c0d4848db0a 100644 --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -55,13 +55,21 @@ #ifndef _@GUARD_PREFIX@_SIGNAL_H #define _@GUARD_PREFIX@_SIGNAL_H -/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android, +/* For testing the OpenBSD version. */ +#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ + && defined __OpenBSD__ +# include +#endif + +/* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD < 5.1, OSF/1 4.0, Solaris 2.6, Android, OS/2 kLIBC declare pthread_sigmask in , not in . But avoid namespace pollution on glibc systems.*/ #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ && ((defined __APPLE__ && defined __MACH__) \ - || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ \ - || defined __sun || defined __ANDROID__ || defined __KLIBC__) \ + || (defined __FreeBSD__ && __FreeBSD__ < 8) \ + || (defined __OpenBSD__ && OpenBSD < 201205) \ + || defined __osf__ || defined __sun || defined __ANDROID__ \ + || defined __KLIBC__) \ && ! defined __GLIBC__ # include #endif diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h index 3b117df11fe..58fd245c627 100644 --- a/lib/stdalign.in.h +++ b/lib/stdalign.in.h @@ -42,10 +42,7 @@ '-malign-double' is used. The result cannot be used as a value for an 'enum' constant, if you - want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. - - Include for offsetof. */ -#include + want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */ /* FreeBSD 9.1 , included by and lots of other standard headers, defines conflicting implementations of _Alignas @@ -61,17 +58,19 @@ && !defined __clang__) \ || (defined __clang__ && __clang_major__ < 8)) # ifdef __cplusplus -# if 201103 <= __cplusplus +# if (201103 <= __cplusplus || defined _MSC_VER) # define _Alignof(type) alignof (type) # else template struct __alignof_helper { char __a; __t __b; }; # define _Alignof(type) offsetof (__alignof_helper, __b) +# define _GL_STDALIGN_NEEDS_STDDEF 1 # endif # else # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) +# define _GL_STDALIGN_NEEDS_STDDEF 1 # endif #endif -#if ! (defined __cplusplus && 201103 <= __cplusplus) +#if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)) # define alignof _Alignof #endif #define __alignof_is_defined 1 @@ -102,7 +101,7 @@ */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 -# if defined __cplusplus && 201103 <= __cplusplus +# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER) # define _Alignas(a) alignas (a) # elif (!defined __attribute__ \ && ((defined __APPLE__ && defined __MACH__ \ @@ -116,12 +115,19 @@ # define _Alignas(a) __declspec (align (a)) # endif #endif -#if ((defined _Alignas && ! (defined __cplusplus && 201103 <= __cplusplus)) \ +#if ((defined _Alignas \ + && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \ || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) # define alignas _Alignas #endif -#if defined alignas || (defined __cplusplus && 201103 <= __cplusplus) +#if (defined alignas \ + || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) # define __alignas_is_defined 1 #endif +/* Include if needed for offsetof. */ +#if _GL_STDALIGN_NEEDS_STDDEF +# include +#endif + #endif /* _GL_STDALIGN_H */ diff --git a/lib/stdckdint.in.h b/lib/stdckdint.in.h index 90fa62e5966..762d3fdb790 100644 --- a/lib/stdckdint.in.h +++ b/lib/stdckdint.in.h @@ -20,8 +20,6 @@ #include "intprops-internal.h" -#include - /* Store into *R the low-order bits of A + B, A - B, A * B, respectively. Return 1 if the result overflows, 0 otherwise. A, B, and *R can have any integer type other than char, bool, a diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index a86643c3ca3..8e0a609f1f7 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -226,7 +226,7 @@ _GL_FUNCDECL_SYS (aligned_alloc, void *, _GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size)); # endif # endif -# if @HAVE_ALIGNED_ALLOC@ +# if (__GLIBC__ >= 2) && @HAVE_ALIGNED_ALLOC@ _GL_CXXALIASWARN (aligned_alloc); # endif #else @@ -1363,7 +1363,9 @@ _GL_CXXALIAS_SYS (strtol, long, (const char *restrict string, char **restrict endptr, int base)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (strtol); +# endif #elif defined GNULIB_POSIXCHECK # undef strtol # if HAVE_RAW_DECL_STRTOL @@ -1444,7 +1446,9 @@ _GL_CXXALIAS_SYS (strtoul, unsigned long, (const char *restrict string, char **restrict endptr, int base)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (strtoul); +# endif #elif defined GNULIB_POSIXCHECK # undef strtoul # if HAVE_RAW_DECL_STRTOUL diff --git a/lib/string.in.h b/lib/string.in.h index 3996da9fcb5..e56f6db0c9c 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -943,7 +943,9 @@ _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (mbslen); +# endif #endif #if @GNULIB_MBSNLEN@ diff --git a/lib/strtoimax.c b/lib/strtoimax.c index cad12d0d9be..29d16d29cef 100644 --- a/lib/strtoimax.c +++ b/lib/strtoimax.c @@ -25,8 +25,6 @@ #include -#include "verify.h" - #ifdef UNSIGNED # ifndef HAVE_DECL_STRTOULL "this configure-time declaration test was not run" @@ -62,8 +60,8 @@ long long int strtoll (char const *, char **, int); Int Strtoimax (char const *ptr, char **endptr, int base) { - verify (sizeof (Int) == sizeof (Unsigned long int) - || sizeof (Int) == sizeof (Unsigned long long int)); + static_assert (sizeof (Int) == sizeof (Unsigned long int) + || sizeof (Int) == sizeof (Unsigned long long int)); if (sizeof (Int) != sizeof (Unsigned long int)) return Strtoll (ptr, endptr, base); diff --git a/lib/sys_random.in.h b/lib/sys_random.in.h index e730e6139f8..c91bcd2cd04 100644 --- a/lib/sys_random.in.h +++ b/lib/sys_random.in.h @@ -84,7 +84,9 @@ _GL_FUNCDECL_SYS (getrandom, ssize_t, _GL_CXXALIAS_SYS (getrandom, ssize_t, (void *buffer, size_t length, unsigned int flags)); # endif +# if __GLIBC__ + (__GLIBC_MINOR__ >= 25) > 2 _GL_CXXALIASWARN (getrandom); +# endif #elif defined GNULIB_POSIXCHECK # undef getrandom # if HAVE_RAW_DECL_GETRANDOM diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index 2bd0e0f79a8..860e957fe0f 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h @@ -82,9 +82,10 @@ of 'struct timeval', and no definition of this type. Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select() in . - But avoid namespace pollution on glibc systems and "unknown type - name" problems on Cygwin. */ -# if !(defined __GLIBC__ || defined __CYGWIN__) + But avoid namespace pollution on glibc systems, a circular include + -> -> on FreeBSD 13.1, and + "unknown type name" problems on Cygwin. */ +# if !(defined __GLIBC__ || defined __FreeBSD__ || defined __CYGWIN__) # include # endif @@ -287,7 +288,9 @@ _GL_CXXALIAS_SYS_CAST (pselect, int, struct timespec const *restrict, const sigset_t *restrict)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (pselect); +# endif #elif defined GNULIB_POSIXCHECK # undef pselect # if HAVE_RAW_DECL_PSELECT diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index 714c3cb189e..0ec320f58c0 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -596,44 +596,6 @@ _GL_WARN_ON_USE (lchmod, "lchmod is unportable - " #endif -#if @GNULIB_LSTAT@ -# if ! @HAVE_LSTAT@ -/* mingw does not support symlinks, therefore it does not have lstat. But - without links, stat does just fine. */ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define lstat stat -# endif -_GL_CXXALIAS_RPL_1 (lstat, stat, int, - (const char *restrict name, struct stat *restrict buf)); -# elif @REPLACE_LSTAT@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef lstat -# define lstat rpl_lstat -# endif -_GL_FUNCDECL_RPL (lstat, int, - (const char *restrict name, struct stat *restrict buf) - _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (lstat, int, - (const char *restrict name, struct stat *restrict buf)); -# else -_GL_CXXALIAS_SYS (lstat, int, - (const char *restrict name, struct stat *restrict buf)); -# endif -# if @HAVE_LSTAT@ -_GL_CXXALIASWARN (lstat); -# endif -#elif @GNULIB_OVERRIDES_STRUCT_STAT@ -# undef lstat -# define lstat lstat_used_without_requesting_gnulib_module_lstat -#elif defined GNULIB_POSIXCHECK -# undef lstat -# if HAVE_RAW_DECL_LSTAT -_GL_WARN_ON_USE (lstat, "lstat is unportable - " - "use gnulib module lstat for portability"); -# endif -#endif - - #if @GNULIB_MKDIR@ # if @REPLACE_MKDIR@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) @@ -895,6 +857,44 @@ _GL_WARN_ON_USE (stat, "stat is unportable - " #endif +#if @GNULIB_LSTAT@ +# if ! @HAVE_LSTAT@ +/* mingw does not support symlinks, therefore it does not have lstat. But + without links, stat does just fine. */ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define lstat stat +# endif +_GL_CXXALIAS_RPL_1 (lstat, stat, int, + (const char *restrict name, struct stat *restrict buf)); +# elif @REPLACE_LSTAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef lstat +# define lstat rpl_lstat +# endif +_GL_FUNCDECL_RPL (lstat, int, + (const char *restrict name, struct stat *restrict buf) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (lstat, int, + (const char *restrict name, struct stat *restrict buf)); +# else +_GL_CXXALIAS_SYS (lstat, int, + (const char *restrict name, struct stat *restrict buf)); +# endif +# if @HAVE_LSTAT@ +_GL_CXXALIASWARN (lstat); +# endif +#elif @GNULIB_OVERRIDES_STRUCT_STAT@ +# undef lstat +# define lstat lstat_used_without_requesting_gnulib_module_lstat +#elif defined GNULIB_POSIXCHECK +# undef lstat +# if HAVE_RAW_DECL_LSTAT +_GL_WARN_ON_USE (lstat, "lstat is unportable - " + "use gnulib module lstat for portability"); +# endif +#endif + + #if @GNULIB_MDA_UMASK@ /* On native Windows, map 'umask' to '_umask', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between diff --git a/lib/tempname.c b/lib/tempname.c index 11b4796b34b..dbff638f701 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -20,7 +20,6 @@ # include "tempname.h" #endif -#include #include #include diff --git a/lib/time.in.h b/lib/time.in.h index 6d4c7719636..6aa67498f57 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -435,8 +435,10 @@ _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " # endif # if defined GNULIB_POSIXCHECK # undef asctime_r +# if HAVE_RAW_DECL_ASCTIME_R _GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); +# endif # endif # if defined GNULIB_POSIXCHECK # undef ctime @@ -445,8 +447,10 @@ _GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - " # endif # if defined GNULIB_POSIXCHECK # undef ctime_r +# if HAVE_RAW_DECL_CTIME_R _GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); +# endif # endif #endif diff --git a/lib/time_rz.c b/lib/time_rz.c index 1a91d3778e7..601ce5950e8 100644 --- a/lib/time_rz.c +++ b/lib/time_rz.c @@ -27,7 +27,6 @@ #include #include -#include #include #include #include diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 57df09ecdf4..50f6e56550e 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1143,7 +1143,9 @@ _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len) # endif _GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (getdomainname); +# endif #elif defined GNULIB_POSIXCHECK # undef getdomainname # if HAVE_RAW_DECL_GETDOMAINNAME @@ -2055,7 +2057,7 @@ _GL_CXXALIAS_MDA_CAST (swab, void, (char *from, char *to, int n)); # else # if defined __hpux /* HP-UX */ _GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, int n)); -# elif defined __sun && !defined _XPG4 /* Solaris */ +# elif defined __sun && (defined __SunOS_5_10 || defined __XOPEN_OR_POSIX) && !defined _XPG4 /* Solaris */ _GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, ssize_t n)); # else _GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n)); diff --git a/lib/utimens.c b/lib/utimens.c index 2fa12518507..23b91809354 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/lib/verify.h b/lib/verify.h index 47b6ee661b3..99af802993e 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -25,19 +25,19 @@ works as per C11. This is supported by GCC 4.6.0+ and by clang 4+. Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as - per C2x. This is supported by GCC 9.1+. + per C23. This is supported by GCC 9.1+. Support compilers claiming conformance to the relevant standard, and also support GCC when not pedantic. If we were willing to slow 'configure' down we could also use it with other compilers, but since this affects only the quality of diagnostics, why bother? */ #ifndef __cplusplus -# if (201112L <= __STDC_VERSION__ \ +# if (201112 <= __STDC_VERSION__ \ || (!defined __STRICT_ANSI__ \ && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 5 <= __clang_major__))) # define _GL_HAVE__STATIC_ASSERT 1 # endif -# if (202000L <= __STDC_VERSION__ \ +# if (202000 <= __STDC_VERSION__ \ || (!defined __STRICT_ANSI__ && 9 <= __GNUC__)) # define _GL_HAVE__STATIC_ASSERT1 1 # endif @@ -202,12 +202,12 @@ template This macro requires three or more arguments but uses at most the first two, so that the _Static_assert macro optionally defined below supports - both the C11 two-argument syntax and the C2x one-argument syntax. + both the C11 two-argument syntax and the C23 one-argument syntax. Unfortunately, unlike C11, this implementation must appear as an ordinary declaration, and cannot appear inside struct { ... }. */ -#if 200410 <= __cpp_static_assert +#if 202311 <= __STDC_VERSION__ || 200410 <= __cpp_static_assert # define _GL_VERIFY(R, DIAGNOSTIC, ...) static_assert (R, DIAGNOSTIC) #elif defined _GL_HAVE__STATIC_ASSERT # define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC) @@ -223,11 +223,30 @@ template /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ #ifdef _GL_STATIC_ASSERT_H # if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert -# define _Static_assert(...) \ - _GL_VERIFY (__VA_ARGS__, "static assertion failed", -) +# define _Static_assert(R, ...) \ + _GL_VERIFY ((R), "static assertion failed", -) # endif -# if __cpp_static_assert < 201411 && !defined static_assert -# define static_assert _Static_assert /* C11 requires this #define. */ +# if (!defined static_assert \ + && __STDC_VERSION__ < 202311 \ + && (!defined __cplusplus \ + || (__cpp_static_assert < 201411 \ + && __GNUG__ < 6 && __clang_major__ < 6))) +# if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__ +/* MSVC 14 in C++ mode supports the two-arguments static_assert but not + the one-argument static_assert, and it does not support _Static_assert. + We have to play preprocessor tricks to distinguish the two cases. + Since the MSVC preprocessor is not ISO C compliant (cf. + ), the solution is specific + to MSVC. */ +# define _GL_EXPAND(x) x +# define _GL_SA1(a1) static_assert ((a1), "static assertion failed") +# define _GL_SA2 static_assert +# define _GL_SA3 static_assert +# define _GL_SA_PICK(x1,x2,x3,x4,...) x4 +# define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__) +# else +# define static_assert _Static_assert /* C11 requires this #define. */ +# endif # endif #endif @@ -303,7 +322,7 @@ template # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) #elif 1200 <= _MSC_VER # define assume(R) __assume (R) -#elif 202311L <= __STDC_VERSION__ +#elif 202311 <= __STDC_VERSION__ # include # define assume(R) ((R) ? (void) 0 : unreachable ()) #elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP diff --git a/m4/assert_h.m4 b/m4/assert_h.m4 new file mode 100644 index 00000000000..c411a34aa7b --- /dev/null +++ b/m4/assert_h.m4 @@ -0,0 +1,60 @@ +# assert-h.m4 +dnl Copyright (C) 2011-2022 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +AC_DEFUN([gl_ASSERT_H], +[ + AC_CACHE_CHECK([for static_assert], [gl_cv_static_assert], + [gl_save_CFLAGS=$CFLAGS + for gl_working in "yes, a keyword" "yes, an macro"; do + AS_CASE([$gl_working], + [*assert.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_ASSERT_H"]) + + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#if defined __clang__ && __STDC_VERSION__ < 202311 + #pragma clang diagnostic error "-Wc2x-extensions" + #endif + #ifdef INCLUDE_ASSERT_H + #include + #endif + static_assert (2 + 2 == 4, "arithmetic does not work"); + static_assert (2 + 2 == 4); + ]], + [[ + static_assert (sizeof (char) == 1, "sizeof does not work"); + static_assert (sizeof (char) == 1); + ]])], + [gl_cv_static_assert=$gl_working], + [gl_cv_static_assert=no]) + CFLAGS=$gl_save_CFLAGS + test "$gl_cv_static_assert" != no && break + done]) + + GL_GENERATE_ASSERT_H=false + AS_CASE([$gl_cv_static_assert], + [yes*keyword*], + [AC_DEFINE([HAVE_C_STATIC_ASSERT], [1], + [Define to 1 if the static_assert keyword works.])], + [no], + [GL_GENERATE_ASSERT_H=true + gl_NEXT_HEADERS([assert.h])]) + + dnl The "zz" puts this toward config.h's end, to avoid potential + dnl collisions with other definitions. #undef assert so that + dnl programs are not tempted to use it without specifically + dnl including assert.h. Break the #undef apart with a comment + dnl so that 'configure' does not comment it out. + AH_VERBATIM([zzstatic_assert], +[#if (!defined HAVE_C_STATIC_ASSERT && !defined assert \ + && (!defined __cplusplus \ + || (__cpp_static_assert < 201411 \ + && __GNUG__ < 6 && __clang_major__ < 6))) + #include + #undef/**/assert +#endif]) +]) diff --git a/m4/gettime.m4 b/m4/gettime.m4 index f0aeb4d0e4d..c3e0713b575 100644 --- a/m4/gettime.m4 +++ b/m4/gettime.m4 @@ -1,4 +1,4 @@ -# gettime.m4 serial 11 +# gettime.m4 serial 12 dnl Copyright (C) 2002, 2004-2006, 2009-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,7 +9,34 @@ AC_DEFUN([gl_GETTIME], dnl Prerequisites of lib/gettime.c. AC_REQUIRE([gl_CLOCK_TIME]) AC_REQUIRE([gl_TIMESPEC]) - AC_CHECK_FUNCS_ONCE([timespec_get]) + + AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET]) + if test $gl_cv_func_timespec_get = yes; then + AC_DEFINE([HAVE_TIMESPEC_GET], [1], + [Define if you have the timespec_get function.]) + fi +]) + +dnl Tests whether the function timespec_get exists. +dnl Sets gl_cv_func_timespec_get. +AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET], +[ + dnl Persuade OpenBSD to declare timespec_get(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + dnl We can't use AC_CHECK_FUNC here, because timespec_get() is defined as a + dnl static inline function in on MSVC 14. + AC_CACHE_CHECK([for timespec_get], [gl_cv_func_timespec_get], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include + struct timespec ts; + ]], + [[return timespec_get (&ts, 0);]]) + ], + [gl_cv_func_timespec_get=yes], + [gl_cv_func_timespec_get=no]) + ]) ]) AC_DEFUN([gl_GETTIME_RES], diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 8a5daa230e3..d17cbec58cb 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 73 +# gnulib-common.m4 serial 74 dnl Copyright (C) 2007-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -115,7 +115,7 @@ AC_DEFUN([gl_COMMON_BODY], [ # define _GL_HAS_C_ATTRIBUTE(attr) 0 #endif -]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead. +]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead. [ /* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function is the size of the returned memory block. diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 0c43dde716c..6a5f3006781 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -46,6 +46,7 @@ AC_DEFUN([gl_EARLY], # Code from module acl-permissions: # Code from module alloca-opt: # Code from module allocator: + # Code from module assert-h: # Code from module at-internal: # Code from module attribute: # Code from module binary-io: @@ -122,8 +123,8 @@ AC_DEFUN([gl_EARLY], # Code from module intprops: # Code from module inttypes-incomplete: # Code from module largefile: - AC_REQUIRE([AC_SYS_LARGEFILE]) AC_REQUIRE([gl_YEAR2038_EARLY]) + AC_REQUIRE([AC_SYS_LARGEFILE]) # Code from module lchmod: # Code from module libc-config: # Code from module libgmp: @@ -233,6 +234,9 @@ AC_DEFUN([gl_INIT], gl_FUNC_ALLOCA gl_CONDITIONAL_HEADER([alloca.h]) AC_PROG_MKDIR_P + gl_ASSERT_H + gl_CONDITIONAL_HEADER([assert.h]) + AC_PROG_MKDIR_P gl___BUILTIN_EXPECT gl_BYTESWAP gl_CONDITIONAL_HEADER([byteswap.h]) @@ -1214,6 +1218,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/allocator.c lib/allocator.h lib/arg-nonnull.h + lib/assert.in.h lib/at-func.c lib/attribute.h lib/binary-io.c @@ -1420,6 +1425,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/absolute-header.m4 m4/acl.m4 m4/alloca.m4 + m4/assert_h.m4 m4/builtin-expect.m4 m4/byteswap.m4 m4/canonicalize.m4 diff --git a/m4/nanosleep.m4 b/m4/nanosleep.m4 index 1964b1ea47d..dfe21f56d5c 100644 --- a/m4/nanosleep.m4 +++ b/m4/nanosleep.m4 @@ -1,4 +1,4 @@ -# serial 41 +# serial 42 dnl From Jim Meyering. dnl Check for the nanosleep function. @@ -100,15 +100,22 @@ AC_DEFUN([gl_FUNC_NANOSLEEP], #else /* A simpler test for native Windows. */ if (nanosleep (&ts_sleep, &ts_remaining) < 0) return 3; + /* Test for 32-bit mingw bug: negative nanosecond values do not + cause failure. */ + ts_sleep.tv_sec = 1; + ts_sleep.tv_nsec = -1; + if (nanosleep (&ts_sleep, &ts_remaining) != -1) + return 7; #endif return 0; }]])], [gl_cv_func_nanosleep=yes], - [case $? in dnl ( - 4|5|6) gl_cv_func_nanosleep='no (mishandles large arguments)';; dnl ( - *) gl_cv_func_nanosleep=no;; + [case $? in + 4|5|6) gl_cv_func_nanosleep='no (mishandles large arguments)' ;; + 7) gl_cv_func_nanosleep='no (mishandles negative tv_nsec)' ;; + *) gl_cv_func_nanosleep=no ;; esac], - [case "$host_os" in dnl (( + [case "$host_os" in linux*) # Guess it halfway works when the kernel is Linux. gl_cv_func_nanosleep='guessing no (mishandles large arguments)' ;; mingw*) # Guess no on native Windows. diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index 78577cb2acc..324e91dae2e 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -1,4 +1,4 @@ -# Check for stdalign.h that conforms to C11. +# Check for alignas and alignof that conform to C23. dnl Copyright 2011-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation @@ -9,12 +9,18 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_STDALIGN_H], [ - AC_CACHE_CHECK([for working stdalign.h], + AC_CACHE_CHECK([for alignas and alignof], [gl_cv_header_working_stdalign_h], - [AC_COMPILE_IFELSE( + [gl_save_CFLAGS=$CFLAGS + for gl_working in "yes, keywords" "yes, macros"; do + AS_CASE([$gl_working], + [*stdalign.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_STDALIGN_H"]) + AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[#include - #include + #ifdef INCLUDE_STDALIGN_H + #include + #endif #include /* Test that alignof yields a result consistent with offsetof. @@ -30,7 +36,7 @@ AC_DEFUN([gl_STDALIGN_H], char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1]; char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1]; - /* Test _Alignas only on platforms where gnulib can help. */ + /* Test alignas only on platforms where gnulib can help. */ #if \ ((defined __cplusplus && 201103 <= __cplusplus) \ || (__TINYC__ && defined __attribute__) \ @@ -45,12 +51,84 @@ AC_DEFUN([gl_STDALIGN_H], ? 1 : -1]; #endif ]])], - [gl_cv_header_working_stdalign_h=yes], - [gl_cv_header_working_stdalign_h=no])]) - - if test $gl_cv_header_working_stdalign_h = yes; then - GL_GENERATE_STDALIGN_H=false - else - GL_GENERATE_STDALIGN_H=true - fi + [gl_cv_header_working_stdalign_h=$gl_working], + [gl_cv_header_working_stdalign_h=no]) + + CFLAGS=$gl_save_CFLAGS + test "$gl_cv_header_working_stdalign_h" != no && break + done]) + + GL_GENERATE_STDALIGN_H=false + AS_CASE([$gl_cv_header_working_stdalign_h], + [no], + [GL_GENERATE_STDALIGN_H=true], + [yes*keyword*], + [AC_DEFINE([HAVE_C_ALIGNASOF], [1], + [Define to 1 if the alignas and alignof keywords work.])]) + + AC_CHECK_HEADERS_ONCE([stdalign.h]) + + dnl The "zz" puts this toward config.h's end, to avoid potential + dnl collisions with other definitions. + AH_VERBATIM([zzalignas], +[#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof +# if HAVE_STDALIGN_H +# include +# else + /* Substitute. Keep consistent with gnulib/lib/stdalign.in.h. */ +# ifndef _GL_STDALIGN_H +# define _GL_STDALIGN_H +# undef _Alignas +# undef _Alignof +# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \ + || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \ + && !defined __clang__) \ + || (defined __clang__ && __clang_major__ < 8)) +# ifdef __cplusplus +# if (201103 <= __cplusplus || defined _MSC_VER) +# define _Alignof(type) alignof (type) +# else + template struct __alignof_helper { char __a; __t __b; }; +# define _Alignof(type) offsetof (__alignof_helper, __b) +# define _GL_STDALIGN_NEEDS_STDDEF 1 +# endif +# else +# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) +# define _GL_STDALIGN_NEEDS_STDDEF 1 +# endif +# endif +# if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)) +# define alignof _Alignof +# endif +# define __alignof_is_defined 1 +# if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 +# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER) +# define _Alignas(a) alignas (a) +# elif (!defined __attribute__ \ + && ((defined __APPLE__ && defined __MACH__ \ + ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \ + : __GNUC__ && !defined __ibmxl__) \ + || (4 <= __clang_major__) \ + || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \ + || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__)) +# define _Alignas(a) __attribute__ ((__aligned__ (a))) +# elif 1300 <= _MSC_VER +# define _Alignas(a) __declspec (align (a)) +# endif +# endif +# if ((defined _Alignas \ + && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \ + || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) +# define alignas _Alignas +# endif +# if (defined alignas \ + || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) +# define __alignas_is_defined 1 +# endif +# if _GL_STDALIGN_NEEDS_STDDEF +# include +# endif +# endif /* _GL_STDALIGN_H */ +# endif +#endif]) ]) diff --git a/m4/time_h.m4 b/m4/time_h.m4 index 98d7b6e01bd..4ac8fd00752 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -2,7 +2,7 @@ # Copyright (C) 2000-2001, 2003-2007, 2009-2022 Free Software Foundation, Inc. -# serial 19 +# serial 20 # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -19,6 +19,12 @@ AC_DEFUN_ONCE([gl_TIME_H], gl_NEXT_HEADERS([time.h]) AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +#include + ]], [asctime_r ctime_r]) + AC_REQUIRE([AC_C_RESTRICT]) AC_CACHE_CHECK([for TIME_UTC in ],