declare smobs in alloc.c
[bpt/emacs.git] / 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-2014 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
11 (at 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 /* The type of bool bitfields. Needed to compile Objective-C with
38 standard GCC. It was also needed to port to pre-C99 compilers,
39 although we don't care about that any more. */
40 #if NS_IMPL_GNUSTEP
41 typedef unsigned int bool_bf;
42 #else
43 typedef bool bool_bf;
44 #endif
45
46 #ifndef WINDOWSNT
47 /* On AIX 3 this must be included before any other include file. */
48 #include <alloca.h>
49 #if ! HAVE_ALLOCA
50 # error "alloca not available on this machine"
51 #endif
52 #endif
53
54 /* When not using Clang, assume its attributes and features are absent. */
55 #ifndef __has_attribute
56 # define __has_attribute(a) false
57 #endif
58 #ifndef __has_feature
59 # define __has_feature(a) false
60 #endif
61
62 /* True if addresses are being sanitized. */
63 #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
64 # define ADDRESS_SANITIZER true
65 #else
66 # define ADDRESS_SANITIZER false
67 #endif
68
69 #ifdef DARWIN_OS
70 #ifdef emacs
71 #define malloc unexec_malloc
72 #define realloc unexec_realloc
73 #define free unexec_free
74 #endif
75 /* The following solves the problem that Emacs hangs when evaluating
76 (make-comint "test0" "/nodir/nofile" nil "") when /nodir/nofile
77 does not exist. Also, setsid is not allowed in the vfork child's
78 context as of Darwin 9/Mac OS X 10.5. */
79 #undef HAVE_WORKING_VFORK
80 #define vfork fork
81 #endif /* DARWIN_OS */
82
83 /* We have to go this route, rather than the old hpux9 approach of
84 renaming the functions via macros. The system's stdlib.h has fully
85 prototyped declarations, which yields a conflicting definition of
86 srand48; it tries to redeclare what was once srandom to be srand48.
87 So we go with HAVE_LRAND48 being defined. */
88 #ifdef HPUX
89 #undef srandom
90 #undef random
91 #undef HAVE_RANDOM
92 #undef HAVE_RINT
93 #endif /* HPUX */
94
95 #ifdef IRIX6_5
96 #ifdef emacs
97 char *_getpty();
98 #endif
99 #define INET6 /* Needed for struct sockaddr_in6. */
100 #undef HAVE_GETADDRINFO /* IRIX has getaddrinfo but not struct addrinfo. */
101 #endif /* IRIX6_5 */
102
103 #ifdef MSDOS
104 #ifndef __DJGPP__
105 You lose; /* Emacs for DOS must be compiled with DJGPP */
106 #endif
107 #define _NAIVE_DOS_REGS
108
109 /* Start of gnulib-related stuff */
110
111 /* lib/ftoastr.c wants strtold, but DJGPP only has _strtold. DJGPP >
112 2.03 has it, but it also has _strtold as a stub that jumps to
113 strtold, so use _strtold in all versions. */
114 #define strtold _strtold
115
116 #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
117 # define HAVE_LSTAT 1
118 #else
119 # define lstat stat
120 #endif
121
122 /* We must intercept 'opendir' calls to stash away the directory name,
123 so we could reuse it in readlinkat; see msdos.c. */
124 #define opendir sys_opendir
125
126 /* The "portable" definition of _GL_INLINE on config.h does not work
127 with DJGPP GCC 3.4.4: it causes unresolved externals in sysdep.c,
128 although lib/execinfo.h is included and the inline functions there
129 are visible. */
130 #if __GNUC__ < 4
131 # define _GL_EXECINFO_INLINE inline
132 #endif
133 /* End of gnulib-related stuff. */
134
135 #define emacs_raise(sig) msdos_fatal_signal (sig)
136
137 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
138 #define DATA_START (&etext + 1)
139
140 /* Define one of these for easier conditionals. */
141 #ifdef HAVE_X_WINDOWS
142 /* We need a little extra space, see ../../lisp/loadup.el and the
143 commentary below, in the non-X branch. The 140KB number was
144 measured on GNU/Linux and on MS-Windows. */
145 #define SYSTEM_PURESIZE_EXTRA (-170000+140000)
146 #else
147 /* We need a little extra space, see ../../lisp/loadup.el.
148 As of 20091024, DOS-specific files use up 62KB of pure space. But
149 overall, we end up wasting 130KB of pure space, because
150 BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
151 non-DOS specific files and load history; the latter is about 55K,
152 but depends on the depth of the top-level Emacs directory in the
153 directory tree). Given the unknown policy of different DPMI
154 hosts regarding loading of untouched pages, I'm not going to risk
155 enlarging Emacs footprint by another 100+ KBytes. */
156 #define SYSTEM_PURESIZE_EXTRA (-170000+90000)
157 #endif
158 #endif /* MSDOS */
159
160 /* Mac OS X / GNUstep need a bit more pure memory. Of the existing knobs,
161 SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems. */
162 #ifdef HAVE_NS
163 #if defined NS_IMPL_GNUSTEP
164 # define SYSTEM_PURESIZE_EXTRA 30000
165 #elif defined DARWIN_OS
166 # define SYSTEM_PURESIZE_EXTRA 200000
167 #endif
168 #endif
169
170 #ifdef CYGWIN
171 #define SYSTEM_PURESIZE_EXTRA 10000
172 #endif
173
174 #if defined HAVE_NTGUI && !defined DebPrint
175 # ifdef EMACSDEBUG
176 extern void _DebPrint (const char *fmt, ...);
177 # define DebPrint(stuff) _DebPrint stuff
178 # else
179 # define DebPrint(stuff)
180 # endif
181 #endif
182
183 #if defined CYGWIN && defined HAVE_NTGUI
184 # define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
185 # define _WIN32_WINNT 0x500 /* Win2k */
186 #endif
187
188 #ifdef emacs /* Don't do this for lib-src. */
189 /* Tell regex.c to use a type compatible with Emacs. */
190 #define RE_TRANSLATE_TYPE Lisp_Object
191 #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
192 #define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_number (0)))
193 #endif
194
195 #include <string.h>
196 #include <stdlib.h>
197
198 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
199 #define NO_INLINE __attribute__((noinline))
200 #else
201 #define NO_INLINE
202 #endif
203
204 #if (__clang__ \
205 ? __has_attribute (externally_visible) \
206 : (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)))
207 #define EXTERNALLY_VISIBLE __attribute__((externally_visible))
208 #else
209 #define EXTERNALLY_VISIBLE
210 #endif
211
212 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
213 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
214 #else
215 # define ATTRIBUTE_FORMAT(spec) /* empty */
216 #endif
217
218 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
219 # define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
220 ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument))
221 #else
222 # define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
223 ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
224 #endif
225
226 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
227
228 #if 3 <= __GNUC__
229 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
230 #else
231 # define ATTRIBUTE_MALLOC
232 #endif
233
234 #if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
235 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
236 #else
237 # define ATTRIBUTE_ALLOC_SIZE(args)
238 #endif
239
240 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
241
242 /* Work around GCC bug 59600: when a function is inlined, the inlined
243 code may have its addresses sanitized even if the function has the
244 no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and
245 clang 3.4. */
246 #if (! ADDRESS_SANITIZER \
247 || ((4 < __GNUC__ + (9 <= __GNUC_MINOR__)) \
248 || 3 < __clang_major__ + (4 <= __clang_minor__)))
249 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed. */
250 #else
251 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
252 #endif
253
254 /* Attribute of functions whose code should not have addresses
255 sanitized. */
256
257 #if (__has_attribute (no_sanitize_address) \
258 || 4 < __GNUC__ + (8 <= __GNUC_MINOR__))
259 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
260 __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
261 #elif __has_attribute (no_address_safety_analysis)
262 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
263 __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
264 #else
265 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
266 #endif
267
268 /* Some versions of GNU/Linux define noinline in their headers. */
269 #ifdef noinline
270 #undef noinline
271 #endif
272
273 /* Use Gnulib's extern-inline module for extern inline functions.
274 An include file foo.h should prepend FOO_INLINE to function
275 definitions, with the following overall pattern:
276
277 [#include any other .h files first.]
278 ...
279 INLINE_HEADER_BEGIN
280 ...
281 INLINE int
282 incr (int i)
283 {
284 return i + 1;
285 }
286 ...
287 INLINE_HEADER_END
288
289 For every executable, exactly one file that includes the header
290 should do this:
291
292 #define INLINE EXTERN_INLINE
293
294 before including config.h or any other .h file.
295 Other .c files should not define INLINE.
296
297 C99 compilers compile functions like 'incr' as C99-style extern
298 inline functions. Pre-C99 GCCs do something similar with
299 GNU-specific keywords. Pre-C99 non-GCC compilers use static
300 functions, which bloats the code but is good enough. */
301
302 #ifndef INLINE
303 # define INLINE _GL_INLINE
304 #endif
305 #define EXTERN_INLINE _GL_EXTERN_INLINE
306 #define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
307 #define INLINE_HEADER_END _GL_INLINE_HEADER_END
308
309 /* To use the struct hack with N elements, declare the struct like this:
310 struct s { ...; t name[FLEXIBLE_ARRAY_MEMBER]; };
311 and allocate (offsetof (struct s, name) + N * sizeof (t)) bytes.
312 IBM xlc 12.1 claims to do C99 but mishandles flexible array members. */
313 #ifdef __IBMC__
314 # define FLEXIBLE_ARRAY_MEMBER 1
315 #else
316 # define FLEXIBLE_ARRAY_MEMBER
317 #endif
318
319 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
320 #ifdef lint
321 /* Use CODE only if lint checking is in effect. */
322 # define IF_LINT(Code) Code
323 #else
324 # define IF_LINT(Code) /* empty */
325 #endif
326
327 /* conf_post.h ends here */