diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-09-30 12:14:04 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-09-30 12:38:52 -0700 |
commit | f4eb8900295d75c4afec256f75aea22494376fde (patch) | |
tree | 70203645e9b0b603ef8dbca6c50c01795a081512 /src | |
parent | d1890a3a4a18f79cabf4caf8d194cdc29ea4bf05 (diff) | |
download | emacs-f4eb8900295d75c4afec256f75aea22494376fde.tar.gz |
Limit <config.h>’s includes
This follows up on recent problems with the fact that config.h
includes stdlib.h etc.; some files need to include stdlib.h later.
config.h generally should limit itself to includes that are
universally safe; outside of MS-Windows, only stdbool.h makes
the cut among the files currently included. So, move the
other includes to just the files that need them (Bug#24506).
* configure.ac (config_opsysfile): Remove, as this generic hook
is no longer needed.
* lib-src/etags.c, src/unexmacosx.c, src/w32.c, src/w32notify.c:
* src/w32proc.c (_GNU_SOURCE):
Remove, as it’s OK for config.h to do this now.
* src/conf_post.h: Include <ms-w32.h>, instead of the generic
config_opsysfile, for simplicity as this old way of configuring is
now done only for the MS-Windows port. Do not include <ms-w32.h>
if DEFER_MS_W32_H, for the benefit of the few files that want its
effects later. Do not include <alloca.h>, <string.h>, or
<stdlib.h>. Other files modified to include these headers as
needed, or to not include headers that are no longer needed.
* src/lisp.h: Include <alloca.h> and <string.h> here, since
some of the inline functions need them.
* src/regex.c: Include <alloca.h> if not emacs. (If emacs,
we can rely on SAFE_ALLOCA.) There is no longer any need to
worry about HAVE_ALLOCA_H.
* src/unexmacosx.c: Rely on config.h not including stdlib.h.
* src/w32.c, src/w32notify.c, src/w32proc.c (DEFER_MS_W32_H):
Define before including <config.h> first, and include <ms-w32.h>
after the troublesome headers.
Diffstat (limited to 'src')
-rw-r--r-- | src/alloc.c | 1 | ||||
-rw-r--r-- | src/buffer.c | 1 | ||||
-rw-r--r-- | src/callproc.c | 1 | ||||
-rw-r--r-- | src/charset.c | 1 | ||||
-rw-r--r-- | src/conf_post.h | 36 | ||||
-rw-r--r-- | src/dbusbind.c | 1 | ||||
-rw-r--r-- | src/dispnew.c | 1 | ||||
-rw-r--r-- | src/doprnt.c | 1 | ||||
-rw-r--r-- | src/editfns.c | 1 | ||||
-rw-r--r-- | src/emacs-module.c | 2 | ||||
-rw-r--r-- | src/emacs.c | 1 | ||||
-rw-r--r-- | src/eval.c | 1 | ||||
-rw-r--r-- | src/filelock.c | 1 | ||||
-rw-r--r-- | src/fns.c | 1 | ||||
-rw-r--r-- | src/font.c | 1 | ||||
-rw-r--r-- | src/fontset.c | 1 | ||||
-rw-r--r-- | src/frame.c | 1 | ||||
-rw-r--r-- | src/keymap.c | 1 | ||||
-rw-r--r-- | src/lisp.h | 2 | ||||
-rw-r--r-- | src/lread.c | 1 | ||||
-rw-r--r-- | src/process.c | 1 | ||||
-rw-r--r-- | src/regex.c | 16 | ||||
-rw-r--r-- | src/sysdep.c | 1 | ||||
-rw-r--r-- | src/systty.h | 1 | ||||
-rw-r--r-- | src/term.c | 1 | ||||
-rw-r--r-- | src/unexcw.c | 1 | ||||
-rw-r--r-- | src/unexmacosx.c | 14 | ||||
-rw-r--r-- | src/w32.c | 8 | ||||
-rw-r--r-- | src/w32notify.c | 8 | ||||
-rw-r--r-- | src/w32proc.c | 8 | ||||
-rw-r--r-- | src/widget.c | 1 | ||||
-rw-r--r-- | src/xdisp.c | 1 | ||||
-rw-r--r-- | src/xfaces.c | 1 | ||||
-rw-r--r-- | src/xfns.c | 1 | ||||
-rw-r--r-- | src/xfont.c | 1 | ||||
-rw-r--r-- | src/xgselect.c | 1 | ||||
-rw-r--r-- | src/xterm.c | 1 |
37 files changed, 59 insertions, 64 deletions
diff --git a/src/alloc.c b/src/alloc.c index 8dae6bffbd9..72987dd3190 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <limits.h> /* For CHAR_BIT. */ #include <signal.h> /* For SIGABRT, SIGDANGER. */ diff --git a/src/buffer.c b/src/buffer.c index 24c997fcdbd..3d205bb71ba 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -25,6 +25,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/param.h> #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <verify.h> diff --git a/src/callproc.c b/src/callproc.c index 454ed6d633c..8ed28556e0d 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <sys/types.h> #include <unistd.h> diff --git a/src/charset.c b/src/charset.c index cdbfe119515..ff937bc5a13 100644 --- a/src/charset.c +++ b/src/charset.c @@ -30,6 +30,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <limits.h> #include <sys/types.h> diff --git a/src/conf_post.h b/src/conf_post.h index 6d54524b970..9c544e89e94 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -18,22 +18,23 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ -/* Commentary: +/* Put the code here rather than in configure.ac using AH_BOTTOM. + This way, the code does not get processed by autoheader. For + example, undefs here are not commented out. - Rather than writing this code directly in AH_BOTTOM, we include it - via this file. This is so that it does not get processed by - autoheader. Eg, any undefs here would otherwise be commented out. -*/ + To help make dependencies clearer elsewhere, this file typically + does not #include other files. The exceptions are first stdbool.h + because it is unlikely to interfere with configuration and bool is + such a core part of the C language, and second ms-w32.h (DOS_NT + only) because it historically was included here and changing that + would take some work. */ -/* Code: */ +#include <stdbool.h> -/* Include any platform specific configuration file. */ -#ifdef config_opsysfile -# include config_opsysfile +#if defined DOS_NT && !defined DEFER_MS_W32_H +# include <ms-w32.h> #endif -#include <stdbool.h> - /* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later. It can be used in a preprocessor expression. */ #ifndef __GNUC_MINOR__ @@ -55,14 +56,6 @@ typedef unsigned int bool_bf; typedef bool bool_bf; #endif -#ifndef WINDOWSNT -/* On AIX 3 this must be included before any other include file. */ -#include <alloca.h> -#if ! HAVE_ALLOCA -# error "alloca not available on this machine" -#endif -#endif - /* Simulate __has_attribute on compilers that lack it. It is used only on arguments like alloc_size that are handled in this simulation. */ #ifndef __has_attribute @@ -239,9 +232,6 @@ extern void _DebPrint (const char *fmt, ...); extern char *emacs_getenv_TZ (void); extern int emacs_setenv_TZ (char const *); -#include <string.h> -#include <stdlib.h> - #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */ #define NO_INLINE __attribute__((noinline)) #else @@ -365,5 +355,3 @@ extern int emacs_setenv_TZ (char const *); #else # define UNINIT /* empty */ #endif - -/* conf_post.h ends here */ diff --git a/src/dbusbind.c b/src/dbusbind.c index 7a94c81eeab..a0146a3bf53 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_DBUS #include <stdio.h> +#include <stdlib.h> #include <dbus/dbus.h> #include "lisp.h" diff --git a/src/dispnew.c b/src/dispnew.c index 82d0b76a95f..70d4de07aac 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include "sysstdio.h" +#include <stdlib.h> #include <unistd.h> #include "lisp.h" diff --git a/src/doprnt.c b/src/doprnt.c index de2b89e1225..73380050059 100644 --- a/src/doprnt.c +++ b/src/doprnt.c @@ -103,6 +103,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include <float.h> #include <unistd.h> #include <limits.h> diff --git a/src/editfns.c b/src/editfns.c index c5b177e41f2..0bcc439e50e 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -49,6 +49,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <limits.h> #include <intprops.h> +#include <stdlib.h> #include <strftime.h> #include <verify.h> diff --git a/src/emacs-module.c b/src/emacs-module.c index 0e755ef956b..5075263edff 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -21,11 +21,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "emacs-module.h" -#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> -#include <string.h> #include "lisp.h" #include "dynlib.h" diff --git a/src/emacs.c b/src/emacs.c index 9b2300989fa..13378c4c3b0 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -24,6 +24,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/file.h> diff --git a/src/eval.c b/src/eval.c index 407561082d1..2fedbf377cf 100644 --- a/src/eval.c +++ b/src/eval.c @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <limits.h> #include <stdio.h> +#include <stdlib.h> #include "lisp.h" #include "blockinput.h" #include "commands.h" diff --git a/src/filelock.c b/src/filelock.c index bde34e2c6c2..a2e1df99f07 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -27,6 +27,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/stat.h> #include <signal.h> #include <stdio.h> +#include <stdlib.h> #ifdef HAVE_PWD_H #include <pwd.h> diff --git a/src/fns.c b/src/fns.c index 31f0fd27418..4f12dd52249 100644 --- a/src/fns.c +++ b/src/fns.c @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> +#include <stdlib.h> #include <unistd.h> #include <filevercmp.h> #include <intprops.h> diff --git a/src/font.c b/src/font.c index f2800633b62..cfbc5c7e266 100644 --- a/src/font.c +++ b/src/font.c @@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <float.h> #include <stdio.h> +#include <stdlib.h> #include <c-ctype.h> diff --git a/src/fontset.c b/src/fontset.c index 67696d0fead..fe595d81a3e 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include "lisp.h" #include "blockinput.h" diff --git a/src/frame.c b/src/frame.c index 42a01f57724..45559b0be98 100644 --- a/src/frame.c +++ b/src/frame.c @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <limits.h> diff --git a/src/keymap.c b/src/keymap.c index b27df1d0452..c4a59adff5b 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -41,6 +41,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include "lisp.h" #include "commands.h" diff --git a/src/lisp.h b/src/lisp.h index f653d855dad..74308985f18 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -21,10 +21,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #ifndef EMACS_LISP_H #define EMACS_LISP_H +#include <alloca.h> #include <setjmp.h> #include <stdalign.h> #include <stdarg.h> #include <stddef.h> +#include <string.h> #include <float.h> #include <inttypes.h> #include <limits.h> diff --git a/src/lread.c b/src/lread.c index d3413d16cea..10eec3b1be0 100644 --- a/src/lread.c +++ b/src/lread.c @@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include "sysstdio.h" +#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/file.h> diff --git a/src/process.c b/src/process.c index 9a0ab00c505..8cf045ca9c2 100644 --- a/src/process.c +++ b/src/process.c @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <sys/types.h> /* Some typedefs are used in sys/file.h. */ #include <sys/file.h> diff --git a/src/regex.c b/src/regex.c index 41c1d3f6106..1917a8480ae 100644 --- a/src/regex.c +++ b/src/regex.c @@ -50,6 +50,7 @@ #include <config.h> #include <stddef.h> +#include <stdlib.h> #ifdef emacs /* We need this for `regex.h', and perhaps for the Emacs include files. */ @@ -443,25 +444,12 @@ init_syntax_once (void) #else /* not REGEX_MALLOC */ -/* Emacs already defines alloca, sometimes. */ -# ifndef alloca - -/* Make alloca work the best possible way. */ -# ifdef __GNUC__ -# define alloca __builtin_alloca -# else /* not __GNUC__ */ -# ifdef HAVE_ALLOCA_H -# include <alloca.h> -# endif /* HAVE_ALLOCA_H */ -# endif /* not __GNUC__ */ - -# endif /* not alloca */ - # ifdef emacs # define REGEX_USE_SAFE_ALLOCA USE_SAFE_ALLOCA # define REGEX_SAFE_FREE() SAFE_FREE () # define REGEX_ALLOCATE SAFE_ALLOCA # else +# include <alloca.h> # define REGEX_ALLOCATE alloca # endif diff --git a/src/sysdep.c b/src/sysdep.c index 190d6fbe920..0121f01631c 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <grp.h> #endif /* HAVE_PWD_H */ #include <limits.h> +#include <stdlib.h> #include <unistd.h> #include <c-ctype.h> diff --git a/src/systty.h b/src/systty.h index fbdc6b18373..a53c874699f 100644 --- a/src/systty.h +++ b/src/systty.h @@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <fcntl.h> #endif /* not DOS_NT */ -#include <stdbool.h> #include <sys/ioctl.h> #ifdef HPUX diff --git a/src/term.c b/src/term.c index c22d07ac579..d691a7aa101 100644 --- a/src/term.c +++ b/src/term.c @@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <stdlib.h> #include <sys/file.h> #include <sys/time.h> #include <unistd.h> diff --git a/src/unexcw.c b/src/unexcw.c index 6343b38bcff..c0d1bc176a5 100644 --- a/src/unexcw.c +++ b/src/unexcw.c @@ -21,7 +21,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include "unexec.h" #include "lisp.h" -#include <string.h> #include <stdio.h> #include <fcntl.h> #include <a.out.h> diff --git a/src/unexmacosx.c b/src/unexmacosx.c index 185a9d1f62b..ea8e884f177 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -85,20 +85,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ be changed accordingly. */ -/* Enable GNU extensions in gnulib replacement headers. */ -#define _GNU_SOURCE 1 - -/* config.h #define:s malloc/realloc/free and then includes stdlib.h. - We want the undefined versions, but if config.h includes stdlib.h - with the #define:s in place, the prototypes will be wrong and we get - warnings. To prevent that, include stdlib.h before config.h. */ - -#include <stdlib.h> #include <config.h> + +/* Although <config.h> redefines malloc to unexec_malloc, etc., this + file wants stdlib.h to declare the originals. */ #undef malloc #undef realloc #undef free +#include <stdlib.h> + #include "unexec.h" #include "lisp.h" diff --git a/src/w32.c b/src/w32.c index 6cb8e748bd5..e0a34060f0a 100644 --- a/src/w32.c +++ b/src/w32.c @@ -21,8 +21,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ Geoff Voelker (voelker@cs.washington.edu) 7-29-94 */ -/* Enable GNU extensions in gnulib replacement headers. */ -#define _GNU_SOURCE 1 +#define DEFER_MS_W32_H +#include <config.h> #include <mingw_time.h> #include <stddef.h> /* for offsetof */ @@ -40,9 +40,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/utime.h> #include <math.h> -/* must include CRT headers *before* config.h */ +/* Include CRT headers *before* ms-w32.h. */ +#include <ms-w32.h> -#include <config.h> #include <mbstring.h> /* for _mbspbrk, _mbslwr, _mbsrchr, ... */ #undef access diff --git a/src/w32notify.c b/src/w32notify.c index 15e8a86cf17..32a03f70a66 100644 --- a/src/w32notify.c +++ b/src/w32notify.c @@ -81,14 +81,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ thread to exit. The main thread waits for some time for the worker thread to exit, and if it doesn't, terminates it forcibly. */ -/* Enable GNU extensions in gnulib replacement headers. */ -#define _GNU_SOURCE 1 +#define DEFER_MS_W32_H +#include <config.h> #include <stddef.h> #include <errno.h> -/* must include CRT headers *before* config.h */ -#include <config.h> +/* Include CRT headers *before* ms-w32.h. */ +#include <ms-w32.h> #include <windows.h> diff --git a/src/w32proc.c b/src/w32proc.c index e23b1b3563c..aef4e44d73a 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -22,8 +22,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ Adapted from alarm.c by Tim Fleehart */ -/* Enable GNU extensions in gnulib replacement headers. */ -#define _GNU_SOURCE 1 +#define DEFER_MS_W32_H +#include <config.h> #include <mingw_time.h> #include <stdio.h> @@ -38,8 +38,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <mbstring.h> #include <locale.h> -/* must include CRT headers *before* config.h */ -#include <config.h> +/* Include CRT headers *before* ms-w32.h. */ +#include <ms-w32.h> #undef signal #undef wait diff --git a/src/widget.c b/src/widget.c index 28bb475ddfa..59ed431e23b 100644 --- a/src/widget.c +++ b/src/widget.c @@ -32,6 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "widget.h" #include <stdio.h> +#include <stdlib.h> #include "lisp.h" #include "xterm.h" diff --git a/src/xdisp.c b/src/xdisp.c index 13af87f953c..e8061663f86 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -288,6 +288,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include <limits.h> #include "lisp.h" diff --git a/src/xfaces.c b/src/xfaces.c index 056f90cb7ac..5837f35d7b6 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -200,6 +200,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ used to fill in unspecified attributes of the default face. */ #include <config.h> +#include <stdlib.h> #include "sysstdio.h" #include <sys/types.h> #include <sys/stat.h> diff --git a/src/xfns.c b/src/xfns.c index dd39e782fac..8571d0e20ab 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include <math.h> #include <unistd.h> diff --git a/src/xfont.c b/src/xfont.c index 8fbe94c01ab..45b0e0a5f53 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #include <X11/Xlib.h> #include "lisp.h" diff --git a/src/xgselect.c b/src/xgselect.c index ac88afdd54b..7850a16e9c0 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -25,7 +25,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <glib.h> #include <errno.h> -#include <stdbool.h> #include "blockinput.h" #include "systime.h" diff --git a/src/xterm.c b/src/xterm.c index 4c14e62058f..747669446f5 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> #ifdef USE_CAIRO #include <math.h> #endif |