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