root/src/conf_post.h

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

/* [<][>][^][v][top][bottom][index][help] */