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