todo-mode: don't assume an ordering of tests
[emacs.git] / src / conf_post.h
blob5e1d8457deb8e0fc88b89b91f26bf1797c98507e
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 /* Put the code here rather than in configure.ac using AH_BOTTOM.
22 This way, the code does not get processed by autoheader. For
23 example, undefs here are not commented out.
25 To help make dependencies clearer elsewhere, this file typically
26 does not #include other files. The exceptions are first stdbool.h
27 because it is unlikely to interfere with configuration and bool is
28 such a core part of the C language, and second ms-w32.h (DOS_NT
29 only) because it historically was included here and changing that
30 would take some work. */
32 #include <stdbool.h>
34 #if defined DOS_NT && !defined DEFER_MS_W32_H
35 # include <ms-w32.h>
36 #endif
38 /* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later.
39 It can be used in a preprocessor expression. */
40 #ifndef __GNUC_MINOR__
41 # define GNUC_PREREQ(v, w, x) false
42 #elif ! defined __GNUC_PATCHLEVEL__
43 # define GNUC_PREREQ(v, w, x) \
44 ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) == 0))
45 #else
46 # define GNUC_PREREQ(v, w, x) \
47 ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__)))
48 #endif
50 /* The type of bool bitfields. Needed to compile Objective-C with
51 standard GCC. It was also needed to port to pre-C99 compilers,
52 although we don't care about that any more. */
53 #if NS_IMPL_GNUSTEP
54 typedef unsigned int bool_bf;
55 #else
56 typedef bool bool_bf;
57 #endif
59 /* Simulate __has_attribute on compilers that lack it. It is used only
60 on arguments like alloc_size that are handled in this simulation. */
61 #ifndef __has_attribute
62 # define __has_attribute(a) __has_attribute_##a
63 # define __has_attribute_alloc_size GNUC_PREREQ (4, 3, 0)
64 # define __has_attribute_cleanup GNUC_PREREQ (3, 4, 0)
65 # define __has_attribute_externally_visible GNUC_PREREQ (4, 1, 0)
66 # define __has_attribute_no_address_safety_analysis false
67 # define __has_attribute_no_sanitize_address GNUC_PREREQ (4, 8, 0)
68 #endif
70 /* Simulate __has_builtin on compilers that lack it. It is used only
71 on arguments like __builtin_assume_aligned that are handled in this
72 simulation. */
73 #ifndef __has_builtin
74 # define __has_builtin(a) __has_builtin_##a
75 # define __has_builtin___builtin_assume_aligned GNUC_PREREQ (4, 7, 0)
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 /* Yield PTR, which must be aligned to ALIGNMENT. */
92 #if ! __has_builtin (__builtin_assume_aligned)
93 # define __builtin_assume_aligned(ptr, ...) ((void *) (ptr))
94 #endif
96 #ifdef DARWIN_OS
97 #if defined emacs && !defined CANNOT_DUMP
98 #define malloc unexec_malloc
99 #define realloc unexec_realloc
100 #define free unexec_free
101 #endif
102 #endif /* DARWIN_OS */
104 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
105 gmalloc before dumping and the system malloc after dumping.
106 hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
107 accomplish this. */
108 #ifdef HYBRID_MALLOC
109 #ifdef emacs
110 #define malloc hybrid_malloc
111 #define realloc hybrid_realloc
112 #define aligned_alloc hybrid_aligned_alloc
113 #define calloc hybrid_calloc
114 #define free hybrid_free
115 #endif
116 #endif /* HYBRID_MALLOC */
118 /* We have to go this route, rather than the old hpux9 approach of
119 renaming the functions via macros. The system's stdlib.h has fully
120 prototyped declarations, which yields a conflicting definition of
121 srand48; it tries to redeclare what was once srandom to be srand48.
122 So we go with HAVE_LRAND48 being defined. */
123 #ifdef HPUX
124 #undef srandom
125 #undef random
126 #undef HAVE_RANDOM
127 #undef HAVE_RINT
128 #endif /* HPUX */
130 #ifdef MSDOS
131 #ifndef __DJGPP__
132 You lose; /* Emacs for DOS must be compiled with DJGPP */
133 #endif
134 #define _NAIVE_DOS_REGS
136 /* Start of gnulib-related stuff */
138 /* lib/ftoastr.c wants strtold, but DJGPP only has _strtold. DJGPP >
139 2.03 has it, but it also has _strtold as a stub that jumps to
140 strtold, so use _strtold in all versions. */
141 #define strtold _strtold
143 #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
144 # define HAVE_LSTAT 1
145 #else
146 # define lstat stat
147 /* DJGPP 2.03 and older don't have the next two. */
148 # define EOVERFLOW ERANGE
149 # define SIZE_MAX 4294967295U
150 #endif
152 /* We must intercept 'opendir' calls to stash away the directory name,
153 so we could reuse it in readlinkat; see msdos.c. */
154 #define opendir sys_opendir
156 /* End of gnulib-related stuff. */
158 #define emacs_raise(sig) msdos_fatal_signal (sig)
160 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
161 #define DATA_START (&etext + 1)
163 /* Define one of these for easier conditionals. */
164 #ifdef HAVE_X_WINDOWS
165 /* We need a little extra space, see ../../lisp/loadup.el and the
166 commentary below, in the non-X branch. The 140KB number was
167 measured on GNU/Linux and on MS-Windows. */
168 #define SYSTEM_PURESIZE_EXTRA (-170000+140000)
169 #else
170 /* We need a little extra space, see ../../lisp/loadup.el.
171 As of 20091024, DOS-specific files use up 62KB of pure space. But
172 overall, we end up wasting 130KB of pure space, because
173 BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
174 non-DOS specific files and load history; the latter is about 55K,
175 but depends on the depth of the top-level Emacs directory in the
176 directory tree). Given the unknown policy of different DPMI
177 hosts regarding loading of untouched pages, I'm not going to risk
178 enlarging Emacs footprint by another 100+ KBytes. */
179 #define SYSTEM_PURESIZE_EXTRA (-170000+90000)
180 #endif
181 #endif /* MSDOS */
183 /* macOS / GNUstep need a bit more pure memory. Of the existing knobs,
184 SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems. */
185 #ifdef HAVE_NS
186 #if defined NS_IMPL_GNUSTEP
187 # define SYSTEM_PURESIZE_EXTRA 30000
188 #elif defined DARWIN_OS
189 # define SYSTEM_PURESIZE_EXTRA 200000
190 #endif
191 #endif
193 #ifdef CYGWIN
194 #define SYSTEM_PURESIZE_EXTRA 50000
195 #endif
197 #if defined HAVE_NTGUI && !defined DebPrint
198 # ifdef EMACSDEBUG
199 extern void _DebPrint (const char *fmt, ...);
200 # define DebPrint(stuff) _DebPrint stuff
201 # else
202 # define DebPrint(stuff) ((void) 0)
203 # endif
204 #endif
206 #if defined CYGWIN && defined HAVE_NTGUI
207 # define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
208 # define _WIN32_WINNT 0x500 /* Win2k */
209 /* The following was in /usr/include/string.h prior to Cygwin 1.7.33. */
210 #ifndef strnicmp
211 #define strnicmp strncasecmp
212 #endif
213 #endif
215 #ifdef emacs /* Don't do this for lib-src. */
216 /* Tell regex.c to use a type compatible with Emacs. */
217 #define RE_TRANSLATE_TYPE Lisp_Object
218 #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
219 #define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_number (0)))
220 #endif
222 /* Tell time_rz.c to use Emacs's getter and setter for TZ.
223 Only Emacs uses time_rz so this is OK. */
224 #define getenv_TZ emacs_getenv_TZ
225 #define setenv_TZ emacs_setenv_TZ
226 extern char *emacs_getenv_TZ (void);
227 extern int emacs_setenv_TZ (char const *);
229 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
230 #define NO_INLINE __attribute__((noinline))
231 #else
232 #define NO_INLINE
233 #endif
235 #if __has_attribute (externally_visible)
236 #define EXTERNALLY_VISIBLE __attribute__((externally_visible))
237 #else
238 #define EXTERNALLY_VISIBLE
239 #endif
241 #if GNUC_PREREQ (2, 7, 0)
242 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
243 #else
244 # define ATTRIBUTE_FORMAT(spec) /* empty */
245 #endif
247 #if GNUC_PREREQ (7, 0, 0)
248 # define FALLTHROUGH __attribute__ ((__fallthrough__))
249 #else
250 # define FALLTHROUGH ((void) 0)
251 #endif
253 #if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
254 # define PRINTF_ARCHETYPE __gnu_printf__
255 #elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
256 # define PRINTF_ARCHETYPE __ms_printf__
257 #else
258 # define PRINTF_ARCHETYPE __printf__
259 #endif
260 #define ATTRIBUTE_FORMAT_PRINTF(string_index, first_to_check) \
261 ATTRIBUTE_FORMAT ((PRINTF_ARCHETYPE, string_index, first_to_check))
263 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
264 #define ATTRIBUTE_UNUSED _GL_UNUSED
266 #if GNUC_PREREQ (3, 3, 0) && !defined __ICC
267 # define ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
268 #else
269 # define ATTRIBUTE_MAY_ALIAS
270 #endif
272 /* Declare NAME to be a pointer to an object of type TYPE, initialized
273 to the address ADDR, which may be of a different type. Accesses
274 via NAME may alias with other accesses with the traditional
275 behavior, even if options like gcc -fstrict-aliasing are used. */
277 #define DECLARE_POINTER_ALIAS(name, type, addr) \
278 type ATTRIBUTE_MAY_ALIAS *name = (type *) (addr)
280 #if 3 <= __GNUC__
281 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
282 #else
283 # define ATTRIBUTE_MALLOC
284 #endif
286 #if __has_attribute (alloc_size)
287 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
288 #else
289 # define ATTRIBUTE_ALLOC_SIZE(args)
290 #endif
292 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
294 /* Work around GCC bug 59600: when a function is inlined, the inlined
295 code may have its addresses sanitized even if the function has the
296 no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and
297 clang 3.4. */
298 #if (! ADDRESS_SANITIZER \
299 || (GNUC_PREREQ (4, 9, 0) \
300 || 3 < __clang_major__ + (4 <= __clang_minor__)))
301 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed. */
302 #else
303 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
304 #endif
306 /* Attribute of functions whose code should not have addresses
307 sanitized. */
309 #if __has_attribute (no_sanitize_address)
310 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
311 __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
312 #elif __has_attribute (no_address_safety_analysis)
313 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
314 __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
315 #else
316 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
317 #endif
319 /* gcc -fsanitize=address does not work with vfork in Fedora 25 x86-64.
320 For now, assume that this problem occurs on all platforms. */
321 #if ADDRESS_SANITIZER && !defined vfork
322 # define vfork fork
323 #endif
325 /* Some versions of GNU/Linux define noinline in their headers. */
326 #ifdef noinline
327 #undef noinline
328 #endif
330 /* Use Gnulib's extern-inline module for extern inline functions.
331 An include file foo.h should prepend FOO_INLINE to function
332 definitions, with the following overall pattern:
334 [#include any other .h files first.]
336 INLINE_HEADER_BEGIN
338 INLINE int
339 incr (int i)
341 return i + 1;
344 INLINE_HEADER_END
346 For every executable, exactly one file that includes the header
347 should do this:
349 #define INLINE EXTERN_INLINE
351 before including config.h or any other .h file.
352 Other .c files should not define INLINE.
353 For Emacs, this is done by having emacs.c first '#define INLINE
354 EXTERN_INLINE' and then include every .h file that uses INLINE.
356 The INLINE_HEADER_BEGIN and INLINE_HEADER_END suppress bogus
357 warnings in some GCC versions; see ../m4/extern-inline.m4.
359 C99 compilers compile functions like 'incr' as C99-style extern
360 inline functions. Buggy GCC implementations do something similar with
361 GNU-specific keywords. Buggy non-GCC compilers use static
362 functions, which bloats the code but is good enough. */
364 #ifndef INLINE
365 # define INLINE _GL_INLINE
366 #endif
367 #define EXTERN_INLINE _GL_EXTERN_INLINE
368 #define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
369 #define INLINE_HEADER_END _GL_INLINE_HEADER_END
371 /* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC
372 into not warning incorrectly about use of an uninitialized variable. */
373 #if defined GCC_LINT || defined lint
374 # define UNINIT = {0,}
375 #else
376 # define UNINIT /* empty */
377 #endif