diff options
author | Zack Weinberg <zackw@panix.com> | 2020-12-06 11:40:39 -0500 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2020-12-06 11:40:39 -0500 |
commit | b045574cb2ea1c8441be7a7b56fd471d704ebf3a (patch) | |
tree | 4e93553716d40939551f142b3b2121f5cbe59a42 /lib/autoconf/headers.m4 | |
parent | c467efab94cd2d0331655d68d067fa0719fc8762 (diff) | |
download | autoconf-b045574cb2ea1c8441be7a7b56fd471d704ebf3a.tar.gz |
AC_INCLUDES_DEFAULT: Check for presence of C90 hosted headers (#110393)
Since 1993, Autoconf has been assuming that it is safe to include any
of the headers defined by ISO C90 without checking for them; this is
inaccurate, since only a subset are necessarily available in a
C90 *freestanding* environment.
It is OK to assume the presence of a header in a macro that checks
specifically for something declared by that header (if the header is
not present, we will think the specific declaration is unavailable,
which is probably accurate for modern embedded environments). It is
also OK to continue recommending that user code use these headers
unconditionally—anyone working with a freestanding environment knows
it. But it is not OK for very generic code within Autoconf itself,
such as AC_INCLUDES_DEFAULT, to make this assumption.
Note that the set of headers that are not always available includes
stdio.h, which we have been assuming can be included unconditionally
for even longer.
In AC_INCLUDES_DEFAULT, revert to checking for string.h and stdlib.h
before including them. Also revert to defining STDC_HEADERS only when
string.h and stdlib.h are available (but do not check for float.h and
stdarg.h, as these are part of the freestanding set). Add a new check
for stdio.h. Sort the inclusion list by standard (C90 freestanding;
C90 hosted; C99; POSIX) and alphabetically within each group. Revise
all the documentation and update the testsuite.
This partially reverts commit 86c213d0e355296f026a36e3203c0813041aae89
and is a partial fix for bug #110393.
* lib/autoconf/headers.m4 (AC_CHECK_INCLUDES_DEFAULT): Check for
stdio.h, stdlib.h, and string.h before including them. Define
STDC_HEADERS only when string.h and stdlib.h are both available.
Organize includes list by standard, then alphabetically.
* doc/autoconf.texi, NEWS: Update to match.
* tests/local.at (AT_CHECK_DEFINES): Make regexes more specific.
Also expect a definition of HAVE_STDIO_H.
* tests/c.at, tests/semantics.at, tests/tools.at: Use <float.h>,
not <stdio.h>, as a header that we expect always to exist.
Add HAVE_STDIO_H to various lists of macros that are expected to
appear in config.h.
Diffstat (limited to 'lib/autoconf/headers.m4')
-rw-r--r-- | lib/autoconf/headers.m4 | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4 index 17a5abac..bc70e0b6 100644 --- a/lib/autoconf/headers.m4 +++ b/lib/autoconf/headers.m4 @@ -293,17 +293,14 @@ dnl If ever you change this variable, please keep autoconf.texi in sync. [# Factoring default headers for most tests. ac_includes_default="\ #include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#ifdef HAVE_SYS_TYPES_H -# include <sys/types.h> +#ifdef HAVE_STDIO_H +# include <stdio.h> #endif -#ifdef HAVE_SYS_STAT_H -# include <sys/stat.h> +#ifdef HAVE_STDLIB_H +# include <stdlib.h> #endif -#ifdef HAVE_STRINGS_H -# include <strings.h> +#ifdef HAVE_STRING_H +# include <string.h> #endif #ifdef HAVE_INTTYPES_H # include <inttypes.h> @@ -311,24 +308,30 @@ ac_includes_default="\ #ifdef HAVE_STDINT_H # include <stdint.h> #endif +#ifdef HAVE_STRINGS_H +# include <strings.h> +#endif +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif #ifdef HAVE_UNISTD_H # include <unistd.h> #endif" ])]dnl -[m4_map_args([_AC_CHECK_HEADER_ONCE], - [sys/types.h], [sys/stat.h], [strings.h], - [inttypes.h], [stdint.h], [unistd.h])]dnl -dnl For backward compatibility, provide unconditional AC_DEFINEs of -dnl HAVE_STDLIB_H, HAVE_STRING_H, and STDC_HEADERS. -[AC_DEFINE([HAVE_STDLIB_H], [1], - [Always define to 1, for backward compatibility. - You can assume <stdlib.h> exists.])]dnl -[AC_DEFINE([HAVE_STRING_H], [1], - [Always define to 1, for backward compatibility. - You can assume <string.h> exists.])]dnl +[dnl We have to check for all the headers that aren't part of the +dnl C-1990 *freestanding* environment, which is all of them except stddef.h. +m4_map_args([_AC_CHECK_HEADER_ONCE], + [stdio.h], [stdlib.h], [string.h], [inttypes.h], [stdint.h], + [strings.h], [sys/stat.h], [sys/types.h], [unistd.h])]dnl +[AS_IF([test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes], [AC_DEFINE([STDC_HEADERS], [1], - [Always define to 1, for backward compatibility. - You can assume the C90 standard headers exist.])]) + [Define to 1 if all of the C90 standard headers exist + (not just the ones required in a freestanding environment). + This macro is provided for backward compatibility; + new code need not use it.])])]) # AC_CHECK_INCLUDES_DEFAULT |