conf_post.h 13.6 KB
Newer Older
1 2
/* conf_post.h --- configure.ac includes this via AH_BOTTOM

Paul Eggert's avatar
Paul Eggert committed
3
Copyright (C) 1988, 1993-1994, 1999-2002, 2004-2020 Free Software
4
Foundation, Inc.
5 6 7 8 9

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
10 11
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
12 13 14 15 16 17 18

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

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

Paul Eggert's avatar
Paul Eggert committed
21 22
/* Put the code here rather than in configure.ac using AH_BOTTOM.
   This way, the code does not get processed by autoheader.  For
23
   example, undefs here are not commented out.  */
24

25 26 27 28 29 30 31 32
/* Disable 'assert' unless enabling checking.  Do this early, in
   case some misguided implementation depends on NDEBUG in some
   include file other than assert.h.  */
#if !defined ENABLE_CHECKING && !defined NDEBUG
# define NDEBUG
#endif

/* To help make dependencies clearer elsewhere, this file typically
33
   does not #include other files.  The exceptions are stdbool.h
Paul Eggert's avatar
Paul Eggert committed
34
   because it is unlikely to interfere with configuration and bool is
35 36
   such a core part of the C language, attribute.h because its
   ATTRIBUTE_* macros are used here, and ms-w32.h (DOS_NT
Paul Eggert's avatar
Paul Eggert committed
37 38
   only) because it historically was included here and changing that
   would take some work.  */
39

Paul Eggert's avatar
Paul Eggert committed
40
#include <stdbool.h>
41
#include <attribute.h>
42

Eli Zaretskii's avatar
Eli Zaretskii committed
43
#if defined WINDOWSNT && !defined DEFER_MS_W32_H
Paul Eggert's avatar
Paul Eggert committed
44
# include <ms-w32.h>
45 46
#endif

47 48 49 50 51
/* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later.
   It can be used in a preprocessor expression.  */
#ifndef __GNUC_MINOR__
# define GNUC_PREREQ(v, w, x) false
#elif ! defined __GNUC_PATCHLEVEL__
52 53
# define GNUC_PREREQ(v, w, x) \
    ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) == 0))
54 55
#else
# define GNUC_PREREQ(v, w, x) \
Paul Eggert's avatar
Paul Eggert committed
56
    ((v) < __GNUC__ + ((w) < __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__)))
57 58
#endif

Paul Eggert's avatar
Paul Eggert committed
59
/* The type of bool bitfields.  Needed to compile Objective-C with
60 61 62 63
   standard GCC, and to make sure adjacent bool_bf fields are packed
   into the same 1-, 2-, or 4-byte allocation unit in the MinGW
   builds.  It was also needed to port to pre-C99 compilers, although
   we don't care about that any more.  */
64
#if NS_IMPL_GNUSTEP || defined __MINGW32__
65 66 67 68 69
typedef unsigned int bool_bf;
#else
typedef bool bool_bf;
#endif

70 71 72
/* A substitute for __has_attribute on compilers that lack it.
   It is used only on arguments like cleanup that are handled here.
   This macro should be used only in #if expressions, as Oracle
73
   Studio 12.5's __has_attribute does not work in plain code.  */
74 75 76 77 78 79
#ifdef __has_attribute
# define HAS_ATTRIBUTE(a) __has_attribute (__##a##__)
#else
# define HAS_ATTRIBUTE(a) HAS_ATTR_##a
# define HAS_ATTR_cleanup GNUC_PREREQ (3, 4, 0)
# define HAS_ATTR_no_address_safety_analysis false
80
# define HAS_ATTR_no_sanitize false
81 82
# define HAS_ATTR_no_sanitize_address GNUC_PREREQ (4, 8, 0)
# define HAS_ATTR_no_sanitize_undefined GNUC_PREREQ (4, 9, 0)
83
#endif
84

85
/* A substitute for __has_feature on compilers that lack it.  It is used only
86
   to define ADDRESS_SANITIZER below.  */
87 88 89 90
#ifdef __has_feature
# define HAS_FEATURE(a) __has_feature (a)
#else
# define HAS_FEATURE(a) false
91 92 93
#endif

/* True if addresses are being sanitized.  */
94
#if defined __SANITIZE_ADDRESS__ || HAS_FEATURE (address_sanitizer)
95 96 97
# define ADDRESS_SANITIZER true
#else
# define ADDRESS_SANITIZER false
98 99
#endif

100 101 102 103
#if defined DARWIN_OS && defined emacs && defined HAVE_UNEXEC
# define malloc unexec_malloc
# define realloc unexec_realloc
# define free unexec_free
Glenn Morris's avatar
Glenn Morris committed
104 105
#endif

