Pacify --enable-gcc-warnings for lib-src/pop.c
[emacs.git] / src / conf_post.h
blob865d0183a57380b05d13f880208d236322f059d5
1 /* conf_post.h --- configure.ac includes this via AH_BOTTOM
3 Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2016 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) \
43 ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) == 0))
44 #else
45 # define GNUC_PREREQ(v, w, x) \
46 ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__)))
47 #endif
49 /* The type of bool bitfields. Needed to compile Objective-C with
50 standard GCC. It was also needed to port to pre-C99 compilers,
51 although we don't care about that any more. */
52 #if NS_IMPL_GNUSTEP
53 typedef unsigned int bool_bf;
54 #else
55 typedef bool bool_bf;
56 #endif
58 #ifndef WINDOWSNT
59 /* On AIX 3 this must be included before any other include file. */
60 #include <alloca.h>
61 #if ! HAVE_ALLOCA
62 # error "alloca not available on this machine"
63 #endif
64 #endif
66 /* Simulate __has_attribute on compilers that lack it. It is used only
67 on arguments like alloc_size that are handled in this simulation. */
68 #ifndef __has_attribute
69 # define __has_attribute(a) __has_attribute_##a
70 # define __has_attribute_alloc_size GNUC_PREREQ (4, 3, 0)
71 # define __has_attribute_cleanup GNUC_PREREQ (3, 4, 0)
72 # define __has_attribute_externally_visible GNUC_PREREQ (4, 1, 0)
73 # define __has_attribute_no_address_safety_analysis false
74 # define __has_attribute_no_sanitize_address GNUC_PREREQ (4, 8, 0)
75 #endif
77 /* Simulate __has_builtin on compilers that lack it. It is used only
78 on arguments like __builtin_assume_aligned that are handled in this
79 simulation. */
80 #ifndef __has_builtin
81 # define __has_builtin(a) __has_builtin_##a
82 # define __has_builtin___builtin_assume_aligned GNUC_PREREQ (4, 7, 0)
83 #endif
85 /* Simulate __has_feature on compilers that lack it. It is used only
86 to define ADDRESS_SANITIZER below. */
87 #ifndef __has_feature
88 # define __has_feature(a) false
89 #endif
91 /* True if addresses are being sanitized. */
92 #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
93 # define ADDRESS_SANITIZER true
94 #else
95 # define ADDRESS_SANITIZER false
96 #endif
98 /* Yield PTR, which must be aligned to ALIGNMENT. */
99 #if ! __has_builtin (__builtin_assume_aligned)
100 # define __builtin_assume_aligned(ptr, ...) ((void *) (ptr))
101 #endif
103 #ifdef DARWIN_OS
104 #ifdef emacs
105 #define malloc unexec_malloc
106 #define realloc unexec_realloc
107 #define free unexec_free
108 #endif
109 /* The following solves the problem that Emacs hangs when evaluating
110 (make-comint "test0" "/nodir/nofile" nil "") when /nodir/nofile
111 does not exist. Also, setsid is not allowed in the vfork child's
112 context as of Darwin 9/Mac OS X 10.5. */
113 #undef HAVE_WORKING_VFORK
114 #define vfork fork
115 #endif /* DARWIN_OS */
117 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
118 gmalloc before dumping and the system malloc after dumping.
119 hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
120 accomplish this. */
121 #ifdef HYBRID_MALLOC
122 #ifdef emacs
123 #define malloc hybrid_malloc
124 #define realloc hybrid_realloc
125 #define aligned_alloc hybrid_aligned_alloc
126 #define calloc hybrid_calloc
127 #define free hybrid_free
128 #endif
129 #endif /* HYBRID_MALLOC */
131 /* We have to go this route, rather than the old hpux9 approach of
132 renaming the functions via macros. The system's stdlib.h has fully
133 prototyped declarations, which yields a conflicting definition of
134 srand48; it tries to redeclare what was once srandom to be srand48.
135 So we go with HAVE_LRAND48 being defined. */
136 #ifdef HPUX
137 #undef srandom
138 #undef random
139 #undef HAVE_RANDOM
140 #undef HAVE_RINT
141 #endif /* HPUX */
143 #ifdef MSDOS
144 #ifndef __DJGPP__
145 You lose; /* Emacs for DOS must be compiled with DJGPP */
146 #endif
147 #define _NAIVE_DOS_REGS
149 /* Start of gnulib-related stuff */
151 /* lib/ftoastr.c wants strtold, but DJGPP only has _strtold. DJGPP >
152 2.03 has it, but it also has _strtold as a stub that jumps to
153 strtold, so use _strtold in all versions. */
154 #define strtold _strtold
156 #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
157 # define HAVE_LSTAT 1
158 #else
159 # define lstat stat
160 /* DJGPP 2.03 and older don't have the next two. */
161 # define EOVERFLOW ERANGE
162 # define SIZE_MAX 4294967295U
163 #endif
165 /* We must intercept 'opendir' calls to stash away the directory name,
166 so we could reuse it in readlinkat; see msdos.c. */
167 #define opendir sys_opendir
169 /* End of gnulib-related stuff. */
171 #define emacs_raise(sig) msdos_fatal_signal (sig)
173 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
174 #define DATA_START (&etext + 1)
176 /* Define one of these for easier conditionals. */
177 #ifdef HAVE_X_WINDOWS
178 /* We need a little extra space, see ../../lisp/loadup.el and the
179 commentary below, in the non-X branch. The 140KB number was
180 measured on GNU/Linux and on MS-Windows. */
181 #define SYSTEM_PURESIZE_EXTRA (-170000+140000)
182 #else
183 /* We need a little extra space, see ../../lisp/loadup.el.
184 As of 20091024, DOS-specific files use up 62KB of pure space. But
185 overall, we end up wasting 130KB of pure space, because
186 BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
187 non-DOS specific files and load history; the latter is about 55K,
188 but depends on the depth of the top-level Emacs directory in the
189 directory tree). Given the unknown policy of different DPMI
190 hosts regarding loading of untouched pages, I'm not going to risk
191 enlarging Emacs footprint by another 100+ KBytes. */
192 #define SYSTEM_PURESIZE_EXTRA (-170000+90000)
193 #endif
194 #endif /* MSDOS */
196 /* Mac OS X / GNUstep need a bit more pure memory. Of the existing knobs,
197 SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems. */
198 #ifdef HAVE_NS
199 #if defined NS_IMPL_GNUSTEP
200 # define SYSTEM_PURESIZE_EXTRA 30000
201 #elif defined DARWIN_OS
202 # define SYSTEM_PURESIZE_EXTRA 200000
203 #endif
204 #endif
206 #ifdef CYGWIN
207 #define SYSTEM_PURESIZE_EXTRA 50000
208 #endif
210 #if defined HAVE_NTGUI && !defined DebPrint
211 # ifdef EMACSDEBUG
212 extern void _DebPrint (const char *fmt, ...);
213 # define DebPrint(stuff) _DebPrint stuff
214 # else
215 # define DebPrint(stuff) ((void) 0)
216 # endif
217 #endif
219 #if defined CYGWIN && defined HAVE_NTGUI
220 # define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
221 # define _WIN32_WINNT 0x500 /* Win2k */
222 /* The following was in /usr/include/string.h prior to Cygwin 1.7.33. */
223 #ifndef strnicmp
224 #define strnicmp strncasecmp
225 #endif
226 #endif
228 #ifdef emacs /* Don't do this for lib-src. */
229 /* Tell regex.c to use a type compatible with Emacs. */
230 #define RE_TRANSLATE_TYPE Lisp_Object
231 #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
232 #define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_number (0)))
233 #endif
235 /* Tell time_rz.c to use Emacs's getter and setter for TZ.
236 Only Emacs uses time_rz so this is OK. */
237 #define getenv_TZ emacs_getenv_TZ
238 #define setenv_TZ emacs_setenv_TZ
239 extern char *emacs_getenv_TZ (void);
240 extern int emacs_setenv_TZ (char const *);
242 #include <string.h>
243 #include <stdlib.h>
245 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
246 #define NO_INLINE __attribute__((noinline))
247 #else
248 #define NO_INLINE
249 #endif
251 #if __has_attribute (externally_visible)
252 #define EXTERNALLY_VISIBLE __attribute__((externally_visible))
253 #else
254 #define EXTERNALLY_VISIBLE
255 #endif
257 #if GNUC_PREREQ (2, 7, 0)
258 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
259 #else
260 # define ATTRIBUTE_FORMAT(spec) /* empty */
261 #endif
263 #if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
264 # define PRINTF_ARCHETYPE __gnu_printf__
265 #elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
266 # define PRINTF_ARCHETYPE __ms_printf__
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 3 <= __GNUC__
277 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
278 #else
279 # define ATTRIBUTE_MALLOC
280 #endif
282 #if __has_attribute (alloc_size)
283 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
284 #else
285 # define ATTRIBUTE_ALLOC_SIZE(args)
286 #endif
288 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
290 /* Work around GCC bug 59600: when a function is inlined, the inlined
291 code may have its addresses sanitized even if the function has the
292 no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and
293 clang 3.4. */
294 #if (! ADDRESS_SANITIZER \
295 || (GNUC_PREREQ (4, 9, 0) \
296 || 3 < __clang_major__ + (4 <= __clang_minor__)))
297 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed. */
298 #else
299 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
300 #endif
302 /* Attribute of functions whose code should not have addresses
303 sanitized. */
305 #if __has_attribute (no_sanitize_address)
306 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
307 __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
308 #elif __has_attribute (no_address_safety_analysis)
309 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
310 __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
311 #else
312 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
313 #endif
315 /* Some versions of GNU/Linux define noinline in their headers. */
316 #ifdef noinline
317 #undef noinline
318 #endif
320 /* Use Gnulib's extern-inline module for extern inline functions.
321 An include file foo.h should prepend FOO_INLINE to function
322 definitions, with the following overall pattern:
324 [#include any other .h files first.]
326 INLINE_HEADER_BEGIN
328 INLINE int
329 incr (int i)
331 return i + 1;
334 INLINE_HEADER_END
336 For every executable, exactly one file that includes the header
337 should do this:
339 #define INLINE EXTERN_INLINE
341 before including config.h or any other .h file.
342 Other .c files should not define INLINE.
343 For Emacs, this is done by having emacs.c first '#define INLINE
344 EXTERN_INLINE' and then include every .h file that uses INLINE.
346 The INLINE_HEADER_BEGIN and INLINE_HEADER_END suppress bogus
347 warnings in some GCC versions; see ../m4/extern-inline.m4.
349 C99 compilers compile functions like 'incr' as C99-style extern
350 inline functions. Buggy GCC implementations do something similar with
351 GNU-specific keywords. Buggy non-GCC compilers use static
352 functions, which bloats the code but is good enough. */
354 #ifndef INLINE
355 # define INLINE _GL_INLINE
356 #endif
357 #define EXTERN_INLINE _GL_EXTERN_INLINE
358 #define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
359 #define INLINE_HEADER_END _GL_INLINE_HEADER_END
361 /* To use the struct hack with N elements, declare the struct like this:
362 struct s { ...; t name[FLEXIBLE_ARRAY_MEMBER]; };
363 and allocate (offsetof (struct s, name) + N * sizeof (t)) bytes.
364 IBM xlc 12.1 claims to do C99 but mishandles flexible array members. */
365 #ifdef __IBMC__
366 # define FLEXIBLE_ARRAY_MEMBER 1
367 #else
368 # define FLEXIBLE_ARRAY_MEMBER
369 #endif
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
379 /* conf_post.h ends here */