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