Remove faulty optimisation from indentation calculation.
[emacs.git] / src / lisp.h
blob517d0abbb6147e42b13f2fa39872f04fa76ce241
1 /* Fundamental definitions for GNU Emacs Lisp interpreter.
3 Copyright (C) 1985-1987, 1993-1995, 1997-2013 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
11 (at 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 <http://www.gnu.org/licenses/>. */
21 #ifndef EMACS_LISP_H
22 #define EMACS_LISP_H
24 #include <setjmp.h>
25 #include <stdalign.h>
26 #include <stdarg.h>
27 #include <stdbool.h>
28 #include <stddef.h>
29 #include <float.h>
30 #include <inttypes.h>
31 #include <limits.h>
33 #include <intprops.h>
35 INLINE_HEADER_BEGIN
36 #ifndef LISP_INLINE
37 # define LISP_INLINE INLINE
38 #endif
40 /* The ubiquitous max and min macros. */
41 #undef min
42 #undef max
43 #define max(a, b) ((a) > (b) ? (a) : (b))
44 #define min(a, b) ((a) < (b) ? (a) : (b))
46 /* EMACS_INT - signed integer wide enough to hold an Emacs value
47 EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
48 pI - printf length modifier for EMACS_INT
49 EMACS_UINT - unsigned variant of EMACS_INT */
50 #ifndef EMACS_INT_MAX
51 # if LONG_MAX < LLONG_MAX && defined WIDE_EMACS_INT
52 typedef long long int EMACS_INT;
53 typedef unsigned long long int EMACS_UINT;
54 # define EMACS_INT_MAX LLONG_MAX
55 # define pI "ll"
56 # elif INT_MAX < LONG_MAX
57 typedef long int EMACS_INT;
58 typedef unsigned long int EMACS_UINT;
59 # define EMACS_INT_MAX LONG_MAX
60 # define pI "l"
61 # else
62 typedef int EMACS_INT;
63 typedef unsigned int EMACS_UINT;
64 # define EMACS_INT_MAX INT_MAX
65 # define pI ""
66 # endif
67 #endif
69 /* Number of bits in some machine integer types. */
70 enum
72 BITS_PER_CHAR = CHAR_BIT,
73 BITS_PER_SHORT = CHAR_BIT * sizeof (short),
74 BITS_PER_INT = CHAR_BIT * sizeof (int),
75 BITS_PER_LONG = CHAR_BIT * sizeof (long int),
76 BITS_PER_PTRDIFF_T = CHAR_BIT * sizeof (ptrdiff_t),
77 BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
80 /* printmax_t and uprintmax_t are types for printing large integers.
81 These are the widest integers that are supported for printing.
82 pMd etc. are conversions for printing them.
83 On C99 hosts, there's no problem, as even the widest integers work.
84 Fall back on EMACS_INT on pre-C99 hosts. */
85 #ifdef PRIdMAX
86 typedef intmax_t printmax_t;
87 typedef uintmax_t uprintmax_t;
88 # define pMd PRIdMAX
89 # define pMu PRIuMAX
90 #else
91 typedef EMACS_INT printmax_t;
92 typedef EMACS_UINT uprintmax_t;
93 # define pMd pI"d"
94 # define pMu pI"u"
95 #endif
97 /* Use pD to format ptrdiff_t values, which suffice for indexes into
98 buffers and strings. Emacs never allocates objects larger than
99 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
100 In C99, pD can always be "t"; configure it here for the sake of
101 pre-C99 libraries such as glibc 2.0 and Solaris 8. */
102 #if PTRDIFF_MAX == INT_MAX
103 # define pD ""
104 #elif PTRDIFF_MAX == LONG_MAX
105 # define pD "l"
106 #elif PTRDIFF_MAX == LLONG_MAX
107 # define pD "ll"
108 #else
109 # define pD "t"
110 #endif
112 /* Extra internal type checking? */
114 /* Define an Emacs version of 'assert (COND)', since some
115 system-defined 'assert's are flaky. COND should be free of side
116 effects; it may or may not be evaluated. */
117 #ifndef ENABLE_CHECKING
118 # define eassert(X) ((void) (0 && (X))) /* Check that X compiles. */
119 #else /* ENABLE_CHECKING */
121 extern _Noreturn void die (const char *, const char *, int);
123 /* The suppress_checking variable is initialized to 0 in alloc.c. Set
124 it to 1 using a debugger to temporarily disable aborting on
125 detected internal inconsistencies or error conditions.
127 In some cases, a good compiler may be able to optimize away the
128 eassert macro altogether, e.g., if XSTRING (x) uses eassert to test
129 STRINGP (x), but a particular use of XSTRING is invoked only after
130 testing that STRINGP (x) is true, making the test redundant. */
131 extern bool suppress_checking EXTERNALLY_VISIBLE;
133 # define eassert(cond) \
134 ((cond) || suppress_checking \
135 ? (void) 0 \
136 : die ("assertion failed: " # cond, __FILE__, __LINE__))
137 #endif /* ENABLE_CHECKING */
139 /* Use the configure flag --enable-check-lisp-object-type to make
140 Lisp_Object use a struct type instead of the default int. The flag
141 causes CHECK_LISP_OBJECT_TYPE to be defined. */
143 /***** Select the tagging scheme. *****/
144 /* The following option controls the tagging scheme:
145 - USE_LSB_TAG means that we can assume the least 3 bits of pointers are
146 always 0, and we can thus use them to hold tag bits, without
147 restricting our addressing space.
149 If ! USE_LSB_TAG, then use the top 3 bits for tagging, thus
150 restricting our possible address range.
152 USE_LSB_TAG not only requires the least 3 bits of pointers returned by
153 malloc to be 0 but also needs to be able to impose a mult-of-8 alignment
154 on the few static Lisp_Objects used: all the defsubr as well
155 as the two special buffers buffer_defaults and buffer_local_symbols. */
157 enum Lisp_Bits
159 /* Number of bits in a Lisp_Object tag. This can be used in #if,
160 and for GDB's sake also as a regular symbol. */
161 GCTYPEBITS =
162 #define GCTYPEBITS 3
163 GCTYPEBITS,
165 /* 2**GCTYPEBITS. This must be a macro that expands to a literal
166 integer constant, for MSVC. */
167 #define GCALIGNMENT 8
169 /* Number of bits in a Lisp_Object value, not counting the tag. */
170 VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS,
172 /* Number of bits in a Lisp fixnum tag. */
173 INTTYPEBITS = GCTYPEBITS - 1,
175 /* Number of bits in a Lisp fixnum value, not counting the tag. */
176 FIXNUM_BITS = VALBITS + 1
179 #if GCALIGNMENT != 1 << GCTYPEBITS
180 # error "GCALIGNMENT and GCTYPEBITS are inconsistent"
181 #endif
183 /* The maximum value that can be stored in a EMACS_INT, assuming all
184 bits other than the type bits contribute to a nonnegative signed value.
185 This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */
186 #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
188 /* Unless otherwise specified, use USE_LSB_TAG on systems where: */
189 #ifndef USE_LSB_TAG
190 /* 1. We know malloc returns a multiple of 8. */
191 # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \
192 || defined DARWIN_OS || defined __sun)
193 /* 2. We can specify multiple-of-8 alignment on static variables. */
194 # ifdef alignas
195 /* 3. Pointers-as-ints exceed VAL_MAX.
196 On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is:
197 a. unnecessary, because the top bits of an EMACS_INT are unused, and
198 b. slower, because it typically requires extra masking.
199 So, default USE_LSB_TAG to 1 only on hosts where it might be useful. */
200 # if VAL_MAX < UINTPTR_MAX
201 # define USE_LSB_TAG 1
202 # endif
203 # endif
204 # endif
205 #endif
206 #ifdef USE_LSB_TAG
207 # undef USE_LSB_TAG
208 enum enum_USE_LSB_TAG { USE_LSB_TAG = 1 };
209 # define USE_LSB_TAG 1
210 #else
211 enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 };
212 # define USE_LSB_TAG 0
213 #endif
215 #ifndef alignas
216 # define alignas(alignment) /* empty */
217 # if USE_LSB_TAG
218 # error "USE_LSB_TAG requires alignas"
219 # endif
220 #endif
223 /* Define the fundamental Lisp data structures. */
225 /* This is the set of Lisp data types. If you want to define a new
226 data type, read the comments after Lisp_Fwd_Type definition
227 below. */
229 /* Lisp integers use 2 tags, to give them one extra bit, thus
230 extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1. */
231 #define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
232 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
233 #define LISP_INT_TAG_P(x) (((x) & ~Lisp_Int1) == 0)
235 /* Idea stolen from GDB. MSVC doesn't support enums in bitfields,
236 and xlc complains vociferously about them. */
237 #if defined _MSC_VER || defined __IBMC__
238 #define ENUM_BF(TYPE) unsigned int
239 #else
240 #define ENUM_BF(TYPE) enum TYPE
241 #endif
244 enum Lisp_Type
246 /* Integer. XINT (obj) is the integer value. */
247 Lisp_Int0 = 0,
248 Lisp_Int1 = USE_LSB_TAG ? 1 << INTTYPEBITS : 1,
250 /* Symbol. XSYMBOL (object) points to a struct Lisp_Symbol. */
251 Lisp_Symbol = 2,
253 /* Miscellaneous. XMISC (object) points to a union Lisp_Misc,
254 whose first member indicates the subtype. */
255 Lisp_Misc = 3,
257 /* String. XSTRING (object) points to a struct Lisp_String.
258 The length of the string, and its contents, are stored therein. */
259 Lisp_String = USE_LSB_TAG ? 1 : 1 << INTTYPEBITS,
261 /* Vector of Lisp objects, or something resembling it.
262 XVECTOR (object) points to a struct Lisp_Vector, which contains
263 the size and contents. The size field also contains the type
264 information, if it's not a real vector object. */
265 Lisp_Vectorlike = 5,
267 /* Cons. XCONS (object) points to a struct Lisp_Cons. */
268 Lisp_Cons = 6,
270 Lisp_Float = 7,
273 /* This is the set of data types that share a common structure.
274 The first member of the structure is a type code from this set.
275 The enum values are arbitrary, but we'll use large numbers to make it
276 more likely that we'll spot the error if a random word in memory is
277 mistakenly interpreted as a Lisp_Misc. */
278 enum Lisp_Misc_Type
280 Lisp_Misc_Free = 0x5eab,
281 Lisp_Misc_Marker,
282 Lisp_Misc_Overlay,
283 Lisp_Misc_Save_Value,
284 /* Currently floats are not a misc type,
285 but let's define this in case we want to change that. */
286 Lisp_Misc_Float,
287 /* This is not a type code. It is for range checking. */
288 Lisp_Misc_Limit
291 /* These are the types of forwarding objects used in the value slot
292 of symbols for special built-in variables whose value is stored in
293 C variables. */
294 enum Lisp_Fwd_Type
296 Lisp_Fwd_Int, /* Fwd to a C `int' variable. */
297 Lisp_Fwd_Bool, /* Fwd to a C boolean var. */
298 Lisp_Fwd_Obj, /* Fwd to a C Lisp_Object variable. */
299 Lisp_Fwd_Buffer_Obj, /* Fwd to a Lisp_Object field of buffers. */
300 Lisp_Fwd_Kboard_Obj, /* Fwd to a Lisp_Object field of kboards. */
303 /* If you want to define a new Lisp data type, here are some
304 instructions. See the thread at
305 http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00561.html
306 for more info.
308 First, there are already a couple of Lisp types that can be used if
309 your new type does not need to be exposed to Lisp programs nor
310 displayed to users. These are Lisp_Save_Value, a Lisp_Misc
311 subtype; and PVEC_OTHER, a kind of vectorlike object. The former
312 is suitable for temporarily stashing away pointers and integers in
313 a Lisp object (see the existing uses of make_save_value and
314 XSAVE_VALUE). The latter is useful for vector-like Lisp objects
315 that need to be used as part of other objects, but which are never
316 shown to users or Lisp code (search for PVEC_OTHER in xterm.c for
317 an example).
319 These two types don't look pretty when printed, so they are
320 unsuitable for Lisp objects that can be exposed to users.
322 To define a new data type, add one more Lisp_Misc subtype or one
323 more pseudovector subtype. Pseudovectors are more suitable for
324 objects with several slots that need to support fast random access,
325 while Lisp_Misc types are for everything else. A pseudovector object
326 provides one or more slots for Lisp objects, followed by struct
327 members that are accessible only from C. A Lisp_Misc object is a
328 wrapper for a C struct that can contain anything you like.
330 Explicit freeing is discouraged for Lisp objects in general. But if
331 you really need to exploit this, use Lisp_Misc (check free_misc in
332 alloc.c to see why). There is no way to free a vectorlike object.
334 To add a new pseudovector type, extend the pvec_type enumeration;
335 to add a new Lisp_Misc, extend the Lisp_Misc_Type enumeration.
337 For a Lisp_Misc, you will also need to add your entry to union
338 Lisp_Misc (but make sure the first word has the same structure as
339 the others, starting with a 16-bit member of the Lisp_Misc_Type
340 enumeration and a 1-bit GC markbit) and make sure the overall size
341 of the union is not increased by your addition.
343 For a new pseudovector, it's highly desirable to limit the size
344 of your data type by VBLOCK_BYTES_MAX bytes (defined in alloc.c).
345 Otherwise you will need to change sweep_vectors (also in alloc.c).
347 Then you will need to add switch branches in print.c (in
348 print_object, to print your object, and possibly also in
349 print_preprocess) and to alloc.c, to mark your object (in
350 mark_object) and to free it (in gc_sweep). The latter is also the
351 right place to call any code specific to your data type that needs
352 to run when the object is recycled -- e.g., free any additional
353 resources allocated for it that are not Lisp objects. You can even
354 make a pointer to the function that frees the resources a slot in
355 your object -- this way, the same object could be used to represent
356 several disparate C structures. */
358 #ifdef CHECK_LISP_OBJECT_TYPE
360 typedef struct { EMACS_INT i; } Lisp_Object;
362 #define XLI(o) (o).i
363 LISP_INLINE Lisp_Object
364 XIL (EMACS_INT i)
366 Lisp_Object o = { i };
367 return o;
370 LISP_INLINE Lisp_Object
371 LISP_MAKE_RVALUE (Lisp_Object o)
373 return o;
376 #define LISP_INITIALLY_ZERO {0}
378 #undef CHECK_LISP_OBJECT_TYPE
379 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = 1 };
380 #else /* CHECK_LISP_OBJECT_TYPE */
382 /* If a struct type is not wanted, define Lisp_Object as just a number. */
384 typedef EMACS_INT Lisp_Object;
385 #define XLI(o) (o)
386 #define XIL(i) (i)
387 #define LISP_MAKE_RVALUE(o) (0 + (o))
388 #define LISP_INITIALLY_ZERO 0
389 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = 0 };
390 #endif /* CHECK_LISP_OBJECT_TYPE */
392 /* In the size word of a vector, this bit means the vector has been marked. */
394 static ptrdiff_t const ARRAY_MARK_FLAG
395 #define ARRAY_MARK_FLAG PTRDIFF_MIN
396 = ARRAY_MARK_FLAG;
398 /* In the size word of a struct Lisp_Vector, this bit means it's really
399 some other vector-like object. */
400 static ptrdiff_t const PSEUDOVECTOR_FLAG
401 #define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
402 = PSEUDOVECTOR_FLAG;
404 /* In a pseudovector, the size field actually contains a word with one
405 PSEUDOVECTOR_FLAG bit set, and one of the following values extracted
406 with PVEC_TYPE_MASK to indicate the actual type. */
407 enum pvec_type
409 PVEC_NORMAL_VECTOR,
410 PVEC_FREE,
411 PVEC_PROCESS,
412 PVEC_FRAME,
413 PVEC_WINDOW,
414 PVEC_BOOL_VECTOR,
415 PVEC_BUFFER,
416 PVEC_HASH_TABLE,
417 PVEC_TERMINAL,
418 PVEC_WINDOW_CONFIGURATION,
419 PVEC_SUBR,
420 PVEC_OTHER,
421 /* These should be last, check internal_equal to see why. */
422 PVEC_COMPILED,
423 PVEC_CHAR_TABLE,
424 PVEC_SUB_CHAR_TABLE,
425 PVEC_FONT /* Should be last because it's used for range checking. */
428 /* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
429 which were stored in a Lisp_Object. */
430 #ifndef DATA_SEG_BITS
431 # define DATA_SEG_BITS 0
432 #endif
433 enum { gdb_DATA_SEG_BITS = DATA_SEG_BITS };
434 #undef DATA_SEG_BITS
436 enum More_Lisp_Bits
438 DATA_SEG_BITS = gdb_DATA_SEG_BITS,
440 /* For convenience, we also store the number of elements in these bits.
441 Note that this size is not necessarily the memory-footprint size, but
442 only the number of Lisp_Object fields (that need to be traced by GC).
443 The distinction is used, e.g., by Lisp_Process, which places extra
444 non-Lisp_Object fields at the end of the structure. */
445 PSEUDOVECTOR_SIZE_BITS = 12,
446 PSEUDOVECTOR_SIZE_MASK = (1 << PSEUDOVECTOR_SIZE_BITS) - 1,
448 /* To calculate the memory footprint of the pseudovector, it's useful
449 to store the size of non-Lisp area in word_size units here. */
450 PSEUDOVECTOR_REST_BITS = 12,
451 PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1)
452 << PSEUDOVECTOR_SIZE_BITS),
454 /* Used to extract pseudovector subtype information. */
455 PSEUDOVECTOR_AREA_BITS = PSEUDOVECTOR_SIZE_BITS + PSEUDOVECTOR_REST_BITS,
456 PVEC_TYPE_MASK = 0x3f << PSEUDOVECTOR_AREA_BITS,
458 /* Number of bits to put in each character in the internal representation
459 of bool vectors. This should not vary across implementations. */
460 BOOL_VECTOR_BITS_PER_CHAR = 8
463 /* These macros extract various sorts of values from a Lisp_Object.
464 For example, if tem is a Lisp_Object whose type is Lisp_Cons,
465 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */
467 #if USE_LSB_TAG
469 enum lsb_bits
471 TYPEMASK = (1 << GCTYPEBITS) - 1,
472 VALMASK = ~ TYPEMASK
474 #define XTYPE(a) ((enum Lisp_Type) (XLI (a) & TYPEMASK))
475 #define XINT(a) (XLI (a) >> INTTYPEBITS)
476 #define XUINT(a) ((EMACS_UINT) XLI (a) >> INTTYPEBITS)
477 #define make_number(N) XIL ((EMACS_INT) (N) << INTTYPEBITS)
478 #define make_lisp_ptr(ptr, type) \
479 (eassert (XTYPE (XIL ((intptr_t) (ptr))) == 0), /* Check alignment. */ \
480 XIL ((type) | (intptr_t) (ptr)))
482 #define XPNTR(a) ((intptr_t) (XLI (a) & ~TYPEMASK))
483 #define XUNTAG(a, type) ((intptr_t) (XLI (a) - (type)))
485 #else /* not USE_LSB_TAG */
487 static EMACS_INT const VALMASK
488 #define VALMASK VAL_MAX
489 = VALMASK;
491 #define XTYPE(a) ((enum Lisp_Type) ((EMACS_UINT) XLI (a) >> VALBITS))
493 /* For integers known to be positive, XFASTINT provides fast retrieval
494 and XSETFASTINT provides fast storage. This takes advantage of the
495 fact that Lisp integers have zero-bits in their tags. */
496 #define XFASTINT(a) (XLI (a) + 0)
497 #define XSETFASTINT(a, b) ((a) = XIL (b))
499 /* Extract the value of a Lisp_Object as a (un)signed integer. */
501 #define XINT(a) (XLI (a) << INTTYPEBITS >> INTTYPEBITS)
502 #define XUINT(a) ((EMACS_UINT) (XLI (a) & INTMASK))
503 #define make_number(N) XIL ((EMACS_INT) (N) & INTMASK)
505 #define make_lisp_ptr(ptr, type) \
506 (XIL ((EMACS_INT) ((EMACS_UINT) (type) << VALBITS) \
507 + ((intptr_t) (ptr) & VALMASK)))
509 /* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
510 which were stored in a Lisp_Object. */
511 #define XPNTR(a) ((uintptr_t) ((XLI (a) & VALMASK) | DATA_SEG_BITS))
513 #endif /* not USE_LSB_TAG */
515 /* Return a (Lisp-integer sized) hash of the Lisp_Object value. Happens to be
516 like XUINT right now, but XUINT should only be applied to objects we know
517 are integers. */
518 #define XHASH(a) XUINT (a)
520 /* For integers known to be positive, XFASTINT sometimes provides
521 faster retrieval and XSETFASTINT provides faster storage.
522 If not, fallback on the non-accelerated path. */
523 #ifndef XFASTINT
524 # define XFASTINT(a) (XINT (a))
525 # define XSETFASTINT(a, b) (XSETINT (a, b))
526 #endif
528 /* Extract the pointer value of the Lisp object A, under the
529 assumption that A's type is TYPE. This is a fallback
530 implementation if nothing faster is available. */
531 #ifndef XUNTAG
532 # define XUNTAG(a, type) XPNTR (a)
533 #endif
535 #define EQ(x, y) (XLI (x) == XLI (y))
537 /* Largest and smallest representable fixnum values. These are the C
538 values. They are macros for use in static initializers. */
539 #define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
540 #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
542 /* Value is non-zero if I doesn't fit into a Lisp fixnum. It is
543 written this way so that it also works if I is of unsigned
544 type or if I is a NaN. */
546 #define FIXNUM_OVERFLOW_P(i) \
547 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
549 LISP_INLINE ptrdiff_t
550 clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
552 return num < lower ? lower : num <= upper ? num : upper;
556 /* Extract a value or address from a Lisp_Object. */
558 #define XCONS(a) (eassert (CONSP (a)), \
559 (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
560 #define XVECTOR(a) (eassert (VECTORLIKEP (a)), \
561 (struct Lisp_Vector *) XUNTAG (a, Lisp_Vectorlike))
562 #define XSTRING(a) (eassert (STRINGP (a)), \
563 (struct Lisp_String *) XUNTAG (a, Lisp_String))
564 #define XSYMBOL(a) (eassert (SYMBOLP (a)), \
565 (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol))
566 #define XFLOAT(a) (eassert (FLOATP (a)), \
567 (struct Lisp_Float *) XUNTAG (a, Lisp_Float))
569 /* Misc types. */
571 #define XMISC(a) ((union Lisp_Misc *) XUNTAG (a, Lisp_Misc))
572 #define XMISCANY(a) (eassert (MISCP (a)), &(XMISC (a)->u_any))
573 #define XMISCTYPE(a) (XMISCANY (a)->type)
574 #define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker))
575 #define XOVERLAY(a) (eassert (OVERLAYP (a)), &(XMISC (a)->u_overlay))
577 /* Forwarding object types. */
579 #define XFWDTYPE(a) (a->u_intfwd.type)
580 #define XINTFWD(a) (eassert (INTFWDP (a)), &((a)->u_intfwd))
581 #define XBOOLFWD(a) (eassert (BOOLFWDP (a)), &((a)->u_boolfwd))
582 #define XOBJFWD(a) (eassert (OBJFWDP (a)), &((a)->u_objfwd))
583 #define XBUFFER_OBJFWD(a) \
584 (eassert (BUFFER_OBJFWDP (a)), &((a)->u_buffer_objfwd))
585 #define XKBOARD_OBJFWD(a) \
586 (eassert (KBOARD_OBJFWDP (a)), &((a)->u_kboard_objfwd))
588 /* Pseudovector types. */
589 struct Lisp_Process;
590 LISP_INLINE Lisp_Object make_lisp_proc (struct Lisp_Process *p)
591 { return make_lisp_ptr (p, Lisp_Vectorlike); }
592 #define XPROCESS(a) (eassert (PROCESSP (a)), \
593 (struct Lisp_Process *) XUNTAG (a, Lisp_Vectorlike))
594 #define XWINDOW(a) (eassert (WINDOWP (a)), \
595 (struct window *) XUNTAG (a, Lisp_Vectorlike))
596 #define XTERMINAL(a) (eassert (TERMINALP (a)), \
597 (struct terminal *) XUNTAG (a, Lisp_Vectorlike))
598 #define XSUBR(a) (eassert (SUBRP (a)), \
599 (struct Lisp_Subr *) XUNTAG (a, Lisp_Vectorlike))
600 #define XBUFFER(a) (eassert (BUFFERP (a)), \
601 (struct buffer *) XUNTAG (a, Lisp_Vectorlike))
602 #define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), \
603 (struct Lisp_Char_Table *) XUNTAG (a, Lisp_Vectorlike))
604 #define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), \
605 ((struct Lisp_Sub_Char_Table *) \
606 XUNTAG (a, Lisp_Vectorlike)))
607 #define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), \
608 ((struct Lisp_Bool_Vector *) \
609 XUNTAG (a, Lisp_Vectorlike)))
611 /* Construct a Lisp_Object from a value or address. */
613 #define XSETINT(a, b) ((a) = make_number (b))
614 #define XSETCONS(a, b) ((a) = make_lisp_ptr (b, Lisp_Cons))
615 #define XSETVECTOR(a, b) ((a) = make_lisp_ptr (b, Lisp_Vectorlike))
616 #define XSETSTRING(a, b) ((a) = make_lisp_ptr (b, Lisp_String))
617 #define XSETSYMBOL(a, b) ((a) = make_lisp_ptr (b, Lisp_Symbol))
618 #define XSETFLOAT(a, b) ((a) = make_lisp_ptr (b, Lisp_Float))
620 /* Misc types. */
622 #define XSETMISC(a, b) ((a) = make_lisp_ptr (b, Lisp_Misc))
623 #define XSETMARKER(a, b) (XSETMISC (a, b), XMISCTYPE (a) = Lisp_Misc_Marker)
625 /* Pseudovector types. */
627 #define XSETPVECTYPE(v, code) \
628 ((v)->header.size |= PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS))
629 #define XSETPVECTYPESIZE(v, code, lispsize, restsize) \
630 ((v)->header.size = (PSEUDOVECTOR_FLAG \
631 | ((code) << PSEUDOVECTOR_AREA_BITS) \
632 | ((restsize) << PSEUDOVECTOR_SIZE_BITS) \
633 | (lispsize)))
635 /* The cast to struct vectorlike_header * avoids aliasing issues. */
636 #define XSETPSEUDOVECTOR(a, b, code) \
637 XSETTYPED_PSEUDOVECTOR (a, b, \
638 (((struct vectorlike_header *) \
639 XUNTAG (a, Lisp_Vectorlike)) \
640 ->size), \
641 code)
642 #define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \
643 (XSETVECTOR (a, b), \
644 eassert ((size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) \
645 == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS))))
647 #define XSETWINDOW_CONFIGURATION(a, b) \
648 (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW_CONFIGURATION))
649 #define XSETPROCESS(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_PROCESS))
650 #define XSETWINDOW(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW))
651 #define XSETTERMINAL(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_TERMINAL))
652 #define XSETSUBR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUBR))
653 #define XSETCOMPILED(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_COMPILED))
654 #define XSETBUFFER(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BUFFER))
655 #define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE))
656 #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
657 #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
659 /* Convenience macros for dealing with Lisp arrays. */
661 #define AREF(ARRAY, IDX) XVECTOR ((ARRAY))->contents[IDX]
662 #define ASIZE(ARRAY) XVECTOR ((ARRAY))->header.size
663 #define ASET(ARRAY, IDX, VAL) \
664 (eassert (0 <= (IDX) && (IDX) < ASIZE (ARRAY)), \
665 XVECTOR (ARRAY)->contents[IDX] = (VAL))
667 /* Convenience macros for dealing with Lisp strings. */
669 #define SDATA(string) (XSTRING (string)->data + 0)
670 #define SREF(string, index) (SDATA (string)[index] + 0)
671 #define SSET(string, index, new) (SDATA (string)[index] = (new))
672 #define SCHARS(string) (XSTRING (string)->size + 0)
673 #define SBYTES(string) (STRING_BYTES (XSTRING (string)) + 0)
675 /* Avoid "differ in sign" warnings. */
676 #define SSDATA(x) ((char *) SDATA (x))
678 #define STRING_SET_CHARS(string, newsize) \
679 (XSTRING (string)->size = (newsize))
681 #define STRING_COPYIN(string, index, new, count) \
682 memcpy (SDATA (string) + index, new, count)
684 /* Type checking. */
686 #define CHECK_TYPE(ok, Qxxxp, x) \
687 do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0)
689 /* Deprecated and will be removed soon. */
691 #define INTERNAL_FIELD(field) field ## _
693 /* See the macros in intervals.h. */
695 typedef struct interval *INTERVAL;
697 /* Complain if object is not string or buffer type. */
698 #define CHECK_STRING_OR_BUFFER(x) \
699 CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x)
701 struct Lisp_Cons
703 /* Car of this cons cell. */
704 Lisp_Object car;
706 union
708 /* Cdr of this cons cell. */
709 Lisp_Object cdr;
711 /* Used to chain conses on a free list. */
712 struct Lisp_Cons *chain;
713 } u;
716 /* Take the car or cdr of something known to be a cons cell. */
717 /* The _AS_LVALUE macros shouldn't be used outside of the minimal set
718 of code that has to know what a cons cell looks like. Other code not
719 part of the basic lisp implementation should assume that the car and cdr
720 fields are not accessible as lvalues. (What if we want to switch to
721 a copying collector someday? Cached cons cell field addresses may be
722 invalidated at arbitrary points.) */
723 #define XCAR_AS_LVALUE(c) (XCONS (c)->car)
724 #define XCDR_AS_LVALUE(c) (XCONS (c)->u.cdr)
726 /* Use these from normal code. */
727 #define XCAR(c) LISP_MAKE_RVALUE (XCAR_AS_LVALUE (c))
728 #define XCDR(c) LISP_MAKE_RVALUE (XCDR_AS_LVALUE (c))
730 /* Use these to set the fields of a cons cell.
732 Note that both arguments may refer to the same object, so 'n'
733 should not be read after 'c' is first modified. Also, neither
734 argument should be evaluated more than once; side effects are
735 especially common in the second argument. */
736 #define XSETCAR(c,n) (XCAR_AS_LVALUE (c) = (n))
737 #define XSETCDR(c,n) (XCDR_AS_LVALUE (c) = (n))
739 /* Take the car or cdr of something whose type is not known. */
740 #define CAR(c) \
741 (CONSP ((c)) ? XCAR ((c)) \
742 : NILP ((c)) ? Qnil \
743 : wrong_type_argument (Qlistp, (c)))
745 #define CDR(c) \
746 (CONSP ((c)) ? XCDR ((c)) \
747 : NILP ((c)) ? Qnil \
748 : wrong_type_argument (Qlistp, (c)))
750 /* Take the car or cdr of something whose type is not known. */
751 #define CAR_SAFE(c) \
752 (CONSP ((c)) ? XCAR ((c)) : Qnil)
754 #define CDR_SAFE(c) \
755 (CONSP ((c)) ? XCDR ((c)) : Qnil)
757 /* True if STR is a multibyte string. */
758 #define STRING_MULTIBYTE(STR) \
759 (XSTRING (STR)->size_byte >= 0)
761 /* Return the length in bytes of STR. */
763 #ifdef GC_CHECK_STRING_BYTES
765 struct Lisp_String;
766 extern ptrdiff_t string_bytes (struct Lisp_String *);
767 #define STRING_BYTES(S) string_bytes ((S))
769 #else /* not GC_CHECK_STRING_BYTES */
771 #define STRING_BYTES(STR) \
772 ((STR)->size_byte < 0 ? (STR)->size : (STR)->size_byte)
774 #endif /* not GC_CHECK_STRING_BYTES */
776 /* An upper bound on the number of bytes in a Lisp string, not
777 counting the terminating null. This a tight enough bound to
778 prevent integer overflow errors that would otherwise occur during
779 string size calculations. A string cannot contain more bytes than
780 a fixnum can represent, nor can it be so long that C pointer
781 arithmetic stops working on the string plus its terminating null.
782 Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
783 may be a bit smaller than STRING_BYTES_BOUND, calculating it here
784 would expose alloc.c internal details that we'd rather keep
785 private.
787 This is a macro for use in static initializers. The cast to
788 ptrdiff_t ensures that the macro is signed. */
789 #define STRING_BYTES_BOUND \
790 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1))
792 /* Mark STR as a unibyte string. */
793 #define STRING_SET_UNIBYTE(STR) \
794 do { if (EQ (STR, empty_multibyte_string)) \
795 (STR) = empty_unibyte_string; \
796 else XSTRING (STR)->size_byte = -1; } while (0)
798 /* Mark STR as a multibyte string. Assure that STR contains only
799 ASCII characters in advance. */
800 #define STRING_SET_MULTIBYTE(STR) \
801 do { if (EQ (STR, empty_unibyte_string)) \
802 (STR) = empty_multibyte_string; \
803 else XSTRING (STR)->size_byte = XSTRING (STR)->size; } while (0)
805 /* In a string or vector, the sign bit of the `size' is the gc mark bit. */
807 struct Lisp_String
809 ptrdiff_t size;
810 ptrdiff_t size_byte;
811 INTERVAL intervals; /* Text properties in this string. */
812 unsigned char *data;
815 /* Header of vector-like objects. This documents the layout constraints on
816 vectors and pseudovectors (objects of PVEC_xxx subtype). It also prevents
817 compilers from being fooled by Emacs's type punning: the XSETPSEUDOVECTOR
818 and PSEUDOVECTORP macros cast their pointers to struct vectorlike_header *,
819 because when two such pointers potentially alias, a compiler won't
820 incorrectly reorder loads and stores to their size fields. See
821 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */
822 struct vectorlike_header
824 /* The only field contains various pieces of information:
825 - The MSB (ARRAY_MARK_FLAG) holds the gcmarkbit.
826 - The next bit (PSEUDOVECTOR_FLAG) indicates whether this is a plain
827 vector (0) or a pseudovector (1).
828 - If PSEUDOVECTOR_FLAG is 0, the rest holds the size (number
829 of slots) of the vector.
830 - If PSEUDOVECTOR_FLAG is 1, the rest is subdivided into three fields:
831 - a) pseudovector subtype held in PVEC_TYPE_MASK field;
832 - b) number of Lisp_Objects slots at the beginning of the object
833 held in PSEUDOVECTOR_SIZE_MASK field. These objects are always
834 traced by the GC;
835 - c) size of the rest fields held in PSEUDOVECTOR_REST_MASK and
836 measured in word_size units. Rest fields may also include
837 Lisp_Objects, but these objects usually needs some special treatment
838 during GC.
839 There are some exceptions. For PVEC_FREE, b) is always zero. For
840 PVEC_BOOL_VECTOR and PVEC_SUBR, both b) and c) are always zero.
841 Current layout limits the pseudovectors to 63 PVEC_xxx subtypes,
842 4095 Lisp_Objects in GC-ed area and 4095 word-sized other slots. */
843 ptrdiff_t size;
846 /* Regular vector is just a header plus array of Lisp_Objects. */
848 struct Lisp_Vector
850 struct vectorlike_header header;
851 Lisp_Object contents[1];
854 /* A boolvector is a kind of vectorlike, with contents are like a string. */
856 struct Lisp_Bool_Vector
858 /* HEADER.SIZE is the vector's size field. It doesn't have the real size,
859 just the subtype information. */
860 struct vectorlike_header header;
861 /* This is the size in bits. */
862 EMACS_INT size;
863 /* This contains the actual bits, packed into bytes. */
864 unsigned char data[1];
867 /* Some handy constants for calculating sizes
868 and offsets, mostly of vectorlike objects. */
870 enum
872 header_size = offsetof (struct Lisp_Vector, contents),
873 bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
874 word_size = sizeof (Lisp_Object)
877 /* If a struct is made to look like a vector, this macro returns the length
878 of the shortest vector that would hold that struct. */
880 #define VECSIZE(type) \
881 ((sizeof (type) - header_size + word_size - 1) / word_size)
883 /* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
884 at the end and we need to compute the number of Lisp_Object fields (the
885 ones that the GC needs to trace). */
887 #define PSEUDOVECSIZE(type, nonlispfield) \
888 ((offsetof (type, nonlispfield) - header_size) / word_size)
890 /* A char-table is a kind of vectorlike, with contents are like a
891 vector but with a few other slots. For some purposes, it makes
892 sense to handle a char-table with type struct Lisp_Vector. An
893 element of a char table can be any Lisp objects, but if it is a sub
894 char-table, we treat it a table that contains information of a
895 specific range of characters. A sub char-table has the same
896 structure as a vector. A sub char table appears only in an element
897 of a char-table, and there's no way to access it directly from
898 Emacs Lisp program. */
900 #ifdef __GNUC__
902 #define CHAR_TABLE_REF_ASCII(CT, IDX) \
903 ({struct Lisp_Char_Table *_tbl = NULL; \
904 Lisp_Object _val; \
905 do { \
906 _tbl = _tbl ? XCHAR_TABLE (_tbl->parent) : XCHAR_TABLE (CT); \
907 _val = (! SUB_CHAR_TABLE_P (_tbl->ascii) ? _tbl->ascii \
908 : XSUB_CHAR_TABLE (_tbl->ascii)->contents[IDX]); \
909 if (NILP (_val)) \
910 _val = _tbl->defalt; \
911 } while (NILP (_val) && ! NILP (_tbl->parent)); \
912 _val; })
914 #else /* not __GNUC__ */
916 #define CHAR_TABLE_REF_ASCII(CT, IDX) \
917 (! NILP (XCHAR_TABLE (CT)->ascii) \
918 ? (! SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii) \
919 ? XCHAR_TABLE (CT)->ascii \
920 : ! NILP (XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX]) \
921 ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] \
922 : char_table_ref ((CT), (IDX))) \
923 : char_table_ref ((CT), (IDX)))
925 #endif /* not __GNUC__ */
927 /* Compute A OP B, using the unsigned comparison operator OP. A and B
928 should be integer expressions. This is not the same as
929 mathematical comparison; for example, UNSIGNED_CMP (0, <, -1)
930 returns 1. For efficiency, prefer plain unsigned comparison if A
931 and B's sizes both fit (after integer promotion). */
932 #define UNSIGNED_CMP(a, op, b) \
933 (max (sizeof ((a) + 0), sizeof ((b) + 0)) <= sizeof (unsigned) \
934 ? ((a) + (unsigned) 0) op ((b) + (unsigned) 0) \
935 : ((a) + (uintmax_t) 0) op ((b) + (uintmax_t) 0))
937 /* Nonzero iff C is an ASCII character. */
938 #define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
940 /* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
941 characters. Do not check validity of CT. */
942 #define CHAR_TABLE_REF(CT, IDX) \
943 (ASCII_CHAR_P (IDX) ? CHAR_TABLE_REF_ASCII ((CT), (IDX)) \
944 : char_table_ref ((CT), (IDX)))
946 /* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
947 8-bit European characters. Do not check validity of CT. */
948 #define CHAR_TABLE_SET(CT, IDX, VAL) \
949 (ASCII_CHAR_P (IDX) && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii) \
950 ? set_sub_char_table_contents (XCHAR_TABLE (CT)->ascii, IDX, VAL) \
951 : char_table_set (CT, IDX, VAL))
953 enum CHARTAB_SIZE_BITS
955 CHARTAB_SIZE_BITS_0 = 6,
956 CHARTAB_SIZE_BITS_1 = 4,
957 CHARTAB_SIZE_BITS_2 = 5,
958 CHARTAB_SIZE_BITS_3 = 7
961 extern const int chartab_size[4];
963 struct Lisp_Char_Table
965 /* HEADER.SIZE is the vector's size field, which also holds the
966 pseudovector type information. It holds the size, too.
967 The size counts the defalt, parent, purpose, ascii,
968 contents, and extras slots. */
969 struct vectorlike_header header;
971 /* This holds a default value,
972 which is used whenever the value for a specific character is nil. */
973 Lisp_Object defalt;
975 /* This points to another char table, which we inherit from when the
976 value for a specific character is nil. The `defalt' slot takes
977 precedence over this. */
978 Lisp_Object parent;
980 /* This is a symbol which says what kind of use this char-table is
981 meant for. */
982 Lisp_Object purpose;
984 /* The bottom sub char-table for characters of the range 0..127. It
985 is nil if none of ASCII character has a specific value. */
986 Lisp_Object ascii;
988 Lisp_Object contents[(1 << CHARTAB_SIZE_BITS_0)];
990 /* These hold additional data. It is a vector. */
991 Lisp_Object extras[1];
994 struct Lisp_Sub_Char_Table
996 /* HEADER.SIZE is the vector's size field, which also holds the
997 pseudovector type information. It holds the size, too. */
998 struct vectorlike_header header;
1000 /* Depth of this sub char-table. It should be 1, 2, or 3. A sub
1001 char-table of depth 1 contains 16 elements, and each element
1002 covers 4096 (128*32) characters. A sub char-table of depth 2
1003 contains 32 elements, and each element covers 128 characters. A
1004 sub char-table of depth 3 contains 128 elements, and each element
1005 is for one character. */
1006 Lisp_Object depth;
1008 /* Minimum character covered by the sub char-table. */
1009 Lisp_Object min_char;
1011 /* Use set_sub_char_table_contents to set this. */
1012 Lisp_Object contents[1];
1015 /* This structure describes a built-in function.
1016 It is generated by the DEFUN macro only.
1017 defsubr makes it into a Lisp object. */
1019 struct Lisp_Subr
1021 struct vectorlike_header header;
1022 union {
1023 Lisp_Object (*a0) (void);
1024 Lisp_Object (*a1) (Lisp_Object);
1025 Lisp_Object (*a2) (Lisp_Object, Lisp_Object);
1026 Lisp_Object (*a3) (Lisp_Object, Lisp_Object, Lisp_Object);
1027 Lisp_Object (*a4) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1028 Lisp_Object (*a5) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1029 Lisp_Object (*a6) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1030 Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1031 Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1032 Lisp_Object (*aUNEVALLED) (Lisp_Object args);
1033 Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
1034 } function;
1035 short min_args, max_args;
1036 const char *symbol_name;
1037 const char *intspec;
1038 const char *doc;
1041 /* This is the number of slots that every char table must have. This
1042 counts the ordinary slots and the top, defalt, parent, and purpose
1043 slots. */
1044 enum CHAR_TABLE_STANDARD_SLOTS
1046 CHAR_TABLE_STANDARD_SLOTS = VECSIZE (struct Lisp_Char_Table) - 1
1049 /* Return the number of "extra" slots in the char table CT. */
1051 #define CHAR_TABLE_EXTRA_SLOTS(CT) \
1052 (((CT)->header.size & PSEUDOVECTOR_SIZE_MASK) - CHAR_TABLE_STANDARD_SLOTS)
1055 /***********************************************************************
1056 Symbols
1057 ***********************************************************************/
1059 /* Interned state of a symbol. */
1061 enum symbol_interned
1063 SYMBOL_UNINTERNED = 0,
1064 SYMBOL_INTERNED = 1,
1065 SYMBOL_INTERNED_IN_INITIAL_OBARRAY = 2
1068 enum symbol_redirect
1070 SYMBOL_PLAINVAL = 4,
1071 SYMBOL_VARALIAS = 1,
1072 SYMBOL_LOCALIZED = 2,
1073 SYMBOL_FORWARDED = 3
1076 struct Lisp_Symbol
1078 unsigned gcmarkbit : 1;
1080 /* Indicates where the value can be found:
1081 0 : it's a plain var, the value is in the `value' field.
1082 1 : it's a varalias, the value is really in the `alias' symbol.
1083 2 : it's a localized var, the value is in the `blv' object.
1084 3 : it's a forwarding variable, the value is in `forward'. */
1085 ENUM_BF (symbol_redirect) redirect : 3;
1087 /* Non-zero means symbol is constant, i.e. changing its value
1088 should signal an error. If the value is 3, then the var
1089 can be changed, but only by `defconst'. */
1090 unsigned constant : 2;
1092 /* Interned state of the symbol. This is an enumerator from
1093 enum symbol_interned. */
1094 unsigned interned : 2;
1096 /* Non-zero means that this variable has been explicitly declared
1097 special (with `defvar' etc), and shouldn't be lexically bound. */
1098 unsigned declared_special : 1;
1100 /* The symbol's name, as a Lisp string. */
1101 Lisp_Object name;
1103 /* Value of the symbol or Qunbound if unbound. Which alternative of the
1104 union is used depends on the `redirect' field above. */
1105 union {
1106 Lisp_Object value;
1107 struct Lisp_Symbol *alias;
1108 struct Lisp_Buffer_Local_Value *blv;
1109 union Lisp_Fwd *fwd;
1110 } val;
1112 /* Function value of the symbol or Qnil if not fboundp. */
1113 Lisp_Object function;
1115 /* The symbol's property list. */
1116 Lisp_Object plist;
1118 /* Next symbol in obarray bucket, if the symbol is interned. */
1119 struct Lisp_Symbol *next;
1122 /* Value is name of symbol. */
1124 #define SYMBOL_VAL(sym) \
1125 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), sym->val.value)
1126 #define SYMBOL_ALIAS(sym) \
1127 (eassert ((sym)->redirect == SYMBOL_VARALIAS), (sym)->val.alias)
1128 #define SYMBOL_BLV(sym) \
1129 (eassert ((sym)->redirect == SYMBOL_LOCALIZED), (sym)->val.blv)
1130 #define SYMBOL_FWD(sym) \
1131 (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd)
1132 #define SET_SYMBOL_VAL(sym, v) \
1133 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value = (v))
1134 #define SET_SYMBOL_ALIAS(sym, v) \
1135 (eassert ((sym)->redirect == SYMBOL_VARALIAS), (sym)->val.alias = (v))
1136 #define SET_SYMBOL_BLV(sym, v) \
1137 (eassert ((sym)->redirect == SYMBOL_LOCALIZED), (sym)->val.blv = (v))
1138 #define SET_SYMBOL_FWD(sym, v) \
1139 (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd = (v))
1141 #define SYMBOL_NAME(sym) XSYMBOL (sym)->name
1143 /* Value is non-zero if SYM is an interned symbol. */
1145 #define SYMBOL_INTERNED_P(sym) \
1146 (XSYMBOL (sym)->interned != SYMBOL_UNINTERNED)
1148 /* Value is non-zero if SYM is interned in initial_obarray. */
1150 #define SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P(sym) \
1151 (XSYMBOL (sym)->interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY)
1153 /* Value is non-zero if symbol is considered a constant, i.e. its
1154 value cannot be changed (there is an exception for keyword symbols,
1155 whose value can be set to the keyword symbol itself). */
1157 #define SYMBOL_CONSTANT_P(sym) XSYMBOL (sym)->constant
1159 #define DEFSYM(sym, name) \
1160 do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0)
1163 /***********************************************************************
1164 Hash Tables
1165 ***********************************************************************/
1167 /* The structure of a Lisp hash table. */
1169 struct hash_table_test
1171 /* Name of the function used to compare keys. */
1172 Lisp_Object name;
1174 /* User-supplied hash function, or nil. */
1175 Lisp_Object user_hash_function;
1177 /* User-supplied key comparison function, or nil. */
1178 Lisp_Object user_cmp_function;
1180 /* C function to compare two keys. */
1181 bool (*cmpfn) (struct hash_table_test *t, Lisp_Object, Lisp_Object);
1183 /* C function to compute hash code. */
1184 EMACS_UINT (*hashfn) (struct hash_table_test *t, Lisp_Object);
1187 struct Lisp_Hash_Table
1189 /* This is for Lisp; the hash table code does not refer to it. */
1190 struct vectorlike_header header;
1192 /* Nil if table is non-weak. Otherwise a symbol describing the
1193 weakness of the table. */
1194 Lisp_Object weak;
1196 /* When the table is resized, and this is an integer, compute the
1197 new size by adding this to the old size. If a float, compute the
1198 new size by multiplying the old size with this factor. */
1199 Lisp_Object rehash_size;
1201 /* Resize hash table when number of entries/ table size is >= this
1202 ratio, a float. */
1203 Lisp_Object rehash_threshold;
1205 /* Vector of hash codes.. If hash[I] is nil, this means that that
1206 entry I is unused. */
1207 Lisp_Object hash;
1209 /* Vector used to chain entries. If entry I is free, next[I] is the
1210 entry number of the next free item. If entry I is non-free,
1211 next[I] is the index of the next entry in the collision chain. */
1212 Lisp_Object next;
1214 /* Index of first free entry in free list. */
1215 Lisp_Object next_free;
1217 /* Bucket vector. A non-nil entry is the index of the first item in
1218 a collision chain. This vector's size can be larger than the
1219 hash table size to reduce collisions. */
1220 Lisp_Object index;
1222 /* Only the fields above are traced normally by the GC. The ones below
1223 `count' are special and are either ignored by the GC or traced in
1224 a special way (e.g. because of weakness). */
1226 /* Number of key/value entries in the table. */
1227 ptrdiff_t count;
1229 /* Vector of keys and values. The key of item I is found at index
1230 2 * I, the value is found at index 2 * I + 1.
1231 This is gc_marked specially if the table is weak. */
1232 Lisp_Object key_and_value;
1234 /* The comparison and hash functions. */
1235 struct hash_table_test test;
1237 /* Next weak hash table if this is a weak hash table. The head
1238 of the list is in weak_hash_tables. */
1239 struct Lisp_Hash_Table *next_weak;
1243 #define XHASH_TABLE(OBJ) \
1244 ((struct Lisp_Hash_Table *) XUNTAG (OBJ, Lisp_Vectorlike))
1246 #define XSET_HASH_TABLE(VAR, PTR) \
1247 (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
1249 #define HASH_TABLE_P(OBJ) PSEUDOVECTORP (OBJ, PVEC_HASH_TABLE)
1251 #define CHECK_HASH_TABLE(x) \
1252 CHECK_TYPE (HASH_TABLE_P (x), Qhash_table_p, x)
1254 /* Value is the key part of entry IDX in hash table H. */
1256 #define HASH_KEY(H, IDX) AREF ((H)->key_and_value, 2 * (IDX))
1258 /* Value is the value part of entry IDX in hash table H. */
1260 #define HASH_VALUE(H, IDX) AREF ((H)->key_and_value, 2 * (IDX) + 1)
1262 /* Value is the index of the next entry following the one at IDX
1263 in hash table H. */
1265 #define HASH_NEXT(H, IDX) AREF ((H)->next, (IDX))
1267 /* Value is the hash code computed for entry IDX in hash table H. */
1269 #define HASH_HASH(H, IDX) AREF ((H)->hash, (IDX))
1271 /* Value is the index of the element in hash table H that is the
1272 start of the collision list at index IDX in the index vector of H. */
1274 #define HASH_INDEX(H, IDX) AREF ((H)->index, (IDX))
1276 /* Value is the size of hash table H. */
1278 #define HASH_TABLE_SIZE(H) ASIZE ((H)->next)
1280 /* Default size for hash tables if not specified. */
1282 enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
1284 /* Default threshold specifying when to resize a hash table. The
1285 value gives the ratio of current entries in the hash table and the
1286 size of the hash table. */
1288 static double const DEFAULT_REHASH_THRESHOLD = 0.8;
1290 /* Default factor by which to increase the size of a hash table. */
1292 static double const DEFAULT_REHASH_SIZE = 1.5;
1294 /* Combine two integers X and Y for hashing. The result might not fit
1295 into a Lisp integer. */
1297 LISP_INLINE EMACS_UINT
1298 sxhash_combine (EMACS_UINT x, EMACS_UINT y)
1300 return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y;
1303 /* Hash X, returning a value that fits into a fixnum. */
1305 LISP_INLINE EMACS_UINT
1306 SXHASH_REDUCE (EMACS_UINT x)
1308 return (x ^ x >> (BITS_PER_EMACS_INT - FIXNUM_BITS)) & INTMASK;
1311 /* These structures are used for various misc types. */
1313 struct Lisp_Misc_Any /* Supertype of all Misc types. */
1315 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_??? */
1316 unsigned gcmarkbit : 1;
1317 int spacer : 15;
1320 struct Lisp_Marker
1322 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Marker */
1323 unsigned gcmarkbit : 1;
1324 int spacer : 13;
1325 /* This flag is temporarily used in the functions
1326 decode/encode_coding_object to record that the marker position
1327 must be adjusted after the conversion. */
1328 unsigned int need_adjustment : 1;
1329 /* 1 means normal insertion at the marker's position
1330 leaves the marker after the inserted text. */
1331 unsigned int insertion_type : 1;
1332 /* This is the buffer that the marker points into, or 0 if it points nowhere.
1333 Note: a chain of markers can contain markers pointing into different
1334 buffers (the chain is per buffer_text rather than per buffer, so it's
1335 shared between indirect buffers). */
1336 /* This is used for (other than NULL-checking):
1337 - Fmarker_buffer
1338 - Fset_marker: check eq(oldbuf, newbuf) to avoid unchain+rechain.
1339 - unchain_marker: to find the list from which to unchain.
1340 - Fkill_buffer: to only unchain the markers of current indirect buffer.
1342 struct buffer *buffer;
1344 /* The remaining fields are meaningless in a marker that
1345 does not point anywhere. */
1347 /* For markers that point somewhere,
1348 this is used to chain of all the markers in a given buffer. */
1349 /* We could remove it and use an array in buffer_text instead.
1350 That would also allow to preserve it ordered. */
1351 struct Lisp_Marker *next;
1352 /* This is the char position where the marker points. */
1353 ptrdiff_t charpos;
1354 /* This is the byte position.
1355 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
1356 used to implement the functionality of markers, but rather to (ab)use
1357 markers as a cache for char<->byte mappings). */
1358 ptrdiff_t bytepos;
1361 /* START and END are markers in the overlay's buffer, and
1362 PLIST is the overlay's property list. */
1363 struct Lisp_Overlay
1364 /* An overlay's real data content is:
1365 - plist
1366 - buffer (really there are two buffer pointers, one per marker,
1367 and both points to the same buffer)
1368 - insertion type of both ends (per-marker fields)
1369 - start & start byte (of start marker)
1370 - end & end byte (of end marker)
1371 - next (singly linked list of overlays)
1372 - next fields of start and end markers (singly linked list of markers).
1373 I.e. 9words plus 2 bits, 3words of which are for external linked lists.
1376 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Overlay */
1377 unsigned gcmarkbit : 1;
1378 int spacer : 15;
1379 struct Lisp_Overlay *next;
1380 Lisp_Object start;
1381 Lisp_Object end;
1382 Lisp_Object plist;
1385 /* Types of data which may be saved in a Lisp_Save_Value. */
1387 enum
1389 SAVE_UNUSED,
1390 SAVE_INTEGER,
1391 SAVE_POINTER,
1392 SAVE_OBJECT
1395 /* Number of bits needed to store one of the above values. */
1396 enum { SAVE_SLOT_BITS = 2 };
1398 /* Number of slots in a save value where save_type is nonzero. */
1399 enum { SAVE_VALUE_SLOTS = 4 };
1401 /* Bit-width and values for struct Lisp_Save_Value's save_type member. */
1403 enum { SAVE_TYPE_BITS = SAVE_VALUE_SLOTS * SAVE_SLOT_BITS + 1 };
1405 enum Lisp_Save_Type
1407 SAVE_TYPE_INT_INT = SAVE_INTEGER + (SAVE_INTEGER << SAVE_SLOT_BITS),
1408 SAVE_TYPE_INT_INT_INT
1409 = (SAVE_INTEGER + (SAVE_TYPE_INT_INT << SAVE_SLOT_BITS)),
1410 SAVE_TYPE_OBJ_OBJ = SAVE_OBJECT + (SAVE_OBJECT << SAVE_SLOT_BITS),
1411 SAVE_TYPE_OBJ_OBJ_OBJ = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ << SAVE_SLOT_BITS),
1412 SAVE_TYPE_OBJ_OBJ_OBJ_OBJ
1413 = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ_OBJ << SAVE_SLOT_BITS),
1414 SAVE_TYPE_PTR_INT = SAVE_POINTER + (SAVE_INTEGER << SAVE_SLOT_BITS),
1415 SAVE_TYPE_PTR_OBJ = SAVE_POINTER + (SAVE_OBJECT << SAVE_SLOT_BITS),
1416 SAVE_TYPE_PTR_PTR = SAVE_POINTER + (SAVE_POINTER << SAVE_SLOT_BITS),
1417 SAVE_TYPE_PTR_PTR_OBJ
1418 = SAVE_POINTER + (SAVE_TYPE_PTR_OBJ << SAVE_SLOT_BITS),
1420 /* This has an extra bit indicating it's raw memory. */
1421 SAVE_TYPE_MEMORY = SAVE_TYPE_PTR_INT + (1 << (SAVE_TYPE_BITS - 1))
1424 /* Special object used to hold a different values for later use.
1426 This is mostly used to package C integers and pointers to call
1427 record_unwind_protect. Typical task is to pass just one C pointer
1428 to unwind function. You should pack pointer with make_save_pointer
1429 and then get it back with XSAVE_POINTER, e.g.:
1432 struct my_data *md = get_my_data ();
1433 record_unwind_protect (my_unwind, make_save_pointer (md));
1436 Lisp_Object my_unwind (Lisp_Object arg)
1438 struct my_data *md = XSAVE_POINTER (arg, 0);
1442 If yon need to pass more than just one C pointer, you should
1443 use make_save_value. This function allows you to pack up to
1444 SAVE_VALUE_SLOTS integers, pointers or Lisp_Objects and
1445 conveniently get them back with XSAVE_POINTER, XSAVE_INTEGER and
1446 XSAVE_OBJECT macros:
1449 struct my_data *md = get_my_data ();
1450 Lisp_Object my_object = get_my_object ();
1451 record_unwind_protect
1452 (my_unwind, make_save_value (SAVE_TYPE_PTR_OBJ, md, my_object));
1455 Lisp_Object my_unwind (Lisp_Object arg)
1457 struct my_data *md = XSAVE_POINTER (arg, 0);
1458 Lisp_Object my_object = XSAVE_OBJECT (arg, 1);
1462 If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the
1463 saved objects and raise eassert if type of the saved object doesn't match
1464 the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2)
1465 or XSAVE_OBJECT (arg, 0) are wrong because nothing was saved in slot 2 and
1466 Lisp_Object was saved in slot 1 of ARG. */
1468 struct Lisp_Save_Value
1470 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */
1471 unsigned gcmarkbit : 1;
1472 int spacer : 32 - (16 + 1 + SAVE_TYPE_BITS);
1474 /* DATA[N] may hold up to SAVE_VALUE_SLOTS entries. The type of
1475 V's Ith entry is given by save_type (V, I). E.g., if save_type
1476 (V, 3) == SAVE_INTEGER, V->data[3].integer is in use.
1478 If SAVE_TYPE == SAVE_TYPE_MEMORY, DATA[0].pointer is the address of
1479 a memory area containing DATA[1].integer potential Lisp_Objects. */
1480 ENUM_BF (Lisp_Save_Type) save_type : SAVE_TYPE_BITS;
1481 union {
1482 void *pointer;
1483 ptrdiff_t integer;
1484 Lisp_Object object;
1485 } data[SAVE_VALUE_SLOTS];
1488 /* A miscellaneous object, when it's on the free list. */
1489 struct Lisp_Free
1491 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Free */
1492 unsigned gcmarkbit : 1;
1493 int spacer : 15;
1494 union Lisp_Misc *chain;
1497 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
1498 It uses one of these struct subtypes to get the type field. */
1500 union Lisp_Misc
1502 struct Lisp_Misc_Any u_any; /* Supertype of all Misc types. */
1503 struct Lisp_Free u_free;
1504 struct Lisp_Marker u_marker;
1505 struct Lisp_Overlay u_overlay;
1506 struct Lisp_Save_Value u_save_value;
1509 /* Forwarding pointer to an int variable.
1510 This is allowed only in the value cell of a symbol,
1511 and it means that the symbol's value really lives in the
1512 specified int variable. */
1513 struct Lisp_Intfwd
1515 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Int */
1516 EMACS_INT *intvar;
1519 /* Boolean forwarding pointer to an int variable.
1520 This is like Lisp_Intfwd except that the ostensible
1521 "value" of the symbol is t if the int variable is nonzero,
1522 nil if it is zero. */
1523 struct Lisp_Boolfwd
1525 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Bool */
1526 bool *boolvar;
1529 /* Forwarding pointer to a Lisp_Object variable.
1530 This is allowed only in the value cell of a symbol,
1531 and it means that the symbol's value really lives in the
1532 specified variable. */
1533 struct Lisp_Objfwd
1535 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Obj */
1536 Lisp_Object *objvar;
1539 /* Like Lisp_Objfwd except that value lives in a slot in the
1540 current buffer. Value is byte index of slot within buffer. */
1541 struct Lisp_Buffer_Objfwd
1543 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Buffer_Obj */
1544 int offset;
1545 /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp or Qnumberp. */
1546 Lisp_Object predicate;
1549 /* struct Lisp_Buffer_Local_Value is used in a symbol value cell when
1550 the symbol has buffer-local or frame-local bindings. (Exception:
1551 some buffer-local variables are built-in, with their values stored
1552 in the buffer structure itself. They are handled differently,
1553 using struct Lisp_Buffer_Objfwd.)
1555 The `realvalue' slot holds the variable's current value, or a
1556 forwarding pointer to where that value is kept. This value is the
1557 one that corresponds to the loaded binding. To read or set the
1558 variable, you must first make sure the right binding is loaded;
1559 then you can access the value in (or through) `realvalue'.
1561 `buffer' and `frame' are the buffer and frame for which the loaded
1562 binding was found. If those have changed, to make sure the right
1563 binding is loaded it is necessary to find which binding goes with
1564 the current buffer and selected frame, then load it. To load it,
1565 first unload the previous binding, then copy the value of the new
1566 binding into `realvalue' (or through it). Also update
1567 LOADED-BINDING to point to the newly loaded binding.
1569 `local_if_set' indicates that merely setting the variable creates a
1570 local binding for the current buffer. Otherwise the latter, setting
1571 the variable does not do that; only make-local-variable does that. */
1573 struct Lisp_Buffer_Local_Value
1575 /* 1 means that merely setting the variable creates a local
1576 binding for the current buffer. */
1577 unsigned int local_if_set : 1;
1578 /* 1 means this variable can have frame-local bindings, otherwise, it is
1579 can have buffer-local bindings. The two cannot be combined. */
1580 unsigned int frame_local : 1;
1581 /* 1 means that the binding now loaded was found.
1582 Presumably equivalent to (defcell!=valcell). */
1583 unsigned int found : 1;
1584 /* If non-NULL, a forwarding to the C var where it should also be set. */
1585 union Lisp_Fwd *fwd; /* Should never be (Buffer|Kboard)_Objfwd. */
1586 /* The buffer or frame for which the loaded binding was found. */
1587 Lisp_Object where;
1588 /* A cons cell that holds the default value. It has the form
1589 (SYMBOL . DEFAULT-VALUE). */
1590 Lisp_Object defcell;
1591 /* The cons cell from `where's parameter alist.
1592 It always has the form (SYMBOL . VALUE)
1593 Note that if `forward' is non-nil, VALUE may be out of date.
1594 Also if the currently loaded binding is the default binding, then
1595 this is `eq'ual to defcell. */
1596 Lisp_Object valcell;
1599 /* Like Lisp_Objfwd except that value lives in a slot in the
1600 current kboard. */
1601 struct Lisp_Kboard_Objfwd
1603 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Kboard_Obj */
1604 int offset;
1607 union Lisp_Fwd
1609 struct Lisp_Intfwd u_intfwd;
1610 struct Lisp_Boolfwd u_boolfwd;
1611 struct Lisp_Objfwd u_objfwd;
1612 struct Lisp_Buffer_Objfwd u_buffer_objfwd;
1613 struct Lisp_Kboard_Objfwd u_kboard_objfwd;
1616 /* Lisp floating point type. */
1617 struct Lisp_Float
1619 union
1621 double data;
1622 struct Lisp_Float *chain;
1623 } u;
1626 #define XFLOAT_DATA(f) (0 ? XFLOAT (f)->u.data : XFLOAT (f)->u.data)
1627 #define XFLOAT_INIT(f, n) (XFLOAT (f)->u.data = (n))
1629 /* Most hosts nowadays use IEEE floating point, so they use IEC 60559
1630 representations, have infinities and NaNs, and do not trap on
1631 exceptions. Define IEEE_FLOATING_POINT if this host is one of the
1632 typical ones. The C11 macro __STDC_IEC_559__ is close to what is
1633 wanted here, but is not quite right because Emacs does not require
1634 all the features of C11 Annex F (and does not require C11 at all,
1635 for that matter). */
1636 #define IEEE_FLOATING_POINT (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
1637 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
1639 /* A character, declared with the following typedef, is a member
1640 of some character set associated with the current buffer. */
1641 #ifndef _UCHAR_T /* Protect against something in ctab.h on AIX. */
1642 #define _UCHAR_T
1643 typedef unsigned char UCHAR;
1644 #endif
1646 /* Meanings of slots in a Lisp_Compiled: */
1648 enum Lisp_Compiled
1650 COMPILED_ARGLIST = 0,
1651 COMPILED_BYTECODE = 1,
1652 COMPILED_CONSTANTS = 2,
1653 COMPILED_STACK_DEPTH = 3,
1654 COMPILED_DOC_STRING = 4,
1655 COMPILED_INTERACTIVE = 5
1658 /* Flag bits in a character. These also get used in termhooks.h.
1659 Richard Stallman <rms@gnu.ai.mit.edu> thinks that MULE
1660 (MUlti-Lingual Emacs) might need 22 bits for the character value
1661 itself, so we probably shouldn't use any bits lower than 0x0400000. */
1662 enum char_bits
1664 CHAR_ALT = 0x0400000,
1665 CHAR_SUPER = 0x0800000,
1666 CHAR_HYPER = 0x1000000,
1667 CHAR_SHIFT = 0x2000000,
1668 CHAR_CTL = 0x4000000,
1669 CHAR_META = 0x8000000,
1671 CHAR_MODIFIER_MASK =
1672 CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META,
1674 /* Actually, the current Emacs uses 22 bits for the character value
1675 itself. */
1676 CHARACTERBITS = 22
1682 /* The glyph datatype, used to represent characters on the display.
1683 It consists of a char code and a face id. */
1685 typedef struct {
1686 int ch;
1687 int face_id;
1688 } GLYPH;
1690 /* Return a glyph's character code. */
1691 #define GLYPH_CHAR(glyph) ((glyph).ch)
1693 /* Return a glyph's face ID. */
1694 #define GLYPH_FACE(glyph) ((glyph).face_id)
1696 #define SET_GLYPH_CHAR(glyph, char) ((glyph).ch = (char))
1697 #define SET_GLYPH_FACE(glyph, face) ((glyph).face_id = (face))
1698 #define SET_GLYPH(glyph, char, face) ((glyph).ch = (char), (glyph).face_id = (face))
1700 /* Return 1 if GLYPH contains valid character code. */
1701 #define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph))
1704 /* Glyph Code from a display vector may either be an integer which
1705 encodes a char code in the lower CHARACTERBITS bits and a (very small)
1706 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */
1708 #define GLYPH_CODE_P(gc) \
1709 (CONSP (gc) \
1710 ? (CHARACTERP (XCAR (gc)) \
1711 && RANGED_INTEGERP (0, XCDR (gc), MAX_FACE_ID)) \
1712 : (RANGED_INTEGERP \
1713 (0, gc, \
1714 (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS \
1715 ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR \
1716 : TYPE_MAXIMUM (EMACS_INT)))))
1718 /* The following are valid only if GLYPH_CODE_P (gc). */
1720 #define GLYPH_CODE_CHAR(gc) \
1721 (CONSP (gc) ? XINT (XCAR (gc)) : XINT (gc) & ((1 << CHARACTERBITS) - 1))
1723 #define GLYPH_CODE_FACE(gc) \
1724 (CONSP (gc) ? XINT (XCDR (gc)) : XINT (gc) >> CHARACTERBITS)
1726 #define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \
1727 do \
1729 if (CONSP (gc)) \
1730 SET_GLYPH (glyph, XINT (XCAR (gc)), XINT (XCDR (gc))); \
1731 else \
1732 SET_GLYPH (glyph, (XINT (gc) & ((1 << CHARACTERBITS)-1)), \
1733 (XINT (gc) >> CHARACTERBITS)); \
1735 while (0)
1737 /* Structure to hold mouse highlight data. This is here because other
1738 header files need it for defining struct x_output etc. */
1739 typedef struct {
1740 /* These variables describe the range of text currently shown in its
1741 mouse-face, together with the window they apply to. As long as
1742 the mouse stays within this range, we need not redraw anything on
1743 its account. Rows and columns are glyph matrix positions in
1744 MOUSE_FACE_WINDOW. */
1745 int mouse_face_beg_row, mouse_face_beg_col;
1746 int mouse_face_beg_x, mouse_face_beg_y;
1747 int mouse_face_end_row, mouse_face_end_col;
1748 int mouse_face_end_x, mouse_face_end_y;
1749 Lisp_Object mouse_face_window;
1750 int mouse_face_face_id;
1751 Lisp_Object mouse_face_overlay;
1753 /* FRAME and X, Y position of mouse when last checked for
1754 highlighting. X and Y can be negative or out of range for the frame. */
1755 struct frame *mouse_face_mouse_frame;
1756 int mouse_face_mouse_x, mouse_face_mouse_y;
1758 /* Nonzero if part of the text currently shown in
1759 its mouse-face is beyond the window end. */
1760 unsigned mouse_face_past_end : 1;
1762 /* Nonzero means defer mouse-motion highlighting. */
1763 unsigned mouse_face_defer : 1;
1765 /* Nonzero means that the mouse highlight should not be shown. */
1766 unsigned mouse_face_hidden : 1;
1767 } Mouse_HLInfo;
1769 /* Data type checking. */
1771 #define NILP(x) EQ (x, Qnil)
1773 #define NUMBERP(x) (INTEGERP (x) || FLOATP (x))
1774 #define NATNUMP(x) (INTEGERP (x) && XINT (x) >= 0)
1776 #define RANGED_INTEGERP(lo, x, hi) \
1777 (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi))
1778 #define TYPE_RANGED_INTEGERP(type, x) \
1779 (TYPE_SIGNED (type) \
1780 ? RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)) \
1781 : RANGED_INTEGERP (0, x, TYPE_MAXIMUM (type)))
1783 #define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x))))
1784 #define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
1785 #define MISCP(x) (XTYPE ((x)) == Lisp_Misc)
1786 #define VECTORLIKEP(x) (XTYPE ((x)) == Lisp_Vectorlike)
1787 #define STRINGP(x) (XTYPE ((x)) == Lisp_String)
1788 #define CONSP(x) (XTYPE ((x)) == Lisp_Cons)
1790 #define FLOATP(x) (XTYPE ((x)) == Lisp_Float)
1791 #define VECTORP(x) (VECTORLIKEP (x) && !(ASIZE (x) & PSEUDOVECTOR_FLAG))
1792 #define OVERLAYP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay)
1793 #define MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker)
1795 LISP_INLINE bool
1796 SAVE_VALUEP (Lisp_Object x)
1798 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value;
1801 LISP_INLINE struct Lisp_Save_Value *
1802 XSAVE_VALUE (Lisp_Object a)
1804 eassert (SAVE_VALUEP (a));
1805 return & XMISC (a)->u_save_value;
1808 /* Return the type of V's Nth saved value. */
1809 LISP_INLINE int
1810 save_type (struct Lisp_Save_Value *v, int n)
1812 eassert (0 <= n && n < SAVE_VALUE_SLOTS);
1813 return (v->save_type >> (SAVE_SLOT_BITS * n) & ((1 << SAVE_SLOT_BITS) - 1));
1816 /* Get and set the Nth saved pointer. */
1818 LISP_INLINE void *
1819 XSAVE_POINTER (Lisp_Object obj, int n)
1821 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
1822 return XSAVE_VALUE (obj)->data[n].pointer;;
1824 LISP_INLINE void
1825 set_save_pointer (Lisp_Object obj, int n, void *val)
1827 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
1828 XSAVE_VALUE (obj)->data[n].pointer = val;
1831 /* Likewise for the saved integer. */
1833 LISP_INLINE ptrdiff_t
1834 XSAVE_INTEGER (Lisp_Object obj, int n)
1836 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
1837 return XSAVE_VALUE (obj)->data[n].integer;
1839 LISP_INLINE void
1840 set_save_integer (Lisp_Object obj, int n, ptrdiff_t val)
1842 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
1843 XSAVE_VALUE (obj)->data[n].integer = val;
1846 /* Extract Nth saved object. */
1848 LISP_INLINE Lisp_Object
1849 XSAVE_OBJECT (Lisp_Object obj, int n)
1851 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_OBJECT);
1852 return XSAVE_VALUE (obj)->data[n].object;
1855 #define AUTOLOADP(x) (CONSP (x) && EQ (Qautoload, XCAR (x)))
1857 #define INTFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Int)
1858 #define BOOLFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Bool)
1859 #define OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Obj)
1860 #define BUFFER_OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Buffer_Obj)
1861 #define KBOARD_OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Kboard_Obj)
1863 /* True if object X is a pseudovector whose code is CODE. The cast to struct
1864 vectorlike_header * avoids aliasing issues. */
1865 #define PSEUDOVECTORP(x, code) \
1866 TYPED_PSEUDOVECTORP (x, vectorlike_header, code)
1868 #define PSEUDOVECTOR_TYPEP(v, code) \
1869 (((v)->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) \
1870 == (PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS)))
1872 /* True if object X, with internal type struct T *, is a pseudovector whose
1873 code is CODE. */
1874 #define TYPED_PSEUDOVECTORP(x, t, code) \
1875 (VECTORLIKEP (x) \
1876 && PSEUDOVECTOR_TYPEP ((struct t *) XUNTAG (x, Lisp_Vectorlike), code))
1878 /* Test for specific pseudovector types. */
1879 #define WINDOW_CONFIGURATIONP(x) PSEUDOVECTORP (x, PVEC_WINDOW_CONFIGURATION)
1880 #define PROCESSP(x) PSEUDOVECTORP (x, PVEC_PROCESS)
1881 #define WINDOWP(x) PSEUDOVECTORP (x, PVEC_WINDOW)
1882 #define TERMINALP(x) PSEUDOVECTORP (x, PVEC_TERMINAL)
1883 #define SUBRP(x) PSEUDOVECTORP (x, PVEC_SUBR)
1884 #define COMPILEDP(x) PSEUDOVECTORP (x, PVEC_COMPILED)
1885 #define BUFFERP(x) PSEUDOVECTORP (x, PVEC_BUFFER)
1886 #define CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_CHAR_TABLE)
1887 #define SUB_CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_SUB_CHAR_TABLE)
1888 #define BOOL_VECTOR_P(x) PSEUDOVECTORP (x, PVEC_BOOL_VECTOR)
1889 #define FRAMEP(x) PSEUDOVECTORP (x, PVEC_FRAME)
1891 /* Test for image (image . spec) */
1892 #define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage))
1894 /* Array types. */
1896 #define ARRAYP(x) \
1897 (VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x))
1899 #define CHECK_LIST(x) \
1900 CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x)
1902 #define CHECK_LIST_CONS(x, y) \
1903 CHECK_TYPE (CONSP (x), Qlistp, y)
1905 #define CHECK_LIST_END(x, y) \
1906 CHECK_TYPE (NILP (x), Qlistp, y)
1908 #define CHECK_STRING(x) \
1909 CHECK_TYPE (STRINGP (x), Qstringp, x)
1911 #define CHECK_STRING_CAR(x) \
1912 CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x))
1914 #define CHECK_CONS(x) \
1915 CHECK_TYPE (CONSP (x), Qconsp, x)
1917 #define CHECK_SYMBOL(x) \
1918 CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
1920 #define CHECK_CHAR_TABLE(x) \
1921 CHECK_TYPE (CHAR_TABLE_P (x), Qchar_table_p, x)
1923 #define CHECK_VECTOR(x) \
1924 CHECK_TYPE (VECTORP (x), Qvectorp, x)
1926 #define CHECK_VECTOR_OR_STRING(x) \
1927 CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x)
1929 #define CHECK_ARRAY(x, Qxxxp) \
1930 CHECK_TYPE (ARRAYP (x), Qxxxp, x)
1932 #define CHECK_VECTOR_OR_CHAR_TABLE(x) \
1933 CHECK_TYPE (VECTORP (x) || CHAR_TABLE_P (x), Qvector_or_char_table_p, x)
1935 #define CHECK_BUFFER(x) \
1936 CHECK_TYPE (BUFFERP (x), Qbufferp, x)
1938 #define CHECK_WINDOW(x) \
1939 CHECK_TYPE (WINDOWP (x), Qwindowp, x)
1941 #define CHECK_WINDOW_CONFIGURATION(x) \
1942 CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x)
1944 #define CHECK_PROCESS(x) \
1945 CHECK_TYPE (PROCESSP (x), Qprocessp, x)
1947 #define CHECK_SUBR(x) \
1948 CHECK_TYPE (SUBRP (x), Qsubrp, x)
1950 #define CHECK_NUMBER(x) \
1951 CHECK_TYPE (INTEGERP (x), Qintegerp, x)
1953 #define CHECK_NATNUM(x) \
1954 CHECK_TYPE (NATNUMP (x), Qwholenump, x)
1956 #define CHECK_RANGED_INTEGER(x, lo, hi) \
1957 do { \
1958 CHECK_NUMBER (x); \
1959 if (! ((lo) <= XINT (x) && XINT (x) <= (hi))) \
1960 args_out_of_range_3 \
1961 (x, \
1962 make_number ((lo) < 0 && (lo) < MOST_NEGATIVE_FIXNUM \
1963 ? MOST_NEGATIVE_FIXNUM \
1964 : (lo)), \
1965 make_number (min (hi, MOST_POSITIVE_FIXNUM))); \
1966 } while (0)
1967 #define CHECK_TYPE_RANGED_INTEGER(type, x) \
1968 do { \
1969 if (TYPE_SIGNED (type)) \
1970 CHECK_RANGED_INTEGER (x, TYPE_MINIMUM (type), TYPE_MAXIMUM (type)); \
1971 else \
1972 CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
1973 } while (0)
1975 #define CHECK_MARKER(x) \
1976 CHECK_TYPE (MARKERP (x), Qmarkerp, x)
1978 #define CHECK_NUMBER_COERCE_MARKER(x) \
1979 do { if (MARKERP ((x))) XSETFASTINT (x, marker_position (x)); \
1980 else CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); } while (0)
1982 #define XFLOATINT(n) extract_float((n))
1984 #define CHECK_FLOAT(x) \
1985 CHECK_TYPE (FLOATP (x), Qfloatp, x)
1987 #define CHECK_NUMBER_OR_FLOAT(x) \
1988 CHECK_TYPE (FLOATP (x) || INTEGERP (x), Qnumberp, x)
1990 #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \
1991 do { if (MARKERP (x)) XSETFASTINT (x, marker_position (x)); \
1992 else CHECK_TYPE (INTEGERP (x) || FLOATP (x), Qnumber_or_marker_p, x); } while (0)
1994 #define CHECK_OVERLAY(x) \
1995 CHECK_TYPE (OVERLAYP (x), Qoverlayp, x)
1997 /* Since we can't assign directly to the CAR or CDR fields of a cons
1998 cell, use these when checking that those fields contain numbers. */
1999 #define CHECK_NUMBER_CAR(x) \
2000 do { \
2001 Lisp_Object tmp = XCAR (x); \
2002 CHECK_NUMBER (tmp); \
2003 XSETCAR ((x), tmp); \
2004 } while (0)
2006 #define CHECK_NUMBER_CDR(x) \
2007 do { \
2008 Lisp_Object tmp = XCDR (x); \
2009 CHECK_NUMBER (tmp); \
2010 XSETCDR ((x), tmp); \
2011 } while (0)
2013 #define CHECK_NATNUM_CAR(x) \
2014 do { \
2015 Lisp_Object tmp = XCAR (x); \
2016 CHECK_NATNUM (tmp); \
2017 XSETCAR ((x), tmp); \
2018 } while (0)
2020 #define CHECK_NATNUM_CDR(x) \
2021 do { \
2022 Lisp_Object tmp = XCDR (x); \
2023 CHECK_NATNUM (tmp); \
2024 XSETCDR ((x), tmp); \
2025 } while (0)
2027 /* Define a built-in function for calling from Lisp.
2028 `lname' should be the name to give the function in Lisp,
2029 as a null-terminated C string.
2030 `fnname' should be the name of the function in C.
2031 By convention, it starts with F.
2032 `sname' should be the name for the C constant structure
2033 that records information on this function for internal use.
2034 By convention, it should be the same as `fnname' but with S instead of F.
2035 It's too bad that C macros can't compute this from `fnname'.
2036 `minargs' should be a number, the minimum number of arguments allowed.
2037 `maxargs' should be a number, the maximum number of arguments allowed,
2038 or else MANY or UNEVALLED.
2039 MANY means pass a vector of evaluated arguments,
2040 in the form of an integer number-of-arguments
2041 followed by the address of a vector of Lisp_Objects
2042 which contains the argument values.
2043 UNEVALLED means pass the list of unevaluated arguments
2044 `intspec' says how interactive arguments are to be fetched.
2045 If the string starts with a `(', `intspec' is evaluated and the resulting
2046 list is the list of arguments.
2047 If it's a string that doesn't start with `(', the value should follow
2048 the one of the doc string for `interactive'.
2049 A null string means call interactively with no arguments.
2050 `doc' is documentation for the user. */
2052 /* This version of DEFUN declares a function prototype with the right
2053 arguments, so we can catch errors with maxargs at compile-time. */
2054 #ifdef _MSC_VER
2055 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
2056 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
2057 static struct Lisp_Subr alignas (GCALIGNMENT) sname = \
2058 { { (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS) \
2059 | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)) }, \
2060 { (Lisp_Object (__cdecl *)(void))fnname }, \
2061 minargs, maxargs, lname, intspec, 0}; \
2062 Lisp_Object fnname
2063 #else /* not _MSC_VER */
2064 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
2065 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
2066 static struct Lisp_Subr alignas (GCALIGNMENT) sname = \
2067 { { PVEC_SUBR << PSEUDOVECTOR_AREA_BITS }, \
2068 { .a ## maxargs = fnname }, \
2069 minargs, maxargs, lname, intspec, 0}; \
2070 Lisp_Object fnname
2071 #endif
2073 /* Note that the weird token-substitution semantics of ANSI C makes
2074 this work for MANY and UNEVALLED. */
2075 #define DEFUN_ARGS_MANY (ptrdiff_t, Lisp_Object *)
2076 #define DEFUN_ARGS_UNEVALLED (Lisp_Object)
2077 #define DEFUN_ARGS_0 (void)
2078 #define DEFUN_ARGS_1 (Lisp_Object)
2079 #define DEFUN_ARGS_2 (Lisp_Object, Lisp_Object)
2080 #define DEFUN_ARGS_3 (Lisp_Object, Lisp_Object, Lisp_Object)
2081 #define DEFUN_ARGS_4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
2082 #define DEFUN_ARGS_5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2083 Lisp_Object)
2084 #define DEFUN_ARGS_6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2085 Lisp_Object, Lisp_Object)
2086 #define DEFUN_ARGS_7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2087 Lisp_Object, Lisp_Object, Lisp_Object)
2088 #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2089 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
2091 /* Non-zero if OBJ is a Lisp function. */
2092 #define FUNCTIONP(OBJ) functionp(OBJ)
2094 /* defsubr (Sname);
2095 is how we define the symbol for function `name' at start-up time. */
2096 extern void defsubr (struct Lisp_Subr *);
2098 enum maxargs
2100 MANY = -2,
2101 UNEVALLED = -1
2104 extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *);
2105 extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *);
2106 extern void defvar_bool (struct Lisp_Boolfwd *, const char *, bool *);
2107 extern void defvar_int (struct Lisp_Intfwd *, const char *, EMACS_INT *);
2108 extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int);
2110 /* Macros we use to define forwarded Lisp variables.
2111 These are used in the syms_of_FILENAME functions.
2113 An ordinary (not in buffer_defaults, per-buffer, or per-keyboard)
2114 lisp variable is actually a field in `struct emacs_globals'. The
2115 field's name begins with "f_", which is a convention enforced by
2116 these macros. Each such global has a corresponding #define in
2117 globals.h; the plain name should be used in the code.
2119 E.g., the global "cons_cells_consed" is declared as "int
2120 f_cons_cells_consed" in globals.h, but there is a define:
2122 #define cons_cells_consed globals.f_cons_cells_consed
2124 All C code uses the `cons_cells_consed' name. This is all done
2125 this way to support indirection for multi-threaded Emacs. */
2127 #define DEFVAR_LISP(lname, vname, doc) \
2128 do { \
2129 static struct Lisp_Objfwd o_fwd; \
2130 defvar_lisp (&o_fwd, lname, &globals.f_ ## vname); \
2131 } while (0)
2132 #define DEFVAR_LISP_NOPRO(lname, vname, doc) \
2133 do { \
2134 static struct Lisp_Objfwd o_fwd; \
2135 defvar_lisp_nopro (&o_fwd, lname, &globals.f_ ## vname); \
2136 } while (0)
2137 #define DEFVAR_BOOL(lname, vname, doc) \
2138 do { \
2139 static struct Lisp_Boolfwd b_fwd; \
2140 defvar_bool (&b_fwd, lname, &globals.f_ ## vname); \
2141 } while (0)
2142 #define DEFVAR_INT(lname, vname, doc) \
2143 do { \
2144 static struct Lisp_Intfwd i_fwd; \
2145 defvar_int (&i_fwd, lname, &globals.f_ ## vname); \
2146 } while (0)
2148 #define DEFVAR_BUFFER_DEFAULTS(lname, vname, doc) \
2149 do { \
2150 static struct Lisp_Objfwd o_fwd; \
2151 defvar_lisp_nopro (&o_fwd, lname, &BVAR (&buffer_defaults, vname)); \
2152 } while (0)
2154 #define DEFVAR_KBOARD(lname, vname, doc) \
2155 do { \
2156 static struct Lisp_Kboard_Objfwd ko_fwd; \
2157 defvar_kboard (&ko_fwd, lname, offsetof (KBOARD, vname ## _)); \
2158 } while (0)
2160 /* Save and restore the instruction and environment pointers,
2161 without affecting the signal mask. */
2163 #ifdef HAVE__SETJMP
2164 typedef jmp_buf sys_jmp_buf;
2165 # define sys_setjmp(j) _setjmp (j)
2166 # define sys_longjmp(j, v) _longjmp (j, v)
2167 #elif defined HAVE_SIGSETJMP
2168 typedef sigjmp_buf sys_jmp_buf;
2169 # define sys_setjmp(j) sigsetjmp (j, 0)
2170 # define sys_longjmp(j, v) siglongjmp (j, v)
2171 #else
2172 /* A platform that uses neither _longjmp nor siglongjmp; assume
2173 longjmp does not affect the sigmask. */
2174 typedef jmp_buf sys_jmp_buf;
2175 # define sys_setjmp(j) setjmp (j)
2176 # define sys_longjmp(j, v) longjmp (j, v)
2177 #endif
2180 /* Elisp uses several stacks:
2181 - the C stack.
2182 - the bytecode stack: used internally by the bytecode interpreter.
2183 Allocated from the C stack.
2184 - The specpdl stack: keeps track of active unwind-protect and
2185 dynamic-let-bindings. Allocated from the `specpdl' array, a manually
2186 managed stack.
2187 - The catch stack: keeps track of active catch tags.
2188 Allocated on the C stack. This is where the setmp data is kept.
2189 - The handler stack: keeps track of active condition-case handlers.
2190 Allocated on the C stack. Every entry there also uses an entry in
2191 the catch stack. */
2193 /* Structure for recording Lisp call stack for backtrace purposes. */
2195 /* The special binding stack holds the outer values of variables while
2196 they are bound by a function application or a let form, stores the
2197 code to be executed for unwind-protect forms.
2199 If func is non-zero, undoing this binding applies func to old_value;
2200 This implements record_unwind_protect.
2202 Otherwise, the element is a variable binding.
2204 If the symbol field is a symbol, it is an ordinary variable binding.
2206 Otherwise, it should be a structure (SYMBOL WHERE . CURRENT-BUFFER),
2207 which means having bound a local value while CURRENT-BUFFER was active.
2208 If WHERE is nil this means we saw the default value when binding SYMBOL.
2209 WHERE being a buffer or frame means we saw a buffer-local or frame-local
2210 value. Other values of WHERE mean an internal error.
2212 NOTE: The specbinding struct is defined here, because SPECPDL_INDEX is
2213 used all over the place, needs to be fast, and needs to know the size of
2214 struct specbinding. But only eval.c should access it. */
2216 typedef Lisp_Object (*specbinding_func) (Lisp_Object);
2218 enum specbind_tag {
2219 SPECPDL_UNWIND, /* An unwind_protect function. */
2220 SPECPDL_BACKTRACE, /* An element of the backtrace. */
2221 SPECPDL_LET, /* A plain and simple dynamic let-binding. */
2222 /* Tags greater than SPECPDL_LET must be "subkinds" of LET. */
2223 SPECPDL_LET_LOCAL, /* A buffer-local let-binding. */
2224 SPECPDL_LET_DEFAULT /* A global binding for a localized var. */
2227 struct specbinding
2229 enum specbind_tag kind;
2230 union {
2231 struct {
2232 Lisp_Object arg;
2233 specbinding_func func;
2234 } unwind;
2235 struct {
2236 /* `where' is not used in the case of SPECPDL_LET. */
2237 Lisp_Object symbol, old_value, where;
2238 } let;
2239 struct {
2240 Lisp_Object function;
2241 Lisp_Object *args;
2242 ptrdiff_t nargs : BITS_PER_PTRDIFF_T - 1;
2243 bool debug_on_exit : 1;
2244 } bt;
2245 } v;
2248 LISP_INLINE Lisp_Object specpdl_symbol (struct specbinding *pdl)
2249 { eassert (pdl->kind >= SPECPDL_LET); return pdl->v.let.symbol; }
2251 LISP_INLINE Lisp_Object specpdl_old_value (struct specbinding *pdl)
2252 { eassert (pdl->kind >= SPECPDL_LET); return pdl->v.let.old_value; }
2254 LISP_INLINE Lisp_Object specpdl_where (struct specbinding *pdl)
2255 { eassert (pdl->kind > SPECPDL_LET); return pdl->v.let.where; }
2257 LISP_INLINE Lisp_Object specpdl_arg (struct specbinding *pdl)
2258 { eassert (pdl->kind == SPECPDL_UNWIND); return pdl->v.unwind.arg; }
2260 LISP_INLINE specbinding_func specpdl_func (struct specbinding *pdl)
2261 { eassert (pdl->kind == SPECPDL_UNWIND); return pdl->v.unwind.func; }
2263 LISP_INLINE Lisp_Object backtrace_function (struct specbinding *pdl)
2264 { eassert (pdl->kind == SPECPDL_BACKTRACE); return pdl->v.bt.function; }
2266 LISP_INLINE ptrdiff_t backtrace_nargs (struct specbinding *pdl)
2267 { eassert (pdl->kind == SPECPDL_BACKTRACE); return pdl->v.bt.nargs; }
2269 LISP_INLINE Lisp_Object *backtrace_args (struct specbinding *pdl)
2270 { eassert (pdl->kind == SPECPDL_BACKTRACE); return pdl->v.bt.args; }
2272 LISP_INLINE bool backtrace_debug_on_exit (struct specbinding *pdl)
2273 { eassert (pdl->kind == SPECPDL_BACKTRACE); return pdl->v.bt.debug_on_exit; }
2275 extern struct specbinding *specpdl;
2276 extern struct specbinding *specpdl_ptr;
2277 extern ptrdiff_t specpdl_size;
2279 #define SPECPDL_INDEX() (specpdl_ptr - specpdl)
2281 /* Everything needed to describe an active condition case.
2283 Members are volatile if their values need to survive _longjmp when
2284 a 'struct handler' is a local variable. */
2285 struct handler
2287 /* The handler clauses and variable from the condition-case form. */
2288 /* For a handler set up in Lisp code, this is always a list.
2289 For an internal handler set up by internal_condition_case*,
2290 this can instead be the symbol t or `error'.
2291 t: handle all conditions.
2292 error: handle all conditions, and errors can run the debugger
2293 or display a backtrace. */
2294 Lisp_Object handler;
2296 Lisp_Object volatile var;
2298 /* Fsignal stores here the condition-case clause that applies,
2299 and Fcondition_case thus knows which clause to run. */
2300 Lisp_Object volatile chosen_clause;
2302 /* Used to effect the longjump out to the handler. */
2303 struct catchtag *tag;
2305 /* The next enclosing handler. */
2306 struct handler *next;
2309 /* This structure helps implement the `catch' and `throw' control
2310 structure. A struct catchtag contains all the information needed
2311 to restore the state of the interpreter after a non-local jump.
2313 Handlers for error conditions (represented by `struct handler'
2314 structures) just point to a catch tag to do the cleanup required
2315 for their jumps.
2317 catchtag structures are chained together in the C calling stack;
2318 the `next' member points to the next outer catchtag.
2320 A call like (throw TAG VAL) searches for a catchtag whose `tag'
2321 member is TAG, and then unbinds to it. The `val' member is used to
2322 hold VAL while the stack is unwound; `val' is returned as the value
2323 of the catch form.
2325 All the other members are concerned with restoring the interpreter
2326 state.
2328 Members are volatile if their values need to survive _longjmp when
2329 a 'struct catchtag' is a local variable. */
2330 struct catchtag
2332 Lisp_Object tag;
2333 Lisp_Object volatile val;
2334 struct catchtag *volatile next;
2335 #if 1 /* GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS, but they're defined later. */
2336 struct gcpro *gcpro;
2337 #endif
2338 sys_jmp_buf jmp;
2339 struct handler *handlerlist;
2340 EMACS_INT lisp_eval_depth;
2341 ptrdiff_t volatile pdlcount;
2342 int poll_suppress_count;
2343 int interrupt_input_blocked;
2344 struct byte_stack *byte_stack;
2347 extern Lisp_Object memory_signal_data;
2349 /* An address near the bottom of the stack.
2350 Tells GC how to save a copy of the stack. */
2351 extern char *stack_bottom;
2353 /* Check quit-flag and quit if it is non-nil.
2354 Typing C-g does not directly cause a quit; it only sets Vquit_flag.
2355 So the program needs to do QUIT at times when it is safe to quit.
2356 Every loop that might run for a long time or might not exit
2357 ought to do QUIT at least once, at a safe place.
2358 Unless that is impossible, of course.
2359 But it is very desirable to avoid creating loops where QUIT is impossible.
2361 Exception: if you set immediate_quit to nonzero,
2362 then the handler that responds to the C-g does the quit itself.
2363 This is a good thing to do around a loop that has no side effects
2364 and (in particular) cannot call arbitrary Lisp code.
2366 If quit-flag is set to `kill-emacs' the SIGINT handler has received
2367 a request to exit Emacs when it is safe to do. */
2369 extern void process_pending_signals (void);
2370 extern bool volatile pending_signals;
2372 extern void process_quit_flag (void);
2373 #define QUIT \
2374 do { \
2375 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
2376 process_quit_flag (); \
2377 else if (pending_signals) \
2378 process_pending_signals (); \
2379 } while (0)
2382 /* Nonzero if ought to quit now. */
2384 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
2386 extern Lisp_Object Vascii_downcase_table;
2387 extern Lisp_Object Vascii_canon_table;
2389 /* Structure for recording stack slots that need marking. */
2391 /* This is a chain of structures, each of which points at a Lisp_Object
2392 variable whose value should be marked in garbage collection.
2393 Normally every link of the chain is an automatic variable of a function,
2394 and its `val' points to some argument or local variable of the function.
2395 On exit to the function, the chain is set back to the value it had on entry.
2396 This way, no link remains in the chain when the stack frame containing the
2397 link disappears.
2399 Every function that can call Feval must protect in this fashion all
2400 Lisp_Object variables whose contents will be used again. */
2402 extern struct gcpro *gcprolist;
2404 struct gcpro
2406 struct gcpro *next;
2408 /* Address of first protected variable. */
2409 volatile Lisp_Object *var;
2411 /* Number of consecutive protected variables. */
2412 ptrdiff_t nvars;
2414 #ifdef DEBUG_GCPRO
2415 int level;
2416 #endif
2419 /* Values of GC_MARK_STACK during compilation:
2421 0 Use GCPRO as before
2422 1 Do the real thing, make GCPROs and UNGCPRO no-ops.
2423 2 Mark the stack, and check that everything GCPRO'd is
2424 marked.
2425 3 Mark using GCPRO's, mark stack last, and count how many
2426 dead objects are kept alive.
2428 Formerly, method 0 was used. Currently, method 1 is used unless
2429 otherwise specified by hand when building, e.g.,
2430 "make CPPFLAGS='-DGC_MARK_STACK=GC_USE_GCPROS_AS_BEFORE'".
2431 Methods 2 and 3 are present mainly to debug the transition from 0 to 1. */
2433 #define GC_USE_GCPROS_AS_BEFORE 0
2434 #define GC_MAKE_GCPROS_NOOPS 1
2435 #define GC_MARK_STACK_CHECK_GCPROS 2
2436 #define GC_USE_GCPROS_CHECK_ZOMBIES 3
2438 #ifndef GC_MARK_STACK
2439 #define GC_MARK_STACK GC_MAKE_GCPROS_NOOPS
2440 #endif
2442 /* Whether we do the stack marking manually. */
2443 #define BYTE_MARK_STACK !(GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \
2444 || GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS)
2447 #if GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS
2449 /* Do something silly with gcproN vars just so gcc shuts up. */
2450 /* You get warnings from MIPSPro... */
2452 #define GCPRO1(varname) ((void) gcpro1)
2453 #define GCPRO2(varname1, varname2) ((void) gcpro2, (void) gcpro1)
2454 #define GCPRO3(varname1, varname2, varname3) \
2455 ((void) gcpro3, (void) gcpro2, (void) gcpro1)
2456 #define GCPRO4(varname1, varname2, varname3, varname4) \
2457 ((void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
2458 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2459 ((void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
2460 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2461 ((void) gcpro6, (void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, \
2462 (void) gcpro1)
2463 #define UNGCPRO ((void) 0)
2465 #else /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
2467 #ifndef DEBUG_GCPRO
2469 #define GCPRO1(varname) \
2470 {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
2471 gcprolist = &gcpro1; }
2473 #define GCPRO2(varname1, varname2) \
2474 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2475 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2476 gcprolist = &gcpro2; }
2478 #define GCPRO3(varname1, varname2, varname3) \
2479 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2480 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2481 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2482 gcprolist = &gcpro3; }
2484 #define GCPRO4(varname1, varname2, varname3, varname4) \
2485 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2486 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2487 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2488 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2489 gcprolist = &gcpro4; }
2491 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2492 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2493 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2494 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2495 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2496 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2497 gcprolist = &gcpro5; }
2499 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2500 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2501 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2502 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2503 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2504 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2505 gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
2506 gcprolist = &gcpro6; }
2508 #define UNGCPRO (gcprolist = gcpro1.next)
2510 #else
2512 extern int gcpro_level;
2514 #define GCPRO1(varname) \
2515 {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
2516 gcpro1.level = gcpro_level++; \
2517 gcprolist = &gcpro1; }
2519 #define GCPRO2(varname1, varname2) \
2520 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2521 gcpro1.level = gcpro_level; \
2522 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2523 gcpro2.level = gcpro_level++; \
2524 gcprolist = &gcpro2; }
2526 #define GCPRO3(varname1, varname2, varname3) \
2527 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2528 gcpro1.level = gcpro_level; \
2529 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2530 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2531 gcpro3.level = gcpro_level++; \
2532 gcprolist = &gcpro3; }
2534 #define GCPRO4(varname1, varname2, varname3, varname4) \
2535 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2536 gcpro1.level = gcpro_level; \
2537 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2538 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2539 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2540 gcpro4.level = gcpro_level++; \
2541 gcprolist = &gcpro4; }
2543 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2544 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2545 gcpro1.level = gcpro_level; \
2546 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2547 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2548 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2549 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2550 gcpro5.level = gcpro_level++; \
2551 gcprolist = &gcpro5; }
2553 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2554 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2555 gcpro1.level = gcpro_level; \
2556 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2557 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2558 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2559 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2560 gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
2561 gcpro6.level = gcpro_level++; \
2562 gcprolist = &gcpro6; }
2564 #define UNGCPRO \
2565 ((--gcpro_level != gcpro1.level) \
2566 ? (emacs_abort (), 0) \
2567 : ((gcprolist = gcpro1.next), 0))
2569 #endif /* DEBUG_GCPRO */
2570 #endif /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
2573 /* Evaluate expr, UNGCPRO, and then return the value of expr. */
2574 #define RETURN_UNGCPRO(expr) \
2575 do \
2577 Lisp_Object ret_ungc_val; \
2578 ret_ungc_val = (expr); \
2579 UNGCPRO; \
2580 return ret_ungc_val; \
2582 while (0)
2584 /* Call staticpro (&var) to protect static variable `var'. */
2586 void staticpro (Lisp_Object *);
2588 /* Declare a Lisp-callable function. The MAXARGS parameter has the same
2589 meaning as in the DEFUN macro, and is used to construct a prototype. */
2590 /* We can use the same trick as in the DEFUN macro to generate the
2591 appropriate prototype. */
2592 #define EXFUN(fnname, maxargs) \
2593 extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
2595 /* Forward declarations for prototypes. */
2596 struct window;
2597 struct frame;
2599 /* Simple access functions. */
2601 LISP_INLINE Lisp_Object *
2602 aref_addr (Lisp_Object array, ptrdiff_t idx)
2604 return & XVECTOR (array)->contents[idx];
2607 LISP_INLINE void
2608 gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
2610 /* Like ASET, but also can be used in the garbage collector:
2611 sweep_weak_table calls set_hash_key etc. while the table is marked. */
2612 eassert (0 <= idx && idx < (ASIZE (array) & ~ARRAY_MARK_FLAG));
2613 XVECTOR (array)->contents[idx] = val;
2616 /* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET. */
2618 LISP_INLINE void
2619 vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
2621 eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
2622 memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
2625 /* Functions to modify hash tables. */
2627 LISP_INLINE void
2628 set_hash_key_and_value (struct Lisp_Hash_Table *h, Lisp_Object key_and_value)
2630 h->key_and_value = key_and_value;
2633 LISP_INLINE void
2634 set_hash_key_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
2636 gc_aset (h->key_and_value, 2 * idx, val);
2639 LISP_INLINE void
2640 set_hash_value_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
2642 gc_aset (h->key_and_value, 2 * idx + 1, val);
2645 LISP_INLINE void
2646 set_hash_next (struct Lisp_Hash_Table *h, Lisp_Object next)
2648 h->next = next;
2651 LISP_INLINE void
2652 set_hash_next_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
2654 gc_aset (h->next, idx, val);
2657 LISP_INLINE void
2658 set_hash_hash (struct Lisp_Hash_Table *h, Lisp_Object hash)
2660 h->hash = hash;
2663 LISP_INLINE void
2664 set_hash_hash_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
2666 gc_aset (h->hash, idx, val);
2669 LISP_INLINE void
2670 set_hash_index (struct Lisp_Hash_Table *h, Lisp_Object index)
2672 h->index = index;
2675 LISP_INLINE void
2676 set_hash_index_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
2678 gc_aset (h->index, idx, val);
2681 /* Use these functions to set Lisp_Object
2682 or pointer slots of struct Lisp_Symbol. */
2684 LISP_INLINE void
2685 set_symbol_name (Lisp_Object sym, Lisp_Object name)
2687 XSYMBOL (sym)->name = name;
2690 LISP_INLINE void
2691 set_symbol_function (Lisp_Object sym, Lisp_Object function)
2693 XSYMBOL (sym)->function = function;
2696 LISP_INLINE void
2697 set_symbol_plist (Lisp_Object sym, Lisp_Object plist)
2699 XSYMBOL (sym)->plist = plist;
2702 LISP_INLINE void
2703 set_symbol_next (Lisp_Object sym, struct Lisp_Symbol *next)
2705 XSYMBOL (sym)->next = next;
2708 /* Buffer-local (also frame-local) variable access functions. */
2710 LISP_INLINE int
2711 blv_found (struct Lisp_Buffer_Local_Value *blv)
2713 eassert (blv->found == !EQ (blv->defcell, blv->valcell));
2714 return blv->found;
2717 LISP_INLINE void
2718 set_blv_found (struct Lisp_Buffer_Local_Value *blv, int found)
2720 eassert (found == !EQ (blv->defcell, blv->valcell));
2721 blv->found = found;
2724 LISP_INLINE Lisp_Object
2725 blv_value (struct Lisp_Buffer_Local_Value *blv)
2727 return XCDR (blv->valcell);
2730 LISP_INLINE void
2731 set_blv_value (struct Lisp_Buffer_Local_Value *blv, Lisp_Object val)
2733 XSETCDR (blv->valcell, val);
2736 LISP_INLINE void
2737 set_blv_where (struct Lisp_Buffer_Local_Value *blv, Lisp_Object val)
2739 blv->where = val;
2742 LISP_INLINE void
2743 set_blv_defcell (struct Lisp_Buffer_Local_Value *blv, Lisp_Object val)
2745 blv->defcell = val;
2748 LISP_INLINE void
2749 set_blv_valcell (struct Lisp_Buffer_Local_Value *blv, Lisp_Object val)
2751 blv->valcell = val;
2754 /* Set overlay's property list. */
2756 LISP_INLINE void
2757 set_overlay_plist (Lisp_Object overlay, Lisp_Object plist)
2759 XOVERLAY (overlay)->plist = plist;
2762 /* Get text properties of S. */
2764 LISP_INLINE INTERVAL
2765 string_intervals (Lisp_Object s)
2767 return XSTRING (s)->intervals;
2770 /* Set text properties of S to I. */
2772 LISP_INLINE void
2773 set_string_intervals (Lisp_Object s, INTERVAL i)
2775 XSTRING (s)->intervals = i;
2778 /* Set a Lisp slot in TABLE to VAL. Most code should use this instead
2779 of setting slots directly. */
2781 LISP_INLINE void
2782 set_char_table_ascii (Lisp_Object table, Lisp_Object val)
2784 XCHAR_TABLE (table)->ascii = val;
2786 LISP_INLINE void
2787 set_char_table_defalt (Lisp_Object table, Lisp_Object val)
2789 XCHAR_TABLE (table)->defalt = val;
2791 LISP_INLINE void
2792 set_char_table_parent (Lisp_Object table, Lisp_Object val)
2794 XCHAR_TABLE (table)->parent = val;
2796 LISP_INLINE void
2797 set_char_table_purpose (Lisp_Object table, Lisp_Object val)
2799 XCHAR_TABLE (table)->purpose = val;
2802 /* Set different slots in (sub)character tables. */
2804 LISP_INLINE void
2805 set_char_table_extras (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
2807 eassert (0 <= idx && idx < CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (table)));
2808 XCHAR_TABLE (table)->extras[idx] = val;
2811 LISP_INLINE void
2812 set_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
2814 eassert (0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0));
2815 XCHAR_TABLE (table)->contents[idx] = val;
2818 LISP_INLINE void
2819 set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
2821 XSUB_CHAR_TABLE (table)->contents[idx] = val;
2824 /* Defined in data.c. */
2825 extern Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
2826 extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
2827 extern Lisp_Object Qerror, Qquit, Qargs_out_of_range;
2828 extern Lisp_Object Qvoid_variable, Qvoid_function;
2829 extern Lisp_Object Qinvalid_read_syntax;
2830 extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
2831 extern Lisp_Object Quser_error, Qend_of_file, Qarith_error, Qmark_inactive;
2832 extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
2833 extern Lisp_Object Qtext_read_only;
2834 extern Lisp_Object Qinteractive_form;
2835 extern Lisp_Object Qcircular_list;
2836 extern Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp;
2837 extern Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
2838 extern Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
2839 extern Lisp_Object Qbuffer_or_string_p;
2840 extern Lisp_Object Qfboundp;
2841 extern Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
2843 extern Lisp_Object Qcdr;
2845 extern Lisp_Object Qrange_error, Qoverflow_error;
2847 extern Lisp_Object Qfloatp;
2848 extern Lisp_Object Qnumberp, Qnumber_or_marker_p;
2850 extern Lisp_Object Qbuffer, Qinteger, Qsymbol;
2852 extern Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
2854 EXFUN (Fbyteorder, 0) ATTRIBUTE_CONST;
2856 /* Defined in data.c. */
2857 extern Lisp_Object indirect_function (Lisp_Object);
2858 extern Lisp_Object find_symbol_value (Lisp_Object);
2860 /* Convert the integer I to an Emacs representation, either the integer
2861 itself, or a cons of two or three integers, or if all else fails a float.
2862 I should not have side effects. */
2863 #define INTEGER_TO_CONS(i) \
2864 (! FIXNUM_OVERFLOW_P (i) \
2865 ? make_number (i) \
2866 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16) \
2867 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16)) \
2868 && FIXNUM_OVERFLOW_P ((i) >> 16)) \
2869 ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff)) \
2870 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16 >> 24) \
2871 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16 >> 24)) \
2872 && FIXNUM_OVERFLOW_P ((i) >> 16 >> 24)) \
2873 ? Fcons (make_number ((i) >> 16 >> 24), \
2874 Fcons (make_number ((i) >> 16 & 0xffffff), \
2875 make_number ((i) & 0xffff))) \
2876 : make_float (i))
2878 /* Convert the Emacs representation CONS back to an integer of type
2879 TYPE, storing the result the variable VAR. Signal an error if CONS
2880 is not a valid representation or is out of range for TYPE. */
2881 #define CONS_TO_INTEGER(cons, type, var) \
2882 (TYPE_SIGNED (type) \
2883 ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
2884 : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
2885 extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
2886 extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
2888 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
2889 extern _Noreturn void args_out_of_range (Lisp_Object, Lisp_Object);
2890 extern _Noreturn void args_out_of_range_3 (Lisp_Object, Lisp_Object,
2891 Lisp_Object);
2892 extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
2893 extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *);
2894 extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, bool);
2895 extern void syms_of_data (void);
2896 extern void swap_in_global_binding (struct Lisp_Symbol *);
2898 /* Defined in cmds.c */
2899 extern void syms_of_cmds (void);
2900 extern void keys_of_cmds (void);
2902 /* Defined in coding.c. */
2903 extern Lisp_Object Qcharset;
2904 extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
2905 ptrdiff_t, bool, bool, Lisp_Object);
2906 extern void init_coding (void);
2907 extern void init_coding_once (void);
2908 extern void syms_of_coding (void);
2910 /* Defined in character.c. */
2911 EXFUN (Fmax_char, 0) ATTRIBUTE_CONST;
2912 extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
2913 extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
2914 extern int multibyte_char_to_unibyte (int) ATTRIBUTE_CONST;
2915 extern int multibyte_char_to_unibyte_safe (int) ATTRIBUTE_CONST;
2916 extern void syms_of_character (void);
2918 /* Defined in charset.c. */
2919 extern void init_charset (void);
2920 extern void init_charset_once (void);
2921 extern void syms_of_charset (void);
2922 /* Structure forward declarations. */
2923 struct charset;
2925 /* Defined in composite.c. */
2926 extern void syms_of_composite (void);
2928 /* Defined in syntax.c. */
2929 extern void init_syntax_once (void);
2930 extern void syms_of_syntax (void);
2932 /* Defined in fns.c. */
2933 extern Lisp_Object QCrehash_size, QCrehash_threshold;
2934 enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
2935 EXFUN (Fidentity, 1) ATTRIBUTE_CONST;
2936 extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
2937 extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
2938 extern void sweep_weak_hash_tables (void);
2939 extern Lisp_Object Qcursor_in_echo_area;
2940 extern Lisp_Object Qstring_lessp;
2941 extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq;
2942 EMACS_UINT hash_string (char const *, ptrdiff_t);
2943 EMACS_UINT sxhash (Lisp_Object, int);
2944 Lisp_Object make_hash_table (struct hash_table_test, Lisp_Object, Lisp_Object,
2945 Lisp_Object, Lisp_Object);
2946 ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
2947 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
2948 EMACS_UINT);
2949 extern struct hash_table_test hashtest_eql, hashtest_equal;
2951 extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
2952 ptrdiff_t, ptrdiff_t);
2953 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
2954 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
2955 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
2956 extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
2957 extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
2958 extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
2959 extern void clear_string_char_byte_cache (void);
2960 extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
2961 extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
2962 extern Lisp_Object string_to_multibyte (Lisp_Object);
2963 extern Lisp_Object string_make_unibyte (Lisp_Object);
2964 extern void syms_of_fns (void);
2966 /* Defined in floatfns.c. */
2967 extern double extract_float (Lisp_Object);
2968 extern void syms_of_floatfns (void);
2969 extern Lisp_Object fmod_float (Lisp_Object x, Lisp_Object y);
2971 /* Defined in fringe.c. */
2972 extern void syms_of_fringe (void);
2973 extern void init_fringe (void);
2974 #ifdef HAVE_WINDOW_SYSTEM
2975 extern void mark_fringe_data (void);
2976 extern void init_fringe_once (void);
2977 #endif /* HAVE_WINDOW_SYSTEM */
2979 /* Defined in image.c. */
2980 extern Lisp_Object QCascent, QCmargin, QCrelief;
2981 extern Lisp_Object QCconversion;
2982 extern int x_bitmap_mask (struct frame *, ptrdiff_t);
2983 extern void reset_image_types (void);
2984 extern void syms_of_image (void);
2986 /* Defined in insdel.c. */
2987 extern Lisp_Object Qinhibit_modification_hooks;
2988 extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2989 extern _Noreturn void buffer_overflow (void);
2990 extern void make_gap (ptrdiff_t);
2991 extern void make_gap_1 (struct buffer *, ptrdiff_t);
2992 extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
2993 ptrdiff_t, bool, bool);
2994 extern int count_combining_before (const unsigned char *,
2995 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2996 extern int count_combining_after (const unsigned char *,
2997 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2998 extern void insert (const char *, ptrdiff_t);
2999 extern void insert_and_inherit (const char *, ptrdiff_t);
3000 extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
3001 bool, bool, bool);
3002 extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
3003 extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
3004 ptrdiff_t, ptrdiff_t, bool);
3005 extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool);
3006 extern void insert_char (int);
3007 extern void insert_string (const char *);
3008 extern void insert_before_markers (const char *, ptrdiff_t);
3009 extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
3010 extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
3011 ptrdiff_t, ptrdiff_t,
3012 ptrdiff_t, bool);
3013 extern void del_range (ptrdiff_t, ptrdiff_t);
3014 extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool);
3015 extern void del_range_byte (ptrdiff_t, ptrdiff_t, bool);
3016 extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
3017 extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
3018 ptrdiff_t, ptrdiff_t, bool);
3019 extern void modify_region_1 (ptrdiff_t, ptrdiff_t, bool);
3020 extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3021 extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3022 extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3023 ptrdiff_t, ptrdiff_t);
3024 extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
3025 ptrdiff_t, ptrdiff_t);
3026 extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool);
3027 extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3028 const char *, ptrdiff_t, ptrdiff_t, bool);
3029 extern void syms_of_insdel (void);
3031 /* Defined in dispnew.c. */
3032 #if (defined PROFILING \
3033 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
3034 _Noreturn void __executable_start (void);
3035 #endif
3036 extern Lisp_Object selected_frame;
3037 extern Lisp_Object Vwindow_system;
3038 extern Lisp_Object sit_for (Lisp_Object, bool, int);
3039 extern void init_display (void);
3040 extern void syms_of_display (void);
3042 /* Defined in xdisp.c. */
3043 extern Lisp_Object Qinhibit_point_motion_hooks;
3044 extern Lisp_Object Qinhibit_redisplay, Qdisplay;
3045 extern Lisp_Object Qmenu_bar_update_hook;
3046 extern Lisp_Object Qwindow_scroll_functions;
3047 extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
3048 extern Lisp_Object Qimage, Qtext, Qboth, Qboth_horiz, Qtext_image_horiz;
3049 extern Lisp_Object Qspace, Qcenter, QCalign_to;
3050 extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
3051 extern Lisp_Object Qleft_margin, Qright_margin;
3052 extern Lisp_Object Qglyphless_char;
3053 extern Lisp_Object QCdata, QCfile;
3054 extern Lisp_Object QCmap;
3055 extern Lisp_Object Qrisky_local_variable;
3056 extern struct frame *last_glyphless_glyph_frame;
3057 extern int last_glyphless_glyph_face_id;
3058 extern int last_glyphless_glyph_merged_face_id;
3059 extern int noninteractive_need_newline;
3060 extern Lisp_Object echo_area_buffer[2];
3061 extern void add_to_log (const char *, Lisp_Object, Lisp_Object);
3062 extern void check_message_stack (void);
3063 extern void setup_echo_area_for_printing (int);
3064 extern bool push_message (void);
3065 extern Lisp_Object pop_message_unwind (Lisp_Object);
3066 extern Lisp_Object restore_message_unwind (Lisp_Object);
3067 extern void restore_message (void);
3068 extern Lisp_Object current_message (void);
3069 extern void clear_message (int, int);
3070 extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
3071 extern void message1 (const char *);
3072 extern void message1_nolog (const char *);
3073 extern void message3 (Lisp_Object);
3074 extern void message3_nolog (Lisp_Object);
3075 extern void message_dolog (const char *, ptrdiff_t, bool, bool);
3076 extern void message_with_string (const char *, Lisp_Object, int);
3077 extern void message_log_maybe_newline (void);
3078 extern void update_echo_area (void);
3079 extern void truncate_echo_area (ptrdiff_t);
3080 extern void redisplay (void);
3081 extern void redisplay_preserve_echo_area (int);
3082 extern void prepare_menu_bars (void);
3084 void set_frame_cursor_types (struct frame *, Lisp_Object);
3085 extern void syms_of_xdisp (void);
3086 extern void init_xdisp (void);
3087 extern Lisp_Object safe_eval (Lisp_Object);
3088 extern int pos_visible_p (struct window *, ptrdiff_t, int *,
3089 int *, int *, int *, int *, int *);
3091 /* Defined in xsettings.c. */
3092 extern void syms_of_xsettings (void);
3094 /* Defined in vm-limit.c. */
3095 extern void memory_warnings (void *, void (*warnfun) (const char *));
3097 /* Defined in alloc.c. */
3098 extern void check_pure_size (void);
3099 extern void free_misc (Lisp_Object);
3100 extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
3101 extern void malloc_warning (const char *);
3102 extern _Noreturn void memory_full (size_t);
3103 extern _Noreturn void buffer_memory_full (ptrdiff_t);
3104 extern bool survives_gc_p (Lisp_Object);
3105 extern void mark_object (Lisp_Object);
3106 #if defined REL_ALLOC && !defined SYSTEM_MALLOC
3107 extern void refill_memory_reserve (void);
3108 #endif
3109 extern const char *pending_malloc_warning;
3110 extern Lisp_Object zero_vector;
3111 extern Lisp_Object *stack_base;
3112 extern EMACS_INT consing_since_gc;
3113 extern EMACS_INT gc_relative_threshold;
3114 extern EMACS_INT memory_full_cons_threshold;
3115 extern Lisp_Object list1 (Lisp_Object);
3116 extern Lisp_Object list2 (Lisp_Object, Lisp_Object);
3117 extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object);
3118 extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3119 extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3120 Lisp_Object);
3121 enum constype {CONSTYPE_HEAP, CONSTYPE_PURE};
3122 extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...);
3124 /* Build a frequently used 2/3/4-integer lists. */
3126 LISP_INLINE Lisp_Object
3127 list2i (EMACS_INT x, EMACS_INT y)
3129 return list2 (make_number (x), make_number (y));
3132 LISP_INLINE Lisp_Object
3133 list3i (EMACS_INT x, EMACS_INT y, EMACS_INT w)
3135 return list3 (make_number (x), make_number (y), make_number (w));
3138 LISP_INLINE Lisp_Object
3139 list4i (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h)
3141 return list4 (make_number (x), make_number (y),
3142 make_number (w), make_number (h));
3145 extern _Noreturn void string_overflow (void);
3146 extern Lisp_Object make_string (const char *, ptrdiff_t);
3147 extern Lisp_Object make_formatted_string (char *, const char *, ...)
3148 ATTRIBUTE_FORMAT_PRINTF (2, 3);
3149 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
3151 /* Make unibyte string from C string when the length isn't known. */
3153 LISP_INLINE Lisp_Object
3154 build_unibyte_string (const char *str)
3156 return make_unibyte_string (str, strlen (str));
3159 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
3160 extern Lisp_Object make_event_array (int, Lisp_Object *);
3161 extern Lisp_Object make_uninit_string (EMACS_INT);
3162 extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
3163 extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
3164 extern Lisp_Object make_specified_string (const char *,
3165 ptrdiff_t, ptrdiff_t, bool);
3166 extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, bool);
3167 extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
3169 /* Make a string allocated in pure space, use STR as string data. */
3171 LISP_INLINE Lisp_Object
3172 build_pure_c_string (const char *str)
3174 return make_pure_c_string (str, strlen (str));
3177 /* Make a string from the data at STR, treating it as multibyte if the
3178 data warrants. */
3180 LISP_INLINE Lisp_Object
3181 build_string (const char *str)
3183 return make_string (str, strlen (str));
3186 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
3187 extern void make_byte_code (struct Lisp_Vector *);
3188 extern Lisp_Object Qautomatic_gc;
3189 extern Lisp_Object Qchar_table_extra_slots;
3190 extern struct Lisp_Vector *allocate_vector (EMACS_INT);
3192 /* Make an uninitialized vector for SIZE objects. NOTE: you must
3193 be sure that GC cannot happen until the vector is completely
3194 initialized. E.g. the following code is likely to crash:
3196 v = make_uninit_vector (3);
3197 ASET (v, 0, obj0);
3198 ASET (v, 1, Ffunction_can_gc ());
3199 ASET (v, 2, obj1); */
3201 LISP_INLINE Lisp_Object
3202 make_uninit_vector (ptrdiff_t size)
3204 Lisp_Object v;
3205 struct Lisp_Vector *p;
3207 p = allocate_vector (size);
3208 XSETVECTOR (v, p);
3209 return v;
3212 extern struct Lisp_Vector *allocate_pseudovector (int, int, enum pvec_type);
3213 #define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
3214 ((typ*) \
3215 allocate_pseudovector \
3216 (VECSIZE (typ), PSEUDOVECSIZE (typ, field), tag))
3217 extern struct Lisp_Hash_Table *allocate_hash_table (void);
3218 extern struct window *allocate_window (void);
3219 extern struct frame *allocate_frame (void);
3220 extern struct Lisp_Process *allocate_process (void);
3221 extern struct terminal *allocate_terminal (void);
3222 extern bool gc_in_progress;
3223 extern bool abort_on_gc;
3224 extern Lisp_Object make_float (double);
3225 extern void display_malloc_warning (void);
3226 extern ptrdiff_t inhibit_garbage_collection (void);
3227 extern Lisp_Object make_save_value (enum Lisp_Save_Type, ...);
3228 extern Lisp_Object make_save_pointer (void *);
3229 extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object);
3230 extern void free_marker (Lisp_Object);
3231 extern void free_cons (struct Lisp_Cons *);
3232 extern void init_alloc_once (void);
3233 extern void init_alloc (void);
3234 extern void syms_of_alloc (void);
3235 extern struct buffer * allocate_buffer (void);
3236 extern int valid_lisp_object_p (Lisp_Object);
3237 #ifdef GC_CHECK_CONS_LIST
3238 extern void check_cons_list (void);
3239 #else
3240 #define check_cons_list() ((void) 0)
3241 #endif
3243 #ifdef REL_ALLOC
3244 /* Defined in ralloc.c. */
3245 extern void *r_alloc (void **, size_t);
3246 extern void r_alloc_free (void **);
3247 extern void *r_re_alloc (void **, size_t);
3248 extern void r_alloc_reset_variable (void **, void **);
3249 extern void r_alloc_inhibit_buffer_relocation (int);
3250 #endif
3252 /* Defined in chartab.c. */
3253 extern Lisp_Object copy_char_table (Lisp_Object);
3254 extern Lisp_Object char_table_ref (Lisp_Object, int);
3255 extern Lisp_Object char_table_ref_and_range (Lisp_Object, int,
3256 int *, int *);
3257 extern void char_table_set (Lisp_Object, int, Lisp_Object);
3258 extern void char_table_set_range (Lisp_Object, int, int, Lisp_Object);
3259 extern int char_table_translate (Lisp_Object, int);
3260 extern void map_char_table (void (*) (Lisp_Object, Lisp_Object,
3261 Lisp_Object),
3262 Lisp_Object, Lisp_Object, Lisp_Object);
3263 extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object),
3264 Lisp_Object, Lisp_Object,
3265 Lisp_Object, struct charset *,
3266 unsigned, unsigned);
3267 extern Lisp_Object uniprop_table (Lisp_Object);
3268 extern void syms_of_chartab (void);
3270 /* Defined in print.c. */
3271 extern Lisp_Object Vprin1_to_string_buffer;
3272 extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
3273 extern Lisp_Object Qstandard_output;
3274 extern Lisp_Object Qexternal_debugging_output;
3275 extern void temp_output_buffer_setup (const char *);
3276 extern int print_level;
3277 extern Lisp_Object Qprint_escape_newlines;
3278 extern void write_string (const char *, int);
3279 extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
3280 Lisp_Object);
3281 extern Lisp_Object internal_with_output_to_temp_buffer
3282 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3283 enum FLOAT_TO_STRING_BUFSIZE { FLOAT_TO_STRING_BUFSIZE = 350 };
3284 extern int float_to_string (char *, double);
3285 extern void init_print_once (void);
3286 extern void syms_of_print (void);
3288 /* Defined in doprnt.c. */
3289 extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
3290 va_list);
3291 extern ptrdiff_t esprintf (char *, char const *, ...)
3292 ATTRIBUTE_FORMAT_PRINTF (2, 3);
3293 extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
3294 char const *, ...)
3295 ATTRIBUTE_FORMAT_PRINTF (5, 6);
3296 extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
3297 char const *, va_list)
3298 ATTRIBUTE_FORMAT_PRINTF (5, 0);
3300 /* Defined in lread.c. */
3301 extern Lisp_Object Qvariable_documentation, Qstandard_input;
3302 extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
3303 extern Lisp_Object Qlexical_binding;
3304 extern Lisp_Object check_obarray (Lisp_Object);
3305 extern Lisp_Object intern_1 (const char *, ptrdiff_t);
3306 extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t);
3307 extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
3308 #define LOADHIST_ATTACH(x) \
3309 do { \
3310 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \
3311 } while (0)
3312 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
3313 Lisp_Object *, Lisp_Object);
3314 extern Lisp_Object string_to_number (char const *, int, bool);
3315 extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
3316 Lisp_Object);
3317 extern void dir_warning (const char *, Lisp_Object);
3318 extern void close_load_descs (void);
3319 extern void init_obarray (void);
3320 extern void init_lread (void);
3321 extern void syms_of_lread (void);
3323 LISP_INLINE Lisp_Object
3324 intern (const char *str)
3326 return intern_1 (str, strlen (str));
3329 LISP_INLINE Lisp_Object
3330 intern_c_string (const char *str)
3332 return intern_c_string_1 (str, strlen (str));
3335 /* Defined in eval.c. */
3336 extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qmacro;
3337 extern Lisp_Object Qinhibit_quit, Qinternal_interpreter_environment, Qclosure;
3338 extern Lisp_Object Qand_rest;
3339 extern Lisp_Object Vautoload_queue;
3340 extern Lisp_Object Vsignaling_function;
3341 extern Lisp_Object inhibit_lisp_code;
3342 #if BYTE_MARK_STACK
3343 extern struct catchtag *catchlist;
3344 extern struct handler *handlerlist;
3345 #endif
3346 /* To run a normal hook, use the appropriate function from the list below.
3347 The calling convention:
3349 if (!NILP (Vrun_hooks))
3350 call1 (Vrun_hooks, Qmy_funny_hook);
3352 should no longer be used. */
3353 extern Lisp_Object Vrun_hooks;
3354 extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
3355 extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
3356 Lisp_Object (*funcall)
3357 (ptrdiff_t nargs, Lisp_Object *args));
3358 extern _Noreturn void xsignal (Lisp_Object, Lisp_Object);
3359 extern _Noreturn void xsignal0 (Lisp_Object);
3360 extern _Noreturn void xsignal1 (Lisp_Object, Lisp_Object);
3361 extern _Noreturn void xsignal2 (Lisp_Object, Lisp_Object, Lisp_Object);
3362 extern _Noreturn void xsignal3 (Lisp_Object, Lisp_Object, Lisp_Object,
3363 Lisp_Object);
3364 extern _Noreturn void signal_error (const char *, Lisp_Object);
3365 extern Lisp_Object eval_sub (Lisp_Object form);
3366 extern Lisp_Object apply1 (Lisp_Object, Lisp_Object);
3367 extern Lisp_Object call0 (Lisp_Object);
3368 extern Lisp_Object call1 (Lisp_Object, Lisp_Object);
3369 extern Lisp_Object call2 (Lisp_Object, Lisp_Object, Lisp_Object);
3370 extern Lisp_Object call3 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3371 extern Lisp_Object call4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3372 extern Lisp_Object call5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3373 extern Lisp_Object call6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3374 extern Lisp_Object call7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3375 extern Lisp_Object internal_catch (Lisp_Object, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3376 extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_Object);
3377 extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
3378 extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3379 extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3380 extern Lisp_Object internal_condition_case_n
3381 (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *,
3382 Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *));
3383 extern void specbind (Lisp_Object, Lisp_Object);
3384 extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
3385 extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
3386 extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
3387 extern _Noreturn void verror (const char *, va_list)
3388 ATTRIBUTE_FORMAT_PRINTF (1, 0);
3389 extern Lisp_Object un_autoload (Lisp_Object);
3390 extern Lisp_Object call_debugger (Lisp_Object arg);
3391 extern void init_eval_once (void);
3392 extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object, ...);
3393 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
3394 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
3395 extern void init_eval (void);
3396 extern void syms_of_eval (void);
3397 extern void record_in_backtrace (Lisp_Object function,
3398 Lisp_Object *args, ptrdiff_t nargs);
3399 extern void mark_specpdl (void);
3400 extern void get_backtrace (Lisp_Object array);
3401 Lisp_Object backtrace_top_function (void);
3402 extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);
3403 extern bool let_shadows_global_binding_p (Lisp_Object symbol);
3406 /* Defined in editfns.c. */
3407 extern Lisp_Object Qfield;
3408 extern void insert1 (Lisp_Object);
3409 extern Lisp_Object format2 (const char *, Lisp_Object, Lisp_Object);
3410 extern Lisp_Object save_excursion_save (void);
3411 extern Lisp_Object save_restriction_save (void);
3412 extern Lisp_Object save_excursion_restore (Lisp_Object);
3413 extern Lisp_Object save_restriction_restore (Lisp_Object);
3414 extern _Noreturn void time_overflow (void);
3415 extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool);
3416 extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3417 ptrdiff_t, bool);
3418 extern void init_editfns (void);
3419 extern void syms_of_editfns (void);
3420 extern void set_time_zone_rule (const char *);
3422 /* Defined in buffer.c. */
3423 extern bool mouse_face_overlay_overlaps (Lisp_Object);
3424 extern _Noreturn void nsberror (Lisp_Object);
3425 extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
3426 extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
3427 extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3428 extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
3429 Lisp_Object, Lisp_Object, Lisp_Object);
3430 extern bool overlay_touches_p (ptrdiff_t);
3431 extern Lisp_Object Vbuffer_alist;
3432 extern Lisp_Object set_buffer_if_live (Lisp_Object);
3433 extern Lisp_Object other_buffer_safely (Lisp_Object);
3434 extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
3435 extern Lisp_Object get_truename_buffer (Lisp_Object);
3436 extern void init_buffer_once (void);
3437 extern void init_buffer (void);
3438 extern void syms_of_buffer (void);
3439 extern void keys_of_buffer (void);
3441 /* Defined in marker.c. */
3443 extern ptrdiff_t marker_position (Lisp_Object);
3444 extern ptrdiff_t marker_byte_position (Lisp_Object);
3445 extern void clear_charpos_cache (struct buffer *);
3446 extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
3447 extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
3448 extern void unchain_marker (struct Lisp_Marker *marker);
3449 extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
3450 extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3451 extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
3452 ptrdiff_t, ptrdiff_t);
3453 extern Lisp_Object build_marker (struct buffer *, ptrdiff_t, ptrdiff_t);
3454 extern void syms_of_marker (void);
3456 /* Defined in fileio.c. */
3458 extern Lisp_Object Qfile_error;
3459 extern Lisp_Object Qfile_exists_p;
3460 extern Lisp_Object Qfile_directory_p;
3461 extern Lisp_Object Qinsert_file_contents;
3462 extern Lisp_Object Qfile_name_history;
3463 extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object);
3464 EXFUN (Fread_file_name, 6); /* Not a normal DEFUN. */
3465 extern Lisp_Object close_file_unwind (Lisp_Object);
3466 extern Lisp_Object restore_point_unwind (Lisp_Object);
3467 extern _Noreturn void report_file_error (const char *, Lisp_Object);
3468 extern bool internal_delete_file (Lisp_Object);
3469 extern Lisp_Object emacs_readlinkat (int, const char *);
3470 extern bool file_directory_p (const char *);
3471 extern bool file_accessible_directory_p (const char *);
3472 extern void init_fileio (void);
3473 extern void syms_of_fileio (void);
3474 extern Lisp_Object make_temp_name (Lisp_Object, bool);
3475 extern Lisp_Object Qdelete_file;
3476 extern bool check_existing (const char *);
3478 /* Defined in search.c. */
3479 extern void shrink_regexp_cache (void);
3480 extern void restore_search_regs (void);
3481 extern void record_unwind_save_match_data (void);
3482 struct re_registers;
3483 extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
3484 struct re_registers *,
3485 Lisp_Object, bool, bool);
3486 extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
3487 extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
3488 ptrdiff_t);
3489 extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
3490 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
3491 ptrdiff_t, ptrdiff_t, Lisp_Object);
3492 extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3493 ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
3494 extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3495 EMACS_INT, bool);
3496 extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
3497 ptrdiff_t, ptrdiff_t *);
3498 extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
3499 ptrdiff_t, ptrdiff_t *);
3500 extern void syms_of_search (void);
3501 extern void clear_regexp_cache (void);
3503 /* Defined in minibuf.c. */
3505 extern Lisp_Object Qcompletion_ignore_case;
3506 extern Lisp_Object Vminibuffer_list;
3507 extern Lisp_Object last_minibuf_string;
3508 extern Lisp_Object get_minibuffer (EMACS_INT);
3509 extern void init_minibuf_once (void);
3510 extern void syms_of_minibuf (void);
3512 /* Defined in callint.c. */
3514 extern Lisp_Object Qminus, Qplus;
3515 extern Lisp_Object Qwhen;
3516 extern Lisp_Object Qmouse_leave_buffer_hook;
3517 extern void syms_of_callint (void);
3519 /* Defined in casefiddle.c. */
3521 extern Lisp_Object Qidentity;
3522 extern void syms_of_casefiddle (void);
3523 extern void keys_of_casefiddle (void);
3525 /* Defined in casetab.c. */
3527 extern void init_casetab_once (void);
3528 extern void syms_of_casetab (void);
3530 /* Defined in keyboard.c. */
3532 extern Lisp_Object echo_message_buffer;
3533 extern struct kboard *echo_kboard;
3534 extern void cancel_echoing (void);
3535 extern Lisp_Object Qdisabled, QCfilter;
3536 extern Lisp_Object Qup, Qdown, Qbottom;
3537 extern Lisp_Object Qtop;
3538 extern Lisp_Object last_undo_boundary;
3539 extern bool input_pending;
3540 extern Lisp_Object menu_bar_items (Lisp_Object);
3541 extern Lisp_Object tool_bar_items (Lisp_Object, int *);
3542 extern void discard_mouse_events (void);
3543 #ifdef USABLE_SIGIO
3544 void handle_input_available_signal (int);
3545 #endif
3546 extern Lisp_Object pending_funcalls;
3547 extern bool detect_input_pending (void);
3548 extern bool detect_input_pending_ignore_squeezables (void);
3549 extern bool detect_input_pending_run_timers (bool);
3550 extern void safe_run_hooks (Lisp_Object);
3551 extern void cmd_error_internal (Lisp_Object, const char *);
3552 extern Lisp_Object command_loop_1 (void);
3553 extern Lisp_Object recursive_edit_1 (void);
3554 extern void record_auto_save (void);
3555 extern void force_auto_save_soon (void);
3556 extern void init_keyboard (void);
3557 extern void syms_of_keyboard (void);
3558 extern void keys_of_keyboard (void);
3560 /* Defined in indent.c. */
3561 extern ptrdiff_t current_column (void);
3562 extern void invalidate_current_column (void);
3563 extern bool indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3564 extern void syms_of_indent (void);
3566 /* Defined in frame.c. */
3567 extern Lisp_Object Qonly, Qnone;
3568 extern Lisp_Object Qvisible;
3569 extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
3570 extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
3571 extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
3572 #if HAVE_NS || defined(WINDOWSNT)
3573 extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
3574 #endif
3575 extern void frames_discard_buffer (Lisp_Object);
3576 extern void syms_of_frame (void);
3578 /* Defined in emacs.c. */
3579 extern char **initial_argv;
3580 extern int initial_argc;
3581 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
3582 extern bool display_arg;
3583 #endif
3584 extern Lisp_Object decode_env_path (const char *, const char *);
3585 extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3586 extern Lisp_Object Qfile_name_handler_alist;
3587 extern _Noreturn void terminate_due_to_signal (int, int);
3588 extern Lisp_Object Qkill_emacs;
3589 #ifdef WINDOWSNT
3590 extern Lisp_Object Vlibrary_cache;
3591 #endif
3592 #if HAVE_SETLOCALE
3593 void fixup_locale (void);
3594 void synchronize_system_messages_locale (void);
3595 void synchronize_system_time_locale (void);
3596 #else
3597 #define setlocale(category, locale)
3598 #define fixup_locale()
3599 #define synchronize_system_messages_locale()
3600 #define synchronize_system_time_locale()
3601 #endif
3602 extern void shut_down_emacs (int, Lisp_Object);
3604 /* True means don't do interactive redisplay and don't change tty modes. */
3605 extern bool noninteractive;
3607 /* True means remove site-lisp directories from load-path. */
3608 extern bool no_site_lisp;
3610 /* Pipe used to send exit notification to the daemon parent at
3611 startup. */
3612 extern int daemon_pipe[2];
3613 #define IS_DAEMON (daemon_pipe[1] != 0)
3615 /* True if handling a fatal error already. */
3616 extern bool fatal_error_in_progress;
3618 /* True means don't do use window-system-specific display code. */
3619 extern bool inhibit_window_system;
3620 /* True means that a filter or a sentinel is running. */
3621 extern bool running_asynch_code;
3623 /* Defined in process.c. */
3624 extern Lisp_Object QCtype, Qlocal;
3625 extern Lisp_Object Qprocessp;
3626 extern void kill_buffer_processes (Lisp_Object);
3627 extern bool wait_reading_process_output (intmax_t, int, int, bool,
3628 Lisp_Object,
3629 struct Lisp_Process *,
3630 int);
3631 /* Max value for the first argument of wait_reading_process_output. */
3632 #if __GNUC__ == 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 5)
3633 /* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.3.
3634 The bug merely causes a bogus warning, but the warning is annoying. */
3635 # define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX)
3636 #else
3637 # define WAIT_READING_MAX INTMAX_MAX
3638 #endif
3639 extern void add_keyboard_wait_descriptor (int);
3640 extern void delete_keyboard_wait_descriptor (int);
3641 #ifdef HAVE_GPM
3642 extern void add_gpm_wait_descriptor (int);
3643 extern void delete_gpm_wait_descriptor (int);
3644 #endif
3645 extern void close_process_descs (void);
3646 extern void init_process_emacs (void);
3647 extern void syms_of_process (void);
3648 extern void setup_process_coding_systems (Lisp_Object);
3650 #ifndef DOS_NT
3651 _Noreturn
3652 #endif
3653 extern int child_setup (int, int, int, char **, bool, Lisp_Object);
3654 extern void init_callproc_1 (void);
3655 extern void init_callproc (void);
3656 extern void set_initial_environment (void);
3657 extern void syms_of_callproc (void);
3659 /* Defined in doc.c. */
3660 extern Lisp_Object Qfunction_documentation;
3661 extern Lisp_Object read_doc_string (Lisp_Object);
3662 extern Lisp_Object get_doc_string (Lisp_Object, bool, bool);
3663 extern void syms_of_doc (void);
3664 extern int read_bytecode_char (bool);
3666 /* Defined in bytecode.c. */
3667 extern void syms_of_bytecode (void);
3668 extern struct byte_stack *byte_stack_list;
3669 #if BYTE_MARK_STACK
3670 extern void mark_byte_stack (void);
3671 #endif
3672 extern void unmark_byte_stack (void);
3673 extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
3674 Lisp_Object, ptrdiff_t, Lisp_Object *);
3676 /* Defined in macros.c. */
3677 extern void init_macros (void);
3678 extern void syms_of_macros (void);
3680 /* Defined in undo.c. */
3681 extern Lisp_Object Qapply;
3682 extern Lisp_Object Qinhibit_read_only;
3683 extern void truncate_undo_list (struct buffer *);
3684 extern void record_marker_adjustment (Lisp_Object, ptrdiff_t);
3685 extern void record_insert (ptrdiff_t, ptrdiff_t);
3686 extern void record_delete (ptrdiff_t, Lisp_Object);
3687 extern void record_first_change (void);
3688 extern void record_change (ptrdiff_t, ptrdiff_t);
3689 extern void record_property_change (ptrdiff_t, ptrdiff_t,
3690 Lisp_Object, Lisp_Object,
3691 Lisp_Object);
3692 extern void syms_of_undo (void);
3693 /* Defined in textprop.c. */
3694 extern Lisp_Object Qfont, Qmouse_face;
3695 extern Lisp_Object Qinsert_in_front_hooks, Qinsert_behind_hooks;
3696 extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
3697 extern Lisp_Object Qminibuffer_prompt;
3699 extern void report_interval_modification (Lisp_Object, Lisp_Object);
3701 /* Defined in menu.c. */
3702 extern void syms_of_menu (void);
3704 /* Defined in xmenu.c. */
3705 extern void syms_of_xmenu (void);
3707 /* Defined in termchar.h. */
3708 struct tty_display_info;
3710 /* Defined in termhooks.h. */
3711 struct terminal;
3713 /* Defined in sysdep.c. */
3714 #ifndef HAVE_GET_CURRENT_DIR_NAME
3715 extern char *get_current_dir_name (void);
3716 #endif
3717 extern void stuff_char (char c);
3718 extern void init_foreground_group (void);
3719 extern void init_sigio (int);
3720 extern void sys_subshell (void);
3721 extern void sys_suspend (void);
3722 extern void discard_tty_input (void);
3723 extern void block_tty_out_signal (void);
3724 extern void unblock_tty_out_signal (void);
3725 extern void init_sys_modes (struct tty_display_info *);
3726 extern void reset_sys_modes (struct tty_display_info *);
3727 extern void init_all_sys_modes (void);
3728 extern void reset_all_sys_modes (void);
3729 extern void flush_pending_output (int) ATTRIBUTE_CONST;
3730 extern void child_setup_tty (int);
3731 extern void setup_pty (int);
3732 extern int set_window_size (int, int, int);
3733 extern EMACS_INT get_random (void);
3734 extern void seed_random (void *, ptrdiff_t);
3735 extern void init_random (void);
3736 extern void emacs_backtrace (int);
3737 extern _Noreturn void emacs_abort (void) NO_INLINE;
3738 extern int emacs_open (const char *, int, int);
3739 extern int emacs_close (int);
3740 extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
3741 extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
3743 extern void unlock_all_files (void);
3744 extern void lock_file (Lisp_Object);
3745 extern void unlock_file (Lisp_Object);
3746 extern void unlock_buffer (struct buffer *);
3747 extern void syms_of_filelock (void);
3749 /* Defined in sound.c. */
3750 extern void syms_of_sound (void);
3752 /* Defined in category.c. */
3753 extern void init_category_once (void);
3754 extern Lisp_Object char_category_set (int);
3755 extern void syms_of_category (void);
3757 /* Defined in ccl.c. */
3758 extern void syms_of_ccl (void);
3760 /* Defined in dired.c. */
3761 extern void syms_of_dired (void);
3762 extern Lisp_Object directory_files_internal (Lisp_Object, Lisp_Object,
3763 Lisp_Object, Lisp_Object,
3764 bool, Lisp_Object);
3766 /* Defined in term.c. */
3767 extern int *char_ins_del_vector;
3768 extern void syms_of_term (void);
3769 extern _Noreturn void fatal (const char *msgid, ...)
3770 ATTRIBUTE_FORMAT_PRINTF (1, 2);
3772 /* Defined in terminal.c. */
3773 extern void syms_of_terminal (void);
3775 /* Defined in font.c. */
3776 extern void syms_of_font (void);
3777 extern void init_font (void);
3779 #ifdef HAVE_WINDOW_SYSTEM
3780 /* Defined in fontset.c. */
3781 extern void syms_of_fontset (void);
3783 /* Defined in xfns.c, w32fns.c, or macfns.c. */
3784 extern Lisp_Object Qfont_param;
3785 #endif
3787 /* Defined in gfilenotify.c */
3788 #ifdef HAVE_GFILENOTIFY
3789 extern void syms_of_gfilenotify (void);
3790 #endif
3792 /* Defined in inotify.c */
3793 #ifdef HAVE_INOTIFY
3794 extern void syms_of_inotify (void);
3795 #endif
3797 #ifdef HAVE_W32NOTIFY
3798 /* Defined on w32notify.c. */
3799 extern void syms_of_w32notify (void);
3800 #endif
3802 /* Defined in xfaces.c. */
3803 extern Lisp_Object Qdefault, Qtool_bar, Qfringe;
3804 extern Lisp_Object Qheader_line, Qscroll_bar, Qcursor;
3805 extern Lisp_Object Qmode_line_inactive;
3806 extern Lisp_Object Qface;
3807 extern Lisp_Object Qnormal;
3808 extern Lisp_Object QCfamily, QCweight, QCslant;
3809 extern Lisp_Object QCheight, QCname, QCwidth, QCforeground, QCbackground;
3810 extern Lisp_Object Qextra_light, Qlight, Qsemi_light, Qsemi_bold;
3811 extern Lisp_Object Qbold, Qextra_bold, Qultra_bold;
3812 extern Lisp_Object Qoblique, Qitalic;
3813 extern Lisp_Object Vface_alternative_font_family_alist;
3814 extern Lisp_Object Vface_alternative_font_registry_alist;
3815 extern void syms_of_xfaces (void);
3817 #ifdef HAVE_X_WINDOWS
3818 /* Defined in xfns.c. */
3819 extern void syms_of_xfns (void);
3821 /* Defined in xsmfns.c. */
3822 extern void syms_of_xsmfns (void);
3824 /* Defined in xselect.c. */
3825 extern void syms_of_xselect (void);
3827 /* Defined in xterm.c. */
3828 extern void syms_of_xterm (void);
3829 #endif /* HAVE_X_WINDOWS */
3831 #ifdef HAVE_WINDOW_SYSTEM
3832 /* Defined in xterm.c, nsterm.m, w32term.c. */
3833 extern char *x_get_keysym_name (int);
3834 #endif /* HAVE_WINDOW_SYSTEM */
3836 #ifdef HAVE_LIBXML2
3837 /* Defined in xml.c. */
3838 extern void syms_of_xml (void);
3839 extern void xml_cleanup_parser (void);
3840 #endif
3842 #ifdef HAVE_DBUS
3843 /* Defined in dbusbind.c. */
3844 void syms_of_dbusbind (void);
3845 #endif
3848 /* Defined in profiler.c. */
3849 extern bool profiler_memory_running;
3850 extern void malloc_probe (size_t);
3851 extern void syms_of_profiler (void);
3854 #ifdef DOS_NT
3855 /* Defined in msdos.c, w32.c. */
3856 extern char *emacs_root_dir (void);
3857 #endif /* DOS_NT */
3859 /* True means Emacs has already been initialized.
3860 Used during startup to detect startup of dumped Emacs. */
3861 extern bool initialized;
3863 /* True means ^G can quit instantly. */
3864 extern bool immediate_quit;
3866 extern void *xmalloc (size_t);
3867 extern void *xzalloc (size_t);
3868 extern void *xrealloc (void *, size_t);
3869 extern void xfree (void *);
3870 extern void *xnmalloc (ptrdiff_t, ptrdiff_t);
3871 extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
3872 extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
3874 extern char *xstrdup (const char *);
3875 extern void xputenv (const char *);
3877 extern char *egetenv (const char *);
3879 /* Set up the name of the machine we're running on. */
3880 extern void init_system_name (void);
3882 /* Return the absolute value of X. X should be a signed integer
3883 expression without side effects, and X's absolute value should not
3884 exceed the maximum for its promoted type. This is called 'eabs'
3885 because 'abs' is reserved by the C standard. */
3886 #define eabs(x) ((x) < 0 ? -(x) : (x))
3888 /* Return a fixnum or float, depending on whether VAL fits in a Lisp
3889 fixnum. */
3891 #define make_fixnum_or_float(val) \
3892 (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
3894 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
3895 larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */
3897 enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 };
3899 extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3900 extern void *record_xmalloc (size_t);
3902 #define USE_SAFE_ALLOCA \
3903 ptrdiff_t sa_count = SPECPDL_INDEX (); bool sa_must_free = 0
3905 /* SAFE_ALLOCA allocates a simple buffer. */
3907 #define SAFE_ALLOCA(size) ((size) < MAX_ALLOCA \
3908 ? alloca (size) \
3909 : (sa_must_free = 1, record_xmalloc (size)))
3911 /* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
3912 NITEMS items, each of the same type as *BUF. MULTIPLIER must
3913 positive. The code is tuned for MULTIPLIER being a constant. */
3915 #define SAFE_NALLOCA(buf, multiplier, nitems) \
3916 do { \
3917 if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \
3918 (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \
3919 else \
3921 (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
3922 sa_must_free = 1; \
3923 record_unwind_protect (safe_alloca_unwind, \
3924 make_save_pointer (buf)); \
3926 } while (0)
3928 /* SAFE_FREE frees xmalloced memory and enables GC as needed. */
3930 #define SAFE_FREE() \
3931 do { \
3932 if (sa_must_free) { \
3933 sa_must_free = 0; \
3934 unbind_to (sa_count, Qnil); \
3936 } while (0)
3939 /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */
3941 #define SAFE_ALLOCA_LISP(buf, nelt) \
3942 do { \
3943 if ((nelt) < MAX_ALLOCA / word_size) \
3944 buf = alloca ((nelt) * word_size); \
3945 else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / word_size) \
3947 Lisp_Object arg_; \
3948 buf = xmalloc ((nelt) * word_size); \
3949 arg_ = make_save_value (SAVE_TYPE_MEMORY, buf, nelt); \
3950 sa_must_free = 1; \
3951 record_unwind_protect (safe_alloca_unwind, arg_); \
3953 else \
3954 memory_full (SIZE_MAX); \
3955 } while (0)
3958 #include "globals.h"
3960 /* Check whether it's time for GC, and run it if so. */
3962 LISP_INLINE void
3963 maybe_gc (void)
3965 if ((consing_since_gc > gc_cons_threshold
3966 && consing_since_gc > gc_relative_threshold)
3967 || (!NILP (Vmemory_full)
3968 && consing_since_gc > memory_full_cons_threshold))
3969 Fgarbage_collect ();
3972 LISP_INLINE int
3973 functionp (Lisp_Object object)
3975 if (SYMBOLP (object) && !NILP (Ffboundp (object)))
3977 object = Findirect_function (object, Qt);
3979 if (CONSP (object) && EQ (XCAR (object), Qautoload))
3981 /* Autoloaded symbols are functions, except if they load
3982 macros or keymaps. */
3983 int i;
3984 for (i = 0; i < 4 && CONSP (object); i++)
3985 object = XCDR (object);
3987 return ! (CONSP (object) && !NILP (XCAR (object)));
3991 if (SUBRP (object))
3992 return XSUBR (object)->max_args != UNEVALLED;
3993 else if (COMPILEDP (object))
3994 return 1;
3995 else if (CONSP (object))
3997 Lisp_Object car = XCAR (object);
3998 return EQ (car, Qlambda) || EQ (car, Qclosure);
4000 else
4001 return 0;
4004 INLINE_HEADER_END
4006 #endif /* EMACS_LISP_H */