; doc/emacs/misc.texi (Network Security): Fix typo.
[emacs.git] / src / conf_post.h
blob080d7b7e6885bb14741c51d60159f5291272e386
1 /* conf_post.h --- configure.ac includes this via AH_BOTTOM
3 Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2018 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 <https://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 WINDOWSNT && !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 __has_attribute should be used only in #if expressions, as Oracle
62 Studio 12.5's __has_attribute does not work in plain code. */
63 #ifndef __has_attribute
64 # define __has_attribute(a) __has_attribute_##a
65 # define __has_attribute_alloc_size GNUC_PREREQ (4, 3, 0)
66 # define __has_attribute_cleanup GNUC_PREREQ (3, 4, 0)
67 # define __has_attribute_externally_visible GNUC_PREREQ (4, 1, 0)
68 # define __has_attribute_no_address_safety_analysis false
69 # define __has_attribute_no_sanitize_address GNUC_PREREQ (4, 8, 0)
70 # define __has_attribute_no_sanitize_undefined GNUC_PREREQ (4, 9, 0)
71 #endif
73 /* Simulate __has_feature on compilers that lack it. It is used only
74 to define ADDRESS_SANITIZER below. */
75 #ifndef __has_feature
76 # define __has_feature(a) false
77 #endif
79 /* True if addresses are being sanitized. */
80 #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
81 # define ADDRESS_SANITIZER true
82 #else
83 # define ADDRESS_SANITIZER false
84 #endif
86 #ifdef DARWIN_OS
87 #if defined emacs && !defined CANNOT_DUMP
88 #define malloc unexec_malloc
89 #define realloc unexec_realloc
90 #define free unexec_free
91 #endif
92 #endif /* DARWIN_OS */
94 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
95 gmalloc before dumping and the system malloc after dumping.
96 hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
97 accomplish this. */
98 #ifdef HYBRID_MALLOC
99 #ifdef emacs
100 #define malloc hybrid_malloc
101 #define realloc hybrid_realloc
102 #define aligned_alloc hybrid_aligned_alloc
103 #define calloc hybrid_calloc
104 #define free hybrid_free
105 #endif
106 #endif /* HYBRID_MALLOC */
108 /* We have to go this route, rather than the old hpux9 approach of
109 renaming the functions via macros. The system's stdlib.h has fully
110 prototyped declarations, which yields a conflicting definition of
111 srand48; it tries to redeclare what was once srandom to be srand48.
112 So we go with HAVE_LRAND48 being defined. */
113 #ifdef HPUX
114 #undef srandom
115 #undef random
116 #undef HAVE_RANDOM
117 #undef HAVE_RINT
118 #endif /* HPUX */
120 #ifdef MSDOS
121 #ifndef __DJGPP__
122 You lose; /* Emacs for DOS must be compiled with DJGPP */
123 #endif
124 #define _NAIVE_DOS_REGS
126 /* Start of gnulib-related stuff */
128 /* lib/ftoastr.c wants strtold, but DJGPP only has _strtold. DJGPP >
129 2.03 has it, but it also has _strtold as a stub that jumps to
130 strtold, so use _strtold in all versions. */
131 #define strtold _strtold
133 #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
134 # define HAVE_LSTAT 1
135 #else
136 # define lstat stat
137 /* DJGPP 2.03 and older don't have the next two. */
138 # define EOVERFLOW ERANGE
139 # define SIZE_MAX 4294967295U
140 #endif
142 /* We must intercept 'opendir' calls to stash away the directory name,
143 so we could reuse it in readlinkat; see msdos.c. */
144 #define opendir sys_opendir
146 /* End of gnulib-related stuff. */
148 #define emacs_raise(sig) msdos_fatal_signal (sig)
150 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
151 #define DATA_START (&etext + 1)
153 /* Define one of these for easier conditionals. */
154 #ifdef HAVE_X_WINDOWS
155 /* We need a little extra space, see ../../lisp/loadup.el and the
156 commentary below, in the non-X branch. The 140KB number was
157 measured on GNU/Linux and on MS-Windows. */
158 #define SYSTEM_PURESIZE_EXTRA (-170000+140000)
159 #else
160 /* We need a little extra space, see ../../lisp/loadup.el.
161 As of 20091024, DOS-specific files use up 62KB of pure space. But
162 overall, we end up wasting 130KB of pure space, because
163 BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
164 non-DOS specific files and load history; the latter is about 55K,
165 but depends on the depth of the top-level Emacs directory in the
166 directory tree). Given the unknown policy of different DPMI
167 hosts regarding loading of untouched pages, I'm not going to risk
168 enlarging Emacs footprint by another 100+ KBytes. */
169 #define SYSTEM_PURESIZE_EXTRA (-170000+90000)
170 #endif
171 #endif /* MSDOS */
173 /* macOS / GNUstep need a bit more pure memory. Of the existing knobs,
174 SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems. */
175 #ifdef HAVE_NS
176 #if defined NS_IMPL_GNUSTEP
177 # define SYSTEM_PURESIZE_EXTRA 30000
178 #elif defined DARWIN_OS
179 # define SYSTEM_PURESIZE_EXTRA 200000
180 #endif
181 #endif
183 #ifdef CYGWIN
184 #define SYSTEM_PURESIZE_EXTRA 50000
185 #endif
187 #if defined HAVE_NTGUI && !defined DebPrint
188 # ifdef EMACSDEBUG
189 extern void _DebPrint (const char *fmt, ...);
190 # define DebPrint(stuff) _DebPrint stuff
191 # else
192 # define DebPrint(stuff) ((void) 0)
193 # endif
194 #endif
196 #if defined CYGWIN && defined HAVE_NTGUI
197 # define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
198 # define _WIN32_WINNT 0x500 /* Win2k */
199 /* The following was in /usr/include/string.h prior to Cygwin 1.7.33. */
200 #ifndef strnicmp
201 #define strnicmp strncasecmp
202 #endif
203 #endif
205 #ifdef emacs /* Don't do this for lib-src. */
206 /* Tell regex.c to use a type compatible with Emacs. */
207 #define RE_TRANSLATE_TYPE Lisp_Object
208 #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
209 #define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_number (0)))
210 #endif
212 /* Tell time_rz.c to use Emacs's getter and setter for TZ.
213 Only Emacs uses time_rz so this is OK. */
214 #define getenv_TZ emacs_getenv_TZ
215 #define setenv_TZ emacs_setenv_TZ
216 extern char *emacs_getenv_TZ (void);
217 extern int emacs_setenv_TZ (char const *);
219 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
220 #define NO_INLINE __attribute__((noinline))
221 #else
222 #define NO_INLINE
223 #endif
225 #if __has_attribute (externally_visible)
226 #define EXTERNALLY_VISIBLE __attribute__((externally_visible))
227 #else
228 #define EXTERNALLY_VISIBLE
229 #endif
231 #if GNUC_PREREQ (2, 7, 0)
232 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
233 #else
234 # define ATTRIBUTE_FORMAT(spec) /* empty */
235 #endif
237 #if GNUC_PREREQ (7, 0, 0)
238 # define FALLTHROUGH __attribute__ ((__fallthrough__))
239 #else
240 # define FALLTHROUGH ((void) 0)
241 #endif
243 #if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
244 # define PRINTF_ARCHETYPE __gnu_printf__
245 #elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
246 # ifdef MINGW_W64
247 /* When __USE_MINGW_ANSI_STDIO is non-zero (as set by config.h),
248 MinGW64 replaces printf* with its own versions that are
249 __gnu_printf__ compatible, and emits warnings for MS native %I64d
250 format spec. */
251 # if __USE_MINGW_ANSI_STDIO
252 # define PRINTF_ARCHETYPE __gnu_printf__
253 # else
254 # define PRINTF_ARCHETYPE __ms_printf__
255 # endif
256 # else /* mingw.org's MinGW */
257 /* Starting from runtime v5.0.0, mingw.org's MinGW with GCC 6 and
258 later turns on __USE_MINGW_ANSI_STDIO by default, replaces printf*
259 with its own __mingw_printf__ version, which still recognizes
260 %I64d. */
261 # if GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5
262 # define PRINTF_ARCHETYPE __mingw_printf__
263 # else /* __MINGW32_MAJOR_VERSION < 5 */
264 # define PRINTF_ARCHETYPE __ms_printf__
265 # endif /* __MINGW32_MAJOR_VERSION < 5 */
266 # endif /* MinGW */
267 #else
268 # define PRINTF_ARCHETYPE __printf__
269 #endif
270 #define ATTRIBUTE_FORMAT_PRINTF(string_index, first_to_check) \
271 ATTRIBUTE_FORMAT ((PRINTF_ARCHETYPE, string_index, first_to_check))
273 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
274 #define ATTRIBUTE_UNUSED _GL_UNUSED
276 #if GNUC_PREREQ (3, 3, 0) && !defined __ICC
277 # define ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
278 #else
279 # define ATTRIBUTE_MAY_ALIAS
280 #endif
282 /* Declare NAME to be a pointer to an object of type TYPE, initialized
283 to the address ADDR, which may be of a different type. Accesses
284 via NAME may alias with other accesses with the traditional
285 behavior, even if options like gcc -fstrict-aliasing are used. */
287 #define DECLARE_POINTER_ALIAS(name, type, addr) \
288 type ATTRIBUTE_MAY_ALIAS *name = (type *) (addr)
290 #if 3 <= __GNUC__
291 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
292 #else
293 # define ATTRIBUTE_MALLOC
294 #endif
296 #if __has_attribute (alloc_size)
297 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
298 #else
299 # define ATTRIBUTE_ALLOC_SIZE(args)
300 #endif
302 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
304 /* Work around GCC bug 59600: when a function is inlined, the inlined
305 code may have its addresses sanitized even if the function has the
306 no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and
307 clang 3.4. */
308 #if (! ADDRESS_SANITIZER \
309 || (GNUC_PREREQ (4, 9, 0) \
310 || 3 < __clang_major__ + (4 <= __clang_minor__)))
311 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed. */
312 #else
313 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
314 #endif
316 /* Attribute of functions whose code should not have addresses
317 sanitized. */
319 #if __has_attribute (no_sanitize_address)
320 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
321 __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
322 #elif __has_attribute (no_address_safety_analysis)
323 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
324 __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
325 #else
326 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
327 #endif
329 /* Attribute of functions whose undefined behavior should not be sanitized. */
331 #if __has_attribute (no_sanitize_undefined)
332 # define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
333 #elif __has_attribute (no_sanitize)
334 # define ATTRIBUTE_NO_SANITIZE_UNDEFINED \
335 __attribute__ ((no_sanitize ("undefined")))
336 #else
337 # define ATTRIBUTE_NO_SANITIZE_UNDEFINED
338 #endif
340 /* gcc -fsanitize=address does not work with vfork in Fedora 28 x86-64. See:
341 https://lists.gnu.org/r/emacs-devel/2017-05/msg00464.html
342 For now, assume that this problem occurs on all platforms. */
343 #if ADDRESS_SANITIZER && !defined vfork
344 # define vfork fork
345 #endif
347 #if ! (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__)
348 # undef PROFILING
349 #endif
351 /* Some versions of GNU/Linux define noinline in their headers. */
352 #ifdef noinline
353 #undef noinline
354 #endif
356 /* Use Gnulib's extern-inline module for extern inline functions.
357 An include file foo.h should prepend FOO_INLINE to function
358 definitions, with the following overall pattern:
360 [#include any other .h files first.]
362 INLINE_HEADER_BEGIN
364 INLINE int
365 incr (int i)
367 return i + 1;
370 INLINE_HEADER_END
372 For every executable, exactly one file that includes the header
373 should do this:
375 #define INLINE EXTERN_INLINE
377 before including config.h or any other .h file.
378 Other .c files should not define INLINE.
379 For Emacs, this is done by having emacs.c first '#define INLINE
380 EXTERN_INLINE' and then include every .h file that uses INLINE.
382 The INLINE_HEADER_BEGIN and INLINE_HEADER_END suppress bogus
383 warnings in some GCC versions; see ../m4/extern-inline.m4.
385 C99 compilers compile functions like 'incr' as C99-style extern
386 inline functions. Buggy GCC implementations do something similar with
387 GNU-specific keywords. Buggy non-GCC compilers use static
388 functions, which bloats the code but is good enough. */
390 #ifndef INLINE
391 # define INLINE _GL_INLINE
392 #endif
393 #define EXTERN_INLINE _GL_EXTERN_INLINE
394 #define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
395 #define INLINE_HEADER_END _GL_INLINE_HEADER_END
397 /* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC
398 into not warning incorrectly about use of an uninitialized variable. */
399 #if defined GCC_LINT || defined lint
400 # define UNINIT = {0,}
401 #else
402 # define UNINIT /* empty */
403 #endif