106 107 108 109 110 111 112 113
/* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
   gmalloc before dumping and the system malloc after dumping.
   hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
   accomplish this.  */
#ifdef HYBRID_MALLOC
#ifdef emacs
#define malloc hybrid_malloc
#define realloc hybrid_realloc
114
#define aligned_alloc hybrid_aligned_alloc
Wolfgang Jenkner's avatar
Wolfgang Jenkner committed
115
#define calloc hybrid_calloc
116 117 118 119
#define free hybrid_free
#endif
#endif	/* HYBRID_MALLOC */

Glenn Morris's avatar
Glenn Morris committed
120 121 122 123 124 125 126 127 128 129 130 131
/* We have to go this route, rather than the old hpux9 approach of
   renaming the functions via macros.  The system's stdlib.h has fully
   prototyped declarations, which yields a conflicting definition of
   srand48; it tries to redeclare what was once srandom to be srand48.
   So we go with HAVE_LRAND48 being defined.  */
#ifdef HPUX
#undef srandom
#undef random
#undef HAVE_RANDOM
#undef HAVE_RINT
#endif  /* HPUX */

Glenn Morris's avatar
Glenn Morris committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#ifdef MSDOS
#ifndef __DJGPP__
You lose; /* Emacs for DOS must be compiled with DJGPP */
#endif
#define _NAIVE_DOS_REGS

/* Start of gnulib-related stuff  */

/* lib/ftoastr.c wants strtold, but DJGPP only has _strtold.  DJGPP >
   2.03 has it, but it also has _strtold as a stub that jumps to
   strtold, so use _strtold in all versions.  */
#define strtold _strtold

#if __DJGPP__ > 2 || __DJGPP_MINOR__ > 3
# define HAVE_LSTAT 1
#else
# define lstat stat
Eli Zaretskii's avatar
Eli Zaretskii committed
149 150 151
/* DJGPP 2.03 and older don't have the next two.  */
# define EOVERFLOW ERANGE
# define SIZE_MAX  4294967295U
Glenn Morris's avatar
Glenn Morris committed
152
#endif
Eli Zaretskii's avatar
Eli Zaretskii committed
153 154

/* We must intercept 'opendir' calls to stash away the directory name,
Paul Eggert's avatar
Paul Eggert committed
155
   so we could reuse it in readlinkat; see msdos.c.  */
Eli Zaretskii's avatar
Eli Zaretskii committed
156 157
#define opendir sys_opendir

Glenn Morris's avatar
Glenn Morris committed
158 159
/* End of gnulib-related stuff.  */

160 161
#define emacs_raise(sig) msdos_fatal_signal (sig)

Eli Zaretskii's avatar
Eli Zaretskii committed
162 163 164
/* DATA_START is needed by vm-limit.c and unexcoff.c. */
#define DATA_START (&etext + 1)

Glenn Morris's avatar
Glenn Morris committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
/* Define one of these for easier conditionals.  */
#ifdef HAVE_X_WINDOWS
/* We need a little extra space, see ../../lisp/loadup.el and the
   commentary below, in the non-X branch.  The 140KB number was
   measured on GNU/Linux and on MS-Windows.  */
#define SYSTEM_PURESIZE_EXTRA (-170000+140000)
#else
/* We need a little extra space, see ../../lisp/loadup.el.
   As of 20091024, DOS-specific files use up 62KB of pure space.  But
   overall, we end up wasting 130KB of pure space, because
   BASE_PURESIZE starts at 1.47MB, while we need only 1.3MB (including
   non-DOS specific files and load history; the latter is about 55K,
   but depends on the depth of the top-level Emacs directory in the
   directory tree).  Given the unknown policy of different DPMI
   hosts regarding loading of untouched pages, I'm not going to risk
   enlarging Emacs footprint by another 100+ KBytes.  */
Eli Zaretskii's avatar
Eli Zaretskii committed
181
#define SYSTEM_PURESIZE_EXTRA (-170000+90000)
Glenn Morris's avatar
Glenn Morris committed
182
#endif
Glenn Morris's avatar
Glenn Morris committed
183
#endif  /* MSDOS */
Glenn Morris's avatar
Glenn Morris committed
184

185
/* macOS / GNUstep need a bit more pure memory.  Of the existing knobs,
186 187 188 189 190 191 192 193 194
   SYSTEM_PURESIZE_EXTRA seems like the least likely to cause problems.  */
#ifdef HAVE_NS
#if defined NS_IMPL_GNUSTEP
#  define SYSTEM_PURESIZE_EXTRA 30000
#elif defined DARWIN_OS
#  define SYSTEM_PURESIZE_EXTRA 200000
#endif
#endif

195
#ifdef CYGWIN
196
#define SYSTEM_PURESIZE_EXTRA 50000
197 198
#endif

