; Update ChangeLog.2 and AUTHORS files
[emacs.git] / src / conf_post.h
blob893b6b9c56c50443480559b727a2f8f4e6bf5c79
1 /* conf_post.h --- configure.ac includes this via AH_BOTTOM
3 Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2017 Free Software
4 Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or (at
11 your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* Commentary:
23 Rather than writing this code directly in AH_BOTTOM, we include it
24 via this file. This is so that it does not get processed by
25 autoheader. Eg, any undefs here would otherwise be commented out.
28 /* Code: */
30 /* Include any platform specific configuration file. */
31 #ifdef config_opsysfile
32 # include config_opsysfile
33 #endif
35 #include <stdbool.h>
37 /* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later.
38 It can be used in a preprocessor expression. */
39 #ifndef __GNUC_MINOR__
40 # define GNUC_PREREQ(v, w, x) false
41 #elif ! defined __GNUC_PATCHLEVEL__
42 # define GNUC_PREREQ(v, w, x) ((v) < __GNUC__ + ((w) <= __GNUC_MINOR__))
43 #else
44 # define GNUC_PREREQ(v, w, x) \
45 ((v) < __GNUC__ + ((w) <= __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__)))
46 #endif
48 /* The type of bool bitfields. Needed to compile Objective-C with
49 standard GCC. It was also needed to port to pre-C99 compilers,
50 although we don't care about that any more. */
51 #if NS_IMPL_GNUSTEP
52 typedef unsigned int bool_bf;
53 #else
54 typedef bool bool_bf;
55 #endif
57 #ifndef WINDOWSNT
58 /* On AIX 3 this must be included before any other include file. */
59 #include <alloca.h>
60 #if ! HAVE_ALLOCA
61 # error "alloca not available on this machine"
62 #endif
63 #endif
65 /* Simulate __has_attribute on compilers that lack it. It is used only
66 on arguments like alloc_size that are handled in this simulation. */
67 #ifndef __has_attribute
68 # define __has_attribute(a) __has_attribute_##a
69 # define __has_attribute_alloc_size (4 < __GNUC__ + (3 <= __GNUC_MINOR__))
70 # define __has_attribute_cleanup (3 < __GNUC__ + (4 <= __GNUC_MINOR__))
71 # define __has_attribute_externally_visible \
72 (4 < __GNUC__ + (1 <= __GNUC_MINOR__))
73 # define __has_attribute_no_address_safety_analysis false
74 # define __has_attribute_no_sanitize_address \
75 (4 < __GNUC__ + (8 <= __GNUC_MINOR__))
76 #endif
78 /* Simulate __has_feature on compilers that lack it. It is used only
79 to define ADDRESS_SANITIZER below. */
80 #ifndef __has_feature
81 # define __has_feature(a) false
82 #endif
84 /* True if addresses are being sanitized. */
85 #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
86 # define ADDRESS_SANITIZER true
87 #else
88 # define ADDRESS_SANITIZER false
89 #endif
91 #ifdef DARWIN_OS
92 #ifdef emacs
93 #define malloc unexec_malloc
94 #define realloc unexec_realloc
95 #define free unexec_free
96 #endif
97 /* The following solves the problem that Emacs hangs when evaluating
98 (make-comint "test0" "/nodir/nofile" nil "") when /nodir/nofile
99 does not exist. Also, setsid is not allowed in the vfork child's
100 context as of Darwin 9/Mac OS X 10.5. */
101 #undef HAVE_WORKING_VFORK
102 #define vfork fork
103 #endif /* DARWIN_OS */
105 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
106 gmalloc before dumping and the system malloc after dumping.
107 hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
108 accomplish this. */
109 #ifdef HYBRID_MALLOC
110 #ifdef emacs
111 #define malloc hybrid_malloc
112 #define realloc hybrid_realloc
113 #define calloc hybrid_calloc
114 #define free hybrid_free
115 #if defined HAVE_GET_CURRENT_DIR_NAME && !defined BROKEN_GET_CURRENT_DIR_NAME
116 #define HYBRID_GET_CURRENT_DIR_NAME 1
117 #define get_current_dir_name hybrid_get_current_dir_name
118 #endif
119 #endif
120 #endif /* HYBRID_MALLOC */
122 /* We have to go this route, rather than the old hpux9 approach of
123 renaming the functions via macros. The system's stdlib.h has fully
124 prototyped declarations, which yields a conflicting definition of
125 srand48; it tries to redeclare what was once srandom to be srand48.
126 So we go with HAVE_LRAND48 being defined. */
127 #ifdef HPUX
128 #undef srandom
129 #undef random
130 #undef HAVE_RANDOM
131 #undef HAVE_RINT
132 #endif /* HPUX */
134 #ifdef IRIX6_5
135 #ifdef emacs
136 char *_getpty();
137 #endif
138 #define INET6 /* Needed for struct sockaddr_in6. */
139 #undef HAVE_GETADDRINFO /* IRIX has getaddrinfo but not struct addrinfo. */
140 #endif /* IRIX6_5 */
142 #ifdef MSDOS
143 #ifndef __DJGPP__
144 You lose; /* Emacs for DOS must be compiled with DJGPP */
145 #endif
146 #define _NAIVE_DOS_REGS
148 /* Start of gnulib-related stuff */
150 /* lib/ftoastr.c wants strtold, but DJGPP only has _strtold. DJGPP >
151 2.03 has it, but it also has _strtold as a stub that jumps to
152 strtold, so use _strtold in all versions. */
153 #define strtold _strtold
155 #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
156 # define HAVE_LSTAT 1
157 #else
158 # define lstat stat
159 /* DJGPP 2.03 and older don't have the next two. */
160 # define EOVERFLOW ERANGE
161 # define SIZE_MAX 4294967295U
162 #endif
164 /* We must intercept 'opendir' calls to stash away the directory name,
165 so we could reuse it in readlinkat; see msdos.c. */
166 #define opendir sys_opendir
168 /* End of gnulib-related stuff. */
170 #define emacs_raise(sig) msdos_fatal_signal (sig)
172 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
173 #define DATA_START (&etext + 1)
175 /* Define one of these for easier conditionals. */
176 #ifdef HAVE_X_WINDOWS
177 /* We need a little extra space, see ../../lisp/loadup.el and the
178 commentary below, in the non-X branch. The 140KB number was
179 measured on GNU/Linux and on MS-Windows. */
180 #define SYSTEM_PURESIZE_EXTRA (-170000+140000)
181 #else
182 /* We need a little extra space, see ../../lisp/loadup.el.
183 As of 20091024, DOS-specific files use up 62KB of pure space. But
184 overall, we end up wasting 130KB of pure space, because
185 BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
186 non-DOS specific files and load history; the latter is about 55K,
187 but depends on the depth of the top-level Emacs directory in the
188 directory tree). Given the unknown policy of different DPMI
189 hosts regarding loading of untouched pages, I'm not going to risk
190 enlarging Emacs footprint by another 100+ KBytes. */
191 #define SYSTEM_PURESIZE_EXTRA (-170000+90000)
192 #endif
193 #endif /* MSDOS */
195 /* macOS / GNUstep need a bit more pure memory. Of the existing knobs,
196 SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems. */
197 #ifdef HAVE_NS
198 #if defined NS_IMPL_GNUSTEP
199 # define SYSTEM_PURESIZE_EXTRA 30000
200 #elif defined DARWIN_OS
201 # define SYSTEM_PURESIZE_EXTRA 200000
202 #endif
203 #endif
205 #ifdef CYGWIN
206 #define SYSTEM_PURESIZE_EXTRA 10000
207 #endif
209 #if defined HAVE_NTGUI && !defined DebPrint
210 # ifdef EMACSDEBUG
211 extern void _DebPrint (const char *fmt, ...);
212 # define DebPrint(stuff) _DebPrint stuff
213 # else
214 # define DebPrint(stuff)
215 # endif
216 #endif
218 #if defined CYGWIN && defined HAVE_NTGUI
219 # define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
220 # define _WIN32_WINNT 0x500 /* Win2k */
221 /* The following was in /usr/include/string.h prior to Cygwin 1.7.33. */
222 #ifndef strnicmp
223 #define strnicmp strncasecmp
224 #endif
225 #endif
227 #ifdef emacs /* Don't do this for lib-src. */
228 /* Tell regex.c to use a type compatible with Emacs. */
229 #define RE_TRANSLATE_TYPE Lisp_Object
230 #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
231 #define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_number (0)))
232 #endif
234 /* Tell time_rz.c to use Emacs's getter and setter for TZ.
235 Only Emacs uses time_rz so this is OK. */
236 #define getenv_TZ emacs_getenv_TZ
237 #define setenv_TZ emacs_setenv_TZ
238 extern char *emacs_getenv_TZ (void);
239 extern int emacs_setenv_TZ (char const *);
241 #include <string.h>
242 #include <stdlib.h>
244 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
245 #define NO_INLINE __attribute__((noinline))
246 #else
247 #define NO_INLINE
248 #endif
250 #if __has_attribute (externally_visible)
251 #define EXTERNALLY_VISIBLE __attribute__((externally_visible))
252 #else
253 #define EXTERNALLY_VISIBLE
254 #endif
256 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
257 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
258 #else
259 # define ATTRIBUTE_FORMAT(spec) /* empty */
260 #endif
262 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
263 # define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
264 ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument))
265 #else
266 # define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
267 ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
268 #endif
270 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
271 #define ATTRIBUTE_UNUSED _GL_UNUSED
273 #if 3 <= __GNUC__
274 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
275 #else
276 # define ATTRIBUTE_MALLOC
277 #endif
279 #if __has_attribute (alloc_size)
280 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
281 #else
282 # define ATTRIBUTE_ALLOC_SIZE(args)
283 #endif
285 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
287 /* Work around GCC bug 59600: when a function is inlined, the inlined
288 code may have its addresses sanitized even if the function has the
289 no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and
290 clang 3.4. */
291 #if (! ADDRESS_SANITIZER \
292 || ((4 < __GNUC__ + (9 <= __GNUC_MINOR__)) \
293 || 3 < __clang_major__ + (4 <= __clang_minor__)))
294 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed. */
295 #else
296 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
297 #endif
299 /* Attribute of functions whose code should not have addresses
300 sanitized. */
302 #if __has_attribute (no_sanitize_address)
303 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
304 __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
305 #elif __has_attribute (no_address_safety_analysis)
306 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
307 __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
308 #else
309 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
310 #endif
312 /* Some versions of GNU/Linux define noinline in their headers. */
313 #ifdef noinline
314 #undef noinline
315 #endif
317 /* Use Gnulib's extern-inline module for extern inline functions.
318 An include file foo.h should prepend FOO_INLINE to function
319 definitions, with the following overall pattern:
321 [#include any other .h files first.]
323 INLINE_HEADER_BEGIN
325 INLINE int
326 incr (int i)
328 return i + 1;
331 INLINE_HEADER_END
333 For every executable, exactly one file that includes the header
334 should do this:
336 #define INLINE EXTERN_INLINE
338 before including config.h or any other .h file.
339 Other .c files should not define INLINE.
340 For Emacs, this is done by having emacs.c first '#define INLINE
341 EXTERN_INLINE' and then include every .h file that uses INLINE.
343 The INLINE_HEADER_BEGIN and INLINE_HEADER_END suppress bogus
344 warnings in some GCC versions; see ../m4/extern-inline.m4.
346 C99 compilers compile functions like 'incr' as C99-style extern
347 inline functions. Buggy GCC implementations do something similar with
348 GNU-specific keywords. Buggy non-GCC compilers use static
349 functions, which bloats the code but is good enough. */
351 #ifndef INLINE
352 # define INLINE _GL_INLINE
353 #endif
354 #define EXTERN_INLINE _GL_EXTERN_INLINE
355 #define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
356 #define INLINE_HEADER_END _GL_INLINE_HEADER_END
358 /* To use the struct hack with N elements, declare the struct like this:
359 struct s { ...; t name[FLEXIBLE_ARRAY_MEMBER]; };
360 and allocate (offsetof (struct s, name) + N * sizeof (t)) bytes.
361 IBM xlc 12.1 claims to do C99 but mishandles flexible array members. */
362 #ifdef __IBMC__
363 # define FLEXIBLE_ARRAY_MEMBER 1
364 #else
365 # define FLEXIBLE_ARRAY_MEMBER
366 #endif
368 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
369 #ifdef lint
370 /* Use CODE only if lint checking is in effect. */
371 # define IF_LINT(Code) Code
372 #else
373 # define IF_LINT(Code) /* empty */
374 #endif
376 /* conf_post.h ends here */