Fix whitespace in previous Makefile.in changes
[bpt/emacs.git] / src / lisp.h
1 /* Fundamental definitions for GNU Emacs Lisp interpreter.
2
3 Copyright (C) 1985-1987, 1993-1995, 1997-2013 Free Software Foundation,
4 Inc.
5
6 This file is part of GNU Emacs.
7
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20
21 #ifndef EMACS_LISP_H
22 #define EMACS_LISP_H
23
24 #include <setjmp.h>
25 #include <stdalign.h>
26 #include <stdarg.h>
27 #include <stdbool.h>
28 #include <stddef.h>
29 #include <float.h>
30 #include <inttypes.h>
31 #include <limits.h>
32
33 #include <intprops.h>
34 #include <verify.h>
35
36 INLINE_HEADER_BEGIN
37
38 /* Define a TYPE constant ID as an externally visible name. Use like this:
39
40 DEFINE_GDB_SYMBOL_BEGIN (TYPE, ID)
41 #define ID something
42 DEFINE_GDB_SYMBOL_END (ID)
43
44 This hack is for the benefit of compilers that do not make macro
45 definitions visible to the debugger. It's used for symbols that
46 .gdbinit needs, symbols whose values may not fit in 'int' (where an
47 enum would suffice). */
48 #ifdef MAIN_PROGRAM
49 # define DEFINE_GDB_SYMBOL_BEGIN(type, id) type const id EXTERNALLY_VISIBLE
50 # define DEFINE_GDB_SYMBOL_END(id) = id;
51 #else
52 # define DEFINE_GDB_SYMBOL_BEGIN(type, id)
53 # define DEFINE_GDB_SYMBOL_END(val)
54 #endif
55
56 /* The ubiquitous max and min macros. */
57 #undef min
58 #undef max
59 #define max(a, b) ((a) > (b) ? (a) : (b))
60 #define min(a, b) ((a) < (b) ? (a) : (b))
61
62 /* EMACS_INT - signed integer wide enough to hold an Emacs value
63 EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
64 pI - printf length modifier for EMACS_INT
65 EMACS_UINT - unsigned variant of EMACS_INT */
66 #ifndef EMACS_INT_MAX
67 # if LONG_MAX < LLONG_MAX && defined WIDE_EMACS_INT
68 typedef long long int EMACS_INT;
69 typedef unsigned long long int EMACS_UINT;
70 # define EMACS_INT_MAX LLONG_MAX
71 # define pI "ll"
72 # elif INT_MAX < LONG_MAX
73 typedef long int EMACS_INT;
74 typedef unsigned long int EMACS_UINT;
75 # define EMACS_INT_MAX LONG_MAX
76 # define pI "l"
77 # else
78 typedef int EMACS_INT;
79 typedef unsigned int EMACS_UINT;
80 # define EMACS_INT_MAX INT_MAX
81 # define pI ""
82 # endif
83 #endif
84
85 /* An unsigned integer type representing a fixed-length bit sequence,
86 suitable for words in a Lisp bool vector. */
87 typedef size_t bits_word;
88 #define BITS_WORD_MAX SIZE_MAX
89
90 /* Number of bits in some machine integer types. */
91 enum
92 {
93 BITS_PER_CHAR = CHAR_BIT,
94 BITS_PER_SHORT = CHAR_BIT * sizeof (short),
95 BITS_PER_INT = CHAR_BIT * sizeof (int),
96 BITS_PER_LONG = CHAR_BIT * sizeof (long int),
97 BITS_PER_BITS_WORD = CHAR_BIT * sizeof (bits_word),
98 BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
99 };
100
101 /* printmax_t and uprintmax_t are types for printing large integers.
102 These are the widest integers that are supported for printing.
103 pMd etc. are conversions for printing them.
104 On C99 hosts, there's no problem, as even the widest integers work.
105 Fall back on EMACS_INT on pre-C99 hosts. */
106 #ifdef PRIdMAX
107 typedef intmax_t printmax_t;
108 typedef uintmax_t uprintmax_t;
109 # define pMd PRIdMAX
110 # define pMu PRIuMAX
111 #else
112 typedef EMACS_INT printmax_t;
113 typedef EMACS_UINT uprintmax_t;
114 # define pMd pI"d"
115 # define pMu pI"u"
116 #endif
117
118 /* Use pD to format ptrdiff_t values, which suffice for indexes into
119 buffers and strings. Emacs never allocates objects larger than
120 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
121 In C99, pD can always be "t"; configure it here for the sake of
122 pre-C99 libraries such as glibc 2.0 and Solaris 8. */
123 #if PTRDIFF_MAX == INT_MAX
124 # define pD ""
125 #elif PTRDIFF_MAX == LONG_MAX
126 # define pD "l"
127 #elif PTRDIFF_MAX == LLONG_MAX
128 # define pD "ll"
129 #else
130 # define pD "t"
131 #endif
132
133 /* Extra internal type checking? */
134
135 /* Define Emacs versions of <assert.h>'s 'assert (COND)' and <verify.h>'s
136 'assume (COND)'. COND should be free of side effects, as it may or
137 may not be evaluated.
138
139 'eassert (COND)' checks COND at runtime if ENABLE_CHECKING is
140 defined and suppress_checking is false, and does nothing otherwise.
141 Emacs dies if COND is checked and is false. The suppress_checking
142 variable is initialized to 0 in alloc.c. Set it to 1 using a
143 debugger to temporarily disable aborting on detected internal
144 inconsistencies or error conditions.
145
146 In some cases, a good compiler may be able to optimize away the
147 eassert macro even if ENABLE_CHECKING is true, e.g., if XSTRING (x)
148 uses eassert to test STRINGP (x), but a particular use of XSTRING
149 is invoked only after testing that STRINGP (x) is true, making the
150 test redundant.
151
152 eassume is like eassert except that it also causes the compiler to
153 assume that COND is true afterwards, regardless of whether runtime
154 checking is enabled. This can improve performance in some cases,
155 though it can degrade performance in others. It's often suboptimal
156 for COND to call external functions or access volatile storage. */
157
158 #ifndef ENABLE_CHECKING
159 # define eassert(cond) ((void) (0 && (cond))) /* Check that COND compiles. */
160 # define eassume(cond) assume (cond)
161 #else /* ENABLE_CHECKING */
162
163 extern _Noreturn void die (const char *, const char *, int);
164
165 extern bool suppress_checking EXTERNALLY_VISIBLE;
166
167 # define eassert(cond) \
168 (suppress_checking || (cond) \
169 ? (void) 0 \
170 : die (# cond, __FILE__, __LINE__))
171 # define eassume(cond) \
172 (suppress_checking \
173 ? assume (cond) \
174 : (cond) \
175 ? (void) 0 \
176 : die (# cond, __FILE__, __LINE__))
177 #endif /* ENABLE_CHECKING */
178
179 \f
180 /* Use the configure flag --enable-check-lisp-object-type to make
181 Lisp_Object use a struct type instead of the default int. The flag
182 causes CHECK_LISP_OBJECT_TYPE to be defined. */
183
184 /***** Select the tagging scheme. *****/
185 /* The following option controls the tagging scheme:
186 - USE_LSB_TAG means that we can assume the least 3 bits of pointers are
187 always 0, and we can thus use them to hold tag bits, without
188 restricting our addressing space.
189
190 If ! USE_LSB_TAG, then use the top 3 bits for tagging, thus
191 restricting our possible address range.
192
193 USE_LSB_TAG not only requires the least 3 bits of pointers returned by
194 malloc to be 0 but also needs to be able to impose a mult-of-8 alignment
195 on the few static Lisp_Objects used: all the defsubr as well
196 as the two special buffers buffer_defaults and buffer_local_symbols. */
197
198 enum Lisp_Bits
199 {
200 /* Number of bits in a Lisp_Object tag. This can be used in #if,
201 and for GDB's sake also as a regular symbol. */
202 GCTYPEBITS =
203 #define GCTYPEBITS 3
204 GCTYPEBITS,
205
206 /* 2**GCTYPEBITS. This must be a macro that expands to a literal
207 integer constant, for MSVC. */
208 #define GCALIGNMENT 8
209
210 /* Number of bits in a Lisp_Object value, not counting the tag. */
211 VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS,
212
213 /* Number of bits in a Lisp fixnum tag. */
214 INTTYPEBITS = GCTYPEBITS - 1,
215
216 /* Number of bits in a Lisp fixnum value, not counting the tag. */
217 FIXNUM_BITS = VALBITS + 1
218 };
219
220 #if GCALIGNMENT != 1 << GCTYPEBITS
221 # error "GCALIGNMENT and GCTYPEBITS are inconsistent"
222 #endif
223
224 /* The maximum value that can be stored in a EMACS_INT, assuming all
225 bits other than the type bits contribute to a nonnegative signed value.
226 This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */
227 #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
228
229 /* Unless otherwise specified, use USE_LSB_TAG on systems where: */
230 #ifndef USE_LSB_TAG
231 /* 1. We know malloc returns a multiple of 8. */
232 # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \
233 || defined DARWIN_OS || defined __sun)
234 /* 2. We can specify multiple-of-8 alignment on static variables. */
235 # ifdef alignas
236 /* 3. Pointers-as-ints exceed VAL_MAX.
237 On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is:
238 a. unnecessary, because the top bits of an EMACS_INT are unused, and
239 b. slower, because it typically requires extra masking.
240 So, default USE_LSB_TAG to 1 only on hosts where it might be useful. */
241 # if VAL_MAX < UINTPTR_MAX
242 # define USE_LSB_TAG 1
243 # endif
244 # endif
245 # endif
246 #endif
247 #ifdef USE_LSB_TAG
248 # undef USE_LSB_TAG
249 enum enum_USE_LSB_TAG { USE_LSB_TAG = 1 };
250 # define USE_LSB_TAG 1
251 #else
252 enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 };
253 # define USE_LSB_TAG 0
254 #endif
255
256 #ifndef alignas
257 # define alignas(alignment) /* empty */
258 # if USE_LSB_TAG
259 # error "USE_LSB_TAG requires alignas"
260 # endif
261 #endif
262
263
264 /* Some operations are so commonly executed that they are implemented
265 as macros, not functions, because otherwise runtime performance would
266 suffer too much when compiling with GCC without optimization.
267 There's no need to inline everything, just the operations that
268 would otherwise cause a serious performance problem.
269
270 For each such operation OP, define a macro lisp_h_OP that contains
271 the operation's implementation. That way, OP can be implemented
272 via a macro definition like this:
273
274 #define OP(x) lisp_h_OP (x)
275
276 and/or via a function definition like this:
277
278 LISP_MACRO_DEFUN (OP, Lisp_Object, (Lisp_Object x), (x))
279
280 which macro-expands to this:
281
282 Lisp_Object (OP) (Lisp_Object x) { return lisp_h_OP (x); }
283
284 without worrying about the implementations diverging, since
285 lisp_h_OP defines the actual implementation. The lisp_h_OP macros
286 are intended to be private to this include file, and should not be
287 used elsewhere.
288
289 FIXME: Remove the lisp_h_OP macros, and define just the inline OP
290 functions, once most developers have access to GCC 4.8 or later and
291 can use "gcc -Og" to debug. Maybe in the year 2016. See
292 Bug#11935.
293
294 Commentary for these macros can be found near their corresponding
295 functions, below. */
296
297 #if CHECK_LISP_OBJECT_TYPE
298 # define lisp_h_XLI(o) ((o).i)
299 # define lisp_h_XIL(i) ((Lisp_Object) { i })
300 #else
301 # define lisp_h_XLI(o) (o)
302 # define lisp_h_XIL(i) (i)
303 #endif
304 #define lisp_h_CHECK_LIST_CONS(x, y) CHECK_TYPE (CONSP (x), Qlistp, y)
305 #define lisp_h_CHECK_NUMBER(x) CHECK_TYPE (INTEGERP (x), Qintegerp, x)
306 #define lisp_h_CHECK_SYMBOL(x) CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
307 #define lisp_h_CHECK_TYPE(ok, Qxxxp, x) \
308 ((ok) ? (void) 0 : (void) wrong_type_argument (Qxxxp, x))
309 #define lisp_h_CONSP(x) (XTYPE (x) == Lisp_Cons)
310 #define lisp_h_EQ(x, y) (XLI (x) == XLI (y))
311 #define lisp_h_FLOATP(x) (XTYPE (x) == Lisp_Float)
312 #define lisp_h_INTEGERP(x) ((XTYPE (x) & ~Lisp_Int1) == 0)
313 #define lisp_h_MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker)
314 #define lisp_h_MISCP(x) (XTYPE (x) == Lisp_Misc)
315 #define lisp_h_NILP(x) EQ (x, Qnil)
316 #define lisp_h_SET_SYMBOL_VAL(sym, v) \
317 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value = (v))
318 #define lisp_h_SYMBOL_CONSTANT_P(sym) (XSYMBOL (sym)->constant)
319 #define lisp_h_SYMBOL_VAL(sym) \
320 (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value)
321 #define lisp_h_SYMBOLP(x) (XTYPE (x) == Lisp_Symbol)
322 #define lisp_h_VECTORLIKEP(x) (XTYPE (x) == Lisp_Vectorlike)
323 #define lisp_h_XCAR(c) XCONS (c)->car
324 #define lisp_h_XCDR(c) XCONS (c)->u.cdr
325 #define lisp_h_XCONS(a) \
326 (eassert (CONSP (a)), (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
327 #define lisp_h_XHASH(a) XUINT (a)
328 #define lisp_h_XPNTR(a) \
329 ((void *) (intptr_t) ((XLI (a) & VALMASK) | DATA_SEG_BITS))
330 #define lisp_h_XSYMBOL(a) \
331 (eassert (SYMBOLP (a)), (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol))
332 #ifndef GC_CHECK_CONS_LIST
333 # define lisp_h_check_cons_list() ((void) 0)
334 #endif
335 #if USE_LSB_TAG
336 # define lisp_h_make_number(n) XIL ((EMACS_INT) (n) << INTTYPEBITS)
337 # define lisp_h_XFASTINT(a) XINT (a)
338 # define lisp_h_XINT(a) (XLI (a) >> INTTYPEBITS)
339 # define lisp_h_XTYPE(a) ((enum Lisp_Type) (XLI (a) & ~VALMASK))
340 # define lisp_h_XUNTAG(a, type) ((void *) (XLI (a) - (type)))
341 #endif
342
343 /* When compiling via gcc -O0, define the key operations as macros, as
344 Emacs is too slow otherwise. To disable this optimization, compile
345 with -DINLINING=0. */
346 #if (defined __NO_INLINE__ \
347 && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \
348 && ! (defined INLINING && ! INLINING))
349 # define XLI(o) lisp_h_XLI (o)
350 # define XIL(i) lisp_h_XIL (i)
351 # define CHECK_LIST_CONS(x, y) lisp_h_CHECK_LIST_CONS (x, y)
352 # define CHECK_NUMBER(x) lisp_h_CHECK_NUMBER (x)
353 # define CHECK_SYMBOL(x) lisp_h_CHECK_SYMBOL (x)
354 # define CHECK_TYPE(ok, Qxxxp, x) lisp_h_CHECK_TYPE (ok, Qxxxp, x)
355 # define CONSP(x) lisp_h_CONSP (x)
356 # define EQ(x, y) lisp_h_EQ (x, y)
357 # define FLOATP(x) lisp_h_FLOATP (x)
358 # define INTEGERP(x) lisp_h_INTEGERP (x)
359 # define MARKERP(x) lisp_h_MARKERP (x)
360 # define MISCP(x) lisp_h_MISCP (x)
361 # define NILP(x) lisp_h_NILP (x)
362 # define SET_SYMBOL_VAL(sym, v) lisp_h_SET_SYMBOL_VAL (sym, v)
363 # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym)
364 # define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym)
365 # define SYMBOLP(x) lisp_h_SYMBOLP (x)
366 # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x)
367 # define XCAR(c) lisp_h_XCAR (c)
368 # define XCDR(c) lisp_h_XCDR (c)
369 # define XCONS(a) lisp_h_XCONS (a)
370 # define XHASH(a) lisp_h_XHASH (a)
371 # define XPNTR(a) lisp_h_XPNTR (a)
372 # define XSYMBOL(a) lisp_h_XSYMBOL (a)
373 # ifndef GC_CHECK_CONS_LIST
374 # define check_cons_list() lisp_h_check_cons_list ()
375 # endif
376 # if USE_LSB_TAG
377 # define make_number(n) lisp_h_make_number (n)
378 # define XFASTINT(a) lisp_h_XFASTINT (a)
379 # define XINT(a) lisp_h_XINT (a)
380 # define XTYPE(a) lisp_h_XTYPE (a)
381 # define XUNTAG(a, type) lisp_h_XUNTAG (a, type)
382 # endif
383 #endif
384
385 /* Define NAME as a lisp.h inline function that returns TYPE and has
386 arguments declared as ARGDECLS and passed as ARGS. ARGDECLS and
387 ARGS should be parenthesized. Implement the function by calling
388 lisp_h_NAME ARGS. */
389 #define LISP_MACRO_DEFUN(name, type, argdecls, args) \
390 INLINE type (name) argdecls { return lisp_h_##name args; }
391
392 /* like LISP_MACRO_DEFUN, except NAME returns void. */
393 #define LISP_MACRO_DEFUN_VOID(name, argdecls, args) \
394 INLINE void (name) argdecls { lisp_h_##name args; }
395
396
397 /* Define the fundamental Lisp data structures. */
398
399 /* This is the set of Lisp data types. If you want to define a new
400 data type, read the comments after Lisp_Fwd_Type definition
401 below. */
402
403 /* Lisp integers use 2 tags, to give them one extra bit, thus
404 extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1. */
405 #define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
406 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
407
408 /* Idea stolen from GDB. Pedantic GCC complains about enum bitfields,
409 MSVC doesn't support them, and xlc complains vociferously about them. */
410 #if defined __STRICT_ANSI__ || defined _MSC_VER || defined __IBMC__
411 #define ENUM_BF(TYPE) unsigned int
412 #else
413 #define ENUM_BF(TYPE) enum TYPE
414 #endif
415
416
417 enum Lisp_Type
418 {
419 /* Integer. XINT (obj) is the integer value. */
420 Lisp_Int0 = 0,
421 Lisp_Int1 = USE_LSB_TAG ? 1 << INTTYPEBITS : 1,
422
423 /* Symbol. XSYMBOL (object) points to a struct Lisp_Symbol. */
424 Lisp_Symbol = 2,
425
426 /* Miscellaneous. XMISC (object) points to a union Lisp_Misc,
427 whose first member indicates the subtype. */
428 Lisp_Misc = 3,
429
430 /* String. XSTRING (object) points to a struct Lisp_String.
431 The length of the string, and its contents, are stored therein. */
432 Lisp_String = USE_LSB_TAG ? 1 : 1 << INTTYPEBITS,
433
434 /* Vector of Lisp objects, or something resembling it.
435 XVECTOR (object) points to a struct Lisp_Vector, which contains
436 the size and contents. The size field also contains the type
437 information, if it's not a real vector object. */
438 Lisp_Vectorlike = 5,
439
440 /* Cons. XCONS (object) points to a struct Lisp_Cons. */
441 Lisp_Cons = 6,
442
443 Lisp_Float = 7
444 };
445
446 /* This is the set of data types that share a common structure.
447 The first member of the structure is a type code from this set.
448 The enum values are arbitrary, but we'll use large numbers to make it
449 more likely that we'll spot the error if a random word in memory is
450 mistakenly interpreted as a Lisp_Misc. */
451 enum Lisp_Misc_Type
452 {
453 Lisp_Misc_Free = 0x5eab,
454 Lisp_Misc_Marker,
455 Lisp_Misc_Overlay,
456 Lisp_Misc_Save_Value,
457 /* Currently floats are not a misc type,
458 but let's define this in case we want to change that. */
459 Lisp_Misc_Float,
460 /* This is not a type code. It is for range checking. */
461 Lisp_Misc_Limit
462 };
463
464 /* These are the types of forwarding objects used in the value slot
465 of symbols for special built-in variables whose value is stored in
466 C variables. */
467 enum Lisp_Fwd_Type
468 {
469 Lisp_Fwd_Int, /* Fwd to a C `int' variable. */
470 Lisp_Fwd_Bool, /* Fwd to a C boolean var. */
471 Lisp_Fwd_Obj, /* Fwd to a C Lisp_Object variable. */
472 Lisp_Fwd_Buffer_Obj, /* Fwd to a Lisp_Object field of buffers. */
473 Lisp_Fwd_Kboard_Obj /* Fwd to a Lisp_Object field of kboards. */
474 };
475
476 /* If you want to define a new Lisp data type, here are some
477 instructions. See the thread at
478 http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00561.html
479 for more info.
480
481 First, there are already a couple of Lisp types that can be used if
482 your new type does not need to be exposed to Lisp programs nor
483 displayed to users. These are Lisp_Save_Value, a Lisp_Misc
484 subtype; and PVEC_OTHER, a kind of vectorlike object. The former
485 is suitable for temporarily stashing away pointers and integers in
486 a Lisp object. The latter is useful for vector-like Lisp objects
487 that need to be used as part of other objects, but which are never
488 shown to users or Lisp code (search for PVEC_OTHER in xterm.c for
489 an example).
490
491 These two types don't look pretty when printed, so they are
492 unsuitable for Lisp objects that can be exposed to users.
493
494 To define a new data type, add one more Lisp_Misc subtype or one
495 more pseudovector subtype. Pseudovectors are more suitable for
496 objects with several slots that need to support fast random access,
497 while Lisp_Misc types are for everything else. A pseudovector object
498 provides one or more slots for Lisp objects, followed by struct
499 members that are accessible only from C. A Lisp_Misc object is a
500 wrapper for a C struct that can contain anything you like.
501
502 Explicit freeing is discouraged for Lisp objects in general. But if
503 you really need to exploit this, use Lisp_Misc (check free_misc in
504 alloc.c to see why). There is no way to free a vectorlike object.
505
506 To add a new pseudovector type, extend the pvec_type enumeration;
507 to add a new Lisp_Misc, extend the Lisp_Misc_Type enumeration.
508
509 For a Lisp_Misc, you will also need to add your entry to union
510 Lisp_Misc (but make sure the first word has the same structure as
511 the others, starting with a 16-bit member of the Lisp_Misc_Type
512 enumeration and a 1-bit GC markbit) and make sure the overall size
513 of the union is not increased by your addition.
514
515 For a new pseudovector, it's highly desirable to limit the size
516 of your data type by VBLOCK_BYTES_MAX bytes (defined in alloc.c).
517 Otherwise you will need to change sweep_vectors (also in alloc.c).
518
519 Then you will need to add switch branches in print.c (in
520 print_object, to print your object, and possibly also in
521 print_preprocess) and to alloc.c, to mark your object (in
522 mark_object) and to free it (in gc_sweep). The latter is also the
523 right place to call any code specific to your data type that needs
524 to run when the object is recycled -- e.g., free any additional
525 resources allocated for it that are not Lisp objects. You can even
526 make a pointer to the function that frees the resources a slot in
527 your object -- this way, the same object could be used to represent
528 several disparate C structures. */
529
530 #ifdef CHECK_LISP_OBJECT_TYPE
531
532 typedef struct { EMACS_INT i; } Lisp_Object;
533
534 #define LISP_INITIALLY_ZERO {0}
535
536 #undef CHECK_LISP_OBJECT_TYPE
537 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = 1 };
538 #else /* CHECK_LISP_OBJECT_TYPE */
539
540 /* If a struct type is not wanted, define Lisp_Object as just a number. */
541
542 typedef EMACS_INT Lisp_Object;
543 #define LISP_INITIALLY_ZERO 0
544 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = 0 };
545 #endif /* CHECK_LISP_OBJECT_TYPE */
546
547 /* Convert a Lisp_Object to the corresponding EMACS_INT and vice versa.
548 At the machine level, these operations are no-ops. */
549 LISP_MACRO_DEFUN (XLI, EMACS_INT, (Lisp_Object o), (o))
550 LISP_MACRO_DEFUN (XIL, Lisp_Object, (EMACS_INT i), (i))
551
552 /* In the size word of a vector, this bit means the vector has been marked. */
553
554 DEFINE_GDB_SYMBOL_BEGIN (ptrdiff_t, ARRAY_MARK_FLAG)
555 #define ARRAY_MARK_FLAG PTRDIFF_MIN
556 DEFINE_GDB_SYMBOL_END (ARRAY_MARK_FLAG)
557
558 /* In the size word of a struct Lisp_Vector, this bit means it's really
559 some other vector-like object. */
560 DEFINE_GDB_SYMBOL_BEGIN (ptrdiff_t, PSEUDOVECTOR_FLAG)
561 #define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
562 DEFINE_GDB_SYMBOL_END (PSEUDOVECTOR_FLAG)
563
564 /* In a pseudovector, the size field actually contains a word with one
565 PSEUDOVECTOR_FLAG bit set, and one of the following values extracted
566 with PVEC_TYPE_MASK to indicate the actual type. */
567 enum pvec_type
568 {
569 PVEC_NORMAL_VECTOR,
570 PVEC_FREE,
571 PVEC_PROCESS,
572 PVEC_FRAME,
573 PVEC_WINDOW,
574 PVEC_BOOL_VECTOR,
575 PVEC_BUFFER,
576 PVEC_HASH_TABLE,
577 PVEC_TERMINAL,
578 PVEC_WINDOW_CONFIGURATION,
579 PVEC_SUBR,
580 PVEC_OTHER,
581 /* These should be last, check internal_equal to see why. */
582 PVEC_COMPILED,
583 PVEC_CHAR_TABLE,
584 PVEC_SUB_CHAR_TABLE,
585 PVEC_FONT /* Should be last because it's used for range checking. */
586 };
587
588 /* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
589 which were stored in a Lisp_Object. */
590 #ifndef DATA_SEG_BITS
591 # define DATA_SEG_BITS 0
592 #endif
593 enum { gdb_DATA_SEG_BITS = DATA_SEG_BITS };
594 #undef DATA_SEG_BITS
595
596 enum More_Lisp_Bits
597 {
598 DATA_SEG_BITS = gdb_DATA_SEG_BITS,
599
600 /* For convenience, we also store the number of elements in these bits.
601 Note that this size is not necessarily the memory-footprint size, but
602 only the number of Lisp_Object fields (that need to be traced by GC).
603 The distinction is used, e.g., by Lisp_Process, which places extra
604 non-Lisp_Object fields at the end of the structure. */
605 PSEUDOVECTOR_SIZE_BITS = 12,
606 PSEUDOVECTOR_SIZE_MASK = (1 << PSEUDOVECTOR_SIZE_BITS) - 1,
607
608 /* To calculate the memory footprint of the pseudovector, it's useful
609 to store the size of non-Lisp area in word_size units here. */
610 PSEUDOVECTOR_REST_BITS = 12,
611 PSEUDOVECTOR_REST_MASK = (((1 << PSEUDOVECTOR_REST_BITS) - 1)
612 << PSEUDOVECTOR_SIZE_BITS),
613
614 /* Used to extract pseudovector subtype information. */
615 PSEUDOVECTOR_AREA_BITS = PSEUDOVECTOR_SIZE_BITS + PSEUDOVECTOR_REST_BITS,
616 PVEC_TYPE_MASK = 0x3f << PSEUDOVECTOR_AREA_BITS,
617
618 /* Number of bits to put in each character in the internal representation
619 of bool vectors. This should not vary across implementations. */
620 BOOL_VECTOR_BITS_PER_CHAR = 8
621 };
622 \f
623 /* These functions extract various sorts of values from a Lisp_Object.
624 For example, if tem is a Lisp_Object whose type is Lisp_Cons,
625 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for
626 that cons. */
627
628 DEFINE_GDB_SYMBOL_BEGIN (EMACS_INT, VALMASK)
629 #define VALMASK (USE_LSB_TAG ? - (1 << GCTYPEBITS) : VAL_MAX)
630 DEFINE_GDB_SYMBOL_END (VALMASK)
631
632 /* Largest and smallest representable fixnum values. These are the C
633 values. They are macros for use in static initializers. */
634 #define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
635 #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
636
637 /* Extract the pointer hidden within A. */
638 LISP_MACRO_DEFUN (XPNTR, void *, (Lisp_Object a), (a))
639
640 #if USE_LSB_TAG
641
642 LISP_MACRO_DEFUN (make_number, Lisp_Object, (EMACS_INT n), (n))
643 LISP_MACRO_DEFUN (XINT, EMACS_INT, (Lisp_Object a), (a))
644 LISP_MACRO_DEFUN (XFASTINT, EMACS_INT, (Lisp_Object a), (a))
645 LISP_MACRO_DEFUN (XTYPE, enum Lisp_Type, (Lisp_Object a), (a))
646 LISP_MACRO_DEFUN (XUNTAG, void *, (Lisp_Object a, int type), (a, type))
647
648 #else /* ! USE_LSB_TAG */
649
650 /* Although compiled only if ! USE_LSB_TAG, the following functions
651 also work when USE_LSB_TAG; this is to aid future maintenance when
652 the lisp_h_* macros are eventually removed. */
653
654 /* Make a Lisp integer representing the value of the low order
655 bits of N. */
656 INLINE Lisp_Object
657 make_number (EMACS_INT n)
658 {
659 return XIL (USE_LSB_TAG ? n << INTTYPEBITS : n & INTMASK);
660 }
661
662 /* Extract A's value as a signed integer. */
663 INLINE EMACS_INT
664 XINT (Lisp_Object a)
665 {
666 EMACS_INT i = XLI (a);
667 return (USE_LSB_TAG ? i : i << INTTYPEBITS) >> INTTYPEBITS;
668 }
669
670 /* Like XINT (A), but may be faster. A must be nonnegative.
671 If ! USE_LSB_TAG, this takes advantage of the fact that Lisp
672 integers have zero-bits in their tags. */
673 INLINE EMACS_INT
674 XFASTINT (Lisp_Object a)
675 {
676 EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a);
677 eassert (0 <= n);
678 return n;
679 }
680
681 /* Extract A's type. */
682 INLINE enum Lisp_Type
683 XTYPE (Lisp_Object a)
684 {
685 EMACS_UINT i = XLI (a);
686 return USE_LSB_TAG ? i & ~VALMASK : i >> VALBITS;
687 }
688
689 /* Extract A's pointer value, assuming A's type is TYPE. */
690 INLINE void *
691 XUNTAG (Lisp_Object a, int type)
692 {
693 if (USE_LSB_TAG)
694 {
695 intptr_t i = XLI (a) - type;
696 return (void *) i;
697 }
698 return XPNTR (a);
699 }
700
701 #endif /* ! USE_LSB_TAG */
702
703 /* Extract A's value as an unsigned integer. */
704 INLINE EMACS_UINT
705 XUINT (Lisp_Object a)
706 {
707 EMACS_UINT i = XLI (a);
708 return USE_LSB_TAG ? i >> INTTYPEBITS : i & INTMASK;
709 }
710
711 /* Return A's (Lisp-integer sized) hash. Happens to be like XUINT
712 right now, but XUINT should only be applied to objects we know are
713 integers. */
714 LISP_MACRO_DEFUN (XHASH, EMACS_INT, (Lisp_Object a), (a))
715
716 /* Like make_number (N), but may be faster. N must be in nonnegative range. */
717 INLINE Lisp_Object
718 make_natnum (EMACS_INT n)
719 {
720 eassert (0 <= n && n <= MOST_POSITIVE_FIXNUM);
721 return USE_LSB_TAG ? make_number (n) : XIL (n);
722 }
723
724 /* Return true if X and Y are the same object. */
725 LISP_MACRO_DEFUN (EQ, bool, (Lisp_Object x, Lisp_Object y), (x, y))
726
727 /* Value is non-zero if I doesn't fit into a Lisp fixnum. It is
728 written this way so that it also works if I is of unsigned
729 type or if I is a NaN. */
730
731 #define FIXNUM_OVERFLOW_P(i) \
732 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
733
734 INLINE ptrdiff_t
735 clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
736 {
737 return num < lower ? lower : num <= upper ? num : upper;
738 }
739 \f
740 /* Forward declarations. */
741
742 /* Defined in this file. */
743 union Lisp_Fwd;
744 INLINE bool BOOL_VECTOR_P (Lisp_Object);
745 INLINE bool BUFFER_OBJFWDP (union Lisp_Fwd *);
746 INLINE bool BUFFERP (Lisp_Object);
747 INLINE bool CHAR_TABLE_P (Lisp_Object);
748 INLINE Lisp_Object CHAR_TABLE_REF_ASCII (Lisp_Object, ptrdiff_t);
749 INLINE bool (CONSP) (Lisp_Object);
750 INLINE bool (FLOATP) (Lisp_Object);
751 INLINE bool functionp (Lisp_Object);
752 INLINE bool (INTEGERP) (Lisp_Object);
753 INLINE bool (MARKERP) (Lisp_Object);
754 INLINE bool (MISCP) (Lisp_Object);
755 INLINE bool (NILP) (Lisp_Object);
756 INLINE bool OVERLAYP (Lisp_Object);
757 INLINE bool PROCESSP (Lisp_Object);
758 INLINE bool PSEUDOVECTORP (Lisp_Object, int);
759 INLINE bool SAVE_VALUEP (Lisp_Object);
760 INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
761 Lisp_Object);
762 INLINE bool STRINGP (Lisp_Object);
763 INLINE bool SUB_CHAR_TABLE_P (Lisp_Object);
764 INLINE bool SUBRP (Lisp_Object);
765 INLINE bool (SYMBOLP) (Lisp_Object);
766 INLINE bool (VECTORLIKEP) (Lisp_Object);
767 INLINE bool WINDOWP (Lisp_Object);
768 INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object);
769
770 /* Defined in chartab.c. */
771 extern Lisp_Object char_table_ref (Lisp_Object, int);
772 extern void char_table_set (Lisp_Object, int, Lisp_Object);
773 extern int char_table_translate (Lisp_Object, int);
774
775 /* Defined in data.c. */
776 extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p;
777 extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil;
778 extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qvectorp;
779 extern Lisp_Object Qbool_vector_p;
780 extern Lisp_Object Qvector_or_char_table_p, Qwholenump;
781 extern Lisp_Object Qwindow;
782 extern Lisp_Object Ffboundp (Lisp_Object);
783 extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
784
785 /* Defined in emacs.c. */
786 extern bool initialized;
787
788 /* Defined in eval.c. */
789 extern Lisp_Object Qautoload;
790
791 /* Defined in floatfns.c. */
792 extern double extract_float (Lisp_Object);
793
794 /* Defined in process.c. */
795 extern Lisp_Object Qprocessp;
796
797 /* Defined in window.c. */
798 extern Lisp_Object Qwindowp;
799
800 /* Defined in xdisp.c. */
801 extern Lisp_Object Qimage;
802 \f
803
804 /* Extract a value or address from a Lisp_Object. */
805
806 LISP_MACRO_DEFUN (XCONS, struct Lisp_Cons *, (Lisp_Object a), (a))
807
808 INLINE struct Lisp_Vector *
809 XVECTOR (Lisp_Object a)
810 {
811 eassert (VECTORLIKEP (a));
812 return XUNTAG (a, Lisp_Vectorlike);
813 }
814
815 INLINE struct Lisp_String *
816 XSTRING (Lisp_Object a)
817 {
818 eassert (STRINGP (a));
819 return XUNTAG (a, Lisp_String);
820 }
821
822 LISP_MACRO_DEFUN (XSYMBOL, struct Lisp_Symbol *, (Lisp_Object a), (a))
823
824 INLINE struct Lisp_Float *
825 XFLOAT (Lisp_Object a)
826 {
827 eassert (FLOATP (a));
828 return XUNTAG (a, Lisp_Float);
829 }
830
831 /* Pseudovector types. */
832
833 INLINE struct Lisp_Process *
834 XPROCESS (Lisp_Object a)
835 {
836 eassert (PROCESSP (a));
837 return XUNTAG (a, Lisp_Vectorlike);
838 }
839
840 INLINE struct window *
841 XWINDOW (Lisp_Object a)
842 {
843 eassert (WINDOWP (a));
844 return XUNTAG (a, Lisp_Vectorlike);
845 }
846
847 INLINE struct terminal *
848 XTERMINAL (Lisp_Object a)
849 {
850 return XUNTAG (a, Lisp_Vectorlike);
851 }
852
853 INLINE struct Lisp_Subr *
854 XSUBR (Lisp_Object a)
855 {
856 eassert (SUBRP (a));
857 return XUNTAG (a, Lisp_Vectorlike);
858 }
859
860 INLINE struct buffer *
861 XBUFFER (Lisp_Object a)
862 {
863 eassert (BUFFERP (a));
864 return XUNTAG (a, Lisp_Vectorlike);
865 }
866
867 INLINE struct Lisp_Char_Table *
868 XCHAR_TABLE (Lisp_Object a)
869 {
870 eassert (CHAR_TABLE_P (a));
871 return XUNTAG (a, Lisp_Vectorlike);
872 }
873
874 INLINE struct Lisp_Sub_Char_Table *
875 XSUB_CHAR_TABLE (Lisp_Object a)
876 {
877 eassert (SUB_CHAR_TABLE_P (a));
878 return XUNTAG (a, Lisp_Vectorlike);
879 }
880
881 INLINE struct Lisp_Bool_Vector *
882 XBOOL_VECTOR (Lisp_Object a)
883 {
884 eassert (BOOL_VECTOR_P (a));
885 return XUNTAG (a, Lisp_Vectorlike);
886 }
887
888 /* Construct a Lisp_Object from a value or address. */
889
890 INLINE Lisp_Object
891 make_lisp_ptr (void *ptr, enum Lisp_Type type)
892 {
893 EMACS_UINT utype = type;
894 EMACS_UINT typebits = USE_LSB_TAG ? type : utype << VALBITS;
895 Lisp_Object a = XIL (typebits | (uintptr_t) ptr);
896 eassert (XTYPE (a) == type && XUNTAG (a, type) == ptr);
897 return a;
898 }
899
900 INLINE Lisp_Object
901 make_lisp_proc (struct Lisp_Process *p)
902 {
903 return make_lisp_ptr (p, Lisp_Vectorlike);
904 }
905
906 #define XSETINT(a, b) ((a) = make_number (b))
907 #define XSETFASTINT(a, b) ((a) = make_natnum (b))
908 #define XSETCONS(a, b) ((a) = make_lisp_ptr (b, Lisp_Cons))
909 #define XSETVECTOR(a, b) ((a) = make_lisp_ptr (b, Lisp_Vectorlike))
910 #define XSETSTRING(a, b) ((a) = make_lisp_ptr (b, Lisp_String))
911 #define XSETSYMBOL(a, b) ((a) = make_lisp_ptr (b, Lisp_Symbol))
912 #define XSETFLOAT(a, b) ((a) = make_lisp_ptr (b, Lisp_Float))
913 #define XSETMISC(a, b) ((a) = make_lisp_ptr (b, Lisp_Misc))
914
915 /* Pseudovector types. */
916
917 #define XSETPVECTYPE(v, code) \
918 ((v)->header.size |= PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_AREA_BITS))
919 #define XSETPVECTYPESIZE(v, code, lispsize, restsize) \
920 ((v)->header.size = (PSEUDOVECTOR_FLAG \
921 | ((code) << PSEUDOVECTOR_AREA_BITS) \
922 | ((restsize) << PSEUDOVECTOR_SIZE_BITS) \
923 | (lispsize)))
924
925 /* The cast to struct vectorlike_header * avoids aliasing issues. */
926 #define XSETPSEUDOVECTOR(a, b, code) \
927 XSETTYPED_PSEUDOVECTOR (a, b, \
928 (((struct vectorlike_header *) \
929 XUNTAG (a, Lisp_Vectorlike)) \
930 ->size), \
931 code)
932 #define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \
933 (XSETVECTOR (a, b), \
934 eassert ((size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) \
935 == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS))))
936
937 #define XSETWINDOW_CONFIGURATION(a, b) \
938 (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW_CONFIGURATION))
939 #define XSETPROCESS(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_PROCESS))
940 #define XSETWINDOW(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_WINDOW))
941 #define XSETTERMINAL(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_TERMINAL))
942 #define XSETSUBR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUBR))
943 #define XSETCOMPILED(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_COMPILED))
944 #define XSETBUFFER(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BUFFER))
945 #define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE))
946 #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
947 #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
948
949 /* Type checking. */
950
951 LISP_MACRO_DEFUN_VOID (CHECK_TYPE, (int ok, Lisp_Object Qxxxp, Lisp_Object x),
952 (ok, Qxxxp, x))
953
954 /* Deprecated and will be removed soon. */
955
956 #define INTERNAL_FIELD(field) field ## _
957
958 /* See the macros in intervals.h. */
959
960 typedef struct interval *INTERVAL;
961
962 struct Lisp_Cons
963 {
964 /* Car of this cons cell. */
965 Lisp_Object car;
966
967 union
968 {
969 /* Cdr of this cons cell. */
970 Lisp_Object cdr;
971
972 /* Used to chain conses on a free list. */
973 struct Lisp_Cons *chain;
974 } u;
975 };
976
977 /* Take the car or cdr of something known to be a cons cell. */
978 /* The _addr functions shouldn't be used outside of the minimal set
979 of code that has to know what a cons cell looks like. Other code not
980 part of the basic lisp implementation should assume that the car and cdr
981 fields are not accessible. (What if we want to switch to
982 a copying collector someday? Cached cons cell field addresses may be
983 invalidated at arbitrary points.) */
984 INLINE Lisp_Object *
985 xcar_addr (Lisp_Object c)
986 {
987 return &XCONS (c)->car;
988 }
989 INLINE Lisp_Object *
990 xcdr_addr (Lisp_Object c)
991 {
992 return &XCONS (c)->u.cdr;
993 }
994
995 /* Use these from normal code. */
996 LISP_MACRO_DEFUN (XCAR, Lisp_Object, (Lisp_Object c), (c))
997 LISP_MACRO_DEFUN (XCDR, Lisp_Object, (Lisp_Object c), (c))
998
999 /* Use these to set the fields of a cons cell.
1000
1001 Note that both arguments may refer to the same object, so 'n'
1002 should not be read after 'c' is first modified. */
1003 INLINE void
1004 XSETCAR (Lisp_Object c, Lisp_Object n)
1005 {
1006 *xcar_addr (c) = n;
1007 }
1008 INLINE void
1009 XSETCDR (Lisp_Object c, Lisp_Object n)
1010 {
1011 *xcdr_addr (c) = n;
1012 }
1013
1014 /* Take the car or cdr of something whose type is not known. */
1015 INLINE Lisp_Object
1016 CAR (Lisp_Object c)
1017 {
1018 return (CONSP (c) ? XCAR (c)
1019 : NILP (c) ? Qnil
1020 : wrong_type_argument (Qlistp, c));
1021 }
1022 INLINE Lisp_Object
1023 CDR (Lisp_Object c)
1024 {
1025 return (CONSP (c) ? XCDR (c)
1026 : NILP (c) ? Qnil
1027 : wrong_type_argument (Qlistp, c));
1028 }
1029
1030 /* Take the car or cdr of something whose type is not known. */
1031 INLINE Lisp_Object
1032 CAR_SAFE (Lisp_Object c)
1033 {
1034 return CONSP (c) ? XCAR (c) : Qnil;
1035 }
1036 INLINE Lisp_Object
1037 CDR_SAFE (Lisp_Object c)
1038 {
1039 return CONSP (c) ? XCDR (c) : Qnil;
1040 }
1041
1042 /* In a string or vector, the sign bit of the `size' is the gc mark bit. */
1043
1044 struct Lisp_String
1045 {
1046 ptrdiff_t size;
1047 ptrdiff_t size_byte;
1048 INTERVAL intervals; /* Text properties in this string. */
1049 unsigned char *data;
1050 };
1051
1052 /* True if STR is a multibyte string. */
1053 INLINE bool
1054 STRING_MULTIBYTE (Lisp_Object str)
1055 {
1056 return 0 <= XSTRING (str)->size_byte;
1057 }
1058
1059 /* An upper bound on the number of bytes in a Lisp string, not
1060 counting the terminating null. This a tight enough bound to
1061 prevent integer overflow errors that would otherwise occur during
1062 string size calculations. A string cannot contain more bytes than
1063 a fixnum can represent, nor can it be so long that C pointer
1064 arithmetic stops working on the string plus its terminating null.
1065 Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
1066 may be a bit smaller than STRING_BYTES_BOUND, calculating it here
1067 would expose alloc.c internal details that we'd rather keep
1068 private.
1069
1070 This is a macro for use in static initializers. The cast to
1071 ptrdiff_t ensures that the macro is signed. */
1072 #define STRING_BYTES_BOUND \
1073 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1))
1074
1075 /* Mark STR as a unibyte string. */
1076 #define STRING_SET_UNIBYTE(STR) \
1077 do { if (EQ (STR, empty_multibyte_string)) \
1078 (STR) = empty_unibyte_string; \
1079 else XSTRING (STR)->size_byte = -1; } while (0)
1080
1081 /* Mark STR as a multibyte string. Assure that STR contains only
1082 ASCII characters in advance. */
1083 #define STRING_SET_MULTIBYTE(STR) \
1084 do { if (EQ (STR, empty_unibyte_string)) \
1085 (STR) = empty_multibyte_string; \
1086 else XSTRING (STR)->size_byte = XSTRING (STR)->size; } while (0)
1087
1088 /* Convenience functions for dealing with Lisp strings. */
1089
1090 INLINE unsigned char *
1091 SDATA (Lisp_Object string)
1092 {
1093 return XSTRING (string)->data;
1094 }
1095 INLINE char *
1096 SSDATA (Lisp_Object string)
1097 {
1098 /* Avoid "differ in sign" warnings. */
1099 return (char *) SDATA (string);
1100 }
1101 INLINE unsigned char
1102 SREF (Lisp_Object string, ptrdiff_t index)
1103 {
1104 return SDATA (string)[index];
1105 }
1106 INLINE void
1107 SSET (Lisp_Object string, ptrdiff_t index, unsigned char new)
1108 {
1109 SDATA (string)[index] = new;
1110 }
1111 INLINE ptrdiff_t
1112 SCHARS (Lisp_Object string)
1113 {
1114 return XSTRING (string)->size;
1115 }
1116
1117 #ifdef GC_CHECK_STRING_BYTES
1118 extern ptrdiff_t string_bytes (struct Lisp_String *);
1119 #endif
1120 INLINE ptrdiff_t
1121 STRING_BYTES (struct Lisp_String *s)
1122 {
1123 #ifdef GC_CHECK_STRING_BYTES
1124 return string_bytes (s);
1125 #else
1126 return s->size_byte < 0 ? s->size : s->size_byte;
1127 #endif
1128 }
1129
1130 INLINE ptrdiff_t
1131 SBYTES (Lisp_Object string)
1132 {
1133 return STRING_BYTES (XSTRING (string));
1134 }
1135 INLINE void
1136 STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize)
1137 {
1138 XSTRING (string)->size = newsize;
1139 }
1140 INLINE void
1141 STRING_COPYIN (Lisp_Object string, ptrdiff_t index, char const *new,
1142 ptrdiff_t count)
1143 {
1144 memcpy (SDATA (string) + index, new, count);
1145 }
1146
1147 /* Header of vector-like objects. This documents the layout constraints on
1148 vectors and pseudovectors (objects of PVEC_xxx subtype). It also prevents
1149 compilers from being fooled by Emacs's type punning: XSETPSEUDOVECTOR
1150 and PSEUDOVECTORP cast their pointers to struct vectorlike_header *,
1151 because when two such pointers potentially alias, a compiler won't
1152 incorrectly reorder loads and stores to their size fields. See
1153 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */
1154 struct vectorlike_header
1155 {
1156 /* The only field contains various pieces of information:
1157 - The MSB (ARRAY_MARK_FLAG) holds the gcmarkbit.
1158 - The next bit (PSEUDOVECTOR_FLAG) indicates whether this is a plain
1159 vector (0) or a pseudovector (1).
1160 - If PSEUDOVECTOR_FLAG is 0, the rest holds the size (number
1161 of slots) of the vector.
1162 - If PSEUDOVECTOR_FLAG is 1, the rest is subdivided into three fields:
1163 - a) pseudovector subtype held in PVEC_TYPE_MASK field;
1164 - b) number of Lisp_Objects slots at the beginning of the object
1165 held in PSEUDOVECTOR_SIZE_MASK field. These objects are always
1166 traced by the GC;
1167 - c) size of the rest fields held in PSEUDOVECTOR_REST_MASK and
1168 measured in word_size units. Rest fields may also include
1169 Lisp_Objects, but these objects usually needs some special treatment
1170 during GC.
1171 There are some exceptions. For PVEC_FREE, b) is always zero. For
1172 PVEC_BOOL_VECTOR and PVEC_SUBR, both b) and c) are always zero.
1173 Current layout limits the pseudovectors to 63 PVEC_xxx subtypes,
1174 4095 Lisp_Objects in GC-ed area and 4095 word-sized other slots. */
1175 ptrdiff_t size;
1176 };
1177
1178 /* Regular vector is just a header plus array of Lisp_Objects... */
1179
1180 struct Lisp_Vector
1181 {
1182 struct vectorlike_header header;
1183 union {
1184 /* ...but sometimes there is also a pointer internally used in
1185 vector allocation code. Usually you don't want to touch this. */
1186 struct Lisp_Vector *next;
1187
1188 /* We can't use FLEXIBLE_ARRAY_MEMBER here. */
1189 Lisp_Object contents[1];
1190 } u;
1191 };
1192
1193 /* A boolvector is a kind of vectorlike, with contents are like a string. */
1194
1195 struct Lisp_Bool_Vector
1196 {
1197 /* HEADER.SIZE is the vector's size field. It doesn't have the real size,
1198 just the subtype information. */
1199 struct vectorlike_header header;
1200 /* This is the size in bits. */
1201 EMACS_INT size;
1202 /* This contains the actual bits, packed into bytes. */
1203 unsigned char data[FLEXIBLE_ARRAY_MEMBER];
1204 };
1205
1206 INLINE EMACS_INT
1207 bool_vector_size (Lisp_Object a)
1208 {
1209 EMACS_INT size = XBOOL_VECTOR (a)->size;
1210 eassume (0 <= size);
1211 return size;
1212 }
1213
1214 /* Some handy constants for calculating sizes
1215 and offsets, mostly of vectorlike objects. */
1216
1217 enum
1218 {
1219 header_size = offsetof (struct Lisp_Vector, u.contents),
1220 bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
1221 word_size = sizeof (Lisp_Object)
1222 };
1223
1224 /* Conveniences for dealing with Lisp arrays. */
1225
1226 INLINE Lisp_Object
1227 AREF (Lisp_Object array, ptrdiff_t idx)
1228 {
1229 return XVECTOR (array)->u.contents[idx];
1230 }
1231
1232 INLINE Lisp_Object *
1233 aref_addr (Lisp_Object array, ptrdiff_t idx)
1234 {
1235 return & XVECTOR (array)->u.contents[idx];
1236 }
1237
1238 INLINE ptrdiff_t
1239 ASIZE (Lisp_Object array)
1240 {
1241 return XVECTOR (array)->header.size;
1242 }
1243
1244 INLINE void
1245 ASET (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
1246 {
1247 eassert (0 <= idx && idx < ASIZE (array));
1248 XVECTOR (array)->u.contents[idx] = val;
1249 }
1250
1251 INLINE void
1252 gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
1253 {
1254 /* Like ASET, but also can be used in the garbage collector:
1255 sweep_weak_table calls set_hash_key etc. while the table is marked. */
1256 eassert (0 <= idx && idx < (ASIZE (array) & ~ARRAY_MARK_FLAG));
1257 XVECTOR (array)->u.contents[idx] = val;
1258 }
1259
1260 /* If a struct is made to look like a vector, this macro returns the length
1261 of the shortest vector that would hold that struct. */
1262
1263 #define VECSIZE(type) \
1264 ((sizeof (type) - header_size + word_size - 1) / word_size)
1265
1266 /* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
1267 at the end and we need to compute the number of Lisp_Object fields (the
1268 ones that the GC needs to trace). */
1269
1270 #define PSEUDOVECSIZE(type, nonlispfield) \
1271 ((offsetof (type, nonlispfield) - header_size) / word_size)
1272
1273 /* Compute A OP B, using the unsigned comparison operator OP. A and B
1274 should be integer expressions. This is not the same as
1275 mathematical comparison; for example, UNSIGNED_CMP (0, <, -1)
1276 returns 1. For efficiency, prefer plain unsigned comparison if A
1277 and B's sizes both fit (after integer promotion). */
1278 #define UNSIGNED_CMP(a, op, b) \
1279 (max (sizeof ((a) + 0), sizeof ((b) + 0)) <= sizeof (unsigned) \
1280 ? ((a) + (unsigned) 0) op ((b) + (unsigned) 0) \
1281 : ((a) + (uintmax_t) 0) op ((b) + (uintmax_t) 0))
1282
1283 /* Nonzero iff C is an ASCII character. */
1284 #define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
1285
1286 /* A char-table is a kind of vectorlike, with contents are like a
1287 vector but with a few other slots. For some purposes, it makes
1288 sense to handle a char-table with type struct Lisp_Vector. An
1289 element of a char table can be any Lisp objects, but if it is a sub
1290 char-table, we treat it a table that contains information of a
1291 specific range of characters. A sub char-table has the same
1292 structure as a vector. A sub char table appears only in an element
1293 of a char-table, and there's no way to access it directly from
1294 Emacs Lisp program. */
1295
1296 enum CHARTAB_SIZE_BITS
1297 {
1298 CHARTAB_SIZE_BITS_0 = 6,
1299 CHARTAB_SIZE_BITS_1 = 4,
1300 CHARTAB_SIZE_BITS_2 = 5,
1301 CHARTAB_SIZE_BITS_3 = 7
1302 };
1303
1304 extern const int chartab_size[4];
1305
1306 struct Lisp_Char_Table
1307 {
1308 /* HEADER.SIZE is the vector's size field, which also holds the
1309 pseudovector type information. It holds the size, too.
1310 The size counts the defalt, parent, purpose, ascii,
1311 contents, and extras slots. */
1312 struct vectorlike_header header;
1313
1314 /* This holds a default value,
1315 which is used whenever the value for a specific character is nil. */
1316 Lisp_Object defalt;
1317
1318 /* This points to another char table, which we inherit from when the
1319 value for a specific character is nil. The `defalt' slot takes
1320 precedence over this. */
1321 Lisp_Object parent;
1322
1323 /* This is a symbol which says what kind of use this char-table is
1324 meant for. */
1325 Lisp_Object purpose;
1326
1327 /* The bottom sub char-table for characters of the range 0..127. It
1328 is nil if none of ASCII character has a specific value. */
1329 Lisp_Object ascii;
1330
1331 Lisp_Object contents[(1 << CHARTAB_SIZE_BITS_0)];
1332
1333 /* These hold additional data. It is a vector. */
1334 Lisp_Object extras[FLEXIBLE_ARRAY_MEMBER];
1335 };
1336
1337 struct Lisp_Sub_Char_Table
1338 {
1339 /* HEADER.SIZE is the vector's size field, which also holds the
1340 pseudovector type information. It holds the size, too. */
1341 struct vectorlike_header header;
1342
1343 /* Depth of this sub char-table. It should be 1, 2, or 3. A sub
1344 char-table of depth 1 contains 16 elements, and each element
1345 covers 4096 (128*32) characters. A sub char-table of depth 2
1346 contains 32 elements, and each element covers 128 characters. A
1347 sub char-table of depth 3 contains 128 elements, and each element
1348 is for one character. */
1349 Lisp_Object depth;
1350
1351 /* Minimum character covered by the sub char-table. */
1352 Lisp_Object min_char;
1353
1354 /* Use set_sub_char_table_contents to set this. */
1355 Lisp_Object contents[FLEXIBLE_ARRAY_MEMBER];
1356 };
1357
1358 INLINE Lisp_Object
1359 CHAR_TABLE_REF_ASCII (Lisp_Object ct, ptrdiff_t idx)
1360 {
1361 struct Lisp_Char_Table *tbl = NULL;
1362 Lisp_Object val;
1363 do
1364 {
1365 tbl = tbl ? XCHAR_TABLE (tbl->parent) : XCHAR_TABLE (ct);
1366 val = (! SUB_CHAR_TABLE_P (tbl->ascii) ? tbl->ascii
1367 : XSUB_CHAR_TABLE (tbl->ascii)->contents[idx]);
1368 if (NILP (val))
1369 val = tbl->defalt;
1370 }
1371 while (NILP (val) && ! NILP (tbl->parent));
1372
1373 return val;
1374 }
1375
1376 /* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
1377 characters. Do not check validity of CT. */
1378 INLINE Lisp_Object
1379 CHAR_TABLE_REF (Lisp_Object ct, int idx)
1380 {
1381 return (ASCII_CHAR_P (idx)
1382 ? CHAR_TABLE_REF_ASCII (ct, idx)
1383 : char_table_ref (ct, idx));
1384 }
1385
1386 /* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
1387 8-bit European characters. Do not check validity of CT. */
1388 INLINE void
1389 CHAR_TABLE_SET (Lisp_Object ct, int idx, Lisp_Object val)
1390 {
1391 if (ASCII_CHAR_P (idx) && SUB_CHAR_TABLE_P (XCHAR_TABLE (ct)->ascii))
1392 set_sub_char_table_contents (XCHAR_TABLE (ct)->ascii, idx, val);
1393 else
1394 char_table_set (ct, idx, val);
1395 }
1396
1397 /* This structure describes a built-in function.
1398 It is generated by the DEFUN macro only.
1399 defsubr makes it into a Lisp object. */
1400
1401 struct Lisp_Subr
1402 {
1403 struct vectorlike_header header;
1404 union {
1405 Lisp_Object (*a0) (void);
1406 Lisp_Object (*a1) (Lisp_Object);
1407 Lisp_Object (*a2) (Lisp_Object, Lisp_Object);
1408 Lisp_Object (*a3) (Lisp_Object, Lisp_Object, Lisp_Object);
1409 Lisp_Object (*a4) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1410 Lisp_Object (*a5) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1411 Lisp_Object (*a6) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1412 Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1413 Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1414 Lisp_Object (*aUNEVALLED) (Lisp_Object args);
1415 Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
1416 } function;
1417 short min_args, max_args;
1418 const char *symbol_name;
1419 const char *intspec;
1420 const char *doc;
1421 };
1422
1423 /* This is the number of slots that every char table must have. This
1424 counts the ordinary slots and the top, defalt, parent, and purpose
1425 slots. */
1426 enum CHAR_TABLE_STANDARD_SLOTS
1427 {
1428 CHAR_TABLE_STANDARD_SLOTS = PSEUDOVECSIZE (struct Lisp_Char_Table, extras)
1429 };
1430
1431 /* Return the number of "extra" slots in the char table CT. */
1432
1433 INLINE int
1434 CHAR_TABLE_EXTRA_SLOTS (struct Lisp_Char_Table *ct)
1435 {
1436 return ((ct->header.size & PSEUDOVECTOR_SIZE_MASK)
1437 - CHAR_TABLE_STANDARD_SLOTS);
1438 }
1439
1440 \f
1441 /***********************************************************************
1442 Symbols
1443 ***********************************************************************/
1444
1445 /* Interned state of a symbol. */
1446
1447 enum symbol_interned
1448 {
1449 SYMBOL_UNINTERNED = 0,
1450 SYMBOL_INTERNED = 1,
1451 SYMBOL_INTERNED_IN_INITIAL_OBARRAY = 2
1452 };
1453
1454 enum symbol_redirect
1455 {
1456 SYMBOL_PLAINVAL = 4,
1457 SYMBOL_VARALIAS = 1,
1458 SYMBOL_LOCALIZED = 2,
1459 SYMBOL_FORWARDED = 3
1460 };
1461
1462 struct Lisp_Symbol
1463 {
1464 unsigned gcmarkbit : 1;
1465
1466 /* Indicates where the value can be found:
1467 0 : it's a plain var, the value is in the `value' field.
1468 1 : it's a varalias, the value is really in the `alias' symbol.
1469 2 : it's a localized var, the value is in the `blv' object.
1470 3 : it's a forwarding variable, the value is in `forward'. */
1471 ENUM_BF (symbol_redirect) redirect : 3;
1472
1473 /* Non-zero means symbol is constant, i.e. changing its value
1474 should signal an error. If the value is 3, then the var
1475 can be changed, but only by `defconst'. */
1476 unsigned constant : 2;
1477
1478 /* Interned state of the symbol. This is an enumerator from
1479 enum symbol_interned. */
1480 unsigned interned : 2;
1481
1482 /* Non-zero means that this variable has been explicitly declared
1483 special (with `defvar' etc), and shouldn't be lexically bound. */
1484 unsigned declared_special : 1;
1485
1486 /* The symbol's name, as a Lisp string. */
1487 Lisp_Object name;
1488
1489 /* Value of the symbol or Qunbound if unbound. Which alternative of the
1490 union is used depends on the `redirect' field above. */
1491 union {
1492 Lisp_Object value;
1493 struct Lisp_Symbol *alias;
1494 struct Lisp_Buffer_Local_Value *blv;
1495 union Lisp_Fwd *fwd;
1496 } val;
1497
1498 /* Function value of the symbol or Qnil if not fboundp. */
1499 Lisp_Object function;
1500
1501 /* The symbol's property list. */
1502 Lisp_Object plist;
1503
1504 /* Next symbol in obarray bucket, if the symbol is interned. */
1505 struct Lisp_Symbol *next;
1506 };
1507
1508 /* Value is name of symbol. */
1509
1510 LISP_MACRO_DEFUN (SYMBOL_VAL, Lisp_Object, (struct Lisp_Symbol *sym), (sym))
1511
1512 INLINE struct Lisp_Symbol *
1513 SYMBOL_ALIAS (struct Lisp_Symbol *sym)
1514 {
1515 eassert (sym->redirect == SYMBOL_VARALIAS);
1516 return sym->val.alias;
1517 }
1518 INLINE struct Lisp_Buffer_Local_Value *
1519 SYMBOL_BLV (struct Lisp_Symbol *sym)
1520 {
1521 eassert (sym->redirect == SYMBOL_LOCALIZED);
1522 return sym->val.blv;
1523 }
1524 INLINE union Lisp_Fwd *
1525 SYMBOL_FWD (struct Lisp_Symbol *sym)
1526 {
1527 eassert (sym->redirect == SYMBOL_FORWARDED);
1528 return sym->val.fwd;
1529 }
1530
1531 LISP_MACRO_DEFUN_VOID (SET_SYMBOL_VAL,
1532 (struct Lisp_Symbol *sym, Lisp_Object v), (sym, v))
1533
1534 INLINE void
1535 SET_SYMBOL_ALIAS (struct Lisp_Symbol *sym, struct Lisp_Symbol *v)
1536 {
1537 eassert (sym->redirect == SYMBOL_VARALIAS);
1538 sym->val.alias = v;
1539 }
1540 INLINE void
1541 SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v)
1542 {
1543 eassert (sym->redirect == SYMBOL_LOCALIZED);
1544 sym->val.blv = v;
1545 }
1546 INLINE void
1547 SET_SYMBOL_FWD (struct Lisp_Symbol *sym, union Lisp_Fwd *v)
1548 {
1549 eassert (sym->redirect == SYMBOL_FORWARDED);
1550 sym->val.fwd = v;
1551 }
1552
1553 INLINE Lisp_Object
1554 SYMBOL_NAME (Lisp_Object sym)
1555 {
1556 return XSYMBOL (sym)->name;
1557 }
1558
1559 /* Value is true if SYM is an interned symbol. */
1560
1561 INLINE bool
1562 SYMBOL_INTERNED_P (Lisp_Object sym)
1563 {
1564 return XSYMBOL (sym)->interned != SYMBOL_UNINTERNED;
1565 }
1566
1567 /* Value is true if SYM is interned in initial_obarray. */
1568
1569 INLINE bool
1570 SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (Lisp_Object sym)
1571 {
1572 return XSYMBOL (sym)->interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
1573 }
1574
1575 /* Value is non-zero if symbol is considered a constant, i.e. its
1576 value cannot be changed (there is an exception for keyword symbols,
1577 whose value can be set to the keyword symbol itself). */
1578
1579 LISP_MACRO_DEFUN (SYMBOL_CONSTANT_P, int, (Lisp_Object sym), (sym))
1580
1581 #define DEFSYM(sym, name) \
1582 do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0)
1583
1584 \f
1585 /***********************************************************************
1586 Hash Tables
1587 ***********************************************************************/
1588
1589 /* The structure of a Lisp hash table. */
1590
1591 struct hash_table_test
1592 {
1593 /* Name of the function used to compare keys. */
1594 Lisp_Object name;
1595
1596 /* User-supplied hash function, or nil. */
1597 Lisp_Object user_hash_function;
1598
1599 /* User-supplied key comparison function, or nil. */
1600 Lisp_Object user_cmp_function;
1601
1602 /* C function to compare two keys. */
1603 bool (*cmpfn) (struct hash_table_test *t, Lisp_Object, Lisp_Object);
1604
1605 /* C function to compute hash code. */
1606 EMACS_UINT (*hashfn) (struct hash_table_test *t, Lisp_Object);
1607 };
1608
1609 struct Lisp_Hash_Table
1610 {
1611 /* This is for Lisp; the hash table code does not refer to it. */
1612 struct vectorlike_header header;
1613
1614 /* Nil if table is non-weak. Otherwise a symbol describing the
1615 weakness of the table. */
1616 Lisp_Object weak;
1617
1618 /* When the table is resized, and this is an integer, compute the
1619 new size by adding this to the old size. If a float, compute the
1620 new size by multiplying the old size with this factor. */
1621 Lisp_Object rehash_size;
1622
1623 /* Resize hash table when number of entries/ table size is >= this
1624 ratio, a float. */
1625 Lisp_Object rehash_threshold;
1626
1627 /* Vector of hash codes.. If hash[I] is nil, this means that that
1628 entry I is unused. */
1629 Lisp_Object hash;
1630
1631 /* Vector used to chain entries. If entry I is free, next[I] is the
1632 entry number of the next free item. If entry I is non-free,
1633 next[I] is the index of the next entry in the collision chain. */
1634 Lisp_Object next;
1635
1636 /* Index of first free entry in free list. */
1637 Lisp_Object next_free;
1638
1639 /* Bucket vector. A non-nil entry is the index of the first item in
1640 a collision chain. This vector's size can be larger than the
1641 hash table size to reduce collisions. */
1642 Lisp_Object index;
1643
1644 /* Only the fields above are traced normally by the GC. The ones below
1645 `count' are special and are either ignored by the GC or traced in
1646 a special way (e.g. because of weakness). */
1647
1648 /* Number of key/value entries in the table. */
1649 ptrdiff_t count;
1650
1651 /* Vector of keys and values. The key of item I is found at index
1652 2 * I, the value is found at index 2 * I + 1.
1653 This is gc_marked specially if the table is weak. */
1654 Lisp_Object key_and_value;
1655
1656 /* The comparison and hash functions. */
1657 struct hash_table_test test;
1658
1659 /* Next weak hash table if this is a weak hash table. The head
1660 of the list is in weak_hash_tables. */
1661 struct Lisp_Hash_Table *next_weak;
1662 };
1663
1664
1665 INLINE struct Lisp_Hash_Table *
1666 XHASH_TABLE (Lisp_Object a)
1667 {
1668 return XUNTAG (a, Lisp_Vectorlike);
1669 }
1670
1671 #define XSET_HASH_TABLE(VAR, PTR) \
1672 (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
1673
1674 INLINE bool
1675 HASH_TABLE_P (Lisp_Object a)
1676 {
1677 return PSEUDOVECTORP (a, PVEC_HASH_TABLE);
1678 }
1679
1680 /* Value is the key part of entry IDX in hash table H. */
1681 INLINE Lisp_Object
1682 HASH_KEY (struct Lisp_Hash_Table *h, ptrdiff_t idx)
1683 {
1684 return AREF (h->key_and_value, 2 * idx);
1685 }
1686
1687 /* Value is the value part of entry IDX in hash table H. */
1688 INLINE Lisp_Object
1689 HASH_VALUE (struct Lisp_Hash_Table *h, ptrdiff_t idx)
1690 {
1691 return AREF (h->key_and_value, 2 * idx + 1);
1692 }
1693
1694 /* Value is the index of the next entry following the one at IDX
1695 in hash table H. */
1696 INLINE Lisp_Object
1697 HASH_NEXT (struct Lisp_Hash_Table *h, ptrdiff_t idx)
1698 {
1699 return AREF (h->next, idx);
1700 }
1701
1702 /* Value is the hash code computed for entry IDX in hash table H. */
1703 INLINE Lisp_Object
1704 HASH_HASH (struct Lisp_Hash_Table *h, ptrdiff_t idx)
1705 {
1706 return AREF (h->hash, idx);
1707 }
1708
1709 /* Value is the index of the element in hash table H that is the
1710 start of the collision list at index IDX in the index vector of H. */
1711 INLINE Lisp_Object
1712 HASH_INDEX (struct Lisp_Hash_Table *h, ptrdiff_t idx)
1713 {
1714 return AREF (h->index, idx);
1715 }
1716
1717 /* Value is the size of hash table H. */
1718 INLINE ptrdiff_t
1719 HASH_TABLE_SIZE (struct Lisp_Hash_Table *h)
1720 {
1721 return ASIZE (h->next);
1722 }
1723
1724 /* Default size for hash tables if not specified. */
1725
1726 enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
1727
1728 /* Default threshold specifying when to resize a hash table. The
1729 value gives the ratio of current entries in the hash table and the
1730 size of the hash table. */
1731
1732 static double const DEFAULT_REHASH_THRESHOLD = 0.8;
1733
1734 /* Default factor by which to increase the size of a hash table. */
1735
1736 static double const DEFAULT_REHASH_SIZE = 1.5;
1737
1738 /* Combine two integers X and Y for hashing. The result might not fit
1739 into a Lisp integer. */
1740
1741 INLINE EMACS_UINT
1742 sxhash_combine (EMACS_UINT x, EMACS_UINT y)
1743 {
1744 return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y;
1745 }
1746
1747 /* Hash X, returning a value that fits into a fixnum. */
1748
1749 INLINE EMACS_UINT
1750 SXHASH_REDUCE (EMACS_UINT x)
1751 {
1752 return (x ^ x >> (BITS_PER_EMACS_INT - FIXNUM_BITS)) & INTMASK;
1753 }
1754
1755 /* These structures are used for various misc types. */
1756
1757 struct Lisp_Misc_Any /* Supertype of all Misc types. */
1758 {
1759 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_??? */
1760 unsigned gcmarkbit : 1;
1761 int spacer : 15;
1762 };
1763
1764 struct Lisp_Marker
1765 {
1766 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Marker */
1767 unsigned gcmarkbit : 1;
1768 int spacer : 13;
1769 /* This flag is temporarily used in the functions
1770 decode/encode_coding_object to record that the marker position
1771 must be adjusted after the conversion. */
1772 unsigned int need_adjustment : 1;
1773 /* 1 means normal insertion at the marker's position
1774 leaves the marker after the inserted text. */
1775 unsigned int insertion_type : 1;
1776 /* This is the buffer that the marker points into, or 0 if it points nowhere.
1777 Note: a chain of markers can contain markers pointing into different
1778 buffers (the chain is per buffer_text rather than per buffer, so it's
1779 shared between indirect buffers). */
1780 /* This is used for (other than NULL-checking):
1781 - Fmarker_buffer
1782 - Fset_marker: check eq(oldbuf, newbuf) to avoid unchain+rechain.
1783 - unchain_marker: to find the list from which to unchain.
1784 - Fkill_buffer: to only unchain the markers of current indirect buffer.
1785 */
1786 struct buffer *buffer;
1787
1788 /* The remaining fields are meaningless in a marker that
1789 does not point anywhere. */
1790
1791 /* For markers that point somewhere,
1792 this is used to chain of all the markers in a given buffer. */
1793 /* We could remove it and use an array in buffer_text instead.
1794 That would also allow to preserve it ordered. */
1795 struct Lisp_Marker *next;
1796 /* This is the char position where the marker points. */
1797 ptrdiff_t charpos;
1798 /* This is the byte position.
1799 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
1800 used to implement the functionality of markers, but rather to (ab)use
1801 markers as a cache for char<->byte mappings). */
1802 ptrdiff_t bytepos;
1803 };
1804
1805 /* START and END are markers in the overlay's buffer, and
1806 PLIST is the overlay's property list. */
1807 struct Lisp_Overlay
1808 /* An overlay's real data content is:
1809 - plist
1810 - buffer (really there are two buffer pointers, one per marker,
1811 and both points to the same buffer)
1812 - insertion type of both ends (per-marker fields)
1813 - start & start byte (of start marker)
1814 - end & end byte (of end marker)
1815 - next (singly linked list of overlays)
1816 - next fields of start and end markers (singly linked list of markers).
1817 I.e. 9words plus 2 bits, 3words of which are for external linked lists.
1818 */
1819 {
1820 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Overlay */
1821 unsigned gcmarkbit : 1;
1822 int spacer : 15;
1823 struct Lisp_Overlay *next;
1824 Lisp_Object start;
1825 Lisp_Object end;
1826 Lisp_Object plist;
1827 };
1828
1829 /* Types of data which may be saved in a Lisp_Save_Value. */
1830
1831 enum
1832 {
1833 SAVE_UNUSED,
1834 SAVE_INTEGER,
1835 SAVE_FUNCPOINTER,
1836 SAVE_POINTER,
1837 SAVE_OBJECT
1838 };
1839
1840 /* Number of bits needed to store one of the above values. */
1841 enum { SAVE_SLOT_BITS = 3 };
1842
1843 /* Number of slots in a save value where save_type is nonzero. */
1844 enum { SAVE_VALUE_SLOTS = 4 };
1845
1846 /* Bit-width and values for struct Lisp_Save_Value's save_type member. */
1847
1848 enum { SAVE_TYPE_BITS = SAVE_VALUE_SLOTS * SAVE_SLOT_BITS + 1 };
1849
1850 enum Lisp_Save_Type
1851 {
1852 SAVE_TYPE_INT_INT = SAVE_INTEGER + (SAVE_INTEGER << SAVE_SLOT_BITS),
1853 SAVE_TYPE_INT_INT_INT
1854 = (SAVE_INTEGER + (SAVE_TYPE_INT_INT << SAVE_SLOT_BITS)),
1855 SAVE_TYPE_OBJ_OBJ = SAVE_OBJECT + (SAVE_OBJECT << SAVE_SLOT_BITS),
1856 SAVE_TYPE_OBJ_OBJ_OBJ = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ << SAVE_SLOT_BITS),
1857 SAVE_TYPE_OBJ_OBJ_OBJ_OBJ
1858 = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ_OBJ << SAVE_SLOT_BITS),
1859 SAVE_TYPE_PTR_INT = SAVE_POINTER + (SAVE_INTEGER << SAVE_SLOT_BITS),
1860 SAVE_TYPE_PTR_OBJ = SAVE_POINTER + (SAVE_OBJECT << SAVE_SLOT_BITS),
1861 SAVE_TYPE_PTR_PTR = SAVE_POINTER + (SAVE_POINTER << SAVE_SLOT_BITS),
1862 SAVE_TYPE_FUNCPTR_PTR_OBJ
1863 = SAVE_FUNCPOINTER + (SAVE_TYPE_PTR_OBJ << SAVE_SLOT_BITS),
1864
1865 /* This has an extra bit indicating it's raw memory. */
1866 SAVE_TYPE_MEMORY = SAVE_TYPE_PTR_INT + (1 << (SAVE_TYPE_BITS - 1))
1867 };
1868
1869 /* Special object used to hold a different values for later use.
1870
1871 This is mostly used to package C integers and pointers to call
1872 record_unwind_protect when two or more values need to be saved.
1873 For example:
1874
1875 ...
1876 struct my_data *md = get_my_data ();
1877 ptrdiff_t mi = get_my_integer ();
1878 record_unwind_protect (my_unwind, make_save_ptr_int (md, mi));
1879 ...
1880
1881 Lisp_Object my_unwind (Lisp_Object arg)
1882 {
1883 struct my_data *md = XSAVE_POINTER (arg, 0);
1884 ptrdiff_t mi = XSAVE_INTEGER (arg, 1);
1885 ...
1886 }
1887
1888 If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the
1889 saved objects and raise eassert if type of the saved object doesn't match
1890 the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2)
1891 and XSAVE_OBJECT (arg, 0) are wrong because nothing was saved in slot 2 and
1892 slot 0 is a pointer. */
1893
1894 typedef void (*voidfuncptr) (void);
1895
1896 struct Lisp_Save_Value
1897 {
1898 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */
1899 unsigned gcmarkbit : 1;
1900 int spacer : 32 - (16 + 1 + SAVE_TYPE_BITS);
1901
1902 /* V->data may hold up to SAVE_VALUE_SLOTS entries. The type of
1903 V's data entries are determined by V->save_type. E.g., if
1904 V->save_type == SAVE_TYPE_PTR_OBJ, V->data[0] is a pointer,
1905 V->data[1] is an integer, and V's other data entries are unused.
1906
1907 If V->save_type == SAVE_TYPE_MEMORY, V->data[0].pointer is the address of
1908 a memory area containing V->data[1].integer potential Lisp_Objects. */
1909 ENUM_BF (Lisp_Save_Type) save_type : SAVE_TYPE_BITS;
1910 union {
1911 void *pointer;
1912 voidfuncptr funcpointer;
1913 ptrdiff_t integer;
1914 Lisp_Object object;
1915 } data[SAVE_VALUE_SLOTS];
1916 };
1917
1918 /* Return the type of V's Nth saved value. */
1919 INLINE int
1920 save_type (struct Lisp_Save_Value *v, int n)
1921 {
1922 eassert (0 <= n && n < SAVE_VALUE_SLOTS);
1923 return (v->save_type >> (SAVE_SLOT_BITS * n) & ((1 << SAVE_SLOT_BITS) - 1));
1924 }
1925
1926 /* Get and set the Nth saved pointer. */
1927
1928 INLINE void *
1929 XSAVE_POINTER (Lisp_Object obj, int n)
1930 {
1931 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
1932 return XSAVE_VALUE (obj)->data[n].pointer;
1933 }
1934 INLINE void
1935 set_save_pointer (Lisp_Object obj, int n, void *val)
1936 {
1937 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
1938 XSAVE_VALUE (obj)->data[n].pointer = val;
1939 }
1940 INLINE voidfuncptr
1941 XSAVE_FUNCPOINTER (Lisp_Object obj, int n)
1942 {
1943 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_FUNCPOINTER);
1944 return XSAVE_VALUE (obj)->data[n].funcpointer;
1945 }
1946
1947 /* Likewise for the saved integer. */
1948
1949 INLINE ptrdiff_t
1950 XSAVE_INTEGER (Lisp_Object obj, int n)
1951 {
1952 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
1953 return XSAVE_VALUE (obj)->data[n].integer;
1954 }
1955 INLINE void
1956 set_save_integer (Lisp_Object obj, int n, ptrdiff_t val)
1957 {
1958 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
1959 XSAVE_VALUE (obj)->data[n].integer = val;
1960 }
1961
1962 /* Extract Nth saved object. */
1963
1964 INLINE Lisp_Object
1965 XSAVE_OBJECT (Lisp_Object obj, int n)
1966 {
1967 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_OBJECT);
1968 return XSAVE_VALUE (obj)->data[n].object;
1969 }
1970
1971 /* A miscellaneous object, when it's on the free list. */
1972 struct Lisp_Free
1973 {
1974 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Free */
1975 unsigned gcmarkbit : 1;
1976 int spacer : 15;
1977 union Lisp_Misc *chain;
1978 };
1979
1980 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
1981 It uses one of these struct subtypes to get the type field. */
1982
1983 union Lisp_Misc
1984 {
1985 struct Lisp_Misc_Any u_any; /* Supertype of all Misc types. */
1986 struct Lisp_Free u_free;
1987 struct Lisp_Marker u_marker;
1988 struct Lisp_Overlay u_overlay;
1989 struct Lisp_Save_Value u_save_value;
1990 };
1991
1992 INLINE union Lisp_Misc *
1993 XMISC (Lisp_Object a)
1994 {
1995 return XUNTAG (a, Lisp_Misc);
1996 }
1997
1998 INLINE struct Lisp_Misc_Any *
1999 XMISCANY (Lisp_Object a)
2000 {
2001 eassert (MISCP (a));
2002 return & XMISC (a)->u_any;
2003 }
2004
2005 INLINE enum Lisp_Misc_Type
2006 XMISCTYPE (Lisp_Object a)
2007 {
2008 return XMISCANY (a)->type;
2009 }
2010
2011 INLINE struct Lisp_Marker *
2012 XMARKER (Lisp_Object a)
2013 {
2014 eassert (MARKERP (a));
2015 return & XMISC (a)->u_marker;
2016 }
2017
2018 INLINE struct Lisp_Overlay *
2019 XOVERLAY (Lisp_Object a)
2020 {
2021 eassert (OVERLAYP (a));
2022 return & XMISC (a)->u_overlay;
2023 }
2024
2025 INLINE struct Lisp_Save_Value *
2026 XSAVE_VALUE (Lisp_Object a)
2027 {
2028 eassert (SAVE_VALUEP (a));
2029 return & XMISC (a)->u_save_value;
2030 }
2031 \f
2032 /* Forwarding pointer to an int variable.
2033 This is allowed only in the value cell of a symbol,
2034 and it means that the symbol's value really lives in the
2035 specified int variable. */
2036 struct Lisp_Intfwd
2037 {
2038 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Int */
2039 EMACS_INT *intvar;
2040 };
2041
2042 /* Boolean forwarding pointer to an int variable.
2043 This is like Lisp_Intfwd except that the ostensible
2044 "value" of the symbol is t if the int variable is nonzero,
2045 nil if it is zero. */
2046 struct Lisp_Boolfwd
2047 {
2048 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Bool */
2049 bool *boolvar;
2050 };
2051
2052 /* Forwarding pointer to a Lisp_Object variable.
2053 This is allowed only in the value cell of a symbol,
2054 and it means that the symbol's value really lives in the
2055 specified variable. */
2056 struct Lisp_Objfwd
2057 {
2058 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Obj */
2059 Lisp_Object *objvar;
2060 };
2061
2062 /* Like Lisp_Objfwd except that value lives in a slot in the
2063 current buffer. Value is byte index of slot within buffer. */
2064 struct Lisp_Buffer_Objfwd
2065 {
2066 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Buffer_Obj */
2067 int offset;
2068 /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp or Qnumberp. */
2069 Lisp_Object predicate;
2070 };
2071
2072 /* struct Lisp_Buffer_Local_Value is used in a symbol value cell when
2073 the symbol has buffer-local or frame-local bindings. (Exception:
2074 some buffer-local variables are built-in, with their values stored
2075 in the buffer structure itself. They are handled differently,
2076 using struct Lisp_Buffer_Objfwd.)
2077
2078 The `realvalue' slot holds the variable's current value, or a
2079 forwarding pointer to where that value is kept. This value is the
2080 one that corresponds to the loaded binding. To read or set the
2081 variable, you must first make sure the right binding is loaded;
2082 then you can access the value in (or through) `realvalue'.
2083
2084 `buffer' and `frame' are the buffer and frame for which the loaded
2085 binding was found. If those have changed, to make sure the right
2086 binding is loaded it is necessary to find which binding goes with
2087 the current buffer and selected frame, then load it. To load it,
2088 first unload the previous binding, then copy the value of the new
2089 binding into `realvalue' (or through it). Also update
2090 LOADED-BINDING to point to the newly loaded binding.
2091
2092 `local_if_set' indicates that merely setting the variable creates a
2093 local binding for the current buffer. Otherwise the latter, setting
2094 the variable does not do that; only make-local-variable does that. */
2095
2096 struct Lisp_Buffer_Local_Value
2097 {
2098 /* 1 means that merely setting the variable creates a local
2099 binding for the current buffer. */
2100 unsigned int local_if_set : 1;
2101 /* 1 means this variable can have frame-local bindings, otherwise, it is
2102 can have buffer-local bindings. The two cannot be combined. */
2103 unsigned int frame_local : 1;
2104 /* 1 means that the binding now loaded was found.
2105 Presumably equivalent to (defcell!=valcell). */
2106 unsigned int found : 1;
2107 /* If non-NULL, a forwarding to the C var where it should also be set. */
2108 union Lisp_Fwd *fwd; /* Should never be (Buffer|Kboard)_Objfwd. */
2109 /* The buffer or frame for which the loaded binding was found. */
2110 Lisp_Object where;
2111 /* A cons cell that holds the default value. It has the form
2112 (SYMBOL . DEFAULT-VALUE). */
2113 Lisp_Object defcell;
2114 /* The cons cell from `where's parameter alist.
2115 It always has the form (SYMBOL . VALUE)
2116 Note that if `forward' is non-nil, VALUE may be out of date.
2117 Also if the currently loaded binding is the default binding, then
2118 this is `eq'ual to defcell. */
2119 Lisp_Object valcell;
2120 };
2121
2122 /* Like Lisp_Objfwd except that value lives in a slot in the
2123 current kboard. */
2124 struct Lisp_Kboard_Objfwd
2125 {
2126 enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Kboard_Obj */
2127 int offset;
2128 };
2129
2130 union Lisp_Fwd
2131 {
2132 struct Lisp_Intfwd u_intfwd;
2133 struct Lisp_Boolfwd u_boolfwd;
2134 struct Lisp_Objfwd u_objfwd;
2135 struct Lisp_Buffer_Objfwd u_buffer_objfwd;
2136 struct Lisp_Kboard_Objfwd u_kboard_objfwd;
2137 };
2138
2139 INLINE enum Lisp_Fwd_Type
2140 XFWDTYPE (union Lisp_Fwd *a)
2141 {
2142 return a->u_intfwd.type;
2143 }
2144
2145 INLINE struct Lisp_Buffer_Objfwd *
2146 XBUFFER_OBJFWD (union Lisp_Fwd *a)
2147 {
2148 eassert (BUFFER_OBJFWDP (a));
2149 return &a->u_buffer_objfwd;
2150 }
2151 \f
2152 /* Lisp floating point type. */
2153 struct Lisp_Float
2154 {
2155 union
2156 {
2157 double data;
2158 struct Lisp_Float *chain;
2159 } u;
2160 };
2161
2162 INLINE double
2163 XFLOAT_DATA (Lisp_Object f)
2164 {
2165 return XFLOAT (f)->u.data;
2166 }
2167
2168 /* Most hosts nowadays use IEEE floating point, so they use IEC 60559
2169 representations, have infinities and NaNs, and do not trap on
2170 exceptions. Define IEEE_FLOATING_POINT if this host is one of the
2171 typical ones. The C11 macro __STDC_IEC_559__ is close to what is
2172 wanted here, but is not quite right because Emacs does not require
2173 all the features of C11 Annex F (and does not require C11 at all,
2174 for that matter). */
2175 enum
2176 {
2177 IEEE_FLOATING_POINT
2178 = (FLT_RADIX == 2 && FLT_MANT_DIG == 24
2179 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
2180 };
2181
2182 /* A character, declared with the following typedef, is a member
2183 of some character set associated with the current buffer. */
2184 #ifndef _UCHAR_T /* Protect against something in ctab.h on AIX. */
2185 #define _UCHAR_T
2186 typedef unsigned char UCHAR;
2187 #endif
2188
2189 /* Meanings of slots in a Lisp_Compiled: */
2190
2191 enum Lisp_Compiled
2192 {
2193 COMPILED_ARGLIST = 0,
2194 COMPILED_BYTECODE = 1,
2195 COMPILED_CONSTANTS = 2,
2196 COMPILED_STACK_DEPTH = 3,
2197 COMPILED_DOC_STRING = 4,
2198 COMPILED_INTERACTIVE = 5
2199 };
2200
2201 /* Flag bits in a character. These also get used in termhooks.h.
2202 Richard Stallman <rms@gnu.ai.mit.edu> thinks that MULE
2203 (MUlti-Lingual Emacs) might need 22 bits for the character value
2204 itself, so we probably shouldn't use any bits lower than 0x0400000. */
2205 enum char_bits
2206 {
2207 CHAR_ALT = 0x0400000,
2208 CHAR_SUPER = 0x0800000,
2209 CHAR_HYPER = 0x1000000,
2210 CHAR_SHIFT = 0x2000000,
2211 CHAR_CTL = 0x4000000,
2212 CHAR_META = 0x8000000,
2213
2214 CHAR_MODIFIER_MASK =
2215 CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META,
2216
2217 /* Actually, the current Emacs uses 22 bits for the character value
2218 itself. */
2219 CHARACTERBITS = 22
2220 };
2221 \f
2222 /* Data type checking. */
2223
2224 LISP_MACRO_DEFUN (NILP, bool, (Lisp_Object x), (x))
2225
2226 INLINE bool
2227 NUMBERP (Lisp_Object x)
2228 {
2229 return INTEGERP (x) || FLOATP (x);
2230 }
2231 INLINE bool
2232 NATNUMP (Lisp_Object x)
2233 {
2234 return INTEGERP (x) && 0 <= XINT (x);
2235 }
2236
2237 INLINE bool
2238 RANGED_INTEGERP (intmax_t lo, Lisp_Object x, intmax_t hi)
2239 {
2240 return INTEGERP (x) && lo <= XINT (x) && XINT (x) <= hi;
2241 }
2242
2243 #define TYPE_RANGED_INTEGERP(type, x) \
2244 (INTEGERP (x) \
2245 && (TYPE_SIGNED (type) ? TYPE_MINIMUM (type) <= XINT (x) : 0 <= XINT (x)) \
2246 && XINT (x) <= TYPE_MAXIMUM (type))
2247
2248 LISP_MACRO_DEFUN (CONSP, bool, (Lisp_Object x), (x))
2249 LISP_MACRO_DEFUN (FLOATP, bool, (Lisp_Object x), (x))
2250 LISP_MACRO_DEFUN (MISCP, bool, (Lisp_Object x), (x))
2251 LISP_MACRO_DEFUN (SYMBOLP, bool, (Lisp_Object x), (x))
2252 LISP_MACRO_DEFUN (INTEGERP, bool, (Lisp_Object x), (x))
2253 LISP_MACRO_DEFUN (VECTORLIKEP, bool, (Lisp_Object x), (x))
2254 LISP_MACRO_DEFUN (MARKERP, bool, (Lisp_Object x), (x))
2255
2256 INLINE bool
2257 STRINGP (Lisp_Object x)
2258 {
2259 return XTYPE (x) == Lisp_String;
2260 }
2261 INLINE bool
2262 VECTORP (Lisp_Object x)
2263 {
2264 return VECTORLIKEP (x) && ! (ASIZE (x) & PSEUDOVECTOR_FLAG);
2265 }
2266 INLINE bool
2267 OVERLAYP (Lisp_Object x)
2268 {
2269 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay;
2270 }
2271 INLINE bool
2272 SAVE_VALUEP (Lisp_Object x)
2273 {
2274 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value;
2275 }
2276
2277 INLINE bool
2278 AUTOLOADP (Lisp_Object x)
2279 {
2280 return CONSP (x) && EQ (Qautoload, XCAR (x));
2281 }
2282
2283 INLINE bool
2284 BUFFER_OBJFWDP (union Lisp_Fwd *a)
2285 {
2286 return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj;
2287 }
2288
2289 INLINE bool
2290 PSEUDOVECTOR_TYPEP (struct vectorlike_header *a, int code)
2291 {
2292 return ((a->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))
2293 == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_AREA_BITS)));
2294 }
2295
2296 /* True if A is a pseudovector whose code is CODE. */
2297 INLINE bool
2298 PSEUDOVECTORP (Lisp_Object a, int code)
2299 {
2300 if (! VECTORLIKEP (a))
2301 return 0;
2302 else
2303 {
2304 /* Converting to struct vectorlike_header * avoids aliasing issues. */
2305 struct vectorlike_header *h = XUNTAG (a, Lisp_Vectorlike);
2306 return PSEUDOVECTOR_TYPEP (h, code);
2307 }
2308 }
2309
2310
2311 /* Test for specific pseudovector types. */
2312
2313 INLINE bool
2314 WINDOW_CONFIGURATIONP (Lisp_Object a)
2315 {
2316 return PSEUDOVECTORP (a, PVEC_WINDOW_CONFIGURATION);
2317 }
2318
2319 INLINE bool
2320 PROCESSP (Lisp_Object a)
2321 {
2322 return PSEUDOVECTORP (a, PVEC_PROCESS);
2323 }
2324
2325 INLINE bool
2326 WINDOWP (Lisp_Object a)
2327 {
2328 return PSEUDOVECTORP (a, PVEC_WINDOW);
2329 }
2330
2331 INLINE bool
2332 TERMINALP (Lisp_Object a)
2333 {
2334 return PSEUDOVECTORP (a, PVEC_TERMINAL);
2335 }
2336
2337 INLINE bool
2338 SUBRP (Lisp_Object a)
2339 {
2340 return PSEUDOVECTORP (a, PVEC_SUBR);
2341 }
2342
2343 INLINE bool
2344 COMPILEDP (Lisp_Object a)
2345 {
2346 return PSEUDOVECTORP (a, PVEC_COMPILED);
2347 }
2348
2349 INLINE bool
2350 BUFFERP (Lisp_Object a)
2351 {
2352 return PSEUDOVECTORP (a, PVEC_BUFFER);
2353 }
2354
2355 INLINE bool
2356 CHAR_TABLE_P (Lisp_Object a)
2357 {
2358 return PSEUDOVECTORP (a, PVEC_CHAR_TABLE);
2359 }
2360
2361 INLINE bool
2362 SUB_CHAR_TABLE_P (Lisp_Object a)
2363 {
2364 return PSEUDOVECTORP (a, PVEC_SUB_CHAR_TABLE);
2365 }
2366
2367 INLINE bool
2368 BOOL_VECTOR_P (Lisp_Object a)
2369 {
2370 return PSEUDOVECTORP (a, PVEC_BOOL_VECTOR);
2371 }
2372
2373 INLINE bool
2374 FRAMEP (Lisp_Object a)
2375 {
2376 return PSEUDOVECTORP (a, PVEC_FRAME);
2377 }
2378
2379 /* Test for image (image . spec) */
2380 INLINE bool
2381 IMAGEP (Lisp_Object x)
2382 {
2383 return CONSP (x) && EQ (XCAR (x), Qimage);
2384 }
2385
2386 /* Array types. */
2387 INLINE bool
2388 ARRAYP (Lisp_Object x)
2389 {
2390 return VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x);
2391 }
2392 \f
2393 INLINE void
2394 CHECK_LIST (Lisp_Object x)
2395 {
2396 CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x);
2397 }
2398
2399 LISP_MACRO_DEFUN_VOID (CHECK_LIST_CONS, (Lisp_Object x, Lisp_Object y), (x, y))
2400 LISP_MACRO_DEFUN_VOID (CHECK_SYMBOL, (Lisp_Object x), (x))
2401 LISP_MACRO_DEFUN_VOID (CHECK_NUMBER, (Lisp_Object x), (x))
2402
2403 INLINE void
2404 CHECK_STRING (Lisp_Object x)
2405 {
2406 CHECK_TYPE (STRINGP (x), Qstringp, x);
2407 }
2408 INLINE void
2409 CHECK_STRING_CAR (Lisp_Object x)
2410 {
2411 CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x));
2412 }
2413 INLINE void
2414 CHECK_CONS (Lisp_Object x)
2415 {
2416 CHECK_TYPE (CONSP (x), Qconsp, x);
2417 }
2418 INLINE void
2419 CHECK_VECTOR (Lisp_Object x)
2420 {
2421 CHECK_TYPE (VECTORP (x), Qvectorp, x);
2422 }
2423 INLINE void
2424 CHECK_BOOL_VECTOR (Lisp_Object x)
2425 {
2426 CHECK_TYPE (BOOL_VECTOR_P (x), Qbool_vector_p, x);
2427 }
2428 INLINE void
2429 CHECK_VECTOR_OR_STRING (Lisp_Object x)
2430 {
2431 CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x);
2432 }
2433 INLINE void
2434 CHECK_ARRAY (Lisp_Object x, Lisp_Object Qxxxp)
2435 {
2436 CHECK_TYPE (ARRAYP (x), Qxxxp, x);
2437 }
2438 INLINE void
2439 CHECK_BUFFER (Lisp_Object x)
2440 {
2441 CHECK_TYPE (BUFFERP (x), Qbufferp, x);
2442 }
2443 INLINE void
2444 CHECK_WINDOW (Lisp_Object x)
2445 {
2446 CHECK_TYPE (WINDOWP (x), Qwindowp, x);
2447 }
2448 INLINE void
2449 CHECK_PROCESS (Lisp_Object x)
2450 {
2451 CHECK_TYPE (PROCESSP (x), Qprocessp, x);
2452 }
2453 INLINE void
2454 CHECK_NATNUM (Lisp_Object x)
2455 {
2456 CHECK_TYPE (NATNUMP (x), Qwholenump, x);
2457 }
2458
2459 #define CHECK_RANGED_INTEGER(x, lo, hi) \
2460 do { \
2461 CHECK_NUMBER (x); \
2462 if (! ((lo) <= XINT (x) && XINT (x) <= (hi))) \
2463 args_out_of_range_3 \
2464 (x, \
2465 make_number ((lo) < 0 && (lo) < MOST_NEGATIVE_FIXNUM \
2466 ? MOST_NEGATIVE_FIXNUM \
2467 : (lo)), \
2468 make_number (min (hi, MOST_POSITIVE_FIXNUM))); \
2469 } while (0)
2470 #define CHECK_TYPE_RANGED_INTEGER(type, x) \
2471 do { \
2472 if (TYPE_SIGNED (type)) \
2473 CHECK_RANGED_INTEGER (x, TYPE_MINIMUM (type), TYPE_MAXIMUM (type)); \
2474 else \
2475 CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
2476 } while (0)
2477
2478 #define CHECK_NUMBER_COERCE_MARKER(x) \
2479 do { if (MARKERP ((x))) XSETFASTINT (x, marker_position (x)); \
2480 else CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); } while (0)
2481
2482 INLINE double
2483 XFLOATINT (Lisp_Object n)
2484 {
2485 return extract_float (n);
2486 }
2487
2488 INLINE void
2489 CHECK_NUMBER_OR_FLOAT (Lisp_Object x)
2490 {
2491 CHECK_TYPE (FLOATP (x) || INTEGERP (x), Qnumberp, x);
2492 }
2493
2494 #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \
2495 do { if (MARKERP (x)) XSETFASTINT (x, marker_position (x)); \
2496 else CHECK_TYPE (INTEGERP (x) || FLOATP (x), Qnumber_or_marker_p, x); } while (0)
2497
2498 /* Since we can't assign directly to the CAR or CDR fields of a cons
2499 cell, use these when checking that those fields contain numbers. */
2500 INLINE void
2501 CHECK_NUMBER_CAR (Lisp_Object x)
2502 {
2503 Lisp_Object tmp = XCAR (x);
2504 CHECK_NUMBER (tmp);
2505 XSETCAR (x, tmp);
2506 }
2507
2508 INLINE void
2509 CHECK_NUMBER_CDR (Lisp_Object x)
2510 {
2511 Lisp_Object tmp = XCDR (x);
2512 CHECK_NUMBER (tmp);
2513 XSETCDR (x, tmp);
2514 }
2515 \f
2516 /* Define a built-in function for calling from Lisp.
2517 `lname' should be the name to give the function in Lisp,
2518 as a null-terminated C string.
2519 `fnname' should be the name of the function in C.
2520 By convention, it starts with F.
2521 `sname' should be the name for the C constant structure
2522 that records information on this function for internal use.
2523 By convention, it should be the same as `fnname' but with S instead of F.
2524 It's too bad that C macros can't compute this from `fnname'.
2525 `minargs' should be a number, the minimum number of arguments allowed.
2526 `maxargs' should be a number, the maximum number of arguments allowed,
2527 or else MANY or UNEVALLED.
2528 MANY means pass a vector of evaluated arguments,
2529 in the form of an integer number-of-arguments
2530 followed by the address of a vector of Lisp_Objects
2531 which contains the argument values.
2532 UNEVALLED means pass the list of unevaluated arguments
2533 `intspec' says how interactive arguments are to be fetched.
2534 If the string starts with a `(', `intspec' is evaluated and the resulting
2535 list is the list of arguments.
2536 If it's a string that doesn't start with `(', the value should follow
2537 the one of the doc string for `interactive'.
2538 A null string means call interactively with no arguments.
2539 `doc' is documentation for the user. */
2540
2541 /* This version of DEFUN declares a function prototype with the right
2542 arguments, so we can catch errors with maxargs at compile-time. */
2543 #ifdef _MSC_VER
2544 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
2545 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
2546 static struct Lisp_Subr alignas (GCALIGNMENT) sname = \
2547 { { (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS) \
2548 | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)) }, \
2549 { (Lisp_Object (__cdecl *)(void))fnname }, \
2550 minargs, maxargs, lname, intspec, 0}; \
2551 Lisp_Object fnname
2552 #else /* not _MSC_VER */
2553 # if __STDC_VERSION__ < 199901
2554 # define DEFUN_FUNCTION_INIT(fnname, maxargs) (Lisp_Object (*) (void)) fnname
2555 # else
2556 # define DEFUN_FUNCTION_INIT(fnname, maxargs) .a ## maxargs = fnname
2557 # endif
2558 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
2559 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
2560 static struct Lisp_Subr alignas (GCALIGNMENT) sname = \
2561 { { PVEC_SUBR << PSEUDOVECTOR_AREA_BITS }, \
2562 { DEFUN_FUNCTION_INIT (fnname, maxargs) }, \
2563 minargs, maxargs, lname, intspec, 0}; \
2564 Lisp_Object fnname
2565 #endif
2566
2567 /* Note that the weird token-substitution semantics of ANSI C makes
2568 this work for MANY and UNEVALLED. */
2569 #define DEFUN_ARGS_MANY (ptrdiff_t, Lisp_Object *)
2570 #define DEFUN_ARGS_UNEVALLED (Lisp_Object)
2571 #define DEFUN_ARGS_0 (void)
2572 #define DEFUN_ARGS_1 (Lisp_Object)
2573 #define DEFUN_ARGS_2 (Lisp_Object, Lisp_Object)
2574 #define DEFUN_ARGS_3 (Lisp_Object, Lisp_Object, Lisp_Object)
2575 #define DEFUN_ARGS_4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
2576 #define DEFUN_ARGS_5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2577 Lisp_Object)
2578 #define DEFUN_ARGS_6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2579 Lisp_Object, Lisp_Object)
2580 #define DEFUN_ARGS_7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2581 Lisp_Object, Lisp_Object, Lisp_Object)
2582 #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
2583 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
2584
2585 /* True if OBJ is a Lisp function. */
2586 INLINE bool
2587 FUNCTIONP (Lisp_Object obj)
2588 {
2589 return functionp (obj);
2590 }
2591
2592 /* defsubr (Sname);
2593 is how we define the symbol for function `name' at start-up time. */
2594 extern void defsubr (struct Lisp_Subr *);
2595
2596 enum maxargs
2597 {
2598 MANY = -2,
2599 UNEVALLED = -1
2600 };
2601
2602 extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *);
2603 extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *);
2604 extern void defvar_bool (struct Lisp_Boolfwd *, const char *, bool *);
2605 extern void defvar_int (struct Lisp_Intfwd *, const char *, EMACS_INT *);
2606 extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int);
2607
2608 /* Macros we use to define forwarded Lisp variables.
2609 These are used in the syms_of_FILENAME functions.
2610
2611 An ordinary (not in buffer_defaults, per-buffer, or per-keyboard)
2612 lisp variable is actually a field in `struct emacs_globals'. The
2613 field's name begins with "f_", which is a convention enforced by
2614 these macros. Each such global has a corresponding #define in
2615 globals.h; the plain name should be used in the code.
2616
2617 E.g., the global "cons_cells_consed" is declared as "int
2618 f_cons_cells_consed" in globals.h, but there is a define:
2619
2620 #define cons_cells_consed globals.f_cons_cells_consed
2621
2622 All C code uses the `cons_cells_consed' name. This is all done
2623 this way to support indirection for multi-threaded Emacs. */
2624
2625 #define DEFVAR_LISP(lname, vname, doc) \
2626 do { \
2627 static struct Lisp_Objfwd o_fwd; \
2628 defvar_lisp (&o_fwd, lname, &globals.f_ ## vname); \
2629 } while (0)
2630 #define DEFVAR_LISP_NOPRO(lname, vname, doc) \
2631 do { \
2632 static struct Lisp_Objfwd o_fwd; \
2633 defvar_lisp_nopro (&o_fwd, lname, &globals.f_ ## vname); \
2634 } while (0)
2635 #define DEFVAR_BOOL(lname, vname, doc) \
2636 do { \
2637 static struct Lisp_Boolfwd b_fwd; \
2638 defvar_bool (&b_fwd, lname, &globals.f_ ## vname); \
2639 } while (0)
2640 #define DEFVAR_INT(lname, vname, doc) \
2641 do { \
2642 static struct Lisp_Intfwd i_fwd; \
2643 defvar_int (&i_fwd, lname, &globals.f_ ## vname); \
2644 } while (0)
2645
2646 #define DEFVAR_BUFFER_DEFAULTS(lname, vname, doc) \
2647 do { \
2648 static struct Lisp_Objfwd o_fwd; \
2649 defvar_lisp_nopro (&o_fwd, lname, &BVAR (&buffer_defaults, vname)); \
2650 } while (0)
2651
2652 #define DEFVAR_KBOARD(lname, vname, doc) \
2653 do { \
2654 static struct Lisp_Kboard_Objfwd ko_fwd; \
2655 defvar_kboard (&ko_fwd, lname, offsetof (KBOARD, vname ## _)); \
2656 } while (0)
2657 \f
2658 /* Save and restore the instruction and environment pointers,
2659 without affecting the signal mask. */
2660
2661 #ifdef HAVE__SETJMP
2662 typedef jmp_buf sys_jmp_buf;
2663 # define sys_setjmp(j) _setjmp (j)
2664 # define sys_longjmp(j, v) _longjmp (j, v)
2665 #elif defined HAVE_SIGSETJMP
2666 typedef sigjmp_buf sys_jmp_buf;
2667 # define sys_setjmp(j) sigsetjmp (j, 0)
2668 # define sys_longjmp(j, v) siglongjmp (j, v)
2669 #else
2670 /* A platform that uses neither _longjmp nor siglongjmp; assume
2671 longjmp does not affect the sigmask. */
2672 typedef jmp_buf sys_jmp_buf;
2673 # define sys_setjmp(j) setjmp (j)
2674 # define sys_longjmp(j, v) longjmp (j, v)
2675 #endif
2676
2677 \f
2678 /* Elisp uses several stacks:
2679 - the C stack.
2680 - the bytecode stack: used internally by the bytecode interpreter.
2681 Allocated from the C stack.
2682 - The specpdl stack: keeps track of active unwind-protect and
2683 dynamic-let-bindings. Allocated from the `specpdl' array, a manually
2684 managed stack.
2685 - The handler stack: keeps track of active catch tags and condition-case
2686 handlers. Allocated in a manually managed stack implemented by a
2687 doubly-linked list allocated via xmalloc and never freed. */
2688
2689 /* Structure for recording Lisp call stack for backtrace purposes. */
2690
2691 /* The special binding stack holds the outer values of variables while
2692 they are bound by a function application or a let form, stores the
2693 code to be executed for unwind-protect forms.
2694
2695 NOTE: The specbinding union is defined here, because SPECPDL_INDEX is
2696 used all over the place, needs to be fast, and needs to know the size of
2697 union specbinding. But only eval.c should access it. */
2698
2699 enum specbind_tag {
2700 SPECPDL_UNWIND, /* An unwind_protect function on Lisp_Object. */
2701 SPECPDL_UNWIND_PTR, /* Likewise, on void *. */
2702 SPECPDL_UNWIND_INT, /* Likewise, on int. */
2703 SPECPDL_UNWIND_VOID, /* Likewise, with no arg. */
2704 SPECPDL_BACKTRACE, /* An element of the backtrace. */
2705 SPECPDL_LET, /* A plain and simple dynamic let-binding. */
2706 /* Tags greater than SPECPDL_LET must be "subkinds" of LET. */
2707 SPECPDL_LET_LOCAL, /* A buffer-local let-binding. */
2708 SPECPDL_LET_DEFAULT /* A global binding for a localized var. */
2709 };
2710
2711 union specbinding
2712 {
2713 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2714 struct {
2715 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2716 void (*func) (Lisp_Object);
2717 Lisp_Object arg;
2718 } unwind;
2719 struct {
2720 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2721 void (*func) (void *);
2722 void *arg;
2723 } unwind_ptr;
2724 struct {
2725 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2726 void (*func) (int);
2727 int arg;
2728 } unwind_int;
2729 struct {
2730 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2731 void (*func) (void);
2732 } unwind_void;
2733 struct {
2734 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2735 /* `where' is not used in the case of SPECPDL_LET. */
2736 Lisp_Object symbol, old_value, where;
2737 } let;
2738 struct {
2739 ENUM_BF (specbind_tag) kind : CHAR_BIT;
2740 bool debug_on_exit : 1;
2741 Lisp_Object function;
2742 Lisp_Object *args;
2743 ptrdiff_t nargs;
2744 } bt;
2745 };
2746
2747 extern union specbinding *specpdl;
2748 extern union specbinding *specpdl_ptr;
2749 extern ptrdiff_t specpdl_size;
2750
2751 INLINE ptrdiff_t
2752 SPECPDL_INDEX (void)
2753 {
2754 return specpdl_ptr - specpdl;
2755 }
2756
2757 /* This structure helps implement the `catch/throw' and `condition-case/signal'
2758 control structures. A struct handler contains all the information needed to
2759 restore the state of the interpreter after a non-local jump.
2760
2761 handler structures are chained together in a doubly linked list; the `next'
2762 member points to the next outer catchtag and the `nextfree' member points in
2763 the other direction to the next inner element (which is typically the next
2764 free element since we mostly use it on the deepest handler).
2765
2766 A call like (throw TAG VAL) searches for a catchtag whose `tag_or_ch'
2767 member is TAG, and then unbinds to it. The `val' member is used to
2768 hold VAL while the stack is unwound; `val' is returned as the value
2769 of the catch form.
2770
2771 All the other members are concerned with restoring the interpreter
2772 state.
2773
2774 Members are volatile if their values need to survive _longjmp when
2775 a 'struct handler' is a local variable. */
2776
2777 enum handlertype { CATCHER, CONDITION_CASE };
2778
2779 struct handler
2780 {
2781 enum handlertype type;
2782 Lisp_Object tag_or_ch;
2783 Lisp_Object val;
2784 struct handler *next;
2785 struct handler *nextfree;
2786
2787 /* The bytecode interpreter can have several handlers active at the same
2788 time, so when we longjmp to one of them, it needs to know which handler
2789 this was and what was the corresponding internal state. This is stored
2790 here, and when we longjmp we make sure that handlerlist points to the
2791 proper handler. */
2792 Lisp_Object *bytecode_top;
2793 int bytecode_dest;
2794
2795 /* Most global vars are reset to their value via the specpdl mechanism,
2796 but a few others are handled by storing their value here. */
2797 #if 1 /* GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS, but they're defined later. */
2798 struct gcpro *gcpro;
2799 #endif
2800 sys_jmp_buf jmp;
2801 EMACS_INT lisp_eval_depth;
2802 ptrdiff_t pdlcount;
2803 int poll_suppress_count;
2804 int interrupt_input_blocked;
2805 struct byte_stack *byte_stack;
2806 };
2807
2808 /* Fill in the components of c, and put it on the list. */
2809 #define PUSH_HANDLER(c, tag_ch_val, handlertype) \
2810 if (handlerlist && handlerlist->nextfree) \
2811 (c) = handlerlist->nextfree; \
2812 else \
2813 { \
2814 (c) = xmalloc (sizeof (struct handler)); \
2815 (c)->nextfree = NULL; \
2816 if (handlerlist) \
2817 handlerlist->nextfree = (c); \
2818 } \
2819 (c)->type = (handlertype); \
2820 (c)->tag_or_ch = (tag_ch_val); \
2821 (c)->val = Qnil; \
2822 (c)->next = handlerlist; \
2823 (c)->lisp_eval_depth = lisp_eval_depth; \
2824 (c)->pdlcount = SPECPDL_INDEX (); \
2825 (c)->poll_suppress_count = poll_suppress_count; \
2826 (c)->interrupt_input_blocked = interrupt_input_blocked;\
2827 (c)->gcpro = gcprolist; \
2828 (c)->byte_stack = byte_stack_list; \
2829 handlerlist = (c);
2830
2831
2832 extern Lisp_Object memory_signal_data;
2833
2834 /* An address near the bottom of the stack.
2835 Tells GC how to save a copy of the stack. */
2836 extern char *stack_bottom;
2837
2838 /* Check quit-flag and quit if it is non-nil.
2839 Typing C-g does not directly cause a quit; it only sets Vquit_flag.
2840 So the program needs to do QUIT at times when it is safe to quit.
2841 Every loop that might run for a long time or might not exit
2842 ought to do QUIT at least once, at a safe place.
2843 Unless that is impossible, of course.
2844 But it is very desirable to avoid creating loops where QUIT is impossible.
2845
2846 Exception: if you set immediate_quit to nonzero,
2847 then the handler that responds to the C-g does the quit itself.
2848 This is a good thing to do around a loop that has no side effects
2849 and (in particular) cannot call arbitrary Lisp code.
2850
2851 If quit-flag is set to `kill-emacs' the SIGINT handler has received
2852 a request to exit Emacs when it is safe to do. */
2853
2854 extern void process_pending_signals (void);
2855 extern bool volatile pending_signals;
2856
2857 extern void process_quit_flag (void);
2858 #define QUIT \
2859 do { \
2860 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
2861 process_quit_flag (); \
2862 else if (pending_signals) \
2863 process_pending_signals (); \
2864 } while (0)
2865
2866
2867 /* Nonzero if ought to quit now. */
2868
2869 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
2870 \f
2871 extern Lisp_Object Vascii_downcase_table;
2872 extern Lisp_Object Vascii_canon_table;
2873 \f
2874 /* Structure for recording stack slots that need marking. */
2875
2876 /* This is a chain of structures, each of which points at a Lisp_Object
2877 variable whose value should be marked in garbage collection.
2878 Normally every link of the chain is an automatic variable of a function,
2879 and its `val' points to some argument or local variable of the function.
2880 On exit to the function, the chain is set back to the value it had on entry.
2881 This way, no link remains in the chain when the stack frame containing the
2882 link disappears.
2883
2884 Every function that can call Feval must protect in this fashion all
2885 Lisp_Object variables whose contents will be used again. */
2886
2887 extern struct gcpro *gcprolist;
2888
2889 struct gcpro
2890 {
2891 struct gcpro *next;
2892
2893 /* Address of first protected variable. */
2894 volatile Lisp_Object *var;
2895
2896 /* Number of consecutive protected variables. */
2897 ptrdiff_t nvars;
2898
2899 #ifdef DEBUG_GCPRO
2900 int level;
2901 #endif
2902 };
2903
2904 /* Values of GC_MARK_STACK during compilation:
2905
2906 0 Use GCPRO as before
2907 1 Do the real thing, make GCPROs and UNGCPRO no-ops.
2908 2 Mark the stack, and check that everything GCPRO'd is
2909 marked.
2910 3 Mark using GCPRO's, mark stack last, and count how many
2911 dead objects are kept alive.
2912
2913 Formerly, method 0 was used. Currently, method 1 is used unless
2914 otherwise specified by hand when building, e.g.,
2915 "make CPPFLAGS='-DGC_MARK_STACK=GC_USE_GCPROS_AS_BEFORE'".
2916 Methods 2 and 3 are present mainly to debug the transition from 0 to 1. */
2917
2918 #define GC_USE_GCPROS_AS_BEFORE 0
2919 #define GC_MAKE_GCPROS_NOOPS 1
2920 #define GC_MARK_STACK_CHECK_GCPROS 2
2921 #define GC_USE_GCPROS_CHECK_ZOMBIES 3
2922
2923 #ifndef GC_MARK_STACK
2924 #define GC_MARK_STACK GC_MAKE_GCPROS_NOOPS
2925 #endif
2926
2927 /* Whether we do the stack marking manually. */
2928 #define BYTE_MARK_STACK !(GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \
2929 || GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS)
2930
2931
2932 #if GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS
2933
2934 /* Do something silly with gcproN vars just so gcc shuts up. */
2935 /* You get warnings from MIPSPro... */
2936
2937 #define GCPRO1(varname) ((void) gcpro1)
2938 #define GCPRO2(varname1, varname2) ((void) gcpro2, (void) gcpro1)
2939 #define GCPRO3(varname1, varname2, varname3) \
2940 ((void) gcpro3, (void) gcpro2, (void) gcpro1)
2941 #define GCPRO4(varname1, varname2, varname3, varname4) \
2942 ((void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
2943 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2944 ((void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
2945 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2946 ((void) gcpro6, (void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, \
2947 (void) gcpro1)
2948 #define UNGCPRO ((void) 0)
2949
2950 #else /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
2951
2952 #ifndef DEBUG_GCPRO
2953
2954 #define GCPRO1(varname) \
2955 {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
2956 gcprolist = &gcpro1; }
2957
2958 #define GCPRO2(varname1, varname2) \
2959 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2960 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2961 gcprolist = &gcpro2; }
2962
2963 #define GCPRO3(varname1, varname2, varname3) \
2964 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2965 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2966 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2967 gcprolist = &gcpro3; }
2968
2969 #define GCPRO4(varname1, varname2, varname3, varname4) \
2970 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2971 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2972 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2973 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2974 gcprolist = &gcpro4; }
2975
2976 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
2977 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2978 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2979 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2980 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2981 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2982 gcprolist = &gcpro5; }
2983
2984 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
2985 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
2986 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
2987 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
2988 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
2989 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
2990 gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
2991 gcprolist = &gcpro6; }
2992
2993 #define UNGCPRO (gcprolist = gcpro1.next)
2994
2995 #else
2996
2997 extern int gcpro_level;
2998
2999 #define GCPRO1(varname) \
3000 {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
3001 gcpro1.level = gcpro_level++; \
3002 gcprolist = &gcpro1; }
3003
3004 #define GCPRO2(varname1, varname2) \
3005 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
3006 gcpro1.level = gcpro_level; \
3007 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
3008 gcpro2.level = gcpro_level++; \
3009 gcprolist = &gcpro2; }
3010
3011 #define GCPRO3(varname1, varname2, varname3) \
3012 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
3013 gcpro1.level = gcpro_level; \
3014 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
3015 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
3016 gcpro3.level = gcpro_level++; \
3017 gcprolist = &gcpro3; }
3018
3019 #define GCPRO4(varname1, varname2, varname3, varname4) \
3020 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
3021 gcpro1.level = gcpro_level; \
3022 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
3023 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
3024 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
3025 gcpro4.level = gcpro_level++; \
3026 gcprolist = &gcpro4; }
3027
3028 #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
3029 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
3030 gcpro1.level = gcpro_level; \
3031 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
3032 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
3033 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
3034 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
3035 gcpro5.level = gcpro_level++; \
3036 gcprolist = &gcpro5; }
3037
3038 #define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
3039 {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
3040 gcpro1.level = gcpro_level; \
3041 gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
3042 gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
3043 gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
3044 gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
3045 gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
3046 gcpro6.level = gcpro_level++; \
3047 gcprolist = &gcpro6; }
3048
3049 #define UNGCPRO \
3050 ((--gcpro_level != gcpro1.level) \
3051 ? (emacs_abort (), 0) \
3052 : ((gcprolist = gcpro1.next), 0))
3053
3054 #endif /* DEBUG_GCPRO */
3055 #endif /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
3056
3057
3058 /* Evaluate expr, UNGCPRO, and then return the value of expr. */
3059 #define RETURN_UNGCPRO(expr) \
3060 do \
3061 { \
3062 Lisp_Object ret_ungc_val; \
3063 ret_ungc_val = (expr); \
3064 UNGCPRO; \
3065 return ret_ungc_val; \
3066 } \
3067 while (0)
3068
3069 /* Call staticpro (&var) to protect static variable `var'. */
3070
3071 void staticpro (Lisp_Object *);
3072 \f
3073 /* Declare a Lisp-callable function. The MAXARGS parameter has the same
3074 meaning as in the DEFUN macro, and is used to construct a prototype. */
3075 /* We can use the same trick as in the DEFUN macro to generate the
3076 appropriate prototype. */
3077 #define EXFUN(fnname, maxargs) \
3078 extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
3079
3080 #include "globals.h"
3081
3082 /* Forward declarations for prototypes. */
3083 struct window;
3084 struct frame;
3085
3086 /* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET. */
3087
3088 INLINE void
3089 vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
3090 {
3091 eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
3092 memcpy (XVECTOR (v)->u.contents + offset, args, count * sizeof *args);
3093 }
3094
3095 /* Functions to modify hash tables. */
3096
3097 INLINE void
3098 set_hash_key_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
3099 {
3100 gc_aset (h->key_and_value, 2 * idx, val);
3101 }
3102
3103 INLINE void
3104 set_hash_value_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
3105 {
3106 gc_aset (h->key_and_value, 2 * idx + 1, val);
3107 }
3108
3109 /* Use these functions to set Lisp_Object
3110 or pointer slots of struct Lisp_Symbol. */
3111
3112 INLINE void
3113 set_symbol_function (Lisp_Object sym, Lisp_Object function)
3114 {
3115 XSYMBOL (sym)->function = function;
3116 }
3117
3118 INLINE void
3119 set_symbol_plist (Lisp_Object sym, Lisp_Object plist)
3120 {
3121 XSYMBOL (sym)->plist = plist;
3122 }
3123
3124 INLINE void
3125 set_symbol_next (Lisp_Object sym, struct Lisp_Symbol *next)
3126 {
3127 XSYMBOL (sym)->next = next;
3128 }
3129
3130 /* Buffer-local (also frame-local) variable access functions. */
3131
3132 INLINE int
3133 blv_found (struct Lisp_Buffer_Local_Value *blv)
3134 {
3135 eassert (blv->found == !EQ (blv->defcell, blv->valcell));
3136 return blv->found;
3137 }
3138
3139 /* Set overlay's property list. */
3140
3141 INLINE void
3142 set_overlay_plist (Lisp_Object overlay, Lisp_Object plist)
3143 {
3144 XOVERLAY (overlay)->plist = plist;
3145 }
3146
3147 /* Get text properties of S. */
3148
3149 INLINE INTERVAL
3150 string_intervals (Lisp_Object s)
3151 {
3152 return XSTRING (s)->intervals;
3153 }
3154
3155 /* Set text properties of S to I. */
3156
3157 INLINE void
3158 set_string_intervals (Lisp_Object s, INTERVAL i)
3159 {
3160 XSTRING (s)->intervals = i;
3161 }
3162
3163 /* Set a Lisp slot in TABLE to VAL. Most code should use this instead
3164 of setting slots directly. */
3165
3166 INLINE void
3167 set_char_table_defalt (Lisp_Object table, Lisp_Object val)
3168 {
3169 XCHAR_TABLE (table)->defalt = val;
3170 }
3171 INLINE void
3172 set_char_table_purpose (Lisp_Object table, Lisp_Object val)
3173 {
3174 XCHAR_TABLE (table)->purpose = val;
3175 }
3176
3177 /* Set different slots in (sub)character tables. */
3178
3179 INLINE void
3180 set_char_table_extras (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
3181 {
3182 eassert (0 <= idx && idx < CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (table)));
3183 XCHAR_TABLE (table)->extras[idx] = val;
3184 }
3185
3186 INLINE void
3187 set_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
3188 {
3189 eassert (0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0));
3190 XCHAR_TABLE (table)->contents[idx] = val;
3191 }
3192
3193 INLINE void
3194 set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
3195 {
3196 XSUB_CHAR_TABLE (table)->contents[idx] = val;
3197 }
3198
3199 /* Defined in data.c. */
3200 extern Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
3201 extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
3202 extern Lisp_Object Qerror, Qquit, Qargs_out_of_range;
3203 extern Lisp_Object Qvoid_variable, Qvoid_function;
3204 extern Lisp_Object Qinvalid_read_syntax;
3205 extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
3206 extern Lisp_Object Quser_error, Qend_of_file, Qarith_error, Qmark_inactive;
3207 extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
3208 extern Lisp_Object Qtext_read_only;
3209 extern Lisp_Object Qinteractive_form;
3210 extern Lisp_Object Qcircular_list;
3211 extern Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp;
3212 extern Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
3213 extern Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
3214 extern Lisp_Object Qbuffer_or_string_p;
3215 extern Lisp_Object Qfboundp;
3216 extern Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
3217
3218 extern Lisp_Object Qcdr;
3219
3220 extern Lisp_Object Qrange_error, Qoverflow_error;
3221
3222 extern Lisp_Object Qfloatp;
3223 extern Lisp_Object Qnumberp, Qnumber_or_marker_p;
3224
3225 extern Lisp_Object Qbuffer, Qinteger, Qsymbol;
3226
3227 extern Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
3228
3229 EXFUN (Fbyteorder, 0) ATTRIBUTE_CONST;
3230
3231 /* Defined in data.c. */
3232 extern Lisp_Object indirect_function (Lisp_Object);
3233 extern Lisp_Object find_symbol_value (Lisp_Object);
3234 enum Arith_Comparison {
3235 ARITH_EQUAL,
3236 ARITH_NOTEQUAL,
3237 ARITH_LESS,
3238 ARITH_GRTR,
3239 ARITH_LESS_OR_EQUAL,
3240 ARITH_GRTR_OR_EQUAL
3241 };
3242 extern Lisp_Object arithcompare (Lisp_Object num1, Lisp_Object num2,
3243 enum Arith_Comparison comparison);
3244
3245 /* Convert the integer I to an Emacs representation, either the integer
3246 itself, or a cons of two or three integers, or if all else fails a float.
3247 I should not have side effects. */
3248 #define INTEGER_TO_CONS(i) \
3249 (! FIXNUM_OVERFLOW_P (i) \
3250 ? make_number (i) \
3251 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16) \
3252 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16)) \
3253 && FIXNUM_OVERFLOW_P ((i) >> 16)) \
3254 ? Fcons (make_number ((i) >> 16), make_number ((i) & 0xffff)) \
3255 : ! ((FIXNUM_OVERFLOW_P (INTMAX_MIN >> 16 >> 24) \
3256 || FIXNUM_OVERFLOW_P (UINTMAX_MAX >> 16 >> 24)) \
3257 && FIXNUM_OVERFLOW_P ((i) >> 16 >> 24)) \
3258 ? Fcons (make_number ((i) >> 16 >> 24), \
3259 Fcons (make_number ((i) >> 16 & 0xffffff), \
3260 make_number ((i) & 0xffff))) \
3261 : make_float (i))
3262
3263 /* Convert the Emacs representation CONS back to an integer of type
3264 TYPE, storing the result the variable VAR. Signal an error if CONS
3265 is not a valid representation or is out of range for TYPE. */
3266 #define CONS_TO_INTEGER(cons, type, var) \
3267 (TYPE_SIGNED (type) \
3268 ? ((var) = cons_to_signed (cons, TYPE_MINIMUM (type), TYPE_MAXIMUM (type))) \
3269 : ((var) = cons_to_unsigned (cons, TYPE_MAXIMUM (type))))
3270 extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t);
3271 extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
3272
3273 extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
3274 extern _Noreturn void args_out_of_range (Lisp_Object, Lisp_Object);
3275 extern _Noreturn void args_out_of_range_3 (Lisp_Object, Lisp_Object,
3276 Lisp_Object);
3277 extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
3278 extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *);
3279 extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, bool);
3280 extern void syms_of_data (void);
3281 extern void swap_in_global_binding (struct Lisp_Symbol *);
3282
3283 /* Defined in cmds.c */
3284 extern void syms_of_cmds (void);
3285 extern void keys_of_cmds (void);
3286
3287 /* Defined in coding.c. */
3288 extern Lisp_Object Qcharset;
3289 extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
3290 ptrdiff_t, bool, bool, Lisp_Object);
3291 extern void init_coding (void);
3292 extern void init_coding_once (void);
3293 extern void syms_of_coding (void);
3294
3295 /* Defined in character.c. */
3296 EXFUN (Fmax_char, 0) ATTRIBUTE_CONST;
3297 extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
3298 extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
3299 extern int multibyte_char_to_unibyte (int) ATTRIBUTE_CONST;
3300 extern int multibyte_char_to_unibyte_safe (int) ATTRIBUTE_CONST;
3301 extern void syms_of_character (void);
3302
3303 /* Defined in charset.c. */
3304 extern void init_charset (void);
3305 extern void init_charset_once (void);
3306 extern void syms_of_charset (void);
3307 /* Structure forward declarations. */
3308 struct charset;
3309
3310 /* Defined in composite.c. */
3311 extern void syms_of_composite (void);
3312
3313 /* Defined in syntax.c. */
3314 extern void init_syntax_once (void);
3315 extern void syms_of_syntax (void);
3316
3317 /* Defined in fns.c. */
3318 extern Lisp_Object QCrehash_size, QCrehash_threshold;
3319 enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
3320 EXFUN (Fidentity, 1) ATTRIBUTE_CONST;
3321 extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
3322 extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
3323 extern void sweep_weak_hash_tables (void);
3324 extern Lisp_Object Qcursor_in_echo_area;
3325 extern Lisp_Object Qstring_lessp;
3326 extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq;
3327 EMACS_UINT hash_string (char const *, ptrdiff_t);
3328 EMACS_UINT sxhash (Lisp_Object, int);
3329 Lisp_Object make_hash_table (struct hash_table_test, Lisp_Object, Lisp_Object,
3330 Lisp_Object, Lisp_Object);
3331 ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
3332 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
3333 EMACS_UINT);
3334 extern struct hash_table_test hashtest_eql, hashtest_equal;
3335
3336 extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
3337 ptrdiff_t, ptrdiff_t);
3338 extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);
3339 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
3340 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
3341 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
3342 extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
3343 extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
3344 extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
3345 extern void clear_string_char_byte_cache (void);
3346 extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
3347 extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
3348 extern Lisp_Object string_to_multibyte (Lisp_Object);
3349 extern Lisp_Object string_make_unibyte (Lisp_Object);
3350 extern void syms_of_fns (void);
3351
3352 /* Defined in floatfns.c. */
3353 extern double extract_float (Lisp_Object);
3354 extern void syms_of_floatfns (void);
3355 extern Lisp_Object fmod_float (Lisp_Object x, Lisp_Object y);
3356
3357 /* Defined in fringe.c. */
3358 extern void syms_of_fringe (void);
3359 extern void init_fringe (void);
3360 #ifdef HAVE_WINDOW_SYSTEM
3361 extern void mark_fringe_data (void);
3362 extern void init_fringe_once (void);
3363 #endif /* HAVE_WINDOW_SYSTEM */
3364
3365 /* Defined in image.c. */
3366 extern Lisp_Object QCascent, QCmargin, QCrelief;
3367 extern Lisp_Object QCconversion;
3368 extern int x_bitmap_mask (struct frame *, ptrdiff_t);
3369 extern void reset_image_types (void);
3370 extern void syms_of_image (void);
3371
3372 /* Defined in insdel.c. */
3373 extern Lisp_Object Qinhibit_modification_hooks;
3374 extern void move_gap_both (ptrdiff_t, ptrdiff_t);
3375 extern _Noreturn void buffer_overflow (void);
3376 extern void make_gap (ptrdiff_t);
3377 extern void make_gap_1 (struct buffer *, ptrdiff_t);
3378 extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
3379 ptrdiff_t, bool, bool);
3380 extern int count_combining_before (const unsigned char *,
3381 ptrdiff_t, ptrdiff_t, ptrdiff_t);
3382 extern int count_combining_after (const unsigned char *,
3383 ptrdiff_t, ptrdiff_t, ptrdiff_t);
3384 extern void insert (const char *, ptrdiff_t);
3385 extern void insert_and_inherit (const char *, ptrdiff_t);
3386 extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
3387 bool, bool, bool);
3388 extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
3389 extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
3390 ptrdiff_t, ptrdiff_t, bool);
3391 extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool);
3392 extern void insert_char (int);
3393 extern void insert_string (const char *);
3394 extern void insert_before_markers (const char *, ptrdiff_t);
3395 extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
3396 extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
3397 ptrdiff_t, ptrdiff_t,
3398 ptrdiff_t, bool);
3399 extern void del_range (ptrdiff_t, ptrdiff_t);
3400 extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool);
3401 extern void del_range_byte (ptrdiff_t, ptrdiff_t, bool);
3402 extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
3403 extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
3404 ptrdiff_t, ptrdiff_t, bool);
3405 extern void modify_text (ptrdiff_t, ptrdiff_t);
3406 extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3407 extern void prepare_to_modify_buffer_1 (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3408 extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3409 extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3410 ptrdiff_t, ptrdiff_t);
3411 extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
3412 ptrdiff_t, ptrdiff_t);
3413 extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool);
3414 extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3415 const char *, ptrdiff_t, ptrdiff_t, bool);
3416 extern void syms_of_insdel (void);
3417
3418 /* Defined in dispnew.c. */
3419 #if (defined PROFILING \
3420 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
3421 _Noreturn void __executable_start (void);
3422 #endif
3423 extern Lisp_Object Vwindow_system;
3424 extern Lisp_Object sit_for (Lisp_Object, bool, int);
3425 extern void init_display (void);
3426 extern void syms_of_display (void);
3427
3428 /* Defined in xdisp.c. */
3429 extern Lisp_Object Qinhibit_point_motion_hooks;
3430 extern Lisp_Object Qinhibit_redisplay, Qdisplay;
3431 extern Lisp_Object Qmenu_bar_update_hook;
3432 extern Lisp_Object Qwindow_scroll_functions;
3433 extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
3434 extern Lisp_Object Qimage, Qtext, Qboth, Qboth_horiz, Qtext_image_horiz;
3435 extern Lisp_Object Qspace, Qcenter, QCalign_to;
3436 extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
3437 extern Lisp_Object Qleft_margin, Qright_margin;
3438 extern Lisp_Object QCdata, QCfile;
3439 extern Lisp_Object QCmap;
3440 extern Lisp_Object Qrisky_local_variable;
3441 extern bool noninteractive_need_newline;
3442 extern Lisp_Object echo_area_buffer[2];
3443 extern void add_to_log (const char *, Lisp_Object, Lisp_Object);
3444 extern void check_message_stack (void);
3445 extern void setup_echo_area_for_printing (int);
3446 extern bool push_message (void);
3447 extern void pop_message_unwind (void);
3448 extern Lisp_Object restore_message_unwind (Lisp_Object);
3449 extern void restore_message (void);
3450 extern Lisp_Object current_message (void);
3451 extern void clear_message (int, int);
3452 extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
3453 extern void message1 (const char *);
3454 extern void message1_nolog (const char *);
3455 extern void message3 (Lisp_Object);
3456 extern void message3_nolog (Lisp_Object);
3457 extern void message_dolog (const char *, ptrdiff_t, bool, bool);
3458 extern void message_with_string (const char *, Lisp_Object, int);
3459 extern void message_log_maybe_newline (void);
3460 extern void update_echo_area (void);
3461 extern void truncate_echo_area (ptrdiff_t);
3462 extern void redisplay (void);
3463 extern void redisplay_preserve_echo_area (int);
3464 extern void prepare_menu_bars (void);
3465
3466 void set_frame_cursor_types (struct frame *, Lisp_Object);
3467 extern void syms_of_xdisp (void);
3468 extern void init_xdisp (void);
3469 extern Lisp_Object safe_eval (Lisp_Object);
3470 extern int pos_visible_p (struct window *, ptrdiff_t, int *,
3471 int *, int *, int *, int *, int *);
3472
3473 /* Defined in xsettings.c. */
3474 extern void syms_of_xsettings (void);
3475
3476 /* Defined in vm-limit.c. */
3477 extern void memory_warnings (void *, void (*warnfun) (const char *));
3478
3479 /* Defined in alloc.c. */
3480 extern void check_pure_size (void);
3481 extern void free_misc (Lisp_Object);
3482 extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
3483 extern void malloc_warning (const char *);
3484 extern _Noreturn void memory_full (size_t);
3485 extern _Noreturn void buffer_memory_full (ptrdiff_t);
3486 extern bool survives_gc_p (Lisp_Object);
3487 extern void mark_object (Lisp_Object);
3488 #if defined REL_ALLOC && !defined SYSTEM_MALLOC
3489 extern void refill_memory_reserve (void);
3490 #endif
3491 extern const char *pending_malloc_warning;
3492 extern Lisp_Object zero_vector;
3493 extern Lisp_Object *stack_base;
3494 extern EMACS_INT consing_since_gc;
3495 extern EMACS_INT gc_relative_threshold;
3496 extern EMACS_INT memory_full_cons_threshold;
3497 extern Lisp_Object list1 (Lisp_Object);
3498 extern Lisp_Object list2 (Lisp_Object, Lisp_Object);
3499 extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object);
3500 extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3501 extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3502 Lisp_Object);
3503 enum constype {CONSTYPE_HEAP, CONSTYPE_PURE};
3504 extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...);
3505
3506 /* Build a frequently used 2/3/4-integer lists. */
3507
3508 INLINE Lisp_Object
3509 list2i (EMACS_INT x, EMACS_INT y)
3510 {
3511 return list2 (make_number (x), make_number (y));
3512 }
3513
3514 INLINE Lisp_Object
3515 list3i (EMACS_INT x, EMACS_INT y, EMACS_INT w)
3516 {
3517 return list3 (make_number (x), make_number (y), make_number (w));
3518 }
3519
3520 INLINE Lisp_Object
3521 list4i (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h)
3522 {
3523 return list4 (make_number (x), make_number (y),
3524 make_number (w), make_number (h));
3525 }
3526
3527 extern _Noreturn void string_overflow (void);
3528 extern Lisp_Object make_string (const char *, ptrdiff_t);
3529 extern Lisp_Object make_formatted_string (char *, const char *, ...)
3530 ATTRIBUTE_FORMAT_PRINTF (2, 3);
3531 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
3532
3533 /* Make unibyte string from C string when the length isn't known. */
3534
3535 INLINE Lisp_Object
3536 build_unibyte_string (const char *str)
3537 {
3538 return make_unibyte_string (str, strlen (str));
3539 }
3540
3541 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
3542 extern Lisp_Object make_event_array (ptrdiff_t, Lisp_Object *);
3543 extern Lisp_Object make_uninit_string (EMACS_INT);
3544 extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
3545 extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
3546 extern Lisp_Object make_specified_string (const char *,
3547 ptrdiff_t, ptrdiff_t, bool);
3548 extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, bool);
3549 extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
3550
3551 /* Make a string allocated in pure space, use STR as string data. */
3552
3553 INLINE Lisp_Object
3554 build_pure_c_string (const char *str)
3555 {
3556 return make_pure_c_string (str, strlen (str));
3557 }
3558
3559 /* Make a string from the data at STR, treating it as multibyte if the
3560 data warrants. */
3561
3562 INLINE Lisp_Object
3563 build_string (const char *str)
3564 {
3565 return make_string (str, strlen (str));
3566 }
3567
3568 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
3569 extern void make_byte_code (struct Lisp_Vector *);
3570 extern Lisp_Object Qautomatic_gc;
3571 extern Lisp_Object Qchar_table_extra_slots;
3572 extern struct Lisp_Vector *allocate_vector (EMACS_INT);
3573
3574 /* Make an uninitialized vector for SIZE objects. NOTE: you must
3575 be sure that GC cannot happen until the vector is completely
3576 initialized. E.g. the following code is likely to crash:
3577
3578 v = make_uninit_vector (3);
3579 ASET (v, 0, obj0);
3580 ASET (v, 1, Ffunction_can_gc ());
3581 ASET (v, 2, obj1); */
3582
3583 INLINE Lisp_Object
3584 make_uninit_vector (ptrdiff_t size)
3585 {
3586 Lisp_Object v;
3587 struct Lisp_Vector *p;
3588
3589 p = allocate_vector (size);
3590 XSETVECTOR (v, p);
3591 return v;
3592 }
3593
3594 extern struct Lisp_Vector *allocate_pseudovector (int, int, enum pvec_type);
3595 #define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
3596 ((typ*) \
3597 allocate_pseudovector \
3598 (VECSIZE (typ), PSEUDOVECSIZE (typ, field), tag))
3599 extern struct Lisp_Hash_Table *allocate_hash_table (void);
3600 extern struct window *allocate_window (void);
3601 extern struct frame *allocate_frame (void);
3602 extern struct Lisp_Process *allocate_process (void);
3603 extern struct terminal *allocate_terminal (void);
3604 extern bool gc_in_progress;
3605 extern bool abort_on_gc;
3606 extern Lisp_Object make_float (double);
3607 extern void display_malloc_warning (void);
3608 extern ptrdiff_t inhibit_garbage_collection (void);
3609 extern Lisp_Object make_save_int_int_int (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3610 extern Lisp_Object make_save_obj_obj_obj_obj (Lisp_Object, Lisp_Object,
3611 Lisp_Object, Lisp_Object);
3612 extern Lisp_Object make_save_ptr (void *);
3613 extern Lisp_Object make_save_ptr_int (void *, ptrdiff_t);
3614 extern Lisp_Object make_save_ptr_ptr (void *, void *);
3615 extern Lisp_Object make_save_funcptr_ptr_obj (void (*) (void), void *,
3616 Lisp_Object);
3617 extern Lisp_Object make_save_memory (Lisp_Object *, ptrdiff_t);
3618 extern void free_save_value (Lisp_Object);
3619 extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object);
3620 extern void free_marker (Lisp_Object);
3621 extern void free_cons (struct Lisp_Cons *);
3622 extern void init_alloc_once (void);
3623 extern void init_alloc (void);
3624 extern void syms_of_alloc (void);
3625 extern struct buffer * allocate_buffer (void);
3626 extern int valid_lisp_object_p (Lisp_Object);
3627 #ifdef GC_CHECK_CONS_LIST
3628 extern void check_cons_list (void);
3629 #else
3630 INLINE void (check_cons_list) (void) { lisp_h_check_cons_list (); }
3631 #endif
3632
3633 #ifdef REL_ALLOC
3634 /* Defined in ralloc.c. */
3635 extern void *r_alloc (void **, size_t);
3636 extern void r_alloc_free (void **);
3637 extern void *r_re_alloc (void **, size_t);
3638 extern void r_alloc_reset_variable (void **, void **);
3639 extern void r_alloc_inhibit_buffer_relocation (int);
3640 #endif
3641
3642 /* Defined in chartab.c. */
3643 extern Lisp_Object copy_char_table (Lisp_Object);
3644 extern Lisp_Object char_table_ref (Lisp_Object, int);
3645 extern Lisp_Object char_table_ref_and_range (Lisp_Object, int,
3646 int *, int *);
3647 extern void char_table_set (Lisp_Object, int, Lisp_Object);
3648 extern void char_table_set_range (Lisp_Object, int, int, Lisp_Object);
3649 extern int char_table_translate (Lisp_Object, int);
3650 extern void map_char_table (void (*) (Lisp_Object, Lisp_Object,
3651 Lisp_Object),
3652 Lisp_Object, Lisp_Object, Lisp_Object);
3653 extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object),
3654 Lisp_Object, Lisp_Object,
3655 Lisp_Object, struct charset *,
3656 unsigned, unsigned);
3657 extern Lisp_Object uniprop_table (Lisp_Object);
3658 extern void syms_of_chartab (void);
3659
3660 /* Defined in print.c. */
3661 extern Lisp_Object Vprin1_to_string_buffer;
3662 extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
3663 extern Lisp_Object Qstandard_output;
3664 extern Lisp_Object Qexternal_debugging_output;
3665 extern void temp_output_buffer_setup (const char *);
3666 extern int print_level;
3667 extern Lisp_Object Qprint_escape_newlines;
3668 extern void write_string (const char *, int);
3669 extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
3670 Lisp_Object);
3671 extern Lisp_Object internal_with_output_to_temp_buffer
3672 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3673 enum FLOAT_TO_STRING_BUFSIZE { FLOAT_TO_STRING_BUFSIZE = 350 };
3674 extern int float_to_string (char *, double);
3675 extern void init_print_once (void);
3676 extern void syms_of_print (void);
3677
3678 /* Defined in doprnt.c. */
3679 extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
3680 va_list);
3681 extern ptrdiff_t esprintf (char *, char const *, ...)
3682 ATTRIBUTE_FORMAT_PRINTF (2, 3);
3683 extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
3684 char const *, ...)
3685 ATTRIBUTE_FORMAT_PRINTF (5, 6);
3686 extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
3687 char const *, va_list)
3688 ATTRIBUTE_FORMAT_PRINTF (5, 0);
3689
3690 /* Defined in lread.c. */
3691 extern Lisp_Object Qvariable_documentation, Qstandard_input;
3692 extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
3693 extern Lisp_Object Qlexical_binding;
3694 extern Lisp_Object check_obarray (Lisp_Object);
3695 extern Lisp_Object intern_1 (const char *, ptrdiff_t);
3696 extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t);
3697 extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
3698 INLINE void
3699 LOADHIST_ATTACH (Lisp_Object x)
3700 {
3701 if (initialized)
3702 Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
3703 }
3704 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
3705 Lisp_Object *, Lisp_Object);
3706 extern Lisp_Object string_to_number (char const *, int, bool);
3707 extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
3708 Lisp_Object);
3709 extern void dir_warning (const char *, Lisp_Object);
3710 extern void init_obarray (void);
3711 extern void init_lread (void);
3712 extern void syms_of_lread (void);
3713
3714 INLINE Lisp_Object
3715 intern (const char *str)
3716 {
3717 return intern_1 (str, strlen (str));
3718 }
3719
3720 INLINE Lisp_Object
3721 intern_c_string (const char *str)
3722 {
3723 return intern_c_string_1 (str, strlen (str));
3724 }
3725
3726 /* Defined in eval.c. */
3727 extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qmacro;
3728 extern Lisp_Object Qinhibit_quit, Qinternal_interpreter_environment, Qclosure;
3729 extern Lisp_Object Qand_rest;
3730 extern Lisp_Object Vautoload_queue;
3731 extern Lisp_Object Vsignaling_function;
3732 extern Lisp_Object inhibit_lisp_code;
3733 extern struct handler *handlerlist;
3734
3735 /* To run a normal hook, use the appropriate function from the list below.
3736 The calling convention:
3737
3738 if (!NILP (Vrun_hooks))
3739 call1 (Vrun_hooks, Qmy_funny_hook);
3740
3741 should no longer be used. */
3742 extern Lisp_Object Vrun_hooks;
3743 extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
3744 extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
3745 Lisp_Object (*funcall)
3746 (ptrdiff_t nargs, Lisp_Object *args));
3747 extern _Noreturn void xsignal (Lisp_Object, Lisp_Object);
3748 extern _Noreturn void xsignal0 (Lisp_Object);
3749 extern _Noreturn void xsignal1 (Lisp_Object, Lisp_Object);
3750 extern _Noreturn void xsignal2 (Lisp_Object, Lisp_Object, Lisp_Object);
3751 extern _Noreturn void xsignal3 (Lisp_Object, Lisp_Object, Lisp_Object,
3752 Lisp_Object);
3753 extern _Noreturn void signal_error (const char *, Lisp_Object);
3754 extern Lisp_Object eval_sub (Lisp_Object form);
3755 extern Lisp_Object apply1 (Lisp_Object, Lisp_Object);
3756 extern Lisp_Object call0 (Lisp_Object);
3757 extern Lisp_Object call1 (Lisp_Object, Lisp_Object);
3758 extern Lisp_Object call2 (Lisp_Object, Lisp_Object, Lisp_Object);
3759 extern Lisp_Object call3 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3760 extern Lisp_Object call4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3761 extern Lisp_Object call5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3762 extern Lisp_Object call6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3763 extern Lisp_Object call7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3764 extern Lisp_Object internal_catch (Lisp_Object, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3765 extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_Object);
3766 extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
3767 extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3768 extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3769 extern Lisp_Object internal_condition_case_n
3770 (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *,
3771 Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *));
3772 extern void specbind (Lisp_Object, Lisp_Object);
3773 extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object);
3774 extern void record_unwind_protect_ptr (void (*) (void *), void *);
3775 extern void record_unwind_protect_int (void (*) (int), int);
3776 extern void record_unwind_protect_void (void (*) (void));
3777 extern void record_unwind_protect_nothing (void);
3778 extern void clear_unwind_protect (ptrdiff_t);
3779 extern void set_unwind_protect (ptrdiff_t, void (*) (Lisp_Object), Lisp_Object);
3780 extern void set_unwind_protect_ptr (ptrdiff_t, void (*) (void *), void *);
3781 extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
3782 extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
3783 extern _Noreturn void verror (const char *, va_list)
3784 ATTRIBUTE_FORMAT_PRINTF (1, 0);
3785 extern void un_autoload (Lisp_Object);
3786 extern Lisp_Object call_debugger (Lisp_Object arg);
3787 extern void init_eval_once (void);
3788 extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object, ...);
3789 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
3790 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
3791 extern void init_eval (void);
3792 extern void syms_of_eval (void);
3793 extern void unwind_body (Lisp_Object);
3794 extern void record_in_backtrace (Lisp_Object function,
3795 Lisp_Object *args, ptrdiff_t nargs);
3796 extern void mark_specpdl (void);
3797 extern void get_backtrace (Lisp_Object array);
3798 Lisp_Object backtrace_top_function (void);
3799 extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);
3800 extern bool let_shadows_global_binding_p (Lisp_Object symbol);
3801
3802
3803 /* Defined in editfns.c. */
3804 extern Lisp_Object Qfield;
3805 extern void insert1 (Lisp_Object);
3806 extern Lisp_Object format2 (const char *, Lisp_Object, Lisp_Object);
3807 extern Lisp_Object save_excursion_save (void);
3808 extern Lisp_Object save_restriction_save (void);
3809 extern void save_excursion_restore (Lisp_Object);
3810 extern void save_restriction_restore (Lisp_Object);
3811 extern _Noreturn void time_overflow (void);
3812 extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool);
3813 extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3814 ptrdiff_t, bool);
3815 extern void init_editfns (void);
3816 extern void syms_of_editfns (void);
3817 extern void set_time_zone_rule (const char *);
3818
3819 /* Defined in buffer.c. */
3820 extern bool mouse_face_overlay_overlaps (Lisp_Object);
3821 extern _Noreturn void nsberror (Lisp_Object);
3822 extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
3823 extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
3824 extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3825 extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
3826 Lisp_Object, Lisp_Object, Lisp_Object);
3827 extern bool overlay_touches_p (ptrdiff_t);
3828 extern Lisp_Object other_buffer_safely (Lisp_Object);
3829 extern Lisp_Object get_truename_buffer (Lisp_Object);
3830 extern void init_buffer_once (void);
3831 extern void init_buffer (void);
3832 extern void syms_of_buffer (void);
3833 extern void keys_of_buffer (void);
3834
3835 /* Defined in marker.c. */
3836
3837 extern ptrdiff_t marker_position (Lisp_Object);
3838 extern ptrdiff_t marker_byte_position (Lisp_Object);
3839 extern void clear_charpos_cache (struct buffer *);
3840 extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
3841 extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
3842 extern void unchain_marker (struct Lisp_Marker *marker);
3843 extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
3844 extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3845 extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
3846 ptrdiff_t, ptrdiff_t);
3847 extern Lisp_Object build_marker (struct buffer *, ptrdiff_t, ptrdiff_t);
3848 extern void syms_of_marker (void);
3849
3850 /* Defined in fileio.c. */
3851
3852 extern Lisp_Object Qfile_error;
3853 extern Lisp_Object Qfile_notify_error;
3854 extern Lisp_Object Qfile_exists_p;
3855 extern Lisp_Object Qfile_directory_p;
3856 extern Lisp_Object Qinsert_file_contents;
3857 extern Lisp_Object Qfile_name_history;
3858 extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object);
3859 extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object,
3860 Lisp_Object, Lisp_Object, Lisp_Object,
3861 Lisp_Object, int);
3862 EXFUN (Fread_file_name, 6); /* Not a normal DEFUN. */
3863 extern void close_file_unwind (int);
3864 extern void fclose_unwind (void *);
3865 extern void restore_point_unwind (Lisp_Object);
3866 extern _Noreturn void report_file_errno (const char *, Lisp_Object, int);
3867 extern _Noreturn void report_file_error (const char *, Lisp_Object);
3868 extern bool internal_delete_file (Lisp_Object);
3869 extern Lisp_Object emacs_readlinkat (int, const char *);
3870 extern bool file_directory_p (const char *);
3871 extern bool file_accessible_directory_p (const char *);
3872 extern void init_fileio (void);
3873 extern void syms_of_fileio (void);
3874 extern Lisp_Object make_temp_name (Lisp_Object, bool);
3875 extern Lisp_Object Qdelete_file;
3876
3877 /* Defined in search.c. */
3878 extern void shrink_regexp_cache (void);
3879 extern void restore_search_regs (void);
3880 extern void record_unwind_save_match_data (void);
3881 struct re_registers;
3882 extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
3883 struct re_registers *,
3884 Lisp_Object, bool, bool);
3885 extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
3886 extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
3887 ptrdiff_t);
3888 extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
3889 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
3890 ptrdiff_t, ptrdiff_t, Lisp_Object);
3891 extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3892 ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
3893 extern ptrdiff_t scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3894 ptrdiff_t, bool);
3895 extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
3896 ptrdiff_t, ptrdiff_t *);
3897 extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
3898 ptrdiff_t, ptrdiff_t *);
3899 extern void syms_of_search (void);
3900 extern void clear_regexp_cache (void);
3901
3902 /* Defined in minibuf.c. */
3903
3904 extern Lisp_Object Qcompletion_ignore_case;
3905 extern Lisp_Object Vminibuffer_list;
3906 extern Lisp_Object last_minibuf_string;
3907 extern Lisp_Object get_minibuffer (EMACS_INT);
3908 extern void init_minibuf_once (void);
3909 extern void syms_of_minibuf (void);
3910
3911 /* Defined in callint.c. */
3912
3913 extern Lisp_Object Qminus, Qplus;
3914 extern Lisp_Object Qwhen;
3915 extern Lisp_Object Qmouse_leave_buffer_hook;
3916 extern void syms_of_callint (void);
3917
3918 /* Defined in casefiddle.c. */
3919
3920 extern Lisp_Object Qidentity;
3921 extern void syms_of_casefiddle (void);
3922 extern void keys_of_casefiddle (void);
3923
3924 /* Defined in casetab.c. */
3925
3926 extern void init_casetab_once (void);
3927 extern void syms_of_casetab (void);
3928
3929 /* Defined in keyboard.c. */
3930
3931 extern Lisp_Object echo_message_buffer;
3932 extern struct kboard *echo_kboard;
3933 extern void cancel_echoing (void);
3934 extern Lisp_Object Qdisabled, QCfilter;
3935 extern Lisp_Object Qup, Qdown, Qbottom;
3936 extern Lisp_Object Qtop;
3937 extern Lisp_Object last_undo_boundary;
3938 extern bool input_pending;
3939 extern Lisp_Object menu_bar_items (Lisp_Object);
3940 extern Lisp_Object tool_bar_items (Lisp_Object, int *);
3941 extern void discard_mouse_events (void);
3942 #ifdef USABLE_SIGIO
3943 void handle_input_available_signal (int);
3944 #endif
3945 extern Lisp_Object pending_funcalls;
3946 extern bool detect_input_pending (void);
3947 extern bool detect_input_pending_ignore_squeezables (void);
3948 extern bool detect_input_pending_run_timers (bool);
3949 extern void safe_run_hooks (Lisp_Object);
3950 extern void cmd_error_internal (Lisp_Object, const char *);
3951 extern Lisp_Object command_loop_1 (void);
3952 extern Lisp_Object read_menu_command (void);
3953 extern Lisp_Object recursive_edit_1 (void);
3954 extern void record_auto_save (void);
3955 extern void force_auto_save_soon (void);
3956 extern void init_keyboard (void);
3957 extern void syms_of_keyboard (void);
3958 extern void keys_of_keyboard (void);
3959
3960 /* Defined in indent.c. */
3961 extern ptrdiff_t current_column (void);
3962 extern void invalidate_current_column (void);
3963 extern bool indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3964 extern void syms_of_indent (void);
3965
3966 /* Defined in frame.c. */
3967 extern Lisp_Object Qonly, Qnone;
3968 extern Lisp_Object Qvisible;
3969 extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
3970 extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
3971 extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
3972 #if HAVE_NS || defined WINDOWSNT
3973 extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
3974 #endif
3975 extern void frames_discard_buffer (Lisp_Object);
3976 extern void syms_of_frame (void);
3977
3978 /* Defined in emacs.c. */
3979 extern char **initial_argv;
3980 extern int initial_argc;
3981 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
3982 extern bool display_arg;
3983 #endif
3984 extern Lisp_Object decode_env_path (const char *, const char *);
3985 extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3986 extern Lisp_Object Qfile_name_handler_alist;
3987 extern _Noreturn void terminate_due_to_signal (int, int);
3988 extern Lisp_Object Qkill_emacs;
3989 #ifdef WINDOWSNT
3990 extern Lisp_Object Vlibrary_cache;
3991 #endif
3992 #if HAVE_SETLOCALE
3993 void fixup_locale (void);
3994 void synchronize_system_messages_locale (void);
3995 void synchronize_system_time_locale (void);
3996 #else
3997 INLINE void fixup_locale (void) {}
3998 INLINE void synchronize_system_messages_locale (void) {}
3999 INLINE void synchronize_system_time_locale (void) {}
4000 #endif
4001 extern void shut_down_emacs (int, Lisp_Object);
4002
4003 /* True means don't do interactive redisplay and don't change tty modes. */
4004 extern bool noninteractive;
4005
4006 /* True means remove site-lisp directories from load-path. */
4007 extern bool no_site_lisp;
4008
4009 /* Pipe used to send exit notification to the daemon parent at
4010 startup. */
4011 extern int daemon_pipe[2];
4012 #define IS_DAEMON (daemon_pipe[1] != 0)
4013
4014 /* True if handling a fatal error already. */
4015 extern bool fatal_error_in_progress;
4016
4017 /* True means don't do use window-system-specific display code. */
4018 extern bool inhibit_window_system;
4019 /* True means that a filter or a sentinel is running. */
4020 extern bool running_asynch_code;
4021
4022 /* Defined in process.c. */
4023 extern Lisp_Object QCtype, Qlocal;
4024 extern Lisp_Object Qprocessp;
4025 extern void kill_buffer_processes (Lisp_Object);
4026 extern bool wait_reading_process_output (intmax_t, int, int, bool,
4027 Lisp_Object,
4028 struct Lisp_Process *,
4029 int);
4030 /* Max value for the first argument of wait_reading_process_output. */
4031 #if __GNUC__ == 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 5)
4032 /* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.3.
4033 The bug merely causes a bogus warning, but the warning is annoying. */
4034 # define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX)
4035 #else
4036 # define WAIT_READING_MAX INTMAX_MAX
4037 #endif
4038 extern void add_keyboard_wait_descriptor (int);
4039 extern void delete_keyboard_wait_descriptor (int);
4040 #ifdef HAVE_GPM
4041 extern void add_gpm_wait_descriptor (int);
4042 extern void delete_gpm_wait_descriptor (int);
4043 #endif
4044 extern void init_process_emacs (void);
4045 extern void syms_of_process (void);
4046 extern void setup_process_coding_systems (Lisp_Object);
4047
4048 /* Defined in callproc.c. */
4049 #ifndef DOS_NT
4050 _Noreturn
4051 #endif
4052 extern int child_setup (int, int, int, char **, bool, Lisp_Object);
4053 extern void init_callproc_1 (void);
4054 extern void init_callproc (void);
4055 extern void set_initial_environment (void);
4056 extern void syms_of_callproc (void);
4057
4058 /* Defined in doc.c. */
4059 extern Lisp_Object Qfunction_documentation;
4060 extern Lisp_Object read_doc_string (Lisp_Object);
4061 extern Lisp_Object get_doc_string (Lisp_Object, bool, bool);
4062 extern void syms_of_doc (void);
4063 extern int read_bytecode_char (bool);
4064
4065 /* Defined in bytecode.c. */
4066 extern void syms_of_bytecode (void);
4067 extern struct byte_stack *byte_stack_list;
4068 #if BYTE_MARK_STACK
4069 extern void mark_byte_stack (void);
4070 #endif
4071 extern void unmark_byte_stack (void);
4072 extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
4073 Lisp_Object, ptrdiff_t, Lisp_Object *);
4074
4075 /* Defined in macros.c. */
4076 extern void init_macros (void);
4077 extern void syms_of_macros (void);
4078
4079 /* Defined in undo.c. */
4080 extern Lisp_Object Qapply;
4081 extern Lisp_Object Qinhibit_read_only;
4082 extern void truncate_undo_list (struct buffer *);
4083 extern void record_marker_adjustment (Lisp_Object, ptrdiff_t);
4084 extern void record_insert (ptrdiff_t, ptrdiff_t);
4085 extern void record_delete (ptrdiff_t, Lisp_Object);
4086 extern void record_first_change (void);
4087 extern void record_change (ptrdiff_t, ptrdiff_t);
4088 extern void record_property_change (ptrdiff_t, ptrdiff_t,
4089 Lisp_Object, Lisp_Object,
4090 Lisp_Object);
4091 extern void syms_of_undo (void);
4092 /* Defined in textprop.c. */
4093 extern Lisp_Object Qfont, Qmouse_face;
4094 extern Lisp_Object Qinsert_in_front_hooks, Qinsert_behind_hooks;
4095 extern Lisp_Object Qfront_sticky, Qrear_nonsticky;
4096 extern Lisp_Object Qminibuffer_prompt;
4097
4098 extern void report_interval_modification (Lisp_Object, Lisp_Object);
4099
4100 /* Defined in menu.c. */
4101 extern void syms_of_menu (void);
4102
4103 /* Defined in xmenu.c. */
4104 extern void syms_of_xmenu (void);
4105
4106 /* Defined in termchar.h. */
4107 struct tty_display_info;
4108
4109 /* Defined in termhooks.h. */
4110 struct terminal;
4111
4112 /* Defined in sysdep.c. */
4113 #ifndef HAVE_GET_CURRENT_DIR_NAME
4114 extern char *get_current_dir_name (void);
4115 #endif
4116 extern void stuff_char (char c);
4117 extern void init_foreground_group (void);
4118 extern void init_sigio (int);
4119 extern void sys_subshell (void);
4120 extern void sys_suspend (void);
4121 extern void discard_tty_input (void);
4122 extern void block_tty_out_signal (void);
4123 extern void unblock_tty_out_signal (void);
4124 extern void init_sys_modes (struct tty_display_info *);
4125 extern void reset_sys_modes (struct tty_display_info *);
4126 extern void init_all_sys_modes (void);
4127 extern void reset_all_sys_modes (void);
4128 extern void child_setup_tty (int);
4129 extern void setup_pty (int);
4130 extern int set_window_size (int, int, int);
4131 extern EMACS_INT get_random (void);
4132 extern void seed_random (void *, ptrdiff_t);
4133 extern void init_random (void);
4134 extern void emacs_backtrace (int);
4135 extern _Noreturn void emacs_abort (void) NO_INLINE;
4136 extern int emacs_open (const char *, int, int);
4137 extern int emacs_pipe (int[2]);
4138 extern int emacs_close (int);
4139 extern ptrdiff_t emacs_read (int, void *, ptrdiff_t);
4140 extern ptrdiff_t emacs_write (int, void const *, ptrdiff_t);
4141 extern ptrdiff_t emacs_write_sig (int, void const *, ptrdiff_t);
4142 extern void emacs_perror (char const *);
4143
4144 extern void unlock_all_files (void);
4145 extern void lock_file (Lisp_Object);
4146 extern void unlock_file (Lisp_Object);
4147 extern void unlock_buffer (struct buffer *);
4148 extern void syms_of_filelock (void);
4149
4150 /* Defined in sound.c. */
4151 extern void syms_of_sound (void);
4152
4153 /* Defined in category.c. */
4154 extern void init_category_once (void);
4155 extern Lisp_Object char_category_set (int);
4156 extern void syms_of_category (void);
4157
4158 /* Defined in ccl.c. */
4159 extern void syms_of_ccl (void);
4160
4161 /* Defined in dired.c. */
4162 extern void syms_of_dired (void);
4163 extern Lisp_Object directory_files_internal (Lisp_Object, Lisp_Object,
4164 Lisp_Object, Lisp_Object,
4165 bool, Lisp_Object);
4166
4167 /* Defined in term.c. */
4168 extern int *char_ins_del_vector;
4169 extern void syms_of_term (void);
4170 extern _Noreturn void fatal (const char *msgid, ...)
4171 ATTRIBUTE_FORMAT_PRINTF (1, 2);
4172
4173 /* Defined in terminal.c. */
4174 extern void syms_of_terminal (void);
4175
4176 /* Defined in font.c. */
4177 extern void syms_of_font (void);
4178 extern void init_font (void);
4179
4180 #ifdef HAVE_WINDOW_SYSTEM
4181 /* Defined in fontset.c. */
4182 extern void syms_of_fontset (void);
4183
4184 /* Defined in xfns.c, w32fns.c, or macfns.c. */
4185 extern Lisp_Object Qfont_param;
4186 #endif
4187
4188 /* Defined in gfilenotify.c */
4189 #ifdef HAVE_GFILENOTIFY
4190 extern void globals_of_gfilenotify (void);
4191 extern void syms_of_gfilenotify (void);
4192 #endif
4193
4194 /* Defined in inotify.c */
4195 #ifdef HAVE_INOTIFY
4196 extern void syms_of_inotify (void);
4197 #endif
4198
4199 #ifdef HAVE_W32NOTIFY
4200 /* Defined on w32notify.c. */
4201 extern void syms_of_w32notify (void);
4202 #endif
4203
4204 /* Defined in xfaces.c. */
4205 extern Lisp_Object Qdefault, Qtool_bar, Qfringe;
4206 extern Lisp_Object Qheader_line, Qscroll_bar, Qcursor;
4207 extern Lisp_Object Qmode_line_inactive;
4208 extern Lisp_Object Qface;
4209 extern Lisp_Object Qnormal;
4210 extern Lisp_Object QCfamily, QCweight, QCslant;
4211 extern Lisp_Object QCheight, QCname, QCwidth, QCforeground, QCbackground;
4212 extern Lisp_Object Qextra_light, Qlight, Qsemi_light, Qsemi_bold;
4213 extern Lisp_Object Qbold, Qextra_bold, Qultra_bold;
4214 extern Lisp_Object Qoblique, Qitalic;
4215 extern Lisp_Object Vface_alternative_font_family_alist;
4216 extern Lisp_Object Vface_alternative_font_registry_alist;
4217 extern void syms_of_xfaces (void);
4218
4219 #ifdef HAVE_X_WINDOWS
4220 /* Defined in xfns.c. */
4221 extern void syms_of_xfns (void);
4222
4223 /* Defined in xsmfns.c. */
4224 extern void syms_of_xsmfns (void);
4225
4226 /* Defined in xselect.c. */
4227 extern void syms_of_xselect (void);
4228
4229 /* Defined in xterm.c. */
4230 extern void syms_of_xterm (void);
4231 #endif /* HAVE_X_WINDOWS */
4232
4233 #ifdef HAVE_WINDOW_SYSTEM
4234 /* Defined in xterm.c, nsterm.m, w32term.c. */
4235 extern char *x_get_keysym_name (int);
4236 #endif /* HAVE_WINDOW_SYSTEM */
4237
4238 #ifdef HAVE_LIBXML2
4239 /* Defined in xml.c. */
4240 extern void syms_of_xml (void);
4241 extern void xml_cleanup_parser (void);
4242 #endif
4243
4244 #ifdef HAVE_ZLIB
4245 /* Defined in decompress.c. */
4246 extern void syms_of_decompress (void);
4247 #endif
4248
4249 #ifdef HAVE_DBUS
4250 /* Defined in dbusbind.c. */
4251 void syms_of_dbusbind (void);
4252 #endif
4253
4254
4255 /* Defined in profiler.c. */
4256 extern bool profiler_memory_running;
4257 extern void malloc_probe (size_t);
4258 extern void syms_of_profiler (void);
4259
4260
4261 #ifdef DOS_NT
4262 /* Defined in msdos.c, w32.c. */
4263 extern char *emacs_root_dir (void);
4264 #endif /* DOS_NT */
4265 \f
4266 /* True means Emacs has already been initialized.
4267 Used during startup to detect startup of dumped Emacs. */
4268 extern bool initialized;
4269
4270 /* True means ^G can quit instantly. */
4271 extern bool immediate_quit;
4272
4273 extern void *xmalloc (size_t);
4274 extern void *xzalloc (size_t);
4275 extern void *xrealloc (void *, size_t);
4276 extern void xfree (void *);
4277 extern void *xnmalloc (ptrdiff_t, ptrdiff_t);
4278 extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
4279 extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
4280
4281 extern char *xstrdup (const char *);
4282 extern char *xlispstrdup (Lisp_Object);
4283 extern void xputenv (const char *);
4284
4285 extern char *egetenv (const char *);
4286
4287 /* Copy Lisp string to temporary (allocated on stack) C string. */
4288
4289 #define xlispstrdupa(string) \
4290 memcpy (alloca (SBYTES (string) + 1), \
4291 SSDATA (string), SBYTES (string) + 1)
4292
4293 /* Set up the name of the machine we're running on. */
4294 extern void init_system_name (void);
4295
4296 /* Return the absolute value of X. X should be a signed integer
4297 expression without side effects, and X's absolute value should not
4298 exceed the maximum for its promoted type. This is called 'eabs'
4299 because 'abs' is reserved by the C standard. */
4300 #define eabs(x) ((x) < 0 ? -(x) : (x))
4301
4302 /* Return a fixnum or float, depending on whether VAL fits in a Lisp
4303 fixnum. */
4304
4305 #define make_fixnum_or_float(val) \
4306 (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
4307
4308 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
4309 larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */
4310
4311 enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 };
4312
4313 extern void *record_xmalloc (size_t);
4314
4315 #define USE_SAFE_ALLOCA \
4316 ptrdiff_t sa_count = SPECPDL_INDEX (); bool sa_must_free = 0
4317
4318 /* SAFE_ALLOCA allocates a simple buffer. */
4319
4320 #define SAFE_ALLOCA(size) ((size) < MAX_ALLOCA \
4321 ? alloca (size) \
4322 : (sa_must_free = 1, record_xmalloc (size)))
4323
4324 /* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
4325 NITEMS items, each of the same type as *BUF. MULTIPLIER must
4326 positive. The code is tuned for MULTIPLIER being a constant. */
4327
4328 #define SAFE_NALLOCA(buf, multiplier, nitems) \
4329 do { \
4330 if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \
4331 (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \
4332 else \
4333 { \
4334 (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
4335 sa_must_free = 1; \
4336 record_unwind_protect_ptr (xfree, buf); \
4337 } \
4338 } while (0)
4339
4340 /* SAFE_FREE frees xmalloced memory and enables GC as needed. */
4341
4342 #define SAFE_FREE() \
4343 do { \
4344 if (sa_must_free) { \
4345 sa_must_free = 0; \
4346 unbind_to (sa_count, Qnil); \
4347 } \
4348 } while (0)
4349
4350
4351 /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */
4352
4353 #define SAFE_ALLOCA_LISP(buf, nelt) \
4354 do { \
4355 if ((nelt) < MAX_ALLOCA / word_size) \
4356 buf = alloca ((nelt) * word_size); \
4357 else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / word_size) \
4358 { \
4359 Lisp_Object arg_; \
4360 buf = xmalloc ((nelt) * word_size); \
4361 arg_ = make_save_memory (buf, nelt); \
4362 sa_must_free = 1; \
4363 record_unwind_protect (free_save_value, arg_); \
4364 } \
4365 else \
4366 memory_full (SIZE_MAX); \
4367 } while (0)
4368
4369 /* Do a `for' loop over alist values. */
4370
4371 #define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var) \
4372 for (list_var = head_var; \
4373 (CONSP (list_var) && (value_var = XCDR (XCAR (list_var)), 1)); \
4374 list_var = XCDR (list_var))
4375
4376 /* Check whether it's time for GC, and run it if so. */
4377
4378 INLINE void
4379 maybe_gc (void)
4380 {
4381 if ((consing_since_gc > gc_cons_threshold
4382 && consing_since_gc > gc_relative_threshold)
4383 || (!NILP (Vmemory_full)
4384 && consing_since_gc > memory_full_cons_threshold))
4385 Fgarbage_collect ();
4386 }
4387
4388 INLINE bool
4389 functionp (Lisp_Object object)
4390 {
4391 if (SYMBOLP (object) && !NILP (Ffboundp (object)))
4392 {
4393 object = Findirect_function (object, Qt);
4394
4395 if (CONSP (object) && EQ (XCAR (object), Qautoload))
4396 {
4397 /* Autoloaded symbols are functions, except if they load
4398 macros or keymaps. */
4399 int i;
4400 for (i = 0; i < 4 && CONSP (object); i++)
4401 object = XCDR (object);
4402
4403 return ! (CONSP (object) && !NILP (XCAR (object)));
4404 }
4405 }
4406
4407 if (SUBRP (object))
4408 return XSUBR (object)->max_args != UNEVALLED;
4409 else if (COMPILEDP (object))
4410 return 1;
4411 else if (CONSP (object))
4412 {
4413 Lisp_Object car = XCAR (object);
4414 return EQ (car, Qlambda) || EQ (car, Qclosure);
4415 }
4416 else
4417 return 0;
4418 }
4419
4420 /* Round x to the next multiple of y. Does not overflow. Evaluates
4421 arguments repeatedly. */
4422 #define ROUNDUP(x,y) ((y)*((x)/(y) + ((x)%(y)!=0)))
4423
4424 INLINE_HEADER_END
4425
4426 #endif /* EMACS_LISP_H */