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