]> code.delx.au - gnu-emacs/blob - src/conf_post.h
; Merge from origin/emacs-25
[gnu-emacs] / src / conf_post.h
1 /* conf_post.h --- configure.ac includes this via AH_BOTTOM
2
3 Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2016 Free Software
4 Foundation, Inc.
5
6 This file is part of GNU Emacs.
7
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.
12
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.
17
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/>. */
20
21 /* Commentary:
22
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.
26 */
27
28 /* Code: */
29
30 /* Include any platform specific configuration file. */
31 #ifdef config_opsysfile
32 # include config_opsysfile
33 #endif
34
35 #include <stdbool.h>
36
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
47
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
56
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
64
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 GNUC_PREREQ (4, 3, 0)
70 # define __has_attribute_cleanup GNUC_PREREQ (3, 4, 0)
71 # define __has_attribute_externally_visible GNUC_PREREQ (4, 1, 0)
72 # define __has_attribute_no_address_safety_analysis false
73 # define __has_attribute_no_sanitize_address GNUC_PREREQ (4, 8, 0)
74 #endif
75
76 /* Simulate __has_builtin on compilers that lack it. It is used only
77 on arguments like __builtin_assume_aligned that are handled in this
78 simulation. */
79 #ifndef __has_builtin
80 # define __has_builtin(a) __has_builtin_##a
81 # define __has_builtin___builtin_assume_aligned GNUC_PREREQ (4, 7, 0)
82 #endif
83
84 /* Simulate __has_feature on compilers that lack it. It is used only
85 to define ADDRESS_SANITIZER below. */
86 #ifndef __has_feature
87 # define __has_feature(a) false
88 #endif
89
90 /* True if addresses are being sanitized. */
91 #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
92 # define ADDRESS_SANITIZER true
93 #else
94 # define ADDRESS_SANITIZER false
95 #endif
96
97 /* Yield PTR, which must be aligned to ALIGNMENT. */
98 #if ! __has_builtin (__builtin_assume_aligned)
99 # define __builtin_assume_aligned(ptr, ...) ((void *) (ptr))
100 #endif
101
102 #ifdef DARWIN_OS
103 #ifdef emacs
104 #define malloc unexec_malloc
105 #define realloc unexec_realloc
106 #define free unexec_free
107 #endif
108 /* The following solves the problem that Emacs hangs when evaluating
109 (make-comint "test0" "/nodir/nofile" nil "") when /nodir/nofile
110 does not exist. Also, setsid is not allowed in the vfork child's
111 context as of Darwin 9/Mac OS X 10.5. */
112 #undef HAVE_WORKING_VFORK
113 #define vfork fork
114 #endif /* DARWIN_OS */
115
116 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
117 gmalloc before dumping and the system malloc after dumping.
118 hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
119 accomplish this. */
120 #ifdef HYBRID_MALLOC
121 #ifdef emacs
122 #define malloc hybrid_malloc
123 #define realloc hybrid_realloc
124 #define aligned_alloc hybrid_aligned_alloc
125 #define calloc hybrid_calloc
126 #define free hybrid_free
127 #endif
128 #endif /* HYBRID_MALLOC */
129
130 /* We have to go this route, rather than the old hpux9 approach of
131 renaming the functions via macros. The system's stdlib.h has fully
132 prototyped declarations, which yields a conflicting definition of
133 srand48; it tries to redeclare what was once srandom to be srand48.
134 So we go with HAVE_LRAND48 being defined. */
135 #ifdef HPUX
136 #undef srandom
137 #undef random
138 #undef HAVE_RANDOM
139 #undef HAVE_RINT
140 #endif /* HPUX */
141
142 #ifdef MSDOS
143 #ifndef __DJGPP__
144 You lose; /* Emacs for DOS must be compiled with DJGPP */
145 #endif
146 #define _NAIVE_DOS_REGS
147
148 /* Start of gnulib-related stuff */
149
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
154
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
163
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
167
168 /* End of gnulib-related stuff. */
169
170 #define emacs_raise(sig) msdos_fatal_signal (sig)
171
172 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
173 #define DATA_START (&etext + 1)
174
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 */
194
195 /* Mac OS X / 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
204
205 #ifdef CYGWIN
206 #define SYSTEM_PURESIZE_EXTRA 50000
207 #endif
208
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
217
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
226
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
233
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 *);
240
241 #include <string.h>
242 #include <stdlib.h>
243
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
249
250 #if __has_attribute (externally_visible)
251 #define EXTERNALLY_VISIBLE __attribute__((externally_visible))
252 #else
253 #define EXTERNALLY_VISIBLE
254 #endif
255
256 #if GNUC_PREREQ (2, 7, 0)
257 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
258 #else
259 # define ATTRIBUTE_FORMAT(spec) /* empty */
260 #endif
261
262 #if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
263 # define PRINTF_ARCHETYPE __gnu_printf__
264 #elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
265 # define PRINTF_ARCHETYPE __ms_printf__
266 #else
267 # define PRINTF_ARCHETYPE __printf__
268 #endif
269 #define ATTRIBUTE_FORMAT_PRINTF(string_index, first_to_check) \
270 ATTRIBUTE_FORMAT ((PRINTF_ARCHETYPE, string_index, first_to_check))
271
272 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
273 #define ATTRIBUTE_UNUSED _GL_UNUSED
274
275 #if 3 <= __GNUC__
276 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
277 #else
278 # define ATTRIBUTE_MALLOC
279 #endif
280
281 #if __has_attribute (alloc_size)
282 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
283 #else
284 # define ATTRIBUTE_ALLOC_SIZE(args)
285 #endif
286
287 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
288
289 /* Work around GCC bug 59600: when a function is inlined, the inlined
290 code may have its addresses sanitized even if the function has the
291 no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and
292 clang 3.4. */
293 #if (! ADDRESS_SANITIZER \
294 || (GNUC_PREREQ (4, 9, 0) \
295 || 3 < __clang_major__ + (4 <= __clang_minor__)))
296 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed. */
297 #else
298 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
299 #endif
300
301 /* Attribute of functions whose code should not have addresses
302 sanitized. */
303
304 #if __has_attribute (no_sanitize_address)
305 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
306 __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
307 #elif __has_attribute (no_address_safety_analysis)
308 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
309 __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
310 #else
311 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
312 #endif
313
314 /* Some versions of GNU/Linux define noinline in their headers. */
315 #ifdef noinline
316 #undef noinline
317 #endif
318
319 /* Use Gnulib's extern-inline module for extern inline functions.
320 An include file foo.h should prepend FOO_INLINE to function
321 definitions, with the following overall pattern:
322
323 [#include any other .h files first.]
324 ...
325 INLINE_HEADER_BEGIN
326 ...
327 INLINE int
328 incr (int i)
329 {
330 return i + 1;
331 }
332 ...
333 INLINE_HEADER_END
334
335 For every executable, exactly one file that includes the header
336 should do this:
337
338 #define INLINE EXTERN_INLINE
339
340 before including config.h or any other .h file.
341 Other .c files should not define INLINE.
342 For Emacs, this is done by having emacs.c first '#define INLINE
343 EXTERN_INLINE' and then include every .h file that uses INLINE.
344
345 The INLINE_HEADER_BEGIN and INLINE_HEADER_END suppress bogus
346 warnings in some GCC versions; see ../m4/extern-inline.m4.
347
348 C99 compilers compile functions like 'incr' as C99-style extern
349 inline functions. Buggy GCC implementations do something similar with
350 GNU-specific keywords. Buggy non-GCC compilers use static
351 functions, which bloats the code but is good enough. */
352
353 #ifndef INLINE
354 # define INLINE _GL_INLINE
355 #endif
356 #define EXTERN_INLINE _GL_EXTERN_INLINE
357 #define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
358 #define INLINE_HEADER_END _GL_INLINE_HEADER_END
359
360 /* To use the struct hack with N elements, declare the struct like this:
361 struct s { ...; t name[FLEXIBLE_ARRAY_MEMBER]; };
362 and allocate (offsetof (struct s, name) + N * sizeof (t)) bytes.
363 IBM xlc 12.1 claims to do C99 but mishandles flexible array members. */
364 #ifdef __IBMC__
365 # define FLEXIBLE_ARRAY_MEMBER 1
366 #else
367 # define FLEXIBLE_ARRAY_MEMBER
368 #endif
369
370 /* When used in place of 'volatile', 'NONVOLATILE' is equivalent to nothing,
371 except it cajoles GCC into not warning incorrectly that a variable needs to
372 be volatile. This works around GCC bug 54561. */
373 #if defined GCC_LINT || defined lint
374 # define NONVOLATILE volatile
375 #else
376 # define NONVOLATILE /* empty */
377 #endif
378
379 /* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC
380 into not warning incorrectly about use of an uninitialized variable. */
381 #if defined GCC_LINT || defined lint
382 # define UNINIT = {0,}
383 #else
384 # define UNINIT /* empty */
385 #endif
386
387 /* conf_post.h ends here */