1 /* conf_post.h --- configure.ac includes this via AH_BOTTOM
2 
3 Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2021 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 <https://www.gnu.org/licenses/>.  */
20 
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.  */
24 
25 /* Disable 'assert' unless enabling checking.  Do this early, in
26    case some misguided implementation depends on NDEBUG in some
27    include file other than assert.h.  */
28 #if !defined ENABLE_CHECKING && !defined NDEBUG
29 # define NDEBUG
30 #endif
31 
32 /* To help make dependencies clearer elsewhere, this file typically
33    does not #include other files.  The exceptions are first stdbool.h
34    because it is unlikely to interfere with configuration and bool is
35    such a core part of the C language, and second ms-w32.h (DOS_NT
36    only) because it historically was included here and changing that
37    would take some work.  */
38 
39 #include <stdbool.h>
40 
41 #if defined WINDOWSNT && !defined DEFER_MS_W32_H
42 # include <ms-w32.h>
43 #endif
44 
45 /* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later.
46    It can be used in a preprocessor expression.  */
47 #ifndef __GNUC_MINOR__
48 # define GNUC_PREREQ(v, w, x) false
49 #elif ! defined __GNUC_PATCHLEVEL__
50 # define GNUC_PREREQ(v, w, x) \
51     ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) == 0))
52 #else
53 # define GNUC_PREREQ(v, w, x) \
54     ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__)))
55 #endif
56 
57 /* The type of bool bitfields.  Needed to compile Objective-C with
58    standard GCC, and to make sure adjacent bool_bf fields are packed
59    into the same 1-, 2-, or 4-byte allocation unit in the MinGW
60    builds.  It was also needed to port to pre-C99 compilers, although
61    we don't care about that any more.  */
62 #if NS_IMPL_GNUSTEP || defined __MINGW32__
63 typedef unsigned int bool_bf;
64 #else
65 typedef bool bool_bf;
66 #endif
67 
68 /* Simulate __has_attribute on compilers that lack it.  It is used only
69    on arguments like alloc_size that are handled in this simulation.
70    __has_attribute should be used only in #if expressions, as Oracle
71    Studio 12.5's __has_attribute does not work in plain code.  */
72 #ifndef __has_attribute
73 # define __has_attribute(a) __has_attribute_##a
74 # define __has_attribute_alloc_size GNUC_PREREQ (4, 3, 0)
75 # define __has_attribute_cleanup GNUC_PREREQ (3, 4, 0)
76 # define __has_attribute_cold GNUC_PREREQ (4, 3, 0)
77 # define __has_attribute_externally_visible GNUC_PREREQ (4, 1, 0)
78 # define __has_attribute_no_address_safety_analysis false
79 # define __has_attribute_no_sanitize_address GNUC_PREREQ (4, 8, 0)
80 # define __has_attribute_no_sanitize_undefined GNUC_PREREQ (4, 9, 0)
81 # define __has_attribute_warn_unused_result GNUC_PREREQ (3, 4, 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 #if defined DARWIN_OS && defined emacs && defined HAVE_UNEXEC
98 # define malloc unexec_malloc
99 # define realloc unexec_realloc
100 # define free unexec_free
101 #endif
102 
103 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
104    gmalloc before dumping and the system malloc after dumping.
105    hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
106    accomplish this.  */
107 #ifdef HYBRID_MALLOC
108 #ifdef emacs
109 #define malloc hybrid_malloc
110 #define realloc hybrid_realloc
111 #define aligned_alloc hybrid_aligned_alloc
112 #define calloc hybrid_calloc
113 #define free hybrid_free
114 #endif
115 #endif	/* HYBRID_MALLOC */
116 
117 /* We have to go this route, rather than the old hpux9 approach of
118    renaming the functions via macros.  The system's stdlib.h has fully
119    prototyped declarations, which yields a conflicting definition of
120    srand48; it tries to redeclare what was once srandom to be srand48.
121    So we go with HAVE_LRAND48 being defined.  */
122 #ifdef HPUX
123 #undef srandom
124 #undef random
125 #undef HAVE_RANDOM
126 #undef HAVE_RINT
127 #endif  /* HPUX */
128 
129 #ifdef MSDOS
130 #ifndef __DJGPP__
131 You lose; /* Emacs for DOS must be compiled with DJGPP */
132 #endif
133 #define _NAIVE_DOS_REGS
134 
135 /* Start of gnulib-related stuff  */
136 
137 /* lib/ftoastr.c wants strtold, but DJGPP only has _strtold.  DJGPP >
138    2.03 has it, but it also has _strtold as a stub that jumps to
139    strtold, so use _strtold in all versions.  */
140 #define strtold _strtold
141 
142 #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
143 # define HAVE_LSTAT 1
144 #else
145 # define lstat stat
146 /* DJGPP 2.03 and older don't have the next two.  */
147 # define EOVERFLOW ERANGE
148 # define SIZE_MAX  4294967295U
149 #endif
150 
151 /* We must intercept 'opendir' calls to stash away the directory name,
152    so we could reuse it in readlinkat; see msdos.c.  */
153 #define opendir sys_opendir
154 
155 /* End of gnulib-related stuff.  */
156 
157 #define emacs_raise(sig) msdos_fatal_signal (sig)
158 
159 /* DATA_START is needed by vm-limit.c and unexcoff.c. */
160 #define DATA_START (&etext + 1)
161 
162 /* Define one of these for easier conditionals.  */
163 #ifdef HAVE_X_WINDOWS
164 /* We need a little extra space, see ../../lisp/loadup.el and the
165    commentary below, in the non-X branch.  The 140KB number was
166    measured on GNU/Linux and on MS-Windows.  */
167 #define SYSTEM_PURESIZE_EXTRA (-170000+140000)
168 #else
169 /* We need a little extra space, see ../../lisp/loadup.el.
170    As of 20091024, DOS-specific files use up 62KB of pure space.  But
171    overall, we end up wasting 130KB of pure space, because
172    BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
173    non-DOS specific files and load history; the latter is about 55K,
174    but depends on the depth of the top-level Emacs directory in the
175    directory tree).  Given the unknown policy of different DPMI
176    hosts regarding loading of untouched pages, I'm not going to risk
177    enlarging Emacs footprint by another 100+ KBytes.  */
178 #define SYSTEM_PURESIZE_EXTRA (-170000+90000)
179 #endif
180 #endif  /* MSDOS */
181 
182 /* macOS / GNUstep need a bit more pure memory.  Of the existing knobs,
183    SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems.  */
184 #ifdef HAVE_NS
185 #if defined NS_IMPL_GNUSTEP
186 #  define SYSTEM_PURESIZE_EXTRA 30000
187 #elif defined DARWIN_OS
188 #  define SYSTEM_PURESIZE_EXTRA 200000
189 #endif
190 #endif
191 
192 #ifdef CYGWIN
193 #define SYSTEM_PURESIZE_EXTRA 50000
194 #endif
195 
196 #if defined HAVE_NTGUI && !defined DebPrint
197 # ifdef EMACSDEBUG
198 extern void _DebPrint (const char *fmt, ...);
199 #  define DebPrint(stuff) _DebPrint stuff
200 # else
201 #  define DebPrint(stuff) ((void) 0)
202 # endif
203 #endif
204 
205 #if defined CYGWIN && defined HAVE_NTGUI
206 # define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
207 # define _WIN32_WINNT 0x500 /* Win2k */
208 /* The following was in /usr/include/string.h prior to Cygwin 1.7.33.  */
209 #ifndef strnicmp
210 #define strnicmp strncasecmp
211 #endif
212 #endif
213 
214 #ifdef emacs /* Don't do this for lib-src.  */
215 /* Tell regex.c to use a type compatible with Emacs.  */
216 #define RE_TRANSLATE_TYPE Lisp_Object
217 #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
218 #define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_fixnum (0)))
219 #endif
220 
221 /* Tell time_rz.c to use Emacs's getter and setter for TZ.
222    Only Emacs uses time_rz so this is OK.  */
223 #define getenv_TZ emacs_getenv_TZ
224 #define setenv_TZ emacs_setenv_TZ
225 extern char *emacs_getenv_TZ (void);
226 extern int emacs_setenv_TZ (char const *);
227 
228 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
229    <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>. */
230 #if __has_attribute (cold) && !defined __MINGW32__
231 # define ATTRIBUTE_COLD __attribute__ ((cold))
232 #else
233 # define ATTRIBUTE_COLD
234 #endif
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_PREREQ (2, 7, 0)
249 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
250 #else
251 # define ATTRIBUTE_FORMAT(spec) /* empty */
252 #endif
253 
254 #if GNUC_PREREQ (7, 0, 0)
255 # define FALLTHROUGH __attribute__ ((__fallthrough__))
256 #else
257 # define FALLTHROUGH ((void) 0)
258 #endif
259 
260 #if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
261 # define PRINTF_ARCHETYPE __gnu_printf__
262 #elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
263 # ifdef MINGW_W64
264 /* When __USE_MINGW_ANSI_STDIO is non-zero (as set by config.h),
265    MinGW64 replaces printf* with its own versions that are
266    __gnu_printf__ compatible, and emits warnings for MS native %I64d
267    format spec.  */
268 #  if __USE_MINGW_ANSI_STDIO
269 #   define PRINTF_ARCHETYPE __gnu_printf__
270 #  else
271 #   define PRINTF_ARCHETYPE __ms_printf__
272 #  endif
273 # else	/* mingw.org's MinGW */
274 /* Starting from runtime v5.0.0, mingw.org's MinGW with GCC 6 and
275    later turns on __USE_MINGW_ANSI_STDIO by default, replaces printf*
276    with its own __mingw_printf__ version, which still recognizes
277    %I64d.  */
278 #  if GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5
279 #   define PRINTF_ARCHETYPE __mingw_printf__
280 #  else  /* __MINGW32_MAJOR_VERSION < 5 */
281 #   define PRINTF_ARCHETYPE __ms_printf__
282 #  endif  /* __MINGW32_MAJOR_VERSION < 5 */
283 # endif	 /* MinGW */
284 #else
285 # define PRINTF_ARCHETYPE __printf__
286 #endif
287 #define ATTRIBUTE_FORMAT_PRINTF(string_index, first_to_check) \
288   ATTRIBUTE_FORMAT ((PRINTF_ARCHETYPE, string_index, first_to_check))
289 
290 #define ARG_NONNULL _GL_ARG_NONNULL
291 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
292 #define ATTRIBUTE_UNUSED _GL_UNUSED
293 
294 #if GNUC_PREREQ (3, 3, 0) && !defined __ICC
295 # define ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
296 #else
297 # define ATTRIBUTE_MAY_ALIAS
298 #endif
299 
300 /* Declare NAME to be a pointer to an object of type TYPE, initialized
301    to the address ADDR, which may be of a different type.  Accesses
302    via NAME may alias with other accesses with the traditional
303    behavior, even if options like gcc -fstrict-aliasing are used.  */
304 
305 #define DECLARE_POINTER_ALIAS(name, type, addr) \
306   type ATTRIBUTE_MAY_ALIAS *name = (type *) (addr)
307 
308 #if 3 <= __GNUC__
309 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
310 # define ATTRIBUTE_SECTION(name) __attribute__((section (name)))
311 #else
312 # define ATTRIBUTE_MALLOC
313 #define ATTRIBUTE_SECTION(name)
314 #endif
315 
316 #if __has_attribute (alloc_size)
317 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
318 #else
319 # define ATTRIBUTE_ALLOC_SIZE(args)
320 #endif
321 
322 #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args)
323 
324 /* Work around GCC bug 59600: when a function is inlined, the inlined
325    code may have its addresses sanitized even if the function has the
326    no_sanitize_address attribute.  This bug is fixed in GCC 4.9.0 and
327    clang 3.4.  */
328 #if (! ADDRESS_SANITIZER \
329      || (GNUC_PREREQ (4, 9, 0) \
330 	 || 3 < __clang_major__ + (4 <= __clang_minor__)))
331 # define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed.  */
332 #else
333 # define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
334 #endif
335 
336 /* Attribute of functions whose code should not have addresses
337    sanitized.  */
338 
339 #if __has_attribute (no_sanitize_address)
340 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
341     __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
342 #elif __has_attribute (no_address_safety_analysis)
343 # define ATTRIBUTE_NO_SANITIZE_ADDRESS \
344     __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
345 #else
346 # define ATTRIBUTE_NO_SANITIZE_ADDRESS
347 #endif
348 
349 /* Attribute of functions whose undefined behavior should not be sanitized.  */
350 
351 #if __has_attribute (no_sanitize_undefined)
352 # define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
353 #elif __has_attribute (no_sanitize)
354 # define ATTRIBUTE_NO_SANITIZE_UNDEFINED \
355     __attribute__ ((no_sanitize ("undefined")))
356 #else
357 # define ATTRIBUTE_NO_SANITIZE_UNDEFINED
358 #endif
359 
360 /* gcc -fsanitize=address does not work with vfork in Fedora 28 x86-64.  See:
361    https://lists.gnu.org/r/emacs-devel/2017-05/msg00464.html
362    For now, assume that this problem occurs on all platforms.  */
363 #if ADDRESS_SANITIZER && !defined vfork
364 # define vfork fork
365 #endif
366 
367 #if ! (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__)
368 # undef PROFILING
369 #endif
370 
371 /* Some versions of GNU/Linux define noinline in their headers.  */
372 #ifdef noinline
373 #undef noinline
374 #endif
375 
376 /* INLINE marks functions defined in Emacs-internal C headers.
377    INLINE is implemented via C99-style 'extern inline' if Emacs is built
378    with -DEMACS_EXTERN_INLINE; otherwise it is implemented via 'static'.
379    EMACS_EXTERN_INLINE is no longer the default, as 'static' seems to
380    have better performance with GCC.
381 
382    An include file foo.h should prepend INLINE to function
383    definitions, with the following overall pattern:
384 
385       [#include any other .h files first.]
386       ...
387       INLINE_HEADER_BEGIN
388       ...
389       INLINE int
390       incr (int i)
391       {
392         return i + 1;
393       }
394       ...
395       INLINE_HEADER_END
396 
397    For every executable, exactly one file that includes the header
398    should do this:
399 
400       #define INLINE EXTERN_INLINE
401 
402    before including config.h or any other .h file.
403    Other .c files should not define INLINE.
404    For Emacs, this is done by having emacs.c first '#define INLINE
405    EXTERN_INLINE' and then include every .h file that uses INLINE.
406 
407    The INLINE_HEADER_BEGIN and INLINE_HEADER_END macros suppress bogus
408    warnings in some GCC versions; see ../m4/extern-inline.m4.  */
409 
410 #ifdef EMACS_EXTERN_INLINE
411 
412 /* Use Gnulib's extern-inline module for extern inline functions.
413 
414    C99 compilers compile functions like 'incr' as C99-style extern
415    inline functions.  Buggy GCC implementations do something similar with
416    GNU-specific keywords.  Buggy non-GCC compilers use static
417    functions, which bloats the code but is good enough.  */
418 
419 # ifndef INLINE
420 #  define INLINE _GL_INLINE
421 # endif
422 # define EXTERN_INLINE _GL_EXTERN_INLINE
423 # define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
424 # define INLINE_HEADER_END _GL_INLINE_HEADER_END
425 
426 #else
427 
428 /* Use 'static' instead of 'extern inline' because 'static' typically
429    has better performance for Emacs.  Do not use the 'inline' keyword,
430    as modern compilers inline automatically.  ATTRIBUTE_UNUSED
431    pacifies gcc -Wunused-function.  */
432 
433 # ifndef INLINE
434 #  define INLINE EXTERN_INLINE
435 # endif
436 # define EXTERN_INLINE static ATTRIBUTE_UNUSED
437 # define INLINE_HEADER_BEGIN
438 # define INLINE_HEADER_END
439 
440 #endif
441 
442 /* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC
443    into not warning incorrectly about use of an uninitialized variable.  */
444 #if defined GCC_LINT || defined lint
445 # define UNINIT = {0,}
446 #else
447 # define UNINIT /* empty */
448 #endif
449