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