199 200
#if defined HAVE_NTGUI && !defined DebPrint
# ifdef EMACSDEBUG
Daniel Colascione's avatar
Daniel Colascione committed
201 202 203
extern void _DebPrint (const char *fmt, ...);
#  define DebPrint(stuff) _DebPrint stuff
# else
204
#  define DebPrint(stuff) ((void) 0)
205 206
# endif
#endif
Daniel Colascione's avatar
Daniel Colascione committed
207

208 209 210
#if defined CYGWIN && defined HAVE_NTGUI
# define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
# define _WIN32_WINNT 0x500 /* Win2k */
211 212 213 214
/* The following was in /usr/include/string.h prior to Cygwin 1.7.33.  */
#ifndef strnicmp
#define strnicmp strncasecmp
#endif
215
#endif
Daniel Colascione's avatar
Daniel Colascione committed
216

217 218 219
#ifdef emacs /* Don't do this for lib-src.  */
/* Tell regex.c to use a type compatible with Emacs.  */
#define RE_TRANSLATE_TYPE Lisp_Object
220
#define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C)
221
#define RE_TRANSLATE_P(TBL) (!EQ (TBL, make_fixnum (0)))
222 223
#endif

224 225 226 227 228 229 230
/* Tell time_rz.c to use Emacs's getter and setter for TZ.
   Only Emacs uses time_rz so this is OK.  */
#define getenv_TZ emacs_getenv_TZ
#define setenv_TZ emacs_setenv_TZ
extern char *emacs_getenv_TZ (void);
extern int emacs_setenv_TZ (char const *);

231 232
#define NO_INLINE ATTRIBUTE_NOINLINE
#define EXTERNALLY_VISIBLE ATTRIBUTE_EXTERNALLY_VISIBLE
233

234 235 236
#if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
# define PRINTF_ARCHETYPE __gnu_printf__
#elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
# ifdef MINGW_W64
/* When __USE_MINGW_ANSI_STDIO is non-zero (as set by config.h),
   MinGW64 replaces printf* with its own versions that are
   __gnu_printf__ compatible, and emits warnings for MS native %I64d
   format spec.  */
#  if __USE_MINGW_ANSI_STDIO
#   define PRINTF_ARCHETYPE __gnu_printf__
#  else
#   define PRINTF_ARCHETYPE __ms_printf__
#  endif
# else	/* mingw.org's MinGW */
/* Starting from runtime v5.0.0, mingw.org's MinGW with GCC 6 and
   later turns on __USE_MINGW_ANSI_STDIO by default, replaces printf*
   with its own __mingw_printf__ version, which still recognizes
   %I64d.  */
#  if GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5
#   define PRINTF_ARCHETYPE __mingw_printf__
#  else  /* __MINGW32_MAJOR_VERSION < 5 */
#   define PRINTF_ARCHETYPE __ms_printf__
#  endif  /* __MINGW32_MAJOR_VERSION < 5 */
# endif	 /* MinGW */
258 259 260 261 262
#else
# define PRINTF_ARCHETYPE __printf__
#endif
#define ATTRIBUTE_FORMAT_PRINTF(string_index, first_to_check) \
  ATTRIBUTE_FORMAT ((PRINTF_ARCHETYPE, string_index, first_to_check))
263

264 265
#define ARG_NONNULL ATTRIBUTE_NONNULL
#define ATTRIBUTE_UNUSED MAYBE_UNUSED
266 267 268 269 270 271 272 273 274

/* Declare NAME to be a pointer to an object of type TYPE, initialized
   to the address ADDR, which may be of a different type.  Accesses
   via NAME may alias with other accesses with the traditional
   behavior, even if options like gcc -fstrict-aliasing are used.  */

#define DECLARE_POINTER_ALIAS(name, type, addr) \
  type ATTRIBUTE_MAY_ALIAS *name = (type *) (addr)

275
#if 3 <= __GNUC__
Daniel Colascione's avatar
Daniel Colascione committed
276
# define ATTRIBUTE_SECTION(name) __attribute__((section (name)))
277
#else
Daniel Colascione's avatar
Daniel Colascione committed
278
#define ATTRIBUTE_SECTION(name)
279 280 281 282
#endif

#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
   code may have its addresses sanitized even if the function has the
285 286 287
   no_sanitize_address attribute.  This bug is fixed in GCC 4.9.0 and
   clang 3.4.  */
#if (! ADDRESS_SANITIZER \
288
     || (GNUC_PREREQ (4, 9, 0) \
289 290
	 || 3 < __clang_major__ + (4 <= __clang_minor__)))
