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