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