# define ADDRESS_SANITIZER_WORKAROUND /* No workaround needed.  */
291
#else
292
# define ADDRESS_SANITIZER_WORKAROUND NO_INLINE
293 294 295 296 297
#endif

/* Attribute of functions whose code should not have addresses
   sanitized.  */

298
#if HAS_ATTRIBUTE (no_sanitize_address)
299 300
# define ATTRIBUTE_NO_SANITIZE_ADDRESS \
    __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND
301
#elif HAS_ATTRIBUTE (no_address_safety_analysis)
302 303 304 305 306 307
# define ATTRIBUTE_NO_SANITIZE_ADDRESS \
    __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND
#else
# define ATTRIBUTE_NO_SANITIZE_ADDRESS
#endif

308 309
/* Attribute of functions whose undefined behavior should not be sanitized.  */

310
#if HAS_ATTRIBUTE (no_sanitize_undefined)
311
# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
312
#elif HAS_ATTRIBUTE (no_sanitize)
313 314 315 316 317 318
# define ATTRIBUTE_NO_SANITIZE_UNDEFINED \
    __attribute__ ((no_sanitize ("undefined")))
#else
# define ATTRIBUTE_NO_SANITIZE_UNDEFINED
#endif

319 320
/* gcc -fsanitize=address does not work with vfork in Fedora 28 x86-64.  See:
   https://lists.gnu.org/r/emacs-devel/2017-05/msg00464.html
321 322 323 324 325
   For now, assume that this problem occurs on all platforms.  */
#if ADDRESS_SANITIZER && !defined vfork
# define vfork fork
#endif

326 327 328 329
#if ! (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__)
# undef PROFILING
#endif

330 331 332 333 334
/* Some versions of GNU/Linux define noinline in their headers.  */
#ifdef noinline
#undef noinline
#endif

335 336 337 338 339 340 341
/* INLINE marks functions defined in Emacs-internal C headers.
   INLINE is implemented via C99-style 'extern inline' if Emacs is built
   with -DEMACS_EXTERN_INLINE; otherwise it is implemented via 'static'.
   EMACS_EXTERN_INLINE is no longer the default, as 'static' seems to
   have better performance with GCC.

   An include file foo.h should prepend INLINE to function
342 343 344 345 346 347
   definitions, with the following overall pattern:

      [#include any other .h files first.]
      ...
      INLINE_HEADER_BEGIN
      ...
Paul Eggert's avatar
Paul Eggert committed
348
      INLINE int
349 350 351 352 353 354 355
      incr (int i)
      {
        return i + 1;
      }
      ...
      INLINE_HEADER_END

Paul Eggert's avatar
Paul Eggert committed
356 357
   For every executable, exactly one file that includes the header
   should do this:
358

Paul Eggert's avatar
Paul Eggert committed
359
      #define INLINE EXTERN_INLINE
360

Paul Eggert's avatar
Paul Eggert committed
361 362
   before including config.h or any other .h file.
   Other .c files should not define INLINE.
363 364 365
   For Emacs, this is done by having emacs.c first '#define INLINE
   EXTERN_INLINE' and then include every .h file that uses INLINE.

366 367 368 369 370 371
   The INLINE_HEADER_BEGIN and INLINE_HEADER_END macros suppress bogus
   warnings in some GCC versions; see ../m4/extern-inline.m4.  */

#ifdef EMACS_EXTERN_INLINE

/* Use Gnulib's extern-inline module for extern inline functions.
372 373

   C99 compilers compile functions like 'incr' as C99-style extern
374 375
   inline functions.  Buggy GCC implementations do something similar with
   GNU-specific keywords.  Buggy non-GCC compilers use static
376 377
   functions, which bloats the code but is good enough.  */

378 379 380 381 382 383 384 385 386
# ifndef INLINE
#  define INLINE _GL_INLINE
# endif
# define EXTERN_INLINE _GL_EXTERN_INLINE
# define INLINE_HEADER_BEGIN _GL_INLINE_HEADER_BEGIN
# define INLINE_HEADER_END _GL_INLINE_HEADER_END

#else

387 388
/* Use 'static inline' instead of 'extern inline' because 'static inline'
   has much better performance for Emacs when compiled with 'gcc -Og'.  */
389 390 391 392

# ifndef INLINE
#  define INLINE EXTERN_INLINE
# endif
393
# define EXTERN_INLINE static inline
394 395 396
# define INLINE_HEADER_BEGIN
# define INLINE_HEADER_END

Paul Eggert's avatar
Paul Eggert committed
397
#endif
398

399 400 401 402 403 404
/* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC
   into not warning incorrectly about use of an uninitialized variable.  */
#if defined GCC_LINT || defined lint
# define UNINIT = {0,}
#else
# define UNINIT /* empty */
405
#endif