Fix export of symbols to GDB.
[emacs.git] / src / lisp.h
blobf845ea6bd12e607a99228982df16850bb9d9f772
1 /* Fundamental definitions for GNU Emacs Lisp interpreter.
3 Copyright (C) 1985-1987, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef EMACS_LISP_H
21 #define EMACS_LISP_H
23 #include <stdarg.h>
24 #include <stddef.h>
25 #include <inttypes.h>
26 #include <limits.h>
28 #include <intprops.h>
30 /* Use the configure flag --enable-checking[=LIST] to enable various
31 types of run time checks for Lisp objects. */
33 #ifdef GC_CHECK_CONS_LIST
34 extern void check_cons_list (void);
35 #define CHECK_CONS_LIST() check_cons_list ()
36 #else
37 #define CHECK_CONS_LIST() ((void) 0)
38 #endif
40 /* Temporarily disable wider-than-pointer integers until they're tested more.
41 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */
42 /* #undef WIDE_EMACS_INT */
44 /* EMACS_INT - signed integer wide enough to hold an Emacs value
45 EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
46 pI - printf length modifier for EMACS_INT
47 EMACS_UINT - unsigned variant of EMACS_INT */
48 #ifndef EMACS_INT_MAX
49 # if LONG_MAX < LLONG_MAX && defined WIDE_EMACS_INT
50 typedef long long int EMACS_INT;
51 typedef unsigned long long int EMACS_UINT;
52 # define EMACS_INT_MAX LLONG_MAX
53 # define pI "ll"
54 # elif INT_MAX < LONG_MAX
55 typedef long int EMACS_INT;
56 typedef unsigned long int EMACS_UINT;
57 # define EMACS_INT_MAX LONG_MAX
58 # define pI "l"
59 # else
60 typedef int EMACS_INT;
61 typedef unsigned int EMACS_UINT;
62 # define EMACS_INT_MAX INT_MAX
63 # define pI ""
64 # endif
65 #endif
67 /* If an enum type is not used, the enum symbols are not put into the
68 executable so the debugger cannot see them on many systems, e.g.,
69 GCC 4.7.1 + GDB 7.4.1 + GNU/Linux. Work around this problem by
70 explicitly using the names in the integer constant expression EXPR. */
71 #define PUBLISH_TO_GDB(expr) extern int (*gdb_dummy (int))[(expr) || 1]
73 /* Number of bits in some machine integer types. */
74 enum
76 BITS_PER_CHAR = CHAR_BIT,
77 BITS_PER_SHORT = CHAR_BIT * sizeof (short),
78 BITS_PER_INT = CHAR_BIT * sizeof (int),
79 BITS_PER_LONG = CHAR_BIT * sizeof (long int),
80 BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
83 /* printmax_t and uprintmax_t are types for printing large integers.
84 These are the widest integers that are supported for printing.
85 pMd etc. are conversions for printing them.
86 On C99 hosts, there's no problem, as even the widest integers work.
87 Fall back on EMACS_INT on pre-C99 hosts. */
88 #ifdef PRIdMAX
89 typedef intmax_t printmax_t;
90 typedef uintmax_t uprintmax_t;
91 # define pMd PRIdMAX
92 # define pMu PRIuMAX
93 #else
94 typedef EMACS_INT printmax_t;
95 typedef EMACS_UINT uprintmax_t;
96 # define pMd pI"d"
97 # define pMu pI"u"
98 #endif
100 /* Use pD to format ptrdiff_t values, which suffice for indexes into
101 buffers and strings. Emacs never allocates objects larger than
102 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
103 In C99, pD can always be "t"; configure it here for the sake of
104 pre-C99 libraries such as glibc 2.0 and Solaris 8. */
105 #if PTRDIFF_MAX == INT_MAX
106 # define pD ""
107 #elif PTRDIFF_MAX == LONG_MAX
108 # define pD "l"
109 #elif PTRDIFF_MAX == LLONG_MAX
110 # define pD "ll"
111 #else
112 # define pD "t"
113 #endif
115 /* Extra internal type checking? */
117 /* Define an Emacs version of 'assert (COND)', since some
118 system-defined 'assert's are flaky. COND should be free of side
119 effects; it may or may not be evaluated. */
120 #ifndef ENABLE_CHECKING
121 # define eassert(X) ((void) (0 && (X))) /* Check that X compiles. */
122 #else /* ENABLE_CHECKING */
124 extern _Noreturn void die (const char *, const char *, int);
126 /* The suppress_checking variable is initialized to 0 in alloc.c. Set
127 it to 1 using a debugger to temporarily disable aborting on
128 detected internal inconsistencies or error conditions.
130 In some cases, a good compiler may be able to optimize away the
131 eassert macro altogether, e.g., if XSTRING (x) uses eassert to test
132 STRINGP (x), but a particular use of XSTRING is invoked only after
133 testing that STRINGP (x) is true, making the test redundant. */
134 extern int suppress_checking EXTERNALLY_VISIBLE;
136 # define eassert(cond) \
137 ((cond) || suppress_checking \
138 ? (void) 0 \
139 : die ("assertion failed: " # cond, __FILE__, __LINE__))
140 #endif /* ENABLE_CHECKING */
142 /* Use the configure flag --enable-check-lisp-object-type to make
143 Lisp_Object use a struct type instead of the default int. The flag
144 causes CHECK_LISP_OBJECT_TYPE to be defined. */
146 /***** Select the tagging scheme. *****/
147 /* The following option controls the tagging scheme:
148 - USE_LSB_TAG means that we can assume the least 3 bits of pointers are
149 always 0, and we can thus use them to hold tag bits, without
150 restricting our addressing space.
152 If ! USE_LSB_TAG, then use the top 3 bits for tagging, thus
153 restricting our possible address range.
155 USE_LSB_TAG not only requires the least 3 bits of pointers returned by
156 malloc to be 0 but also needs to be able to impose a mult-of-8 alignment
157 on the few static Lisp_Objects used: all the defsubr as well
158 as the two special buffers buffer_defaults and buffer_local_symbols. */
160 /* First, try and define DECL_ALIGN(type,var) which declares a static
161 variable VAR of type TYPE with the added requirement that it be
162 TYPEBITS-aligned. */
164 /* Number of bits in a Lisp_Object tag. This can be used in #if,
165 and for GDB's sake also as a regular symbol. */
166 enum { GCTYPEBITS = 3 };
167 PUBLISH_TO_GDB (GCTYPEBITS);
168 #define GCTYPEBITS 3
170 /* Number of bits in a Lisp_Object value, not counting the tag. */
171 enum { VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS };
173 /* The maximum value that can be stored in a EMACS_INT, assuming all
174 bits other than the type bits contribute to a nonnegative signed value.
175 This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */
176 #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
178 #ifndef NO_DECL_ALIGN
179 # ifndef DECL_ALIGN
180 # if HAVE_ATTRIBUTE_ALIGNED
181 # define DECL_ALIGN(type, var) \
182 type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var
183 # elif defined(_MSC_VER)
184 # define ALIGN_GCTYPEBITS 8
185 # if (1 << GCTYPEBITS) != ALIGN_GCTYPEBITS
186 # error ALIGN_GCTYPEBITS is wrong!
187 # endif
188 # define DECL_ALIGN(type, var) \
189 type __declspec(align(ALIGN_GCTYPEBITS)) var
190 # else
191 /* What directives do other compilers use? */
192 # endif
193 # endif
194 #endif
196 /* Unless otherwise specified, use USE_LSB_TAG on systems where: */
197 #ifndef USE_LSB_TAG
198 /* 1. We know malloc returns a multiple of 8. */
199 # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \
200 || defined DARWIN_OS || defined __sun)
201 /* 2. We can specify multiple-of-8 alignment on static variables. */
202 # ifdef DECL_ALIGN
203 /* 3. Pointers-as-ints exceed VAL_MAX.
204 On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is:
205 a. unnecessary, because the top bits of an EMACS_INT are unused, and
206 b. slower, because it typically requires extra masking.
207 So, default USE_LSB_TAG to 1 only on hosts where it might be useful. */
208 # if VAL_MAX < UINTPTR_MAX
209 # define USE_LSB_TAG 1
210 # endif
211 # endif
212 # endif
213 #endif
214 /* USE_LSB_TAG can be used in #if; default it to 0 and make it visible
215 to GDB. */
216 #ifdef USE_LSB_TAG
217 # undef USE_LSB_TAG
218 enum { USE_LSB_TAG = 1 };
219 PUBLISH_TO_GDB (USE_LSB_TAG);
220 # define USE_LSB_TAG 1
221 #else
222 enum { USE_LSB_TAG = 0 };
223 PUBLISH_TO_GDB (USE_LSB_TAG);
224 # define USE_LSB_TAG 0
225 #endif
227 /* If we cannot use 8-byte alignment, make DECL_ALIGN a no-op. */
228 #ifndef DECL_ALIGN
229 # if USE_LSB_TAG
230 # error "USE_LSB_TAG used without defining DECL_ALIGN"
231 # endif
232 # define DECL_ALIGN(type, var) type var
233 #endif
236 /* Define the fundamental Lisp data structures. */
238 /* This is the set of Lisp data types. */
240 /* Lisp integers use 2 tags, to give them one extra bit, thus
241 extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1. */
242 enum { INTTYPEBITS = GCTYPEBITS - 1 };
243 enum { FIXNUM_BITS = VALBITS + 1 };
244 #define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
245 #define LISP_INT_TAG Lisp_Int0
246 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
247 #define LISP_INT1_TAG (USE_LSB_TAG ? 1 << INTTYPEBITS : 1)
248 #define LISP_STRING_TAG (5 - LISP_INT1_TAG)
249 #define LISP_INT_TAG_P(x) (((x) & ~LISP_INT1_TAG) == 0)
251 /* Stolen from GDB. The only known compiler that doesn't support
252 enums in bitfields is MSVC. */
253 #ifdef _MSC_VER
254 #define ENUM_BF(TYPE) unsigned int
255 #else
256 #define ENUM_BF(TYPE) enum TYPE
257 #endif
260 enum Lisp_Type
262 /* Integer. XINT (obj) is the integer value. */
263 Lisp_Int0 = 0,
264 Lisp_Int1 = LISP_INT1_TAG,
266 /* Symbol. XSYMBOL (object) points to a struct Lisp_Symbol. */
267 Lisp_Symbol = 2,
269 /* Miscellaneous. XMISC (object) points to a union Lisp_Misc,
270 whose first member indicates the subtype. */
271 Lisp_Misc = 3,
273 /* String. XSTRING (object) points to a struct Lisp_String.
274 The length of the string, and its contents, are stored therein. */
275 Lisp_String = LISP_STRING_TAG,
277 /* Vector of Lisp objects, or something resembling it.
278 XVECTOR (object) points to a struct Lisp_Vector, which contains
279 the size and contents. The size field also contains the type
280 information, if it's not a real vector object. */
281 Lisp_Vectorlike = 5,
283 /* Cons. XCONS (object) points to a struct Lisp_Cons. */
284 Lisp_Cons = 6,
286 Lisp_Float = 7,
289 /* This is the set of data types that share a common structure.
290 The first member of the structure is a type code from this set.
291 The enum values are arbitrary, but we'll use large numbers to make it
292 more likely that we'll spot the error if a random word in memory is
293 mistakenly interpreted as a Lisp_Misc. */
294 enum Lisp_Misc_Type
296 Lisp_Misc_Free = 0x5eab,
297 Lisp_Misc_Marker,
298 Lisp_Misc_Overlay,
299 Lisp_Misc_Save_Value,
300 /* Currently floats are not a misc type,
301 but let's define this in case we want to change that. */
302 Lisp_Misc_Float,
303 /* This is not a type code. It is for range checking. */
304 Lisp_Misc_Limit
307 /* These are the types of forwarding objects used in the value slot
308 of symbols for special built-in variables whose value is stored in
309 C variables. */
310 enum Lisp_Fwd_Type
312 Lisp_Fwd_Int, /* Fwd to a C `int' variable. */
313 Lisp_Fwd_Bool, /* Fwd to a C boolean var. */
314 Lisp_Fwd_Obj, /* Fwd to a C Lisp_Object variable. */
315 Lisp_Fwd_Buffer_Obj, /* Fwd to a Lisp_Object field of buffers. */
316 Lisp_Fwd_Kboard_Obj, /* Fwd to a Lisp_Object field of kboards. */
319 #ifdef CHECK_LISP_OBJECT_TYPE
321 typedef struct { EMACS_INT i; } Lisp_Object;
323 #define XLI(o) (o).i
324 static inline Lisp_Object
325 XIL (EMACS_INT i)
327 Lisp_Object o = { i };
328 return o;
331 static inline Lisp_Object
332 LISP_MAKE_RVALUE (Lisp_Object o)
334 return o;
337 #define LISP_INITIALLY_ZERO {0}
338 #undef CHECK_LISP_OBJECT_TYPE
339 enum { CHECK_LISP_OBJECT_TYPE = 1 };
341 #else /* CHECK_LISP_OBJECT_TYPE */
343 /* If a struct type is not wanted, define Lisp_Object as just a number. */
345 typedef EMACS_INT Lisp_Object;
346 #define XLI(o) (o)
347 #define XIL(i) (i)
348 #define LISP_MAKE_RVALUE(o) (0+(o))
349 #define LISP_INITIALLY_ZERO 0
350 enum { CHECK_LISP_OBJECT_TYPE = 0 };
351 #endif /* CHECK_LISP_OBJECT_TYPE */
352 PUBLISH_TO_GDB (CHECK_LISP_OBJECT_TYPE);
354 /* In the size word of a vector, this bit means the vector has been marked. */
356 #define ARRAY_MARK_FLAG PTRDIFF_MIN
358 /* In the size word of a struct Lisp_Vector, this bit means it's really
359 some other vector-like object. */
360 #define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
362 /* In a pseudovector, the size field actually contains a word with one
363 PSEUDOVECTOR_FLAG bit set, and exactly one of the following bits to
364 indicate the actual type.
365 We use a bitset, even tho only one of the bits can be set at any
366 particular time just so as to be able to use micro-optimizations such as
367 testing membership of a particular subset of pseudovectors in Fequal.
368 It is not crucial, but there are plenty of bits here, so why not do it? */
369 enum pvec_type
371 PVEC_NORMAL_VECTOR = 0, /* Unused! */
372 PVEC_FREE,
373 PVEC_PROCESS,
374 PVEC_FRAME,
375 PVEC_WINDOW,
376 PVEC_BOOL_VECTOR,
377 PVEC_BUFFER,
378 PVEC_HASH_TABLE,
379 PVEC_TERMINAL,
380 PVEC_WINDOW_CONFIGURATION,
381 PVEC_SUBR,
382 PVEC_OTHER,
383 /* These last 4 are special because we OR them in fns.c:internal_equal,
384 so they have to use a disjoint bit pattern:
385 if (!(size & (PVEC_COMPILED | PVEC_CHAR_TABLE
386 | PVEC_SUB_CHAR_TABLE | PVEC_FONT))) */
387 PVEC_COMPILED = 0x10,
388 PVEC_CHAR_TABLE = 0x20,
389 PVEC_SUB_CHAR_TABLE = 0x30,
390 PVEC_FONT = 0x40
392 PUBLISH_TO_GDB ((enum pvec_type) 0); /* This also publishes PVEC_*. */
394 /* For convenience, we also store the number of elements in these bits.
395 Note that this size is not necessarily the memory-footprint size, but
396 only the number of Lisp_Object fields (that need to be traced by the GC).
397 The distinction is used e.g. by Lisp_Process which places extra
398 non-Lisp_Object fields at the end of the structure. */
399 enum
401 PSEUDOVECTOR_SIZE_BITS = 16,
402 PSEUDOVECTOR_SIZE_MASK = (1 << PSEUDOVECTOR_SIZE_BITS) - 1,
403 PVEC_TYPE_MASK = 0x0fff << PSEUDOVECTOR_SIZE_BITS
406 /* Number of bits to put in each character in the internal representation
407 of bool vectors. This should not vary across implementations. */
408 enum { BOOL_VECTOR_BITS_PER_CHAR = 8 };
410 /* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
411 which were stored in a Lisp_Object. It is not needed in #if, so
412 for GDB's sake change it from a macro to a regular symbol. */
413 #ifdef DATA_SEG_BITS
414 enum { gdb_DATA_SEG_BITS = DATA_SEG_BITS };
415 # undef DATA_SEG_BITS
416 enum { DATA_SEG_BITS = gdb_DATA_SEG_BITS };
417 #else
418 enum { DATA_SEG_BITS = 0 };
419 #endif
420 PUBLISH_TO_GDB (DATA_SEG_BITS);
422 /* These macros extract various sorts of values from a Lisp_Object.
423 For example, if tem is a Lisp_Object whose type is Lisp_Cons,
424 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */
426 /* Return a perfect hash of the Lisp_Object representation. */
427 #define XHASH(a) XLI (a)
429 #if USE_LSB_TAG
431 #define VALMASK (-1 << GCTYPEBITS)
432 #define TYPEMASK ((1 << GCTYPEBITS) - 1)
433 #define XTYPE(a) ((enum Lisp_Type) (XLI (a) & TYPEMASK))
434 #define XINT(a) (XLI (a) >> INTTYPEBITS)
435 #define XUINT(a) ((EMACS_UINT) XLI (a) >> INTTYPEBITS)
436 #define make_number(N) XIL ((EMACS_INT) (N) << INTTYPEBITS)
437 #define XSET(var, type, ptr) \
438 (eassert (XTYPE (XIL ((intptr_t) (ptr))) == 0), /* Check alignment. */ \
439 (var) = XIL ((type) | (intptr_t) (ptr)))
441 #define XPNTR(a) ((intptr_t) (XLI (a) & ~TYPEMASK))
442 #define XUNTAG(a, type) ((intptr_t) (XLI (a) - (type)))
444 #else /* not USE_LSB_TAG */
446 #define VALMASK VAL_MAX
448 #define XTYPE(a) ((enum Lisp_Type) ((EMACS_UINT) XLI (a) >> VALBITS))
450 /* For integers known to be positive, XFASTINT provides fast retrieval
451 and XSETFASTINT provides fast storage. This takes advantage of the
452 fact that Lisp integers have zero-bits in their tags. */
453 #define XFASTINT(a) (XLI (a) + 0)
454 #define XSETFASTINT(a, b) ((a) = XIL (b))
456 /* Extract the value of a Lisp_Object as a (un)signed integer. */
458 #define XINT(a) (XLI (a) << INTTYPEBITS >> INTTYPEBITS)
459 #define XUINT(a) ((EMACS_UINT) (XLI (a) & INTMASK))
460 #define make_number(N) XIL ((EMACS_INT) (N) & INTMASK)
462 #define XSET(var, type, ptr) \
463 ((var) = XIL ((EMACS_INT) ((EMACS_UINT) (type) << VALBITS) \
464 + ((intptr_t) (ptr) & VALMASK)))
466 #if DATA_SEG_BITS
467 /* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
468 which were stored in a Lisp_Object */
469 #define XPNTR(a) ((uintptr_t) ((XLI (a) & VALMASK)) | DATA_SEG_BITS))
470 #else
471 #define XPNTR(a) ((uintptr_t) (XLI (a) & VALMASK))
472 #endif
474 #endif /* not USE_LSB_TAG */
476 /* For integers known to be positive, XFASTINT sometimes provides
477 faster retrieval and XSETFASTINT provides faster storage.
478 If not, fallback on the non-accelerated path. */
479 #ifndef XFASTINT
480 # define XFASTINT(a) (XINT (a))
481 # define XSETFASTINT(a, b) (XSETINT (a, b))
482 #endif
484 /* Extract the pointer value of the Lisp object A, under the
485 assumption that A's type is TYPE. This is a fallback
486 implementation if nothing faster is available. */
487 #ifndef XUNTAG
488 # define XUNTAG(a, type) XPNTR (a)
489 #endif
491 #define EQ(x, y) (XHASH (x) == XHASH (y))
493 /* Largest and smallest representable fixnum values. These are the C
494 values. */
495 #define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
496 #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
498 /* Value is non-zero if I doesn't fit into a Lisp fixnum. It is
499 written this way so that it also works if I is of unsigned
500 type or if I is a NaN. */
502 #define FIXNUM_OVERFLOW_P(i) \
503 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
505 static inline ptrdiff_t
506 clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
508 return num < lower ? lower : num <= upper ? num : upper;
511 /* Extract a value or address from a Lisp_Object. */
513 #define XCONS(a) (eassert (CONSP (a)), \
514 (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
515 #define XVECTOR(a) (eassert (VECTORLIKEP (a)), \
516 (struct Lisp_Vector *) XUNTAG (a, Lisp_Vectorlike))
517 #define XSTRING(a) (eassert (STRINGP (a)), \
518 (struct Lisp_String *) XUNTAG (a, Lisp_String))
519 #define XSYMBOL(a) (eassert (SYMBOLP (a)), \
520 (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol))
521 #define XFLOAT(a) (eassert (FLOATP (a)), \
522 (struct Lisp_Float *) XUNTAG (a, Lisp_Float))
524 /* Misc types. */
526 #define XMISC(a) ((union Lisp_Misc *) XUNTAG (a, Lisp_Misc))
527 #define XMISCANY(a) (eassert (MISCP (a)), &(XMISC (a)->u_any))
528 #define XMISCTYPE(a) (XMISCANY (a)->type)
529 #define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker))
530 #define XOVERLAY(a) (eassert (OVERLAYP (a)), &(XMISC (a)->u_overlay))
531 #define XSAVE_VALUE(a) (eassert (SAVE_VALUEP (a)), &(XMISC (a)->u_save_value))
533 /* Forwarding object types. */
535 #define XFWDTYPE(a) (a->u_intfwd.type)
536 #define XINTFWD(a) (eassert (INTFWDP (a)), &((a)->u_intfwd))
537 #define XBOOLFWD(a) (eassert (BOOLFWDP (a)), &((a)->u_boolfwd))
538 #define XOBJFWD(a) (eassert (OBJFWDP (a)), &((a)->u_objfwd))
539 #define XBUFFER_OBJFWD(a) \
540 (eassert (BUFFER_OBJFWDP (a)), &((a)->u_buffer_objfwd))
541 #define XKBOARD_OBJFWD(a) \
542 (eassert (KBOARD_OBJFWDP (a)), &((a)->u_kboard_objfwd))
544 /* Pseudovector types. */
546 #define XPROCESS(a) (eassert (PROCESSP (a)), \
547 (struct Lisp_Process *) XUNTAG (a, Lisp_Vectorlike))
548 #define XWINDOW(a) (eassert (WINDOWP (a)), \
549 (struct window *) XUNTAG (a, Lisp_Vectorlike))
550 #define XTERMINAL(a) (eassert (TERMINALP (a)), \
551 (struct terminal *) XUNTAG (a, Lisp_Vectorlike))
552 #define XSUBR(a) (eassert (SUBRP (a)), \
553 (struct Lisp_Subr *) XUNTAG (a, Lisp_Vectorlike))
554 #define XBUFFER(a) (eassert (BUFFERP (a)), \
555 (struct buffer *) XUNTAG (a, Lisp_Vectorlike))
556 #define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), \
557 (struct Lisp_Char_Table *) XUNTAG (a, Lisp_Vectorlike))
558 #define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), \
559 ((struct Lisp_Sub_Char_Table *) \
560 XUNTAG (a, Lisp_Vectorlike)))
561 #define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), \
562 ((struct Lisp_Bool_Vector *) \
563 XUNTAG (a, Lisp_Vectorlike)))
565 /* Construct a Lisp_Object from a value or address. */
567 #define XSETINT(a, b) (a) = make_number (b)
568 #define XSETCONS(a, b) XSET (a, Lisp_Cons, b)
569 #define XSETVECTOR(a, b) XSET (a, Lisp_Vectorlike, b)
570 #define XSETSTRING(a, b) XSET (a, Lisp_String, b)
571 #define XSETSYMBOL(a, b) XSET (a, Lisp_Symbol, b)
572 #define XSETFLOAT(a, b) XSET (a, Lisp_Float, b)
574 /* Misc types. */
576 #define XSETMISC(a, b) XSET (a, Lisp_Misc, b)
577 #define XSETMARKER(a, b) (XSETMISC (a, b), XMISCTYPE (a) = Lisp_Misc_Marker)
579 /* Pseudovector types. */
581 #define XSETPVECTYPE(v, code) XSETTYPED_PVECTYPE (v, header.size, code)
582 #define XSETTYPED_PVECTYPE(v, size_member, code) \
583 ((v)->size_member |= PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_SIZE_BITS))
584 #define XSETPVECTYPESIZE(v, code, sizeval) \
585 ((v)->header.size = (PSEUDOVECTOR_FLAG \
586 | ((code) << PSEUDOVECTOR_SIZE_BITS) \
587 | (sizeval)))
589 /* The cast to struct vectorlike_header * avoids aliasing issues. */
590 #define XSETPSEUDOVECTOR(a, b, code) \
591 XSETTYPED_PSEUDOVECTOR (a, b, \
592 (((struct vectorlike_header *) \
593 XUNTAG (a, Lisp_Vectorlike)) \
594 ->size), \
595 code)
596 #define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \
597 (XSETVECTOR (a, b), \
598 eassert ((size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) \
599 == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_SIZE_BITS))))
601 #define XSETWINDOW_CONFIGURATION(a, b) \
602 (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW_CONFIGURATION))
603 #define XSETPROCESS(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_PROCESS))
604 #define XSETWINDOW(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW))
605 #define XSETTERMINAL(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_TERMINAL))
606 /* XSETSUBR is special since Lisp_Subr lacks struct vectorlike_header. */
607 #define XSETSUBR(a, b) \
608 XSETTYPED_PSEUDOVECTOR (a, b, XSUBR (a)->size, PVEC_SUBR)
609 #define XSETCOMPILED(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_COMPILED))
610 #define XSETBUFFER(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BUFFER))
611 #define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE))
612 #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
613 #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
615 /* Convenience macros for dealing with Lisp arrays. */
617 #define AREF(ARRAY, IDX) XVECTOR ((ARRAY))->contents[IDX]
618 #define ASIZE(ARRAY) XVECTOR ((ARRAY))->header.size
619 /* The IDX==IDX tries to detect when the macro argument is side-effecting. */
620 #define ASET(ARRAY, IDX, VAL) \
621 (eassert ((IDX) == (IDX)), \
622 eassert ((IDX) >= 0 && (IDX) < ASIZE (ARRAY)), \
623 AREF ((ARRAY), (IDX)) = (VAL))
625 /* Convenience macros for dealing with Lisp strings. */
627 #define SDATA(string) (XSTRING (string)->data + 0)
628 #define SREF(string, index) (SDATA (string)[index] + 0)
629 #define SSET(string, index, new) (SDATA (string)[index] = (new))
630 #define SCHARS(string) (XSTRING (string)->size + 0)
631 #define SBYTES(string) (STRING_BYTES (XSTRING (string)) + 0)
633 /* Avoid "differ in sign" warnings. */
634 #define SSDATA(x) ((char *) SDATA (x))
636 #define STRING_SET_CHARS(string, newsize) \
637 (XSTRING (string)->size = (newsize))
639 #define STRING_COPYIN(string, index, new, count) \
640 memcpy (SDATA (string) + index, new, count)
642 /* Type checking. */
644 #define CHECK_TYPE(ok, Qxxxp, x) \
645 do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0)
649 /* See the macros in intervals.h. */
651 typedef struct interval *INTERVAL;
653 /* Complain if object is not string or buffer type */
654 #define CHECK_STRING_OR_BUFFER(x) \
655 CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x)
658 /* In a cons, the markbit of the car is the gc mark bit */
660 struct Lisp_Cons
662 /* Please do not use the names of these elements in code other
663 than the core lisp implementation. Use XCAR and XCDR below. */
664 #ifdef HIDE_LISP_IMPLEMENTATION
665 Lisp_Object car_;
666 union
668 Lisp_Object cdr_;
669 struct Lisp_Cons *chain;
670 } u;
671 #else
672 Lisp_Object car;
673 union
675 Lisp_Object cdr;
676 struct Lisp_Cons *chain;
677 } u;
678 #endif
681 /* Take the car or cdr of something known to be a cons cell. */
682 /* The _AS_LVALUE macros shouldn't be used outside of the minimal set
683 of code that has to know what a cons cell looks like. Other code not
684 part of the basic lisp implementation should assume that the car and cdr
685 fields are not accessible as lvalues. (What if we want to switch to
686 a copying collector someday? Cached cons cell field addresses may be
687 invalidated at arbitrary points.) */
688 #ifdef HIDE_LISP_IMPLEMENTATION
689 #define XCAR_AS_LVALUE(c) (XCONS ((c))->car_)
690 #define XCDR_AS_LVALUE(c) (XCONS ((c))->u.cdr_)
691 #else
692 #define XCAR_AS_LVALUE(c) (XCONS ((c))->car)
693 #define XCDR_AS_LVALUE(c) (XCONS ((c))->u.cdr)
694 #endif
696 /* Use these from normal code. */
697 #define XCAR(c) LISP_MAKE_RVALUE (XCAR_AS_LVALUE (c))
698 #define XCDR(c) LISP_MAKE_RVALUE (XCDR_AS_LVALUE (c))
700 /* Use these to set the fields of a cons cell.
702 Note that both arguments may refer to the same object, so 'n'
703 should not be read after 'c' is first modified. Also, neither
704 argument should be evaluated more than once; side effects are
705 especially common in the second argument. */
706 #define XSETCAR(c,n) (XCAR_AS_LVALUE (c) = (n))
707 #define XSETCDR(c,n) (XCDR_AS_LVALUE (c) = (n))
709 /* Take the car or cdr of something whose type is not known. */
710 #define CAR(c) \
711 (CONSP ((c)) ? XCAR ((c)) \
712 : NILP ((c)) ? Qnil \
713 : wrong_type_argument (Qlistp, (c)))
715 #define CDR(c) \
716 (CONSP ((c)) ? XCDR ((c)) \
717 : NILP ((c)) ? Qnil \
718 : wrong_type_argument (Qlistp, (c)))
720 /* Take the car or cdr of something whose type is not known. */
721 #define CAR_SAFE(c) \
722 (CONSP ((c)) ? XCAR ((c)) : Qnil)
724 #define CDR_SAFE(c) \
725 (CONSP ((c)) ? XCDR ((c)) : Qnil)
727 /* Nonzero if STR is a multibyte string. */
728 #define STRING_MULTIBYTE(STR) \
729 (XSTRING (STR)->size_byte >= 0)
731 /* Return the length in bytes of STR. */
733 #ifdef GC_CHECK_STRING_BYTES
735 struct Lisp_String;
736 extern ptrdiff_t string_bytes (struct Lisp_String *);
737 #define STRING_BYTES(S) string_bytes ((S))
739 #else /* not GC_CHECK_STRING_BYTES */
741 #define STRING_BYTES(STR) \
742 ((STR)->size_byte < 0 ? (STR)->size : (STR)->size_byte)
744 #endif /* not GC_CHECK_STRING_BYTES */
746 /* An upper bound on the number of bytes in a Lisp string, not
747 counting the terminating null. This a tight enough bound to
748 prevent integer overflow errors that would otherwise occur during
749 string size calculations. A string cannot contain more bytes than
750 a fixnum can represent, nor can it be so long that C pointer
751 arithmetic stops working on the string plus its terminating null.
752 Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
753 may be a bit smaller than STRING_BYTES_BOUND, calculating it here
754 would expose alloc.c internal details that we'd rather keep
755 private. The cast to ptrdiff_t ensures that STRING_BYTES_BOUND is
756 signed. */
757 #define STRING_BYTES_BOUND \
758 min (MOST_POSITIVE_FIXNUM, (ptrdiff_t) min (SIZE_MAX, PTRDIFF_MAX) - 1)
760 /* Mark STR as a unibyte string. */
761 #define STRING_SET_UNIBYTE(STR) \
762 do { if (EQ (STR, empty_multibyte_string)) \
763 (STR) = empty_unibyte_string; \
764 else XSTRING (STR)->size_byte = -1; } while (0)
766 /* Mark STR as a multibyte string. Assure that STR contains only
767 ASCII characters in advance. */
768 #define STRING_SET_MULTIBYTE(STR) \
769 do { if (EQ (STR, empty_unibyte_string)) \
770 (STR) = empty_multibyte_string; \
771 else XSTRING (STR)->size_byte = XSTRING (STR)->size; } while (0)
773 /* Get text properties. */
774 #define STRING_INTERVALS(STR) (XSTRING (STR)->intervals + 0)
776 /* Set text properties. */
777 #define STRING_SET_INTERVALS(STR, INT) (XSTRING (STR)->intervals = (INT))
779 /* In a string or vector, the sign bit of the `size' is the gc mark bit. */
781 struct Lisp_String
783 ptrdiff_t size;
784 ptrdiff_t size_byte;
785 INTERVAL intervals; /* Text properties in this string. */
786 unsigned char *data;
789 /* Header of vector-like objects. This documents the layout constraints on
790 vectors and pseudovectors other than struct Lisp_Subr. It also prevents
791 compilers from being fooled by Emacs's type punning: the XSETPSEUDOVECTOR
792 and PSEUDOVECTORP macros cast their pointers to struct vectorlike_header *,
793 because when two such pointers potentially alias, a compiler won't
794 incorrectly reorder loads and stores to their size fields. See
795 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */
796 struct vectorlike_header
798 /* This field contains various pieces of information:
799 - The MSB (ARRAY_MARK_FLAG) holds the gcmarkbit.
800 - The next bit (PSEUDOVECTOR_FLAG) indicates whether this is a plain
801 vector (0) or a pseudovector (1).
802 - If PSEUDOVECTOR_FLAG is 0, the rest holds the size (number
803 of slots) of the vector.
804 - If PSEUDOVECTOR_FLAG is 1, the rest is subdivided into
805 a "pvec type" tag held in PVEC_TYPE_MASK and a size held in the lowest
806 PSEUDOVECTOR_SIZE_BITS. That size normally indicates the number of
807 Lisp_Object slots at the beginning of the object that need to be
808 traced by the GC, tho some types use it slightly differently.
809 - E.g. if the pvec type is PVEC_FREE it means this is an unallocated
810 vector on a free-list and PSEUDOVECTOR_SIZE_BITS indicates its size
811 in bytes. */
812 ptrdiff_t size;
814 /* When the vector is allocated from a vector block, NBYTES is used
815 if the vector is not on a free list, and VECTOR is used otherwise.
816 For large vector-like objects, BUFFER or VECTOR is used as a pointer
817 to the next vector-like object. It is generally a buffer or a
818 Lisp_Vector alias, so for convenience it is a union instead of a
819 pointer: this way, one can write P->next.vector instead of ((struct
820 Lisp_Vector *) P->next). */
821 union {
822 /* This is only needed for small vectors that are not free because the
823 `size' field only gives us the number of Lisp_Object slots, whereas we
824 need to know the total size, including non-Lisp_Object data.
825 FIXME: figure out a way to store this info elsewhere so we can
826 finally get rid of this extra word of overhead. */
827 ptrdiff_t nbytes;
828 struct buffer *buffer;
829 /* FIXME: This can be removed: For large vectors, this field could be
830 placed *before* the vector itself. And for small vectors on a free
831 list, this field could be stored in the vector's bytes, since the
832 empty vector is handled specially anyway. */
833 struct Lisp_Vector *vector;
834 } next;
837 struct Lisp_Vector
839 struct vectorlike_header header;
840 Lisp_Object contents[1];
843 /* If a struct is made to look like a vector, this macro returns the length
844 of the shortest vector that would hold that struct. */
845 #define VECSIZE(type) ((sizeof (type) \
846 - offsetof (struct Lisp_Vector, contents[0]) \
847 + sizeof (Lisp_Object) - 1) /* Round up. */ \
848 / sizeof (Lisp_Object))
850 /* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
851 at the end and we need to compute the number of Lisp_Object fields (the
852 ones that the GC needs to trace). */
853 #define PSEUDOVECSIZE(type, nonlispfield) \
854 ((offsetof (type, nonlispfield) - offsetof (struct Lisp_Vector, contents[0])) \
855 / sizeof (Lisp_Object))
857 /* A char-table is a kind of vectorlike, with contents are like a
858 vector but with a few other slots. For some purposes, it makes
859 sense to handle a char-table with type struct Lisp_Vector. An
860 element of a char table can be any Lisp objects, but if it is a sub
861 char-table, we treat it a table that contains information of a
862 specific range of characters. A sub char-table has the same
863 structure as a vector. A sub char table appears only in an element
864 of a char-table, and there's no way to access it directly from
865 Emacs Lisp program. */
867 /* This is the number of slots that every char table must have. This
868 counts the ordinary slots and the top, defalt, parent, and purpose
869 slots. */
870 #define CHAR_TABLE_STANDARD_SLOTS (VECSIZE (struct Lisp_Char_Table) - 1)
872 /* Return the number of "extra" slots in the char table CT. */
874 #define CHAR_TABLE_EXTRA_SLOTS(CT) \
875 (((CT)->header.size & PSEUDOVECTOR_SIZE_MASK) - CHAR_TABLE_STANDARD_SLOTS)
877 #ifdef __GNUC__
879 #define CHAR_TABLE_REF_ASCII(CT, IDX) \
880 ({struct Lisp_Char_Table *_tbl = NULL; \
881 Lisp_Object _val; \
882 do { \
883 _tbl = _tbl ? XCHAR_TABLE (_tbl->parent) : XCHAR_TABLE (CT); \
884 _val = (! SUB_CHAR_TABLE_P (_tbl->ascii) ? _tbl->ascii \
885 : XSUB_CHAR_TABLE (_tbl->ascii)->contents[IDX]); \
886 if (NILP (_val)) \
887 _val = _tbl->defalt; \
888 } while (NILP (_val) && ! NILP (_tbl->parent)); \
889 _val; })
891 #else /* not __GNUC__ */
893 #define CHAR_TABLE_REF_ASCII(CT, IDX) \
894 (! NILP (XCHAR_TABLE (CT)->ascii) \
895 ? (! SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii) \
896 ? XCHAR_TABLE (CT)->ascii \
897 : ! NILP (XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX]) \
898 ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] \
899 : char_table_ref ((CT), (IDX))) \
900 : char_table_ref ((CT), (IDX)))
902 #endif /* not __GNUC__ */
904 /* Compute A OP B, using the unsigned comparison operator OP. A and B
905 should be integer expressions. This is not the same as
906 mathematical comparison; for example, UNSIGNED_CMP (0, <, -1)
907 returns 1. For efficiency, prefer plain unsigned comparison if A
908 and B's sizes both fit (after integer promotion). */
909 #define UNSIGNED_CMP(a, op, b) \
910 (max (sizeof ((a) + 0), sizeof ((b) + 0)) <= sizeof (unsigned) \
911 ? ((a) + (unsigned) 0) op ((b) + (unsigned) 0) \
912 : ((a) + (uintmax_t) 0) op ((b) + (uintmax_t) 0))
914 /* Nonzero iff C is an ASCII character. */
915 #define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
917 /* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
918 characters. Do not check validity of CT. */
919 #define CHAR_TABLE_REF(CT, IDX) \
920 (ASCII_CHAR_P (IDX) ? CHAR_TABLE_REF_ASCII ((CT), (IDX)) \
921 : char_table_ref ((CT), (IDX)))
923 /* Almost equivalent to Faref (CT, IDX). However, if the result is
924 not a character, return IDX.
926 For these characters, do not check validity of CT
927 and do not follow parent. */
928 #define CHAR_TABLE_TRANSLATE(CT, IDX) \
929 char_table_translate (CT, IDX)
931 /* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
932 8-bit European characters. Do not check validity of CT. */
933 #define CHAR_TABLE_SET(CT, IDX, VAL) \
934 (ASCII_CHAR_P (IDX) && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii) \
935 ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] = VAL \
936 : char_table_set (CT, IDX, VAL))
938 #define CHARTAB_SIZE_BITS_0 6
939 #define CHARTAB_SIZE_BITS_1 4
940 #define CHARTAB_SIZE_BITS_2 5
941 #define CHARTAB_SIZE_BITS_3 7
943 extern const int chartab_size[4];
945 struct Lisp_Sub_Char_Table;
947 struct Lisp_Char_Table
949 /* HEADER.SIZE is the vector's size field, which also holds the
950 pseudovector type information. It holds the size, too.
951 The size counts the defalt, parent, purpose, ascii,
952 contents, and extras slots. */
953 struct vectorlike_header header;
955 /* This holds a default value,
956 which is used whenever the value for a specific character is nil. */
957 Lisp_Object defalt;
959 /* This points to another char table, which we inherit from when the
960 value for a specific character is nil. The `defalt' slot takes
961 precedence over this. */
962 Lisp_Object parent;
964 /* This is a symbol which says what kind of use this char-table is
965 meant for. */
966 Lisp_Object purpose;
968 /* The bottom sub char-table for characters of the range 0..127. It
969 is nil if none of ASCII character has a specific value. */
970 Lisp_Object ascii;
972 Lisp_Object contents[(1 << CHARTAB_SIZE_BITS_0)];
974 /* These hold additional data. It is a vector. */
975 Lisp_Object extras[1];
978 struct Lisp_Sub_Char_Table
980 /* HEADER.SIZE is the vector's size field, which also holds the
981 pseudovector type information. It holds the size, too. */
982 struct vectorlike_header header;
984 /* Depth of this sub char-table. It should be 1, 2, or 3. A sub
985 char-table of depth 1 contains 16 elements, and each element
986 covers 4096 (128*32) characters. A sub char-table of depth 2
987 contains 32 elements, and each element covers 128 characters. A
988 sub char-table of depth 3 contains 128 elements, and each element
989 is for one character. */
990 Lisp_Object depth;
992 /* Minimum character covered by the sub char-table. */
993 Lisp_Object min_char;
995 Lisp_Object contents[1];
998 /* A boolvector is a kind of vectorlike, with contents are like a string. */
999 struct Lisp_Bool_Vector
1001 /* HEADER.SIZE is the vector's size field. It doesn't have the real size,
1002 just the subtype information. */
1003 struct vectorlike_header header;
1004 /* This is the size in bits. */
1005 EMACS_INT size;
1006 /* This contains the actual bits, packed into bytes. */
1007 unsigned char data[1];
1010 /* This structure describes a built-in function.
1011 It is generated by the DEFUN macro only.
1012 defsubr makes it into a Lisp object.
1014 This type is treated in most respects as a pseudovector,
1015 but since we never dynamically allocate or free them,
1016 we don't need a struct vectorlike_header and its 'next' field. */
1018 struct Lisp_Subr
1020 ptrdiff_t size;
1021 union {
1022 Lisp_Object (*a0) (void);
1023 Lisp_Object (*a1) (Lisp_Object);
1024 Lisp_Object (*a2) (Lisp_Object, Lisp_Object);
1025 Lisp_Object (*a3) (Lisp_Object, Lisp_Object, Lisp_Object);
1026 Lisp_Object (*a4) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1027 Lisp_Object (*a5) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1028 Lisp_Object (*a6) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1029 Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1030 Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1031 Lisp_Object (*aUNEVALLED) (Lisp_Object args);
1032 Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
1033 } function;
1034 short min_args, max_args;
1035 const char *symbol_name;
1036 const char *intspec;
1037 const char *doc;
1041 /***********************************************************************
1042 Symbols
1043 ***********************************************************************/
1045 /* Interned state of a symbol. */
1047 enum symbol_interned
1049 SYMBOL_UNINTERNED = 0,
1050 SYMBOL_INTERNED = 1,
1051 SYMBOL_INTERNED_IN_INITIAL_OBARRAY = 2
1054 enum symbol_redirect
1056 SYMBOL_PLAINVAL = 4,
1057 SYMBOL_VARALIAS = 1,
1058 SYMBOL_LOCALIZED = 2,
1059 SYMBOL_FORWARDED = 3
1062 struct Lisp_Symbol
1064 unsigned gcmarkbit : 1;
1066 /* Indicates where the value can be found:
1067 0 : it's a plain var, the value is in the `value' field.
1068 1 : it's a varalias, the value is really in the `alias' symbol.
1069 2 : it's a localized var, the value is in the `blv' object.
1070 3 : it's a forwarding variable, the value is in `forward'. */
1071 ENUM_BF (symbol_redirect) redirect : 3;
1073 /* Non-zero means symbol is constant, i.e. changing its value
1074 should signal an error. If the value is 3, then the var
1075 can be changed, but only by `defconst'. */
1076 unsigned constant : 2;
1078 /* Interned state of the symbol. This is an enumerator from
1079 enum symbol_interned. */
1080 unsigned interned : 2;
1082 /* Non-zero means that this variable has been explicitly declared
1083 special (with `defvar' etc), and shouldn't be lexically bound. */
1084 unsigned declared_special : 1;
1086 /* The symbol's name, as a Lisp string.
1087 The name "xname" is used to intentionally break code referring to
1088 the old field "name" of type pointer to struct Lisp_String. */
1089 Lisp_Object xname;
1091 /* Value of the symbol or Qunbound if unbound. Which alternative of the
1092 union is used depends on the `redirect' field above. */
1093 union {
1094 Lisp_Object value;
1095 struct Lisp_Symbol *alias;
1096 struct Lisp_Buffer_Local_Value *blv;
1097 union Lisp_Fwd *fwd;
1098 } val;
1100 /* Function value of the symbol or Qunbound if not fboundp. */
1101 Lisp_Object function;
1103 /* The symbol's property list. */
1104 Lisp_Object plist;
1106 /* Next symbol in obarray bucket, if the symbol is interned. */
1107 struct Lisp_Symbol *next;
1110 /* Value is name of symbol. */
1112 #define SYMBOL_VAL(sym) \
1113 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value)
1114 #define SYMBOL_ALIAS(sym) \
1115 (eassert ((sym)->redirect == SYMBOL_VARALIAS), (sym)->val.alias)
1116 #define SYMBOL_BLV(sym) \
1117 (eassert ((sym)->redirect == SYMBOL_LOCALIZED), (sym)->val.blv)
1118 #define SYMBOL_FWD(sym) \
1119 (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd)
1120 #define SET_SYMBOL_VAL(sym, v) \
1121 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value = (v))
1122 #define SET_SYMBOL_ALIAS(sym, v) \
1123 (eassert ((sym)->redirect == SYMBOL_VARALIAS), (sym)->val.alias = (v))
1124 #define SET_SYMBOL_BLV(sym, v) \
1125 (eassert ((sym)->redirect == SYMBOL_LOCALIZED), (sym)->val.blv = (v))
1126 #define SET_SYMBOL_FWD(sym, v) \
1127 (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd = (v))
1129 #define SYMBOL_NAME(sym) \
1130 LISP_MAKE_RVALUE (XSYMBOL (sym)->xname)
1132 /* Value is non-zero if SYM is an interned symbol. */
1134 #define SYMBOL_INTERNED_P(sym) \
1135 (XSYMBOL (sym)->interned != SYMBOL_UNINTERNED)
1137 /* Value is non-zero if SYM is interned in initial_obarray. */
1139 #define SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P(sym) \
1140 (XSYMBOL (sym)->interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY)
1142 /* Value is non-zero if symbol is considered a constant, i.e. its
1143 value cannot be changed (there is an exception for keyword symbols,
1144 whose value can be set to the keyword symbol itself). */
1146 #define SYMBOL_CONSTANT_P(sym) XSYMBOL (sym)->constant
1148 #define DEFSYM(sym, name) \
1149 do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0)
1152 /***********************************************************************
1153 Hash Tables
1154 ***********************************************************************/
1156 /* The structure of a Lisp hash table. */
1158 struct Lisp_Hash_Table
1160 /* This is for Lisp; the hash table code does not refer to it. */
1161 struct vectorlike_header header;
1163 /* Function used to compare keys. */
1164 Lisp_Object test;
1166 /* Nil if table is non-weak. Otherwise a symbol describing the
1167 weakness of the table. */
1168 Lisp_Object weak;
1170 /* When the table is resized, and this is an integer, compute the
1171 new size by adding this to the old size. If a float, compute the
1172 new size by multiplying the old size with this factor. */
1173 Lisp_Object rehash_size;
1175 /* Resize hash table when number of entries/ table size is >= this
1176 ratio, a float. */
1177 Lisp_Object rehash_threshold;
1179 /* Vector of hash codes.. If hash[I] is nil, this means that that
1180 entry I is unused. */
1181 Lisp_Object hash;
1183 /* Vector used to chain entries. If entry I is free, next[I] is the
1184 entry number of the next free item. If entry I is non-free,
1185 next[I] is the index of the next entry in the collision chain. */
1186 Lisp_Object next;
1188 /* Index of first free entry in free list. */
1189 Lisp_Object next_free;
1191 /* Bucket vector. A non-nil entry is the index of the first item in
1192 a collision chain. This vector's size can be larger than the
1193 hash table size to reduce collisions. */
1194 Lisp_Object index;
1196 /* User-supplied hash function, or nil. */
1197 Lisp_Object user_hash_function;
1199 /* User-supplied key comparison function, or nil. */
1200 Lisp_Object user_cmp_function;
1202 /* Only the fields above are traced normally by the GC. The ones below
1203 `count' are special and are either ignored by the GC or traced in
1204 a special way (e.g. because of weakness). */
1206 /* Number of key/value entries in the table. */
1207 ptrdiff_t count;
1209 /* Vector of keys and values. The key of item I is found at index
1210 2 * I, the value is found at index 2 * I + 1.
1211 This is gc_marked specially if the table is weak. */
1212 Lisp_Object key_and_value;
1214 /* Next weak hash table if this is a weak hash table. The head
1215 of the list is in weak_hash_tables. */
1216 struct Lisp_Hash_Table *next_weak;
1218 /* C function to compare two keys. */
1219 int (*cmpfn) (struct Lisp_Hash_Table *,
1220 Lisp_Object, EMACS_UINT,
1221 Lisp_Object, EMACS_UINT);
1223 /* C function to compute hash code. */
1224 EMACS_UINT (*hashfn) (struct Lisp_Hash_Table *, Lisp_Object);
1228 #define XHASH_TABLE(OBJ) \
1229 ((struct Lisp_Hash_Table *) XUNTAG (OBJ, Lisp_Vectorlike))
1231 #define XSET_HASH_TABLE(VAR, PTR) \
1232 (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
1234 #define HASH_TABLE_P(OBJ) PSEUDOVECTORP (OBJ, PVEC_HASH_TABLE)
1236 #define CHECK_HASH_TABLE(x) \
1237 CHECK_TYPE (HASH_TABLE_P (x), Qhash_table_p, x)
1239 /* Value is the key part of entry IDX in hash table H. */
1241 #define HASH_KEY(H, IDX) AREF ((H)->key_and_value, 2 * (IDX))
1243 /* Value is the value part of entry IDX in hash table H. */
1245 #define HASH_VALUE(H, IDX) AREF ((H)->key_and_value, 2 * (IDX) + 1)
1247 /* Value is the index of the next entry following the one at IDX
1248 in hash table H. */
1250 #define HASH_NEXT(H, IDX) AREF ((H)->next, (IDX))
1252 /* Value is the hash code computed for entry IDX in hash table H. */
1254 #define HASH_HASH(H, IDX) AREF ((H)->hash, (IDX))
1256 /* Value is the index of the element in hash table H that is the
1257 start of the collision list at index IDX in the index vector of H. */
1259 #define HASH_INDEX(H, IDX) AREF ((H)->index, (IDX))
1261 /* Value is the size of hash table H. */
1263 #define HASH_TABLE_SIZE(H) ASIZE ((H)->next)
1265 /* Default size for hash tables if not specified. */
1267 #define DEFAULT_HASH_SIZE 65
1269 /* Default threshold specifying when to resize a hash table. The
1270 value gives the ratio of current entries in the hash table and the
1271 size of the hash table. */
1273 #define DEFAULT_REHASH_THRESHOLD 0.8
1275 /* Default factor by which to increase the size of a hash table. */
1277 #define DEFAULT_REHASH_SIZE 1.5
1280 /* These structures are used for various misc types. */
1282 struct Lisp_Misc_Any /* Supertype of all Misc types. */
1284 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_??? */
1285 unsigned gcmarkbit : 1;
1286 int spacer : 15;
1289 struct Lisp_Marker
1291 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Marker */
1292 unsigned gcmarkbit : 1;
1293 int spacer : 13;
1294 /* This flag is temporarily used in the functions
1295 decode/encode_coding_object to record that the marker position
1296 must be adjusted after the conversion. */
1297 unsigned int need_adjustment : 1;
1298 /* 1 means normal insertion at the marker's position
1299 leaves the marker after the inserted text. */
1300 unsigned int insertion_type : 1;
1301 /* This is the buffer that the marker points into, or 0 if it points nowhere.
1302 Note: a chain of markers can contain markers pointing into different
1303 buffers (the chain is per buffer_text rather than per buffer, so it's
1304 shared between indirect buffers). */
1305 /* This is used for (other than NULL-checking):
1306 - Fmarker_buffer
1307 - Fset_marker: check eq(oldbuf, newbuf) to avoid unchain+rechain.
1308 - unchain_marker: to find the list from which to unchain.
1309 - Fkill_buffer: to only unchain the markers of current indirect buffer.
1311 struct buffer *buffer;
1313 /* The remaining fields are meaningless in a marker that
1314 does not point anywhere. */
1316 /* For markers that point somewhere,
1317 this is used to chain of all the markers in a given buffer. */
1318 /* We could remove it and use an array in buffer_text instead.
1319 That would also allow to preserve it ordered. */
1320 struct Lisp_Marker *next;
1321 /* This is the char position where the marker points. */
1322 ptrdiff_t charpos;
1323 /* This is the byte position.
1324 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
1325 used to implement the functionality of markers, but rather to (ab)use
1326 markers as a cache for char<->byte mappings). */
1327 ptrdiff_t bytepos;
1330 /* START and END are markers in the overlay's buffer, and
1331 PLIST is the overlay's property list. */
1332 struct Lisp_Overlay
1333 /* An overlay's real data content is:
1334 - plist
1335 - buffer (really there are two buffer pointers, one per marker,
1336 and both points to the same buffer)
1337 - insertion type of both ends (per-marker fields)
1338 - start & start byte (of start marker)
1339 - end & end byte (of end marker)
1340 - next (singly linked list of overlays)
1341 - next fields of start and end markers (singly linked list of markers).
1342 I.e. 9words plus 2 bits, 3words of which are for external linked lists.
1345 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Overlay */
1346 unsigned gcmarkbit : 1;
1347 int spacer : 15;
1348 struct Lisp_Overlay *next;
1349 Lisp_Object start, end, plist;
1352 /* Hold a C pointer for later use.
1353 This type of object is used in the arg to record_unwind_protect. */
1354 struct Lisp_Save_Value
1356 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */
1357 unsigned gcmarkbit : 1;
1358 int spacer : 14;
1359 /* If DOGC is set, POINTER is the address of a memory
1360 area containing INTEGER potential Lisp_Objects. */
1361 unsigned int dogc : 1;
1362 void *pointer;
1363 ptrdiff_t integer;
1367 /* A miscellaneous object, when it's on the free list. */
1368 struct Lisp_Free
1370 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Free */
1371 unsigned gcmarkbit : 1;
1372 int spacer : 15;
1373 union Lisp_Misc *chain;
1376 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
1377 It uses one of these struct subtypes to get the type field. */
1379 union Lisp_Misc
1381 struct Lisp_Misc_Any u_any; /* Supertype of all Misc types. */
1382 struct Lisp_Free u_free;
1383 struct Lisp_Marker u_marker;
1384 struct Lisp_Overlay u_overlay;
1385 struct Lisp_Save_Value u_save_value;
1388 /* Forwarding pointer to an int variable.
1389 This is allowed only in the value cell of a symbol,
1390 and it means that the symbol's value really lives in the
1391 specified int variable. */
1392 struct Lisp_Intfwd
1394 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Int */
1395 EMACS_INT *intvar;
1398 /* Boolean forwarding pointer to an int variable.
1399 This is like Lisp_Intfwd except that the ostensible
1400 "value" of the symbol is t if the int variable is nonzero,
1401 nil if it is zero. */
1402 struct Lisp_Boolfwd
1404 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Bool */
1405 int *boolvar;
1408 /* Forwarding pointer to a Lisp_Object variable.
1409 This is allowed only in the value cell of a symbol,
1410 and it means that the symbol's value really lives in the
1411 specified variable. */
1412 struct Lisp_Objfwd
1414 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Obj */
1415 Lisp_Object *objvar;
1418 /* Like Lisp_Objfwd except that value lives in a slot in the
1419 current buffer. Value is byte index of slot within buffer. */
1420 struct Lisp_Buffer_Objfwd
1422 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Buffer_Obj */
1423 int offset;
1424 Lisp_Object slottype; /* Qnil, Lisp_Int, Lisp_Symbol, or Lisp_String. */
1427 /* struct Lisp_Buffer_Local_Value is used in a symbol value cell when
1428 the symbol has buffer-local or frame-local bindings. (Exception:
1429 some buffer-local variables are built-in, with their values stored
1430 in the buffer structure itself. They are handled differently,
1431 using struct Lisp_Buffer_Objfwd.)
1433 The `realvalue' slot holds the variable's current value, or a
1434 forwarding pointer to where that value is kept. This value is the
1435 one that corresponds to the loaded binding. To read or set the
1436 variable, you must first make sure the right binding is loaded;
1437 then you can access the value in (or through) `realvalue'.
1439 `buffer' and `frame' are the buffer and frame for which the loaded
1440 binding was found. If those have changed, to make sure the right
1441 binding is loaded it is necessary to find which binding goes with
1442 the current buffer and selected frame, then load it. To load it,
1443 first unload the previous binding, then copy the value of the new
1444 binding into `realvalue' (or through it). Also update
1445 LOADED-BINDING to point to the newly loaded binding.
1447 `local_if_set' indicates that merely setting the variable creates a
1448 local binding for the current buffer. Otherwise the latter, setting
1449 the variable does not do that; only make-local-variable does that. */
1451 struct Lisp_Buffer_Local_Value
1453 /* 1 means that merely setting the variable creates a local
1454 binding for the current buffer. */
1455 unsigned int local_if_set : 1;
1456 /* 1 means this variable can have frame-local bindings, otherwise, it is
1457 can have buffer-local bindings. The two cannot be combined. */
1458 unsigned int frame_local : 1;
1459 /* 1 means that the binding now loaded was found.
1460 Presumably equivalent to (defcell!=valcell). */
1461 unsigned int found : 1;
1462 /* If non-NULL, a forwarding to the C var where it should also be set. */
1463 union Lisp_Fwd *fwd; /* Should never be (Buffer|Kboard)_Objfwd. */
1464 /* The buffer or frame for which the loaded binding was found. */
1465 Lisp_Object where;
1466 /* A cons cell that holds the default value. It has the form
1467 (SYMBOL . DEFAULT-VALUE). */
1468 Lisp_Object defcell;
1469 /* The cons cell from `where's parameter alist.
1470 It always has the form (SYMBOL . VALUE)
1471 Note that if `forward' is non-nil, VALUE may be out of date.
1472 Also if the currently loaded binding is the default binding, then
1473 this is `eq'ual to defcell. */
1474 Lisp_Object valcell;
1477 #define BLV_FOUND(blv) \
1478 (eassert ((blv)->found == !EQ ((blv)->defcell, (blv)->valcell)), (blv)->found)
1479 #define SET_BLV_FOUND(blv, v) \
1480 (eassert ((v) == !EQ ((blv)->defcell, (blv)->valcell)), (blv)->found = (v))
1482 #define BLV_VALUE(blv) (XCDR ((blv)->valcell))
1483 #define SET_BLV_VALUE(blv, v) (XSETCDR ((blv)->valcell, v))
1485 /* Like Lisp_Objfwd except that value lives in a slot in the
1486 current kboard. */
1487 struct Lisp_Kboard_Objfwd
1489 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Kboard_Obj */
1490 int offset;
1493 union Lisp_Fwd
1495 struct Lisp_Intfwd u_intfwd;
1496 struct Lisp_Boolfwd u_boolfwd;
1497 struct Lisp_Objfwd u_objfwd;
1498 struct Lisp_Buffer_Objfwd u_buffer_objfwd;
1499 struct Lisp_Kboard_Objfwd u_kboard_objfwd;
1502 /* Lisp floating point type. */
1503 struct Lisp_Float
1505 union
1507 #ifdef HIDE_LISP_IMPLEMENTATION
1508 double data_;
1509 #else
1510 double data;
1511 #endif
1512 struct Lisp_Float *chain;
1513 } u;
1516 #ifdef HIDE_LISP_IMPLEMENTATION
1517 #define XFLOAT_DATA(f) (0 ? XFLOAT (f)->u.data_ : XFLOAT (f)->u.data_)
1518 #else
1519 #define XFLOAT_DATA(f) (0 ? XFLOAT (f)->u.data : XFLOAT (f)->u.data)
1520 /* This should be used only in alloc.c, which always disables
1521 HIDE_LISP_IMPLEMENTATION. */
1522 #define XFLOAT_INIT(f,n) (XFLOAT (f)->u.data = (n))
1523 #endif
1525 /* A character, declared with the following typedef, is a member
1526 of some character set associated with the current buffer. */
1527 #ifndef _UCHAR_T /* Protect against something in ctab.h on AIX. */
1528 #define _UCHAR_T
1529 typedef unsigned char UCHAR;
1530 #endif
1532 /* Meanings of slots in a Lisp_Compiled: */
1534 #define COMPILED_ARGLIST 0
1535 #define COMPILED_BYTECODE 1
1536 #define COMPILED_CONSTANTS 2
1537 #define COMPILED_STACK_DEPTH 3
1538 #define COMPILED_DOC_STRING 4
1539 #define COMPILED_INTERACTIVE 5
1541 /* Flag bits in a character. These also get used in termhooks.h.
1542 Richard Stallman <rms@gnu.ai.mit.edu> thinks that MULE
1543 (MUlti-Lingual Emacs) might need 22 bits for the character value
1544 itself, so we probably shouldn't use any bits lower than 0x0400000. */
1545 #define CHAR_ALT (0x0400000)
1546 #define CHAR_SUPER (0x0800000)
1547 #define CHAR_HYPER (0x1000000)
1548 #define CHAR_SHIFT (0x2000000)
1549 #define CHAR_CTL (0x4000000)
1550 #define CHAR_META (0x8000000)
1552 #define CHAR_MODIFIER_MASK \
1553 (CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META)
1556 /* Actually, the current Emacs uses 22 bits for the character value
1557 itself. */
1558 #define CHARACTERBITS 22
1561 /* The glyph datatype, used to represent characters on the display.
1562 It consists of a char code and a face id. */
1564 typedef struct {
1565 int ch;
1566 int face_id;
1567 } GLYPH;
1569 /* Return a glyph's character code. */
1570 #define GLYPH_CHAR(glyph) ((glyph).ch)
1572 /* Return a glyph's face ID. */
1573 #define GLYPH_FACE(glyph) ((glyph).face_id)
1575 #define SET_GLYPH_CHAR(glyph, char) ((glyph).ch = (char))
1576 #define SET_GLYPH_FACE(glyph, face) ((glyph).face_id = (face))
1577 #define SET_GLYPH(glyph, char, face) ((glyph).ch = (char), (glyph).face_id = (face))
1579 /* Return 1 if GLYPH contains valid character code. */
1580 #define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph))
1583 /* Glyph Code from a display vector may either be an integer which
1584 encodes a char code in the lower CHARACTERBITS bits and a (very small)
1585 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */
1587 #define GLYPH_CODE_P(gc) \
1588 (CONSP (gc) \
1589 ? (CHARACTERP (XCAR (gc)) \
1590 && RANGED_INTEGERP (0, XCDR (gc), MAX_FACE_ID)) \
1591 : (RANGED_INTEGERP \
1592 (0, gc, \
1593 (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS \
1594 ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR \
1595 : TYPE_MAXIMUM (EMACS_INT)))))
1597 /* The following are valid only if GLYPH_CODE_P (gc). */
1599 #define GLYPH_CODE_CHAR(gc) \
1600 (CONSP (gc) ? XINT (XCAR (gc)) : XINT (gc) & ((1 << CHARACTERBITS) - 1))
1602 #define GLYPH_CODE_FACE(gc) \
1603 (CONSP (gc) ? XINT (XCDR (gc)) : XINT (gc) >> CHARACTERBITS)
1605 #define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \
1606 do \
1608 if (CONSP (gc)) \
1609 SET_GLYPH (glyph, XINT (XCAR (gc)), XINT (XCDR (gc))); \
1610 else \
1611 SET_GLYPH (glyph, (XINT (gc) & ((1 << CHARACTERBITS)-1)), \
1612 (XINT (gc) >> CHARACTERBITS)); \
1614 while (0)
1616 /* The ID of the mode line highlighting face. */
1617 #define GLYPH_MODE_LINE_FACE 1
1619 /* Structure to hold mouse highlight data. This is here because other
1620 header files need it for defining struct x_output etc. */
1621 typedef struct {
1622 /* These variables describe the range of text currently shown in its
1623 mouse-face, together with the window they apply to. As long as
1624 the mouse stays within this range, we need not redraw anything on
1625 its account. Rows and columns are glyph matrix positions in
1626 MOUSE_FACE_WINDOW. */
1627 int mouse_face_beg_row, mouse_face_beg_col;
1628 int mouse_face_beg_x, mouse_face_beg_y;
1629 int mouse_face_end_row, mouse_face_end_col;
1630 int mouse_face_end_x, mouse_face_end_y;
1631 int mouse_face_past_end;
1632 Lisp_Object mouse_face_window;
1633 int mouse_face_face_id;
1634 Lisp_Object mouse_face_overlay;
1636 /* 1 if a mouse motion event came and we didn't handle it right away because
1637 gc was in progress. */
1638 int mouse_face_deferred_gc;
1640 /* FRAME and X, Y position of mouse when last checked for
1641 highlighting. X and Y can be negative or out of range for the frame. */
1642 struct frame *mouse_face_mouse_frame;
1643 int mouse_face_mouse_x, mouse_face_mouse_y;
1645 /* Nonzero means defer mouse-motion highlighting. */
1646 int mouse_face_defer;
1648 /* Nonzero means that the mouse highlight should not be shown. */
1649 int mouse_face_hidden;
1651 int mouse_face_image_state;
1652 } Mouse_HLInfo;
1654 /* Data type checking */
1656 #define NILP(x) EQ (x, Qnil)
1658 #define NUMBERP(x) (INTEGERP (x) || FLOATP (x))
1659 #define NATNUMP(x) (INTEGERP (x) && XINT (x) >= 0)
1661 #define RANGED_INTEGERP(lo, x, hi) \
1662 (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi))
1663 #define TYPE_RANGED_INTEGERP(type, x) \
1664 (TYPE_SIGNED (type) \
1665 ? RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)) \
1666 : RANGED_INTEGERP (0, x, TYPE_MAXIMUM (type)))
1668 #define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x))))
1669 #define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
1670 #define MISCP(x) (XTYPE ((x)) == Lisp_Misc)
1671 #define VECTORLIKEP(x) (XTYPE ((x)) == Lisp_Vectorlike)
1672 #define STRINGP(x) (XTYPE ((x)) == Lisp_String)
1673 #define CONSP(x) (XTYPE ((x)) == Lisp_Cons)
1675 #define FLOATP(x) (XTYPE ((x)) == Lisp_Float)
1676 #define VECTORP(x) (VECTORLIKEP (x) && !(ASIZE (x) & PSEUDOVECTOR_FLAG))
1677 #define OVERLAYP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay)
1678 #define MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker)
1679 #define SAVE_VALUEP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value)
1681 #define INTFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Int)
1682 #define BOOLFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Bool)
1683 #define OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Obj)
1684 #define BUFFER_OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Buffer_Obj)
1685 #define KBOARD_OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Kboard_Obj)
1687 /* True if object X is a pseudovector whose code is CODE. The cast to struct
1688 vectorlike_header * avoids aliasing issues. */
1689 #define PSEUDOVECTORP(x, code) \
1690 TYPED_PSEUDOVECTORP (x, vectorlike_header, code)
1692 #define PSEUDOVECTOR_TYPEP(v, code) \
1693 (((v)->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) \
1694 == (PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_SIZE_BITS)))
1696 /* True if object X, with internal type struct T *, is a pseudovector whose
1697 code is CODE. */
1698 #define TYPED_PSEUDOVECTORP(x, t, code) \
1699 (VECTORLIKEP (x) \
1700 && PSEUDOVECTOR_TYPEP ((struct t *) XUNTAG (x, Lisp_Vectorlike), code))
1702 /* Test for specific pseudovector types. */
1703 #define WINDOW_CONFIGURATIONP(x) PSEUDOVECTORP (x, PVEC_WINDOW_CONFIGURATION)
1704 #define PROCESSP(x) PSEUDOVECTORP (x, PVEC_PROCESS)
1705 #define WINDOWP(x) PSEUDOVECTORP (x, PVEC_WINDOW)
1706 #define TERMINALP(x) PSEUDOVECTORP (x, PVEC_TERMINAL)
1707 /* SUBRP is special since Lisp_Subr lacks struct vectorlike_header. */
1708 #define SUBRP(x) TYPED_PSEUDOVECTORP (x, Lisp_Subr, PVEC_SUBR)
1709 #define COMPILEDP(x) PSEUDOVECTORP (x, PVEC_COMPILED)
1710 #define BUFFERP(x) PSEUDOVECTORP (x, PVEC_BUFFER)
1711 #define CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_CHAR_TABLE)
1712 #define SUB_CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_SUB_CHAR_TABLE)
1713 #define BOOL_VECTOR_P(x) PSEUDOVECTORP (x, PVEC_BOOL_VECTOR)
1714 #define FRAMEP(x) PSEUDOVECTORP (x, PVEC_FRAME)
1716 /* Test for image (image . spec) */
1717 #define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage))
1719 /* Array types. */
1721 #define ARRAYP(x) \
1722 (VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x))
1724 #define CHECK_LIST(x) \
1725 CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x)
1727 #define CHECK_LIST_CONS(x, y) \
1728 CHECK_TYPE (CONSP (x), Qlistp, y)
1730 #define CHECK_LIST_END(x, y) \
1731 CHECK_TYPE (NILP (x), Qlistp, y)
1733 #define CHECK_STRING(x) \
1734 CHECK_TYPE (STRINGP (x), Qstringp, x)
1736 #define CHECK_STRING_CAR(x) \
1737 CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x))
1739 #define CHECK_CONS(x) \
1740 CHECK_TYPE (CONSP (x), Qconsp, x)
1742 #define CHECK_SYMBOL(x) \
1743 CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
1745 #define CHECK_CHAR_TABLE(x) \
1746 CHECK_TYPE (CHAR_TABLE_P (x), Qchar_table_p, x)
1748 #define CHECK_VECTOR(x) \
1749 CHECK_TYPE (VECTORP (x), Qvectorp, x)
1751 #define CHECK_VECTOR_OR_STRING(x) \
1752 CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x)
1754 #define CHECK_ARRAY(x, Qxxxp) \
1755 CHECK_TYPE (ARRAYP (x), Qxxxp, x)
1757 #define CHECK_VECTOR_OR_CHAR_TABLE(x) \
1758 CHECK_TYPE (VECTORP (x) || CHAR_TABLE_P (x), Qvector_or_char_table_p, x)
1760 #define CHECK_BUFFER(x) \
1761 CHECK_TYPE (BUFFERP (x), Qbufferp, x)
1763 #define CHECK_WINDOW(x) \
1764 CHECK_TYPE (WINDOWP (x), Qwindowp, x)
1766 #define CHECK_WINDOW_CONFIGURATION(x) \
1767 CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x)
1769 /* This macro rejects windows on the interior of the window tree as
1770 "dead", which is what we want; this is an argument-checking macro, and
1771 the user should never get access to interior windows.
1773 A window of any sort, leaf or interior, is dead if the buffer,
1774 vchild, and hchild members are all nil. */
1776 #define CHECK_LIVE_WINDOW(x) \
1777 CHECK_TYPE (WINDOWP (x) && !NILP (XWINDOW (x)->buffer), Qwindow_live_p, x)
1779 #define CHECK_PROCESS(x) \
1780 CHECK_TYPE (PROCESSP (x), Qprocessp, x)
1782 #define CHECK_SUBR(x) \
1783 CHECK_TYPE (SUBRP (x), Qsubrp, x)
1785 #define CHECK_NUMBER(x) \
1786 CHECK_TYPE (INTEGERP (x), Qintegerp, x)
1788 #define CHECK_NATNUM(x) \
1789 CHECK_TYPE (NATNUMP (x), Qwholenump, x)
1791 #define CHECK_RANGED_INTEGER(x, lo, hi) \
1792 do { \
1793 CHECK_NUMBER (x); \
1794 if (! ((lo) <= XINT (x) && XINT (x) <= (hi))) \
1795 args_out_of_range_3 \
1796 (x, \
1797 make_number ((lo) < 0 && (lo) < MOST_NEGATIVE_FIXNUM \
1798 ? MOST_NEGATIVE_FIXNUM \
1799 : (lo)), \
1800 make_number (min (hi, MOST_POSITIVE_FIXNUM))); \
1801 } while (0)
1802 #define CHECK_TYPE_RANGED_INTEGER(type, x) \
1803 do { \
1804 if (TYPE_SIGNED (type)) \
1805 CHECK_RANGED_INTEGER (x, TYPE_MINIMUM (type), TYPE_MAXIMUM (type)); \
1806 else \
1807 CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
1808 } while (0)
1810 #define CHECK_MARKER(x) \
1811 CHECK_TYPE (MARKERP (x), Qmarkerp, x)
1813 #define CHECK_NUMBER_COERCE_MARKER(x) \
1814 do { if (MARKERP ((x))) XSETFASTINT (x, marker_position (x)); \
1815 else CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); } while (0)
1817 #define XFLOATINT(n) extract_float((n))
1819 #define CHECK_FLOAT(x) \
1820 CHECK_TYPE (FLOATP (x), Qfloatp, x)
1822 #define CHECK_NUMBER_OR_FLOAT(x) \
1823 CHECK_TYPE (FLOATP (x) || INTEGERP (x), Qnumberp, x)
1825 #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \
1826 do { if (MARKERP (x)) XSETFASTINT (x, marker_position (x)); \
1827 else CHECK_TYPE (INTEGERP (x) || FLOATP (x), Qnumber_or_marker_p, x); } while (0)
1829 #define CHECK_OVERLAY(x) \
1830 CHECK_TYPE (OVERLAYP (x), Qoverlayp, x)
1832 /* Since we can't assign directly to the CAR or CDR fields of a cons
1833 cell, use these when checking that those fields contain numbers. */
1834 #define CHECK_NUMBER_CAR(x) \
1835 do { \
1836 Lisp_Object tmp = XCAR (x); \
1837 CHECK_NUMBER (tmp); \
1838 XSETCAR ((x), tmp); \
1839 } while (0)
1841 #define CHECK_NUMBER_CDR(x) \
1842 do { \
1843 Lisp_Object tmp = XCDR (x); \
1844 CHECK_NUMBER (tmp); \
1845 XSETCDR ((x), tmp); \
1846 } while (0)
1848 #define CHECK_NATNUM_CAR(x) \
1849 do { \
1850 Lisp_Object tmp = XCAR (x); \
1851 CHECK_NATNUM (tmp); \
1852 XSETCAR ((x), tmp); \
1853 } while (0)
1855 #define CHECK_NATNUM_CDR(x) \
1856 do { \
1857 Lisp_Object tmp = XCDR (x); \
1858 CHECK_NATNUM (tmp); \
1859 XSETCDR ((x), tmp); \
1860 } while (0)
1862 /* Define a built-in function for calling from Lisp.
1863 `lname' should be the name to give the function in Lisp,
1864 as a null-terminated C string.
1865 `fnname' should be the name of the function in C.
1866 By convention, it starts with F.
1867 `sname' should be the name for the C constant structure
1868 that records information on this function for internal use.
1869 By convention, it should be the same as `fnname' but with S instead of F.
1870 It's too bad that C macros can't compute this from `fnname'.
1871 `minargs' should be a number, the minimum number of arguments allowed.
1872 `maxargs' should be a number, the maximum number of arguments allowed,
1873 or else MANY or UNEVALLED.
1874 MANY means pass a vector of evaluated arguments,
1875 in the form of an integer number-of-arguments
1876 followed by the address of a vector of Lisp_Objects
1877 which contains the argument values.
1878 UNEVALLED means pass the list of unevaluated arguments
1879 `intspec' says how interactive arguments are to be fetched.
1880 If the string starts with a `(', `intspec' is evaluated and the resulting
1881 list is the list of arguments.
1882 If it's a string that doesn't start with `(', the value should follow
1883 the one of the doc string for `interactive'.
1884 A null string means call interactively with no arguments.
1885 `doc' is documentation for the user. */
1887 /* This version of DEFUN declares a function prototype with the right
1888 arguments, so we can catch errors with maxargs at compile-time. */
1889 #ifdef _MSC_VER
1890 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
1891 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
1892 static DECL_ALIGN (struct Lisp_Subr, sname) = \
1893 { (PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS) \
1894 | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \
1895 { (Lisp_Object (__cdecl *)(void))fnname }, \
1896 minargs, maxargs, lname, intspec, 0}; \
1897 Lisp_Object fnname
1898 #else /* not _MSC_VER */
1899 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
1900 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
1901 static DECL_ALIGN (struct Lisp_Subr, sname) = \
1902 { PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS, \
1903 { .a ## maxargs = fnname }, \
1904 minargs, maxargs, lname, intspec, 0}; \
1905 Lisp_Object fnname
1906 #endif
1908 /* Note that the weird token-substitution semantics of ANSI C makes
1909 this work for MANY and UNEVALLED. */
1910 #define DEFUN_ARGS_MANY (ptrdiff_t, Lisp_Object *)
1911 #define DEFUN_ARGS_UNEVALLED (Lisp_Object)
1912 #define DEFUN_ARGS_0 (void)
1913 #define DEFUN_ARGS_1 (Lisp_Object)
1914 #define DEFUN_ARGS_2 (Lisp_Object, Lisp_Object)
1915 #define DEFUN_ARGS_3 (Lisp_Object, Lisp_Object, Lisp_Object)
1916 #define DEFUN_ARGS_4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
1917 #define DEFUN_ARGS_5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
1918 Lisp_Object)
1919 #define DEFUN_ARGS_6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
1920 Lisp_Object, Lisp_Object)
1921 #define DEFUN_ARGS_7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
1922 Lisp_Object, Lisp_Object, Lisp_Object)
1923 #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
1924 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
1926 /* Non-zero if OBJ is a Lisp function. */
1927 #define FUNCTIONP(OBJ) \
1928 ((CONSP (OBJ) && EQ (XCAR (OBJ), Qlambda)) \
1929 || (SYMBOLP (OBJ) && !NILP (Ffboundp (OBJ))) \
1930 || COMPILEDP (OBJ) \
1931 || SUBRP (OBJ))
1933 /* defsubr (Sname);
1934 is how we define the symbol for function `name' at start-up time. */
1935 extern void defsubr (struct Lisp_Subr *);
1937 #define MANY -2
1938 #define UNEVALLED -1
1940 extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *);
1941 extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *);
1942 extern void defvar_bool (struct Lisp_Boolfwd *, const char *, int *);
1943 extern void defvar_int (struct Lisp_Intfwd *, const char *, EMACS_INT *);
1944 extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int);
1946 /* Macros we use to define forwarded Lisp variables.
1947 These are used in the syms_of_FILENAME functions.
1949 An ordinary (not in buffer_defaults, per-buffer, or per-keyboard)
1950 lisp variable is actually a field in `struct emacs_globals'. The
1951 field's name begins with "f_", which is a convention enforced by
1952 these macros. Each such global has a corresponding #define in
1953 globals.h; the plain name should be used in the code.
1955 E.g., the global "cons_cells_consed" is declared as "int
1956 f_cons_cells_consed" in globals.h, but there is a define:
1958 #define cons_cells_consed globals.f_cons_cells_consed
1960 All C code uses the `cons_cells_consed' name. This is all done
1961 this way to support indirection for multi-threaded Emacs. */
1963 #define DEFVAR_LISP(lname, vname, doc) \
1964 do { \
1965 static struct Lisp_Objfwd o_fwd; \
1966 defvar_lisp (&o_fwd, lname, &globals.f_ ## vname); \
1967 } while (0)
1968 #define DEFVAR_LISP_NOPRO(lname, vname, doc) \
1969 do { \
1970 static struct Lisp_Objfwd o_fwd; \
1971 defvar_lisp_nopro (&o_fwd, lname, &globals.f_ ## vname); \
1972 } while (0)
1973 #define DEFVAR_BOOL(lname, vname, doc) \
1974 do { \
1975 static struct Lisp_Boolfwd b_fwd; \
1976 defvar_bool (&b_fwd, lname, &globals.f_ ## vname); \
1977 } while (0)
1978 #define DEFVAR_INT(lname, vname, doc) \
1979 do { \
1980 static struct Lisp_Intfwd i_fwd; \
1981 defvar_int (&i_fwd, lname, &globals.f_ ## vname); \
1982 } while (0)
1984 #define DEFVAR_BUFFER_DEFAULTS(lname, vname, doc) \
1985 do { \
1986 static struct Lisp_Objfwd o_fwd; \
1987 defvar_lisp_nopro (&o_fwd, lname, &BVAR (&buffer_defaults, vname)); \
1988 } while (0)
1990 #define DEFVAR_KBOARD(lname, vname, doc) \
1991 do { \
1992 static struct Lisp_Kboard_Objfwd ko_fwd; \
1993 defvar_kboard (&ko_fwd, lname, offsetof (KBOARD, vname ## _)); \
1994 } while (0)
1998 /* Structure for recording Lisp call stack for backtrace purposes. */
2000 /* The special binding stack holds the outer values of variables while
2001 they are bound by a function application or a let form, stores the
2002 code to be executed for Lisp unwind-protect forms, and stores the C
2003 functions to be called for record_unwind_protect.
2005 If func is non-zero, undoing this binding applies func to old_value;
2006 This implements record_unwind_protect.
2008 Otherwise, the element is a variable binding.
2010 If the symbol field is a symbol, it is an ordinary variable binding.
2012 Otherwise, it should be a structure (SYMBOL WHERE . CURRENT-BUFFER),
2013 which means having bound a local value while CURRENT-BUFFER was active.
2014 If WHERE is nil this means we saw the default value when binding SYMBOL.
2015 WHERE being a buffer or frame means we saw a buffer-local or frame-local
2016 value. Other values of WHERE mean an internal error. */
2018 typedef Lisp_Object (*specbinding_func) (Lisp_Object);
2020 struct specbinding
2022 Lisp_Object symbol, old_value;
2023 specbinding_func func;
2024 Lisp_Object unused; /* Dividing by 16 is faster than by 12 */
2027 extern struct specbinding *specpdl;
2028 extern struct specbinding *specpdl_ptr;
2029 extern ptrdiff_t specpdl_size;
2031 #define SPECPDL_INDEX() (specpdl_ptr - specpdl)
2033 /* Everything needed to describe an active condition case. */
2034 struct handler
2036 /* The handler clauses and variable from the condition-case form. */
2037 /* For a handler set up in Lisp code, this is always a list.
2038 For an internal handler set up by internal_condition_case*,
2039 this can instead be the symbol t or `error'.
2040 t: handle all conditions.
2041 error: handle all conditions, and errors can run the debugger
2042 or display a backtrace. */
2043 Lisp_Object handler;
2044 Lisp_Object var;
2045 /* Fsignal stores here the condition-case clause that applies,
2046 and Fcondition_case thus knows which clause to run. */
2047 Lisp_Object chosen_clause;
2049 /* Used to effect the longjump out to the handler. */
2050 struct catchtag *tag;
2052 /* The next enclosing handler. */
2053 struct handler *next;
2056 /* This structure helps implement the `catch' and `throw' control
2057 structure. A struct catchtag contains all the information needed
2058 to restore the state of the interpreter after a non-local jump.
2060 Handlers for error conditions (represented by `struct handler'
2061 structures) just point to a catch tag to do the cleanup required
2062 for their jumps.
2064 catchtag structures are chained together in the C calling stack;
2065 the `next' member points to the next outer catchtag.
2067 A call like (throw TAG VAL) searches for a catchtag whose `tag'
2068 member is TAG, and then unbinds to it. The `val' member is used to
2069 hold VAL while the stack is unwound; `val' is returned as the value
2070 of the catch form.
2072 All the other members are concerned with restoring the interpreter
2073 state. */
2075 struct catchtag
2077 Lisp_Object tag;
2078 Lisp_Object val;
2079 struct catchtag *next;
2080 struct gcpro *gcpro;
2081 jmp_buf jmp;
2082 struct backtrace *backlist;
2083 struct handler *handlerlist;
2084 EMACS_INT lisp_eval_depth;
2085 ptrdiff_t pdlcount;
2086 int poll_suppress_count;
2087 int interrupt_input_blocked;
2088 struct byte_stack *byte_stack;
2091 extern Lisp_Object memory_signal_data;
2093 /* An address near the bottom of the stack.
2094 Tells GC how to save a copy of the stack. */
2095 extern char *stack_bottom;
2097 /* Check quit-flag and quit if it is non-nil.
2098 Typing C-g does not directly cause a quit; it only sets Vquit_flag.
2099 So the program needs to do QUIT at times when it is safe to quit.
2100 Every loop that might run for a long time or might not exit
2101 ought to do QUIT at least once, at a safe place.
2102 Unless that is impossible, of course.
2103 But it is very desirable to avoid creating loops where QUIT is impossible.
2105 Exception: if you set immediate_quit to nonzero,
2106 then the handler that responds to the C-g does the quit itself.
2107 This is a good thing to do around a loop that has no side effects
2108 and (in particular) cannot call arbitrary Lisp code.
2110 If quit-flag is set to `kill-emacs' the SIGINT handler has received
2111 a request to exit Emacs when it is safe to do. */
2113 #ifdef SYNC_INPUT
2114 extern void process_pending_signals (void);
2115 extern int pending_signals;
2116 #define ELSE_PENDING_SIGNALS \
2117 else if (pending_signals) \
2118 process_pending_signals ();
2119 #else /* not SYNC_INPUT */
2120 #define ELSE_PENDING_SIGNALS
2121 #endif /* not SYNC_INPUT */
2123 extern void process_quit_flag (void);
2124 #define QUIT \
2125 do { \
2126 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
2127 process_quit_flag (); \
2128 ELSE_PENDING_SIGNALS \
2129 } while (0)
2132 /* Nonzero if ought to quit now. */
2134 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
2136 extern Lisp_Object Vascii_downcase_table;
2137 extern Lisp_Object Vascii_canon_table;
2139 /* Structure for recording stack slots that need marking. */
2141 /* This is a chain of structures, each of which points at a Lisp_Object
2142 variable whose value should be marked in garbage collection.
2143 Normally every link of the chain is an automatic variable of a function,
2144 and its `val' points to some argument or local variable of the function.
2145 On exit to the function, the chain is set back to the value it had on entry.
2146 This way, no link remains in the chain when the stack frame containing the
2147 link disappears.
2149 Every function that can call Feval must protect in this fashion all
2150 Lisp_Object variables whose contents will be used again. */
2152 extern struct gcpro *gcprolist;
2154 struct gcpro
2156 struct gcpro *next;
2158 /* Address of first protected variable. */
2159 volatile Lisp_Object *var;
2161 /* Number of consecutive protected variables. */
2162 ptrdiff_t nvars;
2164 #ifdef DEBUG_GCPRO
2165 int level;
2166 #endif
2169 /* Values of GC_MARK_STACK during compilation:
2171 0 Use GCPRO as before
2172 1 Do the real thing, make GCPROs and UNGCPRO no-ops.
2173 2 Mark the stack, and check that everything GCPRO'd is
2174 marked.
2175 3 Mark using GCPRO's, mark stack last, and count how many
2176 dead objects are kept alive. */
2179 #define GC_USE_GCPROS_AS_BEFORE 0
2180 #define GC_MAKE_GCPROS_NOOPS 1
2181 #define GC_MARK_STACK_CHECK_GCPROS 2
2182 #define GC_USE_GCPROS_CHECK_ZOMBIES 3
2184 #ifndef GC_MARK_STACK
2185 #define GC_MARK_STACK GC_MAKE_GCPROS_NOOPS
2186 #endif
2188 /* Whether we do the stack marking manually. */
2189 #define BYTE_MARK_STACK !(GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \
2190 || GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS)
2193 #if GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS
2195 /* Do something silly with gcproN vars just so gcc shuts up. */
2196 /* You get warnings from MIPSPro... */
2198 #define GCPRO1(varname) ((void) gcpro1)
2199 #define GCPRO2(varname1, varname2) ((void) gcpro2, (void) gcpro1)
2200 #define GCPRO3(varname1, varname2, varname3) \
2201 ((void) gcpro3, (void) gcpro2, (void) gcpro1)
2202 #define GCPRO4(varname1, varname2, varname3, varname4) \
2203 ((void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
2204 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2205 ((void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
2206 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2207 ((void) gcpro6, (void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, \
2208 (void) gcpro1)
2209 #define UNGCPRO ((void) 0)
2211 #else /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
2213 #ifndef DEBUG_GCPRO
2215 #define GCPRO1(varname) \
2216 {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
2217 gcprolist = &gcpro1; }
2219 #define GCPRO2(varname1, varname2) \
2220 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2221 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2222 gcprolist = &gcpro2; }
2224 #define GCPRO3(varname1, varname2, varname3) \
2225 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2226 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2227 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2228 gcprolist = &gcpro3; }
2230 #define GCPRO4(varname1, varname2, varname3, varname4) \
2231 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2232 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2233 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2234 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2235 gcprolist = &gcpro4; }
2237 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2238 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2239 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2240 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2241 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2242 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2243 gcprolist = &gcpro5; }
2245 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2246 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2247 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2248 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2249 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2250 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2251 gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
2252 gcprolist = &gcpro6; }
2254 #define UNGCPRO (gcprolist = gcpro1.next)
2256 #else
2258 extern int gcpro_level;
2260 #define GCPRO1(varname) \
2261 {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
2262 gcpro1.level = gcpro_level++; \
2263 gcprolist = &gcpro1; }
2265 #define GCPRO2(varname1, varname2) \
2266 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2267 gcpro1.level = gcpro_level; \
2268 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2269 gcpro2.level = gcpro_level++; \
2270 gcprolist = &gcpro2; }
2272 #define GCPRO3(varname1, varname2, varname3) \
2273 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2274 gcpro1.level = gcpro_level; \
2275 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2276 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2277 gcpro3.level = gcpro_level++; \
2278 gcprolist = &gcpro3; }
2280 #define GCPRO4(varname1, varname2, varname3, varname4) \
2281 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2282 gcpro1.level = gcpro_level; \
2283 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2284 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2285 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2286 gcpro4.level = gcpro_level++; \
2287 gcprolist = &gcpro4; }
2289 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2290 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2291 gcpro1.level = gcpro_level; \
2292 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2293 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2294 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2295 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2296 gcpro5.level = gcpro_level++; \
2297 gcprolist = &gcpro5; }
2299 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2300 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2301 gcpro1.level = gcpro_level; \
2302 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2303 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2304 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2305 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2306 gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
2307 gcpro6.level = gcpro_level++; \
2308 gcprolist = &gcpro6; }
2310 #define UNGCPRO \
2311 ((--gcpro_level != gcpro1.level) \
2312 ? (abort (), 0) \
2313 : ((gcprolist = gcpro1.next), 0))
2315 #endif /* DEBUG_GCPRO */
2316 #endif /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
2319 /* Evaluate expr, UNGCPRO, and then return the value of expr. */
2320 #define RETURN_UNGCPRO(expr) \
2321 do \
2323 Lisp_Object ret_ungc_val; \
2324 ret_ungc_val = (expr); \
2325 UNGCPRO; \
2326 return ret_ungc_val; \
2328 while (0)
2330 /* Call staticpro (&var) to protect static variable `var'. */
2332 void staticpro (Lisp_Object *);
2334 /* Declare a Lisp-callable function. The MAXARGS parameter has the same
2335 meaning as in the DEFUN macro, and is used to construct a prototype. */
2336 /* We can use the same trick as in the DEFUN macro to generate the
2337 appropriate prototype. */
2338 #define EXFUN(fnname, maxargs) \
2339 extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
2341 /* Forward declarations for prototypes. */
2342 struct window;
2343 struct frame;
2345 /* Defined in data.c. */
2346 extern Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
2347 extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
2348 extern Lisp_Object Qerror, Qquit, Qargs_out_of_range;
2349 extern Lisp_Object Qvoid_variable, Qvoid_function;
2350 extern Lisp_Object Qinvalid_read_syntax;
2351 extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
2352 extern Lisp_Object Quser_error, Qend_of_file, Qarith_error, Qmark_inactive;
2353 extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
2354 extern Lisp_Object Qtext_read_only;
2355 extern Lisp_Object Qinteractive_form;
2356 extern Lisp_Object Qcircular_list;
2357 extern Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp;
2358 extern Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
2359 extern Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
2360 extern Lisp_Object Qbuffer_or_string_p;
2361 extern Lisp_Object Qfboundp;
2362 extern Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
2364 extern Lisp_Object Qcdr;
2366 extern Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
2367 extern Lisp_Object Qoverflow_error, Qunderflow_error;
2369 extern Lisp_Object Qfloatp;
2370 extern Lisp_Object Qnumberp, Qnumber_or_marker_p;
2372 extern Lisp_Object Qinteger, Qinterval, Qsymbol, Qstring;
2373 extern Lisp_Object Qmisc, Qvector, Qfloat, Qcons, Qbuffer;
2375 extern Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
2377 EXFUN (Fbyteorder, 0) ATTRIBUTE_CONST;
2379 /* Defined in frame.c */
2380 extern Lisp_Object Qframep;
2382 /* Defined in data.c */
2383 extern Lisp_Object indirect_function (Lisp_Object);
2384 extern Lisp_Object find_symbol_value (Lisp_Object);
2386 /* Convert the integer I to an Emacs representation, either the integer
2387 itself, or a cons of two or three integers, or if all else fails a float.
2388 I should not have side effects. */
2389 #define INTEGER_TO_CONS(i) \
2390 (! FIXNUM_OVERFLOW_P (i) \
2391 ? make_number (i) \
2392 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16) \
2393 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16)) \
2394 && FIXNUM_OVERFLOW_P ((i) >> 16)) \
2395 ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff)) \
2396 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16 >> 24) \
2397 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16 >> 24)) \
2398 && FIXNUM_OVERFLOW_P ((i) >> 16 >> 24)) \
2399 ? Fcons (make_number ((i) >> 16 >> 24), \
2400 Fcons (make_number ((i) >> 16 & 0xffffff), \
2401 make_number ((i) & 0xffff))) \
2402 : make_float (i))
2404 /* Convert the Emacs representation CONS back to an integer of type
2405 TYPE, storing the result the variable VAR. Signal an error if CONS
2406 is not a valid representation or is out of range for TYPE. */
2407 #define CONS_TO_INTEGER(cons, type, var) \
2408 (TYPE_SIGNED (type) \
2409 ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
2410 : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
2411 extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
2412 extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
2414 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
2415 extern _Noreturn void args_out_of_range (Lisp_Object, Lisp_Object);
2416 extern _Noreturn void args_out_of_range_3 (Lisp_Object, Lisp_Object,
2417 Lisp_Object);
2418 extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
2419 extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *);
2420 extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, int);
2421 extern void syms_of_data (void);
2422 extern void init_data (void);
2423 extern void swap_in_global_binding (struct Lisp_Symbol *);
2425 /* Defined in cmds.c */
2426 extern void syms_of_cmds (void);
2427 extern void keys_of_cmds (void);
2429 /* Defined in coding.c */
2430 extern Lisp_Object Qcharset;
2431 extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
2432 ptrdiff_t, int, int, Lisp_Object);
2433 extern void init_coding (void);
2434 extern void init_coding_once (void);
2435 extern void syms_of_coding (void);
2437 /* Defined in character.c */
2438 EXFUN (Fmax_char, 0) ATTRIBUTE_CONST;
2439 extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
2440 extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
2441 extern int multibyte_char_to_unibyte (int) ATTRIBUTE_CONST;
2442 extern int multibyte_char_to_unibyte_safe (int) ATTRIBUTE_CONST;
2443 extern void syms_of_character (void);
2445 /* Defined in charset.c */
2446 extern void init_charset (void);
2447 extern void init_charset_once (void);
2448 extern void syms_of_charset (void);
2449 /* Structure forward declarations. */
2450 struct charset;
2452 /* Defined in composite.c */
2453 extern void syms_of_composite (void);
2455 /* Defined in syntax.c */
2456 extern void init_syntax_once (void);
2457 extern void syms_of_syntax (void);
2459 /* Defined in fns.c */
2460 extern Lisp_Object QCrehash_size, QCrehash_threshold;
2461 enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
2462 EXFUN (Fidentity, 1) ATTRIBUTE_CONST;
2463 extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
2464 extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
2465 extern void sweep_weak_hash_tables (void);
2466 extern Lisp_Object Qcursor_in_echo_area;
2467 extern Lisp_Object Qstring_lessp;
2468 extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql;
2469 EMACS_UINT hash_string (char const *, ptrdiff_t);
2470 EMACS_UINT sxhash (Lisp_Object, int);
2471 Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object,
2472 Lisp_Object, Lisp_Object, Lisp_Object,
2473 Lisp_Object);
2474 ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
2475 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
2476 EMACS_UINT);
2478 extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
2479 ptrdiff_t, ptrdiff_t);
2480 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
2481 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
2482 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
2483 extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
2484 extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
2485 extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
2486 extern void clear_string_char_byte_cache (void);
2487 extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
2488 extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
2489 extern Lisp_Object string_to_multibyte (Lisp_Object);
2490 extern Lisp_Object string_make_unibyte (Lisp_Object);
2491 extern void syms_of_fns (void);
2493 /* Defined in floatfns.c */
2494 extern double extract_float (Lisp_Object);
2495 extern void init_floatfns (void);
2496 extern void syms_of_floatfns (void);
2497 extern Lisp_Object fmod_float (Lisp_Object x, Lisp_Object y);
2499 /* Defined in fringe.c */
2500 extern void syms_of_fringe (void);
2501 extern void init_fringe (void);
2502 #ifdef HAVE_WINDOW_SYSTEM
2503 extern void mark_fringe_data (void);
2504 extern void init_fringe_once (void);
2505 #endif /* HAVE_WINDOW_SYSTEM */
2507 /* Defined in image.c */
2508 extern Lisp_Object QCascent, QCmargin, QCrelief;
2509 extern Lisp_Object QCconversion;
2510 extern int x_bitmap_mask (struct frame *, ptrdiff_t);
2511 extern void syms_of_image (void);
2513 /* Defined in insdel.c */
2514 extern Lisp_Object Qinhibit_modification_hooks;
2515 extern void move_gap (ptrdiff_t);
2516 extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2517 extern _Noreturn void buffer_overflow (void);
2518 extern void make_gap (ptrdiff_t);
2519 extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
2520 ptrdiff_t, int, int);
2521 extern int count_combining_before (const unsigned char *,
2522 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2523 extern int count_combining_after (const unsigned char *,
2524 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2525 extern void insert (const char *, ptrdiff_t);
2526 extern void insert_and_inherit (const char *, ptrdiff_t);
2527 extern void insert_1 (const char *, ptrdiff_t, int, int, int);
2528 extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
2529 int, int, int);
2530 extern void insert_from_gap (ptrdiff_t, ptrdiff_t);
2531 extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
2532 ptrdiff_t, ptrdiff_t, int);
2533 extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2534 extern void insert_char (int);
2535 extern void insert_string (const char *);
2536 extern void insert_before_markers (const char *, ptrdiff_t);
2537 extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
2538 extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
2539 ptrdiff_t, ptrdiff_t,
2540 ptrdiff_t, int);
2541 extern void del_range (ptrdiff_t, ptrdiff_t);
2542 extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, int, int);
2543 extern void del_range_byte (ptrdiff_t, ptrdiff_t, int);
2544 extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, int);
2545 extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
2546 ptrdiff_t, ptrdiff_t, int);
2547 extern void modify_region (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2548 extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
2549 extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
2550 extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2551 ptrdiff_t, ptrdiff_t);
2552 extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
2553 ptrdiff_t, ptrdiff_t);
2554 extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, int, int, int);
2555 extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
2556 const char *, ptrdiff_t, ptrdiff_t, int);
2557 extern void syms_of_insdel (void);
2559 /* Defined in dispnew.c */
2560 #if (defined PROFILING \
2561 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
2562 _Noreturn void __executable_start (void);
2563 #endif
2564 extern Lisp_Object selected_frame;
2565 extern Lisp_Object Vwindow_system;
2566 void duration_to_sec_usec (double, int *, int *);
2567 extern Lisp_Object sit_for (Lisp_Object, int, int);
2568 extern void init_display (void);
2569 extern void syms_of_display (void);
2571 /* Defined in xdisp.c */
2572 extern Lisp_Object Qinhibit_point_motion_hooks;
2573 extern Lisp_Object Qinhibit_redisplay, Qdisplay;
2574 extern Lisp_Object Qmenu_bar_update_hook;
2575 extern Lisp_Object Qwindow_scroll_functions;
2576 extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
2577 extern Lisp_Object Qimage, Qtext, Qboth, Qboth_horiz, Qtext_image_horiz;
2578 extern Lisp_Object Qspace, Qcenter, QCalign_to;
2579 extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
2580 extern Lisp_Object Qleft_margin, Qright_margin;
2581 extern Lisp_Object Qglyphless_char;
2582 extern Lisp_Object QCdata, QCfile;
2583 extern Lisp_Object QCmap;
2584 extern Lisp_Object Qrisky_local_variable;
2585 extern struct frame *last_glyphless_glyph_frame;
2586 extern int last_glyphless_glyph_face_id;
2587 extern int last_glyphless_glyph_merged_face_id;
2588 extern int noninteractive_need_newline;
2589 extern Lisp_Object echo_area_buffer[2];
2590 extern void add_to_log (const char *, Lisp_Object, Lisp_Object);
2591 extern void check_message_stack (void);
2592 extern void setup_echo_area_for_printing (int);
2593 extern int push_message (void);
2594 extern Lisp_Object pop_message_unwind (Lisp_Object);
2595 extern Lisp_Object restore_message_unwind (Lisp_Object);
2596 extern void restore_message (void);
2597 extern Lisp_Object current_message (void);
2598 extern void clear_message (int, int);
2599 extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
2600 extern void message1 (const char *);
2601 extern void message1_nolog (const char *);
2602 extern void message2 (const char *, ptrdiff_t, int);
2603 extern void message2_nolog (const char *, ptrdiff_t, int);
2604 extern void message3 (Lisp_Object, ptrdiff_t, int);
2605 extern void message3_nolog (Lisp_Object, ptrdiff_t, int);
2606 extern void message_dolog (const char *, ptrdiff_t, int, int);
2607 extern void message_with_string (const char *, Lisp_Object, int);
2608 extern void message_log_maybe_newline (void);
2609 extern void update_echo_area (void);
2610 extern void truncate_echo_area (ptrdiff_t);
2611 extern void redisplay (void);
2612 extern void redisplay_preserve_echo_area (int);
2613 extern void prepare_menu_bars (void);
2615 void set_frame_cursor_types (struct frame *, Lisp_Object);
2616 extern void syms_of_xdisp (void);
2617 extern void init_xdisp (void);
2618 extern Lisp_Object safe_eval (Lisp_Object);
2619 extern int pos_visible_p (struct window *, ptrdiff_t, int *,
2620 int *, int *, int *, int *, int *);
2622 /* Defined in xsettings.c */
2623 extern void syms_of_xsettings (void);
2625 /* Defined in vm-limit.c. */
2626 extern void memory_warnings (void *, void (*warnfun) (const char *));
2628 /* Defined in alloc.c */
2629 extern void check_pure_size (void);
2630 extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
2631 extern void reset_malloc_hooks (void);
2632 extern void uninterrupt_malloc (void);
2633 extern void malloc_warning (const char *);
2634 extern _Noreturn void memory_full (size_t);
2635 extern _Noreturn void buffer_memory_full (ptrdiff_t);
2636 extern int survives_gc_p (Lisp_Object);
2637 extern void mark_object (Lisp_Object);
2638 #if defined REL_ALLOC && !defined SYSTEM_MALLOC
2639 extern void refill_memory_reserve (void);
2640 #endif
2641 extern const char *pending_malloc_warning;
2642 extern Lisp_Object zero_vector;
2643 extern Lisp_Object *stack_base;
2644 extern EMACS_INT consing_since_gc;
2645 extern EMACS_INT gc_relative_threshold;
2646 extern EMACS_INT memory_full_cons_threshold;
2647 extern Lisp_Object list1 (Lisp_Object);
2648 extern Lisp_Object list2 (Lisp_Object, Lisp_Object);
2649 extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object);
2650 extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2651 extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
2652 Lisp_Object);
2653 extern _Noreturn void string_overflow (void);
2654 extern Lisp_Object make_string (const char *, ptrdiff_t);
2655 extern Lisp_Object make_formatted_string (char *, const char *, ...)
2656 ATTRIBUTE_FORMAT_PRINTF (2, 3);
2657 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
2659 /* Make unibyte string from C string when the length isn't known. */
2661 static inline Lisp_Object
2662 build_unibyte_string (const char *str)
2664 return make_unibyte_string (str, strlen (str));
2667 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
2668 extern Lisp_Object make_event_array (int, Lisp_Object *);
2669 extern Lisp_Object make_uninit_string (EMACS_INT);
2670 extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
2671 extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
2672 extern Lisp_Object make_specified_string (const char *,
2673 ptrdiff_t, ptrdiff_t, int);
2674 extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, int);
2675 extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
2677 /* Make a string allocated in pure space, use STR as string data. */
2679 static inline Lisp_Object
2680 build_pure_c_string (const char *str)
2682 return make_pure_c_string (str, strlen (str));
2685 /* Make a string from the data at STR, treating it as multibyte if the
2686 data warrants. */
2688 static inline Lisp_Object
2689 build_string (const char *str)
2691 return make_string (str, strlen (str));
2694 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
2695 extern void make_byte_code (struct Lisp_Vector *);
2696 extern Lisp_Object Qchar_table_extra_slots;
2697 extern struct Lisp_Vector *allocate_vector (EMACS_INT);
2698 extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, int tag);
2699 #define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
2700 ((typ*) \
2701 allocate_pseudovector \
2702 (VECSIZE (typ), PSEUDOVECSIZE (typ, field), tag))
2703 extern struct Lisp_Hash_Table *allocate_hash_table (void);
2704 extern struct window *allocate_window (void);
2705 extern struct frame *allocate_frame (void);
2706 extern struct Lisp_Process *allocate_process (void);
2707 extern struct terminal *allocate_terminal (void);
2708 extern int gc_in_progress;
2709 extern int abort_on_gc;
2710 extern Lisp_Object make_float (double);
2711 extern void display_malloc_warning (void);
2712 extern ptrdiff_t inhibit_garbage_collection (void);
2713 extern Lisp_Object make_save_value (void *, ptrdiff_t);
2714 extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object);
2715 extern void free_marker (Lisp_Object);
2716 extern void free_cons (struct Lisp_Cons *);
2717 extern void init_alloc_once (void);
2718 extern void init_alloc (void);
2719 extern void syms_of_alloc (void);
2720 extern struct buffer * allocate_buffer (void);
2721 extern int valid_lisp_object_p (Lisp_Object);
2723 #ifdef REL_ALLOC
2724 /* Defined in ralloc.c */
2725 extern void *r_alloc (void **, size_t);
2726 extern void r_alloc_free (void **);
2727 extern void *r_re_alloc (void **, size_t);
2728 extern void r_alloc_reset_variable (void **, void **);
2729 extern void r_alloc_inhibit_buffer_relocation (int);
2730 #endif
2732 /* Defined in chartab.c */
2733 extern Lisp_Object copy_char_table (Lisp_Object);
2734 extern Lisp_Object char_table_ref (Lisp_Object, int);
2735 extern Lisp_Object char_table_ref_and_range (Lisp_Object, int,
2736 int *, int *);
2737 extern Lisp_Object char_table_set (Lisp_Object, int, Lisp_Object);
2738 extern Lisp_Object char_table_set_range (Lisp_Object, int, int,
2739 Lisp_Object);
2740 extern int char_table_translate (Lisp_Object, int);
2741 extern void map_char_table (void (*) (Lisp_Object, Lisp_Object,
2742 Lisp_Object),
2743 Lisp_Object, Lisp_Object, Lisp_Object);
2744 extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object),
2745 Lisp_Object, Lisp_Object,
2746 Lisp_Object, struct charset *,
2747 unsigned, unsigned);
2748 extern Lisp_Object uniprop_table (Lisp_Object);
2749 extern void syms_of_chartab (void);
2751 /* Defined in print.c */
2752 extern Lisp_Object Vprin1_to_string_buffer;
2753 extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
2754 extern Lisp_Object Qstandard_output;
2755 extern Lisp_Object Qexternal_debugging_output;
2756 extern void temp_output_buffer_setup (const char *);
2757 extern int print_level;
2758 extern Lisp_Object Qprint_escape_newlines;
2759 extern void write_string (const char *, int);
2760 extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
2761 Lisp_Object);
2762 extern Lisp_Object internal_with_output_to_temp_buffer
2763 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
2764 #define FLOAT_TO_STRING_BUFSIZE 350
2765 extern int float_to_string (char *, double);
2766 extern void syms_of_print (void);
2768 /* Defined in doprnt.c */
2769 extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
2770 va_list);
2771 extern ptrdiff_t esprintf (char *, char const *, ...)
2772 ATTRIBUTE_FORMAT_PRINTF (2, 3);
2773 extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
2774 char const *, ...)
2775 ATTRIBUTE_FORMAT_PRINTF (5, 6);
2776 extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
2777 char const *, va_list)
2778 ATTRIBUTE_FORMAT_PRINTF (5, 0);
2780 /* Defined in lread.c. */
2781 extern Lisp_Object Qvariable_documentation, Qstandard_input;
2782 extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
2783 extern Lisp_Object check_obarray (Lisp_Object);
2784 extern Lisp_Object intern_1 (const char *, ptrdiff_t);
2785 extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t);
2786 extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
2787 #define LOADHIST_ATTACH(x) \
2788 do { \
2789 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \
2790 } while (0)
2791 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
2792 Lisp_Object *, Lisp_Object);
2793 Lisp_Object string_to_number (char const *, int, int);
2794 extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
2795 Lisp_Object);
2796 extern void dir_warning (const char *, Lisp_Object);
2797 extern void close_load_descs (void);
2798 extern void init_obarray (void);
2799 extern void init_lread (void);
2800 extern void syms_of_lread (void);
2802 static inline Lisp_Object
2803 intern (const char *str)
2805 return intern_1 (str, strlen (str));
2808 static inline Lisp_Object
2809 intern_c_string (const char *str)
2811 return intern_c_string_1 (str, strlen (str));
2814 /* Defined in eval.c. */
2815 extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qmacro;
2816 extern Lisp_Object Qinhibit_quit, Qclosure;
2817 extern Lisp_Object Qand_rest;
2818 extern Lisp_Object Vautoload_queue;
2819 extern Lisp_Object Vsignaling_function;
2820 extern Lisp_Object inhibit_lisp_code;
2821 extern int handling_signal;
2822 #if BYTE_MARK_STACK
2823 extern struct catchtag *catchlist;
2824 extern struct handler *handlerlist;
2825 #endif
2826 /* To run a normal hook, use the appropriate function from the list below.
2827 The calling convention:
2829 if (!NILP (Vrun_hooks))
2830 call1 (Vrun_hooks, Qmy_funny_hook);
2832 should no longer be used. */
2833 extern Lisp_Object Vrun_hooks;
2834 extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
2835 extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2836 Lisp_Object (*funcall)
2837 (ptrdiff_t nargs, Lisp_Object *args));
2838 extern _Noreturn void xsignal (Lisp_Object, Lisp_Object);
2839 extern _Noreturn void xsignal0 (Lisp_Object);
2840 extern _Noreturn void xsignal1 (Lisp_Object, Lisp_Object);
2841 extern _Noreturn void xsignal2 (Lisp_Object, Lisp_Object, Lisp_Object);
2842 extern _Noreturn void xsignal3 (Lisp_Object, Lisp_Object, Lisp_Object,
2843 Lisp_Object);
2844 extern _Noreturn void signal_error (const char *, Lisp_Object);
2845 extern Lisp_Object eval_sub (Lisp_Object form);
2846 extern Lisp_Object apply1 (Lisp_Object, Lisp_Object);
2847 extern Lisp_Object call0 (Lisp_Object);
2848 extern Lisp_Object call1 (Lisp_Object, Lisp_Object);
2849 extern Lisp_Object call2 (Lisp_Object, Lisp_Object, Lisp_Object);
2850 extern Lisp_Object call3 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2851 extern Lisp_Object call4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2852 extern Lisp_Object call5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2853 extern Lisp_Object call6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2854 extern Lisp_Object call7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2855 extern Lisp_Object internal_catch (Lisp_Object, Lisp_Object (*) (Lisp_Object), Lisp_Object);
2856 extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_Object);
2857 extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
2858 extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2859 extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2860 extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2861 extern void specbind (Lisp_Object, Lisp_Object);
2862 extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
2863 extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
2864 extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
2865 extern _Noreturn void verror (const char *, va_list)
2866 ATTRIBUTE_FORMAT_PRINTF (1, 0);
2867 extern Lisp_Object un_autoload (Lisp_Object);
2868 extern void init_eval_once (void);
2869 extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object *);
2870 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
2871 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
2872 extern void init_eval (void);
2873 #if BYTE_MARK_STACK
2874 extern void mark_backtrace (void);
2875 #endif
2876 extern void syms_of_eval (void);
2878 /* Defined in editfns.c. */
2879 extern Lisp_Object Qfield;
2880 extern void insert1 (Lisp_Object);
2881 extern Lisp_Object format2 (const char *, Lisp_Object, Lisp_Object);
2882 extern Lisp_Object save_excursion_save (void);
2883 extern Lisp_Object save_restriction_save (void);
2884 extern Lisp_Object save_excursion_restore (Lisp_Object);
2885 extern Lisp_Object save_restriction_restore (Lisp_Object);
2886 extern _Noreturn void time_overflow (void);
2887 extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, int);
2888 extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2889 ptrdiff_t, int);
2890 extern void init_editfns (void);
2891 const char *get_system_name (void);
2892 extern void syms_of_editfns (void);
2893 extern void set_time_zone_rule (const char *);
2895 /* Defined in buffer.c. */
2896 extern int mouse_face_overlay_overlaps (Lisp_Object);
2897 extern _Noreturn void nsberror (Lisp_Object);
2898 extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
2899 extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
2900 extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
2901 extern void report_overlay_modification (Lisp_Object, Lisp_Object, int,
2902 Lisp_Object, Lisp_Object, Lisp_Object);
2903 extern int overlay_touches_p (ptrdiff_t);
2904 extern Lisp_Object Vbuffer_alist;
2905 extern Lisp_Object set_buffer_if_live (Lisp_Object);
2906 extern Lisp_Object other_buffer_safely (Lisp_Object);
2907 extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
2908 extern Lisp_Object get_truename_buffer (Lisp_Object);
2909 extern void init_buffer_once (void);
2910 extern void init_buffer (void);
2911 extern void syms_of_buffer (void);
2912 extern void keys_of_buffer (void);
2914 /* Defined in marker.c. */
2916 extern ptrdiff_t marker_position (Lisp_Object);
2917 extern ptrdiff_t marker_byte_position (Lisp_Object);
2918 extern void clear_charpos_cache (struct buffer *);
2919 extern ptrdiff_t charpos_to_bytepos (ptrdiff_t);
2920 extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
2921 extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
2922 extern void unchain_marker (struct Lisp_Marker *marker);
2923 extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
2924 extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
2925 extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
2926 ptrdiff_t, ptrdiff_t);
2927 extern Lisp_Object build_marker (struct buffer *, ptrdiff_t, ptrdiff_t);
2928 extern void syms_of_marker (void);
2930 /* Defined in fileio.c */
2932 extern Lisp_Object Qfile_error;
2933 extern Lisp_Object Qfile_exists_p;
2934 extern Lisp_Object Qfile_directory_p;
2935 extern Lisp_Object Qinsert_file_contents;
2936 extern Lisp_Object Qfile_name_history;
2937 extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object);
2938 EXFUN (Fread_file_name, 6); /* not a normal DEFUN */
2939 extern Lisp_Object close_file_unwind (Lisp_Object);
2940 extern Lisp_Object restore_point_unwind (Lisp_Object);
2941 extern _Noreturn void report_file_error (const char *, Lisp_Object);
2942 extern int internal_delete_file (Lisp_Object);
2943 extern void syms_of_fileio (void);
2944 extern Lisp_Object make_temp_name (Lisp_Object, int);
2945 extern Lisp_Object Qdelete_file;
2947 /* Defined in search.c */
2948 extern void shrink_regexp_cache (void);
2949 extern void restore_search_regs (void);
2950 extern void record_unwind_save_match_data (void);
2951 struct re_registers;
2952 extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
2953 struct re_registers *,
2954 Lisp_Object, int, int);
2955 extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
2956 extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
2957 ptrdiff_t);
2958 extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
2959 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
2960 ptrdiff_t, ptrdiff_t, Lisp_Object);
2961 extern ptrdiff_t scan_buffer (int, ptrdiff_t, ptrdiff_t, ptrdiff_t,
2962 ptrdiff_t *, int);
2963 extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
2964 EMACS_INT, int);
2965 extern ptrdiff_t find_next_newline (ptrdiff_t, int);
2966 extern ptrdiff_t find_next_newline_no_quit (ptrdiff_t, ptrdiff_t);
2967 extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t);
2968 extern void syms_of_search (void);
2969 extern void clear_regexp_cache (void);
2971 /* Defined in minibuf.c. */
2973 extern Lisp_Object Qcompletion_ignore_case;
2974 extern Lisp_Object Vminibuffer_list;
2975 extern Lisp_Object last_minibuf_string;
2976 extern Lisp_Object get_minibuffer (EMACS_INT);
2977 extern void init_minibuf_once (void);
2978 extern void syms_of_minibuf (void);
2980 /* Defined in callint.c. */
2982 extern Lisp_Object Qminus, Qplus;
2983 extern Lisp_Object Qwhen;
2984 extern Lisp_Object Qcall_interactively, Qmouse_leave_buffer_hook;
2985 extern void syms_of_callint (void);
2987 /* Defined in casefiddle.c. */
2989 extern Lisp_Object Qidentity;
2990 extern void syms_of_casefiddle (void);
2991 extern void keys_of_casefiddle (void);
2993 /* Defined in casetab.c. */
2995 extern void init_casetab_once (void);
2996 extern void syms_of_casetab (void);
2998 /* Defined in keyboard.c. */
3000 extern Lisp_Object echo_message_buffer;
3001 extern struct kboard *echo_kboard;
3002 extern void cancel_echoing (void);
3003 extern Lisp_Object Qdisabled, QCfilter;
3004 extern Lisp_Object Qup, Qdown, Qbottom;
3005 extern Lisp_Object Qtop;
3006 extern Lisp_Object last_undo_boundary;
3007 extern int input_pending;
3008 extern Lisp_Object menu_bar_items (Lisp_Object);
3009 extern Lisp_Object tool_bar_items (Lisp_Object, int *);
3010 extern void discard_mouse_events (void);
3011 extern Lisp_Object pending_funcalls;
3012 extern int detect_input_pending (void);
3013 extern int detect_input_pending_ignore_squeezables (void);
3014 extern int detect_input_pending_run_timers (int);
3015 extern void safe_run_hooks (Lisp_Object);
3016 extern void cmd_error_internal (Lisp_Object, const char *);
3017 extern Lisp_Object command_loop_1 (void);
3018 extern Lisp_Object recursive_edit_1 (void);
3019 extern void record_auto_save (void);
3020 #ifdef SIGDANGER
3021 extern void force_auto_save_soon (void);
3022 #endif
3023 extern void init_keyboard (void);
3024 extern void syms_of_keyboard (void);
3025 extern void keys_of_keyboard (void);
3027 /* Defined in indent.c. */
3028 extern ptrdiff_t current_column (void);
3029 extern void invalidate_current_column (void);
3030 extern int indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3031 extern void syms_of_indent (void);
3033 /* Defined in frame.c. */
3034 extern Lisp_Object Qonly;
3035 extern Lisp_Object Qvisible;
3036 extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
3037 extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
3038 extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
3039 #if HAVE_NS
3040 extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
3041 #endif
3042 extern Lisp_Object frame_buffer_predicate (Lisp_Object);
3043 extern void frames_discard_buffer (Lisp_Object);
3044 extern void syms_of_frame (void);
3046 /* Defined in emacs.c. */
3047 extern char **initial_argv;
3048 extern int initial_argc;
3049 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
3050 extern int display_arg;
3051 #endif
3052 extern Lisp_Object decode_env_path (const char *, const char *);
3053 extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3054 extern Lisp_Object Qfile_name_handler_alist;
3055 #ifdef FLOAT_CATCH_SIGILL
3056 extern void fatal_error_signal (int);
3057 #endif
3058 extern Lisp_Object Qkill_emacs;
3059 #if HAVE_SETLOCALE
3060 void fixup_locale (void);
3061 void synchronize_system_messages_locale (void);
3062 void synchronize_system_time_locale (void);
3063 #else
3064 #define setlocale(category, locale)
3065 #define fixup_locale()
3066 #define synchronize_system_messages_locale()
3067 #define synchronize_system_time_locale()
3068 #endif
3069 void shut_down_emacs (int, int, Lisp_Object);
3070 /* Nonzero means don't do interactive redisplay and don't change tty modes. */
3071 extern int noninteractive;
3073 /* Nonzero means remove site-lisp directories from load-path. */
3074 extern int no_site_lisp;
3076 /* Pipe used to send exit notification to the daemon parent at
3077 startup. */
3078 extern int daemon_pipe[2];
3079 #define IS_DAEMON (daemon_pipe[1] != 0)
3081 /* Nonzero means don't do use window-system-specific display code. */
3082 extern int inhibit_window_system;
3083 /* Nonzero means that a filter or a sentinel is running. */
3084 extern int running_asynch_code;
3086 /* Defined in process.c. */
3087 extern Lisp_Object QCtype, Qlocal;
3088 extern Lisp_Object Qprocessp;
3089 extern void kill_buffer_processes (Lisp_Object);
3090 extern int wait_reading_process_output (intmax_t, int, int, int,
3091 Lisp_Object,
3092 struct Lisp_Process *,
3093 int);
3094 /* Max value for the first argument of wait_reading_process_output. */
3095 #if __GNUC__ == 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 5)
3096 /* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.3.
3097 The bug merely causes a bogus warning, but the warning is annoying. */
3098 # define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX)
3099 #else
3100 # define WAIT_READING_MAX INTMAX_MAX
3101 #endif
3102 extern void add_keyboard_wait_descriptor (int);
3103 extern void delete_keyboard_wait_descriptor (int);
3104 #ifdef HAVE_GPM
3105 extern void add_gpm_wait_descriptor (int);
3106 extern void delete_gpm_wait_descriptor (int);
3107 #endif
3108 extern void close_process_descs (void);
3109 extern void init_process_emacs (void);
3110 extern void syms_of_process (void);
3111 extern void setup_process_coding_systems (Lisp_Object);
3113 #ifndef DOS_NT
3114 _Noreturn
3115 #endif
3116 extern int child_setup (int, int, int, char **, int, Lisp_Object);
3117 extern void init_callproc_1 (void);
3118 extern void init_callproc (void);
3119 extern void set_initial_environment (void);
3120 extern void syms_of_callproc (void);
3122 /* Defined in doc.c */
3123 extern Lisp_Object Qfunction_documentation;
3124 extern Lisp_Object read_doc_string (Lisp_Object);
3125 extern Lisp_Object get_doc_string (Lisp_Object, int, int);
3126 extern void syms_of_doc (void);
3127 extern int read_bytecode_char (int);
3129 /* Defined in bytecode.c */
3130 extern Lisp_Object Qbytecode;
3131 extern void syms_of_bytecode (void);
3132 extern struct byte_stack *byte_stack_list;
3133 #if BYTE_MARK_STACK
3134 extern void mark_byte_stack (void);
3135 #endif
3136 extern void unmark_byte_stack (void);
3137 extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
3138 Lisp_Object, ptrdiff_t, Lisp_Object *);
3140 /* Defined in macros.c */
3141 extern Lisp_Object Qexecute_kbd_macro;
3142 extern void init_macros (void);
3143 extern void syms_of_macros (void);
3145 /* Defined in undo.c */
3146 extern Lisp_Object Qapply;
3147 extern Lisp_Object Qinhibit_read_only;
3148 extern void truncate_undo_list (struct buffer *);
3149 extern void record_marker_adjustment (Lisp_Object, ptrdiff_t);
3150 extern void record_insert (ptrdiff_t, ptrdiff_t);
3151 extern void record_delete (ptrdiff_t, Lisp_Object);
3152 extern void record_first_change (void);
3153 extern void record_change (ptrdiff_t, ptrdiff_t);
3154 extern void record_property_change (ptrdiff_t, ptrdiff_t,
3155 Lisp_Object, Lisp_Object,
3156 Lisp_Object);
3157 extern void syms_of_undo (void);
3158 /* Defined in textprop.c */
3159 extern Lisp_Object Qfont, Qmouse_face;
3160 extern Lisp_Object Qinsert_in_front_hooks, Qinsert_behind_hooks;
3161 extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
3162 extern Lisp_Object Qminibuffer_prompt;
3164 extern void report_interval_modification (Lisp_Object, Lisp_Object);
3166 /* Defined in menu.c */
3167 extern void syms_of_menu (void);
3169 /* Defined in xmenu.c */
3170 extern void syms_of_xmenu (void);
3172 /* Defined in termchar.h */
3173 struct tty_display_info;
3175 /* Defined in termhooks.h */
3176 struct terminal;
3178 /* Defined in sysdep.c */
3179 #ifndef HAVE_GET_CURRENT_DIR_NAME
3180 extern char *get_current_dir_name (void);
3181 #endif
3182 extern void stuff_char (char c);
3183 extern void init_sigio (int);
3184 extern void sys_subshell (void);
3185 extern void sys_suspend (void);
3186 extern void discard_tty_input (void);
3187 extern void init_sys_modes (struct tty_display_info *);
3188 extern void reset_sys_modes (struct tty_display_info *);
3189 extern void init_all_sys_modes (void);
3190 extern void reset_all_sys_modes (void);
3191 extern void wait_for_termination (pid_t);
3192 extern void interruptible_wait_for_termination (pid_t);
3193 extern void flush_pending_output (int) ATTRIBUTE_CONST;
3194 extern void child_setup_tty (int);
3195 extern void setup_pty (int);
3196 extern int set_window_size (int, int, int);
3197 extern EMACS_INT get_random (void);
3198 extern void seed_random (long);
3199 extern int emacs_open (const char *, int, int);
3200 extern int emacs_close (int);
3201 extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
3202 extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
3203 enum { READLINK_BUFSIZE = 1024 };
3204 extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]);
3206 extern void unlock_all_files (void);
3207 extern void lock_file (Lisp_Object);
3208 extern void unlock_file (Lisp_Object);
3209 extern void unlock_buffer (struct buffer *);
3210 extern void syms_of_filelock (void);
3212 /* Defined in sound.c */
3213 extern void syms_of_sound (void);
3215 /* Defined in category.c */
3216 extern void init_category_once (void);
3217 extern Lisp_Object char_category_set (int);
3218 extern void syms_of_category (void);
3220 /* Defined in ccl.c */
3221 extern void syms_of_ccl (void);
3223 /* Defined in dired.c */
3224 extern void syms_of_dired (void);
3225 extern Lisp_Object directory_files_internal (Lisp_Object, Lisp_Object,
3226 Lisp_Object, Lisp_Object,
3227 int, Lisp_Object);
3229 /* Defined in term.c */
3230 extern int *char_ins_del_vector;
3231 extern void mark_ttys (void);
3232 extern void syms_of_term (void);
3233 extern _Noreturn void fatal (const char *msgid, ...)
3234 ATTRIBUTE_FORMAT_PRINTF (1, 2);
3236 /* Defined in terminal.c */
3237 extern void syms_of_terminal (void);
3239 /* Defined in font.c */
3240 extern void syms_of_font (void);
3241 extern void init_font (void);
3243 #ifdef HAVE_WINDOW_SYSTEM
3244 /* Defined in fontset.c */
3245 extern void syms_of_fontset (void);
3247 /* Defined in xfns.c, w32fns.c, or macfns.c */
3248 extern Lisp_Object Qfont_param;
3249 #endif
3251 /* Defined in xfaces.c */
3252 extern Lisp_Object Qdefault, Qtool_bar, Qfringe;
3253 extern Lisp_Object Qheader_line, Qscroll_bar, Qcursor;
3254 extern Lisp_Object Qmode_line_inactive;
3255 extern Lisp_Object Qface;
3256 extern Lisp_Object Qnormal;
3257 extern Lisp_Object QCfamily, QCweight, QCslant;
3258 extern Lisp_Object QCheight, QCname, QCwidth, QCforeground, QCbackground;
3259 extern Lisp_Object Vface_alternative_font_family_alist;
3260 extern Lisp_Object Vface_alternative_font_registry_alist;
3261 extern void syms_of_xfaces (void);
3263 #ifdef HAVE_X_WINDOWS
3264 /* Defined in xfns.c */
3265 extern void syms_of_xfns (void);
3267 /* Defined in xsmfns.c */
3268 extern void syms_of_xsmfns (void);
3270 /* Defined in xselect.c */
3271 extern void syms_of_xselect (void);
3273 /* Defined in xterm.c */
3274 extern void syms_of_xterm (void);
3275 #endif /* HAVE_X_WINDOWS */
3277 #ifdef HAVE_WINDOW_SYSTEM
3278 /* Defined in xterm.c, nsterm.m, w32term.c */
3279 extern char *x_get_keysym_name (int);
3280 #endif /* HAVE_WINDOW_SYSTEM */
3282 #ifdef HAVE_LIBXML2
3283 /* Defined in xml.c */
3284 extern void syms_of_xml (void);
3285 extern void xml_cleanup_parser (void);
3286 #endif
3288 #ifdef HAVE_MENUS
3289 /* Defined in (x|w32)fns.c, nsfns.m... */
3290 extern int have_menus_p (void);
3291 #endif
3293 #ifdef HAVE_DBUS
3294 /* Defined in dbusbind.c */
3295 void syms_of_dbusbind (void);
3296 #endif
3298 #ifdef DOS_NT
3299 /* Defined in msdos.c, w32.c */
3300 extern char *emacs_root_dir (void);
3301 #endif /* DOS_NT */
3303 /* Nonzero means Emacs has already been initialized.
3304 Used during startup to detect startup of dumped Emacs. */
3305 extern int initialized;
3307 extern int immediate_quit; /* Nonzero means ^G can quit instantly */
3309 extern void *xmalloc (size_t);
3310 extern void *xzalloc (size_t);
3311 extern void *xrealloc (void *, size_t);
3312 extern void xfree (void *);
3313 extern void *xnmalloc (ptrdiff_t, ptrdiff_t);
3314 extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
3315 extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
3317 extern char *xstrdup (const char *);
3319 extern char *egetenv (const char *);
3321 /* Set up the name of the machine we're running on. */
3322 extern void init_system_name (void);
3324 /* Some systems (e.g., NT) use a different path separator than Unix,
3325 in addition to a device separator. Set the path separator
3326 to '/', and don't test for a device separator in IS_ANY_SEP. */
3328 #define DIRECTORY_SEP '/'
3329 #ifndef IS_DIRECTORY_SEP
3330 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
3331 #endif
3332 #ifndef IS_DEVICE_SEP
3333 #ifndef DEVICE_SEP
3334 #define IS_DEVICE_SEP(_c_) 0
3335 #else
3336 #define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP)
3337 #endif
3338 #endif
3339 #ifndef IS_ANY_SEP
3340 #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
3341 #endif
3343 #define SWITCH_ENUM_CAST(x) (x)
3345 /* Use this to suppress gcc's warnings. */
3346 #ifdef lint
3348 /* Use CODE only if lint checking is in effect. */
3349 # define IF_LINT(Code) Code
3351 /* Assume that the expression COND is true. This differs in intent
3352 from 'assert', as it is a message from the programmer to the compiler. */
3353 # define lint_assume(cond) ((cond) ? (void) 0 : abort ())
3355 #else
3356 # define IF_LINT(Code) /* empty */
3357 # define lint_assume(cond) ((void) (0 && (cond)))
3358 #endif
3360 /* The ubiquitous min and max macros. */
3362 #ifdef max
3363 #undef max
3364 #undef min
3365 #endif
3366 #define min(a, b) ((a) < (b) ? (a) : (b))
3367 #define max(a, b) ((a) > (b) ? (a) : (b))
3369 /* We used to use `abs', but that clashes with system headers on some
3370 platforms, and using a name reserved by Standard C is a bad idea
3371 anyway. */
3372 #if !defined (eabs)
3373 #define eabs(x) ((x) < 0 ? -(x) : (x))
3374 #endif
3376 /* Return a fixnum or float, depending on whether VAL fits in a Lisp
3377 fixnum. */
3379 #define make_fixnum_or_float(val) \
3380 (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
3383 /* Checks the `cycle check' variable CHECK to see if it indicates that
3384 EL is part of a cycle; CHECK must be either Qnil or a value returned
3385 by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of
3386 elements after which a cycle might be suspected; after that many
3387 elements, this macro begins consing in order to keep more precise
3388 track of elements.
3390 Returns nil if a cycle was detected, otherwise a new value for CHECK
3391 that includes EL.
3393 CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so
3394 the caller should make sure that's ok. */
3396 #define CYCLE_CHECK(check, el, suspicious) \
3397 (NILP (check) \
3398 ? make_number (0) \
3399 : (INTEGERP (check) \
3400 ? (XFASTINT (check) < (suspicious) \
3401 ? make_number (XFASTINT (check) + 1) \
3402 : Fcons (el, Qnil)) \
3403 : (!NILP (Fmemq ((el), (check))) \
3404 ? Qnil \
3405 : Fcons ((el), (check)))))
3408 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
3409 larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */
3411 #define MAX_ALLOCA 16*1024
3413 extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3415 #define USE_SAFE_ALLOCA \
3416 ptrdiff_t sa_count = SPECPDL_INDEX (); int sa_must_free = 0
3418 /* SAFE_ALLOCA allocates a simple buffer. */
3420 #define SAFE_ALLOCA(buf, type, size) \
3421 do { \
3422 if ((size) < MAX_ALLOCA) \
3423 buf = (type) alloca (size); \
3424 else \
3426 buf = xmalloc (size); \
3427 sa_must_free = 1; \
3428 record_unwind_protect (safe_alloca_unwind, \
3429 make_save_value (buf, 0)); \
3431 } while (0)
3433 /* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
3434 NITEMS items, each of the same type as *BUF. MULTIPLIER must
3435 positive. The code is tuned for MULTIPLIER being a constant. */
3437 #define SAFE_NALLOCA(buf, multiplier, nitems) \
3438 do { \
3439 if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \
3440 (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \
3441 else \
3443 (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
3444 sa_must_free = 1; \
3445 record_unwind_protect (safe_alloca_unwind, \
3446 make_save_value (buf, 0)); \
3448 } while (0)
3450 /* SAFE_FREE frees xmalloced memory and enables GC as needed. */
3452 #define SAFE_FREE() \
3453 do { \
3454 if (sa_must_free) { \
3455 sa_must_free = 0; \
3456 unbind_to (sa_count, Qnil); \
3458 } while (0)
3461 /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */
3463 #define SAFE_ALLOCA_LISP(buf, nelt) \
3464 do { \
3465 if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object)) \
3466 buf = (Lisp_Object *) alloca ((nelt) * sizeof (Lisp_Object)); \
3467 else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
3469 Lisp_Object arg_; \
3470 buf = xmalloc ((nelt) * sizeof (Lisp_Object)); \
3471 arg_ = make_save_value (buf, nelt); \
3472 XSAVE_VALUE (arg_)->dogc = 1; \
3473 sa_must_free = 1; \
3474 record_unwind_protect (safe_alloca_unwind, arg_); \
3476 else \
3477 memory_full (SIZE_MAX); \
3478 } while (0)
3481 #include "globals.h"
3483 /* Check whether it's time for GC, and run it if so. */
3485 static inline void
3486 maybe_gc (void)
3488 if ((consing_since_gc > gc_cons_threshold
3489 && consing_since_gc > gc_relative_threshold)
3490 || (!NILP (Vmemory_full)
3491 && consing_since_gc > memory_full_cons_threshold))
3492 Fgarbage_collect ();
3495 #endif /* EMACS_LISP_H */