Fix alignment portability problems
[emacs.git] / src / lisp.h
blobbf9db591bd537e8a3f19e45b102fc236ac0fbf80
1 /* Fundamental definitions for GNU Emacs Lisp interpreter. -*- coding: utf-8 -*-
3 Copyright (C) 1985-1987, 1993-1995, 1997-2017 Free Software Foundation,
4 Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or (at
11 your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
21 #ifndef EMACS_LISP_H
22 #define EMACS_LISP_H
24 #include <alloca.h>
25 #include <setjmp.h>
26 #include <stdalign.h>
27 #include <stdarg.h>
28 #include <stddef.h>
29 #include <string.h>
30 #include <float.h>
31 #include <inttypes.h>
32 #include <limits.h>
34 #include <intprops.h>
35 #include <verify.h>
37 INLINE_HEADER_BEGIN
39 /* Define a TYPE constant ID as an externally visible name. Use like this:
41 DEFINE_GDB_SYMBOL_BEGIN (TYPE, ID)
42 # define ID (some integer preprocessor expression of type TYPE)
43 DEFINE_GDB_SYMBOL_END (ID)
45 This hack is for the benefit of compilers that do not make macro
46 definitions or enums visible to the debugger. It's used for symbols
47 that .gdbinit needs. */
49 #define DECLARE_GDB_SYM(type, id) type const id EXTERNALLY_VISIBLE
50 #ifdef MAIN_PROGRAM
51 # define DEFINE_GDB_SYMBOL_BEGIN(type, id) DECLARE_GDB_SYM (type, id)
52 # define DEFINE_GDB_SYMBOL_END(id) = id;
53 #else
54 # define DEFINE_GDB_SYMBOL_BEGIN(type, id) extern DECLARE_GDB_SYM (type, id)
55 # define DEFINE_GDB_SYMBOL_END(val) ;
56 #endif
58 /* The ubiquitous max and min macros. */
59 #undef min
60 #undef max
61 #define max(a, b) ((a) > (b) ? (a) : (b))
62 #define min(a, b) ((a) < (b) ? (a) : (b))
64 /* Number of elements in an array. */
65 #define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
67 /* Number of bits in a Lisp_Object tag. */
68 DEFINE_GDB_SYMBOL_BEGIN (int, GCTYPEBITS)
69 #define GCTYPEBITS 3
70 DEFINE_GDB_SYMBOL_END (GCTYPEBITS)
72 /* EMACS_INT - signed integer wide enough to hold an Emacs value
73 EMACS_INT_WIDTH - width in bits of EMACS_INT
74 EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
75 pI - printf length modifier for EMACS_INT
76 EMACS_UINT - unsigned variant of EMACS_INT */
77 #ifndef EMACS_INT_MAX
78 # if INTPTR_MAX <= 0
79 # error "INTPTR_MAX misconfigured"
80 # elif INTPTR_MAX <= INT_MAX && !defined WIDE_EMACS_INT
81 typedef int EMACS_INT;
82 typedef unsigned int EMACS_UINT;
83 enum { EMACS_INT_WIDTH = INT_WIDTH, EMACS_UINT_WIDTH = UINT_WIDTH };
84 # define EMACS_INT_MAX INT_MAX
85 # define pI ""
86 # elif INTPTR_MAX <= LONG_MAX && !defined WIDE_EMACS_INT
87 typedef long int EMACS_INT;
88 typedef unsigned long EMACS_UINT;
89 enum { EMACS_INT_WIDTH = LONG_WIDTH, EMACS_UINT_WIDTH = ULONG_WIDTH };
90 # define EMACS_INT_MAX LONG_MAX
91 # define pI "l"
92 # elif INTPTR_MAX <= LLONG_MAX
93 typedef long long int EMACS_INT;
94 typedef unsigned long long int EMACS_UINT;
95 enum { EMACS_INT_WIDTH = LLONG_WIDTH, EMACS_UINT_WIDTH = ULLONG_WIDTH };
96 # define EMACS_INT_MAX LLONG_MAX
97 /* MinGW supports %lld only if __USE_MINGW_ANSI_STDIO is non-zero,
98 which is arranged by config.h, and (for mingw.org) if GCC is 6.0 or
99 later and the runtime version is 5.0.0 or later. Otherwise,
100 printf-like functions are declared with __ms_printf__ attribute,
101 which will cause a warning for %lld etc. */
102 # if defined __MINGW32__ \
103 && (!defined __USE_MINGW_ANSI_STDIO \
104 || (!defined MINGW_W64 \
105 && !(GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5)))
106 # define pI "I64"
107 # else /* ! MinGW */
108 # define pI "ll"
109 # endif
110 # else
111 # error "INTPTR_MAX too large"
112 # endif
113 #endif
115 /* Number of bits to put in each character in the internal representation
116 of bool vectors. This should not vary across implementations. */
117 enum { BOOL_VECTOR_BITS_PER_CHAR =
118 #define BOOL_VECTOR_BITS_PER_CHAR 8
119 BOOL_VECTOR_BITS_PER_CHAR
122 /* An unsigned integer type representing a fixed-length bit sequence,
123 suitable for bool vector words, GC mark bits, etc. Normally it is size_t
124 for speed, but on weird platforms it is unsigned char and not all
125 its bits are used. */
126 #if BOOL_VECTOR_BITS_PER_CHAR == CHAR_BIT
127 typedef size_t bits_word;
128 # define BITS_WORD_MAX SIZE_MAX
129 enum { BITS_PER_BITS_WORD = SIZE_WIDTH };
130 #else
131 typedef unsigned char bits_word;
132 # define BITS_WORD_MAX ((1u << BOOL_VECTOR_BITS_PER_CHAR) - 1)
133 enum { BITS_PER_BITS_WORD = BOOL_VECTOR_BITS_PER_CHAR };
134 #endif
135 verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1);
137 /* printmax_t and uprintmax_t are types for printing large integers.
138 These are the widest integers that are supported for printing.
139 pMd etc. are conversions for printing them.
140 On C99 hosts, there's no problem, as even the widest integers work.
141 Fall back on EMACS_INT on pre-C99 hosts. */
142 #ifdef PRIdMAX
143 typedef intmax_t printmax_t;
144 typedef uintmax_t uprintmax_t;
145 # define pMd PRIdMAX
146 # define pMu PRIuMAX
147 #else
148 typedef EMACS_INT printmax_t;
149 typedef EMACS_UINT uprintmax_t;
150 # define pMd pI"d"
151 # define pMu pI"u"
152 #endif
154 /* Use pD to format ptrdiff_t values, which suffice for indexes into
155 buffers and strings. Emacs never allocates objects larger than
156 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
157 In C99, pD can always be "t"; configure it here for the sake of
158 pre-C99 libraries such as glibc 2.0 and Solaris 8. */
159 #if PTRDIFF_MAX == INT_MAX
160 # define pD ""
161 #elif PTRDIFF_MAX == LONG_MAX
162 # define pD "l"
163 #elif PTRDIFF_MAX == LLONG_MAX
164 # define pD "ll"
165 #else
166 # define pD "t"
167 #endif
169 /* Extra internal type checking? */
171 /* Define Emacs versions of <assert.h>'s 'assert (COND)' and <verify.h>'s
172 'assume (COND)'. COND should be free of side effects, as it may or
173 may not be evaluated.
175 'eassert (COND)' checks COND at runtime if ENABLE_CHECKING is
176 defined and suppress_checking is false, and does nothing otherwise.
177 Emacs dies if COND is checked and is false. The suppress_checking
178 variable is initialized to 0 in alloc.c. Set it to 1 using a
179 debugger to temporarily disable aborting on detected internal
180 inconsistencies or error conditions.
182 In some cases, a good compiler may be able to optimize away the
183 eassert macro even if ENABLE_CHECKING is true, e.g., if XSTRING (x)
184 uses eassert to test STRINGP (x), but a particular use of XSTRING
185 is invoked only after testing that STRINGP (x) is true, making the
186 test redundant.
188 eassume is like eassert except that it also causes the compiler to
189 assume that COND is true afterwards, regardless of whether runtime
190 checking is enabled. This can improve performance in some cases,
191 though it can degrade performance in others. It's often suboptimal
192 for COND to call external functions or access volatile storage. */
194 #ifndef ENABLE_CHECKING
195 # define eassert(cond) ((void) (false && (cond))) /* Check COND compiles. */
196 # define eassume(cond) assume (cond)
197 #else /* ENABLE_CHECKING */
199 extern _Noreturn void die (const char *, const char *, int);
201 extern bool suppress_checking EXTERNALLY_VISIBLE;
203 # define eassert(cond) \
204 (suppress_checking || (cond) \
205 ? (void) 0 \
206 : die (# cond, __FILE__, __LINE__))
207 # define eassume(cond) \
208 (suppress_checking \
209 ? assume (cond) \
210 : (cond) \
211 ? (void) 0 \
212 : die (# cond, __FILE__, __LINE__))
213 #endif /* ENABLE_CHECKING */
216 /* Use the configure flag --enable-check-lisp-object-type to make
217 Lisp_Object use a struct type instead of the default int. The flag
218 causes CHECK_LISP_OBJECT_TYPE to be defined. */
220 /***** Select the tagging scheme. *****/
221 /* The following option controls the tagging scheme:
222 - USE_LSB_TAG means that we can assume the least 3 bits of pointers are
223 always 0, and we can thus use them to hold tag bits, without
224 restricting our addressing space.
226 If ! USE_LSB_TAG, then use the top 3 bits for tagging, thus
227 restricting our possible address range.
229 USE_LSB_TAG not only requires the least 3 bits of pointers returned by
230 malloc to be 0 but also needs to be able to impose a mult-of-8 alignment
231 on the few static Lisp_Objects used, all of which are aligned via
232 the GCALIGN macro defined below. */
234 enum Lisp_Bits
236 GCALIGNMENT = 1 << GCTYPEBITS,
238 /* Number of bits in a Lisp_Object value, not counting the tag. */
239 VALBITS = EMACS_INT_WIDTH - GCTYPEBITS,
241 /* Number of bits in a Lisp fixnum tag. */
242 INTTYPEBITS = GCTYPEBITS - 1,
244 /* Number of bits in a Lisp fixnum value, not counting the tag. */
245 FIXNUM_BITS = VALBITS + 1
248 /* The maximum value that can be stored in a EMACS_INT, assuming all
249 bits other than the type bits contribute to a nonnegative signed value.
250 This can be used in #if, e.g., '#if USE_LSB_TAG' below expands to an
251 expression involving VAL_MAX. */
252 #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
254 /* Whether the least-significant bits of an EMACS_INT contain the tag.
255 On hosts where pointers-as-ints do not exceed VAL_MAX / 2, USE_LSB_TAG is:
256 a. unnecessary, because the top bits of an EMACS_INT are unused, and
257 b. slower, because it typically requires extra masking.
258 So, USE_LSB_TAG is true only on hosts where it might be useful. */
259 DEFINE_GDB_SYMBOL_BEGIN (bool, USE_LSB_TAG)
260 #define USE_LSB_TAG (VAL_MAX / 2 < INTPTR_MAX)
261 DEFINE_GDB_SYMBOL_END (USE_LSB_TAG)
263 /* Mask for the value (as opposed to the type bits) of a Lisp object. */
264 DEFINE_GDB_SYMBOL_BEGIN (EMACS_INT, VALMASK)
265 # define VALMASK (USE_LSB_TAG ? - (1 << GCTYPEBITS) : VAL_MAX)
266 DEFINE_GDB_SYMBOL_END (VALMASK)
268 #if !USE_LSB_TAG && !defined WIDE_EMACS_INT
269 # error "USE_LSB_TAG not supported on this platform; please report this." \
270 "Try 'configure --with-wide-int' to work around the problem."
271 error !;
272 #endif
274 /* Declare an object to have an address that is a multiple of
275 GCALIGNMENT. alignas is not suitable here, as it fails if the
276 object's natural alignment exceeds GCALIGNMENT. */
277 #ifdef HAVE_STRUCT_ATTRIBUTE_ALIGNED
278 # define GCALIGNED __attribute__ ((aligned (GCALIGNMENT)))
279 #else
280 # define GCALIGNED /* empty */
281 #endif
283 /* Some operations are so commonly executed that they are implemented
284 as macros, not functions, because otherwise runtime performance would
285 suffer too much when compiling with GCC without optimization.
286 There's no need to inline everything, just the operations that
287 would otherwise cause a serious performance problem.
289 For each such operation OP, define a macro lisp_h_OP that contains
290 the operation's implementation. That way, OP can be implemented
291 via a macro definition like this:
293 #define OP(x) lisp_h_OP (x)
295 and/or via a function definition like this:
297 Lisp_Object (OP) (Lisp_Object x) { return lisp_h_OP (x); }
299 without worrying about the implementations diverging, since
300 lisp_h_OP defines the actual implementation. The lisp_h_OP macros
301 are intended to be private to this include file, and should not be
302 used elsewhere.
304 FIXME: Remove the lisp_h_OP macros, and define just the inline OP
305 functions, once "gcc -Og" (new to GCC 4.8) works well enough for
306 Emacs developers. Maybe in the year 2020. See Bug#11935.
308 Commentary for these macros can be found near their corresponding
309 functions, below. */
311 #if CHECK_LISP_OBJECT_TYPE
312 # define lisp_h_XLI(o) ((o).i)
313 # define lisp_h_XIL(i) ((Lisp_Object) { i })
314 #else
315 # define lisp_h_XLI(o) (o)
316 # define lisp_h_XIL(i) (i)
317 #endif
318 #define lisp_h_CHECK_NUMBER(x) CHECK_TYPE (INTEGERP (x), Qintegerp, x)
319 #define lisp_h_CHECK_SYMBOL(x) CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
320 #define lisp_h_CHECK_TYPE(ok, predicate, x) \
321 ((ok) ? (void) 0 : wrong_type_argument (predicate, x))
322 #define lisp_h_CONSP(x) (XTYPE (x) == Lisp_Cons)
323 #define lisp_h_EQ(x, y) (XLI (x) == XLI (y))
324 #define lisp_h_FLOATP(x) (XTYPE (x) == Lisp_Float)
325 #define lisp_h_INTEGERP(x) ((XTYPE (x) & (Lisp_Int0 | ~Lisp_Int1)) == Lisp_Int0)
326 #define lisp_h_MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker)
327 #define lisp_h_MISCP(x) (XTYPE (x) == Lisp_Misc)
328 #define lisp_h_NILP(x) EQ (x, Qnil)
329 #define lisp_h_SET_SYMBOL_VAL(sym, v) \
330 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value = (v))
331 #define lisp_h_SYMBOL_CONSTANT_P(sym) (XSYMBOL (sym)->trapped_write == SYMBOL_NOWRITE)
332 #define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->trapped_write)
333 #define lisp_h_SYMBOL_VAL(sym) \
334 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value)
335 #define lisp_h_SYMBOLP(x) (XTYPE (x) == Lisp_Symbol)
336 #define lisp_h_VECTORLIKEP(x) (XTYPE (x) == Lisp_Vectorlike)
337 #define lisp_h_XCAR(c) XCONS (c)->car
338 #define lisp_h_XCDR(c) XCONS (c)->u.cdr
339 #define lisp_h_XCONS(a) \
340 (eassert (CONSP (a)), (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
341 #define lisp_h_XHASH(a) XUINT (a)
342 #ifndef GC_CHECK_CONS_LIST
343 # define lisp_h_check_cons_list() ((void) 0)
344 #endif
345 #if USE_LSB_TAG
346 # define lisp_h_make_number(n) \
347 XIL ((EMACS_INT) (((EMACS_UINT) (n) << INTTYPEBITS) + Lisp_Int0))
348 # define lisp_h_XFASTINT(a) XINT (a)
349 # define lisp_h_XINT(a) (XLI (a) >> INTTYPEBITS)
350 # define lisp_h_XSYMBOL(a) \
351 (eassert (SYMBOLP (a)), \
352 (struct Lisp_Symbol *) ((intptr_t) XLI (a) - Lisp_Symbol \
353 + (char *) lispsym))
354 # define lisp_h_XTYPE(a) ((enum Lisp_Type) (XLI (a) & ~VALMASK))
355 # define lisp_h_XUNTAG(a, type) \
356 __builtin_assume_aligned ((void *) (intptr_t) (XLI (a) - (type)), \
357 GCALIGNMENT)
358 #endif
360 /* When compiling via gcc -O0, define the key operations as macros, as
361 Emacs is too slow otherwise. To disable this optimization, compile
362 with -DINLINING=false. */
363 #if (defined __NO_INLINE__ \
364 && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \
365 && ! (defined INLINING && ! INLINING))
366 # define DEFINE_KEY_OPS_AS_MACROS true
367 #else
368 # define DEFINE_KEY_OPS_AS_MACROS false
369 #endif
371 #if DEFINE_KEY_OPS_AS_MACROS
372 # define XLI(o) lisp_h_XLI (o)
373 # define XIL(i) lisp_h_XIL (i)
374 # define CHECK_NUMBER(x) lisp_h_CHECK_NUMBER (x)
375 # define CHECK_SYMBOL(x) lisp_h_CHECK_SYMBOL (x)
376 # define CHECK_TYPE(ok, predicate, x) lisp_h_CHECK_TYPE (ok, predicate, x)
377 # define CONSP(x) lisp_h_CONSP (x)
378 # define EQ(x, y) lisp_h_EQ (x, y)
379 # define FLOATP(x) lisp_h_FLOATP (x)
380 # define INTEGERP(x) lisp_h_INTEGERP (x)
381 # define MARKERP(x) lisp_h_MARKERP (x)
382 # define MISCP(x) lisp_h_MISCP (x)
383 # define NILP(x) lisp_h_NILP (x)
384 # define SET_SYMBOL_VAL(sym, v) lisp_h_SET_SYMBOL_VAL (sym, v)
385 # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym)
386 # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym)
387 # define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym)
388 # define SYMBOLP(x) lisp_h_SYMBOLP (x)
389 # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x)
390 # define XCAR(c) lisp_h_XCAR (c)
391 # define XCDR(c) lisp_h_XCDR (c)
392 # define XCONS(a) lisp_h_XCONS (a)
393 # define XHASH(a) lisp_h_XHASH (a)
394 # ifndef GC_CHECK_CONS_LIST
395 # define check_cons_list() lisp_h_check_cons_list ()
396 # endif
397 # if USE_LSB_TAG
398 # define make_number(n) lisp_h_make_number (n)
399 # define XFASTINT(a) lisp_h_XFASTINT (a)
400 # define XINT(a) lisp_h_XINT (a)
401 # define XSYMBOL(a) lisp_h_XSYMBOL (a)
402 # define XTYPE(a) lisp_h_XTYPE (a)
403 # define XUNTAG(a, type) lisp_h_XUNTAG (a, type)
404 # endif
405 #endif
408 /* Define the fundamental Lisp data structures. */
410 /* This is the set of Lisp data types. If you want to define a new
411 data type, read the comments after Lisp_Fwd_Type definition
412 below. */
414 /* Lisp integers use 2 tags, to give them one extra bit, thus
415 extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1. */
416 #define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
417 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
419 /* Idea stolen from GDB. Pedantic GCC complains about enum bitfields,
420 MSVC doesn't support them, and xlc and Oracle Studio c99 complain
421 vociferously about them. */
422 #if (defined __STRICT_ANSI__ || defined _MSC_VER || defined __IBMC__ \
423 || (defined __SUNPRO_C && __STDC__))
424 #define ENUM_BF(TYPE) unsigned int
425 #else
426 #define ENUM_BF(TYPE) enum TYPE
427 #endif
430 enum Lisp_Type
432 /* Symbol. XSYMBOL (object) points to a struct Lisp_Symbol. */
433 Lisp_Symbol = 0,
435 /* Miscellaneous. XMISC (object) points to a union Lisp_Misc,
436 whose first member indicates the subtype. */
437 Lisp_Misc = 1,
439 /* Integer. XINT (obj) is the integer value. */
440 Lisp_Int0 = 2,
441 Lisp_Int1 = USE_LSB_TAG ? 6 : 3,
443 /* String. XSTRING (object) points to a struct Lisp_String.
444 The length of the string, and its contents, are stored therein. */
445 Lisp_String = 4,
447 /* Vector of Lisp objects, or something resembling it.
448 XVECTOR (object) points to a struct Lisp_Vector, which contains
449 the size and contents. The size field also contains the type
450 information, if it's not a real vector object. */
451 Lisp_Vectorlike = 5,
453 /* Cons. XCONS (object) points to a struct Lisp_Cons. */
454 Lisp_Cons = USE_LSB_TAG ? 3 : 6,
456 Lisp_Float = 7
459 /* This is the set of data types that share a common structure.
460 The first member of the structure is a type code from this set.
461 The enum values are arbitrary, but we'll use large numbers to make it
462 more likely that we'll spot the error if a random word in memory is
463 mistakenly interpreted as a Lisp_Misc. */
464 enum Lisp_Misc_Type
466 Lisp_Misc_Free = 0x5eab,
467 Lisp_Misc_Marker,
468 Lisp_Misc_Overlay,
469 Lisp_Misc_Save_Value,
470 Lisp_Misc_Finalizer,
471 #ifdef HAVE_MODULES
472 Lisp_Misc_User_Ptr,
473 #endif
474 /* This is not a type code. It is for range checking. */
475 Lisp_Misc_Limit
478 /* These are the types of forwarding objects used in the value slot
479 of symbols for special built-in variables whose value is stored in
480 C variables. */
481 enum Lisp_Fwd_Type
483 Lisp_Fwd_Int, /* Fwd to a C `int' variable. */
484 Lisp_Fwd_Bool, /* Fwd to a C boolean var. */
485 Lisp_Fwd_Obj, /* Fwd to a C Lisp_Object variable. */
486 Lisp_Fwd_Buffer_Obj, /* Fwd to a Lisp_Object field of buffers. */
487 Lisp_Fwd_Kboard_Obj /* Fwd to a Lisp_Object field of kboards. */
490 /* If you want to define a new Lisp data type, here are some
491 instructions. See the thread at
492 https://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00561.html
493 for more info.
495 First, there are already a couple of Lisp types that can be used if
496 your new type does not need to be exposed to Lisp programs nor
497 displayed to users. These are Lisp_Save_Value, a Lisp_Misc
498 subtype; and PVEC_OTHER, a kind of vectorlike object. The former
499 is suitable for temporarily stashing away pointers and integers in
500 a Lisp object. The latter is useful for vector-like Lisp objects
501 that need to be used as part of other objects, but which are never
502 shown to users or Lisp code (search for PVEC_OTHER in xterm.c for
503 an example).
505 These two types don't look pretty when printed, so they are
506 unsuitable for Lisp objects that can be exposed to users.
508 To define a new data type, add one more Lisp_Misc subtype or one
509 more pseudovector subtype. Pseudovectors are more suitable for
510 objects with several slots that need to support fast random access,
511 while Lisp_Misc types are for everything else. A pseudovector object
512 provides one or more slots for Lisp objects, followed by struct
513 members that are accessible only from C. A Lisp_Misc object is a
514 wrapper for a C struct that can contain anything you like.
516 Explicit freeing is discouraged for Lisp objects in general. But if
517 you really need to exploit this, use Lisp_Misc (check free_misc in
518 alloc.c to see why). There is no way to free a vectorlike object.
520 To add a new pseudovector type, extend the pvec_type enumeration;
521 to add a new Lisp_Misc, extend the Lisp_Misc_Type enumeration.
523 For a Lisp_Misc, you will also need to add your entry to union
524 Lisp_Misc, but make sure the first word has the same structure as
525 the others, starting with a 16-bit member of the Lisp_Misc_Type
526 enumeration and a 1-bit GC markbit. Also make sure the overall
527 size of the union is not increased by your addition. The latter
528 requirement is to keep Lisp_Misc objects small enough, so they
529 are handled faster: since all Lisp_Misc types use the same space,
530 enlarging any of them will affect all the rest. If you really
531 need a larger object, it is best to use Lisp_Vectorlike instead.
533 For a new pseudovector, it's highly desirable to limit the size
534 of your data type by VBLOCK_BYTES_MAX bytes (defined in alloc.c).
535 Otherwise you will need to change sweep_vectors (also in alloc.c).
537 Then you will need to add switch branches in print.c (in
538 print_object, to print your object, and possibly also in
539 print_preprocess) and to alloc.c, to mark your object (in
540 mark_object) and to free it (in gc_sweep). The latter is also the
541 right place to call any code specific to your data type that needs
542 to run when the object is recycled -- e.g., free any additional
543 resources allocated for it that are not Lisp objects. You can even
544 make a pointer to the function that frees the resources a slot in
545 your object -- this way, the same object could be used to represent
546 several disparate C structures. */
548 #ifdef CHECK_LISP_OBJECT_TYPE
550 typedef struct Lisp_Object { EMACS_INT i; } Lisp_Object;
552 #define LISP_INITIALLY(i) {i}
554 #undef CHECK_LISP_OBJECT_TYPE
555 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = true };
556 #else /* CHECK_LISP_OBJECT_TYPE */
558 /* If a struct type is not wanted, define Lisp_Object as just a number. */
560 typedef EMACS_INT Lisp_Object;
561 #define LISP_INITIALLY(i) (i)
562 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = false };
563 #endif /* CHECK_LISP_OBJECT_TYPE */
565 /* Forward declarations. */
567 /* Defined in this file. */
568 INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
569 Lisp_Object);
571 /* Defined in chartab.c. */
572 extern Lisp_Object char_table_ref (Lisp_Object, int);
573 extern void char_table_set (Lisp_Object, int, Lisp_Object);
575 /* Defined in data.c. */
576 extern _Noreturn void wrong_type_argument (Lisp_Object, Lisp_Object);
579 #ifdef CANNOT_DUMP
580 enum { might_dump = false };
581 #elif defined DOUG_LEA_MALLOC
582 /* Defined in emacs.c. */
583 extern bool might_dump;
584 #endif
585 /* True means Emacs has already been initialized.
586 Used during startup to detect startup of dumped Emacs. */
587 extern bool initialized;
589 /* Defined in floatfns.c. */
590 extern double extract_float (Lisp_Object);
593 /* Low-level conversion and type checking. */
595 /* Convert a Lisp_Object to the corresponding EMACS_INT and vice versa.
596 At the machine level, these operations are no-ops. */
598 INLINE EMACS_INT
599 (XLI) (Lisp_Object o)
601 return lisp_h_XLI (o);
604 INLINE Lisp_Object
605 (XIL) (EMACS_INT i)
607 return lisp_h_XIL (i);
610 /* Extract A's type. */
612 INLINE enum Lisp_Type
613 (XTYPE) (Lisp_Object a)
615 #if USE_LSB_TAG
616 return lisp_h_XTYPE (a);
617 #else
618 EMACS_UINT i = XLI (a);
619 return USE_LSB_TAG ? i & ~VALMASK : i >> VALBITS;
620 #endif
623 INLINE void
624 (CHECK_TYPE) (int ok, Lisp_Object predicate, Lisp_Object x)
626 lisp_h_CHECK_TYPE (ok, predicate, x);
629 /* Extract A's pointer value, assuming A's type is TYPE. */
631 INLINE void *
632 (XUNTAG) (Lisp_Object a, int type)
634 #if USE_LSB_TAG
635 return lisp_h_XUNTAG (a, type);
636 #else
637 intptr_t i = USE_LSB_TAG ? XLI (a) - type : XLI (a) & VALMASK;
638 return (void *) i;
639 #endif
643 /* Interned state of a symbol. */
645 enum symbol_interned
647 SYMBOL_UNINTERNED = 0,
648 SYMBOL_INTERNED = 1,
649 SYMBOL_INTERNED_IN_INITIAL_OBARRAY = 2
652 enum symbol_redirect
654 SYMBOL_PLAINVAL = 4,
655 SYMBOL_VARALIAS = 1,
656 SYMBOL_LOCALIZED = 2,
657 SYMBOL_FORWARDED = 3
660 enum symbol_trapped_write
662 SYMBOL_UNTRAPPED_WRITE = 0,
663 SYMBOL_NOWRITE = 1,
664 SYMBOL_TRAPPED_WRITE = 2
667 struct Lisp_Symbol
669 bool_bf gcmarkbit : 1;
671 /* Indicates where the value can be found:
672 0 : it's a plain var, the value is in the `value' field.
673 1 : it's a varalias, the value is really in the `alias' symbol.
674 2 : it's a localized var, the value is in the `blv' object.
675 3 : it's a forwarding variable, the value is in `forward'. */
676 ENUM_BF (symbol_redirect) redirect : 3;
678 /* 0 : normal case, just set the value
679 1 : constant, cannot set, e.g. nil, t, :keywords.
680 2 : trap the write, call watcher functions. */
681 ENUM_BF (symbol_trapped_write) trapped_write : 2;
683 /* Interned state of the symbol. This is an enumerator from
684 enum symbol_interned. */
685 unsigned interned : 2;
687 /* True means that this variable has been explicitly declared
688 special (with `defvar' etc), and shouldn't be lexically bound. */
689 bool_bf declared_special : 1;
691 /* True if pointed to from purespace and hence can't be GC'd. */
692 bool_bf pinned : 1;
694 /* The symbol's name, as a Lisp string. */
695 Lisp_Object name;
697 /* Value of the symbol or Qunbound if unbound. Which alternative of the
698 union is used depends on the `redirect' field above. */
699 union {
700 Lisp_Object value;
701 struct Lisp_Symbol *alias;
702 struct Lisp_Buffer_Local_Value *blv;
703 union Lisp_Fwd *fwd;
704 } val;
706 /* Function value of the symbol or Qnil if not fboundp. */
707 Lisp_Object function;
709 /* The symbol's property list. */
710 Lisp_Object plist;
712 /* Next symbol in obarray bucket, if the symbol is interned. */
713 struct Lisp_Symbol *next;
716 /* Declare a Lisp-callable function. The MAXARGS parameter has the same
717 meaning as in the DEFUN macro, and is used to construct a prototype. */
718 /* We can use the same trick as in the DEFUN macro to generate the
719 appropriate prototype. */
720 #define EXFUN(fnname, maxargs) \
721 extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
723 /* Note that the weird token-substitution semantics of ANSI C makes
724 this work for MANY and UNEVALLED. */
725 #define DEFUN_ARGS_MANY (ptrdiff_t, Lisp_Object *)
726 #define DEFUN_ARGS_UNEVALLED (Lisp_Object)
727 #define DEFUN_ARGS_0 (void)
728 #define DEFUN_ARGS_1 (Lisp_Object)
729 #define DEFUN_ARGS_2 (Lisp_Object, Lisp_Object)
730 #define DEFUN_ARGS_3 (Lisp_Object, Lisp_Object, Lisp_Object)
731 #define DEFUN_ARGS_4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
732 #define DEFUN_ARGS_5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
733 Lisp_Object)
734 #define DEFUN_ARGS_6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
735 Lisp_Object, Lisp_Object)
736 #define DEFUN_ARGS_7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
737 Lisp_Object, Lisp_Object, Lisp_Object)
738 #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
739 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
741 /* Yield a signed integer that contains TAG along with PTR.
743 Sign-extend pointers when USE_LSB_TAG (this simplifies emacs-module.c),
744 and zero-extend otherwise (that’s a bit faster here).
745 Sign extension matters only when EMACS_INT is wider than a pointer. */
746 #define TAG_PTR(tag, ptr) \
747 (USE_LSB_TAG \
748 ? (intptr_t) (ptr) + (tag) \
749 : (EMACS_INT) (((EMACS_UINT) (tag) << VALBITS) + (uintptr_t) (ptr)))
751 /* Yield an integer that contains a symbol tag along with OFFSET.
752 OFFSET should be the offset in bytes from 'lispsym' to the symbol. */
753 #define TAG_SYMOFFSET(offset) TAG_PTR (Lisp_Symbol, offset)
755 /* XLI_BUILTIN_LISPSYM (iQwhatever) is equivalent to
756 XLI (builtin_lisp_symbol (Qwhatever)),
757 except the former expands to an integer constant expression. */
758 #define XLI_BUILTIN_LISPSYM(iname) TAG_SYMOFFSET ((iname) * sizeof *lispsym)
760 /* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is
761 designed for use as an initializer, even for a constant initializer. */
762 #define LISPSYM_INITIALLY(name) LISP_INITIALLY (XLI_BUILTIN_LISPSYM (i##name))
764 /* Declare extern constants for Lisp symbols. These can be helpful
765 when using a debugger like GDB, on older platforms where the debug
766 format does not represent C macros. */
767 #define DEFINE_LISP_SYMBOL(name) \
768 DEFINE_GDB_SYMBOL_BEGIN (Lisp_Object, name) \
769 DEFINE_GDB_SYMBOL_END (LISPSYM_INITIALLY (name))
771 /* The index of the C-defined Lisp symbol SYM.
772 This can be used in a static initializer. */
773 #define SYMBOL_INDEX(sym) i##sym
775 /* By default, define macros for Qt, etc., as this leads to a bit
776 better performance in the core Emacs interpreter. A plugin can
777 define DEFINE_NON_NIL_Q_SYMBOL_MACROS to be false, to be portable to
778 other Emacs instances that assign different values to Qt, etc. */
779 #ifndef DEFINE_NON_NIL_Q_SYMBOL_MACROS
780 # define DEFINE_NON_NIL_Q_SYMBOL_MACROS true
781 #endif
783 #include "globals.h"
785 /* Header of vector-like objects. This documents the layout constraints on
786 vectors and pseudovectors (objects of PVEC_xxx subtype). It also prevents
787 compilers from being fooled by Emacs's type punning: XSETPSEUDOVECTOR
788 and PSEUDOVECTORP cast their pointers to struct vectorlike_header *,
789 because when two such pointers potentially alias, a compiler won't
790 incorrectly reorder loads and stores to their size fields. See
791 Bug#8546. */
792 struct vectorlike_header
794 /* The only field contains various pieces of information:
795 - The MSB (ARRAY_MARK_FLAG) holds the gcmarkbit.
796 - The next bit (PSEUDOVECTOR_FLAG) indicates whether this is a plain
797 vector (0) or a pseudovector (1).
798 - If PSEUDOVECTOR_FLAG is 0, the rest holds the size (number
799 of slots) of the vector.
800 - If PSEUDOVECTOR_FLAG is 1, the rest is subdivided into three fields:
801 - a) pseudovector subtype held in PVEC_TYPE_MASK field;
802 - b) number of Lisp_Objects slots at the beginning of the object
803 held in PSEUDOVECTOR_SIZE_MASK field. These objects are always
804 traced by the GC;
805 - c) size of the rest fields held in PSEUDOVECTOR_REST_MASK and
806 measured in word_size units. Rest fields may also include
807 Lisp_Objects, but these objects usually needs some special treatment
808 during GC.
809 There are some exceptions. For PVEC_FREE, b) is always zero. For
810 PVEC_BOOL_VECTOR and PVEC_SUBR, both b) and c) are always zero.
811 Current layout limits the pseudovectors to 63 PVEC_xxx subtypes,
812 4095 Lisp_Objects in GC-ed area and 4095 word-sized other slots. */
813 ptrdiff_t size;
816 INLINE bool
817 (SYMBOLP) (Lisp_Object x)
819 return lisp_h_SYMBOLP (x);
822 INLINE struct Lisp_Symbol *
823 (XSYMBOL) (Lisp_Object a)
825 #if USE_LSB_TAG
826 return lisp_h_XSYMBOL (a);
827 #else
828 eassert (SYMBOLP (a));
829 intptr_t i = (intptr_t) XUNTAG (a, Lisp_Symbol);
830 void *p = (char *) lispsym + i;
831 return p;
832 #endif
835 INLINE Lisp_Object
836 make_lisp_symbol (struct Lisp_Symbol *sym)
838 Lisp_Object a = XIL (TAG_SYMOFFSET ((char *) sym - (char *) lispsym));
839 eassert (XSYMBOL (a) == sym);
840 return a;
843 INLINE Lisp_Object
844 builtin_lisp_symbol (int index)
846 return make_lisp_symbol (&lispsym[index].s);
849 INLINE void
850 (CHECK_SYMBOL) (Lisp_Object x)
852 lisp_h_CHECK_SYMBOL (x);
855 /* In the size word of a vector, this bit means the vector has been marked. */
857 DEFINE_GDB_SYMBOL_BEGIN (ptrdiff_t, ARRAY_MARK_FLAG)
858 # define ARRAY_MARK_FLAG PTRDIFF_MIN
859 DEFINE_GDB_SYMBOL_END (ARRAY_MARK_FLAG)
861 /* In the size word of a struct Lisp_Vector, this bit means it's really
862 some other vector-like object. */
863 DEFINE_GDB_SYMBOL_BEGIN (ptrdiff_t, PSEUDOVECTOR_FLAG)
864 # define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
865 DEFINE_GDB_SYMBOL_END (PSEUDOVECTOR_FLAG)
867 /* In a pseudovector, the size field actually contains a word with one
868 PSEUDOVECTOR_FLAG bit set, and one of the following values extracted
869 with PVEC_TYPE_MASK to indicate the actual type. */
870 enum pvec_type
872 PVEC_NORMAL_VECTOR,
873 PVEC_FREE,
874 PVEC_PROCESS,
875 PVEC_FRAME,
876 PVEC_WINDOW,
877 PVEC_BOOL_VECTOR,
878 PVEC_BUFFER,
879 PVEC_HASH_TABLE,
880 PVEC_TERMINAL,
881 PVEC_WINDOW_CONFIGURATION,
882 PVEC_SUBR,
883 PVEC_OTHER, /* Should never be visible to Elisp code. */
884 PVEC_XWIDGET,
885 PVEC_XWIDGET_VIEW,
886 PVEC_THREAD,
887 PVEC_MUTEX,
888 PVEC_CONDVAR,
889 PVEC_MODULE_FUNCTION,
891 /* These should be last, check internal_equal to see why. */
892 PVEC_COMPILED,
893 PVEC_CHAR_TABLE,
894 PVEC_SUB_CHAR_TABLE,
895 PVEC_RECORD,
896 PVEC_FONT /* Should be last because it's used for range checking. */
899 enum More_Lisp_Bits
901 /* For convenience, we also store the number of elements in these bits.
902 Note that this size is not necessarily the memory-footprint size, but
903 only the number of Lisp_Object fields (that need to be traced by GC).
904 The distinction is used, e.g., by Lisp_Process, which places extra
905 non-Lisp_Object fields at the end of the structure. */
906 PSEUDOVECTOR_SIZE_BITS = 12,
907 PSEUDOVECTOR_SIZE_MASK = (1 << PSEUDOVECTOR_SIZE_BITS) - 1,
909 /* To calculate the memory footprint of the pseudovector, it's useful
910 to store the size of non-Lisp area in word_size units here. */
911 PSEUDOVECTOR_REST_BITS = 12,
912 PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1)
913 << PSEUDOVECTOR_SIZE_BITS),
915 /* Used to extract pseudovector subtype information. */
916 PSEUDOVECTOR_AREA_BITS = PSEUDOVECTOR_SIZE_BITS + PSEUDOVECTOR_REST_BITS,
917 PVEC_TYPE_MASK = 0x3f << PSEUDOVECTOR_AREA_BITS
920 /* These functions extract various sorts of values from a Lisp_Object.
921 For example, if tem is a Lisp_Object whose type is Lisp_Cons,
922 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for
923 that cons. */
925 /* Largest and smallest representable fixnum values. These are the C
926 values. They are macros for use in static initializers. */
927 #define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
928 #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
930 #if USE_LSB_TAG
932 INLINE Lisp_Object
933 (make_number) (EMACS_INT n)
935 return lisp_h_make_number (n);
938 INLINE EMACS_INT
939 (XINT) (Lisp_Object a)
941 return lisp_h_XINT (a);
944 INLINE EMACS_INT
945 (XFASTINT) (Lisp_Object a)
947 EMACS_INT n = lisp_h_XFASTINT (a);
948 eassume (0 <= n);
949 return n;
952 #else /* ! USE_LSB_TAG */
954 /* Although compiled only if ! USE_LSB_TAG, the following functions
955 also work when USE_LSB_TAG; this is to aid future maintenance when
956 the lisp_h_* macros are eventually removed. */
958 /* Make a Lisp integer representing the value of the low order
959 bits of N. */
960 INLINE Lisp_Object
961 make_number (EMACS_INT n)
963 EMACS_INT int0 = Lisp_Int0;
964 if (USE_LSB_TAG)
966 EMACS_UINT u = n;
967 n = u << INTTYPEBITS;
968 n += int0;
970 else
972 n &= INTMASK;
973 n += (int0 << VALBITS);
975 return XIL (n);
978 /* Extract A's value as a signed integer. */
979 INLINE EMACS_INT
980 XINT (Lisp_Object a)
982 EMACS_INT i = XLI (a);
983 if (! USE_LSB_TAG)
985 EMACS_UINT u = i;
986 i = u << INTTYPEBITS;
988 return i >> INTTYPEBITS;
991 /* Like XINT (A), but may be faster. A must be nonnegative.
992 If ! USE_LSB_TAG, this takes advantage of the fact that Lisp
993 integers have zero-bits in their tags. */
994 INLINE EMACS_INT
995 XFASTINT (Lisp_Object a)
997 EMACS_INT int0 = Lisp_Int0;
998 EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) - (int0 << VALBITS);
999 eassume (0 <= n);
1000 return n;
1003 #endif /* ! USE_LSB_TAG */
1005 /* Extract A's value as an unsigned integer. */
1006 INLINE EMACS_UINT
1007 XUINT (Lisp_Object a)
1009 EMACS_UINT i = XLI (a);
1010 return USE_LSB_TAG ? i >> INTTYPEBITS : i & INTMASK;
1013 /* Return A's (Lisp-integer sized) hash. Happens to be like XUINT
1014 right now, but XUINT should only be applied to objects we know are
1015 integers. */
1017 INLINE EMACS_INT
1018 (XHASH) (Lisp_Object a)
1020 return lisp_h_XHASH (a);
1023 /* Like make_number (N), but may be faster. N must be in nonnegative range. */
1024 INLINE Lisp_Object
1025 make_natnum (EMACS_INT n)
1027 eassert (0 <= n && n <= MOST_POSITIVE_FIXNUM);
1028 EMACS_INT int0 = Lisp_Int0;
1029 return USE_LSB_TAG ? make_number (n) : XIL (n + (int0 << VALBITS));
1032 /* Return true if X and Y are the same object. */
1034 INLINE bool
1035 (EQ) (Lisp_Object x, Lisp_Object y)
1037 return lisp_h_EQ (x, y);
1040 /* True if the possibly-unsigned integer I doesn't fit in a Lisp fixnum. */
1042 #define FIXNUM_OVERFLOW_P(i) \
1043 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
1045 INLINE ptrdiff_t
1046 clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
1048 return num < lower ? lower : num <= upper ? num : upper;
1051 /* Construct a Lisp_Object from a value or address. */
1053 INLINE Lisp_Object
1054 make_lisp_ptr (void *ptr, enum Lisp_Type type)
1056 Lisp_Object a = XIL (TAG_PTR (type, ptr));
1057 eassert (XTYPE (a) == type && XUNTAG (a, type) == ptr);
1058 return a;
1061 INLINE bool
1062 (INTEGERP) (Lisp_Object x)
1064 return lisp_h_INTEGERP (x);
1067 #define XSETINT(a, b) ((a) = make_number (b))
1068 #define XSETFASTINT(a, b) ((a) = make_natnum (b))
1069 #define XSETCONS(a, b) ((a) = make_lisp_ptr (b, Lisp_Cons))
1070 #define XSETVECTOR(a, b) ((a) = make_lisp_ptr (b, Lisp_Vectorlike))
1071 #define XSETSTRING(a, b) ((a) = make_lisp_ptr (b, Lisp_String))
1072 #define XSETSYMBOL(a, b) ((a) = make_lisp_symbol (b))
1073 #define XSETFLOAT(a, b) ((a) = make_lisp_ptr (b, Lisp_Float))
1074 #define XSETMISC(a, b) ((a) = make_lisp_ptr (b, Lisp_Misc))
1076 /* Pseudovector types. */
1078 #define XSETPVECTYPE(v, code) \
1079 ((v)->header.size |= PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS))
1080 #define XSETPVECTYPESIZE(v, code, lispsize, restsize) \
1081 ((v)->header.size = (PSEUDOVECTOR_FLAG \
1082 | ((code) << PSEUDOVECTOR_AREA_BITS) \
1083 | ((restsize) << PSEUDOVECTOR_SIZE_BITS) \
1084 | (lispsize)))
1086 /* The cast to struct vectorlike_header * avoids aliasing issues. */
1087 #define XSETPSEUDOVECTOR(a, b, code) \
1088 XSETTYPED_PSEUDOVECTOR (a, b, \
1089 (((struct vectorlike_header *) \
1090 XUNTAG (a, Lisp_Vectorlike)) \
1091 ->size), \
1092 code)
1093 #define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \
1094 (XSETVECTOR (a, b), \
1095 eassert ((size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) \
1096 == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS))))
1098 #define XSETWINDOW_CONFIGURATION(a, b) \
1099 (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW_CONFIGURATION))
1100 #define XSETPROCESS(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_PROCESS))
1101 #define XSETWINDOW(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW))
1102 #define XSETTERMINAL(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_TERMINAL))
1103 #define XSETSUBR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUBR))
1104 #define XSETCOMPILED(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_COMPILED))
1105 #define XSETBUFFER(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BUFFER))
1106 #define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE))
1107 #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
1108 #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
1109 #define XSETTHREAD(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_THREAD))
1110 #define XSETMUTEX(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_MUTEX))
1111 #define XSETCONDVAR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CONDVAR))
1113 /* Efficiently convert a pointer to a Lisp object and back. The
1114 pointer is represented as a Lisp integer, so the garbage collector
1115 does not know about it. The pointer should not have both Lisp_Int1
1116 bits set, which makes this conversion inherently unportable. */
1118 INLINE void *
1119 XINTPTR (Lisp_Object a)
1121 return XUNTAG (a, Lisp_Int0);
1124 INLINE Lisp_Object
1125 make_pointer_integer (void *p)
1127 Lisp_Object a = XIL (TAG_PTR (Lisp_Int0, p));
1128 eassert (INTEGERP (a) && XINTPTR (a) == p);
1129 return a;
1132 /* See the macros in intervals.h. */
1134 typedef struct interval *INTERVAL;
1136 struct GCALIGNED Lisp_Cons
1138 /* Car of this cons cell. */
1139 Lisp_Object car;
1141 union
1143 /* Cdr of this cons cell. */
1144 Lisp_Object cdr;
1146 /* Used to chain conses on a free list. */
1147 struct Lisp_Cons *chain;
1148 } u;
1151 INLINE bool
1152 (NILP) (Lisp_Object x)
1154 return lisp_h_NILP (x);
1157 INLINE bool
1158 (CONSP) (Lisp_Object x)
1160 return lisp_h_CONSP (x);
1163 INLINE void
1164 CHECK_CONS (Lisp_Object x)
1166 CHECK_TYPE (CONSP (x), Qconsp, x);
1169 INLINE struct Lisp_Cons *
1170 (XCONS) (Lisp_Object a)
1172 return lisp_h_XCONS (a);
1175 /* Take the car or cdr of something known to be a cons cell. */
1176 /* The _addr functions shouldn't be used outside of the minimal set
1177 of code that has to know what a cons cell looks like. Other code not
1178 part of the basic lisp implementation should assume that the car and cdr
1179 fields are not accessible. (What if we want to switch to
1180 a copying collector someday? Cached cons cell field addresses may be
1181 invalidated at arbitrary points.) */
1182 INLINE Lisp_Object *
1183 xcar_addr (Lisp_Object c)
1185 return &XCONS (c)->car;
1187 INLINE Lisp_Object *
1188 xcdr_addr (Lisp_Object c)
1190 return &XCONS (c)->u.cdr;
1193 /* Use these from normal code. */
1195 INLINE Lisp_Object
1196 (XCAR) (Lisp_Object c)
1198 return lisp_h_XCAR (c);
1201 INLINE Lisp_Object
1202 (XCDR) (Lisp_Object c)
1204 return lisp_h_XCDR (c);
1207 /* Use these to set the fields of a cons cell.
1209 Note that both arguments may refer to the same object, so 'n'
1210 should not be read after 'c' is first modified. */
1211 INLINE void
1212 XSETCAR (Lisp_Object c, Lisp_Object n)
1214 *xcar_addr (c) = n;
1216 INLINE void
1217 XSETCDR (Lisp_Object c, Lisp_Object n)
1219 *xcdr_addr (c) = n;
1222 /* Take the car or cdr of something whose type is not known. */
1223 INLINE Lisp_Object
1224 CAR (Lisp_Object c)
1226 if (CONSP (c))
1227 return XCAR (c);
1228 if (!NILP (c))
1229 wrong_type_argument (Qlistp, c);
1230 return Qnil;
1232 INLINE Lisp_Object
1233 CDR (Lisp_Object c)
1235 if (CONSP (c))
1236 return XCDR (c);
1237 if (!NILP (c))
1238 wrong_type_argument (Qlistp, c);
1239 return Qnil;
1242 /* Take the car or cdr of something whose type is not known. */
1243 INLINE Lisp_Object
1244 CAR_SAFE (Lisp_Object c)
1246 return CONSP (c) ? XCAR (c) : Qnil;
1248 INLINE Lisp_Object
1249 CDR_SAFE (Lisp_Object c)
1251 return CONSP (c) ? XCDR (c) : Qnil;
1254 /* In a string or vector, the sign bit of the `size' is the gc mark bit. */
1256 struct GCALIGNED Lisp_String
1258 ptrdiff_t size;
1259 ptrdiff_t size_byte;
1260 INTERVAL intervals; /* Text properties in this string. */
1261 unsigned char *data;
1264 INLINE bool
1265 STRINGP (Lisp_Object x)
1267 return XTYPE (x) == Lisp_String;
1270 INLINE void
1271 CHECK_STRING (Lisp_Object x)
1273 CHECK_TYPE (STRINGP (x), Qstringp, x);
1276 INLINE struct Lisp_String *
1277 XSTRING (Lisp_Object a)
1279 eassert (STRINGP (a));
1280 return XUNTAG (a, Lisp_String);
1283 /* True if STR is a multibyte string. */
1284 INLINE bool
1285 STRING_MULTIBYTE (Lisp_Object str)
1287 return 0 <= XSTRING (str)->size_byte;
1290 /* An upper bound on the number of bytes in a Lisp string, not
1291 counting the terminating null. This a tight enough bound to
1292 prevent integer overflow errors that would otherwise occur during
1293 string size calculations. A string cannot contain more bytes than
1294 a fixnum can represent, nor can it be so long that C pointer
1295 arithmetic stops working on the string plus its terminating null.
1296 Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
1297 may be a bit smaller than STRING_BYTES_BOUND, calculating it here
1298 would expose alloc.c internal details that we'd rather keep
1299 private.
1301 This is a macro for use in static initializers. The cast to
1302 ptrdiff_t ensures that the macro is signed. */
1303 #define STRING_BYTES_BOUND \
1304 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1))
1306 /* Mark STR as a unibyte string. */
1307 #define STRING_SET_UNIBYTE(STR) \
1308 do { \
1309 if (XSTRING (STR)->size == 0) \
1310 (STR) = empty_unibyte_string; \
1311 else \
1312 XSTRING (STR)->size_byte = -1; \
1313 } while (false)
1315 /* Mark STR as a multibyte string. Assure that STR contains only
1316 ASCII characters in advance. */
1317 #define STRING_SET_MULTIBYTE(STR) \
1318 do { \
1319 if (XSTRING (STR)->size == 0) \
1320 (STR) = empty_multibyte_string; \
1321 else \
1322 XSTRING (STR)->size_byte = XSTRING (STR)->size; \
1323 } while (false)
1325 /* Convenience functions for dealing with Lisp strings. */
1327 INLINE unsigned char *
1328 SDATA (Lisp_Object string)
1330 return XSTRING (string)->data;
1332 INLINE char *
1333 SSDATA (Lisp_Object string)
1335 /* Avoid "differ in sign" warnings. */
1336 return (char *) SDATA (string);
1338 INLINE unsigned char
1339 SREF (Lisp_Object string, ptrdiff_t index)
1341 return SDATA (string)[index];
1343 INLINE void
1344 SSET (Lisp_Object string, ptrdiff_t index, unsigned char new)
1346 SDATA (string)[index] = new;
1348 INLINE ptrdiff_t
1349 SCHARS (Lisp_Object string)
1351 ptrdiff_t nchars = XSTRING (string)->size;
1352 eassume (0 <= nchars);
1353 return nchars;
1356 #ifdef GC_CHECK_STRING_BYTES
1357 extern ptrdiff_t string_bytes (struct Lisp_String *);
1358 #endif
1359 INLINE ptrdiff_t
1360 STRING_BYTES (struct Lisp_String *s)
1362 #ifdef GC_CHECK_STRING_BYTES
1363 ptrdiff_t nbytes = string_bytes (s);
1364 #else
1365 ptrdiff_t nbytes = s->size_byte < 0 ? s->size : s->size_byte;
1366 #endif
1367 eassume (0 <= nbytes);
1368 return nbytes;
1371 INLINE ptrdiff_t
1372 SBYTES (Lisp_Object string)
1374 return STRING_BYTES (XSTRING (string));
1376 INLINE void
1377 STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize)
1379 /* This function cannot change the size of data allocated for the
1380 string when it was created. */
1381 eassert (STRING_MULTIBYTE (string)
1382 ? 0 <= newsize && newsize <= SBYTES (string)
1383 : newsize == SCHARS (string));
1384 XSTRING (string)->size = newsize;
1387 /* A regular vector is just a header plus an array of Lisp_Objects. */
1389 struct Lisp_Vector
1391 struct vectorlike_header header;
1392 Lisp_Object contents[FLEXIBLE_ARRAY_MEMBER];
1395 INLINE bool
1396 (VECTORLIKEP) (Lisp_Object x)
1398 return lisp_h_VECTORLIKEP (x);
1401 INLINE struct Lisp_Vector *
1402 XVECTOR (Lisp_Object a)
1404 eassert (VECTORLIKEP (a));
1405 return XUNTAG (a, Lisp_Vectorlike);
1408 INLINE ptrdiff_t
1409 ASIZE (Lisp_Object array)
1411 ptrdiff_t size = XVECTOR (array)->header.size;
1412 eassume (0 <= size);
1413 return size;
1416 INLINE ptrdiff_t
1417 PVSIZE (Lisp_Object pv)
1419 return ASIZE (pv) & PSEUDOVECTOR_SIZE_MASK;
1422 INLINE bool
1423 VECTORP (Lisp_Object x)
1425 return VECTORLIKEP (x) && ! (ASIZE (x) & PSEUDOVECTOR_FLAG);
1428 INLINE void
1429 CHECK_VECTOR (Lisp_Object x)
1431 CHECK_TYPE (VECTORP (x), Qvectorp, x);
1435 /* A pseudovector is like a vector, but has other non-Lisp components. */
1437 INLINE enum pvec_type
1438 PSEUDOVECTOR_TYPE (struct Lisp_Vector *v)
1440 ptrdiff_t size = v->header.size;
1441 return (size & PSEUDOVECTOR_FLAG
1442 ? (size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS
1443 : PVEC_NORMAL_VECTOR);
1446 /* Can't be used with PVEC_NORMAL_VECTOR. */
1447 INLINE bool
1448 PSEUDOVECTOR_TYPEP (struct vectorlike_header *a, enum pvec_type code)
1450 /* We don't use PSEUDOVECTOR_TYPE here so as to avoid a shift
1451 * operation when `code' is known. */
1452 return ((a->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))
1453 == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS)));
1456 /* True if A is a pseudovector whose code is CODE. */
1457 INLINE bool
1458 PSEUDOVECTORP (Lisp_Object a, int code)
1460 if (! VECTORLIKEP (a))
1461 return false;
1462 else
1464 /* Converting to struct vectorlike_header * avoids aliasing issues. */
1465 struct vectorlike_header *h = XUNTAG (a, Lisp_Vectorlike);
1466 return PSEUDOVECTOR_TYPEP (h, code);
1470 /* A boolvector is a kind of vectorlike, with contents like a string. */
1472 struct Lisp_Bool_Vector
1474 /* HEADER.SIZE is the vector's size field. It doesn't have the real size,
1475 just the subtype information. */
1476 struct vectorlike_header header;
1477 /* This is the size in bits. */
1478 EMACS_INT size;
1479 /* The actual bits, packed into bytes.
1480 Zeros fill out the last word if needed.
1481 The bits are in little-endian order in the bytes, and
1482 the bytes are in little-endian order in the words. */
1483 bits_word data[FLEXIBLE_ARRAY_MEMBER];
1486 /* Some handy constants for calculating sizes
1487 and offsets, mostly of vectorlike objects. */
1489 enum
1491 header_size = offsetof (struct Lisp_Vector, contents),
1492 bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
1493 word_size = sizeof (Lisp_Object)
1496 /* The number of data words and bytes in a bool vector with SIZE bits. */
1498 INLINE EMACS_INT
1499 bool_vector_words (EMACS_INT size)
1501 eassume (0 <= size && size <= EMACS_INT_MAX - (BITS_PER_BITS_WORD - 1));
1502 return (size + BITS_PER_BITS_WORD - 1) / BITS_PER_BITS_WORD;
1505 INLINE EMACS_INT
1506 bool_vector_bytes (EMACS_INT size)
1508 eassume (0 <= size && size <= EMACS_INT_MAX - (BITS_PER_BITS_WORD - 1));
1509 return (size + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR;
1512 INLINE bool
1513 BOOL_VECTOR_P (Lisp_Object a)
1515 return PSEUDOVECTORP (a, PVEC_BOOL_VECTOR);
1518 INLINE void
1519 CHECK_BOOL_VECTOR (Lisp_Object x)
1521 CHECK_TYPE (BOOL_VECTOR_P (x), Qbool_vector_p, x);
1524 INLINE struct Lisp_Bool_Vector *
1525 XBOOL_VECTOR (Lisp_Object a)
1527 eassert (BOOL_VECTOR_P (a));
1528 return XUNTAG (a, Lisp_Vectorlike);
1531 INLINE EMACS_INT
1532 bool_vector_size (Lisp_Object a)
1534 EMACS_INT size = XBOOL_VECTOR (a)->size;
1535 eassume (0 <= size);
1536 return size;
1539 INLINE bits_word *
1540 bool_vector_data (Lisp_Object a)
1542 return XBOOL_VECTOR (a)->data;
1545 INLINE unsigned char *
1546 bool_vector_uchar_data (Lisp_Object a)
1548 return (unsigned char *) bool_vector_data (a);
1551 /* True if A's Ith bit is set. */
1553 INLINE bool
1554 bool_vector_bitref (Lisp_Object a, EMACS_INT i)
1556 eassume (0 <= i && i < bool_vector_size (a));
1557 return !! (bool_vector_uchar_data (a)[i / BOOL_VECTOR_BITS_PER_CHAR]
1558 & (1 << (i % BOOL_VECTOR_BITS_PER_CHAR)));
1561 INLINE Lisp_Object
1562 bool_vector_ref (Lisp_Object a, EMACS_INT i)
1564 return bool_vector_bitref (a, i) ? Qt : Qnil;
1567 /* Set A's Ith bit to B. */
1569 INLINE void
1570 bool_vector_set (Lisp_Object a, EMACS_INT i, bool b)
1572 unsigned char *addr;
1574 eassume (0 <= i && i < bool_vector_size (a));
1575 addr = &bool_vector_uchar_data (a)[i / BOOL_VECTOR_BITS_PER_CHAR];
1577 if (b)
1578 *addr |= 1 << (i % BOOL_VECTOR_BITS_PER_CHAR);
1579 else
1580 *addr &= ~ (1 << (i % BOOL_VECTOR_BITS_PER_CHAR));
1583 /* Conveniences for dealing with Lisp arrays. */
1585 INLINE Lisp_Object
1586 AREF (Lisp_Object array, ptrdiff_t idx)
1588 return XVECTOR (array)->contents[idx];
1591 INLINE Lisp_Object *
1592 aref_addr (Lisp_Object array, ptrdiff_t idx)
1594 return & XVECTOR (array)->contents[idx];
1597 INLINE ptrdiff_t
1598 gc_asize (Lisp_Object array)
1600 /* Like ASIZE, but also can be used in the garbage collector. */
1601 return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG;
1604 INLINE void
1605 ASET (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
1607 eassert (0 <= idx && idx < ASIZE (array));
1608 XVECTOR (array)->contents[idx] = val;
1611 INLINE void
1612 gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
1614 /* Like ASET, but also can be used in the garbage collector:
1615 sweep_weak_table calls set_hash_key etc. while the table is marked. */
1616 eassert (0 <= idx && idx < gc_asize (array));
1617 XVECTOR (array)->contents[idx] = val;
1620 /* True, since Qnil's representation is zero. Every place in the code
1621 that assumes Qnil is zero should verify (NIL_IS_ZERO), to make it easy
1622 to find such assumptions later if we change Qnil to be nonzero. */
1623 enum { NIL_IS_ZERO = XLI_BUILTIN_LISPSYM (iQnil) == 0 };
1625 /* Clear the object addressed by P, with size NBYTES, so that all its
1626 bytes are zero and all its Lisp values are nil. */
1627 INLINE void
1628 memclear (void *p, ptrdiff_t nbytes)
1630 eassert (0 <= nbytes);
1631 verify (NIL_IS_ZERO);
1632 /* Since Qnil is zero, memset suffices. */
1633 memset (p, 0, nbytes);
1636 /* If a struct is made to look like a vector, this macro returns the length
1637 of the shortest vector that would hold that struct. */
1639 #define VECSIZE(type) \
1640 ((sizeof (type) - header_size + word_size - 1) / word_size)
1642 /* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
1643 at the end and we need to compute the number of Lisp_Object fields (the
1644 ones that the GC needs to trace). */
1646 #define PSEUDOVECSIZE(type, nonlispfield) \
1647 ((offsetof (type, nonlispfield) - header_size) / word_size)
1649 /* Compute A OP B, using the unsigned comparison operator OP. A and B
1650 should be integer expressions. This is not the same as
1651 mathematical comparison; for example, UNSIGNED_CMP (0, <, -1)
1652 returns true. For efficiency, prefer plain unsigned comparison if A
1653 and B's sizes both fit (after integer promotion). */
1654 #define UNSIGNED_CMP(a, op, b) \
1655 (max (sizeof ((a) + 0), sizeof ((b) + 0)) <= sizeof (unsigned) \
1656 ? ((a) + (unsigned) 0) op ((b) + (unsigned) 0) \
1657 : ((a) + (uintmax_t) 0) op ((b) + (uintmax_t) 0))
1659 /* True iff C is an ASCII character. */
1660 #define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
1662 /* A char-table is a kind of vectorlike, with contents are like a
1663 vector but with a few other slots. For some purposes, it makes
1664 sense to handle a char-table with type struct Lisp_Vector. An
1665 element of a char table can be any Lisp objects, but if it is a sub
1666 char-table, we treat it a table that contains information of a
1667 specific range of characters. A sub char-table is like a vector but
1668 with two integer fields between the header and Lisp data, which means
1669 that it has to be marked with some precautions (see mark_char_table
1670 in alloc.c). A sub char-table appears only in an element of a char-table,
1671 and there's no way to access it directly from Emacs Lisp program. */
1673 enum CHARTAB_SIZE_BITS
1675 CHARTAB_SIZE_BITS_0 = 6,
1676 CHARTAB_SIZE_BITS_1 = 4,
1677 CHARTAB_SIZE_BITS_2 = 5,
1678 CHARTAB_SIZE_BITS_3 = 7
1681 extern const int chartab_size[4];
1683 struct Lisp_Char_Table
1685 /* HEADER.SIZE is the vector's size field, which also holds the
1686 pseudovector type information. It holds the size, too.
1687 The size counts the defalt, parent, purpose, ascii,
1688 contents, and extras slots. */
1689 struct vectorlike_header header;
1691 /* This holds a default value,
1692 which is used whenever the value for a specific character is nil. */
1693 Lisp_Object defalt;
1695 /* This points to another char table, which we inherit from when the
1696 value for a specific character is nil. The `defalt' slot takes
1697 precedence over this. */
1698 Lisp_Object parent;
1700 /* This is a symbol which says what kind of use this char-table is
1701 meant for. */
1702 Lisp_Object purpose;
1704 /* The bottom sub char-table for characters of the range 0..127. It
1705 is nil if none of ASCII character has a specific value. */
1706 Lisp_Object ascii;
1708 Lisp_Object contents[(1 << CHARTAB_SIZE_BITS_0)];
1710 /* These hold additional data. It is a vector. */
1711 Lisp_Object extras[FLEXIBLE_ARRAY_MEMBER];
1714 INLINE bool
1715 CHAR_TABLE_P (Lisp_Object a)
1717 return PSEUDOVECTORP (a, PVEC_CHAR_TABLE);
1720 INLINE struct Lisp_Char_Table *
1721 XCHAR_TABLE (Lisp_Object a)
1723 eassert (CHAR_TABLE_P (a));
1724 return XUNTAG (a, Lisp_Vectorlike);
1727 struct Lisp_Sub_Char_Table
1729 /* HEADER.SIZE is the vector's size field, which also holds the
1730 pseudovector type information. It holds the size, too. */
1731 struct vectorlike_header header;
1733 /* Depth of this sub char-table. It should be 1, 2, or 3. A sub
1734 char-table of depth 1 contains 16 elements, and each element
1735 covers 4096 (128*32) characters. A sub char-table of depth 2
1736 contains 32 elements, and each element covers 128 characters. A
1737 sub char-table of depth 3 contains 128 elements, and each element
1738 is for one character. */
1739 int depth;
1741 /* Minimum character covered by the sub char-table. */
1742 int min_char;
1744 /* Use set_sub_char_table_contents to set this. */
1745 Lisp_Object contents[FLEXIBLE_ARRAY_MEMBER];
1748 INLINE bool
1749 SUB_CHAR_TABLE_P (Lisp_Object a)
1751 return PSEUDOVECTORP (a, PVEC_SUB_CHAR_TABLE);
1754 INLINE struct Lisp_Sub_Char_Table *
1755 XSUB_CHAR_TABLE (Lisp_Object a)
1757 eassert (SUB_CHAR_TABLE_P (a));
1758 return XUNTAG (a, Lisp_Vectorlike);
1761 INLINE Lisp_Object
1762 CHAR_TABLE_REF_ASCII (Lisp_Object ct, ptrdiff_t idx)
1764 struct Lisp_Char_Table *tbl = NULL;
1765 Lisp_Object val;
1768 tbl = tbl ? XCHAR_TABLE (tbl->parent) : XCHAR_TABLE (ct);
1769 val = (! SUB_CHAR_TABLE_P (tbl->ascii) ? tbl->ascii
1770 : XSUB_CHAR_TABLE (tbl->ascii)->contents[idx]);
1771 if (NILP (val))
1772 val = tbl->defalt;
1774 while (NILP (val) && ! NILP (tbl->parent));
1776 return val;
1779 /* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
1780 characters. Do not check validity of CT. */
1781 INLINE Lisp_Object
1782 CHAR_TABLE_REF (Lisp_Object ct, int idx)
1784 return (ASCII_CHAR_P (idx)
1785 ? CHAR_TABLE_REF_ASCII (ct, idx)
1786 : char_table_ref (ct, idx));
1789 /* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
1790 8-bit European characters. Do not check validity of CT. */
1791 INLINE void
1792 CHAR_TABLE_SET (Lisp_Object ct, int idx, Lisp_Object val)
1794 if (ASCII_CHAR_P (idx) && SUB_CHAR_TABLE_P (XCHAR_TABLE (ct)->ascii))
1795 set_sub_char_table_contents (XCHAR_TABLE (ct)->ascii, idx, val);
1796 else
1797 char_table_set (ct, idx, val);
1800 /* This structure describes a built-in function.
1801 It is generated by the DEFUN macro only.
1802 defsubr makes it into a Lisp object. */
1804 struct Lisp_Subr
1806 struct vectorlike_header header;
1807 union {
1808 Lisp_Object (*a0) (void);
1809 Lisp_Object (*a1) (Lisp_Object);
1810 Lisp_Object (*a2) (Lisp_Object, Lisp_Object);
1811 Lisp_Object (*a3) (Lisp_Object, Lisp_Object, Lisp_Object);
1812 Lisp_Object (*a4) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1813 Lisp_Object (*a5) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1814 Lisp_Object (*a6) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1815 Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1816 Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1817 Lisp_Object (*aUNEVALLED) (Lisp_Object args);
1818 Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
1819 } function;
1820 short min_args, max_args;
1821 const char *symbol_name;
1822 const char *intspec;
1823 EMACS_INT doc;
1826 INLINE bool
1827 SUBRP (Lisp_Object a)
1829 return PSEUDOVECTORP (a, PVEC_SUBR);
1832 INLINE struct Lisp_Subr *
1833 XSUBR (Lisp_Object a)
1835 eassert (SUBRP (a));
1836 return XUNTAG (a, Lisp_Vectorlike);
1839 enum char_table_specials
1841 /* This is the number of slots that every char table must have. This
1842 counts the ordinary slots and the top, defalt, parent, and purpose
1843 slots. */
1844 CHAR_TABLE_STANDARD_SLOTS = PSEUDOVECSIZE (struct Lisp_Char_Table, extras),
1846 /* This is an index of first Lisp_Object field in Lisp_Sub_Char_Table
1847 when the latter is treated as an ordinary Lisp_Vector. */
1848 SUB_CHAR_TABLE_OFFSET = PSEUDOVECSIZE (struct Lisp_Sub_Char_Table, contents)
1851 /* Return the number of "extra" slots in the char table CT. */
1853 INLINE int
1854 CHAR_TABLE_EXTRA_SLOTS (struct Lisp_Char_Table *ct)
1856 return ((ct->header.size & PSEUDOVECTOR_SIZE_MASK)
1857 - CHAR_TABLE_STANDARD_SLOTS);
1860 /* Make sure that sub char-table contents slot is where we think it is. */
1861 verify (offsetof (struct Lisp_Sub_Char_Table, contents)
1862 == (offsetof (struct Lisp_Vector, contents)
1863 + SUB_CHAR_TABLE_OFFSET * sizeof (Lisp_Object)));
1866 /* Save and restore the instruction and environment pointers,
1867 without affecting the signal mask. */
1869 #ifdef HAVE__SETJMP
1870 typedef jmp_buf sys_jmp_buf;
1871 # define sys_setjmp(j) _setjmp (j)
1872 # define sys_longjmp(j, v) _longjmp (j, v)
1873 #elif defined HAVE_SIGSETJMP
1874 typedef sigjmp_buf sys_jmp_buf;
1875 # define sys_setjmp(j) sigsetjmp (j, 0)
1876 # define sys_longjmp(j, v) siglongjmp (j, v)
1877 #else
1878 /* A platform that uses neither _longjmp nor siglongjmp; assume
1879 longjmp does not affect the sigmask. */
1880 typedef jmp_buf sys_jmp_buf;
1881 # define sys_setjmp(j) setjmp (j)
1882 # define sys_longjmp(j, v) longjmp (j, v)
1883 #endif
1885 #include "thread.h"
1887 /***********************************************************************
1888 Symbols
1889 ***********************************************************************/
1891 /* Value is name of symbol. */
1893 INLINE Lisp_Object
1894 (SYMBOL_VAL) (struct Lisp_Symbol *sym)
1896 return lisp_h_SYMBOL_VAL (sym);
1899 INLINE struct Lisp_Symbol *
1900 SYMBOL_ALIAS (struct Lisp_Symbol *sym)
1902 eassume (sym->redirect == SYMBOL_VARALIAS && sym->val.alias);
1903 return sym->val.alias;
1905 INLINE struct Lisp_Buffer_Local_Value *
1906 SYMBOL_BLV (struct Lisp_Symbol *sym)
1908 eassume (sym->redirect == SYMBOL_LOCALIZED && sym->val.blv);
1909 return sym->val.blv;
1911 INLINE union Lisp_Fwd *
1912 SYMBOL_FWD (struct Lisp_Symbol *sym)
1914 eassume (sym->redirect == SYMBOL_FORWARDED && sym->val.fwd);
1915 return sym->val.fwd;
1918 INLINE void
1919 (SET_SYMBOL_VAL) (struct Lisp_Symbol *sym, Lisp_Object v)
1921 lisp_h_SET_SYMBOL_VAL (sym, v);
1924 INLINE void
1925 SET_SYMBOL_ALIAS (struct Lisp_Symbol *sym, struct Lisp_Symbol *v)
1927 eassume (sym->redirect == SYMBOL_VARALIAS && v);
1928 sym->val.alias = v;
1930 INLINE void
1931 SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v)
1933 eassume (sym->redirect == SYMBOL_LOCALIZED && v);
1934 sym->val.blv = v;
1936 INLINE void
1937 SET_SYMBOL_FWD (struct Lisp_Symbol *sym, union Lisp_Fwd *v)
1939 eassume (sym->redirect == SYMBOL_FORWARDED && v);
1940 sym->val.fwd = v;
1943 INLINE Lisp_Object
1944 SYMBOL_NAME (Lisp_Object sym)
1946 return XSYMBOL (sym)->name;
1949 /* Value is true if SYM is an interned symbol. */
1951 INLINE bool
1952 SYMBOL_INTERNED_P (Lisp_Object sym)
1954 return XSYMBOL (sym)->interned != SYMBOL_UNINTERNED;
1957 /* Value is true if SYM is interned in initial_obarray. */
1959 INLINE bool
1960 SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (Lisp_Object sym)
1962 return XSYMBOL (sym)->interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
1965 /* Value is non-zero if symbol cannot be changed through a simple set,
1966 i.e. it's a constant (e.g. nil, t, :keywords), or it has some
1967 watching functions. */
1969 INLINE int
1970 (SYMBOL_TRAPPED_WRITE_P) (Lisp_Object sym)
1972 return lisp_h_SYMBOL_TRAPPED_WRITE_P (sym);
1975 /* Value is non-zero if symbol cannot be changed at all, i.e. it's a
1976 constant (e.g. nil, t, :keywords). Code that actually wants to
1977 write to SYM, should also check whether there are any watching
1978 functions. */
1980 INLINE int
1981 (SYMBOL_CONSTANT_P) (Lisp_Object sym)
1983 return lisp_h_SYMBOL_CONSTANT_P (sym);
1986 /* Placeholder for make-docfile to process. The actual symbol
1987 definition is done by lread.c's defsym. */
1988 #define DEFSYM(sym, name) /* empty */
1991 /***********************************************************************
1992 Hash Tables
1993 ***********************************************************************/
1995 /* The structure of a Lisp hash table. */
1997 struct hash_table_test
1999 /* Name of the function used to compare keys. */
2000 Lisp_Object name;
2002 /* User-supplied hash function, or nil. */
2003 Lisp_Object user_hash_function;
2005 /* User-supplied key comparison function, or nil. */
2006 Lisp_Object user_cmp_function;
2008 /* C function to compare two keys. */
2009 bool (*cmpfn) (struct hash_table_test *t, Lisp_Object, Lisp_Object);
2011 /* C function to compute hash code. */
2012 EMACS_UINT (*hashfn) (struct hash_table_test *t, Lisp_Object);
2015 struct Lisp_Hash_Table
2017 /* This is for Lisp; the hash table code does not refer to it. */
2018 struct vectorlike_header header;
2020 /* Nil if table is non-weak. Otherwise a symbol describing the
2021 weakness of the table. */
2022 Lisp_Object weak;
2024 /* Vector of hash codes. If hash[I] is nil, this means that the
2025 I-th entry is unused. */
2026 Lisp_Object hash;
2028 /* Vector used to chain entries. If entry I is free, next[I] is the
2029 entry number of the next free item. If entry I is non-free,
2030 next[I] is the index of the next entry in the collision chain,
2031 or -1 if there is such entry. */
2032 Lisp_Object next;
2034 /* Bucket vector. An entry of -1 indicates no item is present,
2035 and a nonnegative entry is the index of the first item in
2036 a collision chain. This vector's size can be larger than the
2037 hash table size to reduce collisions. */
2038 Lisp_Object index;
2040 /* Only the fields above are traced normally by the GC. The ones below
2041 `count' are special and are either ignored by the GC or traced in
2042 a special way (e.g. because of weakness). */
2044 /* Number of key/value entries in the table. */
2045 ptrdiff_t count;
2047 /* Index of first free entry in free list, or -1 if none. */
2048 ptrdiff_t next_free;
2050 /* True if the table can be purecopied. The table cannot be
2051 changed afterwards. */
2052 bool pure;
2054 /* Resize hash table when number of entries / table size is >= this
2055 ratio. */
2056 float rehash_threshold;
2058 /* Used when the table is resized. If equal to a negative integer,
2059 the user rehash-size is the integer -REHASH_SIZE, and the new
2060 size is the old size plus -REHASH_SIZE. If positive, the user
2061 rehash-size is the floating-point value REHASH_SIZE + 1, and the
2062 new size is the old size times REHASH_SIZE + 1. */
2063 float rehash_size;
2065 /* Vector of keys and values. The key of item I is found at index
2066 2 * I, the value is found at index 2 * I + 1.
2067 This is gc_marked specially if the table is weak. */
2068 Lisp_Object key_and_value;
2070 /* The comparison and hash functions. */
2071 struct hash_table_test test;
2073 /* Next weak hash table if this is a weak hash table. The head
2074 of the list is in weak_hash_tables. */
2075 struct Lisp_Hash_Table *next_weak;
2079 INLINE bool
2080 HASH_TABLE_P (Lisp_Object a)
2082 return PSEUDOVECTORP (a, PVEC_HASH_TABLE);
2085 INLINE struct Lisp_Hash_Table *
2086 XHASH_TABLE (Lisp_Object a)
2088 eassert (HASH_TABLE_P (a));
2089 return XUNTAG (a, Lisp_Vectorlike);
2092 #define XSET_HASH_TABLE(VAR, PTR) \
2093 (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
2095 /* Value is the key part of entry IDX in hash table H. */
2096 INLINE Lisp_Object
2097 HASH_KEY (struct Lisp_Hash_Table *h, ptrdiff_t idx)
2099 return AREF (h->key_and_value, 2 * idx);
2102 /* Value is the value part of entry IDX in hash table H. */
2103 INLINE Lisp_Object
2104 HASH_VALUE (struct Lisp_Hash_Table *h, ptrdiff_t idx)
2106 return AREF (h->key_and_value, 2 * idx + 1);
2109 /* Value is the hash code computed for entry IDX in hash table H. */
2110 INLINE Lisp_Object
2111 HASH_HASH (struct Lisp_Hash_Table *h, ptrdiff_t idx)
2113 return AREF (h->hash, idx);
2116 /* Value is the size of hash table H. */
2117 INLINE ptrdiff_t
2118 HASH_TABLE_SIZE (struct Lisp_Hash_Table *h)
2120 return ASIZE (h->next);
2123 /* Default size for hash tables if not specified. */
2125 enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
2127 /* Default threshold specifying when to resize a hash table. The
2128 value gives the ratio of current entries in the hash table and the
2129 size of the hash table. */
2131 static float const DEFAULT_REHASH_THRESHOLD = 0.8125;
2133 /* Default factor by which to increase the size of a hash table, minus 1. */
2135 static float const DEFAULT_REHASH_SIZE = 1.5 - 1;
2137 /* Combine two integers X and Y for hashing. The result might not fit
2138 into a Lisp integer. */
2140 INLINE EMACS_UINT
2141 sxhash_combine (EMACS_UINT x, EMACS_UINT y)
2143 return (x << 4) + (x >> (EMACS_INT_WIDTH - 4)) + y;
2146 /* Hash X, returning a value that fits into a fixnum. */
2148 INLINE EMACS_UINT
2149 SXHASH_REDUCE (EMACS_UINT x)
2151 return (x ^ x >> (EMACS_INT_WIDTH - FIXNUM_BITS)) & INTMASK;
2154 /* These structures are used for various misc types. */
2156 struct Lisp_Misc_Any /* Supertype of all Misc types. */
2158 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_??? */
2159 bool_bf gcmarkbit : 1;
2160 unsigned spacer : 15;
2163 INLINE bool
2164 (MISCP) (Lisp_Object x)
2166 return lisp_h_MISCP (x);
2169 INLINE struct Lisp_Misc_Any *
2170 XMISCANY (Lisp_Object a)
2172 eassert (MISCP (a));
2173 return XUNTAG (a, Lisp_Misc);
2176 INLINE enum Lisp_Misc_Type
2177 XMISCTYPE (Lisp_Object a)
2179 return XMISCANY (a)->type;
2182 struct Lisp_Marker
2184 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Marker */
2185 bool_bf gcmarkbit : 1;
2186 unsigned spacer : 13;
2187 /* This flag is temporarily used in the functions
2188 decode/encode_coding_object to record that the marker position
2189 must be adjusted after the conversion. */
2190 bool_bf need_adjustment : 1;
2191 /* True means normal insertion at the marker's position
2192 leaves the marker after the inserted text. */
2193 bool_bf insertion_type : 1;
2194 /* This is the buffer that the marker points into, or 0 if it points nowhere.
2195 Note: a chain of markers can contain markers pointing into different
2196 buffers (the chain is per buffer_text rather than per buffer, so it's
2197 shared between indirect buffers). */
2198 /* This is used for (other than NULL-checking):
2199 - Fmarker_buffer
2200 - Fset_marker: check eq(oldbuf, newbuf) to avoid unchain+rechain.
2201 - unchain_marker: to find the list from which to unchain.
2202 - Fkill_buffer: to only unchain the markers of current indirect buffer.
2204 struct buffer *buffer;
2206 /* The remaining fields are meaningless in a marker that
2207 does not point anywhere. */
2209 /* For markers that point somewhere,
2210 this is used to chain of all the markers in a given buffer. */
2211 /* We could remove it and use an array in buffer_text instead.
2212 That would also allow us to preserve it ordered. */
2213 struct Lisp_Marker *next;
2214 /* This is the char position where the marker points. */
2215 ptrdiff_t charpos;
2216 /* This is the byte position.
2217 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
2218 used to implement the functionality of markers, but rather to (ab)use
2219 markers as a cache for char<->byte mappings). */
2220 ptrdiff_t bytepos;
2223 /* START and END are markers in the overlay's buffer, and
2224 PLIST is the overlay's property list. */
2225 struct Lisp_Overlay
2226 /* An overlay's real data content is:
2227 - plist
2228 - buffer (really there are two buffer pointers, one per marker,
2229 and both points to the same buffer)
2230 - insertion type of both ends (per-marker fields)
2231 - start & start byte (of start marker)
2232 - end & end byte (of end marker)
2233 - next (singly linked list of overlays)
2234 - next fields of start and end markers (singly linked list of markers).
2235 I.e. 9words plus 2 bits, 3words of which are for external linked lists.
2238 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Overlay */
2239 bool_bf gcmarkbit : 1;
2240 unsigned spacer : 15;
2241 struct Lisp_Overlay *next;
2242 Lisp_Object start;
2243 Lisp_Object end;
2244 Lisp_Object plist;
2247 /* Number of bits needed to store one of the values
2248 SAVE_UNUSED..SAVE_OBJECT. */
2249 enum { SAVE_SLOT_BITS = 3 };
2251 /* Number of slots in a save value where save_type is nonzero. */
2252 enum { SAVE_VALUE_SLOTS = 4 };
2254 /* Bit-width and values for struct Lisp_Save_Value's save_type member. */
2256 enum { SAVE_TYPE_BITS = SAVE_VALUE_SLOTS * SAVE_SLOT_BITS + 1 };
2258 /* Types of data which may be saved in a Lisp_Save_Value. */
2260 enum Lisp_Save_Type
2262 SAVE_UNUSED,
2263 SAVE_INTEGER,
2264 SAVE_FUNCPOINTER,
2265 SAVE_POINTER,
2266 SAVE_OBJECT,
2267 SAVE_TYPE_INT_INT = SAVE_INTEGER + (SAVE_INTEGER << SAVE_SLOT_BITS),
2268 SAVE_TYPE_INT_INT_INT
2269 = (SAVE_INTEGER + (SAVE_TYPE_INT_INT << SAVE_SLOT_BITS)),
2270 SAVE_TYPE_OBJ_OBJ = SAVE_OBJECT + (SAVE_OBJECT << SAVE_SLOT_BITS),
2271 SAVE_TYPE_OBJ_OBJ_OBJ = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ << SAVE_SLOT_BITS),
2272 SAVE_TYPE_OBJ_OBJ_OBJ_OBJ
2273 = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ_OBJ << SAVE_SLOT_BITS),
2274 SAVE_TYPE_PTR_INT = SAVE_POINTER + (SAVE_INTEGER << SAVE_SLOT_BITS),
2275 SAVE_TYPE_PTR_OBJ = SAVE_POINTER + (SAVE_OBJECT << SAVE_SLOT_BITS),
2276 SAVE_TYPE_PTR_PTR = SAVE_POINTER + (SAVE_POINTER << SAVE_SLOT_BITS),
2277 SAVE_TYPE_FUNCPTR_PTR_OBJ
2278 = SAVE_FUNCPOINTER + (SAVE_TYPE_PTR_OBJ << SAVE_SLOT_BITS),
2280 /* This has an extra bit indicating it's raw memory. */
2281 SAVE_TYPE_MEMORY = SAVE_TYPE_PTR_INT + (1 << (SAVE_TYPE_BITS - 1))
2284 /* SAVE_SLOT_BITS must be large enough to represent these values. */
2285 verify (((SAVE_UNUSED | SAVE_INTEGER | SAVE_FUNCPOINTER
2286 | SAVE_POINTER | SAVE_OBJECT)
2287 >> SAVE_SLOT_BITS)
2288 == 0);
2290 /* Special object used to hold a different values for later use.
2292 This is mostly used to package C integers and pointers to call
2293 record_unwind_protect when two or more values need to be saved.
2294 For example:
2297 struct my_data *md = get_my_data ();
2298 ptrdiff_t mi = get_my_integer ();
2299 record_unwind_protect (my_unwind, make_save_ptr_int (md, mi));
2302 Lisp_Object my_unwind (Lisp_Object arg)
2304 struct my_data *md = XSAVE_POINTER (arg, 0);
2305 ptrdiff_t mi = XSAVE_INTEGER (arg, 1);
2309 If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the
2310 saved objects and raise eassert if type of the saved object doesn't match
2311 the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2)
2312 and XSAVE_OBJECT (arg, 0) are wrong because nothing was saved in slot 2 and
2313 slot 0 is a pointer. */
2315 typedef void (*voidfuncptr) (void);
2317 struct Lisp_Save_Value
2319 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */
2320 bool_bf gcmarkbit : 1;
2321 unsigned spacer : 32 - (16 + 1 + SAVE_TYPE_BITS);
2323 /* V->data may hold up to SAVE_VALUE_SLOTS entries. The type of
2324 V's data entries are determined by V->save_type. E.g., if
2325 V->save_type == SAVE_TYPE_PTR_OBJ, V->data[0] is a pointer,
2326 V->data[1] is an integer, and V's other data entries are unused.
2328 If V->save_type == SAVE_TYPE_MEMORY, V->data[0].pointer is the address of
2329 a memory area containing V->data[1].integer potential Lisp_Objects. */
2330 ENUM_BF (Lisp_Save_Type) save_type : SAVE_TYPE_BITS;
2331 union {
2332 void *pointer;
2333 voidfuncptr funcpointer;
2334 ptrdiff_t integer;
2335 Lisp_Object object;
2336 } data[SAVE_VALUE_SLOTS];
2339 INLINE bool
2340 SAVE_VALUEP (Lisp_Object x)
2342 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value;
2345 INLINE struct Lisp_Save_Value *
2346 XSAVE_VALUE (Lisp_Object a)
2348 eassert (SAVE_VALUEP (a));
2349 return XUNTAG (a, Lisp_Misc);
2352 /* Return the type of V's Nth saved value. */
2353 INLINE int
2354 save_type (struct Lisp_Save_Value *v, int n)
2356 eassert (0 <= n && n < SAVE_VALUE_SLOTS);
2357 return (v->save_type >> (SAVE_SLOT_BITS * n) & ((1 << SAVE_SLOT_BITS) - 1));
2360 /* Get and set the Nth saved pointer. */
2362 INLINE void *
2363 XSAVE_POINTER (Lisp_Object obj, int n)
2365 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
2366 return XSAVE_VALUE (obj)->data[n].pointer;
2368 INLINE void
2369 set_save_pointer (Lisp_Object obj, int n, void *val)
2371 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
2372 XSAVE_VALUE (obj)->data[n].pointer = val;
2374 INLINE voidfuncptr
2375 XSAVE_FUNCPOINTER (Lisp_Object obj, int n)
2377 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_FUNCPOINTER);
2378 return XSAVE_VALUE (obj)->data[n].funcpointer;
2381 /* Likewise for the saved integer. */
2383 INLINE ptrdiff_t
2384 XSAVE_INTEGER (Lisp_Object obj, int n)
2386 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
2387 return XSAVE_VALUE (obj)->data[n].integer;
2389 INLINE void
2390 set_save_integer (Lisp_Object obj, int n, ptrdiff_t val)
2392 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
2393 XSAVE_VALUE (obj)->data[n].integer = val;
2396 /* Extract Nth saved object. */
2398 INLINE Lisp_Object
2399 XSAVE_OBJECT (Lisp_Object obj, int n)
2401 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_OBJECT);
2402 return XSAVE_VALUE (obj)->data[n].object;
2405 #ifdef HAVE_MODULES
2406 struct Lisp_User_Ptr
2408 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_User_Ptr */
2409 bool_bf gcmarkbit : 1;
2410 unsigned spacer : 15;
2412 void (*finalizer) (void *);
2413 void *p;
2415 #endif
2417 /* A finalizer sentinel. */
2418 struct Lisp_Finalizer
2420 struct Lisp_Misc_Any base;
2422 /* Circular list of all active weak references. */
2423 struct Lisp_Finalizer *prev;
2424 struct Lisp_Finalizer *next;
2426 /* Call FUNCTION when the finalizer becomes unreachable, even if
2427 FUNCTION contains a reference to the finalizer; i.e., call
2428 FUNCTION when it is reachable _only_ through finalizers. */
2429 Lisp_Object function;
2432 INLINE bool
2433 FINALIZERP (Lisp_Object x)
2435 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Finalizer;
2438 INLINE struct Lisp_Finalizer *
2439 XFINALIZER (Lisp_Object a)
2441 eassert (FINALIZERP (a));
2442 return XUNTAG (a, Lisp_Misc);
2445 /* A miscellaneous object, when it's on the free list. */
2446 struct Lisp_Free
2448 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Free */
2449 bool_bf gcmarkbit : 1;
2450 unsigned spacer : 15;
2451 union Lisp_Misc *chain;
2454 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
2455 It uses one of these struct subtypes to get the type field. */
2457 union Lisp_Misc
2459 struct Lisp_Misc_Any u_any; /* Supertype of all Misc types. */
2460 struct Lisp_Free u_free;
2461 struct Lisp_Marker u_marker;
2462 struct Lisp_Overlay u_overlay;
2463 struct Lisp_Save_Value u_save_value;
2464 struct Lisp_Finalizer u_finalizer;
2465 #ifdef HAVE_MODULES
2466 struct Lisp_User_Ptr u_user_ptr;
2467 #endif
2470 INLINE union Lisp_Misc *
2471 XMISC (Lisp_Object a)
2473 return XUNTAG (a, Lisp_Misc);
2476 INLINE bool
2477 (MARKERP) (Lisp_Object x)
2479 return lisp_h_MARKERP (x);
2482 INLINE struct Lisp_Marker *
2483 XMARKER (Lisp_Object a)
2485 eassert (MARKERP (a));
2486 return XUNTAG (a, Lisp_Misc);
2489 INLINE bool
2490 OVERLAYP (Lisp_Object x)
2492 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay;
2495 INLINE struct Lisp_Overlay *
2496 XOVERLAY (Lisp_Object a)
2498 eassert (OVERLAYP (a));
2499 return XUNTAG (a, Lisp_Misc);
2502 #ifdef HAVE_MODULES
2503 INLINE bool
2504 USER_PTRP (Lisp_Object x)
2506 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_User_Ptr;
2509 INLINE struct Lisp_User_Ptr *
2510 XUSER_PTR (Lisp_Object a)
2512 eassert (USER_PTRP (a));
2513 return XUNTAG (a, Lisp_Misc);
2515 #endif
2518 /* Forwarding pointer to an int variable.
2519 This is allowed only in the value cell of a symbol,
2520 and it means that the symbol's value really lives in the
2521 specified int variable. */
2522 struct Lisp_Intfwd
2524 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Int */
2525 EMACS_INT *intvar;
2528 /* Boolean forwarding pointer to an int variable.
2529 This is like Lisp_Intfwd except that the ostensible
2530 "value" of the symbol is t if the bool variable is true,
2531 nil if it is false. */
2532 struct Lisp_Boolfwd
2534 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Bool */
2535 bool *boolvar;
2538 /* Forwarding pointer to a Lisp_Object variable.
2539 This is allowed only in the value cell of a symbol,
2540 and it means that the symbol's value really lives in the
2541 specified variable. */
2542 struct Lisp_Objfwd
2544 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Obj */
2545 Lisp_Object *objvar;
2548 /* Like Lisp_Objfwd except that value lives in a slot in the
2549 current buffer. Value is byte index of slot within buffer. */
2550 struct Lisp_Buffer_Objfwd
2552 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Buffer_Obj */
2553 int offset;
2554 /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp or Qnumberp. */
2555 Lisp_Object predicate;
2558 /* struct Lisp_Buffer_Local_Value is used in a symbol value cell when
2559 the symbol has buffer-local bindings. (Exception:
2560 some buffer-local variables are built-in, with their values stored
2561 in the buffer structure itself. They are handled differently,
2562 using struct Lisp_Buffer_Objfwd.)
2564 The `realvalue' slot holds the variable's current value, or a
2565 forwarding pointer to where that value is kept. This value is the
2566 one that corresponds to the loaded binding. To read or set the
2567 variable, you must first make sure the right binding is loaded;
2568 then you can access the value in (or through) `realvalue'.
2570 `buffer' and `frame' are the buffer and frame for which the loaded
2571 binding was found. If those have changed, to make sure the right
2572 binding is loaded it is necessary to find which binding goes with
2573 the current buffer and selected frame, then load it. To load it,
2574 first unload the previous binding, then copy the value of the new
2575 binding into `realvalue' (or through it). Also update
2576 LOADED-BINDING to point to the newly loaded binding.
2578 `local_if_set' indicates that merely setting the variable creates a
2579 local binding for the current buffer. Otherwise the latter, setting
2580 the variable does not do that; only make-local-variable does that. */
2582 struct Lisp_Buffer_Local_Value
2584 /* True means that merely setting the variable creates a local
2585 binding for the current buffer. */
2586 bool_bf local_if_set : 1;
2587 /* True means that the binding now loaded was found.
2588 Presumably equivalent to (defcell!=valcell). */
2589 bool_bf found : 1;
2590 /* If non-NULL, a forwarding to the C var where it should also be set. */
2591 union Lisp_Fwd *fwd; /* Should never be (Buffer|Kboard)_Objfwd. */
2592 /* The buffer or frame for which the loaded binding was found. */
2593 Lisp_Object where;
2594 /* A cons cell that holds the default value. It has the form
2595 (SYMBOL . DEFAULT-VALUE). */
2596 Lisp_Object defcell;
2597 /* The cons cell from `where's parameter alist.
2598 It always has the form (SYMBOL . VALUE)
2599 Note that if `forward' is non-nil, VALUE may be out of date.
2600 Also if the currently loaded binding is the default binding, then
2601 this is `eq'ual to defcell. */
2602 Lisp_Object valcell;
2605 /* Like Lisp_Objfwd except that value lives in a slot in the
2606 current kboard. */
2607 struct Lisp_Kboard_Objfwd
2609 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Kboard_Obj */
2610 int offset;
2613 union Lisp_Fwd
2615 struct Lisp_Intfwd u_intfwd;
2616 struct Lisp_Boolfwd u_boolfwd;
2617 struct Lisp_Objfwd u_objfwd;
2618 struct Lisp_Buffer_Objfwd u_buffer_objfwd;
2619 struct Lisp_Kboard_Objfwd u_kboard_objfwd;
2622 INLINE enum Lisp_Fwd_Type
2623 XFWDTYPE (union Lisp_Fwd *a)
2625 return a->u_intfwd.type;
2628 INLINE bool
2629 BUFFER_OBJFWDP (union Lisp_Fwd *a)
2631 return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj;
2634 INLINE struct Lisp_Buffer_Objfwd *
2635 XBUFFER_OBJFWD (union Lisp_Fwd *a)
2637 eassert (BUFFER_OBJFWDP (a));
2638 return &a->u_buffer_objfwd;
2641 /* Lisp floating point type. */
2642 struct Lisp_Float
2644 union
2646 double data;
2647 struct Lisp_Float *chain;
2648 } u;
2651 INLINE bool
2652 (FLOATP) (Lisp_Object x)
2654 return lisp_h_FLOATP (x);
2657 INLINE struct Lisp_Float *
2658 XFLOAT (Lisp_Object a)
2660 eassert (FLOATP (a));
2661 return XUNTAG (a, Lisp_Float);
2664 INLINE double
2665 XFLOAT_DATA (Lisp_Object f)
2667 return XFLOAT (f)->u.data;
2670 /* Most hosts nowadays use IEEE floating point, so they use IEC 60559
2671 representations, have infinities and NaNs, and do not trap on
2672 exceptions. Define IEEE_FLOATING_POINT if this host is one of the
2673 typical ones. The C11 macro __STDC_IEC_559__ is close to what is
2674 wanted here, but is not quite right because Emacs does not require
2675 all the features of C11 Annex F (and does not require C11 at all,
2676 for that matter). */
2677 enum
2679 IEEE_FLOATING_POINT
2680 = (FLT_RADIX == 2 && FLT_MANT_DIG == 24
2681 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
2684 /* A character, declared with the following typedef, is a member
2685 of some character set associated with the current buffer. */
2686 #ifndef _UCHAR_T /* Protect against something in ctab.h on AIX. */
2687 #define _UCHAR_T
2688 typedef unsigned char UCHAR;
2689 #endif
2691 /* Meanings of slots in a Lisp_Compiled: */
2693 enum Lisp_Compiled
2695 COMPILED_ARGLIST = 0,
2696 COMPILED_BYTECODE = 1,
2697 COMPILED_CONSTANTS = 2,
2698 COMPILED_STACK_DEPTH = 3,
2699 COMPILED_DOC_STRING = 4,
2700 COMPILED_INTERACTIVE = 5
2703 /* Flag bits in a character. These also get used in termhooks.h.
2704 Richard Stallman <rms@gnu.ai.mit.edu> thinks that MULE
2705 (MUlti-Lingual Emacs) might need 22 bits for the character value
2706 itself, so we probably shouldn't use any bits lower than 0x0400000. */
2707 enum char_bits
2709 CHAR_ALT = 0x0400000,
2710 CHAR_SUPER = 0x0800000,
2711 CHAR_HYPER = 0x1000000,
2712 CHAR_SHIFT = 0x2000000,
2713 CHAR_CTL = 0x4000000,
2714 CHAR_META = 0x8000000,
2716 CHAR_MODIFIER_MASK =
2717 CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META,
2719 /* Actually, the current Emacs uses 22 bits for the character value
2720 itself. */
2721 CHARACTERBITS = 22
2724 /* Data type checking. */
2726 INLINE bool
2727 NUMBERP (Lisp_Object x)
2729 return INTEGERP (x) || FLOATP (x);
2731 INLINE bool
2732 NATNUMP (Lisp_Object x)
2734 return INTEGERP (x) && 0 <= XINT (x);
2737 INLINE bool
2738 RANGED_INTEGERP (intmax_t lo, Lisp_Object x, intmax_t hi)
2740 return INTEGERP (x) && lo <= XINT (x) && XINT (x) <= hi;
2743 #define TYPE_RANGED_INTEGERP(type, x) \
2744 (INTEGERP (x) \
2745 && (TYPE_SIGNED (type) ? TYPE_MINIMUM (type) <= XINT (x) : 0 <= XINT (x)) \
2746 && XINT (x) <= TYPE_MAXIMUM (type))
2748 INLINE bool
2749 AUTOLOADP (Lisp_Object x)
2751 return CONSP (x) && EQ (Qautoload, XCAR (x));
2755 /* Test for specific pseudovector types. */
2757 INLINE bool
2758 WINDOW_CONFIGURATIONP (Lisp_Object a)
2760 return PSEUDOVECTORP (a, PVEC_WINDOW_CONFIGURATION);
2763 INLINE bool
2764 COMPILEDP (Lisp_Object a)
2766 return PSEUDOVECTORP (a, PVEC_COMPILED);
2769 INLINE bool
2770 FRAMEP (Lisp_Object a)
2772 return PSEUDOVECTORP (a, PVEC_FRAME);
2775 INLINE bool
2776 RECORDP (Lisp_Object a)
2778 return PSEUDOVECTORP (a, PVEC_RECORD);
2781 INLINE void
2782 CHECK_RECORD (Lisp_Object x)
2784 CHECK_TYPE (RECORDP (x), Qrecordp, x);
2787 /* Test for image (image . spec) */
2788 INLINE bool
2789 IMAGEP (Lisp_Object x)
2791 return CONSP (x) && EQ (XCAR (x), Qimage);
2794 /* Array types. */
2795 INLINE bool
2796 ARRAYP (Lisp_Object x)
2798 return VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x);
2801 INLINE void
2802 CHECK_LIST (Lisp_Object x)
2804 CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x);
2807 INLINE void
2808 CHECK_LIST_END (Lisp_Object x, Lisp_Object y)
2810 CHECK_TYPE (NILP (x), Qlistp, y);
2813 INLINE void
2814 (CHECK_NUMBER) (Lisp_Object x)
2816 lisp_h_CHECK_NUMBER (x);
2819 INLINE void
2820 CHECK_STRING_CAR (Lisp_Object x)
2822 CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x));
2824 /* This is a bit special because we always need size afterwards. */
2825 INLINE ptrdiff_t
2826 CHECK_VECTOR_OR_STRING (Lisp_Object x)
2828 if (VECTORP (x))
2829 return ASIZE (x);
2830 if (STRINGP (x))
2831 return SCHARS (x);
2832 wrong_type_argument (Qarrayp, x);
2834 INLINE void
2835 CHECK_ARRAY (Lisp_Object x, Lisp_Object predicate)
2837 CHECK_TYPE (ARRAYP (x), predicate, x);
2839 INLINE void
2840 CHECK_NATNUM (Lisp_Object x)
2842 CHECK_TYPE (NATNUMP (x), Qwholenump, x);
2845 #define CHECK_RANGED_INTEGER(x, lo, hi) \
2846 do { \
2847 CHECK_NUMBER (x); \
2848 if (! ((lo) <= XINT (x) && XINT (x) <= (hi))) \
2849 args_out_of_range_3 \
2850 (x, \
2851 make_number ((lo) < 0 && (lo) < MOST_NEGATIVE_FIXNUM \
2852 ? MOST_NEGATIVE_FIXNUM \
2853 : (lo)), \
2854 make_number (min (hi, MOST_POSITIVE_FIXNUM))); \
2855 } while (false)
2856 #define CHECK_TYPE_RANGED_INTEGER(type, x) \
2857 do { \
2858 if (TYPE_SIGNED (type)) \
2859 CHECK_RANGED_INTEGER (x, TYPE_MINIMUM (type), TYPE_MAXIMUM (type)); \
2860 else \
2861 CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
2862 } while (false)
2864 #define CHECK_NUMBER_COERCE_MARKER(x) \
2865 do { \
2866 if (MARKERP ((x))) \
2867 XSETFASTINT (x, marker_position (x)); \
2868 else \
2869 CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); \
2870 } while (false)
2872 INLINE double
2873 XFLOATINT (Lisp_Object n)
2875 return FLOATP (n) ? XFLOAT_DATA (n) : XINT (n);
2878 INLINE void
2879 CHECK_NUMBER_OR_FLOAT (Lisp_Object x)
2881 CHECK_TYPE (NUMBERP (x), Qnumberp, x);
2884 #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \
2885 do { \
2886 if (MARKERP (x)) \
2887 XSETFASTINT (x, marker_position (x)); \
2888 else \
2889 CHECK_TYPE (NUMBERP (x), Qnumber_or_marker_p, x); \
2890 } while (false)
2892 /* Since we can't assign directly to the CAR or CDR fields of a cons
2893 cell, use these when checking that those fields contain numbers. */
2894 INLINE void
2895 CHECK_NUMBER_CAR (Lisp_Object x)
2897 Lisp_Object tmp = XCAR (x);
2898 CHECK_NUMBER (tmp);
2899 XSETCAR (x, tmp);
2902 INLINE void
2903 CHECK_NUMBER_CDR (Lisp_Object x)
2905 Lisp_Object tmp = XCDR (x);
2906 CHECK_NUMBER (tmp);
2907 XSETCDR (x, tmp);
2910 /* Define a built-in function for calling from Lisp.
2911 `lname' should be the name to give the function in Lisp,
2912 as a null-terminated C string.
2913 `fnname' should be the name of the function in C.
2914 By convention, it starts with F.
2915 `sname' should be the name for the C constant structure
2916 that records information on this function for internal use.
2917 By convention, it should be the same as `fnname' but with S instead of F.
2918 It's too bad that C macros can't compute this from `fnname'.
2919 `minargs' should be a number, the minimum number of arguments allowed.
2920 `maxargs' should be a number, the maximum number of arguments allowed,
2921 or else MANY or UNEVALLED.
2922 MANY means pass a vector of evaluated arguments,
2923 in the form of an integer number-of-arguments
2924 followed by the address of a vector of Lisp_Objects
2925 which contains the argument values.
2926 UNEVALLED means pass the list of unevaluated arguments
2927 `intspec' says how interactive arguments are to be fetched.
2928 If the string starts with a `(', `intspec' is evaluated and the resulting
2929 list is the list of arguments.
2930 If it's a string that doesn't start with `(', the value should follow
2931 the one of the doc string for `interactive'.
2932 A null string means call interactively with no arguments.
2933 `doc' is documentation for the user. */
2935 /* This version of DEFUN declares a function prototype with the right
2936 arguments, so we can catch errors with maxargs at compile-time. */
2937 #ifdef _MSC_VER
2938 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
2939 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
2940 static struct Lisp_Subr GCALIGNED sname = \
2941 { { (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS) \
2942 | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)) }, \
2943 { (Lisp_Object (__cdecl *)(void))fnname }, \
2944 minargs, maxargs, lname, intspec, 0}; \
2945 Lisp_Object fnname
2946 #else /* not _MSC_VER */
2947 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
2948 static struct Lisp_Subr GCALIGNED sname = \
2949 { { PVEC_SUBR << PSEUDOVECTOR_AREA_BITS }, \
2950 { .a ## maxargs = fnname }, \
2951 minargs, maxargs, lname, intspec, 0}; \
2952 Lisp_Object fnname
2953 #endif
2955 /* defsubr (Sname);
2956 is how we define the symbol for function `name' at start-up time. */
2957 extern void defsubr (struct Lisp_Subr *);
2959 enum maxargs
2961 MANY = -2,
2962 UNEVALLED = -1
2965 /* Call a function F that accepts many args, passing it ARRAY's elements. */
2966 #define CALLMANY(f, array) (f) (ARRAYELTS (array), array)
2968 /* Call a function F that accepts many args, passing it the remaining args,
2969 E.g., 'return CALLN (Fformat, fmt, text);' is less error-prone than
2970 '{ Lisp_Object a[2]; a[0] = fmt; a[1] = text; return Fformat (2, a); }'.
2971 CALLN is overkill for simple usages like 'Finsert (1, &text);'. */
2972 #define CALLN(f, ...) CALLMANY (f, ((Lisp_Object []) {__VA_ARGS__}))
2974 extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *);
2975 extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *);
2976 extern void defvar_bool (struct Lisp_Boolfwd *, const char *, bool *);
2977 extern void defvar_int (struct Lisp_Intfwd *, const char *, EMACS_INT *);
2978 extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int);
2980 /* Macros we use to define forwarded Lisp variables.
2981 These are used in the syms_of_FILENAME functions.
2983 An ordinary (not in buffer_defaults, per-buffer, or per-keyboard)
2984 lisp variable is actually a field in `struct emacs_globals'. The
2985 field's name begins with "f_", which is a convention enforced by
2986 these macros. Each such global has a corresponding #define in
2987 globals.h; the plain name should be used in the code.
2989 E.g., the global "cons_cells_consed" is declared as "int
2990 f_cons_cells_consed" in globals.h, but there is a define:
2992 #define cons_cells_consed globals.f_cons_cells_consed
2994 All C code uses the `cons_cells_consed' name. This is all done
2995 this way to support indirection for multi-threaded Emacs. */
2997 #define DEFVAR_LISP(lname, vname, doc) \
2998 do { \
2999 static struct Lisp_Objfwd o_fwd; \
3000 defvar_lisp (&o_fwd, lname, &globals.f_ ## vname); \
3001 } while (false)
3002 #define DEFVAR_LISP_NOPRO(lname, vname, doc) \
3003 do { \
3004 static struct Lisp_Objfwd o_fwd; \
3005 defvar_lisp_nopro (&o_fwd, lname, &globals.f_ ## vname); \
3006 } while (false)
3007 #define DEFVAR_BOOL(lname, vname, doc) \
3008 do { \
3009 static struct Lisp_Boolfwd b_fwd; \
3010 defvar_bool (&b_fwd, lname, &globals.f_ ## vname); \
3011 } while (false)
3012 #define DEFVAR_INT(lname, vname, doc) \
3013 do { \
3014 static struct Lisp_Intfwd i_fwd; \
3015 defvar_int (&i_fwd, lname, &globals.f_ ## vname); \
3016 } while (false)
3018 #define DEFVAR_KBOARD(lname, vname, doc) \
3019 do { \
3020 static struct Lisp_Kboard_Objfwd ko_fwd; \
3021 defvar_kboard (&ko_fwd, lname, offsetof (KBOARD, vname ## _)); \
3022 } while (false)
3025 /* Elisp uses several stacks:
3026 - the C stack.
3027 - the bytecode stack: used internally by the bytecode interpreter.
3028 Allocated from the C stack.
3029 - The specpdl stack: keeps track of active unwind-protect and
3030 dynamic-let-bindings. Allocated from the `specpdl' array, a manually
3031 managed stack.
3032 - The handler stack: keeps track of active catch tags and condition-case
3033 handlers. Allocated in a manually managed stack implemented by a
3034 doubly-linked list allocated via xmalloc and never freed. */
3036 /* Structure for recording Lisp call stack for backtrace purposes. */
3038 /* The special binding stack holds the outer values of variables while
3039 they are bound by a function application or a let form, stores the
3040 code to be executed for unwind-protect forms.
3042 NOTE: The specbinding union is defined here, because SPECPDL_INDEX is
3043 used all over the place, needs to be fast, and needs to know the size of
3044 union specbinding. But only eval.c should access it. */
3046 enum specbind_tag {
3047 SPECPDL_UNWIND, /* An unwind_protect function on Lisp_Object. */
3048 SPECPDL_UNWIND_PTR, /* Likewise, on void *. */
3049 SPECPDL_UNWIND_INT, /* Likewise, on int. */
3050 SPECPDL_UNWIND_VOID, /* Likewise, with no arg. */
3051 SPECPDL_BACKTRACE, /* An element of the backtrace. */
3052 SPECPDL_LET, /* A plain and simple dynamic let-binding. */
3053 /* Tags greater than SPECPDL_LET must be "subkinds" of LET. */
3054 SPECPDL_LET_LOCAL, /* A buffer-local let-binding. */
3055 SPECPDL_LET_DEFAULT /* A global binding for a localized var. */
3058 union specbinding
3060 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3061 struct {
3062 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3063 void (*func) (Lisp_Object);
3064 Lisp_Object arg;
3065 } unwind;
3066 struct {
3067 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3068 void (*func) (void *);
3069 void *arg;
3070 } unwind_ptr;
3071 struct {
3072 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3073 void (*func) (int);
3074 int arg;
3075 } unwind_int;
3076 struct {
3077 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3078 void (*func) (void);
3079 } unwind_void;
3080 struct {
3081 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3082 /* `where' is not used in the case of SPECPDL_LET. */
3083 Lisp_Object symbol, old_value, where;
3084 /* Normally this is unused; but it is set to the symbol's
3085 current value when a thread is swapped out. */
3086 Lisp_Object saved_value;
3087 } let;
3088 struct {
3089 ENUM_BF (specbind_tag) kind : CHAR_BIT;
3090 bool_bf debug_on_exit : 1;
3091 Lisp_Object function;
3092 Lisp_Object *args;
3093 ptrdiff_t nargs;
3094 } bt;
3097 /* These 3 are defined as macros in thread.h. */
3098 /* extern union specbinding *specpdl; */
3099 /* extern union specbinding *specpdl_ptr; */
3100 /* extern ptrdiff_t specpdl_size; */
3102 INLINE ptrdiff_t
3103 SPECPDL_INDEX (void)
3105 return specpdl_ptr - specpdl;
3108 /* This structure helps implement the `catch/throw' and `condition-case/signal'
3109 control structures. A struct handler contains all the information needed to
3110 restore the state of the interpreter after a non-local jump.
3112 handler structures are chained together in a doubly linked list; the `next'
3113 member points to the next outer catchtag and the `nextfree' member points in
3114 the other direction to the next inner element (which is typically the next
3115 free element since we mostly use it on the deepest handler).
3117 A call like (throw TAG VAL) searches for a catchtag whose `tag_or_ch'
3118 member is TAG, and then unbinds to it. The `val' member is used to
3119 hold VAL while the stack is unwound; `val' is returned as the value
3120 of the catch form. If there is a handler of type CATCHER_ALL, it will
3121 be treated as a handler for all invocations of `throw'; in this case
3122 `val' will be set to (TAG . VAL).
3124 All the other members are concerned with restoring the interpreter
3125 state.
3127 Members are volatile if their values need to survive _longjmp when
3128 a 'struct handler' is a local variable. */
3130 enum handlertype { CATCHER, CONDITION_CASE, CATCHER_ALL };
3132 struct handler
3134 enum handlertype type;
3135 Lisp_Object tag_or_ch;
3136 Lisp_Object val;
3137 struct handler *next;
3138 struct handler *nextfree;
3140 /* The bytecode interpreter can have several handlers active at the same
3141 time, so when we longjmp to one of them, it needs to know which handler
3142 this was and what was the corresponding internal state. This is stored
3143 here, and when we longjmp we make sure that handlerlist points to the
3144 proper handler. */
3145 Lisp_Object *bytecode_top;
3146 int bytecode_dest;
3148 /* Most global vars are reset to their value via the specpdl mechanism,
3149 but a few others are handled by storing their value here. */
3150 sys_jmp_buf jmp;
3151 EMACS_INT f_lisp_eval_depth;
3152 ptrdiff_t pdlcount;
3153 int poll_suppress_count;
3154 int interrupt_input_blocked;
3157 extern Lisp_Object memory_signal_data;
3159 extern void maybe_quit (void);
3161 /* True if ought to quit now. */
3163 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
3165 /* Process a quit rarely, based on a counter COUNT, for efficiency.
3166 "Rarely" means once per USHRT_MAX + 1 times; this is somewhat
3167 arbitrary, but efficient. */
3169 INLINE void
3170 rarely_quit (unsigned short int count)
3172 if (! count)
3173 maybe_quit ();
3176 extern Lisp_Object Vascii_downcase_table;
3177 extern Lisp_Object Vascii_canon_table;
3179 /* Call staticpro (&var) to protect static variable `var'. */
3181 void staticpro (Lisp_Object *);
3183 /* Forward declarations for prototypes. */
3184 struct window;
3185 struct frame;
3187 /* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET. */
3189 INLINE void
3190 vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
3192 eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
3193 memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
3196 /* Functions to modify hash tables. */
3198 INLINE void
3199 set_hash_key_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
3201 gc_aset (h->key_and_value, 2 * idx, val);
3204 INLINE void
3205 set_hash_value_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
3207 gc_aset (h->key_and_value, 2 * idx + 1, val);
3210 /* Use these functions to set Lisp_Object
3211 or pointer slots of struct Lisp_Symbol. */
3213 INLINE void
3214 set_symbol_function (Lisp_Object sym, Lisp_Object function)
3216 XSYMBOL (sym)->function = function;
3219 INLINE void
3220 set_symbol_plist (Lisp_Object sym, Lisp_Object plist)
3222 XSYMBOL (sym)->plist = plist;
3225 INLINE void
3226 set_symbol_next (Lisp_Object sym, struct Lisp_Symbol *next)
3228 XSYMBOL (sym)->next = next;
3231 INLINE void
3232 make_symbol_constant (Lisp_Object sym)
3234 XSYMBOL (sym)->trapped_write = SYMBOL_NOWRITE;
3237 /* Buffer-local variable access functions. */
3239 INLINE int
3240 blv_found (struct Lisp_Buffer_Local_Value *blv)
3242 eassert (blv->found == !EQ (blv->defcell, blv->valcell));
3243 return blv->found;
3246 /* Set overlay's property list. */
3248 INLINE void
3249 set_overlay_plist (Lisp_Object overlay, Lisp_Object plist)
3251 XOVERLAY (overlay)->plist = plist;
3254 /* Get text properties of S. */
3256 INLINE INTERVAL
3257 string_intervals (Lisp_Object s)
3259 return XSTRING (s)->intervals;
3262 /* Set text properties of S to I. */
3264 INLINE void
3265 set_string_intervals (Lisp_Object s, INTERVAL i)
3267 XSTRING (s)->intervals = i;
3270 /* Set a Lisp slot in TABLE to VAL. Most code should use this instead
3271 of setting slots directly. */
3273 INLINE void
3274 set_char_table_defalt (Lisp_Object table, Lisp_Object val)
3276 XCHAR_TABLE (table)->defalt = val;
3278 INLINE void
3279 set_char_table_purpose (Lisp_Object table, Lisp_Object val)
3281 XCHAR_TABLE (table)->purpose = val;
3284 /* Set different slots in (sub)character tables. */
3286 INLINE void
3287 set_char_table_extras (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
3289 eassert (0 <= idx && idx < CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (table)));
3290 XCHAR_TABLE (table)->extras[idx] = val;
3293 INLINE void
3294 set_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
3296 eassert (0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0));
3297 XCHAR_TABLE (table)->contents[idx] = val;
3300 INLINE void
3301 set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
3303 XSUB_CHAR_TABLE (table)->contents[idx] = val;
3306 /* Defined in data.c. */
3307 extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object);
3308 extern void notify_variable_watchers (Lisp_Object, Lisp_Object,
3309 Lisp_Object, Lisp_Object);
3310 extern Lisp_Object indirect_function (Lisp_Object);
3311 extern Lisp_Object find_symbol_value (Lisp_Object);
3312 enum Arith_Comparison {
3313 ARITH_EQUAL,
3314 ARITH_NOTEQUAL,
3315 ARITH_LESS,
3316 ARITH_GRTR,
3317 ARITH_LESS_OR_EQUAL,
3318 ARITH_GRTR_OR_EQUAL
3320 extern Lisp_Object arithcompare (Lisp_Object num1, Lisp_Object num2,
3321 enum Arith_Comparison comparison);
3323 /* Convert the integer I to an Emacs representation, either the integer
3324 itself, or a cons of two or three integers, or if all else fails a float.
3325 I should not have side effects. */
3326 #define INTEGER_TO_CONS(i) \
3327 (! FIXNUM_OVERFLOW_P (i) \
3328 ? make_number (i) \
3329 : EXPR_SIGNED (i) ? intbig_to_lisp (i) : uintbig_to_lisp (i))
3330 extern Lisp_Object intbig_to_lisp (intmax_t);
3331 extern Lisp_Object uintbig_to_lisp (uintmax_t);
3333 /* Convert the Emacs representation CONS back to an integer of type
3334 TYPE, storing the result the variable VAR. Signal an error if CONS
3335 is not a valid representation or is out of range for TYPE. */
3336 #define CONS_TO_INTEGER(cons, type, var) \
3337 (TYPE_SIGNED (type) \
3338 ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
3339 : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
3340 extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
3341 extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
3343 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
3344 extern _Noreturn void args_out_of_range (Lisp_Object, Lisp_Object);
3345 extern _Noreturn void args_out_of_range_3 (Lisp_Object, Lisp_Object,
3346 Lisp_Object);
3347 extern _Noreturn void circular_list (Lisp_Object);
3348 extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *);
3349 enum Set_Internal_Bind {
3350 SET_INTERNAL_SET,
3351 SET_INTERNAL_BIND,
3352 SET_INTERNAL_UNBIND,
3353 SET_INTERNAL_THREAD_SWITCH
3355 extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object,
3356 enum Set_Internal_Bind);
3357 extern void set_default_internal (Lisp_Object, Lisp_Object,
3358 enum Set_Internal_Bind bindflag);
3360 extern void syms_of_data (void);
3361 extern void swap_in_global_binding (struct Lisp_Symbol *);
3363 /* Defined in cmds.c */
3364 extern void syms_of_cmds (void);
3365 extern void keys_of_cmds (void);
3367 /* Defined in coding.c. */
3368 extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
3369 ptrdiff_t, bool, bool, Lisp_Object);
3370 extern void init_coding (void);
3371 extern void init_coding_once (void);
3372 extern void syms_of_coding (void);
3374 /* Defined in character.c. */
3375 extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
3376 extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
3377 extern void syms_of_character (void);
3379 /* Defined in charset.c. */
3380 extern void init_charset (void);
3381 extern void init_charset_once (void);
3382 extern void syms_of_charset (void);
3383 /* Structure forward declarations. */
3384 struct charset;
3386 /* Defined in syntax.c. */
3387 extern void init_syntax_once (void);
3388 extern void syms_of_syntax (void);
3390 /* Defined in fns.c. */
3391 enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
3392 extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
3393 extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
3394 extern void sweep_weak_hash_tables (void);
3395 extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *);
3396 EMACS_UINT hash_string (char const *, ptrdiff_t);
3397 EMACS_UINT sxhash (Lisp_Object, int);
3398 Lisp_Object make_hash_table (struct hash_table_test, EMACS_INT, float, float,
3399 Lisp_Object, bool);
3400 ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
3401 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
3402 EMACS_UINT);
3403 void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object);
3404 extern struct hash_table_test const hashtest_eq, hashtest_eql, hashtest_equal;
3405 extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
3406 ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
3407 extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
3408 ptrdiff_t, ptrdiff_t);
3409 extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);
3410 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
3411 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
3412 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
3413 extern bool equal_no_quit (Lisp_Object, Lisp_Object);
3414 extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
3415 extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
3416 extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
3417 extern void clear_string_char_byte_cache (void);
3418 extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
3419 extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
3420 extern Lisp_Object string_to_multibyte (Lisp_Object);
3421 extern Lisp_Object string_make_unibyte (Lisp_Object);
3422 extern void syms_of_fns (void);
3424 /* Defined in floatfns.c. */
3425 extern void syms_of_floatfns (void);
3426 extern Lisp_Object fmod_float (Lisp_Object x, Lisp_Object y);
3428 /* Defined in fringe.c. */
3429 extern void syms_of_fringe (void);
3430 extern void init_fringe (void);
3431 #ifdef HAVE_WINDOW_SYSTEM
3432 extern void mark_fringe_data (void);
3433 extern void init_fringe_once (void);
3434 #endif /* HAVE_WINDOW_SYSTEM */
3436 /* Defined in image.c. */
3437 extern int x_bitmap_mask (struct frame *, ptrdiff_t);
3438 extern void reset_image_types (void);
3439 extern void syms_of_image (void);
3441 /* Defined in insdel.c. */
3442 extern void move_gap_both (ptrdiff_t, ptrdiff_t);
3443 extern _Noreturn void buffer_overflow (void);
3444 extern void make_gap (ptrdiff_t);
3445 extern void make_gap_1 (struct buffer *, ptrdiff_t);
3446 extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
3447 ptrdiff_t, bool, bool);
3448 extern int count_combining_before (const unsigned char *,
3449 ptrdiff_t, ptrdiff_t, ptrdiff_t);
3450 extern int count_combining_after (const unsigned char *,
3451 ptrdiff_t, ptrdiff_t, ptrdiff_t);
3452 extern void insert (const char *, ptrdiff_t);
3453 extern void insert_and_inherit (const char *, ptrdiff_t);
3454 extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
3455 bool, bool, bool);
3456 extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
3457 extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
3458 ptrdiff_t, ptrdiff_t, bool);
3459 extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool);
3460 extern void insert_char (int);
3461 extern void insert_string (const char *);
3462 extern void insert_before_markers (const char *, ptrdiff_t);
3463 extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
3464 extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
3465 ptrdiff_t, ptrdiff_t,
3466 ptrdiff_t, bool);
3467 extern void del_range (ptrdiff_t, ptrdiff_t);
3468 extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool);
3469 extern void del_range_byte (ptrdiff_t, ptrdiff_t);
3470 extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
3471 extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
3472 ptrdiff_t, ptrdiff_t, bool);
3473 extern void modify_text (ptrdiff_t, ptrdiff_t);
3474 extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3475 extern void prepare_to_modify_buffer_1 (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3476 extern void invalidate_buffer_caches (struct buffer *, ptrdiff_t, ptrdiff_t);
3477 extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3478 extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3479 ptrdiff_t, ptrdiff_t);
3480 extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
3481 ptrdiff_t, ptrdiff_t);
3482 extern void adjust_markers_bytepos (ptrdiff_t, ptrdiff_t,
3483 ptrdiff_t, ptrdiff_t, int);
3484 extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool, bool);
3485 extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3486 const char *, ptrdiff_t, ptrdiff_t, bool);
3487 extern void syms_of_insdel (void);
3489 /* Defined in dispnew.c. */
3490 #if (defined PROFILING \
3491 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
3492 _Noreturn void __executable_start (void);
3493 #endif
3494 extern Lisp_Object Vwindow_system;
3495 extern Lisp_Object sit_for (Lisp_Object, bool, int);
3497 /* Defined in xdisp.c. */
3498 extern bool noninteractive_need_newline;
3499 extern Lisp_Object echo_area_buffer[2];
3500 extern void add_to_log (char const *, ...);
3501 extern void vadd_to_log (char const *, va_list);
3502 extern void check_message_stack (void);
3503 extern void setup_echo_area_for_printing (bool);
3504 extern bool push_message (void);
3505 extern void pop_message_unwind (void);
3506 extern Lisp_Object restore_message_unwind (Lisp_Object);
3507 extern void restore_message (void);
3508 extern Lisp_Object current_message (void);
3509 extern void clear_message (bool, bool);
3510 extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
3511 extern void message1 (const char *);
3512 extern void message1_nolog (const char *);
3513 extern void message3 (Lisp_Object);
3514 extern void message3_nolog (Lisp_Object);
3515 extern void message_dolog (const char *, ptrdiff_t, bool, bool);
3516 extern void message_with_string (const char *, Lisp_Object, bool);
3517 extern void message_log_maybe_newline (void);
3518 extern void update_echo_area (void);
3519 extern void truncate_echo_area (ptrdiff_t);
3520 extern void redisplay (void);
3522 void set_frame_cursor_types (struct frame *, Lisp_Object);
3523 extern void syms_of_xdisp (void);
3524 extern void init_xdisp (void);
3525 extern Lisp_Object safe_eval (Lisp_Object);
3526 extern bool pos_visible_p (struct window *, ptrdiff_t, int *,
3527 int *, int *, int *, int *, int *);
3529 /* Defined in xsettings.c. */
3530 extern void syms_of_xsettings (void);
3532 /* Defined in vm-limit.c. */
3533 extern void memory_warnings (void *, void (*warnfun) (const char *));
3535 /* Defined in character.c. */
3536 extern void parse_str_as_multibyte (const unsigned char *, ptrdiff_t,
3537 ptrdiff_t *, ptrdiff_t *);
3539 /* Defined in alloc.c. */
3540 extern void *my_heap_start (void);
3541 extern void check_pure_size (void);
3542 extern void free_misc (Lisp_Object);
3543 extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
3544 extern void malloc_warning (const char *);
3545 extern _Noreturn void memory_full (size_t);
3546 extern _Noreturn void buffer_memory_full (ptrdiff_t);
3547 extern bool survives_gc_p (Lisp_Object);
3548 extern void mark_object (Lisp_Object);
3549 #if defined REL_ALLOC && !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
3550 extern void refill_memory_reserve (void);
3551 #endif
3552 extern void alloc_unexec_pre (void);
3553 extern void alloc_unexec_post (void);
3554 extern void mark_stack (char *, char *);
3555 extern void flush_stack_call_func (void (*func) (void *arg), void *arg);
3556 extern const char *pending_malloc_warning;
3557 extern Lisp_Object zero_vector;
3558 extern EMACS_INT consing_since_gc;
3559 extern EMACS_INT gc_relative_threshold;
3560 extern EMACS_INT memory_full_cons_threshold;
3561 extern Lisp_Object list1 (Lisp_Object);
3562 extern Lisp_Object list2 (Lisp_Object, Lisp_Object);
3563 extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object);
3564 extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3565 extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3566 Lisp_Object);
3567 enum constype {CONSTYPE_HEAP, CONSTYPE_PURE};
3568 extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...);
3570 /* Build a frequently used 2/3/4-integer lists. */
3572 INLINE Lisp_Object
3573 list2i (EMACS_INT x, EMACS_INT y)
3575 return list2 (make_number (x), make_number (y));
3578 INLINE Lisp_Object
3579 list3i (EMACS_INT x, EMACS_INT y, EMACS_INT w)
3581 return list3 (make_number (x), make_number (y), make_number (w));
3584 INLINE Lisp_Object
3585 list4i (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h)
3587 return list4 (make_number (x), make_number (y),
3588 make_number (w), make_number (h));
3591 extern Lisp_Object make_uninit_bool_vector (EMACS_INT);
3592 extern Lisp_Object bool_vector_fill (Lisp_Object, Lisp_Object);
3593 extern _Noreturn void string_overflow (void);
3594 extern Lisp_Object make_string (const char *, ptrdiff_t);
3595 extern Lisp_Object make_formatted_string (char *, const char *, ...)
3596 ATTRIBUTE_FORMAT_PRINTF (2, 3);
3597 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
3599 /* Make unibyte string from C string when the length isn't known. */
3601 INLINE Lisp_Object
3602 build_unibyte_string (const char *str)
3604 return make_unibyte_string (str, strlen (str));
3607 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
3608 extern Lisp_Object make_event_array (ptrdiff_t, Lisp_Object *);
3609 extern Lisp_Object make_uninit_string (EMACS_INT);
3610 extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
3611 extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
3612 extern Lisp_Object make_specified_string (const char *,
3613 ptrdiff_t, ptrdiff_t, bool);
3614 extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, bool);
3615 extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
3617 /* Make a string allocated in pure space, use STR as string data. */
3619 INLINE Lisp_Object
3620 build_pure_c_string (const char *str)
3622 return make_pure_c_string (str, strlen (str));
3625 /* Make a string from the data at STR, treating it as multibyte if the
3626 data warrants. */
3628 INLINE Lisp_Object
3629 build_string (const char *str)
3631 return make_string (str, strlen (str));
3634 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
3635 extern void make_byte_code (struct Lisp_Vector *);
3636 extern struct Lisp_Vector *allocate_vector (EMACS_INT);
3638 /* Make an uninitialized vector for SIZE objects. NOTE: you must
3639 be sure that GC cannot happen until the vector is completely
3640 initialized. E.g. the following code is likely to crash:
3642 v = make_uninit_vector (3);
3643 ASET (v, 0, obj0);
3644 ASET (v, 1, Ffunction_can_gc ());
3645 ASET (v, 2, obj1); */
3647 INLINE Lisp_Object
3648 make_uninit_vector (ptrdiff_t size)
3650 Lisp_Object v;
3651 struct Lisp_Vector *p;
3653 p = allocate_vector (size);
3654 XSETVECTOR (v, p);
3655 return v;
3658 /* Like above, but special for sub char-tables. */
3660 INLINE Lisp_Object
3661 make_uninit_sub_char_table (int depth, int min_char)
3663 int slots = SUB_CHAR_TABLE_OFFSET + chartab_size[depth];
3664 Lisp_Object v = make_uninit_vector (slots);
3666 XSETPVECTYPE (XVECTOR (v), PVEC_SUB_CHAR_TABLE);
3667 XSUB_CHAR_TABLE (v)->depth = depth;
3668 XSUB_CHAR_TABLE (v)->min_char = min_char;
3669 return v;
3672 extern struct Lisp_Vector *allocate_pseudovector (int, int, int,
3673 enum pvec_type);
3675 /* Allocate partially initialized pseudovector where all Lisp_Object
3676 slots are set to Qnil but the rest (if any) is left uninitialized. */
3678 #define ALLOCATE_PSEUDOVECTOR(type, field, tag) \
3679 ((type *) allocate_pseudovector (VECSIZE (type), \
3680 PSEUDOVECSIZE (type, field), \
3681 PSEUDOVECSIZE (type, field), tag))
3683 /* Allocate fully initialized pseudovector where all Lisp_Object
3684 slots are set to Qnil and the rest (if any) is zeroed. */
3686 #define ALLOCATE_ZEROED_PSEUDOVECTOR(type, field, tag) \
3687 ((type *) allocate_pseudovector (VECSIZE (type), \
3688 PSEUDOVECSIZE (type, field), \
3689 VECSIZE (type), tag))
3691 extern bool gc_in_progress;
3692 extern Lisp_Object make_float (double);
3693 extern void display_malloc_warning (void);
3694 extern ptrdiff_t inhibit_garbage_collection (void);
3695 extern Lisp_Object make_save_int_int_int (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3696 extern Lisp_Object make_save_obj_obj_obj_obj (Lisp_Object, Lisp_Object,
3697 Lisp_Object, Lisp_Object);
3698 extern Lisp_Object make_save_ptr (void *);
3699 extern Lisp_Object make_save_ptr_int (void *, ptrdiff_t);
3700 extern Lisp_Object make_save_ptr_ptr (void *, void *);
3701 extern Lisp_Object make_save_funcptr_ptr_obj (void (*) (void), void *,
3702 Lisp_Object);
3703 extern Lisp_Object make_save_memory (Lisp_Object *, ptrdiff_t);
3704 extern void free_save_value (Lisp_Object);
3705 extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object);
3706 extern void free_marker (Lisp_Object);
3707 extern void free_cons (struct Lisp_Cons *);
3708 extern void init_alloc_once (void);
3709 extern void init_alloc (void);
3710 extern void syms_of_alloc (void);
3711 extern struct buffer * allocate_buffer (void);
3712 extern int valid_lisp_object_p (Lisp_Object);
3713 #ifdef GC_CHECK_CONS_LIST
3714 extern void check_cons_list (void);
3715 #else
3716 INLINE void (check_cons_list) (void) { lisp_h_check_cons_list (); }
3717 #endif
3719 /* Defined in gmalloc.c. */
3720 #if !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC && !defined SYSTEM_MALLOC
3721 extern size_t __malloc_extra_blocks;
3722 #endif
3723 #if !HAVE_DECL_ALIGNED_ALLOC
3724 extern void *aligned_alloc (size_t, size_t) ATTRIBUTE_MALLOC_SIZE ((2));
3725 #endif
3726 extern void malloc_enable_thread (void);
3728 #ifdef REL_ALLOC
3729 /* Defined in ralloc.c. */
3730 extern void *r_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
3731 extern void r_alloc_free (void **);
3732 extern void *r_re_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
3733 extern void r_alloc_reset_variable (void **, void **);
3734 extern void r_alloc_inhibit_buffer_relocation (int);
3735 #endif
3737 /* Defined in chartab.c. */
3738 extern Lisp_Object copy_char_table (Lisp_Object);
3739 extern Lisp_Object char_table_ref_and_range (Lisp_Object, int,
3740 int *, int *);
3741 extern void char_table_set_range (Lisp_Object, int, int, Lisp_Object);
3742 extern void map_char_table (void (*) (Lisp_Object, Lisp_Object,
3743 Lisp_Object),
3744 Lisp_Object, Lisp_Object, Lisp_Object);
3745 extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object),
3746 Lisp_Object, Lisp_Object,
3747 Lisp_Object, struct charset *,
3748 unsigned, unsigned);
3749 extern Lisp_Object uniprop_table (Lisp_Object);
3750 extern void syms_of_chartab (void);
3752 /* Defined in print.c. */
3753 extern Lisp_Object Vprin1_to_string_buffer;
3754 extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
3755 extern void temp_output_buffer_setup (const char *);
3756 extern int print_level;
3757 extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
3758 Lisp_Object);
3759 extern Lisp_Object internal_with_output_to_temp_buffer
3760 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3761 #define FLOAT_TO_STRING_BUFSIZE 350
3762 extern int float_to_string (char *, double);
3763 extern void init_print_once (void);
3764 extern void syms_of_print (void);
3766 /* Defined in doprnt.c. */
3767 extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
3768 va_list);
3769 extern ptrdiff_t esprintf (char *, char const *, ...)
3770 ATTRIBUTE_FORMAT_PRINTF (2, 3);
3771 extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
3772 char const *, ...)
3773 ATTRIBUTE_FORMAT_PRINTF (5, 6);
3774 extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
3775 char const *, va_list)
3776 ATTRIBUTE_FORMAT_PRINTF (5, 0);
3778 /* Defined in lread.c. */
3779 extern Lisp_Object check_obarray (Lisp_Object);
3780 extern Lisp_Object intern_1 (const char *, ptrdiff_t);
3781 extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t);
3782 extern Lisp_Object intern_driver (Lisp_Object, Lisp_Object, Lisp_Object);
3783 extern void init_symbol (Lisp_Object, Lisp_Object);
3784 extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
3785 INLINE void
3786 LOADHIST_ATTACH (Lisp_Object x)
3788 if (initialized)
3789 Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
3791 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
3792 Lisp_Object *, Lisp_Object, bool);
3793 extern Lisp_Object string_to_number (char const *, int, bool);
3794 extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
3795 Lisp_Object);
3796 extern void dir_warning (const char *, Lisp_Object);
3797 extern void init_obarray (void);
3798 extern void init_lread (void);
3799 extern void syms_of_lread (void);
3801 INLINE Lisp_Object
3802 intern (const char *str)
3804 return intern_1 (str, strlen (str));
3807 INLINE Lisp_Object
3808 intern_c_string (const char *str)
3810 return intern_c_string_1 (str, strlen (str));
3813 /* Defined in eval.c. */
3814 extern Lisp_Object Vautoload_queue;
3815 extern Lisp_Object Vrun_hooks;
3816 extern Lisp_Object Vsignaling_function;
3817 extern Lisp_Object inhibit_lisp_code;
3819 /* To run a normal hook, use the appropriate function from the list below.
3820 The calling convention:
3822 if (!NILP (Vrun_hooks))
3823 call1 (Vrun_hooks, Qmy_funny_hook);
3825 should no longer be used. */
3826 extern void run_hook (Lisp_Object);
3827 extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
3828 extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
3829 Lisp_Object (*funcall)
3830 (ptrdiff_t nargs, Lisp_Object *args));
3831 extern Lisp_Object quit (void);
3832 INLINE _Noreturn void
3833 xsignal (Lisp_Object error_symbol, Lisp_Object data)
3835 Fsignal (error_symbol, data);
3837 extern _Noreturn void xsignal0 (Lisp_Object);
3838 extern _Noreturn void xsignal1 (Lisp_Object, Lisp_Object);
3839 extern _Noreturn void xsignal2 (Lisp_Object, Lisp_Object, Lisp_Object);
3840 extern _Noreturn void xsignal3 (Lisp_Object, Lisp_Object, Lisp_Object,
3841 Lisp_Object);
3842 extern _Noreturn void signal_error (const char *, Lisp_Object);
3843 extern bool FUNCTIONP (Lisp_Object);
3844 extern Lisp_Object funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *arg_vector);
3845 extern Lisp_Object eval_sub (Lisp_Object form);
3846 extern Lisp_Object apply1 (Lisp_Object, Lisp_Object);
3847 extern Lisp_Object call0 (Lisp_Object);
3848 extern Lisp_Object call1 (Lisp_Object, Lisp_Object);
3849 extern Lisp_Object call2 (Lisp_Object, Lisp_Object, Lisp_Object);
3850 extern Lisp_Object call3 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3851 extern Lisp_Object call4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3852 extern Lisp_Object call5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3853 extern Lisp_Object call6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3854 extern Lisp_Object call7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3855 extern Lisp_Object call8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3856 extern Lisp_Object internal_catch (Lisp_Object, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3857 extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_Object);
3858 extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
3859 extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3860 extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3861 extern Lisp_Object internal_condition_case_n
3862 (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *,
3863 Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *));
3864 extern struct handler *push_handler (Lisp_Object, enum handlertype);
3865 extern struct handler *push_handler_nosignal (Lisp_Object, enum handlertype);
3866 extern void specbind (Lisp_Object, Lisp_Object);
3867 extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object);
3868 extern void record_unwind_protect_ptr (void (*) (void *), void *);
3869 extern void record_unwind_protect_int (void (*) (int), int);
3870 extern void record_unwind_protect_void (void (*) (void));
3871 extern void record_unwind_protect_nothing (void);
3872 extern void clear_unwind_protect (ptrdiff_t);
3873 extern void set_unwind_protect (ptrdiff_t, void (*) (Lisp_Object), Lisp_Object);
3874 extern void set_unwind_protect_ptr (ptrdiff_t, void (*) (void *), void *);
3875 extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
3876 extern void rebind_for_thread_switch (void);
3877 extern void unbind_for_thread_switch (struct thread_state *);
3878 extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
3879 extern _Noreturn void verror (const char *, va_list)
3880 ATTRIBUTE_FORMAT_PRINTF (1, 0);
3881 extern Lisp_Object vformat_string (const char *, va_list)
3882 ATTRIBUTE_FORMAT_PRINTF (1, 0);
3883 extern void un_autoload (Lisp_Object);
3884 extern Lisp_Object call_debugger (Lisp_Object arg);
3885 extern void init_eval_once (void);
3886 extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object, ...);
3887 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
3888 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
3889 extern void init_eval (void);
3890 extern void syms_of_eval (void);
3891 extern void prog_ignore (Lisp_Object);
3892 extern ptrdiff_t record_in_backtrace (Lisp_Object, Lisp_Object *, ptrdiff_t);
3893 extern void mark_specpdl (union specbinding *first, union specbinding *ptr);
3894 extern void get_backtrace (Lisp_Object array);
3895 Lisp_Object backtrace_top_function (void);
3896 extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);
3898 /* Defined in unexmacosx.c. */
3899 #if defined DARWIN_OS && !defined CANNOT_DUMP
3900 extern void unexec_init_emacs_zone (void);
3901 extern void *unexec_malloc (size_t);
3902 extern void *unexec_realloc (void *, size_t);
3903 extern void unexec_free (void *);
3904 #endif
3906 #include "emacs-module.h"
3908 /* Function prototype for the module Lisp functions. */
3909 typedef emacs_value (*emacs_subr) (emacs_env *, ptrdiff_t,
3910 emacs_value [], void *);
3912 /* Module function. */
3914 /* A function environment is an auxiliary structure returned by
3915 `module_make_function' to store information about a module
3916 function. It is stored in a pseudovector. Its members correspond
3917 to the arguments given to `module_make_function'. */
3919 struct Lisp_Module_Function
3921 struct vectorlike_header header;
3923 /* Fields traced by GC; these must come first. */
3924 Lisp_Object documentation;
3926 /* Fields ignored by GC. */
3927 ptrdiff_t min_arity, max_arity;
3928 emacs_subr subr;
3929 void *data;
3932 INLINE bool
3933 MODULE_FUNCTIONP (Lisp_Object o)
3935 return PSEUDOVECTORP (o, PVEC_MODULE_FUNCTION);
3938 INLINE struct Lisp_Module_Function *
3939 XMODULE_FUNCTION (Lisp_Object o)
3941 eassert (MODULE_FUNCTIONP (o));
3942 return XUNTAG (o, Lisp_Vectorlike);
3945 #ifdef HAVE_MODULES
3946 /* Defined in alloc.c. */
3947 extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p);
3949 /* Defined in emacs-module.c. */
3950 extern Lisp_Object funcall_module (Lisp_Object, ptrdiff_t, Lisp_Object *);
3951 extern Lisp_Object module_function_arity (const struct Lisp_Module_Function *);
3952 extern void mark_modules (void);
3953 extern void init_module_assertions (bool);
3954 extern void syms_of_module (void);
3955 #endif
3957 /* Defined in thread.c. */
3958 extern void mark_threads (void);
3960 /* Defined in editfns.c. */
3961 extern void insert1 (Lisp_Object);
3962 extern Lisp_Object save_excursion_save (void);
3963 extern Lisp_Object save_restriction_save (void);
3964 extern void save_excursion_restore (Lisp_Object);
3965 extern void save_restriction_restore (Lisp_Object);
3966 extern _Noreturn void time_overflow (void);
3967 extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool);
3968 extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3969 ptrdiff_t, bool);
3970 extern void init_editfns (bool);
3971 extern void syms_of_editfns (void);
3973 /* Defined in buffer.c. */
3974 extern bool mouse_face_overlay_overlaps (Lisp_Object);
3975 extern Lisp_Object disable_line_numbers_overlay_at_eob (void);
3976 extern _Noreturn void nsberror (Lisp_Object);
3977 extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
3978 extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
3979 extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3980 extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
3981 Lisp_Object, Lisp_Object, Lisp_Object);
3982 extern bool overlay_touches_p (ptrdiff_t);
3983 extern Lisp_Object other_buffer_safely (Lisp_Object);
3984 extern Lisp_Object get_truename_buffer (Lisp_Object);
3985 extern void init_buffer_once (void);
3986 extern void init_buffer (int);
3987 extern void syms_of_buffer (void);
3988 extern void keys_of_buffer (void);
3990 /* Defined in marker.c. */
3992 extern ptrdiff_t marker_position (Lisp_Object);
3993 extern ptrdiff_t marker_byte_position (Lisp_Object);
3994 extern void clear_charpos_cache (struct buffer *);
3995 extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
3996 extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
3997 extern void unchain_marker (struct Lisp_Marker *marker);
3998 extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
3999 extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
4000 extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
4001 ptrdiff_t, ptrdiff_t);
4002 extern Lisp_Object build_marker (struct buffer *, ptrdiff_t, ptrdiff_t);
4003 extern void syms_of_marker (void);
4005 /* Defined in fileio.c. */
4007 extern Lisp_Object expand_and_dir_to_file (Lisp_Object);
4008 extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object,
4009 Lisp_Object, Lisp_Object, Lisp_Object,
4010 Lisp_Object, int);
4011 extern void close_file_unwind (int);
4012 extern void fclose_unwind (void *);
4013 extern void restore_point_unwind (Lisp_Object);
4014 extern _Noreturn void report_file_errno (const char *, Lisp_Object, int);
4015 extern _Noreturn void report_file_error (const char *, Lisp_Object);
4016 extern _Noreturn void report_file_notify_error (const char *, Lisp_Object);
4017 extern bool internal_delete_file (Lisp_Object);
4018 extern Lisp_Object emacs_readlinkat (int, const char *);
4019 extern bool file_directory_p (const char *);
4020 extern bool file_accessible_directory_p (Lisp_Object);
4021 extern void init_fileio (void);
4022 extern void syms_of_fileio (void);
4024 /* Defined in search.c. */
4025 extern void shrink_regexp_cache (void);
4026 extern void restore_search_regs (void);
4027 extern void update_search_regs (ptrdiff_t oldstart,
4028 ptrdiff_t oldend, ptrdiff_t newend);
4029 extern void record_unwind_save_match_data (void);
4030 struct re_registers;
4031 extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
4032 struct re_registers *,
4033 Lisp_Object, bool, bool);
4034 extern ptrdiff_t fast_string_match_internal (Lisp_Object, Lisp_Object,
4035 Lisp_Object);
4037 INLINE ptrdiff_t
4038 fast_string_match (Lisp_Object regexp, Lisp_Object string)
4040 return fast_string_match_internal (regexp, string, Qnil);
4043 INLINE ptrdiff_t
4044 fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string)
4046 return fast_string_match_internal (regexp, string, Vascii_canon_table);
4049 extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
4050 ptrdiff_t);
4051 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
4052 ptrdiff_t, ptrdiff_t, Lisp_Object);
4053 extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
4054 ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
4055 extern ptrdiff_t scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
4056 ptrdiff_t, bool);
4057 extern ptrdiff_t scan_newline_from_point (ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
4058 extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
4059 ptrdiff_t, ptrdiff_t *);
4060 extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
4061 ptrdiff_t, ptrdiff_t *);
4062 extern void syms_of_search (void);
4063 extern void clear_regexp_cache (void);
4065 /* Defined in minibuf.c. */
4067 extern Lisp_Object Vminibuffer_list;
4068 extern Lisp_Object last_minibuf_string;
4069 extern Lisp_Object get_minibuffer (EMACS_INT);
4070 extern void init_minibuf_once (void);
4071 extern void syms_of_minibuf (void);
4073 /* Defined in callint.c. */
4075 extern void syms_of_callint (void);
4077 /* Defined in casefiddle.c. */
4079 extern void syms_of_casefiddle (void);
4080 extern void keys_of_casefiddle (void);
4082 /* Defined in casetab.c. */
4084 extern void init_casetab_once (void);
4085 extern void syms_of_casetab (void);
4087 /* Defined in keyboard.c. */
4089 extern Lisp_Object echo_message_buffer;
4090 extern struct kboard *echo_kboard;
4091 extern void cancel_echoing (void);
4092 extern bool input_pending;
4093 #ifdef HAVE_STACK_OVERFLOW_HANDLING
4094 extern sigjmp_buf return_to_command_loop;
4095 #endif
4096 extern Lisp_Object menu_bar_items (Lisp_Object);
4097 extern Lisp_Object tool_bar_items (Lisp_Object, int *);
4098 extern void discard_mouse_events (void);
4099 #ifdef USABLE_SIGIO
4100 void handle_input_available_signal (int);
4101 #endif
4102 extern Lisp_Object pending_funcalls;
4103 extern bool detect_input_pending (void);
4104 extern bool detect_input_pending_ignore_squeezables (void);
4105 extern bool detect_input_pending_run_timers (bool);
4106 extern void safe_run_hooks (Lisp_Object);
4107 extern void cmd_error_internal (Lisp_Object, const char *);
4108 extern Lisp_Object command_loop_1 (void);
4109 extern Lisp_Object read_menu_command (void);
4110 extern Lisp_Object recursive_edit_1 (void);
4111 extern void record_auto_save (void);
4112 extern void force_auto_save_soon (void);
4113 extern void init_keyboard (void);
4114 extern void syms_of_keyboard (void);
4115 extern void keys_of_keyboard (void);
4117 /* Defined in indent.c. */
4118 extern ptrdiff_t current_column (void);
4119 extern void invalidate_current_column (void);
4120 extern bool indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
4121 extern void syms_of_indent (void);
4123 /* Defined in frame.c. */
4124 extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
4125 extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
4126 extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
4127 extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
4128 extern void frames_discard_buffer (Lisp_Object);
4129 extern void syms_of_frame (void);
4131 /* Defined in emacs.c. */
4132 extern char **initial_argv;
4133 extern int initial_argc;
4134 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
4135 extern bool display_arg;
4136 #endif
4137 extern Lisp_Object decode_env_path (const char *, const char *, bool);
4138 extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
4139 extern _Noreturn void terminate_due_to_signal (int, int);
4140 #ifdef WINDOWSNT
4141 extern Lisp_Object Vlibrary_cache;
4142 #endif
4143 #if HAVE_SETLOCALE
4144 void fixup_locale (void);
4145 void synchronize_system_messages_locale (void);
4146 void synchronize_system_time_locale (void);
4147 #else
4148 INLINE void fixup_locale (void) {}
4149 INLINE void synchronize_system_messages_locale (void) {}
4150 INLINE void synchronize_system_time_locale (void) {}
4151 #endif
4152 extern char *emacs_strerror (int);
4153 extern void shut_down_emacs (int, Lisp_Object);
4155 /* True means don't do interactive redisplay and don't change tty modes. */
4156 extern bool noninteractive;
4158 /* True means remove site-lisp directories from load-path. */
4159 extern bool no_site_lisp;
4161 /* True means put details like time stamps into builds. */
4162 extern bool build_details;
4164 #ifndef WINDOWSNT
4165 /* 0 not a daemon, 1 foreground daemon, 2 background daemon. */
4166 extern int daemon_type;
4167 #define IS_DAEMON (daemon_type != 0)
4168 #define DAEMON_RUNNING (daemon_type >= 0)
4169 #else /* WINDOWSNT */
4170 extern void *w32_daemon_event;
4171 #define IS_DAEMON (w32_daemon_event != NULL)
4172 #define DAEMON_RUNNING (w32_daemon_event != INVALID_HANDLE_VALUE)
4173 #endif
4175 /* True if handling a fatal error already. */
4176 extern bool fatal_error_in_progress;
4178 /* True means don't do use window-system-specific display code. */
4179 extern bool inhibit_window_system;
4180 /* True means that a filter or a sentinel is running. */
4181 extern bool running_asynch_code;
4183 /* Defined in process.c. */
4184 struct Lisp_Process;
4185 extern void kill_buffer_processes (Lisp_Object);
4186 extern int wait_reading_process_output (intmax_t, int, int, bool, Lisp_Object,
4187 struct Lisp_Process *, int);
4188 /* Max value for the first argument of wait_reading_process_output. */
4189 #if GNUC_PREREQ (3, 0, 0) && ! GNUC_PREREQ (4, 6, 0)
4190 /* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.0.
4191 The bug merely causes a bogus warning, but the warning is annoying. */
4192 # define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX)
4193 #else
4194 # define WAIT_READING_MAX INTMAX_MAX
4195 #endif
4196 #ifdef HAVE_TIMERFD
4197 extern void add_timer_wait_descriptor (int);
4198 #endif
4199 extern void add_keyboard_wait_descriptor (int);
4200 extern void delete_keyboard_wait_descriptor (int);
4201 #ifdef HAVE_GPM
4202 extern void add_gpm_wait_descriptor (int);
4203 extern void delete_gpm_wait_descriptor (int);
4204 #endif
4205 extern void init_process_emacs (int);
4206 extern void syms_of_process (void);
4207 extern void setup_process_coding_systems (Lisp_Object);
4209 /* Defined in callproc.c. */
4210 #ifndef DOS_NT
4211 # define CHILD_SETUP_TYPE _Noreturn void
4212 #else
4213 # define CHILD_SETUP_TYPE int
4214 #endif
4215 extern CHILD_SETUP_TYPE child_setup (int, int, int, char **, bool, Lisp_Object);
4216 extern void init_callproc_1 (void);
4217 extern void init_callproc (void);
4218 extern void set_initial_environment (void);
4219 extern void syms_of_callproc (void);
4221 /* Defined in doc.c. */
4222 enum text_quoting_style
4224 /* Use curved single quotes ‘like this’. */
4225 CURVE_QUOTING_STYLE,
4227 /* Use grave accent and apostrophe `like this'. */
4228 GRAVE_QUOTING_STYLE,
4230 /* Use apostrophes 'like this'. */
4231 STRAIGHT_QUOTING_STYLE
4233 extern enum text_quoting_style text_quoting_style (void);
4234 extern Lisp_Object read_doc_string (Lisp_Object);
4235 extern Lisp_Object get_doc_string (Lisp_Object, bool, bool);
4236 extern void syms_of_doc (void);
4237 extern int read_bytecode_char (bool);
4239 /* Defined in bytecode.c. */
4240 extern void syms_of_bytecode (void);
4241 extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
4242 Lisp_Object, ptrdiff_t, Lisp_Object *);
4243 extern Lisp_Object get_byte_code_arity (Lisp_Object);
4245 /* Defined in macros.c. */
4246 extern void init_macros (void);
4247 extern void syms_of_macros (void);
4249 /* Defined in undo.c. */
4250 extern void truncate_undo_list (struct buffer *);
4251 extern void record_insert (ptrdiff_t, ptrdiff_t);
4252 extern void record_delete (ptrdiff_t, Lisp_Object, bool);
4253 extern void record_first_change (void);
4254 extern void record_change (ptrdiff_t, ptrdiff_t);
4255 extern void record_property_change (ptrdiff_t, ptrdiff_t,
4256 Lisp_Object, Lisp_Object,
4257 Lisp_Object);
4258 extern void syms_of_undo (void);
4260 /* Defined in textprop.c. */
4261 extern void report_interval_modification (Lisp_Object, Lisp_Object);
4263 /* Defined in menu.c. */
4264 extern void syms_of_menu (void);
4266 /* Defined in xmenu.c. */
4267 extern void syms_of_xmenu (void);
4269 /* Defined in termchar.h. */
4270 struct tty_display_info;
4272 /* Defined in sysdep.c. */
4273 #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE
4274 extern bool disable_address_randomization (void);
4275 #else
4276 INLINE bool disable_address_randomization (void) { return false; }
4277 #endif
4278 extern int emacs_exec_file (char const *, char *const *, char *const *);
4279 extern void init_standard_fds (void);
4280 extern char *emacs_get_current_dir_name (void);
4281 extern void stuff_char (char c);
4282 extern void init_foreground_group (void);
4283 extern void sys_subshell (void);
4284 extern void sys_suspend (void);
4285 extern void discard_tty_input (void);
4286 extern void init_sys_modes (struct tty_display_info *);
4287 extern void reset_sys_modes (struct tty_display_info *);
4288 extern void init_all_sys_modes (void);
4289 extern void reset_all_sys_modes (void);
4290 extern void child_setup_tty (int);
4291 extern void setup_pty (int);
4292 extern int set_window_size (int, int, int);
4293 extern EMACS_INT get_random (void);
4294 extern void seed_random (void *, ptrdiff_t);
4295 extern void init_random (void);
4296 extern void emacs_backtrace (int);
4297 extern _Noreturn void emacs_abort (void) NO_INLINE;
4298 extern int emacs_open (const char *, int, int);
4299 extern int emacs_pipe (int[2]);
4300 extern int emacs_close (int);
4301 extern ptrdiff_t emacs_read (int, void *, ptrdiff_t);
4302 extern ptrdiff_t emacs_read_quit (int, void *, ptrdiff_t);
4303 extern ptrdiff_t emacs_write (int, void const *, ptrdiff_t);
4304 extern ptrdiff_t emacs_write_sig (int, void const *, ptrdiff_t);
4305 extern ptrdiff_t emacs_write_quit (int, void const *, ptrdiff_t);
4306 extern void emacs_perror (char const *);
4307 extern int renameat_noreplace (int, char const *, int, char const *);
4308 extern int str_collate (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
4310 /* Defined in filelock.c. */
4311 extern void lock_file (Lisp_Object);
4312 extern void unlock_file (Lisp_Object);
4313 extern void unlock_all_files (void);
4314 extern void unlock_buffer (struct buffer *);
4315 extern void syms_of_filelock (void);
4317 /* Defined in sound.c. */
4318 extern void syms_of_sound (void);
4320 /* Defined in category.c. */
4321 extern void init_category_once (void);
4322 extern Lisp_Object char_category_set (int);
4323 extern void syms_of_category (void);
4325 /* Defined in ccl.c. */
4326 extern void syms_of_ccl (void);
4328 /* Defined in dired.c. */
4329 extern void syms_of_dired (void);
4330 extern Lisp_Object directory_files_internal (Lisp_Object, Lisp_Object,
4331 Lisp_Object, Lisp_Object,
4332 bool, Lisp_Object);
4334 /* Defined in term.c. */
4335 extern int *char_ins_del_vector;
4336 extern void syms_of_term (void);
4337 extern _Noreturn void fatal (const char *msgid, ...)
4338 ATTRIBUTE_FORMAT_PRINTF (1, 2);
4340 /* Defined in terminal.c. */
4341 extern void syms_of_terminal (void);
4343 /* Defined in font.c. */
4344 extern void syms_of_font (void);
4345 extern void init_font (void);
4347 #ifdef HAVE_WINDOW_SYSTEM
4348 /* Defined in fontset.c. */
4349 extern void syms_of_fontset (void);
4350 #endif
4352 /* Defined in inotify.c */
4353 #ifdef HAVE_INOTIFY
4354 extern void syms_of_inotify (void);
4355 #endif
4357 /* Defined in kqueue.c */
4358 #ifdef HAVE_KQUEUE
4359 extern void globals_of_kqueue (void);
4360 extern void syms_of_kqueue (void);
4361 #endif
4363 /* Defined in gfilenotify.c */
4364 #ifdef HAVE_GFILENOTIFY
4365 extern void globals_of_gfilenotify (void);
4366 extern void syms_of_gfilenotify (void);
4367 #endif
4369 #ifdef HAVE_W32NOTIFY
4370 /* Defined on w32notify.c. */
4371 extern void syms_of_w32notify (void);
4372 #endif
4374 /* Defined in xfaces.c. */
4375 extern Lisp_Object Vface_alternative_font_family_alist;
4376 extern Lisp_Object Vface_alternative_font_registry_alist;
4377 extern void syms_of_xfaces (void);
4379 #ifdef HAVE_X_WINDOWS
4380 /* Defined in xfns.c. */
4381 extern void syms_of_xfns (void);
4383 /* Defined in xsmfns.c. */
4384 extern void syms_of_xsmfns (void);
4386 /* Defined in xselect.c. */
4387 extern void syms_of_xselect (void);
4389 /* Defined in xterm.c. */
4390 extern void init_xterm (void);
4391 extern void syms_of_xterm (void);
4392 #endif /* HAVE_X_WINDOWS */
4394 #ifdef HAVE_WINDOW_SYSTEM
4395 /* Defined in xterm.c, nsterm.m, w32term.c. */
4396 extern char *x_get_keysym_name (int);
4397 #endif /* HAVE_WINDOW_SYSTEM */
4399 #ifdef HAVE_LIBXML2
4400 /* Defined in xml.c. */
4401 extern void syms_of_xml (void);
4402 extern void xml_cleanup_parser (void);
4403 #endif
4405 #ifdef HAVE_LCMS2
4406 /* Defined in lcms.c. */
4407 extern void syms_of_lcms2 (void);
4408 #endif
4410 #ifdef HAVE_ZLIB
4411 /* Defined in decompress.c. */
4412 extern void syms_of_decompress (void);
4413 #endif
4415 #ifdef HAVE_DBUS
4416 /* Defined in dbusbind.c. */
4417 void init_dbusbind (void);
4418 void syms_of_dbusbind (void);
4419 #endif
4422 /* Defined in profiler.c. */
4423 extern bool profiler_memory_running;
4424 extern void malloc_probe (size_t);
4425 extern void syms_of_profiler (void);
4428 #ifdef DOS_NT
4429 /* Defined in msdos.c, w32.c. */
4430 extern char *emacs_root_dir (void);
4431 #endif /* DOS_NT */
4433 /* Defined in lastfile.c. */
4434 extern char my_edata[];
4435 extern char my_endbss[];
4436 extern char *my_endbss_static;
4438 extern void *xmalloc (size_t) ATTRIBUTE_MALLOC_SIZE ((1));
4439 extern void *xzalloc (size_t) ATTRIBUTE_MALLOC_SIZE ((1));
4440 extern void *xrealloc (void *, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
4441 extern void xfree (void *);
4442 extern void *xnmalloc (ptrdiff_t, ptrdiff_t) ATTRIBUTE_MALLOC_SIZE ((1,2));
4443 extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t)
4444 ATTRIBUTE_ALLOC_SIZE ((2,3));
4445 extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
4447 extern char *xstrdup (const char *) ATTRIBUTE_MALLOC;
4448 extern char *xlispstrdup (Lisp_Object) ATTRIBUTE_MALLOC;
4449 extern void dupstring (char **, char const *);
4451 /* Make DEST a copy of STRING's data. Return a pointer to DEST's terminating
4452 null byte. This is like stpcpy, except the source is a Lisp string. */
4454 INLINE char *
4455 lispstpcpy (char *dest, Lisp_Object string)
4457 ptrdiff_t len = SBYTES (string);
4458 memcpy (dest, SDATA (string), len + 1);
4459 return dest + len;
4462 extern void xputenv (const char *);
4464 extern char *egetenv_internal (const char *, ptrdiff_t);
4466 INLINE char *
4467 egetenv (const char *var)
4469 /* When VAR is a string literal, strlen can be optimized away. */
4470 return egetenv_internal (var, strlen (var));
4473 /* Set up the name of the machine we're running on. */
4474 extern void init_system_name (void);
4476 /* Return the absolute value of X. X should be a signed integer
4477 expression without side effects, and X's absolute value should not
4478 exceed the maximum for its promoted type. This is called 'eabs'
4479 because 'abs' is reserved by the C standard. */
4480 #define eabs(x) ((x) < 0 ? -(x) : (x))
4482 /* Return a fixnum or float, depending on whether the integer VAL fits
4483 in a Lisp fixnum. */
4485 #define make_fixnum_or_float(val) \
4486 (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
4488 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
4489 larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */
4491 enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 };
4493 extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1));
4495 #define USE_SAFE_ALLOCA \
4496 ptrdiff_t sa_avail = MAX_ALLOCA; \
4497 ptrdiff_t sa_count = SPECPDL_INDEX (); bool sa_must_free = false
4499 #define AVAIL_ALLOCA(size) (sa_avail -= (size), alloca (size))
4501 /* SAFE_ALLOCA allocates a simple buffer. */
4503 #define SAFE_ALLOCA(size) ((size) <= sa_avail \
4504 ? AVAIL_ALLOCA (size) \
4505 : (sa_must_free = true, record_xmalloc (size)))
4507 /* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
4508 NITEMS items, each of the same type as *BUF. MULTIPLIER must
4509 positive. The code is tuned for MULTIPLIER being a constant. */
4511 #define SAFE_NALLOCA(buf, multiplier, nitems) \
4512 do { \
4513 if ((nitems) <= sa_avail / sizeof *(buf) / (multiplier)) \
4514 (buf) = AVAIL_ALLOCA (sizeof *(buf) * (multiplier) * (nitems)); \
4515 else \
4517 (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
4518 sa_must_free = true; \
4519 record_unwind_protect_ptr (xfree, buf); \
4521 } while (false)
4523 /* SAFE_ALLOCA_STRING allocates a C copy of a Lisp string. */
4525 #define SAFE_ALLOCA_STRING(ptr, string) \
4526 do { \
4527 (ptr) = SAFE_ALLOCA (SBYTES (string) + 1); \
4528 memcpy (ptr, SDATA (string), SBYTES (string) + 1); \
4529 } while (false)
4531 /* SAFE_FREE frees xmalloced memory and enables GC as needed. */
4533 #define SAFE_FREE() \
4534 do { \
4535 if (sa_must_free) { \
4536 sa_must_free = false; \
4537 unbind_to (sa_count, Qnil); \
4539 } while (false)
4541 /* Set BUF to point to an allocated array of NELT Lisp_Objects,
4542 immediately followed by EXTRA spare bytes. */
4544 #define SAFE_ALLOCA_LISP_EXTRA(buf, nelt, extra) \
4545 do { \
4546 ptrdiff_t alloca_nbytes; \
4547 if (INT_MULTIPLY_WRAPV (nelt, word_size, &alloca_nbytes) \
4548 || INT_ADD_WRAPV (alloca_nbytes, extra, &alloca_nbytes) \
4549 || SIZE_MAX < alloca_nbytes) \
4550 memory_full (SIZE_MAX); \
4551 else if (alloca_nbytes <= sa_avail) \
4552 (buf) = AVAIL_ALLOCA (alloca_nbytes); \
4553 else \
4555 Lisp_Object arg_; \
4556 (buf) = xmalloc (alloca_nbytes); \
4557 arg_ = make_save_memory (buf, nelt); \
4558 sa_must_free = true; \
4559 record_unwind_protect (free_save_value, arg_); \
4561 } while (false)
4563 /* Set BUF to point to an allocated array of NELT Lisp_Objects. */
4565 #define SAFE_ALLOCA_LISP(buf, nelt) SAFE_ALLOCA_LISP_EXTRA (buf, nelt, 0)
4568 /* If USE_STACK_LISP_OBJECTS, define macros that and functions that allocate
4569 block-scoped conses and strings. These objects are not
4570 managed by the garbage collector, so they are dangerous: passing them
4571 out of their scope (e.g., to user code) results in undefined behavior.
4572 Conversely, they have better performance because GC is not involved.
4574 This feature is experimental and requires careful debugging.
4575 Build with CPPFLAGS='-DUSE_STACK_LISP_OBJECTS=0' to disable it. */
4577 #if (!defined USE_STACK_LISP_OBJECTS \
4578 && defined __GNUC__ && !defined __clang__ && ! GNUC_PREREQ (4, 3, 2))
4579 /* Work around GCC bugs 36584 and 35271, which were fixed in GCC 4.3.2. */
4580 # define USE_STACK_LISP_OBJECTS false
4581 #endif
4582 #ifndef USE_STACK_LISP_OBJECTS
4583 # define USE_STACK_LISP_OBJECTS true
4584 #endif
4586 #ifdef GC_CHECK_STRING_BYTES
4587 enum { defined_GC_CHECK_STRING_BYTES = true };
4588 #else
4589 enum { defined_GC_CHECK_STRING_BYTES = false };
4590 #endif
4592 /* Struct inside unions that are typically no larger and aligned enough. */
4594 union Aligned_Cons
4596 struct Lisp_Cons s;
4597 double d; intmax_t i; void *p;
4600 union Aligned_String
4602 struct Lisp_String s;
4603 double d; intmax_t i; void *p;
4606 /* True for stack-based cons and string implementations, respectively.
4607 Use stack-based strings only if stack-based cons also works.
4608 Otherwise, STACK_CONS would create heap-based cons cells that
4609 could point to stack-based strings, which is a no-no. */
4611 enum
4613 USE_STACK_CONS = (USE_STACK_LISP_OBJECTS
4614 && alignof (union Aligned_Cons) % GCALIGNMENT == 0),
4615 USE_STACK_STRING = (USE_STACK_CONS
4616 && !defined_GC_CHECK_STRING_BYTES
4617 && alignof (union Aligned_String) % GCALIGNMENT == 0)
4620 /* Auxiliary macros used for auto allocation of Lisp objects. Please
4621 use these only in macros like AUTO_CONS that declare a local
4622 variable whose lifetime will be clear to the programmer. */
4623 #define STACK_CONS(a, b) \
4624 make_lisp_ptr (&((union Aligned_Cons) { { a, { b } } }).s, Lisp_Cons)
4625 #define AUTO_CONS_EXPR(a, b) \
4626 (USE_STACK_CONS ? STACK_CONS (a, b) : Fcons (a, b))
4628 /* Declare NAME as an auto Lisp cons or short list if possible, a
4629 GC-based one otherwise. This is in the sense of the C keyword
4630 'auto'; i.e., the object has the lifetime of the containing block.
4631 The resulting object should not be made visible to user Lisp code. */
4633 #define AUTO_CONS(name, a, b) Lisp_Object name = AUTO_CONS_EXPR (a, b)
4634 #define AUTO_LIST1(name, a) \
4635 Lisp_Object name = (USE_STACK_CONS ? STACK_CONS (a, Qnil) : list1 (a))
4636 #define AUTO_LIST2(name, a, b) \
4637 Lisp_Object name = (USE_STACK_CONS \
4638 ? STACK_CONS (a, STACK_CONS (b, Qnil)) \
4639 : list2 (a, b))
4640 #define AUTO_LIST3(name, a, b, c) \
4641 Lisp_Object name = (USE_STACK_CONS \
4642 ? STACK_CONS (a, STACK_CONS (b, STACK_CONS (c, Qnil))) \
4643 : list3 (a, b, c))
4644 #define AUTO_LIST4(name, a, b, c, d) \
4645 Lisp_Object name \
4646 = (USE_STACK_CONS \
4647 ? STACK_CONS (a, STACK_CONS (b, STACK_CONS (c, \
4648 STACK_CONS (d, Qnil)))) \
4649 : list4 (a, b, c, d))
4651 /* Declare NAME as an auto Lisp string if possible, a GC-based one if not.
4652 Take its unibyte value from the null-terminated string STR,
4653 an expression that should not have side effects.
4654 STR's value is not necessarily copied. The resulting Lisp string
4655 should not be modified or made visible to user code. */
4657 #define AUTO_STRING(name, str) \
4658 AUTO_STRING_WITH_LEN (name, str, strlen (str))
4660 /* Declare NAME as an auto Lisp string if possible, a GC-based one if not.
4661 Take its unibyte value from the null-terminated string STR with length LEN.
4662 STR may have side effects and may contain null bytes.
4663 STR's value is not necessarily copied. The resulting Lisp string
4664 should not be modified or made visible to user code. */
4666 #define AUTO_STRING_WITH_LEN(name, str, len) \
4667 Lisp_Object name = \
4668 (USE_STACK_STRING \
4669 ? (make_lisp_ptr \
4670 ((&((union Aligned_String) {{len, -1, 0, (unsigned char *) (str)}}).s), \
4671 Lisp_String)) \
4672 : make_unibyte_string (str, len))
4674 /* Loop over conses of the list TAIL, signaling if a cycle is found,
4675 and possibly quitting after each loop iteration. In the loop body,
4676 set TAIL to the current cons. If the loop exits normally,
4677 set TAIL to the terminating non-cons, typically nil. The loop body
4678 should not modify the list’s top level structure other than by
4679 perhaps deleting the current cons. */
4681 #define FOR_EACH_TAIL(tail) \
4682 FOR_EACH_TAIL_INTERNAL (tail, circular_list (tail), true)
4684 /* Like FOR_EACH_TAIL (LIST), except do not signal or quit.
4685 If the loop exits due to a cycle, TAIL’s value is undefined. */
4687 #define FOR_EACH_TAIL_SAFE(tail) \
4688 FOR_EACH_TAIL_INTERNAL (tail, (void) ((tail) = Qnil), false)
4690 /* Iterator intended for use only within FOR_EACH_TAIL_INTERNAL. */
4691 struct for_each_tail_internal
4693 Lisp_Object tortoise;
4694 intptr_t max, n;
4695 unsigned short int q;
4698 /* Like FOR_EACH_TAIL (LIST), except evaluate CYCLE if a cycle is
4699 found, and check for quit if CHECK_QUIT. This is an internal macro
4700 intended for use only by the above macros.
4702 Use Brent’s teleporting tortoise-hare algorithm. See:
4703 Brent RP. BIT. 1980;20(2):176-84. doi:10.1007/BF01933190
4704 http://maths-people.anu.edu.au/~brent/pd/rpb051i.pdf
4706 This macro uses maybe_quit because of an excess of caution. The
4707 call to maybe_quit should not be needed in practice, as a very long
4708 list, whether circular or not, will cause Emacs to be so slow in
4709 other uninterruptible areas (e.g., garbage collection) that there
4710 is little point to calling maybe_quit here. */
4712 #define FOR_EACH_TAIL_INTERNAL(tail, cycle, check_quit) \
4713 for (struct for_each_tail_internal li = { tail, 2, 0, 2 }; \
4714 CONSP (tail); \
4715 ((tail) = XCDR (tail), \
4716 ((--li.q != 0 \
4717 || ((check_quit) ? maybe_quit () : (void) 0, 0 < --li.n) \
4718 || (li.q = li.n = li.max <<= 1, li.n >>= USHRT_WIDTH, \
4719 li.tortoise = (tail), false)) \
4720 && EQ (tail, li.tortoise)) \
4721 ? (cycle) : (void) 0))
4723 /* Do a `for' loop over alist values. */
4725 #define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var) \
4726 for ((list_var) = (head_var); \
4727 (CONSP (list_var) && ((value_var) = XCDR (XCAR (list_var)), true)); \
4728 (list_var) = XCDR (list_var))
4730 /* Check whether it's time for GC, and run it if so. */
4732 INLINE void
4733 maybe_gc (void)
4735 if ((consing_since_gc > gc_cons_threshold
4736 && consing_since_gc > gc_relative_threshold)
4737 || (!NILP (Vmemory_full)
4738 && consing_since_gc > memory_full_cons_threshold))
4739 Fgarbage_collect ();
4742 INLINE_HEADER_END
4744 #endif /* EMACS_LISP_H */