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