* src/alloc.c (mark_object): Revert part of last patch to use `switch'.
[bpt/emacs.git] / src / lisp.h
... / ...
CommitLineData
1/* Fundamental definitions for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985-1987, 1993-1995, 1997-2012
3 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
34extern 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. */
66enum
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
81typedef intmax_t printmax_t;
82typedef uintmax_t uprintmax_t;
83# define pMd PRIdMAX
84# define pMu PRIuMAX
85#else
86typedef EMACS_INT printmax_t;
87typedef 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
116extern _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. */
126extern 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
237enum 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. */
271enum 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. */
287enum 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
298typedef struct { EMACS_INT i; } Lisp_Object;
299
300#define XLI(o) (o).i
301static inline Lisp_Object
302XIL (EMACS_INT i)
303{
304 Lisp_Object o = { i };
305 return o;
306}
307
308static inline Lisp_Object
309LISP_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
320typedef 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? */
342enum 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
461static inline ptrdiff_t
462clip_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
605typedef 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
614struct 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
689struct Lisp_String;
690extern 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
735struct 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>. */
750struct 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
768struct 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
874extern const int chartab_size[4];
875
876struct Lisp_Sub_Char_Table;
877
878struct 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
909struct 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. */
930struct 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
949struct 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
978enum symbol_interned
979{
980 SYMBOL_UNINTERNED = 0,
981 SYMBOL_INTERNED = 1,
982 SYMBOL_INTERNED_IN_INITIAL_OBARRAY = 2
983};
984
985enum symbol_redirect
986{
987 SYMBOL_PLAINVAL = 4,
988 SYMBOL_VARALIAS = 1,
989 SYMBOL_LOCALIZED = 2,
990 SYMBOL_FORWARDED = 3
991};
992
993struct 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
1089struct 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
1213struct 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
1220struct 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. */
1263struct 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. */
1284struct 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. */
1298struct 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
1309union 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. */
1322struct 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. */
1332struct 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. */
1342struct 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. */
1350struct 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
1381struct 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. */
1417struct Lisp_Kboard_Objfwd
1418 {
1419 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Kboard_Obj */
1420 int offset;
1421 };
1422
1423union 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. */
1433struct 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
1459typedef 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
1494typedef 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. */
1551typedef 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. */
1862extern void defsubr (struct Lisp_Subr *);
1863
1864#define MANY -2
1865#define UNEVALLED -1
1866
1867extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *);
1868extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *);
1869extern void defvar_bool (struct Lisp_Boolfwd *, const char *, int *);
1870extern void defvar_int (struct Lisp_Intfwd *, const char *, EMACS_INT *);
1871extern 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
1945typedef Lisp_Object (*specbinding_func) (Lisp_Object);
1946
1947struct 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
1954extern struct specbinding *specpdl;
1955extern struct specbinding *specpdl_ptr;
1956extern ptrdiff_t specpdl_size;
1957
1958#define SPECPDL_INDEX() (specpdl_ptr - specpdl)
1959
1960/* Everything needed to describe an active condition case. */
1961struct 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
2002struct 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
2018extern 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. */
2022extern 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
2041extern void process_pending_signals (void);
2042extern 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
2050extern 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
2063extern Lisp_Object Vascii_downcase_table;
2064extern Lisp_Object Vascii_canon_table;
2065\f
2066/* Number of bytes of structure consed since last GC. */
2067
2068extern EMACS_INT consing_since_gc;
2069
2070extern EMACS_INT gc_relative_threshold;
2071
2072extern 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
2087extern struct gcpro *gcprolist;
2088
2089struct 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
2193extern 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) \
2256do \
2257 { \
2258 Lisp_Object ret_ungc_val; \
2259 ret_ungc_val = (expr); \
2260 UNGCPRO; \
2261 return ret_ungc_val; \
2262 } \
2263while (0)
2264
2265/* Call staticpro (&var) to protect static variable `var'. */
2266
2267void 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. */
2277struct window;
2278struct frame;
2279
2280/* Defined in data.c. */
2281extern Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
2282extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
2283extern Lisp_Object Qerror, Qquit, Qargs_out_of_range;
2284extern Lisp_Object Qvoid_variable, Qvoid_function;
2285extern Lisp_Object Qinvalid_read_syntax;
2286extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
2287extern Lisp_Object Quser_error, Qend_of_file, Qarith_error, Qmark_inactive;
2288extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
2289extern Lisp_Object Qtext_read_only;
2290extern Lisp_Object Qinteractive_form;
2291extern Lisp_Object Qcircular_list;
2292extern Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp;
2293extern Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
2294extern Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
2295extern Lisp_Object Qbuffer_or_string_p;
2296extern Lisp_Object Qfboundp;
2297extern Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
2298
2299extern Lisp_Object Qcdr;
2300
2301extern Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
2302extern Lisp_Object Qoverflow_error, Qunderflow_error;
2303
2304extern Lisp_Object Qfloatp;
2305extern Lisp_Object Qnumberp, Qnumber_or_marker_p;
2306
2307extern Lisp_Object Qinteger;
2308
2309extern Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
2310
2311EXFUN (Finteractive_form, 1);
2312EXFUN (Fbyteorder, 0);
2313
2314/* Defined in frame.c */
2315extern Lisp_Object Qframep;
2316
2317/* Defined in data.c */
2318EXFUN (Fcar, 1);
2319EXFUN (Fcar_safe, 1);
2320EXFUN (Fcdr, 1);
2321EXFUN (Fcdr_safe, 1);
2322EXFUN (Fsetcar, 2);
2323EXFUN (Fsetcdr, 2);
2324EXFUN (Fboundp, 1);
2325EXFUN (Ffboundp, 1);
2326EXFUN (Fsymbol_function, 1);
2327EXFUN (Fsymbol_name, 1);
2328extern Lisp_Object indirect_function (Lisp_Object);
2329EXFUN (Findirect_function, 2);
2330EXFUN (Ffset, 2);
2331EXFUN (Fsymbol_value, 1);
2332extern Lisp_Object find_symbol_value (Lisp_Object);
2333EXFUN (Fset, 2);
2334EXFUN (Fdefault_value, 1);
2335EXFUN (Fset_default, 2);
2336EXFUN (Fdefault_boundp, 1);
2337EXFUN (Fmake_local_variable, 1);
2338EXFUN (Flocal_variable_p, 2);
2339
2340EXFUN (Faref, 2);
2341EXFUN (Faset, 3);
2342
2343EXFUN (Fstring_to_number, 2);
2344EXFUN (Fnumber_to_string, 1);
2345EXFUN (Fgtr, 2);
2346EXFUN (Flss, 2);
2347EXFUN (Fgeq, 2);
2348EXFUN (Fleq, 2);
2349EXFUN (Fzerop, 1);
2350EXFUN (Fplus, MANY);
2351EXFUN (Fminus, MANY);
2352EXFUN (Ftimes, MANY);
2353EXFUN (Fquo, MANY);
2354EXFUN (Frem, 2);
2355EXFUN (Fmax, MANY);
2356EXFUN (Fmin, MANY);
2357
2358EXFUN (Fadd1, 1);
2359EXFUN (Fsub1, 1);
2360EXFUN (Fmake_variable_buffer_local, 1);
2361
2362/* Convert the integer I to an Emacs representation, either the integer
2363 itself, or a cons of two or three integers, or if all else fails a float.
2364 I should not have side effects. */
2365#define INTEGER_TO_CONS(i) \
2366 (! FIXNUM_OVERFLOW_P (i) \
2367 ? make_number (i) \
2368 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16) \
2369 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16)) \
2370 && FIXNUM_OVERFLOW_P ((i) >> 16)) \
2371 ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff)) \
2372 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16 >> 24) \
2373 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16 >> 24)) \
2374 && FIXNUM_OVERFLOW_P ((i) >> 16 >> 24)) \
2375 ? Fcons (make_number ((i) >> 16 >> 24), \
2376 Fcons (make_number ((i) >> 16 & 0xffffff), \
2377 make_number ((i) & 0xffff))) \
2378 : make_float (i))
2379
2380/* Convert the Emacs representation CONS back to an integer of type
2381 TYPE, storing the result the variable VAR. Signal an error if CONS
2382 is not a valid representation or is out of range for TYPE. */
2383#define CONS_TO_INTEGER(cons, type, var) \
2384 (TYPE_SIGNED (type) \
2385 ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
2386 : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
2387extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
2388extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
2389
2390extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
2391extern _Noreturn void args_out_of_range (Lisp_Object, Lisp_Object);
2392extern _Noreturn void args_out_of_range_3 (Lisp_Object, Lisp_Object,
2393 Lisp_Object);
2394extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
2395extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *);
2396extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, int);
2397extern void syms_of_data (void);
2398extern void init_data (void);
2399extern void swap_in_global_binding (struct Lisp_Symbol *);
2400
2401/* Defined in cmds.c */
2402EXFUN (Fend_of_line, 1);
2403EXFUN (Fforward_char, 1);
2404EXFUN (Fforward_line, 1);
2405extern void syms_of_cmds (void);
2406extern void keys_of_cmds (void);
2407
2408/* Defined in coding.c */
2409extern Lisp_Object Qcharset;
2410EXFUN (Fcoding_system_p, 1);
2411EXFUN (Fcoding_system_base, 1);
2412EXFUN (Fcoding_system_eol_type, 1);
2413EXFUN (Fcheck_coding_system, 1);
2414EXFUN (Fread_coding_system, 2);
2415EXFUN (Fread_non_nil_coding_system, 1);
2416EXFUN (Ffind_operation_coding_system, MANY);
2417EXFUN (Fdecode_coding_string, 4);
2418extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
2419 ptrdiff_t, int, int, Lisp_Object);
2420extern void init_coding (void);
2421extern void init_coding_once (void);
2422extern void syms_of_coding (void);
2423
2424/* Defined in character.c */
2425EXFUN (Fchar_width, 1);
2426EXFUN (Fstring, MANY);
2427extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
2428extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
2429extern int multibyte_char_to_unibyte (int);
2430extern int multibyte_char_to_unibyte_safe (int);
2431extern void init_character_once (void);
2432extern void syms_of_character (void);
2433
2434/* Defined in charset.c */
2435extern void init_charset (void);
2436extern void init_charset_once (void);
2437extern void syms_of_charset (void);
2438/* Structure forward declarations. */
2439struct charset;
2440
2441/* Defined in composite.c */
2442extern void syms_of_composite (void);
2443
2444/* Defined in syntax.c */
2445EXFUN (Fforward_word, 1);
2446EXFUN (Fskip_chars_forward, 2);
2447EXFUN (Fskip_chars_backward, 2);
2448extern void init_syntax_once (void);
2449extern void syms_of_syntax (void);
2450
2451/* Defined in fns.c */
2452extern Lisp_Object QCrehash_size, QCrehash_threshold;
2453enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
2454extern EMACS_INT next_almost_prime (EMACS_INT);
2455extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
2456extern void sweep_weak_hash_tables (void);
2457extern Lisp_Object Qcursor_in_echo_area;
2458extern Lisp_Object Qstring_lessp;
2459extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql;
2460EMACS_UINT hash_string (char const *, ptrdiff_t);
2461EMACS_UINT sxhash (Lisp_Object, int);
2462Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object,
2463 Lisp_Object, Lisp_Object, Lisp_Object,
2464 Lisp_Object);
2465ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
2466ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
2467 EMACS_UINT);
2468void init_weak_hash_tables (void);
2469extern void init_fns (void);
2470EXFUN (Fmake_hash_table, MANY);
2471EXFUN (Fgethash, 3);
2472EXFUN (Fputhash, 3);
2473EXFUN (Fremhash, 2);
2474
2475EXFUN (Fidentity, 1);
2476EXFUN (Flength, 1);
2477EXFUN (Fappend, MANY);
2478EXFUN (Fconcat, MANY);
2479EXFUN (Fvconcat, MANY);
2480EXFUN (Fcopy_sequence, 1);
2481EXFUN (Fstring_make_multibyte, 1);
2482EXFUN (Fstring_make_unibyte, 1);
2483EXFUN (Fstring_as_multibyte, 1);
2484EXFUN (Fstring_as_unibyte, 1);
2485EXFUN (Fstring_to_multibyte, 1);
2486EXFUN (Fsubstring, 3);
2487extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
2488 ptrdiff_t, ptrdiff_t);
2489EXFUN (Fnth, 2);
2490EXFUN (Fnthcdr, 2);
2491EXFUN (Fmemq, 2);
2492EXFUN (Fassq, 2);
2493EXFUN (Fassoc, 2);
2494EXFUN (Felt, 2);
2495EXFUN (Fmember, 2);
2496EXFUN (Frassq, 2);
2497EXFUN (Fdelq, 2);
2498EXFUN (Fdelete, 2);
2499EXFUN (Fsort, 2);
2500EXFUN (Freverse, 1);
2501EXFUN (Fnreverse, 1);
2502EXFUN (Fget, 2);
2503EXFUN (Fput, 3);
2504EXFUN (Fequal, 2);
2505EXFUN (Fnconc, MANY);
2506EXFUN (Fmapcar, 2);
2507EXFUN (Fmapconcat, 3);
2508extern Lisp_Object do_yes_or_no_p (Lisp_Object);
2509EXFUN (Fprovide, 2);
2510extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
2511extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
2512extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
2513extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
2514extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
2515extern void clear_string_char_byte_cache (void);
2516extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
2517extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
2518extern Lisp_Object string_to_multibyte (Lisp_Object);
2519extern Lisp_Object string_make_unibyte (Lisp_Object);
2520EXFUN (Fcopy_alist, 1);
2521EXFUN (Fplist_get, 2);
2522EXFUN (Fplist_put, 3);
2523EXFUN (Fplist_member, 2);
2524EXFUN (Frassoc, 2);
2525EXFUN (Fstring_equal, 2);
2526EXFUN (Fcompare_strings, 7);
2527EXFUN (Fstring_lessp, 2);
2528extern void syms_of_fns (void);
2529
2530/* Defined in floatfns.c */
2531extern double extract_float (Lisp_Object);
2532EXFUN (Ffloat, 1);
2533EXFUN (Ftruncate, 2);
2534extern void init_floatfns (void);
2535extern void syms_of_floatfns (void);
2536extern Lisp_Object fmod_float (Lisp_Object x, Lisp_Object y);
2537
2538/* Defined in fringe.c */
2539extern void syms_of_fringe (void);
2540extern void init_fringe (void);
2541#ifdef HAVE_WINDOW_SYSTEM
2542extern void mark_fringe_data (void);
2543extern void init_fringe_once (void);
2544#endif /* HAVE_WINDOW_SYSTEM */
2545
2546/* Defined in image.c */
2547extern Lisp_Object QCascent, QCmargin, QCrelief;
2548extern Lisp_Object QCconversion;
2549extern int x_bitmap_mask (struct frame *, ptrdiff_t);
2550extern void syms_of_image (void);
2551extern void init_image (void);
2552
2553/* Defined in insdel.c */
2554extern Lisp_Object Qinhibit_modification_hooks;
2555extern void move_gap (ptrdiff_t);
2556extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2557extern _Noreturn void buffer_overflow (void);
2558extern void make_gap (ptrdiff_t);
2559extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
2560 ptrdiff_t, int, int);
2561extern int count_combining_before (const unsigned char *,
2562 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2563extern int count_combining_after (const unsigned char *,
2564 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2565extern void insert (const char *, ptrdiff_t);
2566extern void insert_and_inherit (const char *, ptrdiff_t);
2567extern void insert_1 (const char *, ptrdiff_t, int, int, int);
2568extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
2569 int, int, int);
2570extern void insert_from_gap (ptrdiff_t, ptrdiff_t);
2571extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
2572 ptrdiff_t, ptrdiff_t, int);
2573extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2574extern void insert_char (int);
2575extern void insert_string (const char *);
2576extern void insert_before_markers (const char *, ptrdiff_t);
2577extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
2578extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
2579 ptrdiff_t, ptrdiff_t,
2580 ptrdiff_t, int);
2581extern void del_range (ptrdiff_t, ptrdiff_t);
2582extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, int, int);
2583extern void del_range_byte (ptrdiff_t, ptrdiff_t, int);
2584extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, int);
2585extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
2586 ptrdiff_t, ptrdiff_t, int);
2587extern void modify_region (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2588extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
2589extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
2590extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2591 ptrdiff_t, ptrdiff_t);
2592extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
2593 ptrdiff_t, ptrdiff_t);
2594extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, int, int, int);
2595extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
2596 const char *, ptrdiff_t, ptrdiff_t, int);
2597extern void syms_of_insdel (void);
2598
2599/* Defined in dispnew.c */
2600#if (defined PROFILING \
2601 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
2602_Noreturn void __executable_start (void);
2603#endif
2604extern Lisp_Object selected_frame;
2605extern Lisp_Object Vwindow_system;
2606EXFUN (Fding, 1);
2607EXFUN (Fredraw_frame, 1);
2608void duration_to_sec_usec (double, int *, int *);
2609EXFUN (Fsleep_for, 2);
2610EXFUN (Fredisplay, 1);
2611extern Lisp_Object sit_for (Lisp_Object, int, int);
2612extern void init_display (void);
2613extern void syms_of_display (void);
2614
2615/* Defined in xdisp.c */
2616extern Lisp_Object Qinhibit_point_motion_hooks;
2617extern Lisp_Object Qinhibit_redisplay, Qdisplay;
2618extern Lisp_Object Qmenu_bar_update_hook;
2619extern Lisp_Object Qwindow_scroll_functions;
2620extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
2621extern Lisp_Object Qimage, Qtext, Qboth, Qboth_horiz, Qtext_image_horiz;
2622extern Lisp_Object Qspace, Qcenter, QCalign_to;
2623extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
2624extern Lisp_Object Qleft_margin, Qright_margin;
2625extern Lisp_Object Qglyphless_char;
2626extern Lisp_Object QCdata, QCfile;
2627extern Lisp_Object QCmap;
2628extern Lisp_Object Qrisky_local_variable;
2629extern struct frame *last_glyphless_glyph_frame;
2630extern int last_glyphless_glyph_face_id;
2631extern int last_glyphless_glyph_merged_face_id;
2632extern int noninteractive_need_newline;
2633extern Lisp_Object echo_area_buffer[2];
2634extern void add_to_log (const char *, Lisp_Object, Lisp_Object);
2635extern void check_message_stack (void);
2636extern void setup_echo_area_for_printing (int);
2637extern int push_message (void);
2638extern Lisp_Object pop_message_unwind (Lisp_Object);
2639extern Lisp_Object restore_message_unwind (Lisp_Object);
2640extern void restore_message (void);
2641extern Lisp_Object current_message (void);
2642extern void clear_message (int, int);
2643extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
2644extern void message1 (const char *);
2645extern void message1_nolog (const char *);
2646extern void message2 (const char *, ptrdiff_t, int);
2647extern void message2_nolog (const char *, ptrdiff_t, int);
2648extern void message3 (Lisp_Object, ptrdiff_t, int);
2649extern void message3_nolog (Lisp_Object, ptrdiff_t, int);
2650extern void message_dolog (const char *, ptrdiff_t, int, int);
2651extern void message_with_string (const char *, Lisp_Object, int);
2652extern void message_log_maybe_newline (void);
2653extern void update_echo_area (void);
2654extern void truncate_echo_area (ptrdiff_t);
2655extern void redisplay (void);
2656extern void redisplay_preserve_echo_area (int);
2657extern void prepare_menu_bars (void);
2658
2659void set_frame_cursor_types (struct frame *, Lisp_Object);
2660extern void syms_of_xdisp (void);
2661extern void init_xdisp (void);
2662extern Lisp_Object safe_eval (Lisp_Object);
2663extern int pos_visible_p (struct window *, ptrdiff_t, int *,
2664 int *, int *, int *, int *, int *);
2665
2666/* Defined in xsettings.c */
2667extern void syms_of_xsettings (void);
2668
2669/* Defined in vm-limit.c. */
2670extern void memory_warnings (void *, void (*warnfun) (const char *));
2671
2672/* Defined in alloc.c */
2673extern void check_pure_size (void);
2674extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
2675extern void reset_malloc_hooks (void);
2676extern void uninterrupt_malloc (void);
2677extern void malloc_warning (const char *);
2678extern _Noreturn void memory_full (size_t);
2679extern _Noreturn void buffer_memory_full (ptrdiff_t);
2680extern int survives_gc_p (Lisp_Object);
2681extern void mark_object (Lisp_Object);
2682#if defined REL_ALLOC && !defined SYSTEM_MALLOC
2683extern void refill_memory_reserve (void);
2684#endif
2685extern const char *pending_malloc_warning;
2686extern Lisp_Object *stack_base;
2687EXFUN (Fcons, 2);
2688extern Lisp_Object list1 (Lisp_Object);
2689extern Lisp_Object list2 (Lisp_Object, Lisp_Object);
2690extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object);
2691extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2692extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
2693 Lisp_Object);
2694EXFUN (Flist, MANY);
2695EXFUN (Fmake_list, 2);
2696extern Lisp_Object allocate_misc (void);
2697EXFUN (Fmake_vector, 2);
2698EXFUN (Fvector, MANY);
2699EXFUN (Fmake_symbol, 1);
2700EXFUN (Fmake_marker, 0);
2701extern _Noreturn void string_overflow (void);
2702EXFUN (Fmake_string, 2);
2703extern Lisp_Object make_string (const char *, ptrdiff_t);
2704extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
2705extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
2706extern Lisp_Object make_event_array (int, Lisp_Object *);
2707extern Lisp_Object make_uninit_string (EMACS_INT);
2708extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
2709extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
2710extern Lisp_Object make_specified_string (const char *,
2711 ptrdiff_t, ptrdiff_t, int);
2712EXFUN (Fpurecopy, 1);
2713extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, int);
2714extern Lisp_Object make_pure_c_string (const char *data);
2715
2716/* Make a string from the data at STR, treating it as multibyte if the
2717 data warrants. */
2718
2719static inline Lisp_Object
2720build_string (const char *str)
2721{
2722 return make_string (str, strlen (str));
2723}
2724
2725extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
2726EXFUN (Fgarbage_collect, 0);
2727extern void make_byte_code (struct Lisp_Vector *);
2728EXFUN (Fmake_byte_code, MANY);
2729EXFUN (Fmake_bool_vector, 2);
2730extern Lisp_Object Qchar_table_extra_slots;
2731extern struct Lisp_Vector *allocate_vector (EMACS_INT);
2732extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, int tag);
2733#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
2734 ((typ*) \
2735 allocate_pseudovector \
2736 (VECSIZE (typ), PSEUDOVECSIZE (typ, field), tag))
2737extern struct Lisp_Hash_Table *allocate_hash_table (void);
2738extern struct window *allocate_window (void);
2739extern struct frame *allocate_frame (void);
2740extern struct Lisp_Process *allocate_process (void);
2741extern struct terminal *allocate_terminal (void);
2742extern int gc_in_progress;
2743extern int abort_on_gc;
2744extern Lisp_Object make_float (double);
2745extern void display_malloc_warning (void);
2746extern ptrdiff_t inhibit_garbage_collection (void);
2747extern Lisp_Object make_save_value (void *, ptrdiff_t);
2748extern void free_marker (Lisp_Object);
2749extern void free_cons (struct Lisp_Cons *);
2750extern void init_alloc_once (void);
2751extern void init_alloc (void);
2752extern void syms_of_alloc (void);
2753extern struct buffer * allocate_buffer (void);
2754extern int valid_lisp_object_p (Lisp_Object);
2755
2756#ifdef REL_ALLOC
2757/* Defined in ralloc.c */
2758extern void *r_alloc (void **, size_t);
2759extern void r_alloc_free (void **);
2760extern void *r_re_alloc (void **, size_t);
2761extern void r_alloc_reset_variable (void **, void **);
2762extern void r_alloc_inhibit_buffer_relocation (int);
2763#endif
2764
2765/* Defined in chartab.c */
2766EXFUN (Fmake_char_table, 2);
2767EXFUN (Fset_char_table_parent, 2);
2768EXFUN (Fchar_table_extra_slot, 2);
2769EXFUN (Fset_char_table_extra_slot, 3);
2770EXFUN (Fset_char_table_range, 3);
2771EXFUN (Foptimize_char_table, 2);
2772extern Lisp_Object copy_char_table (Lisp_Object);
2773extern Lisp_Object char_table_ref (Lisp_Object, int);
2774extern Lisp_Object char_table_ref_and_range (Lisp_Object, int,
2775 int *, int *);
2776extern Lisp_Object char_table_set (Lisp_Object, int, Lisp_Object);
2777extern Lisp_Object char_table_set_range (Lisp_Object, int, int,
2778 Lisp_Object);
2779extern int char_table_translate (Lisp_Object, int);
2780extern void map_char_table (void (*) (Lisp_Object, Lisp_Object,
2781 Lisp_Object),
2782 Lisp_Object, Lisp_Object, Lisp_Object);
2783extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object),
2784 Lisp_Object, Lisp_Object,
2785 Lisp_Object, struct charset *,
2786 unsigned, unsigned);
2787extern Lisp_Object uniprop_table (Lisp_Object);
2788extern void syms_of_chartab (void);
2789
2790/* Defined in print.c */
2791extern Lisp_Object Vprin1_to_string_buffer;
2792extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
2793EXFUN (Fprin1, 2);
2794EXFUN (Fprin1_to_string, 2);
2795EXFUN (Fterpri, 1);
2796EXFUN (Fprint, 2);
2797EXFUN (Ferror_message_string, 1);
2798extern Lisp_Object Qstandard_output;
2799extern Lisp_Object Qexternal_debugging_output;
2800extern void temp_output_buffer_setup (const char *);
2801extern int print_level;
2802extern Lisp_Object Qprint_escape_newlines;
2803extern void write_string (const char *, int);
2804extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
2805 Lisp_Object);
2806extern Lisp_Object internal_with_output_to_temp_buffer
2807 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
2808#define FLOAT_TO_STRING_BUFSIZE 350
2809extern int float_to_string (char *, double);
2810extern void syms_of_print (void);
2811
2812/* Defined in doprnt.c */
2813extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
2814 va_list);
2815extern ptrdiff_t esprintf (char *, char const *, ...)
2816 ATTRIBUTE_FORMAT_PRINTF (2, 3);
2817extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
2818 char const *, ...)
2819 ATTRIBUTE_FORMAT_PRINTF (5, 6);
2820extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
2821 char const *, va_list)
2822 ATTRIBUTE_FORMAT_PRINTF (5, 0);
2823
2824/* Defined in lread.c. */
2825extern Lisp_Object Qvariable_documentation, Qstandard_input;
2826extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
2827EXFUN (Fread, 1);
2828EXFUN (Fread_from_string, 3);
2829EXFUN (Fintern, 2);
2830EXFUN (Fintern_soft, 2);
2831EXFUN (Funintern, 2);
2832EXFUN (Fload, 5);
2833EXFUN (Fget_load_suffixes, 0);
2834EXFUN (Fread_char, 3);
2835EXFUN (Fread_event, 3);
2836extern Lisp_Object check_obarray (Lisp_Object);
2837extern Lisp_Object intern (const char *);
2838extern Lisp_Object intern_c_string (const char *);
2839extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
2840#define LOADHIST_ATTACH(x) \
2841 do { \
2842 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \
2843 } while (0)
2844extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
2845 Lisp_Object *, Lisp_Object);
2846Lisp_Object string_to_number (char const *, int, int);
2847extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
2848 Lisp_Object);
2849extern void dir_warning (const char *, Lisp_Object);
2850extern void close_load_descs (void);
2851extern void init_obarray (void);
2852extern void init_lread (void);
2853extern void syms_of_lread (void);
2854
2855/* Defined in eval.c. */
2856extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qmacro;
2857extern Lisp_Object Qinhibit_quit, Qclosure;
2858extern Lisp_Object Qand_rest;
2859extern Lisp_Object Vautoload_queue;
2860extern Lisp_Object Vsignaling_function;
2861extern Lisp_Object inhibit_lisp_code;
2862extern int handling_signal;
2863#if BYTE_MARK_STACK
2864extern struct catchtag *catchlist;
2865extern struct handler *handlerlist;
2866#endif
2867/* To run a normal hook, use the appropriate function from the list below.
2868 The calling convention:
2869
2870 if (!NILP (Vrun_hooks))
2871 call1 (Vrun_hooks, Qmy_funny_hook);
2872
2873 should no longer be used. */
2874extern Lisp_Object Vrun_hooks;
2875EXFUN (Frun_hooks, MANY);
2876EXFUN (Frun_hook_with_args, MANY);
2877EXFUN (Frun_hook_with_args_until_failure, MANY);
2878extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
2879extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2880 Lisp_Object (*funcall)
2881 (ptrdiff_t nargs, Lisp_Object *args));
2882EXFUN (Fprogn, UNEVALLED);
2883EXFUN (Finteractive_p, 0);
2884_Noreturn EXFUN (Fthrow, 2);
2885EXFUN (Fsignal, 2);
2886extern _Noreturn void xsignal (Lisp_Object, Lisp_Object);
2887extern _Noreturn void xsignal0 (Lisp_Object);
2888extern _Noreturn void xsignal1 (Lisp_Object, Lisp_Object);
2889extern _Noreturn void xsignal2 (Lisp_Object, Lisp_Object, Lisp_Object);
2890extern _Noreturn void xsignal3 (Lisp_Object, Lisp_Object, Lisp_Object,
2891 Lisp_Object);
2892extern _Noreturn void signal_error (const char *, Lisp_Object);
2893EXFUN (Fcommandp, 2);
2894EXFUN (Ffunctionp, 1);
2895EXFUN (Feval, 2);
2896extern Lisp_Object eval_sub (Lisp_Object form);
2897EXFUN (Fapply, MANY);
2898EXFUN (Ffuncall, MANY);
2899extern Lisp_Object apply1 (Lisp_Object, Lisp_Object);
2900extern Lisp_Object call0 (Lisp_Object);
2901extern Lisp_Object call1 (Lisp_Object, Lisp_Object);
2902extern Lisp_Object call2 (Lisp_Object, Lisp_Object, Lisp_Object);
2903extern Lisp_Object call3 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2904extern Lisp_Object call4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2905extern Lisp_Object call5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2906extern Lisp_Object call6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2907extern Lisp_Object call7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2908EXFUN (Fdo_auto_save, 2);
2909extern Lisp_Object internal_catch (Lisp_Object, Lisp_Object (*) (Lisp_Object), Lisp_Object);
2910extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_Object);
2911extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
2912extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2913extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2914extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2915extern void specbind (Lisp_Object, Lisp_Object);
2916extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
2917extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
2918extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
2919extern _Noreturn void verror (const char *, va_list)
2920 ATTRIBUTE_FORMAT_PRINTF (1, 0);
2921extern void do_autoload (Lisp_Object, Lisp_Object);
2922extern Lisp_Object un_autoload (Lisp_Object);
2923extern void init_eval_once (void);
2924extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object *);
2925extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
2926extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
2927extern void init_eval (void);
2928#if BYTE_MARK_STACK
2929extern void mark_backtrace (void);
2930#endif
2931extern void syms_of_eval (void);
2932
2933/* Defined in editfns.c */
2934extern Lisp_Object Qfield;
2935EXFUN (Fcurrent_message, 0);
2936EXFUN (Fgoto_char, 1);
2937EXFUN (Fpoint_max_marker, 0);
2938EXFUN (Fpoint, 0);
2939EXFUN (Fpoint_marker, 0);
2940EXFUN (Fline_beginning_position, 1);
2941EXFUN (Fline_end_position, 1);
2942EXFUN (Ffollowing_char, 0);
2943EXFUN (Fprevious_char, 0);
2944EXFUN (Fchar_after, 1);
2945EXFUN (Finsert, MANY);
2946EXFUN (Finsert_char, 3);
2947extern void insert1 (Lisp_Object);
2948EXFUN (Feolp, 0);
2949EXFUN (Feobp, 0);
2950EXFUN (Fbolp, 0);
2951EXFUN (Fbobp, 0);
2952EXFUN (Fformat, MANY);
2953EXFUN (Fmessage, MANY);
2954extern Lisp_Object format2 (const char *, Lisp_Object, Lisp_Object);
2955EXFUN (Fbuffer_substring, 2);
2956EXFUN (Fbuffer_string, 0);
2957extern Lisp_Object save_excursion_save (void);
2958extern Lisp_Object save_restriction_save (void);
2959extern Lisp_Object save_excursion_restore (Lisp_Object);
2960extern Lisp_Object save_restriction_restore (Lisp_Object);
2961EXFUN (Fchar_to_string, 1);
2962EXFUN (Fdelete_region, 2);
2963EXFUN (Fnarrow_to_region, 2);
2964EXFUN (Fwiden, 0);
2965EXFUN (Fuser_login_name, 1);
2966EXFUN (Fsystem_name, 0);
2967extern _Noreturn void time_overflow (void);
2968EXFUN (Fcurrent_time, 0);
2969EXFUN (Fget_internal_run_time, 0);
2970extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, int);
2971extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2972 ptrdiff_t, int);
2973extern void init_editfns (void);
2974const char *get_system_name (void);
2975extern void syms_of_editfns (void);
2976EXFUN (Fconstrain_to_field, 5);
2977EXFUN (Ffield_end, 3);
2978extern void set_time_zone_rule (const char *);
2979
2980/* Defined in buffer.c */
2981extern int mouse_face_overlay_overlaps (Lisp_Object);
2982extern _Noreturn void nsberror (Lisp_Object);
2983EXFUN (Fset_buffer_multibyte, 1);
2984EXFUN (Foverlay_start, 1);
2985EXFUN (Foverlay_end, 1);
2986extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
2987extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
2988extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
2989extern void report_overlay_modification (Lisp_Object, Lisp_Object, int,
2990 Lisp_Object, Lisp_Object, Lisp_Object);
2991extern int overlay_touches_p (ptrdiff_t);
2992extern Lisp_Object Vbuffer_alist;
2993EXFUN (Fget_buffer, 1);
2994EXFUN (Fget_buffer_create, 1);
2995EXFUN (Fgenerate_new_buffer_name, 2);
2996EXFUN (Fset_buffer, 1);
2997extern Lisp_Object set_buffer_if_live (Lisp_Object);
2998EXFUN (Fbarf_if_buffer_read_only, 0);
2999EXFUN (Fcurrent_buffer, 0);
3000EXFUN (Fother_buffer, 3);
3001extern Lisp_Object other_buffer_safely (Lisp_Object);
3002EXFUN (Foverlay_get, 2);
3003EXFUN (Fbuffer_modified_p, 1);
3004EXFUN (Fset_buffer_modified_p, 1);
3005EXFUN (Fkill_buffer, 1);
3006EXFUN (Fkill_all_local_variables, 0);
3007EXFUN (Fbuffer_enable_undo, 1);
3008EXFUN (Ferase_buffer, 0);
3009extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
3010extern Lisp_Object get_truename_buffer (Lisp_Object);
3011extern struct buffer *all_buffers;
3012EXFUN (Fprevious_overlay_change, 1);
3013EXFUN (Fbuffer_file_name, 1);
3014extern void init_buffer_once (void);
3015extern void init_buffer (void);
3016extern void syms_of_buffer (void);
3017extern void keys_of_buffer (void);
3018
3019/* Defined in marker.c */
3020
3021EXFUN (Fmarker_position, 1);
3022EXFUN (Fmarker_buffer, 1);
3023EXFUN (Fcopy_marker, 2);
3024EXFUN (Fset_marker, 3);
3025extern ptrdiff_t marker_position (Lisp_Object);
3026extern ptrdiff_t marker_byte_position (Lisp_Object);
3027extern void clear_charpos_cache (struct buffer *);
3028extern ptrdiff_t charpos_to_bytepos (ptrdiff_t);
3029extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
3030extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
3031extern void unchain_marker (struct Lisp_Marker *marker);
3032extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
3033extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3034extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
3035 ptrdiff_t, ptrdiff_t);
3036extern void syms_of_marker (void);
3037
3038/* Defined in fileio.c */
3039
3040extern Lisp_Object Qfile_error;
3041extern Lisp_Object Qfile_exists_p;
3042extern Lisp_Object Qfile_directory_p;
3043extern Lisp_Object Qinsert_file_contents;
3044extern Lisp_Object Qfile_name_history;
3045EXFUN (Ffind_file_name_handler, 2);
3046EXFUN (Ffile_name_as_directory, 1);
3047EXFUN (Fexpand_file_name, 2);
3048EXFUN (Ffile_name_nondirectory, 1);
3049EXFUN (Fsubstitute_in_file_name, 1);
3050EXFUN (Ffile_symlink_p, 1);
3051EXFUN (Fverify_visited_file_modtime, 1);
3052EXFUN (Ffile_exists_p, 1);
3053EXFUN (Ffile_name_absolute_p, 1);
3054EXFUN (Fdirectory_file_name, 1);
3055EXFUN (Ffile_name_directory, 1);
3056extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object);
3057EXFUN (Ffile_accessible_directory_p, 1);
3058EXFUN (Funhandled_file_name_directory, 1);
3059EXFUN (Ffile_directory_p, 1);
3060EXFUN (Fwrite_region, 7);
3061EXFUN (Ffile_readable_p, 1);
3062EXFUN (Fread_file_name, 6);
3063extern Lisp_Object close_file_unwind (Lisp_Object);
3064extern Lisp_Object restore_point_unwind (Lisp_Object);
3065extern _Noreturn void report_file_error (const char *, Lisp_Object);
3066extern int internal_delete_file (Lisp_Object);
3067extern void syms_of_fileio (void);
3068extern Lisp_Object make_temp_name (Lisp_Object, int);
3069extern Lisp_Object Qdelete_file;
3070
3071/* Defined in search.c */
3072extern void shrink_regexp_cache (void);
3073EXFUN (Fstring_match, 3);
3074extern void restore_search_regs (void);
3075EXFUN (Fmatch_data, 3);
3076EXFUN (Fset_match_data, 2);
3077EXFUN (Fmatch_beginning, 1);
3078EXFUN (Fmatch_end, 1);
3079extern void record_unwind_save_match_data (void);
3080struct re_registers;
3081extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
3082 struct re_registers *,
3083 Lisp_Object, int, int);
3084extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
3085extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *);
3086extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
3087extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
3088 ptrdiff_t, ptrdiff_t, Lisp_Object);
3089extern ptrdiff_t scan_buffer (int, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3090 ptrdiff_t *, int);
3091extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3092 EMACS_INT, int);
3093extern ptrdiff_t find_next_newline (ptrdiff_t, int);
3094extern ptrdiff_t find_next_newline_no_quit (ptrdiff_t, ptrdiff_t);
3095extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3096extern void syms_of_search (void);
3097extern void clear_regexp_cache (void);
3098
3099/* Defined in minibuf.c */
3100
3101extern Lisp_Object Qcompletion_ignore_case;
3102extern Lisp_Object Vminibuffer_list;
3103extern Lisp_Object last_minibuf_string;
3104EXFUN (Fcompleting_read, 8);
3105EXFUN (Fread_from_minibuffer, 7);
3106EXFUN (Fread_variable, 2);
3107EXFUN (Fread_buffer, 3);
3108EXFUN (Fread_minibuffer, 2);
3109EXFUN (Feval_minibuffer, 2);
3110EXFUN (Fread_string, 5);
3111EXFUN (Fassoc_string, 3);
3112extern Lisp_Object get_minibuffer (EMACS_INT);
3113extern void init_minibuf_once (void);
3114extern void syms_of_minibuf (void);
3115
3116/* Defined in callint.c */
3117
3118extern Lisp_Object Qminus, Qplus;
3119extern Lisp_Object Qwhen;
3120extern Lisp_Object Qcall_interactively, Qmouse_leave_buffer_hook;
3121EXFUN (Fprefix_numeric_value, 1);
3122extern void syms_of_callint (void);
3123
3124/* Defined in casefiddle.c */
3125
3126extern Lisp_Object Qidentity;
3127EXFUN (Fdowncase, 1);
3128EXFUN (Fupcase, 1);
3129EXFUN (Fupcase_region, 2);
3130EXFUN (Fupcase_initials, 1);
3131EXFUN (Fupcase_initials_region, 2);
3132extern void syms_of_casefiddle (void);
3133extern void keys_of_casefiddle (void);
3134
3135/* Defined in casetab.c */
3136
3137EXFUN (Fset_case_table, 1);
3138EXFUN (Fset_standard_case_table, 1);
3139extern void init_casetab_once (void);
3140extern void syms_of_casetab (void);
3141
3142/* Defined in keyboard.c */
3143
3144extern Lisp_Object echo_message_buffer;
3145extern struct kboard *echo_kboard;
3146extern void cancel_echoing (void);
3147extern Lisp_Object Qdisabled, QCfilter;
3148extern Lisp_Object Qup, Qdown, Qbottom;
3149extern Lisp_Object Qtop;
3150extern int input_pending;
3151EXFUN (Fdiscard_input, 0);
3152EXFUN (Frecursive_edit, 0);
3153_Noreturn EXFUN (Ftop_level, 0);
3154extern Lisp_Object menu_bar_items (Lisp_Object);
3155extern Lisp_Object tool_bar_items (Lisp_Object, int *);
3156extern void discard_mouse_events (void);
3157EXFUN (Fevent_convert_list, 1);
3158EXFUN (Fread_key_sequence, 5);
3159EXFUN (Fset_input_interrupt_mode, 1);
3160EXFUN (Fset_input_mode, 4);
3161extern Lisp_Object pending_funcalls;
3162extern int detect_input_pending (void);
3163extern int detect_input_pending_ignore_squeezables (void);
3164extern int detect_input_pending_run_timers (int);
3165extern void safe_run_hooks (Lisp_Object);
3166extern void cmd_error_internal (Lisp_Object, const char *);
3167extern Lisp_Object command_loop_1 (void);
3168extern Lisp_Object recursive_edit_1 (void);
3169extern void record_auto_save (void);
3170#ifdef SIGDANGER
3171extern void force_auto_save_soon (void);
3172#endif
3173extern void init_keyboard (void);
3174extern void syms_of_keyboard (void);
3175extern void keys_of_keyboard (void);
3176
3177/* Defined in indent.c */
3178EXFUN (Fvertical_motion, 2);
3179EXFUN (Findent_to, 2);
3180EXFUN (Fmove_to_column, 2);
3181extern ptrdiff_t current_column (void);
3182extern void invalidate_current_column (void);
3183extern int indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3184extern void syms_of_indent (void);
3185
3186/* Defined in frame.c */
3187#ifdef HAVE_WINDOW_SYSTEM
3188#endif /* HAVE_WINDOW_SYSTEM */
3189extern Lisp_Object Qonly;
3190extern Lisp_Object Qvisible;
3191extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
3192extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
3193extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
3194#if HAVE_NS
3195extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
3196#endif
3197extern Lisp_Object frame_buffer_predicate (Lisp_Object);
3198EXFUN (Fselect_frame, 2);
3199EXFUN (Fselected_frame, 0);
3200EXFUN (Fmake_frame_visible, 1);
3201EXFUN (Ficonify_frame, 1);
3202EXFUN (Fframe_parameter, 2);
3203EXFUN (Fmodify_frame_parameters, 2);
3204EXFUN (Fraise_frame, 1);
3205EXFUN (Fredirect_frame_focus, 2);
3206extern void frames_discard_buffer (Lisp_Object);
3207extern void syms_of_frame (void);
3208
3209/* Defined in emacs.c */
3210extern char **initial_argv;
3211extern int initial_argc;
3212#if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
3213extern int display_arg;
3214#endif
3215extern Lisp_Object decode_env_path (const char *, const char *);
3216extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3217extern Lisp_Object Qfile_name_handler_alist;
3218#ifdef FLOAT_CATCH_SIGILL
3219extern void fatal_error_signal (int);
3220#endif
3221extern Lisp_Object Qkill_emacs;
3222_Noreturn EXFUN (Fkill_emacs, 1);
3223#if HAVE_SETLOCALE
3224void fixup_locale (void);
3225void synchronize_system_messages_locale (void);
3226void synchronize_system_time_locale (void);
3227#else
3228#define setlocale(category, locale)
3229#define fixup_locale()
3230#define synchronize_system_messages_locale()
3231#define synchronize_system_time_locale()
3232#endif
3233void shut_down_emacs (int, int, Lisp_Object);
3234/* Nonzero means don't do interactive redisplay and don't change tty modes. */
3235extern int noninteractive;
3236
3237/* Nonzero means remove site-lisp directories from load-path. */
3238extern int no_site_lisp;
3239
3240/* Pipe used to send exit notification to the daemon parent at
3241 startup. */
3242extern int daemon_pipe[2];
3243#define IS_DAEMON (daemon_pipe[1] != 0)
3244
3245/* Nonzero means don't do use window-system-specific display code. */
3246extern int inhibit_window_system;
3247/* Nonzero means that a filter or a sentinel is running. */
3248extern int running_asynch_code;
3249
3250/* Defined in process.c. */
3251extern Lisp_Object QCtype, Qlocal;
3252EXFUN (Fget_buffer_process, 1);
3253EXFUN (Fprocess_status, 1);
3254EXFUN (Fkill_process, 2);
3255EXFUN (Fwaiting_for_user_input_p, 0);
3256extern Lisp_Object Qprocessp;
3257extern void kill_buffer_processes (Lisp_Object);
3258extern int wait_reading_process_output (intmax_t, int, int, int,
3259 Lisp_Object,
3260 struct Lisp_Process *,
3261 int);
3262/* Max value for the first argument of wait_reading_process_output. */
3263#if __GNUC__ == 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 5)
3264/* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.3.
3265 The bug merely causes a bogus warning, but the warning is annoying. */
3266# define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX)
3267#else
3268# define WAIT_READING_MAX INTMAX_MAX
3269#endif
3270extern void add_keyboard_wait_descriptor (int);
3271extern void delete_keyboard_wait_descriptor (int);
3272#ifdef HAVE_GPM
3273extern void add_gpm_wait_descriptor (int);
3274extern void delete_gpm_wait_descriptor (int);
3275#endif
3276extern void close_process_descs (void);
3277extern void init_process (void);
3278extern void syms_of_process (void);
3279extern void setup_process_coding_systems (Lisp_Object);
3280
3281EXFUN (Fcall_process, MANY);
3282#ifndef DOS_NT
3283 _Noreturn
3284#endif
3285extern int child_setup (int, int, int, char **, int, Lisp_Object);
3286extern void init_callproc_1 (void);
3287extern void init_callproc (void);
3288extern void set_initial_environment (void);
3289extern void syms_of_callproc (void);
3290
3291/* Defined in doc.c */
3292extern Lisp_Object Qfunction_documentation;
3293EXFUN (Fsubstitute_command_keys, 1);
3294extern Lisp_Object read_doc_string (Lisp_Object);
3295extern Lisp_Object get_doc_string (Lisp_Object, int, int);
3296extern void syms_of_doc (void);
3297extern int read_bytecode_char (int);
3298
3299/* Defined in bytecode.c */
3300extern Lisp_Object Qbytecode;
3301extern void syms_of_bytecode (void);
3302extern struct byte_stack *byte_stack_list;
3303#if BYTE_MARK_STACK
3304extern void mark_byte_stack (void);
3305#endif
3306extern void unmark_byte_stack (void);
3307extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
3308 Lisp_Object, ptrdiff_t, Lisp_Object *);
3309
3310/* Defined in macros.c */
3311extern Lisp_Object Qexecute_kbd_macro;
3312EXFUN (Fexecute_kbd_macro, 3);
3313EXFUN (Fcancel_kbd_macro_events, 0);
3314extern void init_macros (void);
3315extern void syms_of_macros (void);
3316
3317/* Defined in undo.c */
3318extern Lisp_Object Qapply;
3319extern Lisp_Object Qinhibit_read_only;
3320EXFUN (Fundo_boundary, 0);
3321extern void truncate_undo_list (struct buffer *);
3322extern void record_marker_adjustment (Lisp_Object, ptrdiff_t);
3323extern void record_insert (ptrdiff_t, ptrdiff_t);
3324extern void record_delete (ptrdiff_t, Lisp_Object);
3325extern void record_first_change (void);
3326extern void record_change (ptrdiff_t, ptrdiff_t);
3327extern void record_property_change (ptrdiff_t, ptrdiff_t,
3328 Lisp_Object, Lisp_Object,
3329 Lisp_Object);
3330extern void syms_of_undo (void);
3331/* Defined in textprop.c */
3332extern Lisp_Object Qfont, Qmouse_face;
3333extern Lisp_Object Qinsert_in_front_hooks, Qinsert_behind_hooks;
3334extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
3335extern Lisp_Object Qminibuffer_prompt;
3336
3337EXFUN (Fnext_single_property_change, 4);
3338EXFUN (Fnext_single_char_property_change, 4);
3339EXFUN (Fprevious_single_property_change, 4);
3340EXFUN (Fget_text_property, 3);
3341EXFUN (Fput_text_property, 5);
3342EXFUN (Fprevious_char_property_change, 2);
3343EXFUN (Fnext_char_property_change, 2);
3344extern void report_interval_modification (Lisp_Object, Lisp_Object);
3345
3346/* Defined in menu.c */
3347extern void syms_of_menu (void);
3348
3349/* Defined in xmenu.c */
3350EXFUN (Fx_popup_menu, 2);
3351EXFUN (Fx_popup_dialog, 3);
3352extern void syms_of_xmenu (void);
3353
3354/* Defined in termchar.h */
3355struct tty_display_info;
3356
3357/* Defined in termhooks.h */
3358struct terminal;
3359
3360/* Defined in sysdep.c */
3361#ifndef HAVE_GET_CURRENT_DIR_NAME
3362extern char *get_current_dir_name (void);
3363#endif
3364extern void stuff_char (char c);
3365extern void init_sigio (int);
3366extern void sys_subshell (void);
3367extern void sys_suspend (void);
3368extern void discard_tty_input (void);
3369extern void init_sys_modes (struct tty_display_info *);
3370extern void reset_sys_modes (struct tty_display_info *);
3371extern void init_all_sys_modes (void);
3372extern void reset_all_sys_modes (void);
3373extern void wait_for_termination (pid_t);
3374extern void interruptible_wait_for_termination (pid_t);
3375extern void flush_pending_output (int);
3376extern void child_setup_tty (int);
3377extern void setup_pty (int);
3378extern int set_window_size (int, int, int);
3379extern EMACS_INT get_random (void);
3380extern void seed_random (long);
3381extern int emacs_open (const char *, int, int);
3382extern int emacs_close (int);
3383extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
3384extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
3385enum { READLINK_BUFSIZE = 1024 };
3386extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]);
3387
3388EXFUN (Funlock_buffer, 0);
3389extern void unlock_all_files (void);
3390extern void lock_file (Lisp_Object);
3391extern void unlock_file (Lisp_Object);
3392extern void unlock_buffer (struct buffer *);
3393extern void syms_of_filelock (void);
3394extern void init_filelock (void);
3395
3396/* Defined in sound.c */
3397extern void syms_of_sound (void);
3398extern void init_sound (void);
3399
3400/* Defined in category.c */
3401extern void init_category_once (void);
3402extern Lisp_Object char_category_set (int);
3403extern void syms_of_category (void);
3404
3405/* Defined in ccl.c */
3406extern void syms_of_ccl (void);
3407
3408/* Defined in dired.c */
3409extern void syms_of_dired (void);
3410extern Lisp_Object directory_files_internal (Lisp_Object, Lisp_Object,
3411 Lisp_Object, Lisp_Object,
3412 int, Lisp_Object);
3413
3414/* Defined in term.c */
3415extern int *char_ins_del_vector;
3416extern void mark_ttys (void);
3417extern void syms_of_term (void);
3418extern _Noreturn void fatal (const char *msgid, ...)
3419 ATTRIBUTE_FORMAT_PRINTF (1, 2);
3420
3421/* Defined in terminal.c */
3422EXFUN (Fframe_terminal, 1);
3423EXFUN (Fdelete_terminal, 2);
3424extern void syms_of_terminal (void);
3425
3426/* Defined in font.c */
3427extern void syms_of_font (void);
3428extern void init_font (void);
3429
3430#ifdef HAVE_WINDOW_SYSTEM
3431/* Defined in fontset.c */
3432extern void syms_of_fontset (void);
3433
3434/* Defined in xfns.c, w32fns.c, or macfns.c */
3435extern Lisp_Object Qfont_param;
3436EXFUN (Fxw_display_color_p, 1);
3437EXFUN (Fx_focus_frame, 1);
3438#endif
3439
3440/* Defined in xfaces.c */
3441extern Lisp_Object Qdefault, Qtool_bar, Qfringe;
3442extern Lisp_Object Qheader_line, Qscroll_bar, Qcursor;
3443extern Lisp_Object Qmode_line_inactive;
3444extern Lisp_Object Qface;
3445extern Lisp_Object Qnormal;
3446extern Lisp_Object QCfamily, QCweight, QCslant;
3447extern Lisp_Object QCheight, QCname, QCwidth, QCforeground, QCbackground;
3448extern Lisp_Object Vface_alternative_font_family_alist;
3449extern Lisp_Object Vface_alternative_font_registry_alist;
3450EXFUN (Fclear_face_cache, 1);
3451EXFUN (Fx_load_color_file, 1);
3452extern void syms_of_xfaces (void);
3453
3454#ifdef HAVE_X_WINDOWS
3455/* Defined in xfns.c */
3456extern void syms_of_xfns (void);
3457
3458/* Defined in xsmfns.c */
3459extern void syms_of_xsmfns (void);
3460
3461/* Defined in xselect.c */
3462extern void syms_of_xselect (void);
3463
3464/* Defined in xterm.c */
3465extern void syms_of_xterm (void);
3466#endif /* HAVE_X_WINDOWS */
3467
3468#ifdef HAVE_WINDOW_SYSTEM
3469/* Defined in xterm.c, nsterm.m, w32term.c */
3470extern char *x_get_keysym_name (int);
3471#endif /* HAVE_WINDOW_SYSTEM */
3472
3473#ifdef MSDOS
3474/* Defined in msdos.c */
3475EXFUN (Fmsdos_downcase_filename, 1);
3476#endif
3477
3478#ifdef HAVE_LIBXML2
3479/* Defined in xml.c */
3480extern void syms_of_xml (void);
3481extern void xml_cleanup_parser (void);
3482#endif
3483
3484#ifdef HAVE_MENUS
3485/* Defined in (x|w32)fns.c, nsfns.m... */
3486extern int have_menus_p (void);
3487#endif
3488
3489#ifdef HAVE_DBUS
3490/* Defined in dbusbind.c */
3491void syms_of_dbusbind (void);
3492#endif
3493
3494#ifdef DOS_NT
3495/* Defined in msdos.c, w32.c */
3496extern char *emacs_root_dir (void);
3497#endif /* DOS_NT */
3498\f
3499/* Nonzero means Emacs has already been initialized.
3500 Used during startup to detect startup of dumped Emacs. */
3501extern int initialized;
3502
3503extern int immediate_quit; /* Nonzero means ^G can quit instantly */
3504
3505extern void *xmalloc (size_t);
3506extern void *xrealloc (void *, size_t);
3507extern void xfree (void *);
3508extern void *xnmalloc (ptrdiff_t, ptrdiff_t);
3509extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
3510extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
3511
3512extern char *xstrdup (const char *);
3513
3514extern char *egetenv (const char *);
3515
3516/* Set up the name of the machine we're running on. */
3517extern void init_system_name (void);
3518
3519/* Some systems (e.g., NT) use a different path separator than Unix,
3520 in addition to a device separator. Set the path separator
3521 to '/', and don't test for a device separator in IS_ANY_SEP. */
3522
3523#define DIRECTORY_SEP '/'
3524#ifndef IS_DIRECTORY_SEP
3525#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
3526#endif
3527#ifndef IS_DEVICE_SEP
3528#ifndef DEVICE_SEP
3529#define IS_DEVICE_SEP(_c_) 0
3530#else
3531#define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP)
3532#endif
3533#endif
3534#ifndef IS_ANY_SEP
3535#define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
3536#endif
3537
3538#define SWITCH_ENUM_CAST(x) (x)
3539
3540/* Use this to suppress gcc's warnings. */
3541#ifdef lint
3542
3543/* Use CODE only if lint checking is in effect. */
3544# define IF_LINT(Code) Code
3545
3546/* Assume that the expression COND is true. This differs in intent
3547 from 'assert', as it is a message from the programmer to the compiler. */
3548# define lint_assume(cond) ((cond) ? (void) 0 : abort ())
3549
3550#else
3551# define IF_LINT(Code) /* empty */
3552# define lint_assume(cond) ((void) (0 && (cond)))
3553#endif
3554
3555/* The ubiquitous min and max macros. */
3556
3557#ifdef max
3558#undef max
3559#undef min
3560#endif
3561#define min(a, b) ((a) < (b) ? (a) : (b))
3562#define max(a, b) ((a) > (b) ? (a) : (b))
3563
3564/* We used to use `abs', but that clashes with system headers on some
3565 platforms, and using a name reserved by Standard C is a bad idea
3566 anyway. */
3567#if !defined (eabs)
3568#define eabs(x) ((x) < 0 ? -(x) : (x))
3569#endif
3570
3571/* Return a fixnum or float, depending on whether VAL fits in a Lisp
3572 fixnum. */
3573
3574#define make_fixnum_or_float(val) \
3575 (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
3576
3577
3578/* Checks the `cycle check' variable CHECK to see if it indicates that
3579 EL is part of a cycle; CHECK must be either Qnil or a value returned
3580 by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of
3581 elements after which a cycle might be suspected; after that many
3582 elements, this macro begins consing in order to keep more precise
3583 track of elements.
3584
3585 Returns nil if a cycle was detected, otherwise a new value for CHECK
3586 that includes EL.
3587
3588 CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so
3589 the caller should make sure that's ok. */
3590
3591#define CYCLE_CHECK(check, el, suspicious) \
3592 (NILP (check) \
3593 ? make_number (0) \
3594 : (INTEGERP (check) \
3595 ? (XFASTINT (check) < (suspicious) \
3596 ? make_number (XFASTINT (check) + 1) \
3597 : Fcons (el, Qnil)) \
3598 : (!NILP (Fmemq ((el), (check))) \
3599 ? Qnil \
3600 : Fcons ((el), (check)))))
3601
3602
3603/* SAFE_ALLOCA normally allocates memory on the stack, but if size is
3604 larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */
3605
3606#define MAX_ALLOCA 16*1024
3607
3608extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3609
3610#define USE_SAFE_ALLOCA \
3611 ptrdiff_t sa_count = SPECPDL_INDEX (); int sa_must_free = 0
3612
3613/* SAFE_ALLOCA allocates a simple buffer. */
3614
3615#define SAFE_ALLOCA(buf, type, size) \
3616 do { \
3617 if ((size) < MAX_ALLOCA) \
3618 buf = (type) alloca (size); \
3619 else \
3620 { \
3621 buf = (type) xmalloc (size); \
3622 sa_must_free = 1; \
3623 record_unwind_protect (safe_alloca_unwind, \
3624 make_save_value (buf, 0)); \
3625 } \
3626 } while (0)
3627
3628/* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
3629 NITEMS items, each of the same type as *BUF. MULTIPLIER must
3630 positive. The code is tuned for MULTIPLIER being a constant. */
3631
3632#define SAFE_NALLOCA(buf, multiplier, nitems) \
3633 do { \
3634 if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \
3635 (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \
3636 else \
3637 { \
3638 (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
3639 sa_must_free = 1; \
3640 record_unwind_protect (safe_alloca_unwind, \
3641 make_save_value (buf, 0)); \
3642 } \
3643 } while (0)
3644
3645/* SAFE_FREE frees xmalloced memory and enables GC as needed. */
3646
3647#define SAFE_FREE() \
3648 do { \
3649 if (sa_must_free) { \
3650 sa_must_free = 0; \
3651 unbind_to (sa_count, Qnil); \
3652 } \
3653 } while (0)
3654
3655
3656/* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */
3657
3658#define SAFE_ALLOCA_LISP(buf, nelt) \
3659 do { \
3660 if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object)) \
3661 buf = (Lisp_Object *) alloca ((nelt) * sizeof (Lisp_Object)); \
3662 else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
3663 { \
3664 Lisp_Object arg_; \
3665 buf = (Lisp_Object *) xmalloc ((nelt) * sizeof (Lisp_Object)); \
3666 arg_ = make_save_value (buf, nelt); \
3667 XSAVE_VALUE (arg_)->dogc = 1; \
3668 sa_must_free = 1; \
3669 record_unwind_protect (safe_alloca_unwind, arg_); \
3670 } \
3671 else \
3672 memory_full (SIZE_MAX); \
3673 } while (0)
3674
3675
3676#include "globals.h"
3677
3678#endif /* EMACS_LISP_H */