root/src/lisp.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. DEFINE_GDB_SYMBOL_END
  2. bignum_to_double
  3. will_dump_p
  4. will_bootstrap_p
  5. will_dump_with_pdumper_p
  6. dumped_with_pdumper_p
  7. will_dump_with_unexec_p
  8. dumped_with_unexec_p
  9. definitely_will_not_unexec_p
  10. DEFINE_GDB_SYMBOL_END
  11. PSEUDOVECTORP
  12. XSYMBOL_WITH_POS
  13. make_lisp_symbol
  14. builtin_lisp_symbol
  15. c_symbol_p
  16. make_ufixnum
  17. make_fixnum
  18. XFIXNUM_RAW
  19. make_ufixnum
  20. XFIXNUM
  21. XUFIXNUM_RAW
  22. XUFIXNUM
  23. make_fixed_natnum
  24. clip_to_bounds
  25. make_lisp_ptr
  26. dead_object
  27. XFIXNUMPTR
  28. make_pointer_integer_unsafe
  29. make_pointer_integer
  30. CHECK_CONS
  31. xcar_addr
  32. xcdr_addr
  33. XSETCAR
  34. XSETCDR
  35. CAR
  36. CDR
  37. CAR_SAFE
  38. CDR_SAFE
  39. STRINGP
  40. CHECK_STRING
  41. XSTRING
  42. STRING_MULTIBYTE
  43. STRING_SET_MULTIBYTE
  44. SDATA
  45. SSDATA
  46. SREF
  47. SSET
  48. SCHARS
  49. STRING_BYTES
  50. SBYTES
  51. STRING_SET_CHARS
  52. CHECK_STRING_NULL_BYTES
  53. string_immovable_p
  54. XVECTOR
  55. ASIZE
  56. gc_asize
  57. PVSIZE
  58. VECTORP
  59. CHECK_VECTOR
  60. PSEUDOVECTOR_TYPE
  61. PSEUDOVECTOR_TYPEP
  62. bool_vector_words
  63. bool_vector_bytes
  64. BOOL_VECTOR_P
  65. CHECK_BOOL_VECTOR
  66. XBOOL_VECTOR
  67. bool_vector_size
  68. bool_vector_data
  69. bool_vector_uchar_data
  70. bool_vector_bitref
  71. bool_vector_ref
  72. bool_vector_set
  73. AREF
  74. aref_addr
  75. ASET
  76. gc_aset
  77. memclear
  78. ASCII_CHAR_P
  79. CHAR_TABLE_P
  80. XCHAR_TABLE
  81. SUB_CHAR_TABLE_P
  82. XSUB_CHAR_TABLE
  83. CHAR_TABLE_REF_ASCII
  84. CHAR_TABLE_REF
  85. CHAR_TABLE_SET
  86. SUBRP
  87. XSUBR
  88. VALID_DOCSTRING_P
  89. CHAR_TABLE_EXTRA_SLOTS
  90. SYMBOL_ALIAS
  91. SYMBOL_BLV
  92. SYMBOL_FWD
  93. SET_SYMBOL_ALIAS
  94. SET_SYMBOL_BLV
  95. SET_SYMBOL_FWD
  96. SYMBOL_NAME
  97. SYMBOL_INTERNED_P
  98. SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P
  99. HASH_TABLE_P
  100. XHASH_TABLE
  101. HASH_KEY
  102. HASH_VALUE
  103. HASH_HASH
  104. HASH_TABLE_SIZE
  105. sxhash_combine
  106. SXHASH_REDUCE
  107. make_mint_ptr
  108. mint_ptrp
  109. xmint_pointer
  110. FINALIZERP
  111. XFINALIZER
  112. MARKERP
  113. XMARKER
  114. OVERLAYP
  115. XOVERLAY
  116. SYMBOL_WITH_POS_SYM
  117. SYMBOL_WITH_POS_POS
  118. USER_PTRP
  119. XUSER_PTR
  120. SQLITEP
  121. SQLITE
  122. CHECK_SQLITE
  123. XSQLITE
  124. BIGNUMP
  125. INTEGERP
  126. make_int
  127. make_uint
  128. XFWDTYPE
  129. BUFFER_OBJFWDP
  130. XBUFFER_OBJFWD
  131. XFLOAT
  132. XFLOAT_DATA
  133. FIXNATP
  134. XFIXNAT
  135. NUMBERP
  136. RANGED_FIXNUMP
  137. AUTOLOADP
  138. WINDOW_CONFIGURATIONP
  139. COMPILEDP
  140. FRAMEP
  141. RECORDP
  142. CHECK_RECORD
  143. IMAGEP
  144. ARRAYP
  145. CHECK_LIST
  146. CHECK_LIST_END
  147. CHECK_STRING_CAR
  148. CHECK_VECTOR_OR_STRING
  149. CHECK_ARRAY
  150. CHECK_FIXNAT
  151. XFLOATINT
  152. CHECK_NUMBER
  153. CHECK_INTEGER
  154. CHECK_SUBR
  155. call0
  156. call1
  157. call2
  158. call3
  159. call4
  160. call5
  161. call6
  162. call7
  163. call8
  164. wrap_specpdl_ref
  165. unwrap_specpdl_ref
  166. specpdl_count_to_ref
  167. specpdl_ref_to_count
  168. specpdl_ref_eq
  169. specpdl_ref_lt
  170. specpdl_ref_valid_p
  171. make_invalid_specpdl_ref
  172. specpdl_ref_add
  173. specpdl_ref_to_ptr
  174. SPECPDL_INDEX
  175. backtrace_debug_on_exit
  176. grow_specpdl
  177. record_in_backtrace
  178. maybe_quit
  179. rarely_quit
  180. xvector_contents_addr
  181. xvector_contents
  182. vcopy
  183. set_hash_key_slot
  184. set_hash_value_slot
  185. set_symbol_function
  186. set_symbol_plist
  187. set_symbol_next
  188. make_symbol_constant
  189. blv_found
  190. set_overlay_plist
  191. string_intervals
  192. set_string_intervals
  193. set_char_table_defalt
  194. set_char_table_purpose
  195. set_char_table_extras
  196. set_char_table_contents
  197. set_sub_char_table_contents
  198. bignum_to_intmax
  199. integer_to_uintmax
  200. elogb
  201. modiff_incr
  202. modiff_to_integer
  203. flush_stack_call_func
  204. list1i
  205. list2i
  206. list3i
  207. list4i
  208. make_formatted_string
  209. build_unibyte_string
  210. build_pure_c_string
  211. build_string
  212. allocate_nil_vector
  213. make_uninit_sub_char_table
  214. make_nil_vector
  215. esprintf
  216. intern
  217. intern_c_string
  218. xsignal
  219. push_handler
  220. XMODULE_FUNCTION
  221. splice_dir_file
  222. fast_string_match_ignore_case
  223. fast_c_string_match
  224. fast_c_string_match_ignore_case
  225. fixup_locale
  226. synchronize_system_messages_locale
  227. synchronize_system_time_locale
  228. make_environment_block
  229. set_act_rec
  230. maybe_disable_address_randomization
  231. emacs_fdopen
  232. SUBR_NATIVE_COMPILED_DYNP
  233. SUBR_TYPE
  234. allocate_native_comp_unit
  235. SUBR_NATIVE_COMPILEDP
  236. SUBR_NATIVE_COMPILED_DYNP
  237. xmalloc
  238. __lsan_ignore_object
  239. egetenv
  240. safe_free
  241. safe_free_unbind_to
  242. maybe_gc

     1 /* Fundamental definitions for GNU Emacs Lisp interpreter. -*- coding: utf-8 -*-
     2 
     3 Copyright (C) 1985-2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 #ifndef EMACS_LISP_H
    21 #define EMACS_LISP_H
    22 
    23 #include <alloca.h>
    24 #include <setjmp.h>
    25 #include <stdarg.h>
    26 #include <stdckdint.h>
    27 #include <stddef.h>
    28 #include <string.h>
    29 #include <float.h>
    30 #include <inttypes.h>
    31 #include <limits.h>
    32 #include <stdio.h>
    33 
    34 #ifdef HAVE_SYS_STAT_H
    35 #include <sys/stat.h>
    36 #endif
    37 
    38 #include <attribute.h>
    39 #include <count-leading-zeros.h>
    40 #include <intprops.h>
    41 #include <verify.h>
    42 
    43 INLINE_HEADER_BEGIN
    44 
    45 /* Define a TYPE constant ID as an externally visible name.  Use like this:
    46 
    47       DEFINE_GDB_SYMBOL_BEGIN (TYPE, ID)
    48       # define ID (some integer preprocessor expression of type TYPE)
    49       DEFINE_GDB_SYMBOL_END (ID)
    50 
    51    This hack is for the benefit of compilers that do not make macro
    52    definitions or enums visible to the debugger.  It's used for symbols
    53    that .gdbinit needs.  */
    54 
    55 #define DECLARE_GDB_SYM(type, id) type const id EXTERNALLY_VISIBLE
    56 #ifdef MAIN_PROGRAM
    57 # define DEFINE_GDB_SYMBOL_BEGIN(type, id) DECLARE_GDB_SYM (type, id)
    58 # define DEFINE_GDB_SYMBOL_END(id) = id;
    59 #else
    60 # define DEFINE_GDB_SYMBOL_BEGIN(type, id) extern DECLARE_GDB_SYM (type, id)
    61 # define DEFINE_GDB_SYMBOL_END(val) ;
    62 #endif
    63 
    64 /* The ubiquitous max and min macros.  */
    65 #undef min
    66 #undef max
    67 #define max(a, b) ((a) > (b) ? (a) : (b))
    68 #define min(a, b) ((a) < (b) ? (a) : (b))
    69 
    70 /* Number of elements in an array.  */
    71 #define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
    72 
    73 /* Number of bits in a Lisp_Object tag.  */
    74 DEFINE_GDB_SYMBOL_BEGIN (int, GCTYPEBITS)
    75 #define GCTYPEBITS 3
    76 DEFINE_GDB_SYMBOL_END (GCTYPEBITS)
    77 
    78 /* EMACS_INT - signed integer wide enough to hold an Emacs value
    79    EMACS_INT_WIDTH - width in bits of EMACS_INT
    80    EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
    81    pI - printf length modifier for EMACS_INT
    82    EMACS_UINT - unsigned variant of EMACS_INT */
    83 #ifndef EMACS_INT_MAX
    84 # if INTPTR_MAX <= 0
    85 #  error "INTPTR_MAX misconfigured"
    86 # elif INTPTR_MAX <= INT_MAX && !defined WIDE_EMACS_INT
    87 typedef int EMACS_INT;
    88 typedef unsigned int EMACS_UINT;
    89 enum { EMACS_INT_WIDTH = INT_WIDTH, EMACS_UINT_WIDTH = UINT_WIDTH };
    90 #  define EMACS_INT_MAX INT_MAX
    91 #  define pI ""
    92 # elif INTPTR_MAX <= LONG_MAX && !defined WIDE_EMACS_INT
    93 typedef long int EMACS_INT;
    94 typedef unsigned long EMACS_UINT;
    95 enum { EMACS_INT_WIDTH = LONG_WIDTH, EMACS_UINT_WIDTH = ULONG_WIDTH };
    96 #  define EMACS_INT_MAX LONG_MAX
    97 #  define pI "l"
    98 # elif INTPTR_MAX <= LLONG_MAX
    99 typedef long long int EMACS_INT;
   100 typedef unsigned long long int EMACS_UINT;
   101 enum { EMACS_INT_WIDTH = LLONG_WIDTH, EMACS_UINT_WIDTH = ULLONG_WIDTH };
   102 #  define EMACS_INT_MAX LLONG_MAX
   103 /* MinGW supports %lld only if __USE_MINGW_ANSI_STDIO is non-zero,
   104    which is arranged by config.h, and (for mingw.org) if GCC is 6.0 or
   105    later and the runtime version is 5.0.0 or later.  Otherwise,
   106    printf-like functions are declared with __ms_printf__ attribute,
   107    which will cause a warning for %lld etc.  */
   108 #  if defined __MINGW32__                                               \
   109   && (!defined __USE_MINGW_ANSI_STDIO                                   \
   110       || (!defined MINGW_W64                                            \
   111           && !(GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5)))
   112 #   define pI "I64"
   113 #  else  /* ! MinGW */
   114 #   define pI "ll"
   115 #  endif
   116 # else
   117 #  error "INTPTR_MAX too large"
   118 # endif
   119 #endif
   120 
   121 /* Number of bits to put in each character in the internal representation
   122    of bool vectors.  This should not vary across implementations.  */
   123 enum {  BOOL_VECTOR_BITS_PER_CHAR =
   124 #define BOOL_VECTOR_BITS_PER_CHAR 8
   125         BOOL_VECTOR_BITS_PER_CHAR
   126 };
   127 
   128 /* An unsigned integer type representing a fixed-length bit sequence,
   129    suitable for bool vector words, GC mark bits, etc.  Normally it is size_t
   130    for speed, but on weird platforms it is unsigned char and not all
   131    its bits are used.  */
   132 #if BOOL_VECTOR_BITS_PER_CHAR == CHAR_BIT
   133 typedef size_t bits_word;
   134 # define BITS_WORD_MAX SIZE_MAX
   135 enum { BITS_PER_BITS_WORD = SIZE_WIDTH };
   136 #else
   137 typedef unsigned char bits_word;
   138 # define BITS_WORD_MAX ((1u << BOOL_VECTOR_BITS_PER_CHAR) - 1)
   139 enum { BITS_PER_BITS_WORD = BOOL_VECTOR_BITS_PER_CHAR };
   140 #endif
   141 verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1);
   142 
   143 /* Use pD to format ptrdiff_t values, which suffice for indexes into
   144    buffers and strings.  Emacs never allocates objects larger than
   145    PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
   146    In C99, pD can always be "t", as we no longer need to worry about
   147    pre-C99 libraries such as glibc 2.0 (1997) and Solaris 8 (2000).  */
   148 #define pD "t"
   149 
   150 /* Convenience macro for rarely-used functions that do not return.  */
   151 #define AVOID _Noreturn ATTRIBUTE_COLD void
   152 
   153 /* Extra internal type checking?  */
   154 
   155 /* Define Emacs versions of <assert.h>'s 'assert (COND)' and <verify.h>'s
   156    'assume (COND)'.  COND should be free of side effects, as it may or
   157    may not be evaluated.
   158 
   159    'eassert (COND)' checks COND at runtime if ENABLE_CHECKING is
   160    defined and suppress_checking is false, and does nothing otherwise.
   161    Emacs dies if COND is checked and is false.  The suppress_checking
   162    variable is initialized to 0 in alloc.c.  Set it to 1 using a
   163    debugger to temporarily disable aborting on detected internal
   164    inconsistencies or error conditions.
   165 
   166    In some cases, a good compiler may be able to optimize away the
   167    eassert macro even if ENABLE_CHECKING is true, e.g., if XSTRING (x)
   168    uses eassert to test STRINGP (x), but a particular use of XSTRING
   169    is invoked only after testing that STRINGP (x) is true, making the
   170    test redundant.
   171 
   172    eassume is like eassert except that it also causes the compiler to
   173    assume that COND is true afterwards, regardless of whether runtime
   174    checking is enabled.  This can improve performance in some cases,
   175    though it can degrade performance in others.  It's often suboptimal
   176    for COND to call external functions or access volatile storage.  */
   177 
   178 #ifndef ENABLE_CHECKING
   179 # define eassert(cond) ((void) (false && (cond))) /* Check COND compiles.  */
   180 # define eassume(cond) assume (cond)
   181 #else /* ENABLE_CHECKING */
   182 
   183 extern AVOID die (const char *, const char *, int);
   184 
   185 extern bool suppress_checking EXTERNALLY_VISIBLE;
   186 
   187 # define eassert(cond)                                          \
   188    (suppress_checking || (cond)                                 \
   189     ? (void) 0                                                  \
   190     : die (# cond, __FILE__, __LINE__))
   191 # define eassume(cond)                                          \
   192    (suppress_checking                                           \
   193     ? assume (cond)                                             \
   194     : (cond)                                                    \
   195     ? (void) 0                                                  \
   196     : die (# cond, __FILE__, __LINE__))
   197 #endif /* ENABLE_CHECKING */
   198 
   199 
   200 /* Use the configure flag --enable-check-lisp-object-type to make
   201    Lisp_Object use a struct type instead of the default int.  The flag
   202    causes CHECK_LISP_OBJECT_TYPE to be defined.  */
   203 
   204 /***** Select the tagging scheme.  *****/
   205 /* The following option controls the tagging scheme:
   206    - USE_LSB_TAG means that we can assume the least 3 bits of pointers are
   207      always 0, and we can thus use them to hold tag bits, without
   208      restricting our addressing space.
   209 
   210    If ! USE_LSB_TAG, then use the top 3 bits for tagging, thus
   211    restricting our possible address range.
   212 
   213    USE_LSB_TAG not only requires the least 3 bits of pointers returned by
   214    malloc to be 0 but also needs to be able to impose a mult-of-8 alignment
   215    on some non-GC Lisp_Objects, all of which are aligned via
   216    GCALIGNED_UNION_MEMBER.  */
   217 
   218 enum Lisp_Bits
   219   {
   220     /* Number of bits in a Lisp_Object value, not counting the tag.  */
   221     VALBITS = EMACS_INT_WIDTH - GCTYPEBITS,
   222 
   223     /* Number of bits in a fixnum value, not counting the tag.  */
   224     FIXNUM_BITS = VALBITS + 1
   225   };
   226 
   227 /* Number of bits in a fixnum tag; can be used in #if.  */
   228 DEFINE_GDB_SYMBOL_BEGIN (int, INTTYPEBITS)
   229 #define INTTYPEBITS (GCTYPEBITS - 1)
   230 DEFINE_GDB_SYMBOL_END (INTTYPEBITS)
   231 
   232 /* The maximum value that can be stored in a EMACS_INT, assuming all
   233    bits other than the type bits contribute to a nonnegative signed value.
   234    This can be used in #if, e.g., '#if USE_LSB_TAG' below expands to an
   235    expression involving VAL_MAX.  */
   236 #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
   237 
   238 /* Whether the least-significant bits of an EMACS_INT contain the tag.
   239    On hosts where pointers-as-ints do not exceed VAL_MAX / 2, USE_LSB_TAG is:
   240     a. unnecessary, because the top bits of an EMACS_INT are unused, and
   241     b. slower, because it typically requires extra masking.
   242    So, USE_LSB_TAG is true only on hosts where it might be useful.  */
   243 DEFINE_GDB_SYMBOL_BEGIN (bool, USE_LSB_TAG)
   244 #define USE_LSB_TAG (VAL_MAX / 2 < INTPTR_MAX)
   245 DEFINE_GDB_SYMBOL_END (USE_LSB_TAG)
   246 
   247 /* Mask for the value (as opposed to the type bits) of a Lisp object.  */
   248 DEFINE_GDB_SYMBOL_BEGIN (EMACS_INT, VALMASK)
   249 # define VALMASK (USE_LSB_TAG ? - (1 << GCTYPEBITS) : VAL_MAX)
   250 DEFINE_GDB_SYMBOL_END (VALMASK)
   251 
   252 /* Ignore 'alignas' on compilers lacking it.  */
   253 #if (!defined alignas && !defined __alignas_is_defined \
   254      && __STDC_VERSION__ < 202311 && __cplusplus < 201103)
   255 # define alignas(a)
   256 #endif
   257 
   258 /* Minimum alignment requirement for Lisp objects, imposed by the
   259    internal representation of tagged pointers.  It is 2**GCTYPEBITS if
   260    USE_LSB_TAG, 1 otherwise.  It must be a literal integer constant,
   261    for older versions of GCC (through at least 4.9).  */
   262 #if USE_LSB_TAG
   263 # define GCALIGNMENT 8
   264 # if GCALIGNMENT != 1 << GCTYPEBITS
   265 #  error "GCALIGNMENT and GCTYPEBITS are inconsistent"
   266 # endif
   267 #else
   268 # define GCALIGNMENT 1
   269 #endif
   270 
   271 /* To cause a union to have alignment of at least GCALIGNMENT, put
   272    GCALIGNED_UNION_MEMBER in its member list.
   273 
   274    If a struct is always GC-aligned (either by the GC, or via
   275    allocation in a containing union that has GCALIGNED_UNION_MEMBER)
   276    and does not contain a GC-aligned struct or union, putting
   277    GCALIGNED_STRUCT after its closing '}' can help the compiler
   278    generate better code.  Also, such structs should be added to the
   279    emacs_align_type union in alloc.c.
   280 
   281    Although these macros are reasonably portable, they are not
   282    guaranteed on non-GCC platforms, as the C standard does not require support
   283    for alignment to GCALIGNMENT and older compilers may ignore
   284    alignment requests.  For any type T where garbage collection
   285    requires alignment, use verify (GCALIGNED (T)) to verify the
   286    requirement on the current platform.  Types need this check if
   287    their objects can be allocated outside the garbage collector.  For
   288    example, struct Lisp_Symbol needs the check because of lispsym and
   289    struct Lisp_Cons needs it because of STACK_CONS.  */
   290 
   291 #define GCALIGNED_UNION_MEMBER char alignas (GCALIGNMENT) gcaligned;
   292 #if HAVE_STRUCT_ATTRIBUTE_ALIGNED
   293 # define GCALIGNED_STRUCT __attribute__ ((aligned (GCALIGNMENT)))
   294 #else
   295 # define GCALIGNED_STRUCT
   296 #endif
   297 #define GCALIGNED(type) (alignof (type) % GCALIGNMENT == 0)
   298 
   299 /* Lisp_Word is a scalar word suitable for holding a tagged pointer or
   300    integer.  Usually it is a pointer to a deliberately-incomplete type
   301    'struct Lisp_X'.  However, it is EMACS_INT when Lisp_Objects and
   302    pointers differ in width.  */
   303 
   304 #define LISP_WORDS_ARE_POINTERS (EMACS_INT_MAX == INTPTR_MAX)
   305 #if LISP_WORDS_ARE_POINTERS
   306 typedef struct Lisp_X *Lisp_Word;
   307 #else
   308 typedef EMACS_INT Lisp_Word;
   309 #endif
   310 
   311 /* Some operations are so commonly executed that they are implemented
   312    as macros, not functions, because otherwise runtime performance would
   313    suffer too much when compiling with GCC without optimization.
   314    There's no need to inline everything, just the operations that
   315    would otherwise cause a serious performance problem.
   316 
   317    For each such operation OP, define a macro lisp_h_OP that contains
   318    the operation's implementation.  That way, OP can be implemented
   319    via a macro definition like this:
   320 
   321      #define OP(x) lisp_h_OP (x)
   322 
   323    and/or via a function definition like this:
   324 
   325      Lisp_Object (OP) (Lisp_Object x) { return lisp_h_OP (x); }
   326 
   327    without worrying about the implementations diverging, since
   328    lisp_h_OP defines the actual implementation.  The lisp_h_OP macros
   329    are intended to be private to this include file, and should not be
   330    used elsewhere.
   331 
   332    FIXME: Remove the lisp_h_OP macros, and define just the inline OP
   333    functions, once "gcc -Og" (new to GCC 4.8) or equivalent works well
   334    enough for Emacs developers.  Maybe in the year 2025.  See Bug#11935.
   335 
   336    For the macros that have corresponding functions (defined later),
   337    see these functions for commentary.  */
   338 
   339 /* Convert among the various Lisp-related types: I for EMACS_INT, L
   340    for Lisp_Object, P for void *.
   341 
   342    These use the following mnemonics:
   343 
   344    XLI: Lisp_Object to Integer;
   345    XIL: Integer to Lisp_Object;
   346    XLP: Lisp_Object to Pointer.  */
   347 
   348 #if !CHECK_LISP_OBJECT_TYPE
   349 # if LISP_WORDS_ARE_POINTERS
   350 #  define lisp_h_XLI(o) ((EMACS_INT) (o))
   351 #  define lisp_h_XIL(i) ((Lisp_Object) (i))
   352 #  define lisp_h_XLP(o) ((void *) (o))
   353 # else
   354 #  define lisp_h_XLI(o) (o)
   355 #  define lisp_h_XIL(i) (i)
   356 #  define lisp_h_XLP(o) ((void *) (uintptr_t) (o))
   357 # endif
   358 # define lisp_h_Qnil 0
   359 #else
   360 # if LISP_WORDS_ARE_POINTERS
   361 #  define lisp_h_XLI(o) ((EMACS_INT) (o).i)
   362 #  define lisp_h_XIL(i) ((Lisp_Object) {(Lisp_Word) (i)})
   363 #  define lisp_h_XLP(o) ((void *) (o).i)
   364 # else
   365 #  define lisp_h_XLI(o) ((o).i)
   366 #  define lisp_h_XIL(i) ((Lisp_Object) {i})
   367 #  define lisp_h_XLP(o) ((void *) (uintptr_t) (o).i)
   368 # endif
   369 # define lisp_h_Qnil {0}
   370 #endif
   371 
   372 #define lisp_h_PSEUDOVECTORP(a,code)                            \
   373   (lisp_h_VECTORLIKEP((a)) &&                                   \
   374    ((XUNTAG ((a), Lisp_Vectorlike, union vectorlike_header)->size     \
   375      & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))                    \
   376     == (PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS))))
   377 
   378 #define lisp_h_CHECK_FIXNUM(x) CHECK_TYPE (FIXNUMP (x), Qfixnump, x)
   379 #define lisp_h_CHECK_SYMBOL(x) CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
   380 #define lisp_h_CHECK_TYPE(ok, predicate, x) \
   381    ((ok) ? (void) 0 : wrong_type_argument (predicate, x))
   382 #define lisp_h_CONSP(x) TAGGEDP (x, Lisp_Cons)
   383 #define lisp_h_BASE_EQ(x, y) (XLI (x) == XLI (y))
   384 #define lisp_h_BASE2_EQ(x, y)                               \
   385   (BASE_EQ (x, y)                                           \
   386    || (symbols_with_pos_enabled                             \
   387        && SYMBOL_WITH_POS_P (x)                             \
   388        && BASE_EQ (XSYMBOL_WITH_POS (x)->sym, y)))
   389 
   390 /* FIXME: Do we really need to inline the whole thing?
   391  * What about keeping the part after `symbols_with_pos_enabled` in
   392  * a separate function?  */
   393 #define lisp_h_EQ(x, y)                                     \
   394   ((XLI ((x)) == XLI ((y)))                                 \
   395    || (symbols_with_pos_enabled                             \
   396        && (SYMBOL_WITH_POS_P ((x))                          \
   397            ? (BARE_SYMBOL_P ((y))                           \
   398               ? XLI (XSYMBOL_WITH_POS((x))->sym) == XLI (y) \
   399               : SYMBOL_WITH_POS_P((y))                      \
   400                 && (XLI (XSYMBOL_WITH_POS((x))->sym)        \
   401                     == XLI (XSYMBOL_WITH_POS((y))->sym)))   \
   402            : (SYMBOL_WITH_POS_P ((y))                       \
   403               && BARE_SYMBOL_P ((x))                        \
   404               && (XLI (x) == XLI ((XSYMBOL_WITH_POS ((y)))->sym))))))
   405 
   406 #define lisp_h_FIXNUMP(x) \
   407    (! (((unsigned) (XLI (x) >> (USE_LSB_TAG ? 0 : FIXNUM_BITS)) \
   408         - (unsigned) (Lisp_Int0 >> !USE_LSB_TAG)) \
   409        & ((1 << INTTYPEBITS) - 1)))
   410 #define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float)
   411 #define lisp_h_NILP(x)  BASE_EQ (x, Qnil)
   412 #define lisp_h_SET_SYMBOL_VAL(sym, v) \
   413    (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \
   414     (sym)->u.s.val.value = (v))
   415 #define lisp_h_SYMBOL_CONSTANT_P(sym) \
   416    (XSYMBOL (sym)->u.s.trapped_write == SYMBOL_NOWRITE)
   417 #define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->u.s.trapped_write)
   418 #define lisp_h_SYMBOL_VAL(sym) \
   419    (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), (sym)->u.s.val.value)
   420 #define lisp_h_SYMBOL_WITH_POS_P(x) PSEUDOVECTORP ((x), PVEC_SYMBOL_WITH_POS)
   421 #define lisp_h_BARE_SYMBOL_P(x) TAGGEDP ((x), Lisp_Symbol)
   422 #define lisp_h_SYMBOLP(x) ((BARE_SYMBOL_P ((x)) ||               \
   423                             (symbols_with_pos_enabled && (SYMBOL_WITH_POS_P ((x))))))
   424 #define lisp_h_TAGGEDP(a, tag) \
   425    (! (((unsigned) (XLI (a) >> (USE_LSB_TAG ? 0 : VALBITS)) \
   426         - (unsigned) (tag)) \
   427        & ((1 << GCTYPEBITS) - 1)))
   428 #define lisp_h_VECTORLIKEP(x) TAGGEDP (x, Lisp_Vectorlike)
   429 #define lisp_h_XCAR(c) XCONS (c)->u.s.car
   430 #define lisp_h_XCDR(c) XCONS (c)->u.s.u.cdr
   431 #define lisp_h_XCONS(a) \
   432    (eassert (CONSP (a)), XUNTAG (a, Lisp_Cons, struct Lisp_Cons))
   433 #define lisp_h_XHASH(a) XUFIXNUM_RAW (a)
   434 #if USE_LSB_TAG
   435 # define lisp_h_make_fixnum_wrap(n) \
   436     XIL ((EMACS_INT) (((EMACS_UINT) (n) << INTTYPEBITS) + Lisp_Int0))
   437 # if defined HAVE_STATEMENT_EXPRESSIONS && defined HAVE_TYPEOF
   438 #  define lisp_h_make_fixnum(n) \
   439      ({ typeof (+(n)) lisp_h_make_fixnum_n = n; \
   440         eassert (!FIXNUM_OVERFLOW_P (lisp_h_make_fixnum_n)); \
   441         lisp_h_make_fixnum_wrap (lisp_h_make_fixnum_n); })
   442 # else
   443 #  define lisp_h_make_fixnum(n) lisp_h_make_fixnum_wrap (n)
   444 # endif
   445 # define lisp_h_XFIXNUM_RAW(a) (XLI (a) >> INTTYPEBITS)
   446 # define lisp_h_XTYPE(a) ((enum Lisp_Type) (XLI (a) & ~VALMASK))
   447 #endif
   448 
   449 /* When DEFINE_KEY_OPS_AS_MACROS, define key operations as macros to
   450    cajole the compiler into inlining them; otherwise define them as
   451    inline functions as this is cleaner and can be more efficient.
   452    The default is true if the compiler is GCC-like and if function
   453    inlining is disabled because the compiler is not optimizing or is
   454    optimizing for size.  Otherwise the default is false.  */
   455 #ifndef DEFINE_KEY_OPS_AS_MACROS
   456 # if (defined __NO_INLINE__ \
   457       && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__)
   458 #  define DEFINE_KEY_OPS_AS_MACROS true
   459 # else
   460 #  define DEFINE_KEY_OPS_AS_MACROS false
   461 # endif
   462 #endif
   463 
   464 #if DEFINE_KEY_OPS_AS_MACROS
   465 # define XLI(o) lisp_h_XLI (o)
   466 # define XIL(i) lisp_h_XIL (i)
   467 # define XLP(o) lisp_h_XLP (o)
   468 # define BARE_SYMBOL_P(x) lisp_h_BARE_SYMBOL_P (x)
   469 # define CHECK_FIXNUM(x) lisp_h_CHECK_FIXNUM (x)
   470 # define CHECK_SYMBOL(x) lisp_h_CHECK_SYMBOL (x)
   471 # define CHECK_TYPE(ok, predicate, x) lisp_h_CHECK_TYPE (ok, predicate, x)
   472 # define CONSP(x) lisp_h_CONSP (x)
   473 # define BASE_EQ(x, y) lisp_h_BASE_EQ (x, y)
   474 # define BASE2_EQ(x, y) lisp_h_BASE2_EQ (x, y)
   475 # define FLOATP(x) lisp_h_FLOATP (x)
   476 # define FIXNUMP(x) lisp_h_FIXNUMP (x)
   477 # define NILP(x) lisp_h_NILP (x)
   478 # define SET_SYMBOL_VAL(sym, v) lisp_h_SET_SYMBOL_VAL (sym, v)
   479 # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym)
   480 # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym)
   481 # define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym)
   482 /* # define SYMBOLP(x) lisp_h_SYMBOLP (x) */ /* X is accessed more than once. */
   483 # define TAGGEDP(a, tag) lisp_h_TAGGEDP (a, tag)
   484 # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x)
   485 # define XCAR(c) lisp_h_XCAR (c)
   486 # define XCDR(c) lisp_h_XCDR (c)
   487 # define XCONS(a) lisp_h_XCONS (a)
   488 # define XHASH(a) lisp_h_XHASH (a)
   489 # if USE_LSB_TAG
   490 #  define make_fixnum(n) lisp_h_make_fixnum (n)
   491 #  define XFIXNUM_RAW(a) lisp_h_XFIXNUM_RAW (a)
   492 #  define XTYPE(a) lisp_h_XTYPE (a)
   493 # endif
   494 #endif
   495 
   496 
   497 /* Define the fundamental Lisp data structures.  */
   498 
   499 /* This is the set of Lisp data types.  If you want to define a new
   500    data type, read the comments after Lisp_Fwd_Type definition
   501    below.  */
   502 
   503 /* Fixnums use 2 tags, to give them one extra bit, thus
   504    extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1.  */
   505 #define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
   506 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
   507 
   508 /* Idea stolen from GDB.  Pedantic GCC complains about enum bitfields,
   509    and xlc and Oracle Studio c99 complain vociferously about them.  */
   510 #if (defined __STRICT_ANSI__ || defined __IBMC__ \
   511      || (defined __SUNPRO_C && __STDC__))
   512 #define ENUM_BF(TYPE) unsigned int
   513 #else
   514 #define ENUM_BF(TYPE) enum TYPE
   515 #endif
   516 
   517 
   518 enum Lisp_Type
   519   {
   520     /* Symbol.  XSYMBOL (object) points to a struct Lisp_Symbol.  */
   521     Lisp_Symbol = 0,
   522 
   523     /* Type 1 is currently unused.  */
   524     Lisp_Type_Unused0 = 1,
   525 
   526     /* Fixnum.  XFIXNUM (obj) is the integer value.  */
   527     Lisp_Int0 = 2,
   528     Lisp_Int1 = USE_LSB_TAG ? 6 : 3,
   529 
   530     /* String.  XSTRING (object) points to a struct Lisp_String.
   531        The length of the string, and its contents, are stored therein.  */
   532     Lisp_String = 4,
   533 
   534     /* Vector of Lisp objects, or something resembling it.
   535        XVECTOR (object) points to a struct Lisp_Vector, which contains
   536        the size and contents.  The size field also contains the type
   537        information, if it's not a real vector object.  */
   538     Lisp_Vectorlike = 5,
   539 
   540     /* Cons.  XCONS (object) points to a struct Lisp_Cons.  */
   541     Lisp_Cons = USE_LSB_TAG ? 3 : 6,
   542 
   543     /* Must be last entry in Lisp_Type enumeration.  */
   544     Lisp_Float = 7
   545   };
   546 
   547 /* These are the types of forwarding objects used in the value slot
   548    of symbols for special built-in variables whose value is stored in
   549    C variables.  */
   550 enum Lisp_Fwd_Type
   551   {
   552     Lisp_Fwd_Int,               /* Fwd to a C `int' variable.  */
   553     Lisp_Fwd_Bool,              /* Fwd to a C boolean var.  */
   554     Lisp_Fwd_Obj,               /* Fwd to a C Lisp_Object variable.  */
   555     Lisp_Fwd_Buffer_Obj,        /* Fwd to a Lisp_Object field of buffers.  */
   556     Lisp_Fwd_Kboard_Obj         /* Fwd to a Lisp_Object field of kboards.  */
   557   };
   558 
   559 /* If you want to define a new Lisp data type, here are some
   560    instructions.
   561 
   562    First, there are already a couple of Lisp types that can be used if
   563    your new type does not need to be exposed to Lisp programs nor
   564    displayed to users.  These are Lisp_Misc_Ptr and PVEC_OTHER,
   565    which are both vectorlike objects.  The former
   566    is suitable for stashing a pointer in a Lisp object; the pointer
   567    might be to some low-level C object that contains auxiliary
   568    information.  The latter is useful for vector-like Lisp objects
   569    that need to be used as part of other objects, but which are never
   570    shown to users or Lisp code (search for PVEC_OTHER in xterm.c for
   571    an example).
   572 
   573    These two types don't look pretty when printed, so they are
   574    unsuitable for Lisp objects that can be exposed to users.
   575 
   576    To define a new data type, add a pseudovector subtype by extending
   577    the pvec_type enumeration.  A pseudovector provides one or more
   578    slots for Lisp objects, followed by struct members that are
   579    accessible only from C.
   580 
   581    There is no way to explicitly free a Lisp Object; only the garbage
   582    collector frees them.
   583 
   584    For a new pseudovector, it's highly desirable to limit the size
   585    of your data type by VBLOCK_BYTES_MAX bytes (defined in alloc.c).
   586    Otherwise you will need to change sweep_vectors (also in alloc.c).
   587 
   588    Then you will need to add switch branches in print.c (in
   589    print_object, to print your object, and possibly also in
   590    print_preprocess) and to alloc.c, to mark your object (in
   591    mark_object) and to free it (in gc_sweep).  The latter is also the
   592    right place to call any code specific to your data type that needs
   593    to run when the object is recycled -- e.g., free any additional
   594    resources allocated for it that are not Lisp objects.  You can even
   595    make a pointer to the function that frees the resources a slot in
   596    your object -- this way, the same object could be used to represent
   597    several disparate C structures.
   598 
   599    In addition, you need to add switch branches in data.c for Ftype_of.
   600 
   601    You also need to add the new type to the constant
   602    `cl--typeof-types' in lisp/emacs-lisp/cl-preloaded.el.  */
   603 
   604 
   605 /* A Lisp_Object is a tagged pointer or integer.  Ordinarily it is a
   606    Lisp_Word.  However, if CHECK_LISP_OBJECT_TYPE, it is a wrapper
   607    around Lisp_Word, to help catch thinkos like 'Lisp_Object x = 0;'.
   608 
   609    LISP_INITIALLY (W) initializes a Lisp object with a tagged value
   610    that is a Lisp_Word W.  It can be used in a static initializer.  */
   611 
   612 #ifdef CHECK_LISP_OBJECT_TYPE
   613 typedef struct Lisp_Object { Lisp_Word i; } Lisp_Object;
   614 # define LISP_OBJECT_IS_STRUCT
   615 # define LISP_INITIALLY(w) {w}
   616 # undef CHECK_LISP_OBJECT_TYPE
   617 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = true };
   618 #else
   619 typedef Lisp_Word Lisp_Object;
   620 # define LISP_INITIALLY(w) (w)
   621 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = false };
   622 #endif
   623 
   624 /* Forward declarations.  */
   625 
   626 /* Defined in this file.  */
   627 INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
   628                                               Lisp_Object);
   629 
   630 /* Defined in bignum.c.  */
   631 extern int check_int_nonnegative (Lisp_Object);
   632 extern intmax_t check_integer_range (Lisp_Object, intmax_t, intmax_t);
   633 extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST;
   634 extern Lisp_Object make_bigint (intmax_t);
   635 extern Lisp_Object make_biguint (uintmax_t);
   636 extern uintmax_t check_uinteger_max (Lisp_Object, uintmax_t);
   637 
   638 /* Defined in chartab.c.  */
   639 extern Lisp_Object char_table_ref (Lisp_Object, int) ATTRIBUTE_PURE;
   640 extern void char_table_set (Lisp_Object, int, Lisp_Object);
   641 
   642 /* Defined in data.c.  */
   643 extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object);
   644 extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object);
   645 extern Lisp_Object default_value (Lisp_Object symbol);
   646 extern void defalias (Lisp_Object symbol, Lisp_Object definition);
   647 extern char *fixnum_to_string (EMACS_INT number, char *buffer, char *end);
   648 
   649 
   650 /* Defined in emacs.c.  */
   651 
   652 /* Set after Emacs has started up the first time.
   653    Prevents reinitialization of the Lisp world and keymaps on
   654    subsequent starts.  */
   655 extern bool initialized;
   656 
   657 extern struct gflags
   658 {
   659   /* True means this Emacs instance was born to dump.  */
   660   bool will_dump_ : 1;
   661   bool will_bootstrap_ : 1;
   662 #ifdef HAVE_PDUMPER
   663   /* Set in an Emacs process that will likely dump with pdumper; all
   664      Emacs processes may dump with pdumper, however.  */
   665   bool will_dump_with_pdumper_ : 1;
   666   /* Set in an Emacs process that has been restored from a portable
   667      dump.  */
   668   bool dumped_with_pdumper_ : 1;
   669 #endif
   670 #ifdef HAVE_UNEXEC
   671   bool will_dump_with_unexec_ : 1;
   672   /* Set in an Emacs process that has been restored from an unexec
   673      dump.  */
   674   bool dumped_with_unexec_ : 1;
   675   /* We promise not to unexec: useful for hybrid malloc.  */
   676   bool will_not_unexec_ : 1;
   677 #endif
   678 } gflags;
   679 
   680 INLINE bool
   681 will_dump_p (void)
   682 {
   683 #if HAVE_PDUMPER || defined HAVE_UNEXEC
   684   return gflags.will_dump_;
   685 #else
   686   return false;
   687 #endif
   688 }
   689 
   690 INLINE bool
   691 will_bootstrap_p (void)
   692 {
   693 #if HAVE_PDUMPER || defined HAVE_UNEXEC
   694   return gflags.will_bootstrap_;
   695 #else
   696   return false;
   697 #endif
   698 }
   699 
   700 INLINE bool
   701 will_dump_with_pdumper_p (void)
   702 {
   703 #if HAVE_PDUMPER
   704   return gflags.will_dump_with_pdumper_;
   705 #else
   706   return false;
   707 #endif
   708 }
   709 
   710 INLINE bool
   711 dumped_with_pdumper_p (void)
   712 {
   713 #if HAVE_PDUMPER
   714   return gflags.dumped_with_pdumper_;
   715 #else
   716   return false;
   717 #endif
   718 }
   719 
   720 INLINE bool
   721 will_dump_with_unexec_p (void)
   722 {
   723 #ifdef HAVE_UNEXEC
   724   return gflags.will_dump_with_unexec_;
   725 #else
   726   return false;
   727 #endif
   728 }
   729 
   730 INLINE bool
   731 dumped_with_unexec_p (void)
   732 {
   733 #ifdef HAVE_UNEXEC
   734   return gflags.dumped_with_unexec_;
   735 #else
   736   return false;
   737 #endif
   738 }
   739 
   740 /* This function is the opposite of will_dump_with_unexec_p(), except
   741    that it returns false before main runs.  It's important to use
   742    gmalloc for any pre-main allocations if we're going to unexec.  */
   743 INLINE bool
   744 definitely_will_not_unexec_p (void)
   745 {
   746 #ifdef HAVE_UNEXEC
   747   return gflags.will_not_unexec_;
   748 #else
   749   return true;
   750 #endif
   751 }
   752 
   753 /* Defined in floatfns.c.  */
   754 extern double extract_float (Lisp_Object);
   755 
   756 
   757 /* Low-level conversion and type checking.  */
   758 
   759 /* Convert among various types use to implement Lisp_Object.  At the
   760    machine level, these operations may widen or narrow their arguments
   761    if pointers differ in width from EMACS_INT; otherwise they are
   762    no-ops.  */
   763 
   764 INLINE EMACS_INT
   765 (XLI) (Lisp_Object o)
   766 {
   767   return lisp_h_XLI (o);
   768 }
   769 
   770 INLINE Lisp_Object
   771 (XIL) (EMACS_INT i)
   772 {
   773   return lisp_h_XIL (i);
   774 }
   775 
   776 INLINE void *
   777 (XLP) (Lisp_Object o)
   778 {
   779   return lisp_h_XLP (o);
   780 }
   781 
   782 /* Extract A's type.  */
   783 
   784 INLINE enum Lisp_Type
   785 (XTYPE) (Lisp_Object a)
   786 {
   787 #if USE_LSB_TAG
   788   return lisp_h_XTYPE (a);
   789 #else
   790   EMACS_UINT i = XLI (a);
   791   return USE_LSB_TAG ? i & ~VALMASK : i >> VALBITS;
   792 #endif
   793 }
   794 
   795 /* True if A has type tag TAG.
   796    Equivalent to XTYPE (a) == TAG, but often faster.  */
   797 
   798 INLINE bool
   799 (TAGGEDP) (Lisp_Object a, enum Lisp_Type tag)
   800 {
   801   return lisp_h_TAGGEDP (a, tag);
   802 }
   803 
   804 INLINE void
   805 (CHECK_TYPE) (int ok, Lisp_Object predicate, Lisp_Object x)
   806 {
   807   lisp_h_CHECK_TYPE (ok, predicate, x);
   808 }
   809 
   810 /* Extract A's pointer value, assuming A's Lisp type is TYPE and the
   811    extracted pointer's type is CTYPE *.  */
   812 
   813 #define XUNTAG(a, type, ctype) ((ctype *) \
   814                                 ((char *) XLP (a) - LISP_WORD_TAG (type)))
   815 
   816 /* A forwarding pointer to a value.  It uses a generic pointer to
   817    avoid alignment bugs that could occur if it used a pointer to a
   818    union of the possible values (struct Lisp_Objfwd, struct
   819    Lisp_Intfwd, etc.).  The pointer is packaged inside a struct to
   820    help static checking.  */
   821 typedef struct { void const *fwdptr; } lispfwd;
   822 
   823 /* Interned state of a symbol.  */
   824 
   825 enum symbol_interned
   826 {
   827   SYMBOL_UNINTERNED,                  /* not interned anywhere */
   828   SYMBOL_INTERNED,                    /* interned but not in initial obarray */
   829   SYMBOL_INTERNED_IN_INITIAL_OBARRAY  /* interned in initial obarray */
   830 };
   831 
   832 enum symbol_redirect
   833 {
   834   SYMBOL_PLAINVAL,   /* plain var, value is in the `value' field */
   835   SYMBOL_VARALIAS,   /* var alias, value is really in the `alias' symbol */
   836   SYMBOL_LOCALIZED,  /* localized var, value is in the `blv' object */
   837   SYMBOL_FORWARDED   /* forwarding var, value is in `forward' */
   838 };
   839 
   840 enum symbol_trapped_write
   841 {
   842   SYMBOL_UNTRAPPED_WRITE,  /* normal case, just set the value */
   843   SYMBOL_NOWRITE,          /* constant, cannot set, e.g. nil, t, :keyword */
   844   SYMBOL_TRAPPED_WRITE     /* trap the write, call watcher functions */
   845 };
   846 
   847 struct Lisp_Symbol
   848 {
   849   union
   850   {
   851     struct
   852     {
   853       bool_bf gcmarkbit : 1;
   854 
   855       /* Indicates where the value can be found.  */
   856       ENUM_BF (symbol_redirect) redirect : 2;
   857 
   858       ENUM_BF (symbol_trapped_write) trapped_write : 2;
   859 
   860       /* Interned state of the symbol.  */
   861       ENUM_BF (symbol_interned) interned : 2;
   862 
   863       /* True means that this variable has been explicitly declared
   864          special (with `defvar' etc), and shouldn't be lexically bound.  */
   865       bool_bf declared_special : 1;
   866 
   867       /* True if pointed to from purespace and hence can't be GC'd.  */
   868       bool_bf pinned : 1;
   869 
   870       /* The symbol's name, as a Lisp string.  */
   871       Lisp_Object name;
   872 
   873       /* Value of the symbol or Qunbound if unbound.  Which alternative of the
   874          union is used depends on the `redirect' field above.  */
   875       union {
   876         Lisp_Object value;
   877         struct Lisp_Symbol *alias;
   878         struct Lisp_Buffer_Local_Value *blv;
   879         lispfwd fwd;
   880       } val;
   881 
   882       /* Function value of the symbol or Qnil if not fboundp.  */
   883       Lisp_Object function;
   884 
   885       /* The symbol's property list.  */
   886       Lisp_Object plist;
   887 
   888       /* Next symbol in obarray bucket, if the symbol is interned.  */
   889       struct Lisp_Symbol *next;
   890     } s;
   891     GCALIGNED_UNION_MEMBER
   892   } u;
   893 };
   894 verify (GCALIGNED (struct Lisp_Symbol));
   895 
   896 /* Declare a Lisp-callable function.  The MAXARGS parameter has the same
   897    meaning as in the DEFUN macro, and is used to construct a prototype.  */
   898 /* We can use the same trick as in the DEFUN macro to generate the
   899    appropriate prototype.  */
   900 #define EXFUN(fnname, maxargs) \
   901   extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
   902 
   903 /* Note that the weird token-substitution semantics of ANSI C makes
   904    this work for MANY and UNEVALLED.  */
   905 #define DEFUN_ARGS_MANY         (ptrdiff_t, Lisp_Object *)
   906 #define DEFUN_ARGS_UNEVALLED    (Lisp_Object)
   907 #define DEFUN_ARGS_0    (void)
   908 #define DEFUN_ARGS_1    (Lisp_Object)
   909 #define DEFUN_ARGS_2    (Lisp_Object, Lisp_Object)
   910 #define DEFUN_ARGS_3    (Lisp_Object, Lisp_Object, Lisp_Object)
   911 #define DEFUN_ARGS_4    (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
   912 #define DEFUN_ARGS_5    (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
   913                          Lisp_Object)
   914 #define DEFUN_ARGS_6    (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
   915                          Lisp_Object, Lisp_Object)
   916 #define DEFUN_ARGS_7    (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
   917                          Lisp_Object, Lisp_Object, Lisp_Object)
   918 #define DEFUN_ARGS_8    (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
   919                          Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
   920 
   921 /* untagged_ptr represents a pointer before tagging, and Lisp_Word_tag
   922    contains a possibly-shifted tag to be added to an untagged_ptr to
   923    convert it to a Lisp_Word.  */
   924 #if LISP_WORDS_ARE_POINTERS
   925 /* untagged_ptr is a pointer so that the compiler knows that TAG_PTR
   926    yields a pointer.  It is char * so that adding a tag uses simple
   927    machine addition.  */
   928 typedef char *untagged_ptr;
   929 typedef uintptr_t Lisp_Word_tag;
   930 #else
   931 /* untagged_ptr is an unsigned integer instead of a pointer, so that
   932    it can be added to the possibly-wider Lisp_Word_tag type without
   933    losing information.  */
   934 typedef uintptr_t untagged_ptr;
   935 typedef EMACS_UINT Lisp_Word_tag;
   936 #endif
   937 
   938 /* A integer value tagged with TAG, and otherwise all zero.  */
   939 #define LISP_WORD_TAG(tag) \
   940   ((Lisp_Word_tag) (tag) << (USE_LSB_TAG ? 0 : VALBITS))
   941 
   942 /* An initializer for a Lisp_Object that contains TAG along with PTR.  */
   943 #define TAG_PTR(tag, ptr) \
   944   LISP_INITIALLY ((Lisp_Word) ((untagged_ptr) (ptr) + LISP_WORD_TAG (tag)))
   945 
   946 /* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is
   947    designed for use as an initializer, even for a constant initializer.  */
   948 #define LISPSYM_INITIALLY(name) \
   949   TAG_PTR (Lisp_Symbol, (char *) (intptr_t) ((i##name) * sizeof *lispsym))
   950 
   951 /* Declare extern constants for Lisp symbols.  These can be helpful
   952    when using a debugger like GDB, on older platforms where the debug
   953    format does not represent C macros.  However, they are unbounded
   954    and would just be asking for trouble if checking pointer bounds.  */
   955 #define DEFINE_LISP_SYMBOL(name) \
   956   DEFINE_GDB_SYMBOL_BEGIN (Lisp_Object, name) \
   957   DEFINE_GDB_SYMBOL_END (LISPSYM_INITIALLY (name))
   958 
   959 /* The index of the C-defined Lisp symbol SYM.
   960    This can be used in a static initializer.  */
   961 #define SYMBOL_INDEX(sym) i##sym
   962 
   963 /* By default, define macros for Qt, etc., as this leads to a bit
   964    better performance in the core Emacs interpreter.  A plugin can
   965    define DEFINE_NON_NIL_Q_SYMBOL_MACROS to be false, to be portable to
   966    other Emacs instances that assign different values to Qt, etc.  */
   967 #ifndef DEFINE_NON_NIL_Q_SYMBOL_MACROS
   968 # define DEFINE_NON_NIL_Q_SYMBOL_MACROS true
   969 #endif
   970 
   971 /* True if N is a power of 2.  N should be positive.  */
   972 
   973 #define POWER_OF_2(n) (((n) & ((n) - 1)) == 0)
   974 
   975 /* Return X rounded to the next multiple of Y.  Y should be positive,
   976    and Y - 1 + X should not overflow.  Arguments should not have side
   977    effects, as they are evaluated more than once.  Tune for Y being a
   978    power of 2.  */
   979 
   980 #define ROUNDUP(x, y) (POWER_OF_2 (y)                                   \
   981                        ? ((y) - 1 + (x)) & ~ ((y) - 1)                  \
   982                        : ((y) - 1 + (x)) - ((y) - 1 + (x)) % (y))
   983 
   984 #include <globals.h>
   985 
   986 /* Header of vector-like objects.  This documents the layout constraints on
   987    vectors and pseudovectors (objects of PVEC_xxx subtype).  It also prevents
   988    compilers from being fooled by Emacs's type punning: XSETPSEUDOVECTOR
   989    and PSEUDOVECTORP cast their pointers to union vectorlike_header *,
   990    because when two such pointers potentially alias, a compiler won't
   991    incorrectly reorder loads and stores to their size fields.  See
   992    Bug#8546.  This union formerly contained more members, and there's
   993    no compelling reason to change it to a struct merely because the
   994    number of members has been reduced to one.  */
   995 union vectorlike_header
   996   {
   997     /* The main member contains various pieces of information:
   998        - The MSB (ARRAY_MARK_FLAG) holds the gcmarkbit.
   999        - The next bit (PSEUDOVECTOR_FLAG) indicates whether this is a plain
  1000          vector (0) or a pseudovector (1).
  1001        - If PSEUDOVECTOR_FLAG is 0, the rest holds the size (number
  1002          of slots) of the vector.
  1003        - If PSEUDOVECTOR_FLAG is 1, the rest is subdivided into three fields:
  1004          - a) pseudovector subtype held in PVEC_TYPE_MASK field;
  1005          - b) number of Lisp_Objects slots at the beginning of the object
  1006            held in PSEUDOVECTOR_SIZE_MASK field.  These objects are always
  1007            traced by the GC;
  1008          - c) size of the rest fields held in PSEUDOVECTOR_REST_MASK and
  1009            measured in word_size units.  Rest fields may also include
  1010            Lisp_Objects, but these objects usually needs some special treatment
  1011            during GC.
  1012          There are some exceptions.  For PVEC_FREE, b) is always zero.  For
  1013          PVEC_BOOL_VECTOR and PVEC_SUBR, both b) and c) are always zero.
  1014          Current layout limits the pseudovectors to 63 PVEC_xxx subtypes,
  1015          4095 Lisp_Objects in GC-ed area and 4095 word-sized other slots.  */
  1016     ptrdiff_t size;
  1017   };
  1018 
  1019 struct Lisp_Symbol_With_Pos
  1020 {
  1021   union vectorlike_header header;
  1022   Lisp_Object sym;              /* A symbol */
  1023   Lisp_Object pos;              /* A fixnum */
  1024 } GCALIGNED_STRUCT;
  1025 
  1026 /* In the size word of a vector, this bit means the vector has been marked.  */
  1027 
  1028 DEFINE_GDB_SYMBOL_BEGIN (ptrdiff_t, ARRAY_MARK_FLAG)
  1029 # define ARRAY_MARK_FLAG PTRDIFF_MIN
  1030 DEFINE_GDB_SYMBOL_END (ARRAY_MARK_FLAG)
  1031 
  1032 /* In the size word of a struct Lisp_Vector, this bit means it's really
  1033    some other vector-like object.  */
  1034 DEFINE_GDB_SYMBOL_BEGIN (ptrdiff_t, PSEUDOVECTOR_FLAG)
  1035 # define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
  1036 DEFINE_GDB_SYMBOL_END (PSEUDOVECTOR_FLAG)
  1037 
  1038 /* In a pseudovector, the size field actually contains a word with one
  1039    PSEUDOVECTOR_FLAG bit set, and one of the following values extracted
  1040    with PVEC_TYPE_MASK to indicate the actual type.  */
  1041 enum pvec_type
  1042 {
  1043   PVEC_NORMAL_VECTOR,   /* Should be first, for sxhash_obj.  */
  1044   PVEC_FREE,
  1045   PVEC_BIGNUM,
  1046   PVEC_MARKER,
  1047   PVEC_OVERLAY,
  1048   PVEC_FINALIZER,
  1049   PVEC_SYMBOL_WITH_POS,
  1050   PVEC_MISC_PTR,
  1051   PVEC_USER_PTR,
  1052   PVEC_PROCESS,
  1053   PVEC_FRAME,
  1054   PVEC_WINDOW,
  1055   PVEC_BOOL_VECTOR,
  1056   PVEC_BUFFER,
  1057   PVEC_HASH_TABLE,
  1058   PVEC_TERMINAL,
  1059   PVEC_WINDOW_CONFIGURATION,
  1060   PVEC_SUBR,
  1061   PVEC_OTHER,            /* Should never be visible to Elisp code.  */
  1062   PVEC_XWIDGET,
  1063   PVEC_XWIDGET_VIEW,
  1064   PVEC_THREAD,
  1065   PVEC_MUTEX,
  1066   PVEC_CONDVAR,
  1067   PVEC_MODULE_FUNCTION,
  1068   PVEC_NATIVE_COMP_UNIT,
  1069   PVEC_TS_PARSER,
  1070   PVEC_TS_NODE,
  1071   PVEC_TS_COMPILED_QUERY,
  1072   PVEC_SQLITE,
  1073 
  1074   /* These should be last, for internal_equal and sxhash_obj.  */
  1075   PVEC_COMPILED,
  1076   PVEC_CHAR_TABLE,
  1077   PVEC_SUB_CHAR_TABLE,
  1078   PVEC_RECORD,
  1079   PVEC_FONT /* Should be last because it's used for range checking.  */
  1080 };
  1081 
  1082 enum More_Lisp_Bits
  1083   {
  1084     /* For convenience, we also store the number of elements in these bits.
  1085        Note that this size is not necessarily the memory-footprint size, but
  1086        only the number of Lisp_Object fields (that need to be traced by GC).
  1087        The distinction is used, e.g., by Lisp_Process, which places extra
  1088        non-Lisp_Object fields at the end of the structure.  */
  1089     PSEUDOVECTOR_SIZE_BITS = 12,
  1090     PSEUDOVECTOR_SIZE_MASK = (1 << PSEUDOVECTOR_SIZE_BITS) - 1,
  1091 
  1092     /* To calculate the memory footprint of the pseudovector, it's useful
  1093        to store the size of non-Lisp area in word_size units here.  */
  1094     PSEUDOVECTOR_REST_BITS = 12,
  1095     PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1)
  1096                               << PSEUDOVECTOR_SIZE_BITS),
  1097 
  1098     /* Used to extract pseudovector subtype information.  */
  1099     PSEUDOVECTOR_AREA_BITS = PSEUDOVECTOR_SIZE_BITS + PSEUDOVECTOR_REST_BITS,
  1100     PVEC_TYPE_MASK = 0x3f << PSEUDOVECTOR_AREA_BITS
  1101   };
  1102 
  1103 /* These functions extract various sorts of values from a Lisp_Object.
  1104    For example, if tem is a Lisp_Object whose type is Lisp_Cons,
  1105    XCONS (tem) is the struct Lisp_Cons * pointing to the memory for
  1106    that cons.  */
  1107 
  1108 /* Largest and smallest representable fixnum values.  These are the C
  1109    values.  They are macros for use in #if and static initializers.  */
  1110 #define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
  1111 #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
  1112 
  1113 INLINE bool
  1114 PSEUDOVECTORP (Lisp_Object a, int code)
  1115 {
  1116   return lisp_h_PSEUDOVECTORP (a, code);
  1117 }
  1118 
  1119 INLINE bool
  1120 (BARE_SYMBOL_P) (Lisp_Object x)
  1121 {
  1122   return lisp_h_BARE_SYMBOL_P (x);
  1123 }
  1124 
  1125 INLINE bool
  1126 (SYMBOL_WITH_POS_P) (Lisp_Object x)
  1127 {
  1128   return lisp_h_SYMBOL_WITH_POS_P (x);
  1129 }
  1130 
  1131 INLINE bool
  1132 (SYMBOLP) (Lisp_Object x)
  1133 {
  1134   return lisp_h_SYMBOLP (x);
  1135 }
  1136 
  1137 INLINE struct Lisp_Symbol_With_Pos *
  1138 XSYMBOL_WITH_POS (Lisp_Object a)
  1139 {
  1140     eassert (SYMBOL_WITH_POS_P (a));
  1141     return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Symbol_With_Pos);
  1142 }
  1143 
  1144 INLINE struct Lisp_Symbol * ATTRIBUTE_NO_SANITIZE_UNDEFINED
  1145 (XBARE_SYMBOL) (Lisp_Object a)
  1146 {
  1147   eassert (BARE_SYMBOL_P (a));
  1148   intptr_t i = (intptr_t) XUNTAG (a, Lisp_Symbol, struct Lisp_Symbol);
  1149   void *p = (char *) lispsym + i;
  1150   return p;
  1151 }
  1152 
  1153 INLINE struct Lisp_Symbol * ATTRIBUTE_NO_SANITIZE_UNDEFINED
  1154 (XSYMBOL) (Lisp_Object a)
  1155 {
  1156   eassert (SYMBOLP ((a)));
  1157   if (!symbols_with_pos_enabled || BARE_SYMBOL_P (a))
  1158     return XBARE_SYMBOL (a);
  1159   return XBARE_SYMBOL (XSYMBOL_WITH_POS (a)->sym);
  1160 }
  1161 
  1162 INLINE Lisp_Object
  1163 make_lisp_symbol (struct Lisp_Symbol *sym)
  1164 {
  1165   /* GCC 7 x86-64 generates faster code if lispsym is
  1166      cast to char * rather than to intptr_t.  */
  1167   char *symoffset = (char *) ((char *) sym - (char *) lispsym);
  1168   Lisp_Object a = TAG_PTR (Lisp_Symbol, symoffset);
  1169   eassert (XSYMBOL (a) == sym);
  1170   return a;
  1171 }
  1172 
  1173 INLINE Lisp_Object
  1174 builtin_lisp_symbol (int index)
  1175 {
  1176   return make_lisp_symbol (&lispsym[index]);
  1177 }
  1178 
  1179 INLINE bool
  1180 c_symbol_p (struct Lisp_Symbol *sym)
  1181 {
  1182   char *bp = (char *) lispsym;
  1183   char *sp = (char *) sym;
  1184   if (PTRDIFF_MAX < INTPTR_MAX)
  1185     return bp <= sp && sp < bp + sizeof lispsym;
  1186   else
  1187     {
  1188       ptrdiff_t offset = sp - bp;
  1189       return 0 <= offset && offset < sizeof lispsym;
  1190     }
  1191 }
  1192 
  1193 INLINE void
  1194 (CHECK_SYMBOL) (Lisp_Object x)
  1195 {
  1196   lisp_h_CHECK_SYMBOL (x);
  1197 }
  1198 
  1199 /* True if the possibly-unsigned integer I doesn't fit in a fixnum.  */
  1200 
  1201 #define FIXNUM_OVERFLOW_P(i) \
  1202   (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
  1203 
  1204 #if USE_LSB_TAG
  1205 
  1206 INLINE Lisp_Object
  1207 (make_fixnum) (EMACS_INT n)
  1208 {
  1209   eassert (!FIXNUM_OVERFLOW_P (n));
  1210   return lisp_h_make_fixnum_wrap (n);
  1211 }
  1212 
  1213 INLINE EMACS_INT
  1214 (XFIXNUM_RAW) (Lisp_Object a)
  1215 {
  1216   return lisp_h_XFIXNUM_RAW (a);
  1217 }
  1218 
  1219 INLINE Lisp_Object
  1220 make_ufixnum (EMACS_INT n)
  1221 {
  1222   eassert (0 <= n && n <= INTMASK);
  1223   return lisp_h_make_fixnum_wrap (n);
  1224 }
  1225 
  1226 #else /* ! USE_LSB_TAG */
  1227 
  1228 /* Although compiled only if ! USE_LSB_TAG, the following functions
  1229    also work when USE_LSB_TAG; this is to aid future maintenance when
  1230    the lisp_h_* macros are eventually removed.  */
  1231 
  1232 /* Make a fixnum representing the value of the low order bits of N.  */
  1233 INLINE Lisp_Object
  1234 make_fixnum (EMACS_INT n)
  1235 {
  1236   eassert (! FIXNUM_OVERFLOW_P (n));
  1237   EMACS_INT int0 = Lisp_Int0;
  1238   if (USE_LSB_TAG)
  1239     {
  1240       EMACS_UINT u = n;
  1241       n = u << INTTYPEBITS;
  1242       n += int0;
  1243     }
  1244   else
  1245     {
  1246       n &= INTMASK;
  1247       n += (int0 << VALBITS);
  1248     }
  1249   return XIL (n);
  1250 }
  1251 
  1252 /* Extract A's value as a signed integer.  Unlike XFIXNUM, this works
  1253    on any Lisp object, although the resulting integer is useful only
  1254    for things like hashing when A is not a fixnum.  */
  1255 INLINE EMACS_INT
  1256 XFIXNUM_RAW (Lisp_Object a)
  1257 {
  1258   EMACS_INT i = XLI (a);
  1259   if (! USE_LSB_TAG)
  1260     {
  1261       EMACS_UINT u = i;
  1262       i = u << INTTYPEBITS;
  1263     }
  1264   return i >> INTTYPEBITS;
  1265 }
  1266 
  1267 INLINE Lisp_Object
  1268 make_ufixnum (EMACS_INT n)
  1269 {
  1270   eassert (0 <= n && n <= INTMASK);
  1271   EMACS_INT int0 = Lisp_Int0;
  1272   if (USE_LSB_TAG)
  1273     {
  1274       EMACS_UINT u = n;
  1275       n = u << INTTYPEBITS;
  1276       n += int0;
  1277     }
  1278   else
  1279     n += int0 << VALBITS;
  1280   return XIL (n);
  1281 }
  1282 
  1283 #endif /* ! USE_LSB_TAG */
  1284 
  1285 INLINE bool
  1286 (FIXNUMP) (Lisp_Object x)
  1287 {
  1288   return lisp_h_FIXNUMP (x);
  1289 }
  1290 
  1291 INLINE EMACS_INT
  1292 XFIXNUM (Lisp_Object a)
  1293 {
  1294   eassert (FIXNUMP (a));
  1295   return XFIXNUM_RAW (a);
  1296 }
  1297 
  1298 /* Extract A's value as an unsigned integer in the range 0..INTMASK.  */
  1299 INLINE EMACS_UINT
  1300 XUFIXNUM_RAW (Lisp_Object a)
  1301 {
  1302   EMACS_UINT i = XLI (a);
  1303   return USE_LSB_TAG ? i >> INTTYPEBITS : i & INTMASK;
  1304 }
  1305 INLINE EMACS_UINT
  1306 XUFIXNUM (Lisp_Object a)
  1307 {
  1308   eassert (FIXNUMP (a));
  1309   return XUFIXNUM_RAW (a);
  1310 }
  1311 
  1312 /* Return A's hash, which is in the range 0..INTMASK.  */
  1313 INLINE EMACS_INT
  1314 (XHASH) (Lisp_Object a)
  1315 {
  1316   return lisp_h_XHASH (a);
  1317 }
  1318 
  1319 /* Like make_fixnum (N), but may be faster.  N must be in nonnegative range.  */
  1320 INLINE Lisp_Object
  1321 make_fixed_natnum (EMACS_INT n)
  1322 {
  1323   eassert (0 <= n && n <= MOST_POSITIVE_FIXNUM);
  1324   EMACS_INT int0 = Lisp_Int0;
  1325   return USE_LSB_TAG ? make_fixnum (n) : XIL (n + (int0 << VALBITS));
  1326 }
  1327 
  1328 /* Return true if X and Y are the same object.  */
  1329 INLINE bool
  1330 (BASE_EQ) (Lisp_Object x, Lisp_Object y)
  1331 {
  1332   return lisp_h_BASE_EQ (x, y);
  1333 }
  1334 
  1335 /* Return true if X and Y are the same object, reckoning X to be the
  1336    same as a bare symbol Y if X is Y with position.  */
  1337 INLINE bool
  1338 (BASE2_EQ) (Lisp_Object x, Lisp_Object y)
  1339 {
  1340   return lisp_h_BASE2_EQ (x, y);
  1341 }
  1342 
  1343 /* Return true if X and Y are the same object, reckoning a symbol with
  1344    position as being the same as the bare symbol.  */
  1345 INLINE bool
  1346 (EQ) (Lisp_Object x, Lisp_Object y)
  1347 {
  1348   return lisp_h_EQ (x, y);
  1349 }
  1350 
  1351 INLINE intmax_t
  1352 clip_to_bounds (intmax_t lower, intmax_t num, intmax_t upper)
  1353 {
  1354   return num < lower ? lower : num <= upper ? num : upper;
  1355 }
  1356 
  1357 /* Construct a Lisp_Object from a value or address.  */
  1358 
  1359 INLINE Lisp_Object
  1360 make_lisp_ptr (void *ptr, enum Lisp_Type type)
  1361 {
  1362   Lisp_Object a = TAG_PTR (type, ptr);
  1363   eassert (TAGGEDP (a, type) && XUNTAG (a, type, char) == ptr);
  1364   return a;
  1365 }
  1366 
  1367 #define XSETINT(a, b) ((a) = make_fixnum (b))
  1368 #define XSETFASTINT(a, b) ((a) = make_fixed_natnum (b))
  1369 #define XSETCONS(a, b) ((a) = make_lisp_ptr (b, Lisp_Cons))
  1370 #define XSETVECTOR(a, b) ((a) = make_lisp_ptr (b, Lisp_Vectorlike))
  1371 #define XSETSTRING(a, b) ((a) = make_lisp_ptr (b, Lisp_String))
  1372 #define XSETSYMBOL(a, b) ((a) = make_lisp_symbol (b))
  1373 #define XSETFLOAT(a, b) ((a) = make_lisp_ptr (b, Lisp_Float))
  1374 
  1375 /* Return a Lisp_Object value that does not correspond to any object.
  1376    This can make some Lisp objects on free lists recognizable in O(1).  */
  1377 
  1378 INLINE Lisp_Object
  1379 dead_object (void)
  1380 {
  1381   return make_lisp_ptr (NULL, Lisp_String);
  1382 }
  1383 
  1384 /* Pseudovector types.  */
  1385 
  1386 #define XSETPVECTYPE(v, code)                                           \
  1387   ((v)->header.size |= PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS))
  1388 #define PVECHEADERSIZE(code, lispsize, restsize) \
  1389   (PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS) \
  1390    | ((restsize) << PSEUDOVECTOR_SIZE_BITS) | (lispsize))
  1391 #define XSETPVECTYPESIZE(v, code, lispsize, restsize)           \
  1392   ((v)->header.size = PVECHEADERSIZE (code, lispsize, restsize))
  1393 
  1394 /* The cast to union vectorlike_header * avoids aliasing issues.  */
  1395 #define XSETPSEUDOVECTOR(a, b, code) \
  1396   XSETTYPED_PSEUDOVECTOR (a, b,                                 \
  1397                           (XUNTAG (a, Lisp_Vectorlike,          \
  1398                                    union vectorlike_header)     \
  1399                            ->size),                             \
  1400                           code)
  1401 #define XSETTYPED_PSEUDOVECTOR(a, b, size, code)                        \
  1402   (XSETVECTOR (a, b),                                                   \
  1403    eassert ((size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))               \
  1404             == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS))))
  1405 
  1406 #define XSETWINDOW_CONFIGURATION(a, b) \
  1407   (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW_CONFIGURATION))
  1408 #define XSETPROCESS(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_PROCESS))
  1409 #define XSETWINDOW(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW))
  1410 #define XSETTERMINAL(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_TERMINAL))
  1411 #define XSETSUBR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUBR))
  1412 #define XSETBUFFER(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BUFFER))
  1413 #define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE))
  1414 #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
  1415 #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
  1416 #define XSETTHREAD(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_THREAD))
  1417 #define XSETMUTEX(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_MUTEX))
  1418 #define XSETCONDVAR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CONDVAR))
  1419 #define XSETNATIVE_COMP_UNIT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_NATIVE_COMP_UNIT))
  1420 
  1421 /* Efficiently convert a pointer to a Lisp object and back.  The
  1422    pointer is represented as a fixnum, so the garbage collector
  1423    does not know about it.  The pointer should not have both Lisp_Int1
  1424    bits set, which makes this conversion inherently unportable.  */
  1425 
  1426 INLINE void *
  1427 XFIXNUMPTR (Lisp_Object a)
  1428 {
  1429   return XUNTAG (a, Lisp_Int0, char);
  1430 }
  1431 
  1432 INLINE Lisp_Object
  1433 make_pointer_integer_unsafe (void *p)
  1434 {
  1435   Lisp_Object a = TAG_PTR (Lisp_Int0, p);
  1436   return a;
  1437 }
  1438 
  1439 INLINE Lisp_Object
  1440 make_pointer_integer (void *p)
  1441 {
  1442   Lisp_Object a = make_pointer_integer_unsafe (p);
  1443   eassert (FIXNUMP (a) && XFIXNUMPTR (a) == p);
  1444   return a;
  1445 }
  1446 
  1447 /* See the macros in intervals.h.  */
  1448 
  1449 typedef struct interval *INTERVAL;
  1450 
  1451 struct Lisp_Cons
  1452 {
  1453   union
  1454   {
  1455     struct
  1456     {
  1457       /* Car of this cons cell.  */
  1458       Lisp_Object car;
  1459 
  1460       union
  1461       {
  1462         /* Cdr of this cons cell.  */
  1463         Lisp_Object cdr;
  1464 
  1465         /* Used to chain conses on a free list.  */
  1466         struct Lisp_Cons *chain;
  1467       } u;
  1468     } s;
  1469     GCALIGNED_UNION_MEMBER
  1470   } u;
  1471 };
  1472 verify (GCALIGNED (struct Lisp_Cons));
  1473 
  1474 INLINE bool
  1475 (NILP) (Lisp_Object x)
  1476 {
  1477   return lisp_h_NILP (x);
  1478 }
  1479 
  1480 INLINE bool
  1481 (CONSP) (Lisp_Object x)
  1482 {
  1483   return lisp_h_CONSP (x);
  1484 }
  1485 
  1486 INLINE void
  1487 CHECK_CONS (Lisp_Object x)
  1488 {
  1489   CHECK_TYPE (CONSP (x), Qconsp, x);
  1490 }
  1491 
  1492 INLINE struct Lisp_Cons *
  1493 (XCONS) (Lisp_Object a)
  1494 {
  1495   return lisp_h_XCONS (a);
  1496 }
  1497 
  1498 /* Take the car or cdr of something known to be a cons cell.  */
  1499 /* The _addr functions shouldn't be used outside of the minimal set
  1500    of code that has to know what a cons cell looks like.  Other code not
  1501    part of the basic lisp implementation should assume that the car and cdr
  1502    fields are not accessible.  (What if we want to switch to
  1503    a copying collector someday?  Cached cons cell field addresses may be
  1504    invalidated at arbitrary points.)  */
  1505 INLINE Lisp_Object *
  1506 xcar_addr (Lisp_Object c)
  1507 {
  1508   return &XCONS (c)->u.s.car;
  1509 }
  1510 INLINE Lisp_Object *
  1511 xcdr_addr (Lisp_Object c)
  1512 {
  1513   return &XCONS (c)->u.s.u.cdr;
  1514 }
  1515 
  1516 /* Use these from normal code.  */
  1517 
  1518 INLINE Lisp_Object
  1519 (XCAR) (Lisp_Object c)
  1520 {
  1521   return lisp_h_XCAR (c);
  1522 }
  1523 
  1524 INLINE Lisp_Object
  1525 (XCDR) (Lisp_Object c)
  1526 {
  1527   return lisp_h_XCDR (c);
  1528 }
  1529 
  1530 /* Use these to set the fields of a cons cell.
  1531 
  1532    Note that both arguments may refer to the same object, so 'n'
  1533    should not be read after 'c' is first modified.  */
  1534 INLINE void
  1535 XSETCAR (Lisp_Object c, Lisp_Object n)
  1536 {
  1537   *xcar_addr (c) = n;
  1538 }
  1539 INLINE void
  1540 XSETCDR (Lisp_Object c, Lisp_Object n)
  1541 {
  1542   *xcdr_addr (c) = n;
  1543 }
  1544 
  1545 /* Take the car or cdr of something whose type is not known.  */
  1546 INLINE Lisp_Object
  1547 CAR (Lisp_Object c)
  1548 {
  1549   if (CONSP (c))
  1550     return XCAR (c);
  1551   if (!NILP (c))
  1552     wrong_type_argument (Qlistp, c);
  1553   return Qnil;
  1554 }
  1555 INLINE Lisp_Object
  1556 CDR (Lisp_Object c)
  1557 {
  1558   if (CONSP (c))
  1559     return XCDR (c);
  1560   if (!NILP (c))
  1561     wrong_type_argument (Qlistp, c);
  1562   return Qnil;
  1563 }
  1564 
  1565 /* Take the car or cdr of something whose type is not known.  */
  1566 INLINE Lisp_Object
  1567 CAR_SAFE (Lisp_Object c)
  1568 {
  1569   return CONSP (c) ? XCAR (c) : Qnil;
  1570 }
  1571 INLINE Lisp_Object
  1572 CDR_SAFE (Lisp_Object c)
  1573 {
  1574   return CONSP (c) ? XCDR (c) : Qnil;
  1575 }
  1576 
  1577 /* In a string or vector, the sign bit of u.s.size is the gc mark bit.  */
  1578 
  1579 struct Lisp_String
  1580 {
  1581   union
  1582   {
  1583     struct
  1584     {
  1585       /* Number of characters in string; MSB is used as the mark bit.  */
  1586       ptrdiff_t size;
  1587       /* If nonnegative, number of bytes in the string (which is multibyte).
  1588          If negative, the string is unibyte:
  1589          -1 for data normally allocated
  1590          -2 for data in rodata (C string constants)
  1591          -3 for data that must be immovable (used for bytecode)  */
  1592       ptrdiff_t size_byte;
  1593 
  1594       INTERVAL intervals;       /* Text properties in this string.  */
  1595       unsigned char *data;
  1596     } s;
  1597     struct Lisp_String *next;
  1598     GCALIGNED_UNION_MEMBER
  1599   } u;
  1600 };
  1601 verify (GCALIGNED (struct Lisp_String));
  1602 
  1603 INLINE bool
  1604 STRINGP (Lisp_Object x)
  1605 {
  1606   return TAGGEDP (x, Lisp_String);
  1607 }
  1608 
  1609 INLINE void
  1610 CHECK_STRING (Lisp_Object x)
  1611 {
  1612   CHECK_TYPE (STRINGP (x), Qstringp, x);
  1613 }
  1614 
  1615 INLINE struct Lisp_String *
  1616 XSTRING (Lisp_Object a)
  1617 {
  1618   eassert (STRINGP (a));
  1619   return XUNTAG (a, Lisp_String, struct Lisp_String);
  1620 }
  1621 
  1622 /* True if STR is a multibyte string.  */
  1623 INLINE bool
  1624 STRING_MULTIBYTE (Lisp_Object str)
  1625 {
  1626   return 0 <= XSTRING (str)->u.s.size_byte;
  1627 }
  1628 
  1629 /* An upper bound on the number of bytes in a Lisp string, not
  1630    counting the terminating null.  This a tight enough bound to
  1631    prevent integer overflow errors that would otherwise occur during
  1632    string size calculations.  A string cannot contain more bytes than
  1633    a fixnum can represent, nor can it be so long that C pointer
  1634    arithmetic stops working on the string plus its terminating null.
  1635    Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
  1636    may be a bit smaller than STRING_BYTES_BOUND, calculating it here
  1637    would expose alloc.c internal details that we'd rather keep
  1638    private.
  1639 
  1640    This is a macro for use in static initializers.  The cast to
  1641    ptrdiff_t ensures that the macro is signed.  */
  1642 #define STRING_BYTES_BOUND  \
  1643   ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1))
  1644 
  1645 /* Mark STR as a unibyte string.  */
  1646 #define STRING_SET_UNIBYTE(STR)                         \
  1647   do {                                                  \
  1648     if (XSTRING (STR)->u.s.size == 0)                   \
  1649       (STR) = empty_unibyte_string;                     \
  1650     else                                                \
  1651       XSTRING (STR)->u.s.size_byte = -1;                \
  1652   } while (false)
  1653 
  1654 /* Mark STR as a multibyte string.  Assure that STR contains only
  1655    ASCII characters in advance.  */
  1656 INLINE void
  1657 STRING_SET_MULTIBYTE (Lisp_Object str)
  1658 {
  1659   /* The 0-length strings are unique&shared so we can't modify them.  */
  1660   eassert (XSTRING (str)->u.s.size > 0);
  1661   XSTRING (str)->u.s.size_byte = XSTRING (str)->u.s.size;
  1662 }
  1663 
  1664 /* Convenience functions for dealing with Lisp strings.  */
  1665 
  1666 /* WARNING: Use the 'char *' pointers to string data with care in code
  1667    that could GC: GC can relocate string data, invalidating such
  1668    pointers.  It is best to use string character or byte index
  1669    instead, delaying the access through SDATA/SSDATA pointers to the
  1670    latest possible moment.  If you must use the 'char *' pointers
  1671    (e.g., for speed), be sure to adjust them after any call that could
  1672    potentially GC.  */
  1673 
  1674 INLINE unsigned char *
  1675 SDATA (Lisp_Object string)
  1676 {
  1677   return XSTRING (string)->u.s.data;
  1678 }
  1679 INLINE char *
  1680 SSDATA (Lisp_Object string)
  1681 {
  1682   /* Avoid "differ in sign" warnings.  */
  1683   return (char *) SDATA (string);
  1684 }
  1685 INLINE unsigned char
  1686 SREF (Lisp_Object string, ptrdiff_t index)
  1687 {
  1688   return SDATA (string)[index];
  1689 }
  1690 INLINE void
  1691 SSET (Lisp_Object string, ptrdiff_t index, unsigned char new)
  1692 {
  1693   SDATA (string)[index] = new;
  1694 }
  1695 INLINE ptrdiff_t
  1696 SCHARS (Lisp_Object string)
  1697 {
  1698   ptrdiff_t nchars = XSTRING (string)->u.s.size;
  1699   eassume (0 <= nchars);
  1700   return nchars;
  1701 }
  1702 
  1703 #ifdef GC_CHECK_STRING_BYTES
  1704 extern ptrdiff_t string_bytes (struct Lisp_String *);
  1705 #endif
  1706 INLINE ptrdiff_t
  1707 STRING_BYTES (struct Lisp_String *s)
  1708 {
  1709 #ifdef GC_CHECK_STRING_BYTES
  1710   ptrdiff_t nbytes = string_bytes (s);
  1711 #else
  1712   ptrdiff_t nbytes = s->u.s.size_byte < 0 ? s->u.s.size : s->u.s.size_byte;
  1713 #endif
  1714   eassume (0 <= nbytes);
  1715   return nbytes;
  1716 }
  1717 
  1718 INLINE ptrdiff_t
  1719 SBYTES (Lisp_Object string)
  1720 {
  1721   return STRING_BYTES (XSTRING (string));
  1722 }
  1723 INLINE void
  1724 STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize)
  1725 {
  1726   /* This function cannot change the size of data allocated for the
  1727      string when it was created.  */
  1728   eassert (STRING_MULTIBYTE (string)
  1729            ? 0 <= newsize && newsize <= SBYTES (string)
  1730            : newsize == SCHARS (string));
  1731   XSTRING (string)->u.s.size = newsize;
  1732 }
  1733 
  1734 INLINE void
  1735 CHECK_STRING_NULL_BYTES (Lisp_Object string)
  1736 {
  1737   CHECK_TYPE (memchr (SSDATA (string), '\0', SBYTES (string)) == NULL,
  1738               Qfilenamep, string);
  1739 }
  1740 
  1741 /* True if STR is immovable (whose data won't move during GC).  */
  1742 INLINE bool
  1743 string_immovable_p (Lisp_Object str)
  1744 {
  1745   return XSTRING (str)->u.s.size_byte == -3;
  1746 }
  1747 
  1748 /* A regular vector is just a header plus an array of Lisp_Objects.  */
  1749 
  1750 struct Lisp_Vector
  1751   {
  1752     union vectorlike_header header;
  1753     Lisp_Object contents[FLEXIBLE_ARRAY_MEMBER];
  1754   } GCALIGNED_STRUCT;
  1755 
  1756 INLINE bool
  1757 (VECTORLIKEP) (Lisp_Object x)
  1758 {
  1759   return lisp_h_VECTORLIKEP (x);
  1760 }
  1761 
  1762 INLINE struct Lisp_Vector *
  1763 XVECTOR (Lisp_Object a)
  1764 {
  1765   eassert (VECTORLIKEP (a));
  1766   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Vector);
  1767 }
  1768 
  1769 INLINE ptrdiff_t
  1770 ASIZE (Lisp_Object array)
  1771 {
  1772   ptrdiff_t size = XVECTOR (array)->header.size;
  1773   eassume (0 <= size);
  1774   return size;
  1775 }
  1776 
  1777 INLINE ptrdiff_t
  1778 gc_asize (Lisp_Object array)
  1779 {
  1780   /* Like ASIZE, but also can be used in the garbage collector.  */
  1781   return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG;
  1782 }
  1783 
  1784 INLINE ptrdiff_t
  1785 PVSIZE (Lisp_Object pv)
  1786 {
  1787   return ASIZE (pv) & PSEUDOVECTOR_SIZE_MASK;
  1788 }
  1789 
  1790 INLINE bool
  1791 VECTORP (Lisp_Object x)
  1792 {
  1793   return VECTORLIKEP (x) && ! (ASIZE (x) & PSEUDOVECTOR_FLAG);
  1794 }
  1795 
  1796 INLINE void
  1797 CHECK_VECTOR (Lisp_Object x)
  1798 {
  1799   CHECK_TYPE (VECTORP (x), Qvectorp, x);
  1800 }
  1801 
  1802 
  1803 /* A pseudovector is like a vector, but has other non-Lisp components.  */
  1804 
  1805 INLINE enum pvec_type
  1806 PSEUDOVECTOR_TYPE (const struct Lisp_Vector *v)
  1807 {
  1808   ptrdiff_t size = v->header.size;
  1809   return (size & PSEUDOVECTOR_FLAG
  1810           ? (size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS
  1811           : PVEC_NORMAL_VECTOR);
  1812 }
  1813 
  1814 /* Can't be used with PVEC_NORMAL_VECTOR.  */
  1815 INLINE bool
  1816 PSEUDOVECTOR_TYPEP (const union vectorlike_header *a, enum pvec_type code)
  1817 {
  1818   /* We don't use PSEUDOVECTOR_TYPE here so as to avoid a shift
  1819    * operation when `code' is known.  */
  1820   return ((a->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))
  1821           == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS)));
  1822 }
  1823 
  1824 /* A boolvector is a kind of vectorlike, with contents like a string.  */
  1825 
  1826 struct Lisp_Bool_Vector
  1827   {
  1828     /* HEADER.SIZE is the vector's size field.  It doesn't have the real size,
  1829        just the subtype information.  */
  1830     union vectorlike_header header;
  1831     /* This is the size in bits.  */
  1832     EMACS_INT size;
  1833     /* The actual bits, packed into bytes.
  1834        Zeros fill out the last word if needed.
  1835        The bits are in little-endian order in the bytes, and
  1836        the bytes are in little-endian order in the words.  */
  1837     bits_word data[FLEXIBLE_ARRAY_MEMBER];
  1838   } GCALIGNED_STRUCT;
  1839 
  1840 /* Some handy constants for calculating sizes
  1841    and offsets, mostly of vectorlike objects.
  1842 
  1843    The garbage collector assumes that the initial part of any struct
  1844    that starts with a union vectorlike_header followed by N
  1845    Lisp_Objects (some possibly in arrays and/or a trailing flexible
  1846    array) will be laid out like a struct Lisp_Vector with N
  1847    Lisp_Objects.  This assumption is true in practice on known Emacs
  1848    targets even though the C standard does not guarantee it.  This
  1849    header contains a few sanity checks that should suffice to detect
  1850    violations of this assumption on plausible practical hosts.  */
  1851 
  1852 enum
  1853   {
  1854     header_size = offsetof (struct Lisp_Vector, contents),
  1855     bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
  1856     word_size = sizeof (Lisp_Object)
  1857   };
  1858 
  1859 /* The number of data words and bytes in a bool vector with SIZE bits.  */
  1860 
  1861 INLINE EMACS_INT
  1862 bool_vector_words (EMACS_INT size)
  1863 {
  1864   eassume (0 <= size && size <= EMACS_INT_MAX - (BITS_PER_BITS_WORD - 1));
  1865   return (size + BITS_PER_BITS_WORD - 1) / BITS_PER_BITS_WORD;
  1866 }
  1867 
  1868 INLINE EMACS_INT
  1869 bool_vector_bytes (EMACS_INT size)
  1870 {
  1871   eassume (0 <= size && size <= EMACS_INT_MAX - (BITS_PER_BITS_WORD - 1));
  1872   return (size + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR;
  1873 }
  1874 
  1875 INLINE bool
  1876 BOOL_VECTOR_P (Lisp_Object a)
  1877 {
  1878   return PSEUDOVECTORP (a, PVEC_BOOL_VECTOR);
  1879 }
  1880 
  1881 INLINE void
  1882 CHECK_BOOL_VECTOR (Lisp_Object x)
  1883 {
  1884   CHECK_TYPE (BOOL_VECTOR_P (x), Qbool_vector_p, x);
  1885 }
  1886 
  1887 INLINE struct Lisp_Bool_Vector *
  1888 XBOOL_VECTOR (Lisp_Object a)
  1889 {
  1890   eassert (BOOL_VECTOR_P (a));
  1891   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Bool_Vector);
  1892 }
  1893 
  1894 INLINE EMACS_INT
  1895 bool_vector_size (Lisp_Object a)
  1896 {
  1897   EMACS_INT size = XBOOL_VECTOR (a)->size;
  1898   eassume (0 <= size);
  1899   return size;
  1900 }
  1901 
  1902 INLINE bits_word *
  1903 bool_vector_data (Lisp_Object a)
  1904 {
  1905   return XBOOL_VECTOR (a)->data;
  1906 }
  1907 
  1908 INLINE unsigned char *
  1909 bool_vector_uchar_data (Lisp_Object a)
  1910 {
  1911   return (unsigned char *) bool_vector_data (a);
  1912 }
  1913 
  1914 /* True if A's Ith bit is set.  */
  1915 
  1916 INLINE bool
  1917 bool_vector_bitref (Lisp_Object a, EMACS_INT i)
  1918 {
  1919   eassume (0 <= i);
  1920   eassert (i < bool_vector_size (a));
  1921   return !! (bool_vector_uchar_data (a)[i / BOOL_VECTOR_BITS_PER_CHAR]
  1922              & (1 << (i % BOOL_VECTOR_BITS_PER_CHAR)));
  1923 }
  1924 
  1925 INLINE Lisp_Object
  1926 bool_vector_ref (Lisp_Object a, EMACS_INT i)
  1927 {
  1928   return bool_vector_bitref (a, i) ? Qt : Qnil;
  1929 }
  1930 
  1931 /* Set A's Ith bit to B.  */
  1932 
  1933 INLINE void
  1934 bool_vector_set (Lisp_Object a, EMACS_INT i, bool b)
  1935 {
  1936   eassume (0 <= i);
  1937   eassert (i < bool_vector_size (a));
  1938 
  1939   unsigned char *addr
  1940     = &bool_vector_uchar_data (a)[i / BOOL_VECTOR_BITS_PER_CHAR];
  1941   if (b)
  1942     *addr |= 1 << (i % BOOL_VECTOR_BITS_PER_CHAR);
  1943   else
  1944     *addr &= ~ (1 << (i % BOOL_VECTOR_BITS_PER_CHAR));
  1945 }
  1946 
  1947 /* Conveniences for dealing with Lisp arrays.  */
  1948 
  1949 INLINE Lisp_Object
  1950 AREF (Lisp_Object array, ptrdiff_t idx)
  1951 {
  1952   eassert (0 <= idx && idx < gc_asize (array));
  1953   return XVECTOR (array)->contents[idx];
  1954 }
  1955 
  1956 INLINE Lisp_Object *
  1957 aref_addr (Lisp_Object array, ptrdiff_t idx)
  1958 {
  1959   eassert (0 <= idx && idx <= gc_asize (array));
  1960   return & XVECTOR (array)->contents[idx];
  1961 }
  1962 
  1963 INLINE void
  1964 ASET (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
  1965 {
  1966   eassert (0 <= idx && idx < ASIZE (array));
  1967   XVECTOR (array)->contents[idx] = val;
  1968 }
  1969 
  1970 INLINE void
  1971 gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
  1972 {
  1973   /* Like ASET, but also can be used in the garbage collector:
  1974      sweep_weak_table calls set_hash_key etc. while the table is marked.  */
  1975   eassert (0 <= idx && idx < gc_asize (array));
  1976   XVECTOR (array)->contents[idx] = val;
  1977 }
  1978 
  1979 /* True, since Qnil's representation is zero.  Every place in the code
  1980    that assumes Qnil is zero should verify (NIL_IS_ZERO), to make it easy
  1981    to find such assumptions later if we change Qnil to be nonzero.
  1982    Test iQnil and Lisp_Symbol instead of Qnil directly, since the latter
  1983    is not suitable for use in an integer constant expression.  */
  1984 enum { NIL_IS_ZERO = iQnil == 0 && Lisp_Symbol == 0 };
  1985 
  1986 /* Clear the object addressed by P, with size NBYTES, so that all its
  1987    bytes are zero and all its Lisp values are nil.  */
  1988 INLINE void
  1989 memclear (void *p, ptrdiff_t nbytes)
  1990 {
  1991   eassert (0 <= nbytes);
  1992   verify (NIL_IS_ZERO);
  1993   /* Since Qnil is zero, memset suffices.  */
  1994   memset (p, 0, nbytes);
  1995 }
  1996 
  1997 /* If a struct is made to look like a vector, this macro returns the length
  1998    of the shortest vector that would hold that struct.  */
  1999 
  2000 #define VECSIZE(type)                                           \
  2001   ((sizeof (type) - header_size + word_size - 1) / word_size)
  2002 
  2003 /* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
  2004    at the end and we need to compute the number of Lisp_Object fields (the
  2005    ones that the GC needs to trace).  */
  2006 
  2007 #define PSEUDOVECSIZE(type, lastlispfield)                              \
  2008   (offsetof (type, lastlispfield) + word_size < header_size             \
  2009    ? 0 : (offsetof (type, lastlispfield) + word_size - header_size) / word_size)
  2010 
  2011 /* True iff C is an ASCII character.  */
  2012 INLINE bool
  2013 ASCII_CHAR_P (intmax_t c)
  2014 {
  2015   return 0 <= c && c < 0x80;
  2016 }
  2017 
  2018 /* A char-table is a kind of vectorlike, with contents like a vector,
  2019    but with a few additional slots.  For some purposes, it makes sense
  2020    to handle a char-table as type 'struct Lisp_Vector'.  An element of
  2021    a char-table can be any Lisp object, but if it is a sub-char-table,
  2022    we treat it as a table that contains information of a specific
  2023    range of characters.  A sub-char-table is like a vector, but with
  2024    two integer fields between the header and Lisp data, which means
  2025    that it has to be marked with some precautions (see mark_char_table
  2026    in alloc.c).  A sub-char-table appears in an element of a char-table.  */
  2027 
  2028 enum CHARTAB_SIZE_BITS
  2029   {
  2030     CHARTAB_SIZE_BITS_0 = 6,
  2031     CHARTAB_SIZE_BITS_1 = 4,
  2032     CHARTAB_SIZE_BITS_2 = 5,
  2033     CHARTAB_SIZE_BITS_3 = 7
  2034   };
  2035 
  2036 extern const int chartab_size[4];
  2037 
  2038 struct Lisp_Char_Table
  2039   {
  2040     /* HEADER.SIZE is the vector's size field, which also holds the
  2041        pseudovector type information.  It holds the size, too.
  2042        The size counts the defalt, parent, purpose, ascii,
  2043        contents, and extras slots.  */
  2044     union vectorlike_header header;
  2045 
  2046     /* This holds the default value, which is used whenever the value
  2047        for a specific character is nil.  */
  2048     Lisp_Object defalt;
  2049 
  2050     /* This points to another char table, from which we inherit when the
  2051        value for a specific character is nil.  The `defalt' slot takes
  2052        precedence over this.  */
  2053     Lisp_Object parent;
  2054 
  2055     /* This is a symbol which says what kind of use this char-table is
  2056        meant for.  */
  2057     Lisp_Object purpose;
  2058 
  2059     /* The bottom sub char-table for characters in the range 0..127.  It
  2060        is nil if no ASCII character has a specific value.  */
  2061     Lisp_Object ascii;
  2062 
  2063     Lisp_Object contents[(1 << CHARTAB_SIZE_BITS_0)];
  2064 
  2065     /* These hold additional data.  It is a vector.  */
  2066     Lisp_Object extras[FLEXIBLE_ARRAY_MEMBER];
  2067   } GCALIGNED_STRUCT;
  2068 
  2069 INLINE bool
  2070 CHAR_TABLE_P (Lisp_Object a)
  2071 {
  2072   return PSEUDOVECTORP (a, PVEC_CHAR_TABLE);
  2073 }
  2074 
  2075 INLINE struct Lisp_Char_Table *
  2076 XCHAR_TABLE (Lisp_Object a)
  2077 {
  2078   eassert (CHAR_TABLE_P (a));
  2079   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Char_Table);
  2080 }
  2081 
  2082 struct Lisp_Sub_Char_Table
  2083   {
  2084     /* HEADER.SIZE is the vector's size field, which also holds the
  2085        pseudovector type information.  It holds the size, too.  */
  2086     union vectorlike_header header;
  2087 
  2088     /* Depth of this sub char-table.  It should be 1, 2, or 3.  A sub
  2089        char-table of depth 1 contains 16 elements, and each element
  2090        covers 4096 (128*32) characters.  A sub char-table of depth 2
  2091        contains 32 elements, and each element covers 128 characters.  A
  2092        sub char-table of depth 3 contains 128 elements, and each element
  2093        is for one character.  */
  2094     int depth;
  2095 
  2096     /* Minimum character covered by the sub char-table.  */
  2097     int min_char;
  2098 
  2099     /* Use set_sub_char_table_contents to set this.  */
  2100     Lisp_Object contents[FLEXIBLE_ARRAY_MEMBER];
  2101   } GCALIGNED_STRUCT;
  2102 
  2103 INLINE bool
  2104 SUB_CHAR_TABLE_P (Lisp_Object a)
  2105 {
  2106   return PSEUDOVECTORP (a, PVEC_SUB_CHAR_TABLE);
  2107 }
  2108 
  2109 INLINE struct Lisp_Sub_Char_Table *
  2110 XSUB_CHAR_TABLE (Lisp_Object a)
  2111 {
  2112   eassert (SUB_CHAR_TABLE_P (a));
  2113   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Sub_Char_Table);
  2114 }
  2115 
  2116 INLINE Lisp_Object
  2117 CHAR_TABLE_REF_ASCII (Lisp_Object ct, ptrdiff_t idx)
  2118 {
  2119   for (struct Lisp_Char_Table *tbl = XCHAR_TABLE (ct); ;
  2120        tbl = XCHAR_TABLE (tbl->parent))
  2121     {
  2122       Lisp_Object val = (SUB_CHAR_TABLE_P (tbl->ascii)
  2123                          ? XSUB_CHAR_TABLE (tbl->ascii)->contents[idx]
  2124                          : tbl->ascii);
  2125       if (NILP (val))
  2126         val = tbl->defalt;
  2127       if (!NILP (val) || NILP (tbl->parent))
  2128         return val;
  2129     }
  2130 }
  2131 
  2132 /* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
  2133    characters.  Does not check validity of CT.  */
  2134 INLINE Lisp_Object
  2135 CHAR_TABLE_REF (Lisp_Object ct, int idx)
  2136 {
  2137   return (ASCII_CHAR_P (idx)
  2138           ? CHAR_TABLE_REF_ASCII (ct, idx)
  2139           : char_table_ref (ct, idx));
  2140 }
  2141 
  2142 /* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
  2143    8-bit European characters.  Does not check validity of CT.  */
  2144 INLINE void
  2145 CHAR_TABLE_SET (Lisp_Object ct, int idx, Lisp_Object val)
  2146 {
  2147   if (ASCII_CHAR_P (idx) && SUB_CHAR_TABLE_P (XCHAR_TABLE (ct)->ascii))
  2148     set_sub_char_table_contents (XCHAR_TABLE (ct)->ascii, idx, val);
  2149   else
  2150     char_table_set (ct, idx, val);
  2151 }
  2152 
  2153 #include "comp.h"
  2154 
  2155 /* This structure describes a built-in function.
  2156    It is generated by the DEFUN macro only.
  2157    defsubr makes it into a Lisp object.  */
  2158 
  2159 struct Lisp_Subr
  2160   {
  2161     union vectorlike_header header;
  2162     union {
  2163       Lisp_Object (*a0) (void);
  2164       Lisp_Object (*a1) (Lisp_Object);
  2165       Lisp_Object (*a2) (Lisp_Object, Lisp_Object);
  2166       Lisp_Object (*a3) (Lisp_Object, Lisp_Object, Lisp_Object);
  2167       Lisp_Object (*a4) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  2168       Lisp_Object (*a5) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  2169       Lisp_Object (*a6) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  2170       Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  2171       Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  2172       Lisp_Object (*aUNEVALLED) (Lisp_Object args);
  2173       Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
  2174     } function;
  2175     short min_args, max_args;
  2176     const char *symbol_name;
  2177     union {
  2178       const char *string;
  2179       Lisp_Object native;
  2180     } intspec;
  2181     Lisp_Object command_modes;
  2182     EMACS_INT doc;
  2183 #ifdef HAVE_NATIVE_COMP
  2184     Lisp_Object native_comp_u;
  2185     char *native_c_name;
  2186     Lisp_Object lambda_list;
  2187     Lisp_Object type;
  2188 #endif
  2189   } GCALIGNED_STRUCT;
  2190 union Aligned_Lisp_Subr
  2191   {
  2192     struct Lisp_Subr s;
  2193     GCALIGNED_UNION_MEMBER
  2194   };
  2195 verify (GCALIGNED (union Aligned_Lisp_Subr));
  2196 
  2197 INLINE bool
  2198 SUBRP (Lisp_Object a)
  2199 {
  2200   return PSEUDOVECTORP (a, PVEC_SUBR);
  2201 }
  2202 
  2203 INLINE struct Lisp_Subr *
  2204 XSUBR (Lisp_Object a)
  2205 {
  2206   eassert (SUBRP (a));
  2207   return &XUNTAG (a, Lisp_Vectorlike, union Aligned_Lisp_Subr)->s;
  2208 }
  2209 
  2210 /* Return whether a value might be a valid docstring.
  2211    Used to distinguish the presence of non-docstring in the docstring slot,
  2212    as in the case of OClosures.  */
  2213 INLINE bool
  2214 VALID_DOCSTRING_P (Lisp_Object doc)
  2215 {
  2216   return FIXNUMP (doc) || STRINGP (doc)
  2217          || (CONSP (doc) && STRINGP (XCAR (doc)) && FIXNUMP (XCDR (doc)));
  2218 }
  2219 
  2220 enum char_table_specials
  2221   {
  2222     /* This is the number of slots that every char table must have.  This
  2223        counts the ordinary slots and the top, defalt, parent, and purpose
  2224        slots.  */
  2225     CHAR_TABLE_STANDARD_SLOTS
  2226       = (PSEUDOVECSIZE (struct Lisp_Char_Table, contents) - 1
  2227          + (1 << CHARTAB_SIZE_BITS_0)),
  2228 
  2229     /* This is the index of the first Lisp_Object field in Lisp_Sub_Char_Table
  2230        when the latter is treated as an ordinary Lisp_Vector.  */
  2231     SUB_CHAR_TABLE_OFFSET
  2232       = PSEUDOVECSIZE (struct Lisp_Sub_Char_Table, contents) - 1
  2233   };
  2234 
  2235 /* Sanity-check pseudovector layout.  */
  2236 verify (offsetof (struct Lisp_Char_Table, defalt) == header_size);
  2237 verify (offsetof (struct Lisp_Char_Table, extras)
  2238         == header_size + CHAR_TABLE_STANDARD_SLOTS * sizeof (Lisp_Object));
  2239 verify (offsetof (struct Lisp_Sub_Char_Table, contents)
  2240         == header_size + SUB_CHAR_TABLE_OFFSET * sizeof (Lisp_Object));
  2241 
  2242 /* Return the number of "extra" slots in the char table CT.  */
  2243 
  2244 INLINE int
  2245 CHAR_TABLE_EXTRA_SLOTS (struct Lisp_Char_Table *ct)
  2246 {
  2247   return ((ct->header.size & PSEUDOVECTOR_SIZE_MASK)
  2248           - CHAR_TABLE_STANDARD_SLOTS);
  2249 }
  2250 
  2251 
  2252 /* Save and restore the instruction and environment pointers,
  2253    without affecting the signal mask.  */
  2254 
  2255 #ifdef HAVE__SETJMP
  2256 typedef jmp_buf sys_jmp_buf;
  2257 # define sys_setjmp(j) _setjmp (j)
  2258 # define sys_longjmp(j, v) _longjmp (j, v)
  2259 #elif defined HAVE_SIGSETJMP
  2260 typedef sigjmp_buf sys_jmp_buf;
  2261 # define sys_setjmp(j) sigsetjmp (j, 0)
  2262 # define sys_longjmp(j, v) siglongjmp (j, v)
  2263 #else
  2264 /* A platform that uses neither _longjmp nor siglongjmp; assume
  2265    longjmp does not affect the sigmask.  */
  2266 typedef jmp_buf sys_jmp_buf;
  2267 # define sys_setjmp(j) setjmp (j)
  2268 # define sys_longjmp(j, v) longjmp (j, v)
  2269 #endif
  2270 
  2271 #include "thread.h"
  2272 
  2273 /***********************************************************************
  2274                                Symbols
  2275  ***********************************************************************/
  2276 
  2277 /* Value is name of symbol.  */
  2278 
  2279 INLINE Lisp_Object
  2280 (SYMBOL_VAL) (struct Lisp_Symbol *sym)
  2281 {
  2282   return lisp_h_SYMBOL_VAL (sym);
  2283 }
  2284 
  2285 INLINE struct Lisp_Symbol *
  2286 SYMBOL_ALIAS (struct Lisp_Symbol *sym)
  2287 {
  2288   eassume (sym->u.s.redirect == SYMBOL_VARALIAS && sym->u.s.val.alias);
  2289   return sym->u.s.val.alias;
  2290 }
  2291 INLINE struct Lisp_Buffer_Local_Value *
  2292 SYMBOL_BLV (struct Lisp_Symbol *sym)
  2293 {
  2294   eassume (sym->u.s.redirect == SYMBOL_LOCALIZED && sym->u.s.val.blv);
  2295   return sym->u.s.val.blv;
  2296 }
  2297 INLINE lispfwd
  2298 SYMBOL_FWD (struct Lisp_Symbol *sym)
  2299 {
  2300   eassume (sym->u.s.redirect == SYMBOL_FORWARDED && sym->u.s.val.fwd.fwdptr);
  2301   return sym->u.s.val.fwd;
  2302 }
  2303 
  2304 INLINE void
  2305 (SET_SYMBOL_VAL) (struct Lisp_Symbol *sym, Lisp_Object v)
  2306 {
  2307   lisp_h_SET_SYMBOL_VAL (sym, v);
  2308 }
  2309 
  2310 INLINE void
  2311 SET_SYMBOL_ALIAS (struct Lisp_Symbol *sym, struct Lisp_Symbol *v)
  2312 {
  2313   eassume (sym->u.s.redirect == SYMBOL_VARALIAS && v);
  2314   sym->u.s.val.alias = v;
  2315 }
  2316 INLINE void
  2317 SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v)
  2318 {
  2319   eassume (sym->u.s.redirect == SYMBOL_LOCALIZED && v);
  2320   sym->u.s.val.blv = v;
  2321 }
  2322 INLINE void
  2323 SET_SYMBOL_FWD (struct Lisp_Symbol *sym, void const *v)
  2324 {
  2325   eassume (sym->u.s.redirect == SYMBOL_FORWARDED && v);
  2326   sym->u.s.val.fwd.fwdptr = v;
  2327 }
  2328 
  2329 INLINE Lisp_Object
  2330 SYMBOL_NAME (Lisp_Object sym)
  2331 {
  2332   return XSYMBOL (sym)->u.s.name;
  2333 }
  2334 
  2335 /* Value is true if SYM is an interned symbol.  */
  2336 
  2337 INLINE bool
  2338 SYMBOL_INTERNED_P (Lisp_Object sym)
  2339 {
  2340   return XSYMBOL (sym)->u.s.interned != SYMBOL_UNINTERNED;
  2341 }
  2342 
  2343 /* Value is true if SYM is interned in initial_obarray.  */
  2344 
  2345 INLINE bool
  2346 SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (Lisp_Object sym)
  2347 {
  2348   return XSYMBOL (sym)->u.s.interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
  2349 }
  2350 
  2351 /* Value is non-zero if symbol cannot be changed through a simple set,
  2352    i.e. it's a constant (e.g. nil, t, :keywords), or it has some
  2353    watching functions.  */
  2354 
  2355 INLINE int
  2356 (SYMBOL_TRAPPED_WRITE_P) (Lisp_Object sym)
  2357 {
  2358   return lisp_h_SYMBOL_TRAPPED_WRITE_P (sym);
  2359 }
  2360 
  2361 /* Value is non-zero if symbol cannot be changed at all, i.e. it's a
  2362    constant (e.g. nil, t, :keywords).  Code that actually wants to
  2363    write to SYM, should also check whether there are any watching
  2364    functions.  */
  2365 
  2366 INLINE int
  2367 (SYMBOL_CONSTANT_P) (Lisp_Object sym)
  2368 {
  2369   return lisp_h_SYMBOL_CONSTANT_P (sym);
  2370 }
  2371 
  2372 /* Placeholder for make-docfile to process.  The actual symbol
  2373    definition is done by lread.c's define_symbol.  */
  2374 #define DEFSYM(sym, name) /* empty */
  2375 
  2376 
  2377 /***********************************************************************
  2378                              Hash Tables
  2379  ***********************************************************************/
  2380 
  2381 /* The structure of a Lisp hash table.  */
  2382 
  2383 struct Lisp_Hash_Table;
  2384 
  2385 struct hash_table_test
  2386 {
  2387   /* Name of the function used to compare keys.  */
  2388   Lisp_Object name;
  2389 
  2390   /* User-supplied hash function, or nil.  */
  2391   Lisp_Object user_hash_function;
  2392 
  2393   /* User-supplied key comparison function, or nil.  */
  2394   Lisp_Object user_cmp_function;
  2395 
  2396   /* C function to compare two keys.  */
  2397   Lisp_Object (*cmpfn) (Lisp_Object, Lisp_Object, struct Lisp_Hash_Table *);
  2398 
  2399   /* C function to compute hash code.  */
  2400   Lisp_Object (*hashfn) (Lisp_Object, struct Lisp_Hash_Table *);
  2401 };
  2402 
  2403 struct Lisp_Hash_Table
  2404 {
  2405   /* Change pdumper.c if you change the fields here.  */
  2406 
  2407   /* This is for Lisp; the hash table code does not refer to it.  */
  2408   union vectorlike_header header;
  2409 
  2410   /* Nil if table is non-weak.  Otherwise a symbol describing the
  2411      weakness of the table.  */
  2412   Lisp_Object weak;
  2413 
  2414   /* Vector of hash codes, or nil if the table needs rehashing.
  2415      If the I-th entry is unused, then hash[I] should be nil.  */
  2416   Lisp_Object hash;
  2417 
  2418   /* Vector used to chain entries.  If entry I is free, next[I] is the
  2419      entry number of the next free item.  If entry I is non-free,
  2420      next[I] is the index of the next entry in the collision chain,
  2421      or -1 if there is such entry.  */
  2422   Lisp_Object next;
  2423 
  2424   /* Bucket vector.  An entry of -1 indicates no item is present,
  2425      and a nonnegative entry is the index of the first item in
  2426      a collision chain.  This vector's size can be larger than the
  2427      hash table size to reduce collisions.  */
  2428   Lisp_Object index;
  2429 
  2430   /* Only the fields above are traced normally by the GC.  The ones after
  2431      'index' are special and are either ignored by the GC or traced in
  2432      a special way (e.g. because of weakness).  */
  2433 
  2434   /* Number of key/value entries in the table.  */
  2435   ptrdiff_t count;
  2436 
  2437   /* Index of first free entry in free list, or -1 if none.  */
  2438   ptrdiff_t next_free;
  2439 
  2440   /* True if the table can be purecopied.  The table cannot be
  2441      changed afterwards.  */
  2442   bool purecopy;
  2443 
  2444   /* True if the table is mutable.  Ordinarily tables are mutable, but
  2445      pure tables are not, and while a table is being mutated it is
  2446      immutable for recursive attempts to mutate it.  */
  2447   bool mutable;
  2448 
  2449   /* Resize hash table when number of entries / table size is >= this
  2450      ratio.  */
  2451   float rehash_threshold;
  2452 
  2453   /* Used when the table is resized.  If equal to a negative integer,
  2454      the user rehash-size is the integer -REHASH_SIZE, and the new
  2455      size is the old size plus -REHASH_SIZE.  If positive, the user
  2456      rehash-size is the floating-point value REHASH_SIZE + 1, and the
  2457      new size is the old size times REHASH_SIZE + 1.  */
  2458   float rehash_size;
  2459 
  2460   /* Vector of keys and values.  The key of item I is found at index
  2461      2 * I, the value is found at index 2 * I + 1.
  2462      If the key is equal to Qunbound, then this slot is unused.
  2463      This is gc_marked specially if the table is weak.  */
  2464   Lisp_Object key_and_value;
  2465 
  2466   /* The comparison and hash functions.  */
  2467   struct hash_table_test test;
  2468 
  2469   /* Next weak hash table if this is a weak hash table.  The head of
  2470      the list is in weak_hash_tables.  Used only during garbage
  2471      collection --- at other times, it is NULL.  */
  2472   struct Lisp_Hash_Table *next_weak;
  2473 } GCALIGNED_STRUCT;
  2474 
  2475 /* Sanity-check pseudovector layout.  */
  2476 verify (offsetof (struct Lisp_Hash_Table, weak) == header_size);
  2477 
  2478 INLINE bool
  2479 HASH_TABLE_P (Lisp_Object a)
  2480 {
  2481   return PSEUDOVECTORP (a, PVEC_HASH_TABLE);
  2482 }
  2483 
  2484 INLINE struct Lisp_Hash_Table *
  2485 XHASH_TABLE (Lisp_Object a)
  2486 {
  2487   eassert (HASH_TABLE_P (a));
  2488   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Hash_Table);
  2489 }
  2490 
  2491 #define XSET_HASH_TABLE(VAR, PTR) \
  2492      (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
  2493 
  2494 /* Value is the key part of entry IDX in hash table H.  */
  2495 INLINE Lisp_Object
  2496 HASH_KEY (const struct Lisp_Hash_Table *h, ptrdiff_t idx)
  2497 {
  2498   return AREF (h->key_and_value, 2 * idx);
  2499 }
  2500 
  2501 /* Value is the value part of entry IDX in hash table H.  */
  2502 INLINE Lisp_Object
  2503 HASH_VALUE (const struct Lisp_Hash_Table *h, ptrdiff_t idx)
  2504 {
  2505   return AREF (h->key_and_value, 2 * idx + 1);
  2506 }
  2507 
  2508 /* Value is the hash code computed for entry IDX in hash table H.  */
  2509 INLINE Lisp_Object
  2510 HASH_HASH (const struct Lisp_Hash_Table *h, ptrdiff_t idx)
  2511 {
  2512   return AREF (h->hash, idx);
  2513 }
  2514 
  2515 /* Value is the size of hash table H.  */
  2516 INLINE ptrdiff_t
  2517 HASH_TABLE_SIZE (const struct Lisp_Hash_Table *h)
  2518 {
  2519   ptrdiff_t size = ASIZE (h->next);
  2520   eassume (0 < size);
  2521   return size;
  2522 }
  2523 
  2524 void hash_table_rehash (Lisp_Object);
  2525 
  2526 /* Default size for hash tables if not specified.  */
  2527 
  2528 enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
  2529 
  2530 /* Default threshold specifying when to resize a hash table.  The
  2531    value gives the ratio of current entries in the hash table and the
  2532    size of the hash table.  */
  2533 
  2534 static float const DEFAULT_REHASH_THRESHOLD = 0.8125;
  2535 
  2536 /* Default factor by which to increase the size of a hash table, minus 1.  */
  2537 
  2538 static float const DEFAULT_REHASH_SIZE = 1.5 - 1;
  2539 
  2540 /* Combine two integers X and Y for hashing.  The result might exceed
  2541    INTMASK.  */
  2542 
  2543 INLINE EMACS_UINT
  2544 sxhash_combine (EMACS_UINT x, EMACS_UINT y)
  2545 {
  2546   return (x << 4) + (x >> (EMACS_INT_WIDTH - 4)) + y;
  2547 }
  2548 
  2549 /* Hash X, returning a value in the range 0..INTMASK.  */
  2550 
  2551 INLINE EMACS_UINT
  2552 SXHASH_REDUCE (EMACS_UINT x)
  2553 {
  2554   return (x ^ x >> (EMACS_INT_WIDTH - FIXNUM_BITS)) & INTMASK;
  2555 }
  2556 
  2557 struct Lisp_Marker
  2558 {
  2559   union vectorlike_header header;
  2560 
  2561   /* This is the buffer that the marker points into, or 0 if it points nowhere.
  2562      Note: a chain of markers can contain markers pointing into different
  2563      buffers (the chain is per buffer_text rather than per buffer, so it's
  2564      shared between indirect buffers).  */
  2565   /* This is used for (other than NULL-checking):
  2566      - Fmarker_buffer
  2567      - Fset_marker: check eq(oldbuf, newbuf) to avoid unchain+rechain.
  2568      - unchain_marker: to find the list from which to unchain.
  2569      - Fkill_buffer: to only unchain the markers of current indirect buffer.
  2570      */
  2571   struct buffer *buffer;
  2572 
  2573   /* This flag is temporarily used in the functions
  2574      decode/encode_coding_object to record that the marker position
  2575      must be adjusted after the conversion.  */
  2576   bool_bf need_adjustment : 1;
  2577   /* True means normal insertion at the marker's position
  2578      leaves the marker after the inserted text.  */
  2579   bool_bf insertion_type : 1;
  2580 
  2581   /* The remaining fields are meaningless in a marker that
  2582      does not point anywhere.  */
  2583 
  2584   /* For markers that point somewhere,
  2585      this is used to chain of all the markers in a given buffer.
  2586      The chain does not preserve markers from garbage collection;
  2587      instead, markers are removed from the chain when freed by GC.  */
  2588   /* We could remove it and use an array in buffer_text instead.
  2589      That would also allow us to preserve it ordered.  */
  2590   struct Lisp_Marker *next;
  2591   /* This is the char position where the marker points.  */
  2592   ptrdiff_t charpos;
  2593   /* This is the byte position.
  2594      It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
  2595      used to implement the functionality of markers, but rather to (ab)use
  2596      markers as a cache for char<->byte mappings).  */
  2597   ptrdiff_t bytepos;
  2598 } GCALIGNED_STRUCT;
  2599 
  2600 struct Lisp_Overlay
  2601 /* An overlay's real data content is:
  2602    - plist
  2603    - buffer
  2604    - itree node
  2605    - start buffer position (field of the itree node)
  2606    - end buffer position (field of the itree node)
  2607    - insertion types of both ends (fields of the itree node).  */
  2608   {
  2609     union vectorlike_header header;
  2610     Lisp_Object plist;
  2611     struct buffer *buffer;        /* eassert (live buffer || NULL). */
  2612     struct itree_node *interval;
  2613   } GCALIGNED_STRUCT;
  2614 
  2615 struct Lisp_Misc_Ptr
  2616   {
  2617     union vectorlike_header header;
  2618     void *pointer;
  2619   } GCALIGNED_STRUCT;
  2620 
  2621 extern Lisp_Object make_misc_ptr (void *);
  2622 
  2623 /* A mint_ptr object OBJ represents a C-language pointer P efficiently.
  2624    Preferably (and typically), OBJ is a fixnum I such that
  2625    XFIXNUMPTR (I) == P, as this represents P within a single Lisp value
  2626    without requiring any auxiliary memory.  However, if P would be
  2627    damaged by being tagged as an integer and then untagged via
  2628    XFIXNUMPTR, then OBJ is a Lisp_Misc_Ptr with pointer component P.
  2629 
  2630    mint_ptr objects are efficiency hacks intended for C code.
  2631    Although xmint_ptr can be given any mint_ptr generated by non-buggy
  2632    C code, it should not be given a mint_ptr generated from Lisp code
  2633    as that would allow Lisp code to coin pointers from integers and
  2634    could lead to crashes.  To package a C pointer into a Lisp-visible
  2635    object you can put the pointer into a pseudovector instead; see
  2636    Lisp_User_Ptr for an example.  */
  2637 
  2638 INLINE Lisp_Object
  2639 make_mint_ptr (void *a)
  2640 {
  2641   Lisp_Object val = TAG_PTR (Lisp_Int0, a);
  2642   return FIXNUMP (val) && XFIXNUMPTR (val) == a ? val : make_misc_ptr (a);
  2643 }
  2644 
  2645 INLINE bool
  2646 mint_ptrp (Lisp_Object x)
  2647 {
  2648   return FIXNUMP (x) || PSEUDOVECTORP (x, PVEC_MISC_PTR);
  2649 }
  2650 
  2651 INLINE void *
  2652 xmint_pointer (Lisp_Object a)
  2653 {
  2654   eassert (mint_ptrp (a));
  2655   if (FIXNUMP (a))
  2656     return XFIXNUMPTR (a);
  2657   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Misc_Ptr)->pointer;
  2658 }
  2659 
  2660 struct Lisp_Sqlite
  2661 {
  2662   union vectorlike_header header;
  2663   void *db;
  2664   void *stmt;
  2665   char *name;
  2666   void (*finalizer) (void *);
  2667   bool eof;
  2668   bool is_statement;
  2669 } GCALIGNED_STRUCT;
  2670 
  2671 struct Lisp_User_Ptr
  2672 {
  2673   union vectorlike_header header;
  2674   void (*finalizer) (void *);
  2675   void *p;
  2676 } GCALIGNED_STRUCT;
  2677 
  2678 /* A finalizer sentinel.  */
  2679 struct Lisp_Finalizer
  2680   {
  2681     union vectorlike_header header;
  2682 
  2683     /* Call FUNCTION when the finalizer becomes unreachable, even if
  2684        FUNCTION contains a reference to the finalizer; i.e., call
  2685        FUNCTION when it is reachable _only_ through finalizers.  */
  2686     Lisp_Object function;
  2687 
  2688     /* Circular list of all active weak references.  */
  2689     struct Lisp_Finalizer *prev;
  2690     struct Lisp_Finalizer *next;
  2691   } GCALIGNED_STRUCT;
  2692 
  2693 extern struct Lisp_Finalizer finalizers;
  2694 extern struct Lisp_Finalizer doomed_finalizers;
  2695 
  2696 INLINE bool
  2697 FINALIZERP (Lisp_Object x)
  2698 {
  2699   return PSEUDOVECTORP (x, PVEC_FINALIZER);
  2700 }
  2701 
  2702 INLINE struct Lisp_Finalizer *
  2703 XFINALIZER (Lisp_Object a)
  2704 {
  2705   eassert (FINALIZERP (a));
  2706   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Finalizer);
  2707 }
  2708 
  2709 INLINE bool
  2710 MARKERP (Lisp_Object x)
  2711 {
  2712   return PSEUDOVECTORP (x, PVEC_MARKER);
  2713 }
  2714 
  2715 INLINE struct Lisp_Marker *
  2716 XMARKER (Lisp_Object a)
  2717 {
  2718   eassert (MARKERP (a));
  2719   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Marker);
  2720 }
  2721 
  2722 INLINE bool
  2723 OVERLAYP (Lisp_Object x)
  2724 {
  2725   return PSEUDOVECTORP (x, PVEC_OVERLAY);
  2726 }
  2727 
  2728 INLINE struct Lisp_Overlay *
  2729 XOVERLAY (Lisp_Object a)
  2730 {
  2731   eassert (OVERLAYP (a));
  2732   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Overlay);
  2733 }
  2734 
  2735 INLINE Lisp_Object
  2736 SYMBOL_WITH_POS_SYM (Lisp_Object a)
  2737 {
  2738   if (!SYMBOL_WITH_POS_P (a))
  2739     wrong_type_argument (Qsymbol_with_pos_p, a);
  2740   return XSYMBOL_WITH_POS (a)->sym;
  2741 }
  2742 
  2743 INLINE Lisp_Object
  2744 SYMBOL_WITH_POS_POS (Lisp_Object a)
  2745 {
  2746   if (!SYMBOL_WITH_POS_P (a))
  2747     wrong_type_argument (Qsymbol_with_pos_p, a);
  2748   return XSYMBOL_WITH_POS (a)->pos;
  2749 }
  2750 
  2751 INLINE bool
  2752 USER_PTRP (Lisp_Object x)
  2753 {
  2754   return PSEUDOVECTORP (x, PVEC_USER_PTR);
  2755 }
  2756 
  2757 INLINE struct Lisp_User_Ptr *
  2758 XUSER_PTR (Lisp_Object a)
  2759 {
  2760   eassert (USER_PTRP (a));
  2761   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_User_Ptr);
  2762 }
  2763 
  2764 INLINE bool
  2765 SQLITEP (Lisp_Object x)
  2766 {
  2767   return PSEUDOVECTORP (x, PVEC_SQLITE);
  2768 }
  2769 
  2770 INLINE bool
  2771 SQLITE (Lisp_Object a)
  2772 {
  2773   return PSEUDOVECTORP (a, PVEC_SQLITE);
  2774 }
  2775 
  2776 INLINE void
  2777 CHECK_SQLITE (Lisp_Object x)
  2778 {
  2779   CHECK_TYPE (SQLITE (x), Qsqlitep, x);
  2780 }
  2781 
  2782 INLINE struct Lisp_Sqlite *
  2783 XSQLITE (Lisp_Object a)
  2784 {
  2785   eassert (SQLITEP (a));
  2786   return XUNTAG (a, Lisp_Vectorlike, struct Lisp_Sqlite);
  2787 }
  2788 
  2789 INLINE bool
  2790 BIGNUMP (Lisp_Object x)
  2791 {
  2792   return PSEUDOVECTORP (x, PVEC_BIGNUM);
  2793 }
  2794 
  2795 INLINE bool
  2796 INTEGERP (Lisp_Object x)
  2797 {
  2798   return FIXNUMP (x) || BIGNUMP (x);
  2799 }
  2800 
  2801 /* Return a Lisp integer with value taken from N.  */
  2802 INLINE Lisp_Object
  2803 make_int (intmax_t n)
  2804 {
  2805   return FIXNUM_OVERFLOW_P (n) ? make_bigint (n) : make_fixnum (n);
  2806 }
  2807 INLINE Lisp_Object
  2808 make_uint (uintmax_t n)
  2809 {
  2810   return FIXNUM_OVERFLOW_P (n) ? make_biguint (n) : make_fixnum (n);
  2811 }
  2812 
  2813 /* Return a Lisp integer equal to the value of the C integer EXPR.  */
  2814 #define INT_TO_INTEGER(expr) \
  2815   (EXPR_SIGNED (expr) ? make_int (expr) : make_uint (expr))
  2816 
  2817 
  2818 /* Forwarding pointer to an int variable.
  2819    This is allowed only in the value cell of a symbol,
  2820    and it means that the symbol's value really lives in the
  2821    specified int variable.  */
  2822 struct Lisp_Intfwd
  2823   {
  2824     enum Lisp_Fwd_Type type;    /* = Lisp_Fwd_Int */
  2825     intmax_t *intvar;
  2826   };
  2827 
  2828 /* Boolean forwarding pointer to an int variable.
  2829    This is like Lisp_Intfwd except that the ostensible
  2830    "value" of the symbol is t if the bool variable is true,
  2831    nil if it is false.  */
  2832 struct Lisp_Boolfwd
  2833   {
  2834     enum Lisp_Fwd_Type type;    /* = Lisp_Fwd_Bool */
  2835     bool *boolvar;
  2836   };
  2837 
  2838 /* Forwarding pointer to a Lisp_Object variable.
  2839    This is allowed only in the value cell of a symbol,
  2840    and it means that the symbol's value really lives in the
  2841    specified variable.  */
  2842 struct Lisp_Objfwd
  2843   {
  2844     enum Lisp_Fwd_Type type;    /* = Lisp_Fwd_Obj */
  2845     Lisp_Object *objvar;
  2846   };
  2847 
  2848 /* Like Lisp_Objfwd except that value lives in a slot in the
  2849    current buffer.  Value is byte index of slot within buffer.  */
  2850 struct Lisp_Buffer_Objfwd
  2851   {
  2852     enum Lisp_Fwd_Type type;    /* = Lisp_Fwd_Buffer_Obj */
  2853     int offset;
  2854     /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp or Qnumberp.  */
  2855     Lisp_Object predicate;
  2856   };
  2857 
  2858 /* struct Lisp_Buffer_Local_Value is used in a symbol value cell when
  2859    the symbol has buffer-local bindings.  (Exception:
  2860    some buffer-local variables are built-in, with their values stored
  2861    in the buffer structure itself.  They are handled differently,
  2862    using struct Lisp_Buffer_Objfwd.)
  2863 
  2864    The `valcell' slot holds the variable's current value (unless `fwd'
  2865    is set).  This value is the one that corresponds to the loaded binding.
  2866    To read or set the variable, you must first make sure the right binding
  2867    is loaded; then you can access the value in (or through) `valcell'.
  2868 
  2869    `where' is the buffer for which the loaded binding was found.
  2870    If it has changed, to make sure the right binding is loaded it is
  2871    necessary to find which binding goes with the current buffer, then
  2872    load it.  To load it, first unload the previous binding.
  2873 
  2874    `local_if_set' indicates that merely setting the variable creates a
  2875    local binding for the current buffer.  Otherwise the latter, setting
  2876    the variable does not do that; only make-local-variable does that.  */
  2877 
  2878 struct Lisp_Buffer_Local_Value
  2879   {
  2880     /* True means that merely setting the variable creates a local
  2881        binding for the current buffer.  */
  2882     bool_bf local_if_set : 1;
  2883     /* True means that the binding now loaded was found.
  2884        Presumably equivalent to (defcell!=valcell).  */
  2885     bool_bf found : 1;
  2886     /* If non-NULL, a forwarding to the C var where it should also be set.  */
  2887     lispfwd fwd;        /* Should never be (Buffer|Kboard)_Objfwd.  */
  2888     /* The buffer for which the loaded binding was found.  */
  2889     Lisp_Object where;
  2890     /* A cons cell that holds the default value.  It has the form
  2891        (SYMBOL . DEFAULT-VALUE).  */
  2892     Lisp_Object defcell;
  2893     /* The cons cell from `where's parameter alist.
  2894        It always has the form (SYMBOL . VALUE)
  2895        Note that if `fwd' is non-NULL, VALUE may be out of date.
  2896        Also if the currently loaded binding is the default binding, then
  2897        this is `eq'ual to defcell.  */
  2898     Lisp_Object valcell;
  2899   };
  2900 
  2901 /* Like Lisp_Objfwd except that value lives in a slot in the
  2902    current kboard.  */
  2903 struct Lisp_Kboard_Objfwd
  2904   {
  2905     enum Lisp_Fwd_Type type;    /* = Lisp_Fwd_Kboard_Obj */
  2906     int offset;
  2907   };
  2908 
  2909 INLINE enum Lisp_Fwd_Type
  2910 XFWDTYPE (lispfwd a)
  2911 {
  2912   enum Lisp_Fwd_Type const *p = a.fwdptr;
  2913   return *p;
  2914 }
  2915 
  2916 INLINE bool
  2917 BUFFER_OBJFWDP (lispfwd a)
  2918 {
  2919   return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj;
  2920 }
  2921 
  2922 INLINE struct Lisp_Buffer_Objfwd const *
  2923 XBUFFER_OBJFWD (lispfwd a)
  2924 {
  2925   eassert (BUFFER_OBJFWDP (a));
  2926   return a.fwdptr;
  2927 }
  2928 
  2929 /* Lisp floating point type.  */
  2930 struct Lisp_Float
  2931   {
  2932     union
  2933     {
  2934       double data;
  2935       struct Lisp_Float *chain;
  2936       GCALIGNED_UNION_MEMBER
  2937     } u;
  2938   };
  2939 verify (GCALIGNED (struct Lisp_Float));
  2940 
  2941 INLINE bool
  2942 (FLOATP) (Lisp_Object x)
  2943 {
  2944   return lisp_h_FLOATP (x);
  2945 }
  2946 
  2947 INLINE struct Lisp_Float *
  2948 XFLOAT (Lisp_Object a)
  2949 {
  2950   eassert (FLOATP (a));
  2951   return XUNTAG (a, Lisp_Float, struct Lisp_Float);
  2952 }
  2953 
  2954 INLINE double
  2955 XFLOAT_DATA (Lisp_Object f)
  2956 {
  2957   return XFLOAT (f)->u.data;
  2958 }
  2959 
  2960 /* Most hosts nowadays use IEEE floating point, so they use IEC 60559
  2961    representations, have infinities and NaNs, and do not trap on
  2962    exceptions.  Define IEEE_FLOATING_POINT to 1 if this host is one of the
  2963    typical ones.  The C23 macro __STDC_IEC_60559_BFP__ (or its
  2964    obsolescent C11 counterpart __STDC_IEC_559__) is close to what is
  2965    wanted here, but is not quite right because Emacs does not require
  2966    all the features of C23 Annex F (and does not require C11 or later,
  2967    for that matter).  */
  2968 
  2969 #define IEEE_FLOATING_POINT (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
  2970                              && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
  2971 
  2972 /* Meanings of slots in a Lisp_Compiled:  */
  2973 
  2974 enum Lisp_Compiled
  2975   {
  2976     COMPILED_ARGLIST = 0,
  2977     COMPILED_BYTECODE = 1,
  2978     COMPILED_CONSTANTS = 2,
  2979     COMPILED_STACK_DEPTH = 3,
  2980     COMPILED_DOC_STRING = 4,
  2981     COMPILED_INTERACTIVE = 5
  2982   };
  2983 
  2984 /* Flag bits in a character.  These also get used in termhooks.h.
  2985    Emacs needs 22 bits for the character value itself, see MAX_CHAR,
  2986    so we shouldn't use any bits lower than 0x0400000.  */
  2987 enum char_bits
  2988   {
  2989     CHAR_ALT = 0x0400000,
  2990     CHAR_SUPER = 0x0800000,
  2991     CHAR_HYPER = 0x1000000,
  2992     CHAR_SHIFT = 0x2000000,
  2993     CHAR_CTL = 0x4000000,
  2994     CHAR_META = 0x8000000,
  2995 
  2996     CHAR_MODIFIER_MASK =
  2997       CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META,
  2998 
  2999     /* Actually, the current Emacs uses 22 bits for the character value
  3000        itself.  */
  3001     CHARACTERBITS = 22
  3002   };
  3003 
  3004 /* Data type checking.  */
  3005 
  3006 INLINE bool
  3007 FIXNATP (Lisp_Object x)
  3008 {
  3009   return FIXNUMP (x) && 0 <= XFIXNUM (x);
  3010 }
  3011 
  3012 /* Like XFIXNUM (A), but may be faster.  A must be nonnegative.  */
  3013 INLINE EMACS_INT
  3014 XFIXNAT (Lisp_Object a)
  3015 {
  3016   eassert (FIXNUMP (a));
  3017   EMACS_INT int0 = Lisp_Int0;
  3018   EMACS_INT result = USE_LSB_TAG ? XFIXNUM (a) : XLI (a) - (int0 << VALBITS);
  3019   eassume (0 <= result);
  3020   return result;
  3021 }
  3022 
  3023 INLINE bool
  3024 NUMBERP (Lisp_Object x)
  3025 {
  3026   return INTEGERP (x) || FLOATP (x);
  3027 }
  3028 
  3029 INLINE bool
  3030 RANGED_FIXNUMP (intmax_t lo, Lisp_Object x, intmax_t hi)
  3031 {
  3032   return FIXNUMP (x) && lo <= XFIXNUM (x) && XFIXNUM (x) <= hi;
  3033 }
  3034 
  3035 #define TYPE_RANGED_FIXNUMP(type, x) \
  3036   (FIXNUMP (x)                        \
  3037    && (TYPE_SIGNED (type) ? TYPE_MINIMUM (type) <= XFIXNUM (x) : 0 <= XFIXNUM (x)) \
  3038    && XFIXNUM (x) <= TYPE_MAXIMUM (type))
  3039 
  3040 INLINE bool
  3041 AUTOLOADP (Lisp_Object x)
  3042 {
  3043   return CONSP (x) && EQ (Qautoload, XCAR (x));
  3044 }
  3045 
  3046 
  3047 /* Test for specific pseudovector types.  */
  3048 
  3049 INLINE bool
  3050 WINDOW_CONFIGURATIONP (Lisp_Object a)
  3051 {
  3052   return PSEUDOVECTORP (a, PVEC_WINDOW_CONFIGURATION);
  3053 }
  3054 
  3055 INLINE bool
  3056 COMPILEDP (Lisp_Object a)
  3057 {
  3058   return PSEUDOVECTORP (a, PVEC_COMPILED);
  3059 }
  3060 
  3061 INLINE bool
  3062 FRAMEP (Lisp_Object a)
  3063 {
  3064   return PSEUDOVECTORP (a, PVEC_FRAME);
  3065 }
  3066 
  3067 INLINE bool
  3068 RECORDP (Lisp_Object a)
  3069 {
  3070   return PSEUDOVECTORP (a, PVEC_RECORD);
  3071 }
  3072 
  3073 INLINE void
  3074 CHECK_RECORD (Lisp_Object x)
  3075 {
  3076   CHECK_TYPE (RECORDP (x), Qrecordp, x);
  3077 }
  3078 
  3079 /* Test for image (image . spec)  */
  3080 INLINE bool
  3081 IMAGEP (Lisp_Object x)
  3082 {
  3083   return CONSP (x) && EQ (XCAR (x), Qimage);
  3084 }
  3085 
  3086 /* Array types.  */
  3087 INLINE bool
  3088 ARRAYP (Lisp_Object x)
  3089 {
  3090   return VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x);
  3091 }
  3092 
  3093 INLINE void
  3094 CHECK_LIST (Lisp_Object x)
  3095 {
  3096   CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x);
  3097 }
  3098 
  3099 INLINE void
  3100 CHECK_LIST_END (Lisp_Object x, Lisp_Object y)
  3101 {
  3102   CHECK_TYPE (NILP (x), Qlistp, y);
  3103 }
  3104 
  3105 INLINE void
  3106 (CHECK_FIXNUM) (Lisp_Object x)
  3107 {
  3108   lisp_h_CHECK_FIXNUM (x);
  3109 }
  3110 
  3111 INLINE void
  3112 CHECK_STRING_CAR (Lisp_Object x)
  3113 {
  3114   CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x));
  3115 }
  3116 /* This is a bit special because we always need size afterwards.  */
  3117 INLINE ptrdiff_t
  3118 CHECK_VECTOR_OR_STRING (Lisp_Object x)
  3119 {
  3120   if (VECTORP (x))
  3121     return ASIZE (x);
  3122   if (STRINGP (x))
  3123     return SCHARS (x);
  3124   wrong_type_argument (Qarrayp, x);
  3125 }
  3126 INLINE void
  3127 CHECK_ARRAY (Lisp_Object x, Lisp_Object predicate)
  3128 {
  3129   CHECK_TYPE (ARRAYP (x), predicate, x);
  3130 }
  3131 INLINE void
  3132 CHECK_FIXNAT (Lisp_Object x)
  3133 {
  3134   CHECK_TYPE (FIXNATP (x), Qwholenump, x);
  3135 }
  3136 
  3137 INLINE double
  3138 XFLOATINT (Lisp_Object n)
  3139 {
  3140   return (FIXNUMP (n) ? XFIXNUM (n)
  3141           : FLOATP (n) ? XFLOAT_DATA (n)
  3142           : bignum_to_double (n));
  3143 }
  3144 
  3145 INLINE void
  3146 CHECK_NUMBER (Lisp_Object x)
  3147 {
  3148   CHECK_TYPE (NUMBERP (x), Qnumberp, x);
  3149 }
  3150 
  3151 INLINE void
  3152 CHECK_INTEGER (Lisp_Object x)
  3153 {
  3154   CHECK_TYPE (INTEGERP (x), Qintegerp, x);
  3155 }
  3156 
  3157 INLINE void
  3158 CHECK_SUBR (Lisp_Object x)
  3159 {
  3160   CHECK_TYPE (SUBRP (x), Qsubrp, x);
  3161 }
  3162 
  3163 
  3164 /* If we're not dumping using the legacy dumper and we might be using
  3165    the portable dumper, try to bunch all the subr structures together
  3166    for more efficient dump loading.  */
  3167 #ifndef HAVE_UNEXEC
  3168 # ifdef DARWIN_OS
  3169 #  define SUBR_SECTION_ATTRIBUTE ATTRIBUTE_SECTION ("__DATA,subrs")
  3170 # else
  3171 #  define SUBR_SECTION_ATTRIBUTE ATTRIBUTE_SECTION (".subrs")
  3172 # endif
  3173 #else
  3174 # define SUBR_SECTION_ATTRIBUTE
  3175 #endif
  3176 
  3177 /* Define a built-in function for calling from Lisp.
  3178  `lname' should be the name to give the function in Lisp,
  3179     as a null-terminated C string.
  3180  `fnname' should be the name of the function in C.
  3181     By convention, it starts with F.
  3182  `sname' should be the name for the C constant structure
  3183     that records information on this function for internal use.
  3184     By convention, it should be the same as `fnname' but with S instead of F.
  3185     It's too bad that C macros can't compute this from `fnname'.
  3186  `minargs' should be a number, the minimum number of arguments allowed.
  3187  `maxargs' should be a number, the maximum number of arguments allowed,
  3188     or else MANY or UNEVALLED.
  3189     MANY means there are &rest arguments.  Here we pass a vector
  3190         of evaluated arguments in the form of an integer
  3191         number-of-arguments followed by the address of a vector of
  3192         Lisp_Objects which contains the argument values.  (We also use
  3193         this convention when calling a subr with more than 8 parameters.)
  3194     UNEVALLED means pass the list of unevaluated arguments
  3195  `intspec' says how interactive arguments are to be fetched.
  3196     If the string starts with a `(', `intspec' is evaluated and the resulting
  3197     list is the list of arguments.
  3198     If it's a string that doesn't start with `(', the value should follow
  3199     the one of the doc string for `interactive'.
  3200     A null string means call interactively with no arguments.
  3201  `doc' is documentation for the user.  */
  3202 
  3203 /* This version of DEFUN declares a function prototype with the right
  3204    arguments, so we can catch errors with maxargs at compile-time.  */
  3205 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
  3206   SUBR_SECTION_ATTRIBUTE                                            \
  3207   static union Aligned_Lisp_Subr sname =                            \
  3208      {{{ PVEC_SUBR << PSEUDOVECTOR_AREA_BITS },                     \
  3209        { .a ## maxargs = fnname },                                  \
  3210        minargs, maxargs, lname, {intspec}, lisp_h_Qnil}};           \
  3211    Lisp_Object fnname
  3212 
  3213 /* defsubr (Sname);
  3214    is how we define the symbol for function `name' at start-up time.  */
  3215 extern void defsubr (union Aligned_Lisp_Subr *);
  3216 
  3217 enum maxargs
  3218   {
  3219     MANY = -2,
  3220     UNEVALLED = -1
  3221   };
  3222 
  3223 /* Call a function F that accepts many args, passing it ARRAY's elements.  */
  3224 #define CALLMANY(f, array) (f) (ARRAYELTS (array), array)
  3225 
  3226 /* Call a function F that accepts many args, passing it the remaining args,
  3227    E.g., 'return CALLN (Fformat, fmt, text);' is less error-prone than
  3228    '{ Lisp_Object a[2]; a[0] = fmt; a[1] = text; return Fformat (2, a); }'.
  3229    CALLN requires at least one function argument (as C99 prohibits
  3230    empty initializers), and is overkill for simple usages like
  3231    'Finsert (1, &text);'.  */
  3232 #define CALLN(f, ...) CALLMANY (f, ((Lisp_Object []) {__VA_ARGS__}))
  3233 
  3234 /* Call function fn on no arguments.  */
  3235 INLINE Lisp_Object
  3236 call0 (Lisp_Object fn)
  3237 {
  3238   return Ffuncall (1, &fn);
  3239 }
  3240 
  3241 /* Call function fn with 1 argument arg1.  */
  3242 INLINE Lisp_Object
  3243 call1 (Lisp_Object fn, Lisp_Object arg1)
  3244 {
  3245   return CALLN (Ffuncall, fn, arg1);
  3246 }
  3247 
  3248 /* Call function fn with 2 arguments arg1, arg2.  */
  3249 INLINE Lisp_Object
  3250 call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
  3251 {
  3252   return CALLN (Ffuncall, fn, arg1, arg2);
  3253 }
  3254 
  3255 /* Call function fn with 3 arguments arg1, arg2, arg3.  */
  3256 INLINE Lisp_Object
  3257 call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
  3258 {
  3259   return CALLN (Ffuncall, fn, arg1, arg2, arg3);
  3260 }
  3261 
  3262 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4.  */
  3263 INLINE Lisp_Object
  3264 call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
  3265        Lisp_Object arg4)
  3266 {
  3267   return CALLN (Ffuncall, fn, arg1, arg2, arg3, arg4);
  3268 }
  3269 
  3270 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5.  */
  3271 INLINE Lisp_Object
  3272 call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
  3273        Lisp_Object arg4, Lisp_Object arg5)
  3274 {
  3275   return CALLN (Ffuncall, fn, arg1, arg2, arg3, arg4, arg5);
  3276 }
  3277 
  3278 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6.  */
  3279 INLINE Lisp_Object
  3280 call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
  3281        Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6)
  3282 {
  3283   return CALLN (Ffuncall, fn, arg1, arg2, arg3, arg4, arg5, arg6);
  3284 }
  3285 
  3286 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7.  */
  3287 INLINE Lisp_Object
  3288 call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
  3289        Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7)
  3290 {
  3291   return CALLN (Ffuncall, fn, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
  3292 }
  3293 
  3294 /* Call function fn with 8 arguments arg1, arg2, arg3, arg4, arg5,
  3295    arg6, arg7, arg8.  */
  3296 INLINE Lisp_Object
  3297 call8 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
  3298        Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7,
  3299        Lisp_Object arg8)
  3300 {
  3301   return CALLN (Ffuncall, fn, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
  3302 }
  3303 
  3304 extern void defvar_lisp (struct Lisp_Objfwd const *, char const *);
  3305 extern void defvar_lisp_nopro (struct Lisp_Objfwd const *, char const *);
  3306 extern void defvar_bool (struct Lisp_Boolfwd const *, char const *);
  3307 extern void defvar_int (struct Lisp_Intfwd const *, char const *);
  3308 extern void defvar_kboard (struct Lisp_Kboard_Objfwd const *, char const *);
  3309 
  3310 /* Macros we use to define forwarded Lisp variables.
  3311    These are used in the syms_of_FILENAME functions.
  3312 
  3313    An ordinary (not in buffer_defaults, per-buffer, or per-keyboard)
  3314    lisp variable is actually a field in `struct emacs_globals'.  The
  3315    field's name begins with "f_", which is a convention enforced by
  3316    these macros.  Each such global has a corresponding #define in
  3317    globals.h; the plain name should be used in the code.
  3318 
  3319    E.g., the global "cons_cells_consed" is declared as "int
  3320    f_cons_cells_consed" in globals.h, but there is a define:
  3321 
  3322       #define cons_cells_consed globals.f_cons_cells_consed
  3323 
  3324    All C code uses the `cons_cells_consed' name.  This is all done
  3325    this way to support indirection for multi-threaded Emacs.  */
  3326 
  3327 #define DEFVAR_LISP(lname, vname, doc)          \
  3328   do {                                          \
  3329     static struct Lisp_Objfwd const o_fwd       \
  3330       = {Lisp_Fwd_Obj, &globals.f_##vname};     \
  3331     defvar_lisp (&o_fwd, lname);                \
  3332   } while (false)
  3333 #define DEFVAR_LISP_NOPRO(lname, vname, doc)    \
  3334   do {                                          \
  3335     static struct Lisp_Objfwd const o_fwd       \
  3336       = {Lisp_Fwd_Obj, &globals.f_##vname};     \
  3337     defvar_lisp_nopro (&o_fwd, lname);          \
  3338   } while (false)
  3339 #define DEFVAR_BOOL(lname, vname, doc)          \
  3340   do {                                          \
  3341     static struct Lisp_Boolfwd const b_fwd      \
  3342       = {Lisp_Fwd_Bool, &globals.f_##vname};    \
  3343     defvar_bool (&b_fwd, lname);                \
  3344   } while (false)
  3345 #define DEFVAR_INT(lname, vname, doc)           \
  3346   do {                                          \
  3347     static struct Lisp_Intfwd const i_fwd       \
  3348       = {Lisp_Fwd_Int, &globals.f_##vname};     \
  3349     defvar_int (&i_fwd, lname);                 \
  3350   } while (false)
  3351 
  3352 #define DEFVAR_KBOARD(lname, vname, doc)                        \
  3353   do {                                                          \
  3354     static struct Lisp_Kboard_Objfwd const ko_fwd               \
  3355       = {Lisp_Fwd_Kboard_Obj, offsetof (KBOARD, vname##_)};     \
  3356     defvar_kboard (&ko_fwd, lname);                             \
  3357   } while (false)
  3358 
  3359 
  3360 /* Elisp uses multiple stacks:
  3361    - The C stack.
  3362    - The specpdl stack keeps track of backtraces, unwind-protects and
  3363      dynamic let-bindings.  It is allocated from the 'specpdl' array,
  3364      a manually managed stack.
  3365    - The handler stack keeps track of active catch tags and condition-case
  3366      handlers.  It is allocated in a manually managed stack implemented by a
  3367      doubly-linked list allocated via xmalloc and never freed.  */
  3368 
  3369 /* Structure for recording Lisp call stack for backtrace purposes.  */
  3370 
  3371 /* The special binding stack holds the outer values of variables while
  3372    they are bound by a function application or a let form, stores the
  3373    code to be executed for unwind-protect forms.
  3374 
  3375    NOTE: The specbinding union is defined here, because SPECPDL_INDEX is
  3376    used all over the place, needs to be fast, and needs to know the size of
  3377    union specbinding.  But only eval.c should access it.  */
  3378 
  3379 enum specbind_tag {
  3380   SPECPDL_UNWIND,               /* An unwind_protect function on Lisp_Object.  */
  3381   SPECPDL_UNWIND_ARRAY,         /* Likewise, on an array that needs freeing.
  3382                                    Its elements are potential Lisp_Objects.  */
  3383   SPECPDL_UNWIND_PTR,           /* Likewise, on void *.  */
  3384   SPECPDL_UNWIND_INT,           /* Likewise, on int.  */
  3385   SPECPDL_UNWIND_INTMAX,        /* Likewise, on intmax_t.  */
  3386   SPECPDL_UNWIND_EXCURSION,     /* Likewise, on an excursion.  */
  3387   SPECPDL_UNWIND_VOID,          /* Likewise, with no arg.  */
  3388   SPECPDL_BACKTRACE,            /* An element of the backtrace.  */
  3389   SPECPDL_NOP,                  /* A filler.  */
  3390 #ifdef HAVE_MODULES
  3391   SPECPDL_MODULE_RUNTIME,       /* A live module runtime.  */
  3392   SPECPDL_MODULE_ENVIRONMENT,   /* A live module environment.  */
  3393 #endif
  3394   SPECPDL_LET,                  /* A plain and simple dynamic let-binding.  */
  3395   /* Tags greater than SPECPDL_LET must be "subkinds" of LET.  */
  3396   SPECPDL_LET_LOCAL,            /* A buffer-local let-binding.  */
  3397   SPECPDL_LET_DEFAULT           /* A global binding for a localized var.  */
  3398 };
  3399 
  3400 union specbinding
  3401   {
  3402     /* Aligning similar members consistently might help efficiency slightly
  3403        (Bug#31996#25).  */
  3404     ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3405     struct {
  3406       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3407       void (*func) (Lisp_Object);
  3408       Lisp_Object arg;
  3409       EMACS_INT eval_depth;
  3410     } unwind;
  3411     struct {
  3412       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3413       ptrdiff_t nelts;
  3414       Lisp_Object *array;
  3415     } unwind_array;
  3416     struct {
  3417       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3418       void (*func) (void *);    /* Unwind function.  */
  3419       void *arg;
  3420       void (*mark) (void *);    /* GC mark function (if non-null).  */
  3421     } unwind_ptr;
  3422     struct {
  3423       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3424       void (*func) (int);
  3425       int arg;
  3426     } unwind_int;
  3427     struct {
  3428       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3429       void (*func) (intmax_t);
  3430       intmax_t arg;
  3431     } unwind_intmax;
  3432     struct {
  3433       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3434       Lisp_Object marker, window;
  3435     } unwind_excursion;
  3436     struct {
  3437       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3438       void (*func) (void);
  3439     } unwind_void;
  3440     struct {
  3441       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3442       /* `where' is not used in the case of SPECPDL_LET.  */
  3443       Lisp_Object symbol, old_value, where;
  3444     } let;
  3445     struct {
  3446       ENUM_BF (specbind_tag) kind : CHAR_BIT;
  3447       bool_bf debug_on_exit : 1;
  3448       Lisp_Object function;
  3449       Lisp_Object *args;
  3450       ptrdiff_t nargs;
  3451     } bt;
  3452   };
  3453 
  3454 /* We use 64-bit platforms as a proxy for ones with ABIs that treat
  3455    small structs efficiently.  */
  3456 #if SIZE_MAX > 0xffffffff
  3457 #define WRAP_SPECPDL_REF 1
  3458 #endif
  3459 
  3460 /* Abstract reference to a specpdl entry.
  3461    The number is always a multiple of sizeof (union specbinding).  */
  3462 #ifdef WRAP_SPECPDL_REF
  3463 /* Use a proper type for specpdl_ref if it does not make the code slower,
  3464    since the type checking is quite useful.  */
  3465 typedef struct { ptrdiff_t bytes; } specpdl_ref;
  3466 #else
  3467 typedef ptrdiff_t specpdl_ref;
  3468 #endif
  3469 
  3470 /* Internal use only.  */
  3471 INLINE specpdl_ref
  3472 wrap_specpdl_ref (ptrdiff_t bytes)
  3473 {
  3474 #ifdef WRAP_SPECPDL_REF
  3475   return (specpdl_ref){.bytes = bytes};
  3476 #else
  3477   return bytes;
  3478 #endif
  3479 }
  3480 
  3481 /* Internal use only.  */
  3482 INLINE ptrdiff_t
  3483 unwrap_specpdl_ref (specpdl_ref ref)
  3484 {
  3485 #ifdef WRAP_SPECPDL_REF
  3486   return ref.bytes;
  3487 #else
  3488   return ref;
  3489 #endif
  3490 }
  3491 
  3492 INLINE specpdl_ref
  3493 specpdl_count_to_ref (ptrdiff_t count)
  3494 {
  3495   return wrap_specpdl_ref (count * sizeof (union specbinding));
  3496 }
  3497 
  3498 INLINE ptrdiff_t
  3499 specpdl_ref_to_count (specpdl_ref ref)
  3500 {
  3501   return unwrap_specpdl_ref (ref) / sizeof (union specbinding);
  3502 }
  3503 
  3504 /* Whether two `specpdl_ref' refer to the same entry.  */
  3505 INLINE bool
  3506 specpdl_ref_eq (specpdl_ref a, specpdl_ref b)
  3507 {
  3508   return unwrap_specpdl_ref (a) == unwrap_specpdl_ref (b);
  3509 }
  3510 
  3511 /* Whether `a' refers to an earlier entry than `b'.  */
  3512 INLINE bool
  3513 specpdl_ref_lt (specpdl_ref a, specpdl_ref b)
  3514 {
  3515   return unwrap_specpdl_ref (a) < unwrap_specpdl_ref (b);
  3516 }
  3517 
  3518 INLINE bool
  3519 specpdl_ref_valid_p (specpdl_ref ref)
  3520 {
  3521   return unwrap_specpdl_ref (ref) >= 0;
  3522 }
  3523 
  3524 INLINE specpdl_ref
  3525 make_invalid_specpdl_ref (void)
  3526 {
  3527   return wrap_specpdl_ref (-1);
  3528 }
  3529 
  3530 /* Return a reference that is `delta' steps more recent than `ref'.
  3531    `delta' may be negative or zero.  */
  3532 INLINE specpdl_ref
  3533 specpdl_ref_add (specpdl_ref ref, ptrdiff_t delta)
  3534 {
  3535   return wrap_specpdl_ref (unwrap_specpdl_ref (ref)
  3536                            + delta * sizeof (union specbinding));
  3537 }
  3538 
  3539 INLINE union specbinding *
  3540 specpdl_ref_to_ptr (specpdl_ref ref)
  3541 {
  3542   return (union specbinding *)((char *)specpdl + unwrap_specpdl_ref (ref));
  3543 }
  3544 
  3545 /* Return a reference to the most recent specpdl entry.  */
  3546 INLINE specpdl_ref
  3547 SPECPDL_INDEX (void)
  3548 {
  3549   return wrap_specpdl_ref ((char *)specpdl_ptr - (char *)specpdl);
  3550 }
  3551 
  3552 INLINE bool
  3553 backtrace_debug_on_exit (union specbinding *pdl)
  3554 {
  3555   eassert (pdl->kind == SPECPDL_BACKTRACE);
  3556   return pdl->bt.debug_on_exit;
  3557 }
  3558 
  3559 void grow_specpdl_allocation (void);
  3560 
  3561 /* Grow the specpdl stack by one entry.
  3562    The caller should have already initialized the entry.
  3563    Signal an error on stack overflow.
  3564 
  3565    Make sure that there is always one unused entry past the top of the
  3566    stack, so that the just-initialized entry is safely unwound if
  3567    memory exhausted and an error is signaled here.  Also, allocate a
  3568    never-used entry just before the bottom of the stack; sometimes its
  3569    address is taken.  */
  3570 INLINE void
  3571 grow_specpdl (void)
  3572 {
  3573   specpdl_ptr++;
  3574   if (specpdl_ptr == specpdl_end)
  3575     grow_specpdl_allocation ();
  3576 }
  3577 
  3578 INLINE specpdl_ref
  3579 record_in_backtrace (Lisp_Object function, Lisp_Object *args, ptrdiff_t nargs)
  3580 {
  3581   specpdl_ref count = SPECPDL_INDEX ();
  3582 
  3583   eassert (nargs >= UNEVALLED);
  3584   specpdl_ptr->bt.kind = SPECPDL_BACKTRACE;
  3585   specpdl_ptr->bt.debug_on_exit = false;
  3586   specpdl_ptr->bt.function = function;
  3587   current_thread->stack_top = specpdl_ptr->bt.args = args;
  3588   specpdl_ptr->bt.nargs = nargs;
  3589   grow_specpdl ();
  3590 
  3591   return count;
  3592 }
  3593 
  3594 /* This structure helps implement the `catch/throw' and `condition-case/signal'
  3595    control structures.  A struct handler contains all the information needed to
  3596    restore the state of the interpreter after a non-local jump.
  3597 
  3598    Handler structures are chained together in a doubly linked list; the `next'
  3599    member points to the next outer catchtag and the `nextfree' member points in
  3600    the other direction to the next inner element (which is typically the next
  3601    free element since we mostly use it on the deepest handler).
  3602 
  3603    A call like (throw TAG VAL) searches for a catchtag whose `tag_or_ch'
  3604    member is TAG, and then unbinds to it.  The `val' member is used to
  3605    hold VAL while the stack is unwound; `val' is returned as the value
  3606    of the catch form.  If there is a handler of type CATCHER_ALL, it will
  3607    be treated as a handler for all invocations of `signal' and `throw';
  3608    in this case `val' will be set to (ERROR-SYMBOL . DATA) or (TAG . VAL),
  3609    respectively.  During stack unwinding, `nonlocal_exit' is set to
  3610    specify the type of nonlocal exit that caused the stack unwinding.
  3611 
  3612    All the other members are concerned with restoring the interpreter
  3613    state.
  3614 
  3615    Members are volatile if their values need to survive _longjmp when
  3616    a 'struct handler' is a local variable.  */
  3617 
  3618 enum handlertype { CATCHER, CONDITION_CASE, CATCHER_ALL };
  3619 
  3620 enum nonlocal_exit
  3621 {
  3622   NONLOCAL_EXIT_SIGNAL,
  3623   NONLOCAL_EXIT_THROW,
  3624 };
  3625 
  3626 struct handler
  3627 {
  3628   enum handlertype type;
  3629   Lisp_Object tag_or_ch;
  3630 
  3631   /* The next two are set by unwind_to_catch.  */
  3632   enum nonlocal_exit nonlocal_exit;
  3633   Lisp_Object val;
  3634 
  3635   struct handler *next;
  3636   struct handler *nextfree;
  3637 
  3638   /* The bytecode interpreter can have several handlers active at the same
  3639      time, so when we longjmp to one of them, it needs to know which handler
  3640      this was and what was the corresponding internal state.  This is stored
  3641      here, and when we longjmp we make sure that handlerlist points to the
  3642      proper handler.  */
  3643   Lisp_Object *bytecode_top;
  3644   int bytecode_dest;
  3645 
  3646   /* Most global vars are reset to their value via the specpdl mechanism,
  3647      but a few others are handled by storing their value here.  */
  3648   sys_jmp_buf jmp;
  3649   EMACS_INT f_lisp_eval_depth;
  3650   specpdl_ref pdlcount;
  3651   struct bc_frame *act_rec;
  3652   int poll_suppress_count;
  3653   int interrupt_input_blocked;
  3654 
  3655 #ifdef HAVE_X_WINDOWS
  3656   int x_error_handler_depth;
  3657 #endif
  3658 };
  3659 
  3660 extern Lisp_Object memory_signal_data;
  3661 
  3662 /* True if ought to quit now.  */
  3663 
  3664 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
  3665 
  3666 extern bool volatile pending_signals;
  3667 extern void process_pending_signals (void);
  3668 extern void probably_quit (void);
  3669 
  3670 /* Check quit-flag and quit if it is non-nil.  Typing C-g does not
  3671    directly cause a quit; it only sets Vquit_flag.  So the program
  3672    needs to call maybe_quit at times when it is safe to quit.  Every
  3673    loop that might run for a long time or might not exit ought to call
  3674    maybe_quit at least once, at a safe place.  Unless that is
  3675    impossible, of course.  But it is very desirable to avoid creating
  3676    loops where maybe_quit is impossible.
  3677 
  3678    If quit-flag is set to `kill-emacs' the SIGINT handler has received
  3679    a request to exit Emacs when it is safe to do.
  3680 
  3681    When not quitting, process any pending signals.  */
  3682 
  3683 INLINE void
  3684 maybe_quit (void)
  3685 {
  3686   if (!NILP (Vquit_flag) || pending_signals)
  3687     probably_quit ();
  3688 }
  3689 
  3690 /* Process a quit rarely, based on a counter COUNT, for efficiency.
  3691    "Rarely" means once per USHRT_MAX + 1 times; this is somewhat
  3692    arbitrary, but efficient.  */
  3693 
  3694 INLINE void
  3695 rarely_quit (unsigned short int count)
  3696 {
  3697   if (! count)
  3698     maybe_quit ();
  3699 }
  3700 
  3701 extern Lisp_Object Vascii_downcase_table;
  3702 extern Lisp_Object Vascii_canon_table;
  3703 
  3704 /* Call staticpro (&var) to protect static variable `var'.  */
  3705 
  3706 void staticpro (Lisp_Object const *);
  3707 
  3708 enum { NSTATICS = 2048 };
  3709 extern Lisp_Object const *staticvec[NSTATICS];
  3710 extern int staticidx;
  3711 
  3712 
  3713 /* Forward declarations for prototypes.  */
  3714 struct window;
  3715 struct frame;
  3716 
  3717 /* Define if the windowing system provides a menu bar.  */
  3718 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
  3719   || defined (HAVE_NS) || defined (USE_GTK) || defined (HAVE_HAIKU)
  3720 #define HAVE_EXT_MENU_BAR true
  3721 #endif
  3722 
  3723 /* Define if the windowing system provides a tool-bar.  */
  3724 #if defined (USE_GTK) || defined (HAVE_NS)
  3725 #define HAVE_EXT_TOOL_BAR true
  3726 #endif
  3727 
  3728 /* Return the address of vector A's element at index I.  */
  3729 
  3730 INLINE Lisp_Object *
  3731 xvector_contents_addr (Lisp_Object a, ptrdiff_t i)
  3732 {
  3733   /* This should return &XVECTOR (a)->contents[i], but that would run
  3734      afoul of GCC bug 95072.  */
  3735   void *v = XVECTOR (a);
  3736   char *p = v;
  3737   void *w = p + header_size + i * word_size;
  3738   return w;
  3739 }
  3740 
  3741 /* Return the address of vector A's elements.  */
  3742 
  3743 INLINE Lisp_Object *
  3744 xvector_contents (Lisp_Object a)
  3745 {
  3746   return xvector_contents_addr (a, 0);
  3747 }
  3748 
  3749 /* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET.  */
  3750 
  3751 INLINE void
  3752 vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object const *args,
  3753        ptrdiff_t count)
  3754 {
  3755   eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
  3756   memcpy (xvector_contents_addr (v, offset), args, count * sizeof *args);
  3757 }
  3758 
  3759 /* Functions to modify hash tables.  */
  3760 
  3761 INLINE void
  3762 set_hash_key_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
  3763 {
  3764   gc_aset (h->key_and_value, 2 * idx, val);
  3765 }
  3766 
  3767 INLINE void
  3768 set_hash_value_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
  3769 {
  3770   gc_aset (h->key_and_value, 2 * idx + 1, val);
  3771 }
  3772 
  3773 /* Use these functions to set Lisp_Object
  3774    or pointer slots of struct Lisp_Symbol.  */
  3775 
  3776 INLINE void
  3777 set_symbol_function (Lisp_Object sym, Lisp_Object function)
  3778 {
  3779   XSYMBOL (sym)->u.s.function = function;
  3780 }
  3781 
  3782 INLINE void
  3783 set_symbol_plist (Lisp_Object sym, Lisp_Object plist)
  3784 {
  3785   XSYMBOL (sym)->u.s.plist = plist;
  3786 }
  3787 
  3788 INLINE void
  3789 set_symbol_next (Lisp_Object sym, struct Lisp_Symbol *next)
  3790 {
  3791   XSYMBOL (sym)->u.s.next = next;
  3792 }
  3793 
  3794 INLINE void
  3795 make_symbol_constant (Lisp_Object sym)
  3796 {
  3797   XSYMBOL (sym)->u.s.trapped_write = SYMBOL_NOWRITE;
  3798 }
  3799 
  3800 /* Buffer-local variable access functions.  */
  3801 
  3802 INLINE bool
  3803 blv_found (struct Lisp_Buffer_Local_Value *blv)
  3804 {
  3805   eassert (blv->found == !BASE_EQ (blv->defcell, blv->valcell));
  3806   return blv->found;
  3807 }
  3808 
  3809 /* Set overlay's property list.  */
  3810 
  3811 INLINE void
  3812 set_overlay_plist (Lisp_Object overlay, Lisp_Object plist)
  3813 {
  3814   XOVERLAY (overlay)->plist = plist;
  3815 }
  3816 
  3817 /* Get text properties of S.  */
  3818 
  3819 INLINE INTERVAL
  3820 string_intervals (Lisp_Object s)
  3821 {
  3822   return XSTRING (s)->u.s.intervals;
  3823 }
  3824 
  3825 /* Set text properties of S to I.  */
  3826 
  3827 INLINE void
  3828 set_string_intervals (Lisp_Object s, INTERVAL i)
  3829 {
  3830   XSTRING (s)->u.s.intervals = i;
  3831 }
  3832 
  3833 /* Set a Lisp slot in TABLE to VAL.  Most code should use this instead
  3834    of setting slots directly.  */
  3835 
  3836 INLINE void
  3837 set_char_table_defalt (Lisp_Object table, Lisp_Object val)
  3838 {
  3839   XCHAR_TABLE (table)->defalt = val;
  3840 }
  3841 INLINE void
  3842 set_char_table_purpose (Lisp_Object table, Lisp_Object val)
  3843 {
  3844   XCHAR_TABLE (table)->purpose = val;
  3845 }
  3846 
  3847 /* Set different slots in (sub)character tables.  */
  3848 
  3849 INLINE void
  3850 set_char_table_extras (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
  3851 {
  3852   eassert (0 <= idx && idx < CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (table)));
  3853   XCHAR_TABLE (table)->extras[idx] = val;
  3854 }
  3855 
  3856 INLINE void
  3857 set_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
  3858 {
  3859   eassert (0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0));
  3860   XCHAR_TABLE (table)->contents[idx] = val;
  3861 }
  3862 
  3863 INLINE void
  3864 set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
  3865 {
  3866   XSUB_CHAR_TABLE (table)->contents[idx] = val;
  3867 }
  3868 
  3869 /* Defined in bignum.c.  This part of bignum.c's API does not require
  3870    the caller to access bignum internals; see bignum.h for that.  */
  3871 extern intmax_t bignum_to_intmax (Lisp_Object) ATTRIBUTE_CONST;
  3872 extern uintmax_t bignum_to_uintmax (Lisp_Object) ATTRIBUTE_CONST;
  3873 extern ptrdiff_t bignum_bufsize (Lisp_Object, int) ATTRIBUTE_CONST;
  3874 extern ptrdiff_t bignum_to_c_string (char *, ptrdiff_t, Lisp_Object, int);
  3875 extern Lisp_Object bignum_to_string (Lisp_Object, int);
  3876 extern Lisp_Object make_bignum_str (char const *, int);
  3877 extern Lisp_Object make_neg_biguint (uintmax_t);
  3878 extern Lisp_Object double_to_integer (double);
  3879 
  3880 /* Convert the integer NUM to *N.  Return true if successful, false
  3881    (possibly setting *N) otherwise.  */
  3882 INLINE bool
  3883 integer_to_intmax (Lisp_Object num, intmax_t *n)
  3884 {
  3885   if (FIXNUMP (num))
  3886     {
  3887       *n = XFIXNUM (num);
  3888       return true;
  3889     }
  3890   else
  3891     {
  3892       intmax_t i = bignum_to_intmax (num);
  3893       *n = i;
  3894       return i != 0;
  3895     }
  3896 }
  3897 INLINE bool
  3898 integer_to_uintmax (Lisp_Object num, uintmax_t *n)
  3899 {
  3900   if (FIXNUMP (num))
  3901     {
  3902       *n = XFIXNUM (num);
  3903       return 0 <= XFIXNUM (num);
  3904     }
  3905   else
  3906     {
  3907       uintmax_t i = bignum_to_uintmax (num);
  3908       *n = i;
  3909       return i != 0;
  3910     }
  3911 }
  3912 
  3913 /* Return floor (log2 (N)) as an int, where 0 < N <= ULLONG_MAX.  */
  3914 INLINE int
  3915 elogb (unsigned long long int n)
  3916 {
  3917   return ULLONG_WIDTH - 1 - count_leading_zeros_ll (n);
  3918 }
  3919 
  3920 /* A modification count.  These are wide enough, and incremented
  3921    rarely enough, so that they should never overflow a 60-bit counter
  3922    in practice, and the code below assumes this so a compiler can
  3923    generate better code if EMACS_INT is 64 bits.  */
  3924 typedef intmax_t modiff_count;
  3925 
  3926 INLINE modiff_count
  3927 modiff_incr (modiff_count *a, ptrdiff_t len)
  3928 {
  3929   modiff_count a0 = *a;
  3930   /* Increase the counter more for a large modification and less for a
  3931      small modification.  Increase it logarithmically to avoid
  3932      increasing it too much.  */
  3933   verify (PTRDIFF_MAX <= ULLONG_MAX);
  3934   int incr = len == 0 ? 1 : elogb (len) + 1;
  3935   bool modiff_overflow = ckd_add (a, a0, incr);
  3936   eassert (!modiff_overflow && *a >> 30 >> 30 == 0);
  3937   return a0;
  3938 }
  3939 
  3940 INLINE Lisp_Object
  3941 modiff_to_integer (modiff_count a)
  3942 {
  3943   eassume (0 <= a && a >> 30 >> 30 == 0);
  3944   return make_int (a);
  3945 }
  3946 
  3947 /* Defined in data.c.  */
  3948 extern AVOID wrong_choice (Lisp_Object, Lisp_Object);
  3949 extern void notify_variable_watchers (Lisp_Object, Lisp_Object,
  3950                                       Lisp_Object, Lisp_Object);
  3951 extern Lisp_Object indirect_function (Lisp_Object);
  3952 extern Lisp_Object find_symbol_value (Lisp_Object);
  3953 enum Arith_Comparison {
  3954   ARITH_EQUAL,
  3955   ARITH_NOTEQUAL,
  3956   ARITH_LESS,
  3957   ARITH_GRTR,
  3958   ARITH_LESS_OR_EQUAL,
  3959   ARITH_GRTR_OR_EQUAL
  3960 };
  3961 extern Lisp_Object arithcompare (Lisp_Object num1, Lisp_Object num2,
  3962                                  enum Arith_Comparison comparison);
  3963 
  3964 /* Convert the Emacs representation CONS back to an integer of type
  3965    TYPE, storing the result the variable VAR.  Signal an error if CONS
  3966    is not a valid representation or is out of range for TYPE.  */
  3967 #define CONS_TO_INTEGER(cons, type, var)                                \
  3968  (TYPE_SIGNED (type)                                                    \
  3969   ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
  3970   : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
  3971 extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
  3972 extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
  3973 
  3974 extern AVOID args_out_of_range (Lisp_Object, Lisp_Object);
  3975 extern AVOID circular_list (Lisp_Object);
  3976 extern Lisp_Object do_symval_forwarding (lispfwd);
  3977 enum Set_Internal_Bind {
  3978   SET_INTERNAL_SET,
  3979   SET_INTERNAL_BIND,
  3980   SET_INTERNAL_UNBIND,
  3981   SET_INTERNAL_THREAD_SWITCH
  3982 };
  3983 extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object,
  3984                           enum Set_Internal_Bind);
  3985 extern void set_default_internal (Lisp_Object, Lisp_Object,
  3986                                   enum Set_Internal_Bind bindflag);
  3987 extern Lisp_Object expt_integer (Lisp_Object, Lisp_Object);
  3988 extern void syms_of_data (void);
  3989 extern void swap_in_global_binding (struct Lisp_Symbol *);
  3990 
  3991 /* Defined in cmds.c */
  3992 extern void syms_of_cmds (void);
  3993 
  3994 /* Defined in coding.c.  */
  3995 extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
  3996                                          ptrdiff_t, bool, bool, Lisp_Object);
  3997 extern void init_coding (void);
  3998 extern void init_coding_once (void);
  3999 extern void syms_of_coding (void);
  4000 extern bool string_ascii_p (Lisp_Object);
  4001 
  4002 /* Defined in character.c.  */
  4003 extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
  4004 extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
  4005 extern void syms_of_character (void);
  4006 
  4007 /* Defined in charset.c.  */
  4008 extern void init_charset (void);
  4009 extern void init_charset_once (void);
  4010 extern void syms_of_charset (void);
  4011 /* Structure forward declarations.  */
  4012 struct charset;
  4013 
  4014 /* Defined in syntax.c.  */
  4015 extern void init_syntax_once (void);
  4016 extern void syms_of_syntax (void);
  4017 
  4018 /* Defined in fns.c.  */
  4019 enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
  4020 extern ptrdiff_t list_length (Lisp_Object);
  4021 extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
  4022 extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
  4023 extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool);
  4024 extern void hexbuf_digest (char *, void const *, int);
  4025 extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *);
  4026 EMACS_UINT hash_string (char const *, ptrdiff_t);
  4027 EMACS_UINT sxhash (Lisp_Object);
  4028 Lisp_Object hashfn_user_defined (Lisp_Object, struct Lisp_Hash_Table *);
  4029 Lisp_Object make_hash_table (struct hash_table_test, EMACS_INT, float, float,
  4030                              Lisp_Object, bool);
  4031 ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object *);
  4032 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
  4033                     Lisp_Object);
  4034 void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object);
  4035 extern struct hash_table_test const hashtest_eq, hashtest_eql, hashtest_equal;
  4036 extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
  4037                                ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
  4038 extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
  4039                                    ptrdiff_t, ptrdiff_t);
  4040 extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);
  4041 extern Lisp_Object merge_c (Lisp_Object, Lisp_Object, bool (*) (Lisp_Object, Lisp_Object));
  4042 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
  4043 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
  4044 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
  4045 extern bool equal_no_quit (Lisp_Object, Lisp_Object);
  4046 extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
  4047 extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
  4048 extern Lisp_Object assq_no_signal (Lisp_Object, Lisp_Object);
  4049 extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
  4050 extern void clear_string_char_byte_cache (void);
  4051 extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
  4052 extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
  4053 extern Lisp_Object string_to_multibyte (Lisp_Object);
  4054 extern Lisp_Object string_make_unibyte (Lisp_Object);
  4055 extern Lisp_Object plist_get (Lisp_Object plist, Lisp_Object prop);
  4056 extern Lisp_Object plist_put (Lisp_Object plist, Lisp_Object prop,
  4057                               Lisp_Object val);
  4058 extern Lisp_Object plist_member (Lisp_Object plist, Lisp_Object prop);
  4059 extern void syms_of_fns (void);
  4060 
  4061 /* Defined in sort.c  */
  4062 extern void tim_sort (Lisp_Object, Lisp_Object *, const ptrdiff_t);
  4063 
  4064 /* Defined in floatfns.c.  */
  4065 verify (FLT_RADIX == 2 || FLT_RADIX == 16);
  4066 enum { LOG2_FLT_RADIX = FLT_RADIX == 2 ? 1 : 4 };
  4067 int double_integer_scale (double);
  4068 #ifndef HAVE_TRUNC
  4069 extern double trunc (double);
  4070 #endif
  4071 extern Lisp_Object fmod_float (Lisp_Object x, Lisp_Object y);
  4072 extern void syms_of_floatfns (void);
  4073 
  4074 /* Defined in fringe.c.  */
  4075 extern void syms_of_fringe (void);
  4076 extern void init_fringe (void);
  4077 #ifdef HAVE_WINDOW_SYSTEM
  4078 extern void mark_fringe_data (void);
  4079 extern void init_fringe_once (void);
  4080 #endif /* HAVE_WINDOW_SYSTEM */
  4081 
  4082 /* Defined in image.c.  */
  4083 extern int x_bitmap_mask (struct frame *, ptrdiff_t);
  4084 extern void syms_of_image (void);
  4085 
  4086 #ifdef HAVE_JSON
  4087 /* Defined in json.c.  */
  4088 extern void init_json (void);
  4089 extern void syms_of_json (void);
  4090 #endif
  4091 
  4092 /* Defined in insdel.c.  */
  4093 extern void move_gap_both (ptrdiff_t, ptrdiff_t);
  4094 extern AVOID buffer_overflow (void);
  4095 extern void make_gap (ptrdiff_t);
  4096 extern void make_gap_1 (struct buffer *, ptrdiff_t);
  4097 extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
  4098                             ptrdiff_t, bool, bool);
  4099 extern int count_combining_before (const unsigned char *,
  4100                                    ptrdiff_t, ptrdiff_t, ptrdiff_t);
  4101 extern int count_combining_after (const unsigned char *,
  4102                                   ptrdiff_t, ptrdiff_t, ptrdiff_t);
  4103 extern void insert (const char *, ptrdiff_t);
  4104 extern void insert_and_inherit (const char *, ptrdiff_t);
  4105 extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
  4106                            bool, bool, bool);
  4107 extern void insert_from_gap_1 (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
  4108 extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
  4109 extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
  4110                                 ptrdiff_t, ptrdiff_t, bool);
  4111 extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool);
  4112 extern void insert_char (int);
  4113 extern void insert_string (const char *);
  4114 extern void insert_before_markers (const char *, ptrdiff_t);
  4115 extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
  4116 extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
  4117                                                ptrdiff_t, ptrdiff_t,
  4118                                                ptrdiff_t, bool);
  4119 extern void del_range (ptrdiff_t, ptrdiff_t);
  4120 extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool);
  4121 extern void del_range_byte (ptrdiff_t, ptrdiff_t);
  4122 extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
  4123 extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
  4124                                 ptrdiff_t, ptrdiff_t, bool);
  4125 extern int safe_del_range (ptrdiff_t, ptrdiff_t);
  4126 extern void modify_text (ptrdiff_t, ptrdiff_t);
  4127 extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
  4128 extern void prepare_to_modify_buffer_1 (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
  4129 extern void invalidate_buffer_caches (struct buffer *, ptrdiff_t, ptrdiff_t);
  4130 extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
  4131 extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
  4132                                  ptrdiff_t, ptrdiff_t);
  4133 extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
  4134                                        ptrdiff_t, ptrdiff_t);
  4135 extern void adjust_markers_bytepos (ptrdiff_t, ptrdiff_t,
  4136                                     ptrdiff_t, ptrdiff_t, int);
  4137 extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool,
  4138                            bool, bool, bool);
  4139 extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
  4140                              const char *, ptrdiff_t, ptrdiff_t, bool);
  4141 extern void syms_of_insdel (void);
  4142 
  4143 /* Defined in dispnew.c.  */
  4144 #ifdef PROFILING
  4145 _Noreturn void __executable_start (void);
  4146 #endif
  4147 extern Lisp_Object Vwindow_system;
  4148 extern Lisp_Object sit_for (Lisp_Object, bool, int);
  4149 
  4150 /* Defined in xdisp.c.  */
  4151 extern bool noninteractive_need_newline;
  4152 extern Lisp_Object echo_area_buffer[2];
  4153 extern void add_to_log (char const *, ...);
  4154 extern void vadd_to_log (char const *, va_list);
  4155 extern void check_message_stack (void);
  4156 extern void clear_message_stack (void);
  4157 extern void setup_echo_area_for_printing (bool);
  4158 extern bool push_message (void);
  4159 extern void pop_message_unwind (void);
  4160 extern Lisp_Object restore_message_unwind (Lisp_Object);
  4161 extern void restore_message (void);
  4162 extern Lisp_Object current_message (void);
  4163 extern void clear_message (bool, bool);
  4164 extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
  4165 extern void message1 (const char *);
  4166 extern void message1_nolog (const char *);
  4167 extern void message3 (Lisp_Object);
  4168 extern void message3_nolog (Lisp_Object);
  4169 extern void message_dolog (const char *, ptrdiff_t, bool, bool);
  4170 extern void message_with_string (const char *, Lisp_Object, bool);
  4171 extern void message_log_maybe_newline (void);
  4172 extern void update_echo_area (void);
  4173 extern void truncate_echo_area (ptrdiff_t);
  4174 extern void redisplay (void);
  4175 extern ptrdiff_t count_lines (ptrdiff_t start_byte, ptrdiff_t end_byte);
  4176 
  4177 void set_frame_cursor_types (struct frame *, Lisp_Object);
  4178 extern void syms_of_xdisp (void);
  4179 extern void init_xdisp (void);
  4180 extern Lisp_Object safe_eval (Lisp_Object);
  4181 extern bool pos_visible_p (struct window *, ptrdiff_t, int *,
  4182                            int *, int *, int *, int *, int *);
  4183 
  4184 /* Defined in sqlite.c.  */
  4185 extern void syms_of_sqlite (void);
  4186 
  4187 /* Defined in xsettings.c.  */
  4188 extern void syms_of_xsettings (void);
  4189 
  4190 /* Defined in vm-limit.c.  */
  4191 extern void memory_warnings (void *, void (*warnfun) (const char *));
  4192 
  4193 /* Defined in character.c.  */
  4194 extern void parse_str_as_multibyte (const unsigned char *, ptrdiff_t,
  4195                                     ptrdiff_t *, ptrdiff_t *);
  4196 
  4197 /* Defined in alloc.c.  */
  4198 extern void *my_heap_start (void);
  4199 extern void check_pure_size (void);
  4200 unsigned char *resize_string_data (Lisp_Object, ptrdiff_t, int, int);
  4201 extern void malloc_warning (const char *);
  4202 extern AVOID memory_full (size_t);
  4203 extern AVOID buffer_memory_full (ptrdiff_t);
  4204 extern bool survives_gc_p (Lisp_Object);
  4205 extern void mark_object (Lisp_Object);
  4206 extern void mark_objects (Lisp_Object *, ptrdiff_t);
  4207 #if defined REL_ALLOC && !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
  4208 extern void refill_memory_reserve (void);
  4209 #endif
  4210 extern void alloc_unexec_pre (void);
  4211 extern void alloc_unexec_post (void);
  4212 extern void mark_c_stack (char const *, char const *);
  4213 extern void flush_stack_call_func1 (void (*func) (void *arg), void *arg);
  4214 extern void mark_memory (void const *start, void const *end);
  4215 
  4216 /* Force callee-saved registers and register windows onto the stack,
  4217    so that conservative garbage collection can see their values.  */
  4218 #ifndef HAVE___BUILTIN_UNWIND_INIT
  4219 # ifdef __sparc__
  4220    /* This trick flushes the register windows so that all the state of
  4221       the process is contained in the stack.
  4222       FreeBSD does not have a ta 3 handler, so handle it specially.
  4223       FIXME: Code in the Boehm GC suggests flushing (with 'flushrs') is
  4224       needed on ia64 too.  See mach_dep.c, where it also says inline
  4225       assembler doesn't work with relevant proprietary compilers.  */
  4226 #  if defined __sparc64__ && defined __FreeBSD__
  4227 #   define __builtin_unwind_init() asm ("flushw")
  4228 #  else
  4229 #   define __builtin_unwind_init() asm ("ta 3")
  4230 #  endif
  4231 # else
  4232 #  define __builtin_unwind_init() ((void) 0)
  4233 # endif
  4234 #endif
  4235 INLINE void
  4236 flush_stack_call_func (void (*func) (void *arg), void *arg)
  4237 {
  4238   __builtin_unwind_init ();
  4239   flush_stack_call_func1 (func, arg);
  4240 }
  4241 
  4242 extern void garbage_collect (void);
  4243 extern void maybe_garbage_collect (void);
  4244 extern bool maybe_garbage_collect_eagerly (EMACS_INT factor);
  4245 extern const char *pending_malloc_warning;
  4246 extern Lisp_Object zero_vector;
  4247 extern EMACS_INT consing_until_gc;
  4248 #ifdef HAVE_PDUMPER
  4249 extern int number_finalizers_run;
  4250 #endif
  4251 extern Lisp_Object list1 (Lisp_Object);
  4252 extern Lisp_Object list2 (Lisp_Object, Lisp_Object);
  4253 extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object);
  4254 extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  4255 extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
  4256                           Lisp_Object);
  4257 extern Lisp_Object listn (ptrdiff_t, Lisp_Object, ...);
  4258 extern Lisp_Object pure_listn (ptrdiff_t, Lisp_Object, ...);
  4259 #define list(...) \
  4260   listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__)
  4261 #define pure_list(...) \
  4262   pure_listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__)
  4263 
  4264 enum gc_root_type
  4265 {
  4266   GC_ROOT_STATICPRO,
  4267   GC_ROOT_BUFFER_LOCAL_DEFAULT,
  4268   GC_ROOT_BUFFER_LOCAL_NAME,
  4269   GC_ROOT_C_SYMBOL
  4270 };
  4271 
  4272 struct gc_root_visitor
  4273 {
  4274   void (*visit) (Lisp_Object const *, enum gc_root_type, void *);
  4275   void *data;
  4276 };
  4277 extern void visit_static_gc_roots (struct gc_root_visitor visitor);
  4278 
  4279 /* Build a frequently used 1/2/3/4-integer lists.  */
  4280 
  4281 INLINE Lisp_Object
  4282 list1i (intmax_t a)
  4283 {
  4284   return list1 (make_int (a));
  4285 }
  4286 
  4287 INLINE Lisp_Object
  4288 list2i (intmax_t a, intmax_t b)
  4289 {
  4290   return list2 (make_int (a), make_int (b));
  4291 }
  4292 
  4293 INLINE Lisp_Object
  4294 list3i (intmax_t a, intmax_t b, intmax_t c)
  4295 {
  4296   return list3 (make_int (a), make_int (b), make_int (c));
  4297 }
  4298 
  4299 INLINE Lisp_Object
  4300 list4i (intmax_t a, intmax_t b, intmax_t c, intmax_t d)
  4301 {
  4302   return list4 (make_int (a), make_int (b), make_int (c), make_int (d));
  4303 }
  4304 
  4305 extern Lisp_Object make_uninit_bool_vector (EMACS_INT);
  4306 extern Lisp_Object bool_vector_fill (Lisp_Object, Lisp_Object);
  4307 extern AVOID string_overflow (void);
  4308 extern Lisp_Object make_string (const char *, ptrdiff_t);
  4309 extern Lisp_Object make_formatted_string (char *, const char *, ...)
  4310   ATTRIBUTE_FORMAT_PRINTF (2, 3);
  4311 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
  4312 extern ptrdiff_t vectorlike_nbytes (const union vectorlike_header *hdr);
  4313 
  4314 INLINE ptrdiff_t
  4315 vector_nbytes (const struct Lisp_Vector *v)
  4316 {
  4317   return vectorlike_nbytes (&v->header);
  4318 }
  4319 
  4320 /* Make unibyte string from C string when the length isn't known.  */
  4321 
  4322 INLINE Lisp_Object
  4323 build_unibyte_string (const char *str)
  4324 {
  4325   return make_unibyte_string (str, strlen (str));
  4326 }
  4327 
  4328 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
  4329 extern Lisp_Object make_event_array (ptrdiff_t, Lisp_Object *);
  4330 extern Lisp_Object make_uninit_string (EMACS_INT);
  4331 extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
  4332 extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
  4333 extern Lisp_Object make_specified_string (const char *,
  4334                                           ptrdiff_t, ptrdiff_t, bool);
  4335 extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, bool);
  4336 extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
  4337 extern void pin_string (Lisp_Object string);
  4338 
  4339 /* Make a string allocated in pure space, use STR as string data.  */
  4340 
  4341 INLINE Lisp_Object
  4342 build_pure_c_string (const char *str)
  4343 {
  4344   return make_pure_c_string (str, strlen (str));
  4345 }
  4346 
  4347 /* Make a string from the data at STR, treating it as multibyte if the
  4348    data warrants.  */
  4349 
  4350 INLINE Lisp_Object
  4351 build_string (const char *str)
  4352 {
  4353   return make_string (str, strlen (str));
  4354 }
  4355 
  4356 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
  4357 extern Lisp_Object make_vector (ptrdiff_t, Lisp_Object);
  4358 extern struct Lisp_Vector *allocate_nil_vector (ptrdiff_t)
  4359   ATTRIBUTE_RETURNS_NONNULL;
  4360 
  4361 /* Make an uninitialized vector for SIZE objects.  NOTE: you must
  4362    be sure that GC cannot happen until the vector is completely
  4363    initialized.  E.g. the following code is likely to crash:
  4364 
  4365    v = make_uninit_vector (3);
  4366    ASET (v, 0, obj0);
  4367    ASET (v, 1, Ffunction_can_gc ());
  4368    ASET (v, 2, obj1);
  4369 
  4370    allocate_vector has a similar problem.  */
  4371 
  4372 extern struct Lisp_Vector *allocate_vector (ptrdiff_t)
  4373   ATTRIBUTE_RETURNS_NONNULL;
  4374 
  4375 INLINE Lisp_Object
  4376 make_uninit_vector (ptrdiff_t size)
  4377 {
  4378   return make_lisp_ptr (allocate_vector (size), Lisp_Vectorlike);
  4379 }
  4380 
  4381 /* Like above, but special for sub char-tables.  */
  4382 
  4383 INLINE Lisp_Object
  4384 make_uninit_sub_char_table (int depth, int min_char)
  4385 {
  4386   int slots = SUB_CHAR_TABLE_OFFSET + chartab_size[depth];
  4387   Lisp_Object v = make_uninit_vector (slots);
  4388 
  4389   XSETPVECTYPE (XVECTOR (v), PVEC_SUB_CHAR_TABLE);
  4390   XSUB_CHAR_TABLE (v)->depth = depth;
  4391   XSUB_CHAR_TABLE (v)->min_char = min_char;
  4392   return v;
  4393 }
  4394 
  4395 /* Make a vector of SIZE nils - faster than make_vector (size, Qnil)
  4396    if the OS already cleared the new memory.  */
  4397 
  4398 INLINE Lisp_Object
  4399 make_nil_vector (ptrdiff_t size)
  4400 {
  4401   return make_lisp_ptr (allocate_nil_vector (size), Lisp_Vectorlike);
  4402 }
  4403 
  4404 extern struct Lisp_Vector *allocate_pseudovector (int, int, int,
  4405                                                   enum pvec_type)
  4406   ATTRIBUTE_RETURNS_NONNULL;
  4407 
  4408 /* Allocate uninitialized pseudovector with no Lisp_Object slots.  */
  4409 
  4410 #define ALLOCATE_PLAIN_PSEUDOVECTOR(type, tag) \
  4411   ((type *) allocate_pseudovector (VECSIZE (type), 0, 0, tag))
  4412 
  4413 /* Allocate partially initialized pseudovector where all Lisp_Object
  4414    slots are set to Qnil but the rest (if any) is left uninitialized.  */
  4415 
  4416 #define ALLOCATE_PSEUDOVECTOR(type, field, tag)                        \
  4417   ((type *) allocate_pseudovector (VECSIZE (type),                     \
  4418                                    PSEUDOVECSIZE (type, field),        \
  4419                                    PSEUDOVECSIZE (type, field), tag))
  4420 
  4421 /* Allocate fully initialized pseudovector where all Lisp_Object
  4422    slots are set to Qnil and the rest (if any) is zeroed.  */
  4423 
  4424 #define ALLOCATE_ZEROED_PSEUDOVECTOR(type, field, tag)                 \
  4425   ((type *) allocate_pseudovector (VECSIZE (type),                     \
  4426                                    PSEUDOVECSIZE (type, field),        \
  4427                                    VECSIZE (type), tag))
  4428 
  4429 extern bool gc_in_progress;
  4430 extern Lisp_Object make_float (double);
  4431 extern void display_malloc_warning (void);
  4432 extern specpdl_ref inhibit_garbage_collection (void);
  4433 extern Lisp_Object build_symbol_with_pos (Lisp_Object, Lisp_Object);
  4434 extern void free_cons (struct Lisp_Cons *);
  4435 extern void init_alloc_once (void);
  4436 extern void init_alloc (void);
  4437 extern void syms_of_alloc (void);
  4438 extern struct buffer *allocate_buffer (void) ATTRIBUTE_RETURNS_NONNULL;
  4439 extern int valid_lisp_object_p (Lisp_Object);
  4440 
  4441 /* Defined in gmalloc.c.  */
  4442 #if !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC && !defined SYSTEM_MALLOC
  4443 extern size_t __malloc_extra_blocks;
  4444 #endif
  4445 #if !HAVE_DECL_ALIGNED_ALLOC
  4446 extern void *aligned_alloc (size_t, size_t) ATTRIBUTE_MALLOC_SIZE ((2));
  4447 #endif
  4448 extern void malloc_enable_thread (void);
  4449 
  4450 #ifdef REL_ALLOC
  4451 /* Defined in ralloc.c.  */
  4452 extern void *r_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
  4453 extern void r_alloc_free (void **);
  4454 extern void *r_re_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
  4455 extern void r_alloc_reset_variable (void **, void **);
  4456 extern void r_alloc_inhibit_buffer_relocation (int);
  4457 #endif
  4458 
  4459 /* Defined in chartab.c.  */
  4460 extern Lisp_Object copy_char_table (Lisp_Object);
  4461 extern Lisp_Object char_table_ref_and_range (Lisp_Object, int,
  4462                                              int *, int *);
  4463 extern void char_table_set_range (Lisp_Object, int, int, Lisp_Object);
  4464 extern void map_char_table (void (*) (Lisp_Object, Lisp_Object,
  4465                             Lisp_Object),
  4466                             Lisp_Object, Lisp_Object, Lisp_Object);
  4467 extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object),
  4468                                         Lisp_Object, Lisp_Object,
  4469                                         Lisp_Object, struct charset *,
  4470                                         unsigned, unsigned);
  4471 extern Lisp_Object uniprop_table (Lisp_Object);
  4472 extern Lisp_Object get_unicode_property (Lisp_Object, int);
  4473 extern void syms_of_chartab (void);
  4474 
  4475 /* Defined in print.c.  */
  4476 extern Lisp_Object Vprin1_to_string_buffer;
  4477 extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
  4478 extern void temp_output_buffer_setup (const char *);
  4479 extern int print_level;
  4480 extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
  4481                                  Lisp_Object);
  4482 extern Lisp_Object internal_with_output_to_temp_buffer
  4483         (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
  4484 #define FLOAT_TO_STRING_BUFSIZE 350
  4485 extern int float_to_string (char *, double);
  4486 extern void init_print_once (void);
  4487 extern void syms_of_print (void);
  4488 
  4489 /* Defined in doprnt.c.  */
  4490 extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
  4491                          va_list);
  4492 extern ptrdiff_t esprintf (char *, char const *, ...)
  4493   ATTRIBUTE_FORMAT_PRINTF (2, 3);
  4494 extern ptrdiff_t exprintf (char **, ptrdiff_t *, char *, ptrdiff_t,
  4495                            char const *, ...)
  4496   ATTRIBUTE_FORMAT_PRINTF (5, 6);
  4497 extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char *, ptrdiff_t,
  4498                             char const *, va_list)
  4499   ATTRIBUTE_FORMAT_PRINTF (5, 0);
  4500 
  4501 /* Defined in lread.c.  */
  4502 extern Lisp_Object check_obarray (Lisp_Object);
  4503 extern Lisp_Object intern_1 (const char *, ptrdiff_t);
  4504 extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t);
  4505 extern Lisp_Object intern_driver (Lisp_Object, Lisp_Object, Lisp_Object);
  4506 extern void init_symbol (Lisp_Object, Lisp_Object);
  4507 extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
  4508 INLINE void
  4509 LOADHIST_ATTACH (Lisp_Object x)
  4510 {
  4511   if (initialized)
  4512     Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
  4513 }
  4514 extern bool suffix_p (Lisp_Object, const char *);
  4515 extern Lisp_Object save_match_data_load (Lisp_Object, Lisp_Object, Lisp_Object,
  4516                                          Lisp_Object, Lisp_Object);
  4517 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
  4518                   Lisp_Object *, Lisp_Object, bool, bool,
  4519                   void **);
  4520 enum { S2N_IGNORE_TRAILING = 1 };
  4521 extern Lisp_Object string_to_number (char const *, int, ptrdiff_t *);
  4522 extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
  4523                          Lisp_Object);
  4524 extern void dir_warning (const char *, Lisp_Object);
  4525 extern void init_obarray_once (void);
  4526 extern void init_lread (void);
  4527 extern void syms_of_lread (void);
  4528 extern void mark_lread (void);
  4529 
  4530 INLINE Lisp_Object
  4531 intern (const char *str)
  4532 {
  4533   return intern_1 (str, strlen (str));
  4534 }
  4535 
  4536 INLINE Lisp_Object
  4537 intern_c_string (const char *str)
  4538 {
  4539   return intern_c_string_1 (str, strlen (str));
  4540 }
  4541 
  4542 /* Defined in eval.c.  */
  4543 extern Lisp_Object Vautoload_queue;
  4544 extern Lisp_Object Vrun_hooks;
  4545 extern Lisp_Object Vsignaling_function;
  4546 extern Lisp_Object inhibit_lisp_code;
  4547 extern bool signal_quit_p (Lisp_Object);
  4548 extern bool backtrace_yet;
  4549 
  4550 /* To run a normal hook, use the appropriate function from the list below.
  4551    The calling convention:
  4552 
  4553    if (!NILP (Vrun_hooks))
  4554      call1 (Vrun_hooks, Qmy_funny_hook);
  4555 
  4556    should no longer be used.  */
  4557 extern void run_hook (Lisp_Object);
  4558 extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
  4559 extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
  4560                                        Lisp_Object (*funcall)
  4561                                        (ptrdiff_t nargs, Lisp_Object *args));
  4562 extern Lisp_Object quit (void);
  4563 INLINE AVOID
  4564 xsignal (Lisp_Object error_symbol, Lisp_Object data)
  4565 {
  4566   Fsignal (error_symbol, data);
  4567 }
  4568 extern AVOID xsignal0 (Lisp_Object);
  4569 extern AVOID xsignal1 (Lisp_Object, Lisp_Object);
  4570 extern AVOID xsignal2 (Lisp_Object, Lisp_Object, Lisp_Object);
  4571 extern AVOID xsignal3 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  4572 extern AVOID signal_error (const char *, Lisp_Object);
  4573 extern AVOID overflow_error (void);
  4574 extern bool FUNCTIONP (Lisp_Object);
  4575 extern Lisp_Object funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *arg_vector);
  4576 extern Lisp_Object eval_sub (Lisp_Object form);
  4577 extern Lisp_Object apply1 (Lisp_Object, Lisp_Object);
  4578 extern Lisp_Object internal_catch (Lisp_Object, Lisp_Object (*) (Lisp_Object), Lisp_Object);
  4579 extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_Object);
  4580 extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
  4581 extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
  4582 extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
  4583 extern Lisp_Object internal_condition_case_n
  4584     (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *,
  4585      Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *));
  4586 extern Lisp_Object internal_catch_all (Lisp_Object (*) (void *), void *, Lisp_Object (*) (enum nonlocal_exit, Lisp_Object));
  4587 extern struct handler *push_handler (Lisp_Object, enum handlertype)
  4588   ATTRIBUTE_RETURNS_NONNULL;
  4589 extern struct handler *push_handler_nosignal (Lisp_Object, enum handlertype);
  4590 extern void specbind (Lisp_Object, Lisp_Object);
  4591 extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object);
  4592 extern void record_unwind_protect_array (Lisp_Object *, ptrdiff_t);
  4593 extern void record_unwind_protect_ptr (void (*) (void *), void *);
  4594 extern void record_unwind_protect_ptr_mark (void (*function) (void *),
  4595                                             void *arg, void (*mark) (void *));
  4596 extern void record_unwind_protect_int (void (*) (int), int);
  4597 extern void record_unwind_protect_intmax (void (*) (intmax_t), intmax_t);
  4598 extern void record_unwind_protect_void (void (*) (void));
  4599 extern void record_unwind_protect_excursion (void);
  4600 extern void record_unwind_protect_nothing (void);
  4601 extern void record_unwind_protect_module (enum specbind_tag, void *);
  4602 extern void clear_unwind_protect (specpdl_ref);
  4603 extern void set_unwind_protect (specpdl_ref, void (*) (Lisp_Object),
  4604                                 Lisp_Object);
  4605 extern void set_unwind_protect_ptr (specpdl_ref, void (*) (void *), void *);
  4606 extern Lisp_Object unbind_to (specpdl_ref, Lisp_Object);
  4607 void specpdl_unrewind (union specbinding *pdl, int distance, bool vars_only);
  4608 extern AVOID error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
  4609 extern AVOID verror (const char *, va_list)
  4610   ATTRIBUTE_FORMAT_PRINTF (1, 0);
  4611 extern Lisp_Object vformat_string (const char *, va_list)
  4612   ATTRIBUTE_FORMAT_PRINTF (1, 0);
  4613 extern Lisp_Object load_with_autoload_queue
  4614            (Lisp_Object file, Lisp_Object noerror, Lisp_Object nomessage,
  4615             Lisp_Object nosuffix, Lisp_Object must_suffix);
  4616 extern Lisp_Object call_debugger (Lisp_Object arg);
  4617 extern void init_eval_once (void);
  4618 extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object, ...);
  4619 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
  4620 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
  4621 extern void init_eval (void);
  4622 extern void syms_of_eval (void);
  4623 extern void prog_ignore (Lisp_Object);
  4624 extern void mark_specpdl (union specbinding *first, union specbinding *ptr);
  4625 extern void get_backtrace (Lisp_Object array);
  4626 Lisp_Object backtrace_top_function (void);
  4627 extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);
  4628 void do_debug_on_call (Lisp_Object code, specpdl_ref count);
  4629 Lisp_Object funcall_general (Lisp_Object fun,
  4630                              ptrdiff_t numargs, Lisp_Object *args);
  4631 
  4632 /* Defined in unexmacosx.c.  */
  4633 #if defined DARWIN_OS && defined HAVE_UNEXEC
  4634 extern void unexec_init_emacs_zone (void);
  4635 extern void *unexec_malloc (size_t);
  4636 extern void *unexec_realloc (void *, size_t);
  4637 extern void unexec_free (void *);
  4638 #endif
  4639 
  4640 /* The definition of Lisp_Module_Function depends on emacs-module.h,
  4641    so we don't define it here.  It's defined in emacs-module.c.  */
  4642 
  4643 INLINE bool
  4644 MODULE_FUNCTIONP (Lisp_Object o)
  4645 {
  4646   return PSEUDOVECTORP (o, PVEC_MODULE_FUNCTION);
  4647 }
  4648 
  4649 INLINE struct Lisp_Module_Function *
  4650 XMODULE_FUNCTION (Lisp_Object o)
  4651 {
  4652   eassert (MODULE_FUNCTIONP (o));
  4653   return XUNTAG (o, Lisp_Vectorlike, struct Lisp_Module_Function);
  4654 }
  4655 
  4656 #ifdef HAVE_MODULES
  4657 /* A function pointer type good enough for lisp.h.  Actual module
  4658    function pointers are of a different type that relies on details
  4659    internal to emacs-module.c.  */
  4660 typedef void (*module_funcptr) (void);
  4661 
  4662 /* Defined in alloc.c.  */
  4663 extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p);
  4664 
  4665 /* Defined in emacs-module.c.  */
  4666 extern Lisp_Object funcall_module (Lisp_Object, ptrdiff_t, Lisp_Object *);
  4667 extern Lisp_Object module_function_arity (const struct Lisp_Module_Function *);
  4668 extern Lisp_Object module_function_documentation
  4669   (struct Lisp_Module_Function const *);
  4670 extern Lisp_Object module_function_interactive_form
  4671   (const struct Lisp_Module_Function *);
  4672 extern Lisp_Object module_function_command_modes
  4673   (const struct Lisp_Module_Function *);
  4674 extern module_funcptr module_function_address
  4675   (struct Lisp_Module_Function const *);
  4676 extern void *module_function_data (const struct Lisp_Module_Function *);
  4677 extern void module_finalize_function (const struct Lisp_Module_Function *);
  4678 extern void mark_module_environment (void *);
  4679 extern void finalize_runtime_unwind (void *);
  4680 extern void finalize_environment_unwind (void *);
  4681 extern void init_module_assertions (bool);
  4682 extern void syms_of_module (void);
  4683 #endif
  4684 
  4685 /* Defined in thread.c.  */
  4686 extern void mark_threads (void);
  4687 extern void unmark_main_thread (void);
  4688 
  4689 /* Defined in editfns.c.  */
  4690 extern void insert1 (Lisp_Object);
  4691 extern void save_excursion_save (union specbinding *);
  4692 extern void save_excursion_restore (Lisp_Object, Lisp_Object);
  4693 extern Lisp_Object save_restriction_save (void);
  4694 extern void save_restriction_restore (Lisp_Object);
  4695 extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool);
  4696 extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
  4697                                             ptrdiff_t, bool);
  4698 extern void labeled_narrow_to_region (Lisp_Object, Lisp_Object, Lisp_Object);
  4699 extern void reset_outermost_restrictions (void);
  4700 extern void labeled_restrictions_remove_in_current_buffer (void);
  4701 extern void init_editfns (void);
  4702 extern void syms_of_editfns (void);
  4703 
  4704 /* Defined in buffer.c.  */
  4705 extern bool mouse_face_overlay_overlaps (Lisp_Object);
  4706 extern Lisp_Object disable_line_numbers_overlay_at_eob (void);
  4707 extern AVOID nsberror (Lisp_Object);
  4708 extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t, bool);
  4709 extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
  4710 extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
  4711 extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
  4712                                          Lisp_Object, Lisp_Object, Lisp_Object);
  4713 extern bool overlay_touches_p (ptrdiff_t);
  4714 extern Lisp_Object other_buffer_safely (Lisp_Object);
  4715 extern Lisp_Object get_truename_buffer (Lisp_Object);
  4716 extern void init_buffer_once (void);
  4717 extern void init_buffer (void);
  4718 extern void syms_of_buffer (void);
  4719 
  4720 /* Defined in marker.c.  */
  4721 
  4722 extern ptrdiff_t marker_position (Lisp_Object);
  4723 extern ptrdiff_t marker_byte_position (Lisp_Object);
  4724 extern void clear_charpos_cache (struct buffer *);
  4725 extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
  4726 extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
  4727 extern void detach_marker (Lisp_Object);
  4728 extern void unchain_marker (struct Lisp_Marker *);
  4729 extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
  4730 extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
  4731 extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
  4732                                                ptrdiff_t, ptrdiff_t);
  4733 extern Lisp_Object build_marker (struct buffer *, ptrdiff_t, ptrdiff_t);
  4734 extern void syms_of_marker (void);
  4735 
  4736 /* Defined in fileio.c.  */
  4737 
  4738 extern Lisp_Object file_name_directory (Lisp_Object);
  4739 extern char *splice_dir_file (char *, char const *, char const *)
  4740   ATTRIBUTE_RETURNS_NONNULL;
  4741 extern bool file_name_absolute_p (const char *);
  4742 extern char const *get_homedir (void) ATTRIBUTE_RETURNS_NONNULL;
  4743 extern Lisp_Object expand_and_dir_to_file (Lisp_Object);
  4744 extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object,
  4745                                  Lisp_Object, Lisp_Object, Lisp_Object,
  4746                                  Lisp_Object, int);
  4747 extern void close_file_unwind (int);
  4748 extern void fclose_unwind (void *);
  4749 extern void restore_point_unwind (Lisp_Object);
  4750 extern bool file_access_p (char const *, int);
  4751 extern Lisp_Object get_file_errno_data (const char *, Lisp_Object, int);
  4752 extern AVOID report_file_errno (const char *, Lisp_Object, int);
  4753 extern AVOID report_file_error (const char *, Lisp_Object);
  4754 extern AVOID report_file_notify_error (const char *, Lisp_Object);
  4755 extern Lisp_Object file_attribute_errno (Lisp_Object, int);
  4756 extern bool internal_delete_file (Lisp_Object);
  4757 extern Lisp_Object check_emacs_readlinkat (int, Lisp_Object, char const *);
  4758 extern bool file_directory_p (Lisp_Object);
  4759 extern bool file_accessible_directory_p (Lisp_Object);
  4760 extern Lisp_Object buffer_visited_file_modtime (struct buffer *);
  4761 extern void init_fileio (void);
  4762 extern void syms_of_fileio (void);
  4763 
  4764 /* Defined in search.c.  */
  4765 extern void shrink_regexp_cache (void);
  4766 extern void restore_search_regs (void);
  4767 extern void update_search_regs (ptrdiff_t oldstart,
  4768                                 ptrdiff_t oldend, ptrdiff_t newend);
  4769 extern void record_unwind_save_match_data (void);
  4770 extern ptrdiff_t fast_string_match_internal (Lisp_Object, Lisp_Object,
  4771                                              Lisp_Object);
  4772 extern ptrdiff_t fast_c_string_match_internal (Lisp_Object, const char *,
  4773                                                ptrdiff_t, Lisp_Object);
  4774 
  4775 INLINE ptrdiff_t
  4776 fast_string_match (Lisp_Object regexp, Lisp_Object string)
  4777 {
  4778   return fast_string_match_internal (regexp, string, Qnil);
  4779 }
  4780 
  4781 INLINE ptrdiff_t
  4782 fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string)
  4783 {
  4784   return fast_string_match_internal (regexp, string, Vascii_canon_table);
  4785 }
  4786 
  4787 INLINE ptrdiff_t
  4788 fast_c_string_match (Lisp_Object regexp,
  4789                      const char *string, ptrdiff_t len)
  4790 {
  4791   return fast_c_string_match_internal (regexp, string, len, Qnil);
  4792 }
  4793 
  4794 INLINE ptrdiff_t
  4795 fast_c_string_match_ignore_case (Lisp_Object regexp,
  4796                                  const char *string, ptrdiff_t len)
  4797 {
  4798   return fast_c_string_match_internal (regexp, string, len,
  4799                                        Vascii_canon_table);
  4800 }
  4801 
  4802 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
  4803                                   ptrdiff_t, ptrdiff_t, Lisp_Object);
  4804 extern ptrdiff_t find_newline1 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
  4805                                ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
  4806 extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
  4807                                ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
  4808 extern void scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
  4809                           ptrdiff_t, bool);
  4810 extern ptrdiff_t scan_newline_from_point (ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
  4811 extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
  4812                                        ptrdiff_t, ptrdiff_t *);
  4813 extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
  4814                                            ptrdiff_t, ptrdiff_t *);
  4815 extern EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t,
  4816                                 ptrdiff_t, ptrdiff_t, EMACS_INT,
  4817                                 bool, Lisp_Object, Lisp_Object, bool);
  4818 extern void syms_of_search (void);
  4819 extern void clear_regexp_cache (void);
  4820 
  4821 /* Defined in minibuf.c.  */
  4822 
  4823 extern Lisp_Object Vminibuffer_list;
  4824 extern Lisp_Object last_minibuf_string;
  4825 extern void move_minibuffers_onto_frame (struct frame *, Lisp_Object, bool);
  4826 extern bool is_minibuffer (EMACS_INT, Lisp_Object);
  4827 extern EMACS_INT this_minibuffer_depth (Lisp_Object);
  4828 extern EMACS_INT minibuf_level;
  4829 extern Lisp_Object get_minibuffer (EMACS_INT);
  4830 extern void init_minibuf_once (void);
  4831 extern void set_initial_minibuffer_mode (void);
  4832 extern void syms_of_minibuf (void);
  4833 extern void barf_if_interaction_inhibited (void);
  4834 
  4835 /* Defined in callint.c.  */
  4836 
  4837 extern void syms_of_callint (void);
  4838 
  4839 /* Defined in casefiddle.c.  */
  4840 
  4841 extern void syms_of_casefiddle (void);
  4842 
  4843 /* Defined in casetab.c.  */
  4844 
  4845 extern void init_casetab_once (void);
  4846 extern void syms_of_casetab (void);
  4847 
  4848 /* Defined in keyboard.c.  */
  4849 
  4850 extern EMACS_INT command_loop_level;
  4851 extern Lisp_Object echo_message_buffer;
  4852 extern struct kboard *echo_kboard;
  4853 extern void cancel_echoing (void);
  4854 extern bool input_pending;
  4855 #ifdef HAVE_STACK_OVERFLOW_HANDLING
  4856 extern sigjmp_buf return_to_command_loop;
  4857 #endif
  4858 extern Lisp_Object menu_bar_items (Lisp_Object);
  4859 extern Lisp_Object tab_bar_items (Lisp_Object, int *);
  4860 extern Lisp_Object tool_bar_items (Lisp_Object, int *);
  4861 extern void discard_mouse_events (void);
  4862 #if defined (USABLE_SIGIO) || defined (USABLE_SIGPOLL)
  4863 void handle_input_available_signal (int);
  4864 #endif
  4865 extern Lisp_Object pending_funcalls;
  4866 extern bool detect_input_pending (void);
  4867 extern bool detect_input_pending_ignore_squeezables (void);
  4868 extern bool detect_input_pending_run_timers (bool);
  4869 extern void safe_run_hooks (Lisp_Object);
  4870 extern void safe_run_hooks_2 (Lisp_Object, Lisp_Object, Lisp_Object);
  4871 extern void cmd_error_internal (Lisp_Object, const char *);
  4872 extern Lisp_Object command_loop_2 (Lisp_Object);
  4873 extern Lisp_Object read_menu_command (void);
  4874 extern Lisp_Object recursive_edit_1 (void);
  4875 extern void record_auto_save (void);
  4876 extern void force_auto_save_soon (void);
  4877 extern void init_keyboard (void);
  4878 extern void syms_of_keyboard (void);
  4879 extern void keys_of_keyboard (void);
  4880 
  4881 /* Defined in indent.c.  */
  4882 extern ptrdiff_t current_column (void);
  4883 extern void invalidate_current_column (void);
  4884 extern bool indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
  4885 extern void syms_of_indent (void);
  4886 
  4887 /* Defined in frame.c.  */
  4888 extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
  4889 extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
  4890 extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
  4891 extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
  4892 extern void frames_discard_buffer (Lisp_Object);
  4893 extern void init_frame_once (void);
  4894 extern void syms_of_frame (void);
  4895 
  4896 /* Defined in emacs.c.  */
  4897 extern char **initial_argv;
  4898 extern int initial_argc;
  4899 extern char const *emacs_wd;
  4900 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
  4901 extern bool display_arg;
  4902 #endif
  4903 extern Lisp_Object decode_env_path (const char *, const char *, bool);
  4904 extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
  4905 extern AVOID terminate_due_to_signal (int, int);
  4906 #ifdef WINDOWSNT
  4907 extern Lisp_Object Vlibrary_cache;
  4908 #endif
  4909 #if HAVE_SETLOCALE
  4910 void fixup_locale (void);
  4911 void synchronize_system_messages_locale (void);
  4912 void synchronize_system_time_locale (void);
  4913 #else
  4914 INLINE void fixup_locale (void) {}
  4915 INLINE void synchronize_system_messages_locale (void) {}
  4916 INLINE void synchronize_system_time_locale (void) {}
  4917 #endif
  4918 extern char *emacs_strerror (int) ATTRIBUTE_RETURNS_NONNULL;
  4919 extern void shut_down_emacs (int, Lisp_Object);
  4920 
  4921 /* True means don't do interactive redisplay and don't change tty modes.  */
  4922 extern bool noninteractive;
  4923 
  4924 /* True means remove site-lisp directories from load-path.  */
  4925 extern bool no_site_lisp;
  4926 
  4927 /* True means put details like time stamps into builds.  */
  4928 extern bool build_details;
  4929 
  4930 #ifndef WINDOWSNT
  4931 /* 0 not a daemon, 1 foreground daemon, 2 background daemon.  */
  4932 extern int daemon_type;
  4933 #define IS_DAEMON (daemon_type != 0)
  4934 #define DAEMON_RUNNING (daemon_type >= 0)
  4935 #else  /* WINDOWSNT */
  4936 extern void *w32_daemon_event;
  4937 #define IS_DAEMON (w32_daemon_event != NULL)
  4938 #define DAEMON_RUNNING (w32_daemon_event != INVALID_HANDLE_VALUE)
  4939 #endif
  4940 
  4941 /* True if handling a fatal error already.  */
  4942 extern bool fatal_error_in_progress;
  4943 
  4944 /* True means don't do use window-system-specific display code.  */
  4945 extern bool inhibit_window_system;
  4946 /* True means that a filter or a sentinel is running.  */
  4947 extern bool running_asynch_code;
  4948 
  4949 /* Defined in process.c.  */
  4950 struct Lisp_Process;
  4951 extern void child_signal_init (void);
  4952 extern void kill_buffer_processes (Lisp_Object);
  4953 extern int wait_reading_process_output (intmax_t, int, int, bool, Lisp_Object,
  4954                                         struct Lisp_Process *, int);
  4955 /* Max value for the first argument of wait_reading_process_output.  */
  4956 #if GNUC_PREREQ (3, 0, 0) && ! GNUC_PREREQ (4, 6, 0)
  4957 /* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.0.
  4958    The bug merely causes a bogus warning, but the warning is annoying.  */
  4959 # define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX)
  4960 #else
  4961 # define WAIT_READING_MAX INTMAX_MAX
  4962 #endif
  4963 #ifdef HAVE_TIMERFD
  4964 extern void add_timer_wait_descriptor (int);
  4965 #endif
  4966 extern void add_keyboard_wait_descriptor (int);
  4967 extern void delete_keyboard_wait_descriptor (int);
  4968 #ifdef HAVE_GPM
  4969 extern void add_gpm_wait_descriptor (int);
  4970 extern void delete_gpm_wait_descriptor (int);
  4971 #endif
  4972 extern void init_process_emacs (int);
  4973 extern void syms_of_process (void);
  4974 extern void setup_process_coding_systems (Lisp_Object);
  4975 
  4976 /* Defined in callproc.c.  */
  4977 #ifdef DOS_NT
  4978 # define CHILD_SETUP_ERROR_DESC "Spawning child process"
  4979 #else
  4980 # define CHILD_SETUP_ERROR_DESC "Doing vfork"
  4981 #endif
  4982 
  4983 extern int emacs_spawn (pid_t *, int, int, int, char **, char **,
  4984                         const char *, const char *, bool, bool,
  4985                         const sigset_t *);
  4986 extern char **make_environment_block (Lisp_Object) ATTRIBUTE_RETURNS_NONNULL;
  4987 extern void init_callproc_1 (void);
  4988 extern void init_callproc (void);
  4989 extern void set_initial_environment (void);
  4990 extern void syms_of_callproc (void);
  4991 
  4992 /* Defined in doc.c.  */
  4993 extern Lisp_Object read_doc_string (Lisp_Object);
  4994 extern Lisp_Object get_doc_string (Lisp_Object, bool, bool);
  4995 extern void syms_of_doc (void);
  4996 extern int read_bytecode_char (bool);
  4997 
  4998 /* Defined in bytecode.c.  */
  4999 extern void syms_of_bytecode (void);
  5000 extern Lisp_Object exec_byte_code (Lisp_Object, ptrdiff_t,
  5001                                    ptrdiff_t, Lisp_Object *);
  5002 extern Lisp_Object get_byte_code_arity (Lisp_Object);
  5003 extern void init_bc_thread (struct bc_thread_state *bc);
  5004 extern void free_bc_thread (struct bc_thread_state *bc);
  5005 extern void mark_bytecode (struct bc_thread_state *bc);
  5006 
  5007 INLINE struct bc_frame *
  5008 get_act_rec (struct thread_state *th)
  5009 {
  5010   return th->bc.fp;
  5011 }
  5012 
  5013 INLINE void
  5014 set_act_rec (struct thread_state *th, struct bc_frame *act_rec)
  5015 {
  5016   th->bc.fp = act_rec;
  5017 }
  5018 
  5019 /* Defined in macros.c.  */
  5020 extern void init_macros (void);
  5021 extern void syms_of_macros (void);
  5022 
  5023 /* Defined in undo.c.  */
  5024 extern void truncate_undo_list (struct buffer *);
  5025 extern void record_insert (ptrdiff_t, ptrdiff_t);
  5026 extern void record_delete (ptrdiff_t, Lisp_Object, bool);
  5027 extern void record_first_change (void);
  5028 extern void record_change (ptrdiff_t, ptrdiff_t);
  5029 extern void record_property_change (ptrdiff_t, ptrdiff_t,
  5030                                     Lisp_Object, Lisp_Object,
  5031                                     Lisp_Object);
  5032 extern void syms_of_undo (void);
  5033 
  5034 /* Defined in textprop.c.  */
  5035 extern void report_interval_modification (Lisp_Object, Lisp_Object);
  5036 
  5037 /* Defined in menu.c.  */
  5038 extern void syms_of_menu (void);
  5039 
  5040 /* Defined in xmenu.c.  */
  5041 extern void syms_of_xmenu (void);
  5042 
  5043 /* Defined in termchar.h.  */
  5044 struct tty_display_info;
  5045 
  5046 /* Defined in sysdep.c.  */
  5047 #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE
  5048 extern int maybe_disable_address_randomization (int, char **);
  5049 #else
  5050 INLINE int
  5051 maybe_disable_address_randomization (int argc, char **argv)
  5052 {
  5053   return argc;
  5054 }
  5055 #endif
  5056 extern int emacs_exec_file (char const *, char *const *, char *const *);
  5057 extern void init_standard_fds (void);
  5058 extern char *emacs_get_current_dir_name (void);
  5059 extern void stuff_char (char c);
  5060 extern void init_foreground_group (void);
  5061 extern void sys_subshell (void);
  5062 extern void sys_suspend (void);
  5063 extern void discard_tty_input (void);
  5064 extern void init_sys_modes (struct tty_display_info *);
  5065 extern void reset_sys_modes (struct tty_display_info *);
  5066 extern void init_all_sys_modes (void);
  5067 extern void reset_all_sys_modes (void);
  5068 extern void child_setup_tty (int);
  5069 extern void setup_pty (int);
  5070 extern int set_window_size (int, int, int);
  5071 extern EMACS_INT get_random (void);
  5072 extern unsigned long int get_random_ulong (void);
  5073 extern void seed_random (void *, ptrdiff_t);
  5074 extern void init_random (void);
  5075 extern void emacs_backtrace (int);
  5076 extern AVOID emacs_abort (void) NO_INLINE;
  5077 extern int emacs_fstatat (int, char const *, void *, int);
  5078 #ifdef HAVE_SYS_STAT_H
  5079 extern int sys_fstat (int, struct stat *);
  5080 #endif
  5081 extern int sys_faccessat (int, const char *, int, int);
  5082 #if !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY)
  5083 extern int emacs_openat (int, char const *, int, int);
  5084 #endif
  5085 extern int emacs_open (const char *, int, int);
  5086 extern int emacs_open_noquit (const char *, int, int);
  5087 extern int emacs_pipe (int[2]);
  5088 extern int emacs_close (int);
  5089 #if !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY)
  5090 # define emacs_fclose fclose
  5091 #else
  5092 extern int emacs_fclose (FILE *);
  5093 #endif
  5094 extern FILE *emacs_fdopen (int, const char *)
  5095   ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1);
  5096 extern FILE *emacs_fopen (char const *, char const *)
  5097   ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1);
  5098 extern int emacs_unlink (const char *);
  5099 extern int emacs_symlink (const char *, const char *);
  5100 extern int emacs_rmdir (const char *);
  5101 extern int emacs_mkdir (const char *, mode_t);
  5102 extern int emacs_renameat_noreplace (int, const char *, int,
  5103                                      const char *);
  5104 extern int emacs_rename (const char *, const char *);
  5105 extern int emacs_fchmodat (int, const char *, mode_t, int);
  5106 extern ptrdiff_t emacs_read (int, void *, ptrdiff_t);
  5107 extern ptrdiff_t emacs_read_quit (int, void *, ptrdiff_t);
  5108 extern ptrdiff_t emacs_write (int, void const *, ptrdiff_t);
  5109 extern ptrdiff_t emacs_write_sig (int, void const *, ptrdiff_t);
  5110 extern ptrdiff_t emacs_write_quit (int, void const *, ptrdiff_t);
  5111 extern void emacs_perror (char const *);
  5112 extern int renameat_noreplace (int, char const *, int, char const *);
  5113 extern int str_collate (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
  5114 extern void syms_of_sysdep (void);
  5115 
  5116 /* Defined in filelock.c.  */
  5117 extern void unlock_all_files (void);
  5118 extern void unlock_buffer (struct buffer *);
  5119 extern void syms_of_filelock (void);
  5120 
  5121 /* Defined in sound.c.  */
  5122 extern void syms_of_sound (void);
  5123 
  5124 /* Defined in category.c.  */
  5125 extern void init_category_once (void);
  5126 extern Lisp_Object char_category_set (int);
  5127 extern void syms_of_category (void);
  5128 
  5129 /* Defined in ccl.c.  */
  5130 extern void syms_of_ccl (void);
  5131 
  5132 /* Defined in dired.c.  */
  5133 extern void syms_of_dired (void);
  5134 extern Lisp_Object directory_files_internal (Lisp_Object, Lisp_Object,
  5135                                              Lisp_Object, Lisp_Object,
  5136                                              bool, Lisp_Object, Lisp_Object);
  5137 
  5138 /* Defined in term.c.  */
  5139 #ifndef HAVE_ANDROID
  5140 extern int *char_ins_del_vector;
  5141 #endif
  5142 extern void syms_of_term (void);
  5143 extern AVOID fatal (const char *msgid, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
  5144 
  5145 /* Defined in terminal.c.  */
  5146 extern void syms_of_terminal (void);
  5147 extern char * tty_type_name (Lisp_Object);
  5148 
  5149 /* Defined in font.c.  */
  5150 extern void syms_of_font (void);
  5151 extern void init_font (void);
  5152 
  5153 #ifdef HAVE_WINDOW_SYSTEM
  5154 /* Defined in fontset.c.  */
  5155 extern void syms_of_fontset (void);
  5156 #endif
  5157 
  5158 /* Defined in inotify.c */
  5159 #ifdef HAVE_INOTIFY
  5160 extern void syms_of_inotify (void);
  5161 #endif
  5162 
  5163 /* Defined in kqueue.c */
  5164 #ifdef HAVE_KQUEUE
  5165 extern void globals_of_kqueue (void);
  5166 extern void syms_of_kqueue (void);
  5167 #endif
  5168 
  5169 /* Defined in gfilenotify.c */
  5170 #ifdef HAVE_GFILENOTIFY
  5171 extern void globals_of_gfilenotify (void);
  5172 extern void syms_of_gfilenotify (void);
  5173 #endif
  5174 
  5175 #ifdef HAVE_W32NOTIFY
  5176 /* Defined on w32notify.c.  */
  5177 extern void syms_of_w32notify (void);
  5178 #endif
  5179 
  5180 #if defined HAVE_NTGUI || defined CYGWIN
  5181 /* Defined in w32cygwinx.c.  */
  5182 extern void syms_of_w32cygwinx (void);
  5183 #endif
  5184 
  5185 /* Defined in xfaces.c.  */
  5186 extern Lisp_Object Vface_alternative_font_family_alist;
  5187 extern Lisp_Object Vface_alternative_font_registry_alist;
  5188 extern void syms_of_xfaces (void);
  5189 extern void init_xfaces (void);
  5190 
  5191 #ifdef HAVE_X_WINDOWS
  5192 /* Defined in xfns.c.  */
  5193 extern void syms_of_xfns (void);
  5194 
  5195 /* Defined in xsmfns.c.  */
  5196 extern void syms_of_xsmfns (void);
  5197 
  5198 /* Defined in xselect.c.  */
  5199 extern void syms_of_xselect (void);
  5200 
  5201 /* Defined in xterm.c.  */
  5202 extern void init_xterm (void);
  5203 extern void syms_of_xterm (void);
  5204 #endif /* HAVE_X_WINDOWS */
  5205 
  5206 #ifdef HAVE_WINDOW_SYSTEM
  5207 /* Defined in xterm.c, nsterm.m, w32term.c.  */
  5208 extern char *get_keysym_name (int);
  5209 #endif /* HAVE_WINDOW_SYSTEM */
  5210 
  5211 /* Defined in xml.c.  */
  5212 extern void syms_of_xml (void);
  5213 #ifdef HAVE_LIBXML2
  5214 extern void xml_cleanup_parser (void);
  5215 #endif
  5216 
  5217 #ifdef HAVE_LCMS2
  5218 /* Defined in lcms.c.  */
  5219 extern void syms_of_lcms2 (void);
  5220 #endif
  5221 
  5222 #ifdef HAVE_ZLIB
  5223 
  5224 #include <stdio.h>
  5225 
  5226 /* Defined in decompress.c.  */
  5227 extern int md5_gz_stream (FILE *, void *);
  5228 extern void syms_of_decompress (void);
  5229 #endif
  5230 
  5231 #ifdef HAVE_DBUS
  5232 /* Defined in dbusbind.c.  */
  5233 void init_dbusbind (void);
  5234 void syms_of_dbusbind (void);
  5235 #endif
  5236 
  5237 
  5238 /* Defined in profiler.c.  */
  5239 extern bool profiler_memory_running;
  5240 extern void malloc_probe (size_t);
  5241 extern void syms_of_profiler (void);
  5242 
  5243 
  5244 #ifdef DOS_NT
  5245 /* Defined in msdos.c, w32.c.  */
  5246 extern char *emacs_root_dir (void);
  5247 #endif /* DOS_NT */
  5248 
  5249 #ifdef HAVE_TEXT_CONVERSION
  5250 /* Defined in textconv.c.  */
  5251 extern void reset_frame_state (struct frame *);
  5252 extern void report_selected_window_change (struct frame *);
  5253 extern void report_point_change (struct frame *, struct window *,
  5254                                  struct buffer *);
  5255 extern void disable_text_conversion (void);
  5256 extern void resume_text_conversion (void);
  5257 extern void syms_of_textconv (void);
  5258 #endif
  5259 
  5260 #ifdef HAVE_NATIVE_COMP
  5261 INLINE bool
  5262 SUBR_NATIVE_COMPILEDP (Lisp_Object a)
  5263 {
  5264   return SUBRP (a) && !NILP (XSUBR (a)->native_comp_u);
  5265 }
  5266 
  5267 INLINE bool
  5268 SUBR_NATIVE_COMPILED_DYNP (Lisp_Object a)
  5269 {
  5270   return SUBR_NATIVE_COMPILEDP (a) && !NILP (XSUBR (a)->lambda_list);
  5271 }
  5272 
  5273 INLINE Lisp_Object
  5274 SUBR_TYPE (Lisp_Object a)
  5275 {
  5276   return XSUBR (a)->type;
  5277 }
  5278 
  5279 INLINE struct Lisp_Native_Comp_Unit *
  5280 allocate_native_comp_unit (void)
  5281 {
  5282   return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Native_Comp_Unit,
  5283                                        data_impure_vec, PVEC_NATIVE_COMP_UNIT);
  5284 }
  5285 #else
  5286 INLINE bool
  5287 SUBR_NATIVE_COMPILEDP (Lisp_Object a)
  5288 {
  5289   return false;
  5290 }
  5291 
  5292 INLINE bool
  5293 SUBR_NATIVE_COMPILED_DYNP (Lisp_Object a)
  5294 {
  5295   return false;
  5296 }
  5297 
  5298 #endif
  5299 
  5300 /* Defined in lastfile.c.  */
  5301 extern char my_edata[];
  5302 extern char my_endbss[];
  5303 extern char *my_endbss_static;
  5304 
  5305 extern void *xmalloc (size_t)
  5306   ATTRIBUTE_MALLOC_SIZE ((1)) ATTRIBUTE_RETURNS_NONNULL;
  5307 extern void *xzalloc (size_t)
  5308   ATTRIBUTE_MALLOC_SIZE ((1)) ATTRIBUTE_RETURNS_NONNULL;
  5309 extern void *xrealloc (void *, size_t)
  5310   ATTRIBUTE_ALLOC_SIZE ((2)) ATTRIBUTE_RETURNS_NONNULL;
  5311 extern void xfree (void *);
  5312 extern void *xnmalloc (ptrdiff_t, ptrdiff_t)
  5313   ATTRIBUTE_MALLOC_SIZE ((1,2)) ATTRIBUTE_RETURNS_NONNULL;
  5314 extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t)
  5315   ATTRIBUTE_ALLOC_SIZE ((2,3)) ATTRIBUTE_RETURNS_NONNULL;
  5316 extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t)
  5317   ATTRIBUTE_RETURNS_NONNULL;
  5318 
  5319 extern char *xstrdup (char const *)
  5320   ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
  5321 extern char *xlispstrdup (Lisp_Object)
  5322   ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
  5323 extern void dupstring (char **, char const *);
  5324 
  5325 /* Make DEST a copy of STRING's data.  Return a pointer to DEST's terminating
  5326    null byte.  This is like stpcpy, except the source is a Lisp string.  */
  5327 
  5328 INLINE char *
  5329 lispstpcpy (char *dest, Lisp_Object string)
  5330 {
  5331   ptrdiff_t len = SBYTES (string);
  5332   memcpy (dest, SDATA (string), len + 1);
  5333   return dest + len;
  5334 }
  5335 
  5336 #if (defined HAVE___LSAN_IGNORE_OBJECT \
  5337      && defined HAVE_SANITIZER_LSAN_INTERFACE_H)
  5338 # include <sanitizer/lsan_interface.h>
  5339 #else
  5340 /* Treat *P as a non-leak.  */
  5341 INLINE void
  5342 __lsan_ignore_object (void const *p)
  5343 {
  5344 }
  5345 #endif
  5346 
  5347 extern void xputenv (const char *);
  5348 
  5349 extern char *egetenv_internal (const char *, ptrdiff_t);
  5350 
  5351 INLINE char *
  5352 egetenv (const char *var)
  5353 {
  5354   /* When VAR is a string literal, strlen can be optimized away.  */
  5355   return egetenv_internal (var, strlen (var));
  5356 }
  5357 
  5358 /* Set up the name of the machine we're running on.  */
  5359 extern void init_system_name (void);
  5360 
  5361 /* Return the absolute value of X.  X should be a signed integer
  5362    expression without side effects, and X's absolute value should not
  5363    exceed the maximum for its promoted type.  This is called 'eabs'
  5364    because 'abs' is reserved by the C standard.  */
  5365 #define eabs(x)         ((x) < 0 ? -(x) : (x))
  5366 
  5367 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
  5368    larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack.  */
  5369 
  5370 enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 };
  5371 
  5372 extern void *record_xmalloc (size_t)
  5373   ATTRIBUTE_ALLOC_SIZE ((1)) ATTRIBUTE_RETURNS_NONNULL;
  5374 
  5375 #define USE_SAFE_ALLOCA                 \
  5376   ptrdiff_t sa_avail = MAX_ALLOCA;      \
  5377   specpdl_ref sa_count = SPECPDL_INDEX ()
  5378 
  5379 #define AVAIL_ALLOCA(size) (sa_avail -= (size), alloca (size))
  5380 
  5381 /* SAFE_ALLOCA allocates a simple buffer.  */
  5382 
  5383 #define SAFE_ALLOCA(size) ((size) <= sa_avail                           \
  5384                            ? AVAIL_ALLOCA (size)                        \
  5385                            : record_xmalloc (size))
  5386 
  5387 /* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
  5388    NITEMS items, each of the same type as *BUF.  MULTIPLIER must
  5389    positive.  The code is tuned for MULTIPLIER being a constant.  */
  5390 
  5391 #define SAFE_NALLOCA(buf, multiplier, nitems)                    \
  5392   do {                                                           \
  5393     if ((nitems) <= sa_avail / sizeof *(buf) / (multiplier))     \
  5394       (buf) = AVAIL_ALLOCA (sizeof *(buf) * (multiplier) * (nitems)); \
  5395     else                                                         \
  5396       {                                                          \
  5397         (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
  5398         record_unwind_protect_ptr (xfree, buf);                  \
  5399       }                                                          \
  5400   } while (false)
  5401 
  5402 /* SAFE_ALLOCA_STRING allocates a C copy of a Lisp string.  */
  5403 
  5404 #define SAFE_ALLOCA_STRING(ptr, string)                 \
  5405   do {                                                  \
  5406     (ptr) = SAFE_ALLOCA (SBYTES (string) + 1);          \
  5407     memcpy (ptr, SDATA (string), SBYTES (string) + 1);  \
  5408   } while (false)
  5409 
  5410 /* Free xmalloced memory and enable GC as needed.  */
  5411 
  5412 #define SAFE_FREE() safe_free (sa_count)
  5413 
  5414 INLINE void
  5415 safe_free (specpdl_ref sa_count)
  5416 {
  5417   while (specpdl_ptr != specpdl_ref_to_ptr (sa_count))
  5418     {
  5419       specpdl_ptr--;
  5420       if (specpdl_ptr->kind == SPECPDL_UNWIND_PTR)
  5421         {
  5422           eassert (specpdl_ptr->unwind_ptr.func == xfree);
  5423           xfree (specpdl_ptr->unwind_ptr.arg);
  5424         }
  5425       else
  5426         {
  5427           eassert (specpdl_ptr->kind == SPECPDL_UNWIND_ARRAY);
  5428           xfree (specpdl_ptr->unwind_array.array);
  5429         }
  5430     }
  5431 }
  5432 
  5433 /* Pop the specpdl stack back to COUNT, and return VAL.
  5434    Prefer this to { SAFE_FREE (); unbind_to (COUNT, VAL); }
  5435    when COUNT predates USE_SAFE_ALLOCA, as it is a bit more efficient
  5436    and also lets callers intermix SAFE_ALLOCA calls with other calls
  5437    that grow the specpdl stack.  */
  5438 
  5439 #define SAFE_FREE_UNBIND_TO(count, val) \
  5440   safe_free_unbind_to (count, sa_count, val)
  5441 
  5442 INLINE Lisp_Object
  5443 safe_free_unbind_to (specpdl_ref count, specpdl_ref sa_count, Lisp_Object val)
  5444 {
  5445   eassert (!specpdl_ref_lt (sa_count, count));
  5446   return unbind_to (count, val);
  5447 }
  5448 
  5449 /* Work around GCC bug 109577
  5450    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109577
  5451    which causes GCC to mistakenly complain about the
  5452    memory allocation in SAFE_ALLOCA_LISP_EXTRA.  */
  5453 #if GNUC_PREREQ (13, 0, 0)
  5454 # pragma GCC diagnostic ignored "-Wanalyzer-allocation-size"
  5455 #endif
  5456 
  5457 /* Set BUF to point to an allocated array of NELT Lisp_Objects,
  5458    immediately followed by EXTRA spare bytes.  */
  5459 
  5460 #define SAFE_ALLOCA_LISP_EXTRA(buf, nelt, extra)               \
  5461   do {                                                         \
  5462     ptrdiff_t alloca_nbytes;                                   \
  5463     if (ckd_mul (&alloca_nbytes, nelt, word_size)              \
  5464         || ckd_add (&alloca_nbytes, alloca_nbytes, extra)      \
  5465         || SIZE_MAX < alloca_nbytes)                           \
  5466       memory_full (SIZE_MAX);                                  \
  5467     else if (alloca_nbytes <= sa_avail)                        \
  5468       (buf) = AVAIL_ALLOCA (alloca_nbytes);                    \
  5469     else                                                       \
  5470       {                                                        \
  5471         /* Although only the first nelt words need clearing,   \
  5472            typically EXTRA is 0 or small so just use xzalloc;  \
  5473            this is simpler and often faster.  */               \
  5474         (buf) = xzalloc (alloca_nbytes);                       \
  5475         record_unwind_protect_array (buf, nelt);               \
  5476       }                                                        \
  5477   } while (false)
  5478 
  5479 /* Set BUF to point to an allocated array of NELT Lisp_Objects.  */
  5480 
  5481 #define SAFE_ALLOCA_LISP(buf, nelt) SAFE_ALLOCA_LISP_EXTRA (buf, nelt, 0)
  5482 
  5483 
  5484 /* If USE_STACK_LISP_OBJECTS, define macros and functions that
  5485    allocate some Lisp objects on the C stack.  As the storage is not
  5486    managed by the garbage collector, these objects are dangerous:
  5487    passing them to user code could result in undefined behavior if the
  5488    objects are in use after the C function returns.  Conversely, these
  5489    objects have better performance because GC is not involved.
  5490 
  5491    While debugging you may want to disable allocation on the C stack.
  5492    Build with CPPFLAGS='-DUSE_STACK_LISP_OBJECTS=0' to disable it.  */
  5493 
  5494 #if (!defined USE_STACK_LISP_OBJECTS \
  5495      && defined __GNUC__ && !defined __clang__ && ! GNUC_PREREQ (4, 3, 2))
  5496   /* Work around GCC bugs 36584 and 35271, which were fixed in GCC 4.3.2.  */
  5497 # define USE_STACK_LISP_OBJECTS false
  5498 #endif
  5499 #ifndef USE_STACK_LISP_OBJECTS
  5500 # define USE_STACK_LISP_OBJECTS true
  5501 #endif
  5502 
  5503 #ifdef GC_CHECK_STRING_BYTES
  5504 enum { defined_GC_CHECK_STRING_BYTES = true };
  5505 #else
  5506 enum { defined_GC_CHECK_STRING_BYTES = false };
  5507 #endif
  5508 
  5509 /* True for stack-based cons and string implementations, respectively.
  5510    Use stack-based strings only if stack-based cons also works.
  5511    Otherwise, STACK_CONS would create heap-based cons cells that
  5512    could point to stack-based strings, which is a no-no.  */
  5513 
  5514 enum
  5515   {
  5516     USE_STACK_CONS = USE_STACK_LISP_OBJECTS,
  5517     USE_STACK_STRING = (USE_STACK_CONS
  5518                         && !defined_GC_CHECK_STRING_BYTES)
  5519   };
  5520 
  5521 /* Auxiliary macros used for auto allocation of Lisp objects.  Please
  5522    use these only in macros like AUTO_CONS that declare a local
  5523    variable whose lifetime will be clear to the programmer.  */
  5524 #define STACK_CONS(a, b) \
  5525   make_lisp_ptr (&((struct Lisp_Cons) {{{a, {b}}}}), Lisp_Cons)
  5526 #define AUTO_CONS_EXPR(a, b) \
  5527   (USE_STACK_CONS ? STACK_CONS (a, b) : Fcons (a, b))
  5528 
  5529 /* Declare NAME as an auto Lisp cons or short list if possible, a
  5530    GC-based one otherwise.  This is in the sense of the C keyword
  5531    'auto'; i.e., the object has the lifetime of the containing block.
  5532    The resulting object should not be made visible to user Lisp code.  */
  5533 
  5534 #define AUTO_CONS(name, a, b) Lisp_Object name = AUTO_CONS_EXPR (a, b)
  5535 #define AUTO_LIST1(name, a)                                             \
  5536   Lisp_Object name = (USE_STACK_CONS ? STACK_CONS (a, Qnil) : list1 (a))
  5537 #define AUTO_LIST2(name, a, b)                                          \
  5538   Lisp_Object name = (USE_STACK_CONS                                    \
  5539                       ? STACK_CONS (a, STACK_CONS (b, Qnil))            \
  5540                       : list2 (a, b))
  5541 #define AUTO_LIST3(name, a, b, c)                                       \
  5542   Lisp_Object name = (USE_STACK_CONS                                    \
  5543                       ? STACK_CONS (a, STACK_CONS (b, STACK_CONS (c, Qnil))) \
  5544                       : list3 (a, b, c))
  5545 #define AUTO_LIST4(name, a, b, c, d)                                    \
  5546     Lisp_Object name                                                    \
  5547       = (USE_STACK_CONS                                                 \
  5548          ? STACK_CONS (a, STACK_CONS (b, STACK_CONS (c,                 \
  5549                                                      STACK_CONS (d, Qnil)))) \
  5550          : list4 (a, b, c, d))
  5551 
  5552 /* Declare NAME as an auto Lisp string if possible, a GC-based one if not.
  5553    Take its unibyte value from the null-terminated string STR,
  5554    an expression that should not have side effects.
  5555    STR's value is not necessarily copied.  The resulting Lisp string
  5556    should not be modified or given text properties or made visible to
  5557    user code.  */
  5558 
  5559 #define AUTO_STRING(name, str) \
  5560   AUTO_STRING_WITH_LEN (name, str, strlen (str))
  5561 
  5562 /* Declare NAME as an auto Lisp string if possible, a GC-based one if not.
  5563    Take its unibyte value from the null-terminated string STR with length LEN.
  5564    STR may have side effects and may contain null bytes.
  5565    STR's value is not necessarily copied.  The resulting Lisp string
  5566    should not be modified or given text properties or made visible to
  5567    user code.  */
  5568 
  5569 #define AUTO_STRING_WITH_LEN(name, str, len)                            \
  5570   Lisp_Object name =                                                    \
  5571     (USE_STACK_STRING                                                   \
  5572      ? (make_lisp_ptr                                                   \
  5573         ((&(struct Lisp_String) {{{len, -1, 0, (unsigned char *) (str)}}}), \
  5574          Lisp_String))                                                  \
  5575      : make_unibyte_string (str, len))
  5576 
  5577 /* The maximum length of "small" lists, as a heuristic.  These lists
  5578    are so short that code need not check for cycles or quits while
  5579    traversing.  */
  5580 enum { SMALL_LIST_LEN_MAX = 127 };
  5581 
  5582 /* Loop over conses of the list TAIL, signaling if a cycle is found,
  5583    and possibly quitting after each loop iteration.  In the loop body,
  5584    set TAIL to the current cons.  If the loop exits normally,
  5585    set TAIL to the terminating non-cons, typically nil.  The loop body
  5586    should not modify the list’s top level structure other than by
  5587    perhaps deleting the current cons.  */
  5588 
  5589 #define FOR_EACH_TAIL(tail) \
  5590   FOR_EACH_TAIL_INTERNAL (tail, circular_list (tail), true)
  5591 
  5592 /* Like FOR_EACH_TAIL (TAIL), except do not signal or quit.
  5593    If the loop exits due to a cycle, TAIL’s value is undefined.  */
  5594 
  5595 #define FOR_EACH_TAIL_SAFE(tail) \
  5596   FOR_EACH_TAIL_INTERNAL (tail, (void) ((tail) = Qnil), false)
  5597 
  5598 /* Iterator intended for use only within FOR_EACH_TAIL_INTERNAL.  */
  5599 struct for_each_tail_internal
  5600 {
  5601   Lisp_Object tortoise;
  5602   intptr_t max, n;
  5603   unsigned short int q;
  5604 };
  5605 
  5606 /* Like FOR_EACH_TAIL (LIST), except evaluate CYCLE if a cycle is
  5607    found, and check for quit if CHECK_QUIT.  This is an internal macro
  5608    intended for use only by the above macros.
  5609 
  5610    Use Brent’s teleporting tortoise-hare algorithm.  See:
  5611    Brent RP. BIT. 1980;20(2):176-184. doi:10.1007/BF01933190
  5612    https://maths-people.anu.edu.au/~brent/pd/rpb051i.pdf
  5613 
  5614    This macro uses maybe_quit because of an excess of caution.  The
  5615    call to maybe_quit should not be needed in practice, as a very long
  5616    list, whether circular or not, will cause Emacs to be so slow in
  5617    other uninterruptible areas (e.g., garbage collection) that there
  5618    is little point to calling maybe_quit here.  */
  5619 
  5620 #define FOR_EACH_TAIL_INTERNAL(tail, cycle, check_quit)                 \
  5621   for (struct for_each_tail_internal li = { tail, 2, 0, 2 };            \
  5622        CONSP (tail);                                                    \
  5623        ((tail) = XCDR (tail),                                           \
  5624         ((--li.q != 0                                                   \
  5625           || ((check_quit) ? maybe_quit () : (void) 0, 0 < --li.n)      \
  5626           || (li.q = li.n = li.max <<= 1, li.n >>= USHRT_WIDTH,         \
  5627               li.tortoise = (tail), false))                             \
  5628          && BASE_EQ (tail, li.tortoise))                                \
  5629         ? (cycle) : (void) 0))
  5630 
  5631 /* Do a `for' loop over alist values.  */
  5632 
  5633 #define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var)             \
  5634   for ((list_var) = (head_var);                                         \
  5635        (CONSP (list_var) && ((value_var) = XCDR (XCAR (list_var)), true)); \
  5636        (list_var) = XCDR (list_var))
  5637 
  5638 /* Check whether it's time for GC, and run it if so.  */
  5639 
  5640 INLINE void
  5641 maybe_gc (void)
  5642 {
  5643   if (consing_until_gc < 0)
  5644     maybe_garbage_collect ();
  5645 }
  5646 
  5647 /* Simplified version of 'define-error' that works with pure
  5648    objects.  */
  5649 void
  5650 define_error (Lisp_Object name, const char *message, Lisp_Object parent);
  5651 
  5652 INLINE_HEADER_END
  5653 
  5654 #endif /* EMACS_LISP_H */

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