Fixup assert definitions.
[sxemacs] / src / lisp.h
1 /* Fundamental definitions for SXEmacs Lisp interpreter.
2    Copyright (C) 1985-1987, 1992-1995 Free Software Foundation, Inc.
3    Copyright (C) 1993-1996 Richard Mlynarik.
4    Copyright (C) 1995, 1996, 2000 Ben Wing.
5    Copyright (C) 2004 Steve Youngs.
6
7 This file is part of SXEmacs
8
9 SXEmacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 SXEmacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
21
22
23 /* Synched up with: FSF 19.30. */
24
25 #ifndef INCLUDED_lisp_h_
26 #define INCLUDED_lisp_h_
27
28 /************************************************************************/
29 /*                        general definitions                           */
30 /************************************************************************/
31
32 /* the old SXEmacs general includes and utility macros moved here: */
33 #include "sxe-utils.h"
34 #include "sxe-memory.h"
35
36 /* ------------------------ dynamic arrays ------------------- */
37
38 #define Dynarr_declare(type)    \
39   type *base;                   \
40   int elsize;                   \
41   int cur;                      \
42   int largest;                  \
43   int max
44
45 typedef struct dynarr {
46         Dynarr_declare(void);
47 } Dynarr;
48
49 void *Dynarr_newf(int elsize);
50 void Dynarr_resize(void *dy, int size);
51 void Dynarr_insert_many(void *d, const void *el, int len, int start);
52 void Dynarr_delete_many(void *d, int start, int len);
53 void Dynarr_free(void *d);
54
55 #define Dynarr_new(type) ((type##_dynarr *) Dynarr_newf (sizeof (type)))
56 #define Dynarr_new2(dynarr_type, type) \
57   ((dynarr_type *) Dynarr_newf (sizeof (type)))
58 #define Dynarr_at(d, pos) ((d)->base[pos])
59 #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos))
60 #define Dynarr_begin(d) Dynarr_atp (d, 0)
61 #define Dynarr_end(d) Dynarr_atp (d, Dynarr_length (d) - 1)
62 #define Dynarr_sizeof(d) ((d)->cur * (d)->elsize)
63 #define Dynarr_length(d) ((d)->cur)
64 #define Dynarr_largest(d) ((d)->largest)
65 #define Dynarr_reset(d) ((d)->cur = 0)
66 #define Dynarr_add_many(d, el, len) Dynarr_insert_many (d, el, len, (d)->cur)
67 #define Dynarr_insert_many_at_start(d, el, len) \
68   Dynarr_insert_many (d, el, len, 0)
69 #define Dynarr_add_literal_string(d, s) Dynarr_add_many (d, s, sizeof (s) - 1)
70 #define Dynarr_add_lisp_string(d, s) do {               \
71   Lisp_String *dyna_ls_s = XSTRING (s);                 \
72   Dynarr_add_many (d, (char *) string_data (dyna_ls_s), \
73                    string_length (dyna_ls_s));          \
74 } while (0)
75
76 #define Dynarr_add(d, el) (                                             \
77   (d)->cur >= (d)->max ? Dynarr_resize ((d), (d)->cur+1) : (void) 0,    \
78   ((d)->base)[(d)->cur++] = (el),                                       \
79   (d)->cur > (d)->largest ? (d)->largest = (d)->cur : (int) 0)
80
81 /* The following defines will get you into real trouble if you aren't
82    careful.  But they can save a lot of execution time when used wisely. */
83 #define Dynarr_increment(d) ((d)->cur++)
84 #define Dynarr_set_size(d, n) ((d)->cur = n)
85
86 #ifdef MEMORY_USAGE_STATS
87 struct overhead_stats;
88 size_t Dynarr_memory_usage(void *d, struct overhead_stats *stats);
89 #endif
90
91
92 \f
93
94
95
96 /*#ifdef DEBUG_SXEMACS*/
97 #define REGISTER
98 #define register
99 /*#else*/
100 /*#define REGISTER register*/
101 /*#endif*/
102
103 /* EMACS_INT is the underlying integral type into which a Lisp_Object must fit.
104    In particular, it must be large enough to contain a pointer.
105    config.h can override this, e.g. to use `long long' for bigger lisp ints.
106
107    #### In point of fact, it would NOT be a good idea for config.h to mess
108    with EMACS_INT.  A lot of code makes the basic assumption that EMACS_INT
109    is the size of a pointer. */
110
111 #ifndef SIZEOF_EMACS_INT
112 # define SIZEOF_EMACS_INT SIZEOF_VOID_P
113 #endif
114
115 #ifndef EMACS_INT
116 # if   SIZEOF_EMACS_INT == SIZEOF_LONG
117 #  define EMACS_INT long
118 # elif SIZEOF_EMACS_INT == SIZEOF_INT
119 #  define EMACS_INT int
120 # elif SIZEOF_EMACS_INT == SIZEOF_LONG_LONG_INT
121 #  define EMACS_INT long long
122 # else
123 #  error Unable to determine suitable type for EMACS_INT
124 # endif
125 #endif
126
127 #ifndef EMACS_UINT
128 # define EMACS_UINT unsigned EMACS_INT
129 #endif
130
131 #define BITS_PER_EMACS_INT (SIZEOF_EMACS_INT * BITS_PER_CHAR)
132 \f
133 /************************************************************************/
134 /*                                typedefs                              */
135 /************************************************************************/
136
137 /* We put typedefs here so that prototype declarations don't choke.
138    Note that we don't actually declare the structures here (except
139    maybe for simple structures like Dynarrs); that keeps them private
140    to the routines that actually use them. */
141
142 /* ------------------------------- */
143 /*     basic char/int typedefs     */
144 /* ------------------------------- */
145
146 /* The definitions we put here use typedefs to attribute specific meaning
147    to types that by themselves are pretty general.  Stuff pointed to by a
148    char * or unsigned char * will nearly always be one of four types:
149    a) pointer to internally-formatted text; b) pointer to text in some
150    external format, which can be defined as all formats other than the
151    internal one; c) pure ASCII text; d) binary data that is not meant to
152    be interpreted as text. [A fifth possible type "e) a general pointer
153    to memory" should be replaced with void *.]  Using these more specific
154    types rather than the general ones helps avoid the confusions that
155    occur when the semantics of a char * argument being studied are unclear. */
156
157 typedef unsigned char UChar;
158
159 /* The data representing the text in a buffer is logically a set
160    of Bufbytes, declared as follows. */
161
162 typedef UChar Bufbyte;
163
164 /* Explicitly signed or unsigned versions: */
165 typedef UChar UBufbyte;
166 typedef char SBufbyte;
167
168 /* The data representing a string in "external" format (binary or any
169    external encoding) is logically a set of Extbytes, declared as
170    follows.  Extbyte is guaranteed to be just a char, so for example
171    strlen (Extbyte *) is OK.  Extbyte is only a documentation device
172    for referring to external text. */
173
174 typedef char Extbyte;
175
176 /* A byte in a string in binary format: */
177 typedef char Char_Binary;
178 typedef UChar UChar_Binary;
179
180 /* A byte in a string in entirely US-ASCII format: (Nothing outside
181  the range 00 - 7F) */
182
183 typedef char Char_ASCII;
184 typedef UChar UChar_ASCII;
185
186 /* To the user, a buffer is made up of characters, declared as follows.
187    In the non-Mule world, characters and Bufbytes are equivalent.
188    In the Mule world, a character requires (typically) 1 to 4
189    Bufbytes for its representation in a buffer. */
190
191 typedef int Emchar;
192
193 /* Different ways of referring to a position in a buffer.  We use
194    the typedefs in preference to 'EMACS_INT' to make it clearer what
195    sort of position is being used.  See extents.c for a description
196    of the different positions.  We put them here instead of in
197    buffer.h (where they rightfully belong) to avoid syntax errors
198    in function prototypes. */
199
200 typedef EMACS_INT Bufpos;
201 typedef EMACS_INT Bytind;
202 typedef EMACS_INT Memind;
203
204 /* Counts of bytes or chars */
205
206 typedef EMACS_INT Bytecount;
207 typedef EMACS_INT Charcount;
208
209 /* Length in bytes of a string in external format */
210 typedef EMACS_INT Extcount;
211
212 /* ------------------------------- */
213 /*     structure/other typedefs    */
214 /* ------------------------------- */
215
216 /* Counts of bytes or array elements */
217 typedef EMACS_INT Memory_count;
218 typedef EMACS_INT Element_count;
219
220 /* is this right here? */
221 typedef struct lstream_s *lstream_t;
222 /* deprecated */
223 typedef struct lstream_s Lstream;
224
225 typedef unsigned int face_index;
226
227 typedef struct {
228         Dynarr_declare(struct face_cachel);
229 } face_cachel_dynarr;
230
231 typedef unsigned int glyph_index;
232
233 /* This is shared by process.h, events.h and others in future.
234    See events.h for description */
235 typedef long unsigned int USID;
236
237 typedef struct {
238         Dynarr_declare(struct glyph_cachel);
239 } glyph_cachel_dynarr;
240
241 struct buffer;                  /* "buffer.h" */
242 struct console;                 /* "console.h" */
243 struct device;                  /* "device.h" */
244 struct extent_fragment;
245 struct extent;
246 typedef struct extent *EXTENT;
247 struct frame;                   /* "frame.h" */
248 struct window;                  /* "window.h" */
249 typedef struct Lisp_Event Lisp_Event;   /* "events.h" */
250 typedef struct Lisp_Face Lisp_Face;     /* "faces.h" */
251 typedef struct Lisp_Process Lisp_Process;       /* "procimpl.h" */
252 struct stat;                    /* <sys/stat.h> */
253 typedef struct Lisp_Color_Instance Lisp_Color_Instance;
254 typedef struct Lisp_Font_Instance Lisp_Font_Instance;
255 typedef struct Lisp_Image_Instance Lisp_Image_Instance;
256 typedef struct Lisp_Gui_Item Lisp_Gui_Item;
257 struct display_line;
258 struct display_glyph_area;
259 struct display_box;
260 struct redisplay_info;
261 struct window_mirror;
262 struct scrollbar_instance;
263 struct font_metric_info;
264 struct face_cachel;
265 struct console_type_entry;
266
267 typedef struct {
268         Dynarr_declare(Bufbyte);
269 } Bufbyte_dynarr;
270
271 typedef struct {
272         Dynarr_declare(Extbyte);
273 } Extbyte_dynarr;
274
275 typedef struct {
276         Dynarr_declare(Emchar);
277 } Emchar_dynarr;
278
279 typedef struct {
280         Dynarr_declare(char);
281 } char_dynarr;
282
283 typedef unsigned char unsigned_char;
284 typedef struct {
285         Dynarr_declare(unsigned char);
286 } unsigned_char_dynarr;
287
288 typedef unsigned long unsigned_long;
289 typedef struct {
290         Dynarr_declare(unsigned long);
291 } unsigned_long_dynarr;
292
293 typedef struct {
294         Dynarr_declare(int);
295 } int_dynarr;
296
297 typedef struct {
298         Dynarr_declare(Bufpos);
299 } Bufpos_dynarr;
300
301 typedef struct {
302         Dynarr_declare(Bytind);
303 } Bytind_dynarr;
304
305 typedef struct {
306         Dynarr_declare(Charcount);
307 } Charcount_dynarr;
308
309 typedef struct {
310         Dynarr_declare(Bytecount);
311 } Bytecount_dynarr;
312
313 typedef struct {
314         Dynarr_declare(struct console_type_entry);
315 } console_type_entry_dynarr;
316
317 enum run_hooks_condition {
318         RUN_HOOKS_TO_COMPLETION,
319         RUN_HOOKS_UNTIL_SUCCESS,
320         RUN_HOOKS_UNTIL_FAILURE
321 };
322
323 #ifdef HAVE_TOOLBARS
324 enum toolbar_pos {
325         TOP_TOOLBAR,
326         BOTTOM_TOOLBAR,
327         LEFT_TOOLBAR,
328         RIGHT_TOOLBAR
329 };
330 #endif
331
332 enum edge_style {
333         EDGE_ETCHED_IN,
334         EDGE_ETCHED_OUT,
335         EDGE_BEVEL_IN,
336         EDGE_BEVEL_OUT
337 };
338
339 #ifndef ERROR_CHECK_TYPECHECK
340
341 typedef enum error_behavior {
342         ERROR_ME,
343         ERROR_ME_NOT,
344         ERROR_ME_WARN
345 } Error_behavior;
346
347 #define ERRB_EQ(a, b) ((a) == (b))
348
349 #else
350
351 /* By defining it like this, we provide strict type-checking
352    for code that lazily uses ints. */
353
354 typedef struct _error_behavior_struct_ {
355         int really_unlikely_name_to_have_accidentally_in_a_non_errb_structure;
356 } Error_behavior;
357
358 extern Error_behavior ERROR_ME;
359 extern Error_behavior ERROR_ME_NOT;
360 extern Error_behavior ERROR_ME_WARN;
361
362 #define ERRB_EQ(a, b)                                                      \
363  ((a).really_unlikely_name_to_have_accidentally_in_a_non_errb_structure == \
364   (b).really_unlikely_name_to_have_accidentally_in_a_non_errb_structure)
365
366 #endif
367
368 enum munge_me_out_the_door {
369         MUNGE_ME_FUNCTION_KEY,
370         MUNGE_ME_KEY_TRANSLATION
371 };
372
373 /* very cool convenience type */
374 typedef size_t sxe_index_t;
375 \f
376 /************************************************************************/
377 /*                   Definition of Lisp_Object data type                */
378 /************************************************************************/
379
380 /* Define the fundamental Lisp data structures */
381
382 /* This is the set of Lisp data types */
383
384 enum Lisp_Type {
385         Lisp_Type_Record,
386         Lisp_Type_Int_Even,
387         Lisp_Type_Char,
388         Lisp_Type_Int_Odd
389 };
390
391 #define POINTER_TYPE_P(type) ((type) == Lisp_Type_Record)
392
393 /* Overridden by m/next.h */
394 #ifndef ASSERT_VALID_POINTER
395 # define ASSERT_VALID_POINTER(pnt) assert((((EMACS_UINT) pnt) & 3) == 0)
396 #endif
397
398 #define GCMARKBITS  0
399 #define GCTYPEBITS  2
400 #define GCBITS      2
401 #define INT_GCBITS  1
402
403 #define INT_VALBITS (BITS_PER_EMACS_INT - INT_GCBITS)
404 #define VALBITS (BITS_PER_EMACS_INT - GCBITS)
405 #define EMACS_INT_MAX ((EMACS_INT) ((1UL << (INT_VALBITS - 1)) -1UL))
406 #define EMACS_INT_MIN (-(EMACS_INT_MAX) - 1)
407 #define NUMBER_FITS_IN_AN_EMACS_INT(num) \
408   ((num) <= EMACS_INT_MAX && (num) >= EMACS_INT_MIN)
409
410 #include "lisp-disunion.h"
411
412 #define XPNTR(x) ((void *) XPNTRVAL(x))
413
414 /* WARNING WARNING WARNING.  You must ensure on your own that proper
415    GC protection is provided for the elements in this array. */
416 typedef struct {
417         Dynarr_declare(Lisp_Object);
418 } Lisp_Object_dynarr;
419
420 typedef struct {
421         Dynarr_declare(Lisp_Object *);
422 } Lisp_Object_ptr_dynarr;
423
424 /* Close your eyes now lest you vomit or spontaneously combust ... */
425
426 #define HACKEQ_UNSAFE(obj1, obj2)                               \
427   (EQ (obj1, obj2) || (!POINTER_TYPE_P (XTYPE (obj1))           \
428                        && !POINTER_TYPE_P (XTYPE (obj2))        \
429                        && XCHAR_OR_INT (obj1) == XCHAR_OR_INT (obj2)))
430
431 #ifdef DEBUG_SXEMACS
432 extern int debug_issue_ebola_notices;
433 int eq_with_ebola_notice(Lisp_Object, Lisp_Object);
434 #define EQ_WITH_EBOLA_NOTICE(obj1, obj2)                                \
435   (debug_issue_ebola_notices ? eq_with_ebola_notice (obj1, obj2)        \
436    : EQ (obj1, obj2))
437 #else
438 #define EQ_WITH_EBOLA_NOTICE(obj1, obj2) EQ (obj1, obj2)
439 #endif
440
441 /* OK, you can open them again */
442 \f
443 /************************************************************************/
444 /**                  Definitions of basic Lisp objects                 **/
445 /************************************************************************/
446
447 #include "lrecord.h"
448
449 /*------------------------------ unbound -------------------------------*/
450
451 /* Qunbound is a special Lisp_Object (actually of type
452    symbol-value-forward), that can never be visible to
453    the Lisp caller and thus can be used in the C code
454    to mean "no such value". */
455
456 #define UNBOUNDP(val) EQ (val, Qunbound)
457
458 /*------------------------------- cons ---------------------------------*/
459
460 /* In a cons, the markbit of the car is the gc mark bit */
461
462 struct Lisp_Cons {
463         struct lrecord_header lheader;
464         /* for seq iterators */
465         void *si;
466         Lisp_Object car, cdr;
467 };
468 typedef struct Lisp_Cons Lisp_Cons;
469
470 DECLARE_LRECORD(cons, Lisp_Cons);
471 #define XCONS(x) XRECORD (x, cons, Lisp_Cons)
472 #define XSETCONS(x, p) XSETRECORD (x, p, cons)
473 #define CONSP(x) RECORDP (x, cons)
474 #define CHECK_CONS(x) CHECK_RECORD (x, cons)
475 #define CONCHECK_CONS(x) CONCHECK_RECORD (x, cons)
476
477 #define CONS_MARKED_P(c) MARKED_RECORD_HEADER_P(&((c)->lheader))
478 #define MARK_CONS(c) MARK_RECORD_HEADER (&((c)->lheader))
479
480 extern Lisp_Object Qnil;
481
482 #define NILP(x)  EQ (x, Qnil)
483 #define XCAR(a) (XCONS (a)->car)
484 #define XCDR(a) (XCONS (a)->cdr)
485 #define LISTP(x) (CONSP(x) || NILP(x))
486
487 #define CHECK_LIST(x) do {                      \
488   if (!LISTP (x))                               \
489     dead_wrong_type_argument (Qlistp, x);       \
490 } while (0)
491
492 #define CONCHECK_LIST(x) do {                   \
493   if (!LISTP (x))                               \
494     x = wrong_type_argument (Qlistp, x);        \
495 } while (0)
496
497 /*---------------------- list traversal macros -------------------------*/
498
499 /* Note: These macros are for traversing through a list in some format,
500    and executing code that you specify on each member of the list.
501
502    There are two kinds of macros, those requiring surrounding braces, and
503    those not requiring this.  Which type of macro will be indicated.
504    The general format for using a brace-requiring macro is
505
506    {
507      LIST_LOOP_3 (elt, list, tail)
508        execute_code_here;
509    }
510
511    or
512
513    {
514      LIST_LOOP_3 (elt, list, tail)
515        {
516          execute_code_here;
517        }
518    }
519
520    You can put variable declarations between the brace and beginning of
521    macro, but NOTHING ELSE.
522
523    The brace-requiring macros typically declare themselves any arguments
524    that are initialized and iterated by the macros.  If for some reason
525    you need to declare these arguments yourself (e.g. to do something on
526    them before the iteration starts, use the _NO_DECLARE versions of the
527    macros.)
528 */
529
530 /* There are two basic kinds of macros: those that handle "internal" lists
531    that are known to be correctly structured (i.e. first element is a cons
532    or nil, and the car of each cons is also a cons or nil, and there are
533    no circularities), and those that handle "external" lists, where the
534    list may have any sort of invalid formation.  This is reflected in
535    the names: those with "EXTERNAL_" work with external lists, and those
536    without this prefix work with internal lists.  The internal-list
537    macros will hit an assertion failure if the structure is ill-formed;
538    the external-list macros will signal an error in this case, either a
539    malformed-list error or a circular-list error.
540
541    Note also that the simplest external list iterator, EXTERNAL_LIST_LOOP,
542    does *NOT* check for circularities.  Therefore, make sure you call
543    QUIT each iteration or so.  However, it's probably easier just to use
544    EXTERNAL_LIST_LOOP_2, which is easier to use in any case.
545 */
546
547 /* LIST_LOOP and EXTERNAL_LIST_LOOP are the simplest macros.  They don't
548    require brace surrounding, and iterate through a list, which may or may
549    not known to be syntactically correct.  EXTERNAL_LIST_LOOP is for those
550    not known to be correct, and it detects and signals a malformed list
551    error when encountering a problem.  Circularities, however, are not
552    handled, and cause looping forever, so make sure to include a QUIT.
553    These functions also accept two args, TAIL (set progressively to each
554    cons starting with the first), and LIST, the list to iterate over.
555    TAIL needs to be defined by the program.
556
557    In each iteration, you can retrieve the current list item using XCAR
558    (tail), or destructively modify the list using XSETCAR (tail,
559    ...). */
560
561 #define LIST_LOOP(tail, list)           \
562         for (tail = list;               \
563              !NILP (tail);              \
564              tail = XCDR (tail))
565
566 #define EXTERNAL_LIST_LOOP(tail, list)                          \
567         for (tail = list; !NILP (tail); tail = XCDR (tail))     \
568                 if (!CONSP (tail)) {                            \
569                         signal_malformed_list_error (list);     \
570                 } else
571
572 /* The following macros are the "core" macros for list traversal.
573
574    *** ALL OF THESE MACROS MUST BE DECLARED INSIDE BRACES -- SEE ABOVE. ***
575
576    LIST_LOOP_2 and EXTERNAL_LIST_LOOP_2 are the standard, most-often used
577    macros.  They take two arguments, an element variable ELT and the list
578    LIST.  ELT is automatically declared, and set to each element in turn
579    from LIST.
580
581    LIST_LOOP_3 and EXTERNAL_LIST_LOOP_3 are the same, but they have a third
582    argument TAIL, another automatically-declared variable.  At each iteration,
583    this one points to the cons cell for which ELT is the car.
584
585    EXTERNAL_LIST_LOOP_4 is like EXTERNAL_LIST_LOOP_3 but takes an additional
586    LEN argument, again automatically declared, which counts the number of
587    iterations gone by.  It is 0 during the first iteration.
588
589    EXTERNAL_LIST_LOOP_4_NO_DECLARE is like EXTERNAL_LIST_LOOP_4 but none
590    of the variables are automatically declared, and so you need to declare
591    them yourself. (ELT and TAIL are Lisp_Objects, and LEN is an EMACS_INT.)
592 */
593
594 #define LIST_LOOP_2(elt, list)                          \
595         LIST_LOOP_3(elt, list, unused_tail_##elt)
596
597 #define LIST_LOOP_3(elt, list, tail)                            \
598         for (Lisp_Object elt, tail = list;                      \
599              NILP(tail) ? false : (elt = XCAR (tail), true);    \
600              tail = XCDR (tail))
601
602 /* The following macros are for traversing lisp lists.
603    Signal an error if LIST is not properly acyclic and nil-terminated.
604
605    Use tortoise/hare algorithm to check for cycles, but only if it
606    looks like the list is getting too long.  Not only is the hare
607    faster than the tortoise; it even gets a head start! */
608
609 /* Optimized and safe macros for looping over external lists.  */
610 #define CIRCULAR_LIST_SUSPICION_LENGTH 1024
611
612 #define EXTERNAL_LIST_LOOP_1(list)                                      \
613 Lisp_Object ELL1_elt, ELL1_hare, ELL1_tortoise;                         \
614 EMACS_INT ELL1_len;                                                     \
615 PRIVATE_EXTERNAL_LIST_LOOP_6 (ELL1_elt, list, ELL1_len, ELL1_hare,      \
616                       ELL1_tortoise, CIRCULAR_LIST_SUSPICION_LENGTH)
617
618 #define EXTERNAL_LIST_LOOP_2(elt, list)                                 \
619 Lisp_Object elt, hare_##elt, tortoise_##elt;                            \
620 EMACS_INT len_##elt;                                                    \
621 PRIVATE_EXTERNAL_LIST_LOOP_6 (elt, list, len_##elt, hare_##elt,         \
622                       tortoise_##elt, CIRCULAR_LIST_SUSPICION_LENGTH)
623
624 #define EXTERNAL_LIST_LOOP_3(elt, list, tail)                           \
625 Lisp_Object elt, tail, tortoise_##elt;                                  \
626 EMACS_INT len_##elt;                                                    \
627 PRIVATE_EXTERNAL_LIST_LOOP_6 (elt, list, len_##elt, tail,               \
628                       tortoise_##elt, CIRCULAR_LIST_SUSPICION_LENGTH)
629
630 #define EXTERNAL_LIST_LOOP_4_NO_DECLARE(elt, list, tail, len)           \
631 Lisp_Object tortoise_##elt;                                             \
632 PRIVATE_EXTERNAL_LIST_LOOP_6 (elt, list, len, tail,                     \
633                       tortoise_##elt, CIRCULAR_LIST_SUSPICION_LENGTH)
634
635 #define EXTERNAL_LIST_LOOP_4(elt, list, tail, len)                      \
636 Lisp_Object elt, tail, tortoise_##elt;                                  \
637 EMACS_INT len;                                                          \
638 PRIVATE_EXTERNAL_LIST_LOOP_6 (elt, list, len, tail,                     \
639                       tortoise_##elt, CIRCULAR_LIST_SUSPICION_LENGTH)
640
641 #define PRIVATE_EXTERNAL_LIST_LOOP_6(elt, list, len, hare,              \
642                                      tortoise, suspicion_length)        \
643         for (tortoise = hare = list, len = 0;                           \
644                                                                         \
645              (CONSP (hare) ? ((elt = XCAR (hare)), 1) :                 \
646               (NILP (hare) ? 0 :                                        \
647                (signal_malformed_list_error (list), 0)));               \
648                                                                         \
649              (hare = XCDR (hare)),                                      \
650                      (void)((++len > suspicion_length) &&               \
651                             ((void)(((len & 1) != 0)&&                  \
652                                     ((tortoise = XCDR (tortoise)), 0)), \
653                              (EQ (hare, tortoise) &&                    \
654                               (signal_circular_list_error (list), 0)))))
655
656 /* GET_LIST_LENGTH and GET_EXTERNAL_LIST_LENGTH:
657
658    These two macros return the length of LIST (either an internal or external
659    list, according to which macro is used), stored into LEN (which must
660    be declared by the caller).  Circularities are trapped in external lists
661    (and cause errors).  Neither macro need be declared inside brackets. */
662
663 #define GET_LIST_LENGTH(list, len) do {         \
664   Lisp_Object GLL_tail;                         \
665   for (GLL_tail = list, len = 0;                \
666        !NILP (GLL_tail);                        \
667        GLL_tail = XCDR (GLL_tail), ++len)       \
668     DO_NOTHING;                                 \
669 } while (0)
670
671 #define GET_EXTERNAL_LIST_LENGTH(list, len)                             \
672 do {                                                                    \
673   Lisp_Object GELL_elt, GELL_tail;                                      \
674   EXTERNAL_LIST_LOOP_4_NO_DECLARE (GELL_elt, list, GELL_tail, len)      \
675     ;                                                                   \
676   (void)GELL_elt;                                                       \
677 } while (0)
678
679 /* For a list that's known to be in valid list format, where we may
680    be deleting the current element out of the list --
681    will abort() if the list is not in valid format */
682 #define LIST_LOOP_DELETING(consvar, nextconsvar, list)          \
683   for (consvar = list;                                          \
684        !NILP (consvar) ? (nextconsvar = XCDR (consvar), 1) :0;  \
685        consvar = nextconsvar)
686
687 /* LIST_LOOP_DELETE_IF and EXTERNAL_LIST_LOOP_DELETE_IF:
688
689    These two macros delete all elements of LIST (either an internal or
690    external list, according to which macro is used) satisfying
691    CONDITION, a C expression referring to variable ELT.  ELT is
692    automatically declared.  Circularities are trapped in external
693    lists (and cause errors).  Neither macro need be declared inside
694    brackets. */
695
696 #define LIST_LOOP_DELETE_IF(elt, list, condition) do {          \
697   /* Do not use ##list when creating new variables because      \
698      that may not be just a variable name. */                   \
699   Lisp_Object prev_tail_##elt = Qnil;                           \
700   LIST_LOOP_3 (elt, list, tail_##elt)                           \
701     {                                                           \
702       if (condition)                                            \
703         {                                                       \
704           if (NILP (prev_tail_##elt))                           \
705             list = XCDR (tail_##elt);                           \
706           else                                                  \
707             XCDR (prev_tail_##elt) = XCDR (tail_##elt); \
708         }                                                       \
709       else                                                      \
710         prev_tail_##elt = tail_##elt;                           \
711     }                                                           \
712 } while (0)
713
714 #define EXTERNAL_LIST_LOOP_DELETE_IF(elt, list, condition) do { \
715   Lisp_Object prev_tail_##elt = Qnil;                           \
716   EXTERNAL_LIST_LOOP_4 (elt, list, tail_##elt, len_##elt)       \
717     {                                                           \
718       if (condition)                                            \
719         {                                                       \
720           if (NILP (prev_tail_##elt))                           \
721             list = XCDR (tail_##elt);                           \
722           else                                                  \
723             XCDR (prev_tail_##elt) = XCDR (tail_##elt);         \
724           /* Keep tortoise from ever passing hare. */           \
725           len_##elt = 0;                                        \
726         }                                                       \
727       else                                                      \
728         prev_tail_##elt = tail_##elt;                           \
729     }                                                           \
730 } while (0)
731
732 /* Macros for looping over external alists.
733
734    *** ALL OF THESE MACROS MUST BE DECLARED INSIDE BRACES -- SEE ABOVE. ***
735
736    EXTERNAL_ALIST_LOOP_4 is similar to EXTERNAL_LIST_LOOP_2, but it
737    assumes the elements are aconses (the elements in an alist) and
738    sets two additional argument variables ELT_CAR and ELT_CDR to the
739    car and cdr of the acons.  All of the variables ELT, ELT_CAR and
740    ELT_CDR are automatically declared.
741
742    EXTERNAL_ALIST_LOOP_5 adds a TAIL argument to EXTERNAL_ALIST_LOOP_4,
743    just like EXTERNAL_LIST_LOOP_3 does, and again TAIL is automatically
744    declared.
745
746    EXTERNAL_ALIST_LOOP_6 adds a LEN argument to EXTERNAL_ALIST_LOOP_5,
747    just like EXTERNAL_LIST_LOOP_4 does, and again LEN is automatically
748    declared.
749
750    EXTERNAL_ALIST_LOOP_6_NO_DECLARE does not declare any of its arguments,
751    just like EXTERNAL_LIST_LOOP_4_NO_DECLARE, and so these must be declared
752    manually.
753  */
754
755 /* Optimized and safe macros for looping over external alists. */
756 #define EXTERNAL_ALIST_LOOP_4(elt, elt_car, elt_cdr, list)      \
757 Lisp_Object elt, elt_car, elt_cdr;                              \
758 Lisp_Object hare_##elt, tortoise_##elt;                         \
759 EMACS_INT len_##elt;                                            \
760 PRIVATE_EXTERNAL_ALIST_LOOP_8 (elt, elt_car, elt_cdr, list,     \
761                        len_##elt, hare_##elt, tortoise_##elt,   \
762                        CIRCULAR_LIST_SUSPICION_LENGTH)
763
764 #define EXTERNAL_ALIST_LOOP_5(elt, elt_car, elt_cdr, list, tail)        \
765 Lisp_Object elt, elt_car, elt_cdr, tail;                                \
766 Lisp_Object tortoise_##elt;                                             \
767 EMACS_INT len_##elt;                                                    \
768 PRIVATE_EXTERNAL_ALIST_LOOP_8 (elt, elt_car, elt_cdr, list,             \
769                        len_##elt, tail, tortoise_##elt,                 \
770                        CIRCULAR_LIST_SUSPICION_LENGTH)                  \
771
772 #define EXTERNAL_ALIST_LOOP_6(elt, elt_car, elt_cdr, list, tail, len)   \
773 Lisp_Object elt, elt_car, elt_cdr, tail;                                \
774 EMACS_INT len;                                                          \
775 Lisp_Object tortoise_##elt;                                             \
776 PRIVATE_EXTERNAL_ALIST_LOOP_8 (elt, elt_car, elt_cdr, list,             \
777                        len, tail, tortoise_##elt,                       \
778                        CIRCULAR_LIST_SUSPICION_LENGTH)
779
780 #define EXTERNAL_ALIST_LOOP_6_NO_DECLARE(elt, elt_car, elt_cdr, list,   \
781                                          tail, len)                     \
782 Lisp_Object tortoise_##elt;                                             \
783 PRIVATE_EXTERNAL_ALIST_LOOP_8 (elt, elt_car, elt_cdr, list,             \
784                        len, tail, tortoise_##elt,                       \
785                        CIRCULAR_LIST_SUSPICION_LENGTH)
786
787 #define PRIVATE_EXTERNAL_ALIST_LOOP_8(elt, elt_car, elt_cdr, list, len, \
788                                       hare, tortoise, suspicion_length) \
789 PRIVATE_EXTERNAL_LIST_LOOP_6 (elt, list, len, hare, tortoise,           \
790                               suspicion_length)                         \
791   if (CONSP (elt) ? (elt_car = XCAR (elt), elt_cdr = XCDR (elt), 0) :1) \
792     continue;                                                           \
793   else
794
795 /* Macros for looping over external property lists.
796
797    *** ALL OF THESE MACROS MUST BE DECLARED INSIDE BRACES -- SEE ABOVE. ***
798
799    EXTERNAL_PROPERTY_LIST_LOOP_3 maps over an external list assumed to
800    be a property list, consisting of alternating pairs of keys
801    (typically symbols or keywords) and values.  Each iteration
802    processes one such pair out of LIST, assigning the two elements to
803    KEY and VALUE respectively.  Malformed lists and circularities are
804    trapped as usual, and in addition, property lists with an odd number
805    of elements also signal an error.
806
807    EXTERNAL_PROPERTY_LIST_LOOP_4 adds a TAIL argument to
808    EXTERNAL_PROPERTY_LIST_LOOP_3, just like EXTERNAL_LIST_LOOP_3 does,
809    and again TAIL is automatically declared.
810
811    EXTERNAL_PROPERTY_LIST_LOOP_5 adds a LEN argument to
812    EXTERNAL_PROPERTY_LIST_LOOP_4, just like EXTERNAL_LIST_LOOP_4 does,
813    and again LEN is automatically declared.  Note that in this case,
814    LEN counts the iterations, NOT the total number of list elements
815    processed, which is 2 * LEN.
816
817    EXTERNAL_PROPERTY_LIST_LOOP_5_NO_DECLARE does not declare any of its
818    arguments, just like EXTERNAL_LIST_LOOP_4_NO_DECLARE, and so these
819    must be declared manually.  */
820
821 /* Optimized and safe macros for looping over external property lists. */
822 #define EXTERNAL_PROPERTY_LIST_LOOP_3(key, value, list)                 \
823 Lisp_Object key, value, hare_##key, tortoise_##key;                     \
824 EMACS_INT len_##key;                                                    \
825 EXTERNAL_PROPERTY_LIST_LOOP_7 (key, value, list, len_##key, hare_##key, \
826                      tortoise_##key, CIRCULAR_LIST_SUSPICION_LENGTH)
827
828 #define EXTERNAL_PROPERTY_LIST_LOOP_4(key, value, list, tail)           \
829 Lisp_Object key, value, tail, tortoise_##key;                           \
830 EMACS_INT len_##key;                                                    \
831 EXTERNAL_PROPERTY_LIST_LOOP_7 (key, value, list, len_##key, tail,       \
832                      tortoise_##key, CIRCULAR_LIST_SUSPICION_LENGTH)
833
834 #define EXTERNAL_PROPERTY_LIST_LOOP_5(key, value, list, tail, len)      \
835 Lisp_Object key, value, tail, tortoise_##key;                           \
836 EMACS_INT len;                                                          \
837 EXTERNAL_PROPERTY_LIST_LOOP_7 (key, value, list, len, tail,             \
838                      tortoise_##key, CIRCULAR_LIST_SUSPICION_LENGTH)
839
840 #define EXTERNAL_PROPERTY_LIST_LOOP_5_NO_DECLARE(key, value, list,      \
841                                                  tail, len)             \
842 Lisp_Object tortoise_##key;                                             \
843 EXTERNAL_PROPERTY_LIST_LOOP_7 (key, value, list, len, tail,             \
844                      tortoise_##key, CIRCULAR_LIST_SUSPICION_LENGTH)
845
846 #define EXTERNAL_PROPERTY_LIST_LOOP_7(key, value, list, len, hare,      \
847                              tortoise, suspicion_length)                \
848   for (tortoise = hare = list, len = 0;                                 \
849                                                                         \
850        ((CONSP (hare) &&                                                \
851          (key = XCAR (hare),                                            \
852           hare = XCDR (hare),                                           \
853           (CONSP (hare) ? 1 :                                           \
854            (signal_malformed_property_list_error (list), 0)))) ?        \
855         (value = XCAR (hare), 1) :                                      \
856         (NILP (hare) ? 0 :                                              \
857          (signal_malformed_property_list_error (list), 0)));            \
858                                                                         \
859        hare = XCDR (hare),                                              \
860          ((++len < suspicion_length) ?                                  \
861           ((void) 0) :                                                  \
862           (((len & 1) ?                                                 \
863             ((void) (tortoise = XCDR (XCDR (tortoise)))) :              \
864             ((void) 0))                                                 \
865            ,                                                            \
866            (EQ (hare, tortoise) ?                                       \
867             ((void) signal_circular_property_list_error (list)) :       \
868             ((void) 0)))))
869
870 /* For a property list (alternating keywords/values) that may not be
871    in valid list format -- will signal an error if the list is not in
872    valid format.  CONSVAR is used to keep track of the iterations
873    without modifying PLIST.
874
875    We have to be tricky to still keep the same C format.*/
876 #define EXTERNAL_PROPERTY_LIST_LOOP(tail, key, value, plist)    \
877   for (tail = plist;                                            \
878        (CONSP (tail) && CONSP (XCDR (tail)) ?                   \
879         (key = XCAR (tail), value = XCAR (XCDR (tail))) :       \
880         (key = Qunbound,    value = Qunbound)),                 \
881        !NILP (tail);                                            \
882        tail = XCDR (XCDR (tail)))                               \
883     if (UNBOUNDP (key))                                         \
884       Fsignal (Qmalformed_property_list, list1 (plist));        \
885     else
886
887 #define PROPERTY_LIST_LOOP(tail, key, value, plist)     \
888   for (tail = plist;                                    \
889        NILP (tail) ? 0 :                                \
890          (key   = XCAR (tail), tail = XCDR (tail),      \
891           value = XCAR (tail), tail = XCDR (tail), 1);  \
892        )
893
894 /* Return 1 if LIST is properly acyclic and nil-terminated, else 0. */
895 extern_inline int TRUE_LIST_P(Lisp_Object object);
896 extern_inline int TRUE_LIST_P(Lisp_Object object)
897 {
898         Lisp_Object hare, tortoise;
899         EMACS_INT len;
900
901         for (hare = tortoise = object, len = 0;
902              CONSP(hare); hare = XCDR(hare), len++) {
903                 if (len < CIRCULAR_LIST_SUSPICION_LENGTH)
904                         continue;
905
906                 if (len & 1)
907                         tortoise = XCDR(tortoise);
908                 else if (EQ(hare, tortoise))
909                         return 0;
910         }
911
912         return NILP(hare);
913 }
914
915 /* Signal an error if LIST is not properly acyclic and nil-terminated. */
916 #define CHECK_TRUE_LIST(list) do {                      \
917   Lisp_Object CTL_list = (list);                        \
918   Lisp_Object CTL_hare, CTL_tortoise;                   \
919   EMACS_INT CTL_len;                                    \
920                                                         \
921   for (CTL_hare = CTL_tortoise = CTL_list, CTL_len = 0; \
922        CONSP (CTL_hare);                                \
923        CTL_hare = XCDR (CTL_hare), CTL_len++)           \
924     {                                                   \
925       if (CTL_len < CIRCULAR_LIST_SUSPICION_LENGTH)     \
926         continue;                                       \
927                                                         \
928       if (CTL_len & 1)                                  \
929         CTL_tortoise = XCDR (CTL_tortoise);             \
930       else if (EQ (CTL_hare, CTL_tortoise))             \
931         Fsignal (Qcircular_list, list1 (CTL_list));     \
932     }                                                   \
933                                                         \
934   if (! NILP (CTL_hare))                                \
935     signal_malformed_list_error (CTL_list);             \
936 } while (0)
937
938 /*------------------------------ string --------------------------------*/
939
940 struct Lisp_String {
941         struct lrecord_header lheader;
942         Bytecount size;
943         Bufbyte *data;
944 #ifdef EF_USE_COMPRE
945         Lisp_Object compre;
946 #endif
947         Lisp_Object plist;
948 };
949 typedef struct Lisp_String Lisp_String;
950
951 DECLARE_LRECORD(string, Lisp_String);
952 #define XSTRING(x) XRECORD (x, string, Lisp_String)
953 #define XSETSTRING(x, p) XSETRECORD (x, p, string)
954 #define STRINGP(x) RECORDP (x, string)
955 #define CHECK_STRING(x) CHECK_RECORD (x, string)
956 #define CONCHECK_STRING(x) CONCHECK_RECORD (x, string)
957
958 #ifdef MULE
959
960 Charcount bytecount_to_charcount(const Bufbyte * ptr, Bytecount len);
961 Bytecount charcount_to_bytecount(const Bufbyte * ptr, Charcount len);
962
963 #else                           /* not MULE */
964
965 # define bytecount_to_charcount(ptr, len) (len)
966 # define charcount_to_bytecount(ptr, len) (len)
967
968 #endif                          /* not MULE */
969
970 #define string_length(s) ((s)->size)
971 #define XSTRING_LENGTH(s) string_length (XSTRING (s))
972 #define XSTRING_CHAR_LENGTH(s) string_char_length (XSTRING (s))
973 #define string_data(s) ((s)->data + 0)
974 #define XSTRING_DATA(s) string_data (XSTRING (s))
975 #define string_byte(s, i) ((s)->data[i] + 0)
976 #define XSTRING_BYTE(s, i) string_byte (XSTRING (s), i)
977 #define string_byte_addr(s, i) (&((s)->data[i]))
978 #define set_string_length(s, len) ((void) ((s)->size = (len)))
979 #define set_string_data(s, ptr) ((void) ((s)->data = (ptr)))
980 #define set_string_byte(s, i, b) ((void) ((s)->data[i] = (b)))
981
982 void resize_string(Lisp_String * s, Bytecount pos, Bytecount delta);
983
984 #ifdef MULE
985
986 extern_inline Charcount string_char_length(const Lisp_String *s);
987 extern_inline Charcount string_char_length(const Lisp_String *s)
988 {
989         return bytecount_to_charcount(string_data(s), string_length(s));
990 }
991
992 # define string_char(s, i) charptr_emchar_n (string_data (s), i)
993 # define string_char_addr(s, i) charptr_n_addr (string_data (s), i)
994 void set_string_char(Lisp_String * s, Charcount i, Emchar c);
995
996 #else                           /* not MULE */
997
998 # define string_char_length(s) string_length (s)
999 # define string_char(s, i) ((Emchar) string_byte (s, i))
1000 # define string_char_addr(s, i) string_byte_addr (s, i)
1001 # define set_string_char(s, i, c) set_string_byte (s, i, (Bufbyte)c)
1002
1003 #endif                          /* not MULE */
1004
1005 /* Return the true aligned size of a struct whose last member is a
1006    variable-length array field.  (this is known as the "struct hack") */
1007 /* Implementation: in practice, structtype and fieldtype usually have
1008    the same alignment, but we can't be sure.  We need to use
1009    ALIGN_SIZE to be absolutely sure of getting the correct alignment.
1010    To help the compiler's optimizer, we use a ternary expression that
1011    only a very stupid compiler would fail to correctly simplify. */
1012 #define FLEXIBLE_ARRAY_STRUCT_SIZEOF(structtype,        \
1013                                      fieldtype,         \
1014                                      fieldname,         \
1015                                      array_length)      \
1016 (ALIGNOF (structtype) == ALIGNOF (fieldtype)            \
1017  ? (offsetof (structtype, fieldname) +                  \
1018     (offsetof (structtype, fieldname[1]) -              \
1019      offsetof (structtype, fieldname[0])) *             \
1020     (array_length))                                     \
1021  : (ALIGN_SIZE                                          \
1022     ((offsetof (structtype, fieldname) +                \
1023       (offsetof (structtype, fieldname[1]) -            \
1024        offsetof (structtype, fieldname[0])) *           \
1025       (array_length)),                                  \
1026      ALIGNOF (structtype))))
1027
1028 /*------------------------------ vector --------------------------------*/
1029
1030 struct Lisp_Vector {
1031         struct lcrecord_header header;
1032         /* the sequence category */
1033         void *si;
1034         /* this vector's length */
1035         long int size;
1036         /* next is now chained through v->contents[size], terminated by Qzero.
1037            This means that pure vectors don't need a "next" */
1038         /* struct Lisp_Vector *next; */
1039         Lisp_Object contents[1];
1040 };
1041 typedef struct Lisp_Vector Lisp_Vector;
1042
1043 DECLARE_LRECORD(vector, Lisp_Vector);
1044 #define XVECTOR(x) XRECORD (x, vector, Lisp_Vector)
1045 #define XSETVECTOR(x, p) XSETRECORD (x, p, vector)
1046 #define VECTORP(x) RECORDP (x, vector)
1047 #define CHECK_VECTOR(x) CHECK_RECORD (x, vector)
1048 #define CONCHECK_VECTOR(x) CONCHECK_RECORD (x, vector)
1049
1050 #define vector_length(v) ((v)->size)
1051 #define XVECTOR_LENGTH(s) vector_length (XVECTOR (s))
1052 #define vector_data(v) ((v)->contents)
1053 #define XVECTOR_DATA(s) vector_data (XVECTOR (s))
1054
1055 /*---------------------------- bit vectors -----------------------------*/
1056
1057 #if (SXE_LONGBITS < 16)
1058 #error What the hell?!
1059 #elif (SXE_LONGBITS < 32)
1060 # define LONGBITS_LOG2 4
1061 # define LONGBITS_POWER_OF_2 16
1062 #elif (SXE_LONGBITS < 64)
1063 # define LONGBITS_LOG2 5
1064 # define LONGBITS_POWER_OF_2 32
1065 #elif (SXE_LONGBITS < 128)
1066 # define LONGBITS_LOG2 6
1067 # define LONGBITS_POWER_OF_2 64
1068 #else
1069 #error You really have 128-bit integers?!
1070 #endif
1071
1072 struct Lisp_Bit_Vector {
1073         struct lrecord_header lheader;
1074
1075         /* category subsystem */
1076         void *si;
1077
1078         Lisp_Object next;
1079         EMACS_INT size;
1080         unsigned long bits[1];
1081 };
1082 typedef struct Lisp_Bit_Vector Lisp_Bit_Vector;
1083
1084 DECLARE_LRECORD(bit_vector, Lisp_Bit_Vector);
1085 #define XBIT_VECTOR(x) XRECORD (x, bit_vector, Lisp_Bit_Vector)
1086 #define XSETBIT_VECTOR(x, p) XSETRECORD (x, p, bit_vector)
1087 #define BIT_VECTORP(x) RECORDP (x, bit_vector)
1088 #define CHECK_BIT_VECTOR(x) CHECK_RECORD (x, bit_vector)
1089 #define CONCHECK_BIT_VECTOR(x) CONCHECK_RECORD (x, bit_vector)
1090
1091 #define BITP(x) (INTP (x) && (XINT (x) == 0 || XINT (x) == 1))
1092
1093 #define CHECK_BIT(x) do {               \
1094   if (!BITP (x))                        \
1095     dead_wrong_type_argument (Qbitp, x);\
1096 } while (0)
1097
1098 #define CONCHECK_BIT(x) do {            \
1099   if (!BITP (x))                        \
1100     x = wrong_type_argument (Qbitp, x); \
1101 } while (0)
1102
1103 #define bit_vector_length(v) ((v)->size)
1104 #define bit_vector_next(v) ((v)->next)
1105
1106 extern_inline int bit_vector_bit(const Lisp_Bit_Vector *v, size_t n);
1107 extern_inline int bit_vector_bit(const Lisp_Bit_Vector *v, size_t n)
1108 {
1109         return ((v->bits[n >> LONGBITS_LOG2] >> (n & (LONGBITS_POWER_OF_2 - 1)))
1110                 & 1);
1111 }
1112
1113 extern_inline void set_bit_vector_bit(Lisp_Bit_Vector *v, size_t n, int value);
1114 extern_inline void set_bit_vector_bit(Lisp_Bit_Vector *v, size_t n, int value)
1115 {
1116         if (value)
1117                 v->bits[n >> LONGBITS_LOG2] |=
1118                     (1UL << (n & (LONGBITS_POWER_OF_2 - 1)));
1119         else
1120                 v->bits[n >> LONGBITS_LOG2] &=
1121                     ~(1UL << (n & (LONGBITS_POWER_OF_2 - 1)));
1122 }
1123
1124 /* Number of longs required to hold LEN bits */
1125 #define BIT_VECTOR_LONG_STORAGE(len) \
1126   (((len) + LONGBITS_POWER_OF_2 - 1) >> LONGBITS_LOG2)
1127
1128 /*------------------------------ symbol --------------------------------*/
1129
1130 typedef struct Lisp_Symbol Lisp_Symbol;
1131 struct Lisp_Symbol {
1132         struct lrecord_header lheader;
1133         /* next symbol in this obarray bucket */
1134         Lisp_Symbol *next;
1135         Lisp_String *name;
1136         Lisp_Object value;
1137         Lisp_Object function;
1138         Lisp_Object plist;
1139 };
1140
1141 #define SYMBOL_IS_KEYWORD(sym)                                          \
1142   ((string_byte (symbol_name (XSYMBOL (sym)), 0) == ':')                \
1143    && EQ (sym, oblookup (Vobarray,                                      \
1144                          string_data (symbol_name (XSYMBOL (sym))),     \
1145                          string_length (symbol_name (XSYMBOL (sym))))))
1146 #define KEYWORDP(obj) (SYMBOLP (obj) && SYMBOL_IS_KEYWORD (obj))
1147
1148 DECLARE_LRECORD(symbol, Lisp_Symbol);
1149 #define XSYMBOL(x) XRECORD (x, symbol, Lisp_Symbol)
1150 #define XSETSYMBOL(x, p) XSETRECORD (x, p, symbol)
1151 #define SYMBOLP(x) RECORDP (x, symbol)
1152 #define CHECK_SYMBOL(x) CHECK_RECORD (x, symbol)
1153 #define CONCHECK_SYMBOL(x) CONCHECK_RECORD (x, symbol)
1154
1155 #define symbol_next(s) ((s)->next)
1156 #define symbol_name(s) ((s)->name)
1157 #define symbol_value(s) ((s)->value)
1158 #define symbol_function(s) ((s)->function)
1159 #define symbol_plist(s) ((s)->plist)
1160
1161 /*------------------------------- subr ---------------------------------*/
1162
1163 typedef Lisp_Object(*lisp_fn_t) (void);
1164
1165 struct Lisp_Subr {
1166         struct lrecord_header lheader;
1167         short min_args;
1168         short max_args;
1169         const char *prompt;
1170         const char *doc;
1171         const char *name;
1172         lisp_fn_t subr_fn;
1173 };
1174 typedef struct Lisp_Subr Lisp_Subr;
1175
1176 DECLARE_LRECORD(subr, Lisp_Subr);
1177 #define XSUBR(x) XRECORD (x, subr, Lisp_Subr)
1178 #define XSETSUBR(x, p) XSETRECORD (x, p, subr)
1179 #define SUBRP(x) RECORDP (x, subr)
1180 #define CHECK_SUBR(x) CHECK_RECORD (x, subr)
1181 #define CONCHECK_SUBR(x) CONCHECK_RECORD (x, subr)
1182
1183 #define subr_function(subr) ((subr)->subr_fn)
1184 #define SUBR_FUNCTION(subr,max_args) \
1185   ((Lisp_Object (*) (EXFUN_##max_args)) (subr)->subr_fn)
1186 #define subr_name(subr) ((subr)->name)
1187
1188 /*------------------------------ marker --------------------------------*/
1189
1190 typedef struct Lisp_Marker Lisp_Marker;
1191 struct Lisp_Marker {
1192         struct lrecord_header lheader;
1193         Lisp_Marker *next;
1194         Lisp_Marker *prev;
1195         struct buffer *buffer;
1196         Memind memind;
1197         char insertion_type;
1198 };
1199
1200 DECLARE_LRECORD(marker, Lisp_Marker);
1201 #define XMARKER(x) XRECORD (x, marker, Lisp_Marker)
1202 #define XSETMARKER(x, p) XSETRECORD (x, p, marker)
1203 #define MARKERP(x) RECORDP (x, marker)
1204 #define CHECK_MARKER(x) CHECK_RECORD (x, marker)
1205 #define CONCHECK_MARKER(x) CONCHECK_RECORD (x, marker)
1206
1207 /* The second check was looking for GCed markers still in use */
1208 /* if (INTP (XMARKER (x)->lheader.next.v)) abort (); */
1209
1210 #define marker_next(m) ((m)->next)
1211 #define marker_prev(m) ((m)->prev)
1212
1213 /*------------------------------- char ---------------------------------*/
1214
1215 #define CHARP(x) (XTYPE (x) == Lisp_Type_Char)
1216
1217 #ifdef ERROR_CHECK_TYPECHECK
1218
1219 extern_inline Emchar XCHAR(Lisp_Object obj);
1220 extern_inline Emchar XCHAR(Lisp_Object obj)
1221 {
1222         assert(CHARP(obj));
1223         return XCHARVAL(obj);
1224 }
1225
1226 #else
1227
1228 #define XCHAR(x) ((Emchar)XCHARVAL (x))
1229
1230 #endif
1231
1232 #define CHECK_CHAR(x) CHECK_NONRECORD (x, Lisp_Type_Char, Qcharacterp)
1233 #define CONCHECK_CHAR(x) CONCHECK_NONRECORD (x, Lisp_Type_Char, Qcharacterp)
1234
1235 /*------------------------------ float ---------------------------------*/
1236
1237 /* moved to ent-float.h */
1238
1239 /*-------------------------------- int ---------------------------------*/
1240
1241 #define ZEROP(x) EQ (x, Qzero)
1242
1243 #ifdef ERROR_CHECK_TYPECHECK
1244
1245 extern_inline EMACS_INT XINT(Lisp_Object obj);
1246 extern_inline EMACS_INT XINT(Lisp_Object obj)
1247 {
1248         assert(INTP(obj));
1249         return XREALINT(obj);
1250 }
1251
1252 extern_inline EMACS_INT XCHAR_OR_INT(Lisp_Object obj);
1253 extern_inline EMACS_INT XCHAR_OR_INT(Lisp_Object obj)
1254 {
1255         assert(INTP(obj) || CHARP(obj));
1256         return CHARP(obj) ? XCHAR(obj) : XINT(obj);
1257 }
1258
1259 #else                           /* no error checking */
1260
1261 #define XINT(obj) XREALINT (obj)
1262 #define XCHAR_OR_INT(obj) (CHARP (obj) ? XCHAR (obj) : XINT (obj))
1263
1264 #endif                          /* no error checking */
1265
1266 #define CHECK_INT(x) do {                       \
1267   if (!INTP (x))                                \
1268     dead_wrong_type_argument (Qintegerp, x);    \
1269 } while (0)
1270
1271 #define CONCHECK_INT(x) do {                    \
1272   if (!INTP (x))                                \
1273     x = wrong_type_argument (Qintegerp, x);     \
1274 } while (0)
1275
1276 #define NATNUMP(x) (INTP (x) && XINT (x) >= 0)
1277
1278 #define CHECK_NATNUM(x) do {                    \
1279   if (!NATNUMP (x))                             \
1280     dead_wrong_type_argument (Qnatnump, x);     \
1281 } while (0)
1282
1283 #define CONCHECK_NATNUM(x) do {                 \
1284   if (!NATNUMP (x))                             \
1285     x = wrong_type_argument (Qnatnump, x);      \
1286 } while (0)
1287
1288 /* next three always continuable because they coerce their arguments. */
1289 #define CHECK_INT_COERCE_CHAR(x) do {                   \
1290   if (INTP (x))                                         \
1291     ;                                                   \
1292   else if (CHARP (x))                                   \
1293     x = make_int (XCHAR (x));                           \
1294   else                                                  \
1295     x = wrong_type_argument (Qinteger_or_char_p, x);    \
1296 } while (0)
1297
1298 #define CHECK_INT_COERCE_MARKER(x) do {                 \
1299   if (INTP (x))                                         \
1300     ;                                                   \
1301   else if (MARKERP (x))                                 \
1302     x = make_int (marker_position (x));                 \
1303   else                                                  \
1304     x = wrong_type_argument (Qinteger_or_marker_p, x);  \
1305 } while (0)
1306
1307 #define CHECK_INT_COERCE_CHAR_OR_MARKER(x) do {                 \
1308   if (INTP (x))                                                 \
1309     ;                                                           \
1310   else if (CHARP (x))                                           \
1311     x = make_int (XCHAR (x));                                   \
1312   else if (MARKERP (x))                                         \
1313     x = make_int (marker_position (x));                         \
1314   else                                                          \
1315     x = wrong_type_argument (Qinteger_char_or_marker_p, x);     \
1316 } while (0)
1317
1318 /* basic integer definitions, used quite a lot */
1319 #include "ent/ent-int.h"
1320
1321 /*--------------------------- readonly objects -------------------------*/
1322
1323 #define CHECK_C_WRITEABLE(obj)                                  \
1324   do { if (c_readonly (obj)) c_write_error (obj); } while (0)
1325
1326 #define CHECK_LISP_WRITEABLE(obj)                                       \
1327   do { if (lisp_readonly (obj)) lisp_write_error (obj); } while (0)
1328
1329 #define C_READONLY(obj) (C_READONLY_RECORD_HEADER_P(XRECORD_LHEADER (obj)))
1330 #define LISP_READONLY(obj) (LISP_READONLY_RECORD_HEADER_P(XRECORD_LHEADER (obj)))
1331
1332 /*----------------------------- structures -----------------------------*/
1333
1334 typedef struct structure_keyword_entry structure_keyword_entry;
1335 struct structure_keyword_entry {
1336         Lisp_Object keyword;
1337         int (*validate) (Lisp_Object keyword, Lisp_Object value,
1338                          Error_behavior errb);
1339 };
1340
1341 typedef struct {
1342         Dynarr_declare(structure_keyword_entry);
1343 } structure_keyword_entry_dynarr;
1344
1345 typedef struct structure_type structure_type;
1346 struct structure_type {
1347         Lisp_Object type;
1348         structure_keyword_entry_dynarr *keywords;
1349         int (*validate) (Lisp_Object data, Error_behavior errb);
1350          Lisp_Object(*instantiate) (Lisp_Object data);
1351 };
1352
1353 typedef struct {
1354         Dynarr_declare(structure_type);
1355 } structure_type_dynarr;
1356
1357 struct structure_type *define_structure_type(Lisp_Object type, int (*validate)
1358                                               (Lisp_Object data,
1359                                                Error_behavior errb),
1360                                              Lisp_Object(*instantiate)
1361                                               (Lisp_Object data));
1362 void define_structure_type_keyword(struct structure_type *st,
1363                                    Lisp_Object keyword,
1364                                    int (*validate) (Lisp_Object keyword,
1365                                                     Lisp_Object value,
1366                                                     Error_behavior errb));
1367
1368 /*---------------------------- weak lists ------------------------------*/
1369
1370 enum weak_list_type {
1371         /* element disappears if it's unmarked. */
1372         WEAK_LIST_SIMPLE,
1373         /* element disappears if it's a cons and either its car or
1374            cdr is unmarked. */
1375         WEAK_LIST_ASSOC,
1376         /* element disappears if it's a cons and its car is unmarked. */
1377         WEAK_LIST_KEY_ASSOC,
1378         /* element disappears if it's a cons and its cdr is unmarked. */
1379         WEAK_LIST_VALUE_ASSOC,
1380         /* element disappears if it's a cons and neither its car nor
1381            its cdr is marked. */
1382         WEAK_LIST_FULL_ASSOC
1383 };
1384
1385 struct weak_list {
1386         struct lcrecord_header header;
1387         Lisp_Object list;       /* don't mark through this! */
1388         enum weak_list_type type;
1389         Lisp_Object next_weak;  /* don't mark through this! */
1390 };
1391
1392 DECLARE_LRECORD(weak_list, struct weak_list);
1393 #define XWEAK_LIST(x) XRECORD (x, weak_list, struct weak_list)
1394 #define XSETWEAK_LIST(x, p) XSETRECORD (x, p, weak_list)
1395 #define WEAK_LISTP(x) RECORDP (x, weak_list)
1396 #define CHECK_WEAK_LIST(x) CHECK_RECORD (x, weak_list)
1397 #define CONCHECK_WEAK_LIST(x) CONCHECK_RECORD (x, weak_list)
1398
1399 #define weak_list_list(w) ((w)->list)
1400 #define XWEAK_LIST_LIST(w) (XWEAK_LIST (w)->list)
1401
1402 Lisp_Object make_weak_list(enum weak_list_type type);
1403 /* The following two are only called by the garbage collector */
1404 int finish_marking_weak_lists(void);
1405 void prune_weak_lists(void);
1406
1407 /*-------------------------- lcrecord-list -----------------------------*/
1408
1409 struct lcrecord_list {
1410         struct lcrecord_header header;
1411         Lisp_Object free;
1412         size_t size;
1413         const struct lrecord_implementation *implementation;
1414 };
1415
1416 DECLARE_LRECORD(lcrecord_list, struct lcrecord_list);
1417 #define XLCRECORD_LIST(x) XRECORD (x, lcrecord_list, struct lcrecord_list)
1418 #define XSETLCRECORD_LIST(x, p) XSETRECORD (x, p, lcrecord_list)
1419 #define LCRECORD_LISTP(x) RECORDP (x, lcrecord_list)
1420 /* #define CHECK_LCRECORD_LIST(x) CHECK_RECORD (x, lcrecord_list)
1421    Lcrecord lists should never escape to the Lisp level, so
1422    functions should not be doing this. */
1423
1424 Lisp_Object make_lcrecord_list(size_t size, const struct lrecord_implementation
1425                                *implementation);
1426 Lisp_Object allocate_managed_lcrecord(Lisp_Object lcrecord_list);
1427 void free_managed_lcrecord(Lisp_Object lcrecord_list, Lisp_Object lcrecord);
1428 \f
1429 /************************************************************************/
1430 /*         Definitions of primitive Lisp functions and variables        */
1431 /************************************************************************/
1432
1433 /* DEFUN - Define a built-in Lisp-visible C function or `subr'.
1434  `lname' should be the name to give the function in Lisp,
1435     as a null-terminated C string.
1436  `Fname' should be the C equivalent of `lname', using only characters
1437     valid in a C identifier, with an "F" prepended.
1438     The name of the C constant structure that records information
1439     on this function for internal use is "S" concatenated with Fname.
1440  `min_args' should be a number, the minimum number of arguments allowed.
1441  `max_args' should be a number, the maximum number of arguments allowed,
1442     or else MANY or UNEVALLED.
1443     MANY means pass a vector of evaluated arguments,
1444          in the form of an integer number-of-arguments
1445          followed by the address of a vector of Lisp_Objects
1446          which contains the argument values.
1447     UNEVALLED means pass the list of unevaluated arguments.
1448  `prompt' says how to read arguments for an interactive call.
1449     See the doc string for `interactive'.
1450     A null string means call interactively with no arguments.
1451  `arglist' are the comma-separated arguments (always Lisp_Objects) for
1452     the function.
1453   The docstring for the function is placed as a "C" comment between
1454     the prompt and the `args' argument.  make-docfile reads the
1455     comment and creates the DOC file from it.
1456 */
1457
1458 #define EXFUN_0 void
1459 #define EXFUN_1 Lisp_Object
1460 #define EXFUN_2 Lisp_Object,Lisp_Object
1461 #define EXFUN_3 Lisp_Object,Lisp_Object,Lisp_Object
1462 #define EXFUN_4 Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object
1463 #define EXFUN_5 Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object
1464 #define EXFUN_6 Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object, \
1465 Lisp_Object
1466 #define EXFUN_7 Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object, \
1467 Lisp_Object,Lisp_Object
1468 #define EXFUN_8 Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object,Lisp_Object, \
1469 Lisp_Object,Lisp_Object,Lisp_Object
1470 #define EXFUN_MANY int, Lisp_Object*
1471 #define EXFUN_UNEVALLED Lisp_Object
1472 #define EXFUN(sym, max_args) Lisp_Object sym (EXFUN_##max_args)
1473
1474 #define SUBR_MAX_ARGS 8
1475 #define MANY -2
1476 #define UNEVALLED -1
1477
1478 /* Can't be const, because then subr->doc is read-only and
1479    Snarf_documentation chokes */
1480
1481 #define DEFUN(lname, Fname, min_args, max_args, prompt, arglist)        \
1482   Lisp_Object Fname (EXFUN_##max_args);                                 \
1483   static struct Lisp_Subr S##Fname =                                    \
1484   {                                                                     \
1485     { /* struct lrecord_header */                                       \
1486       lrecord_type_subr, /* lrecord_type_index */                       \
1487       1, /* mark bit */                                                 \
1488       1, /* c_readonly bit */                                           \
1489       1  /* lisp_readonly bit */                                        \
1490     },                                                                  \
1491     min_args,                                                           \
1492     max_args,                                                           \
1493     prompt,                                                             \
1494     0,  /* doc string */                                                \
1495     lname,                                                              \
1496     (lisp_fn_t) Fname                                                   \
1497   };                                                                    \
1498   Lisp_Object Fname (DEFUN_##max_args arglist)
1499
1500 /* Heavy ANSI C preprocessor hackery to get DEFUN to declare a
1501    prototype that matches max_args, and add the obligatory
1502    `Lisp_Object' type declaration to the formal C arguments.  */
1503
1504 #define DEFUN_MANY(named_int, named_Lisp_Object) named_int, named_Lisp_Object
1505 #define DEFUN_UNEVALLED(args) Lisp_Object args
1506 #define DEFUN_0() void
1507 #define DEFUN_1(a)                                      Lisp_Object a
1508 #define DEFUN_2(a,b)             DEFUN_1(a),            Lisp_Object b
1509 #define DEFUN_3(a,b,c)           DEFUN_2(a,b),          Lisp_Object c
1510 #define DEFUN_4(a,b,c,d)         DEFUN_3(a,b,c),        Lisp_Object d
1511 #define DEFUN_5(a,b,c,d,e)       DEFUN_4(a,b,c,d),      Lisp_Object e
1512 #define DEFUN_6(a,b,c,d,e,f)     DEFUN_5(a,b,c,d,e),    Lisp_Object f
1513 #define DEFUN_7(a,b,c,d,e,f,g)   DEFUN_6(a,b,c,d,e,f),  Lisp_Object g
1514 #define DEFUN_8(a,b,c,d,e,f,g,h) DEFUN_7(a,b,c,d,e,f,g),Lisp_Object h
1515
1516 /* WARNING: If you add defines here for higher values of max_args,
1517    make sure to also fix the clauses in PRIMITIVE_FUNCALL(),
1518    and change the define of SUBR_MAX_ARGS above.  */
1519
1520 #include "symeval.h"
1521
1522 /* `specpdl' is the special binding/unwind-protect stack.
1523
1524    Knuth says (see the Jargon File):
1525    At MIT, `pdl' [abbreviation for `Push Down List'] used to
1526    be a more common synonym for `stack'.
1527    Everywhere else `stack' seems to be the preferred term.
1528
1529    specpdl_depth is the current depth of `specpdl'.
1530    Save this for use later as arg to `unbind_to'.  */
1531 extern int specpdl_depth_counter;
1532 #define specpdl_depth() specpdl_depth_counter
1533
1534 #define CHECK_FUNCTION(fun) do {                \
1535  while (NILP (Ffunctionp (fun)))                \
1536    signal_invalid_function_error (fun);         \
1537  } while (0)
1538 \f
1539 /************************************************************************/
1540 /*                         Checking for QUIT                            */
1541 /************************************************************************/
1542
1543 /* Asynchronous events set something_happened, and then are processed
1544    within the QUIT macro.  At this point, we are guaranteed to not be in
1545    any sensitive code. */
1546
1547 extern volatile int something_happened;
1548 int check_what_happened(void);
1549
1550 extern volatile int quit_check_signal_happened;
1551 extern volatile int quit_check_signal_tick_count;
1552 int check_quit(void);
1553
1554 void signal_quit(void);
1555
1556 /* Nonzero if ought to quit now.  */
1557 #define QUITP                                                   \
1558   ((quit_check_signal_happened ? check_quit () : 0),            \
1559    (!NILP (Vquit_flag) && (NILP (Vinhibit_quit)                 \
1560                            || EQ (Vquit_flag, Qcritical))))
1561
1562 /* QUIT used to call QUITP, but there are some places where QUITP
1563    is called directly, and check_what_happened() should only be called
1564    when Emacs is actually ready to quit because it could do things
1565    like switch threads. */
1566 #define INTERNAL_QUITP                                          \
1567   ((something_happened ? check_what_happened () : 0),           \
1568    (!NILP (Vquit_flag) &&                                       \
1569     (NILP (Vinhibit_quit) || EQ (Vquit_flag, Qcritical))))
1570
1571 #define INTERNAL_REALLY_QUITP                                   \
1572   (check_what_happened (),                                      \
1573    (!NILP (Vquit_flag) &&                                       \
1574     (NILP (Vinhibit_quit) || EQ (Vquit_flag, Qcritical))))
1575
1576 /* Check quit-flag and quit if it is non-nil.  Also do any other things
1577    that might have gotten queued until it was safe. */
1578 #define QUIT do { if (INTERNAL_QUITP) signal_quit (); } while (0)
1579
1580 #define REALLY_QUIT do { if (INTERNAL_REALLY_QUITP) signal_quit (); } while (0)
1581 \f
1582 /************************************************************************/
1583 /*                               hashing                                */
1584 /************************************************************************/
1585 typedef long unsigned int hcode_t;
1586
1587 /* #### for a 64-bit machine, we should substitute a prime just over 2^32 */
1588 #define GOOD_HASH 65599         /* prime number just over 2^16; Dragon book, p. 435 */
1589 #define HASH2(a,b)               (GOOD_HASH * (a)                     + (b))
1590 #define HASH3(a,b,c)             (GOOD_HASH * HASH2 (a,b)             + (c))
1591 #define HASH4(a,b,c,d)           (GOOD_HASH * HASH3 (a,b,c)           + (d))
1592 #define HASH5(a,b,c,d,e)         (GOOD_HASH * HASH4 (a,b,c,d)         + (e))
1593 #define HASH6(a,b,c,d,e,f)       (GOOD_HASH * HASH5 (a,b,c,d,e)       + (f))
1594 #define HASH7(a,b,c,d,e,f,g)     (GOOD_HASH * HASH6 (a,b,c,d,e,f)     + (g))
1595 #define HASH8(a,b,c,d,e,f,g,h)   (GOOD_HASH * HASH7 (a,b,c,d,e,f,g)   + (h))
1596 #define HASH9(a,b,c,d,e,f,g,h,i) (GOOD_HASH * HASH8 (a,b,c,d,e,f,g,h) + (i))
1597
1598 #define LISP_HASH(obj) ((hcode_t)LISP_TO_VOID(obj))
1599 hcode_t string_hash(const char *xv);
1600 hcode_t memory_hash(const void *xv, size_t size);
1601 hcode_t internal_hash(const Lisp_Object obj, int depth);
1602 hcode_t internal_array_hash(const Lisp_Object *arr, size_t size, int depth);
1603 \f
1604 /************************************************************************/
1605 /*                       String translation                             */
1606 /************************************************************************/
1607
1608 #ifdef I18N3
1609 #ifdef HAVE_LIBINTL_H
1610 #include <libintl.h>
1611 #else
1612 char *dgettext(const char *, const char *);
1613 char *gettext(const char *);
1614 char *textdomain(const char *);
1615 char *bindtextdomain(const char *, const char *);
1616 #endif                          /* HAVE_LIBINTL_H */
1617
1618 #define GETTEXT(x)  gettext(x)
1619 #define LISP_GETTEXT(x)  Fgettext (x)
1620 #else                           /* !I18N3 */
1621 #define GETTEXT(x)  (x)
1622 #define LISP_GETTEXT(x)  (x)
1623 #endif                          /* !I18N3 */
1624
1625 /* DEFER_GETTEXT is used to identify strings which are translated when
1626    they are referenced instead of when they are defined.
1627    These include Qerror_messages and initialized arrays of strings.
1628 */
1629 #define DEFER_GETTEXT(x) (x)
1630 \f
1631 /************************************************************************/
1632 /*                   Garbage collection / GC-protection                 */
1633 /************************************************************************/
1634
1635 #include "dllist.h"
1636 #if (defined EF_USE_POM || defined EF_USE_ASYNEQ) &&    \
1637         !(defined HAVE_BDWGC && defined EF_USE_BDWGC)
1638 #include "semaphore.h"
1639 extern sxe_mutex_t cons_mutex;
1640
1641 extern_inline void
1642 lock_allocator(void)
1643         __attribute__((always_inline));
1644 extern_inline void
1645 lock_allocator(void)
1646 {
1647         SXE_DEBUG_GC_PT("locking cons mutex.\n");
1648         SXE_MUTEX_LOCK(&cons_mutex);
1649 }
1650
1651 extern_inline void
1652 unlock_allocator(void)
1653         __attribute__((always_inline));
1654 extern_inline void
1655 unlock_allocator(void)
1656 {
1657         SXE_DEBUG_GC_PT("unlocking cons mutex.\n");
1658         SXE_MUTEX_UNLOCK(&cons_mutex);
1659 }
1660
1661 #else  /* !EF_USE_POM || !BDWGC */
1662
1663 extern_inline void
1664 lock_allocator(void)
1665         __attribute__((always_inline));
1666 extern_inline void
1667 lock_allocator(void)
1668 {
1669 }
1670
1671 extern_inline void
1672 unlock_allocator(void)
1673         __attribute__((always_inline));
1674 extern_inline void
1675 unlock_allocator(void)
1676 {
1677 }
1678 #endif
1679
1680 /* number of bytes of structure consed since last GC */
1681
1682 extern EMACS_INT consing_since_gc;
1683
1684 /* threshold for doing another gc */
1685
1686 extern Fixnum gc_cons_threshold;
1687
1688 /* Structure for recording stack slots that need marking */
1689
1690 /* This is a chain of structures, each of which points at a Lisp_Object
1691    variable whose value should be marked in garbage collection.
1692    Normally every link of the chain is an automatic variable of a function,
1693    and its `val' points to some argument or local variable of the function.
1694    On exit to the function, the chain is set back to the value it had on
1695    entry.  This way, no link remains in the chain when the stack frame
1696    containing the link disappears.
1697
1698    Every function that can call Feval must protect in this fashion all
1699    Lisp_Object variables whose contents will be used again. */
1700
1701 extern struct gcpro *gcprolist;
1702
1703 struct gcpro {
1704         struct gcpro *next;
1705         Lisp_Object *var;       /* Address of first protected variable */
1706         int nvars;              /* Number of consecutive protected variables */
1707 };
1708
1709 #if defined(EF_USE_ASYNEQ)
1710 #include "events/workers.h"
1711
1712 extern void init_threads(int, sxe_thread_f);
1713 extern void fini_threads(int);
1714 extern dllist_t workers;
1715
1716 extern_inline struct gcpro *_get_gcprolist(void);
1717 extern_inline void _set_gcprolist(struct gcpro *provar);
1718
1719 #if defined HAVE_BDWGC && defined EF_USE_BDWGC
1720 extern_inline struct gcpro*
1721 _get_gcprolist(void)
1722 {
1723         return NULL;
1724 }
1725
1726 extern_inline void
1727 _set_gcprolist(struct gcpro *provar)
1728 {
1729         return;
1730 }
1731
1732 #else  /* !BDWGC */
1733
1734 extern_inline struct gcpro*
1735 _get_gcprolist(void)
1736 {
1737         WITH_DLLIST_TRAVERSE(
1738                 workers,
1739                 eq_worker_t eqw = dllist_item;
1740                 sxe_thread_t me = pthread_self();
1741                 if (eq_worker_thread(eqw) == me) {
1742                         RETURN_FROM_DLLIST_TRAVERSE(
1743                                 workers, eq_worker_gcprolist(eqw));
1744                 });
1745         return NULL;
1746 }
1747
1748 extern_inline void
1749 _set_gcprolist(struct gcpro *provar)
1750 {
1751         WITH_DLLIST_TRAVERSE(
1752                 workers,
1753                 eq_worker_t eqw = dllist_item;
1754                 sxe_thread_t me = pthread_self();
1755                 if (eq_worker_thread(eqw) == me) {
1756                         eq_worker_gcprolist(eqw) = provar;
1757                         RETURN_FROM_DLLIST_TRAVERSE(workers, );
1758                 });
1759         return;
1760 }
1761 #endif  /* BDWGC */
1762
1763 #else  /* !EF_USE_ASYNEQ */
1764
1765 #define _get_gcprolist()        gcprolist
1766 #define _set_gcprolist(_var)    gcprolist = (_var)
1767
1768 #endif  /* EF_USE_ASYNEQ */
1769
1770 /* Normally, you declare variables gcpro1, gcpro2, ... and use the
1771    GCPROn() macros.  However, if you need to have nested gcpro's,
1772    declare ngcpro1, ngcpro2, ... and use NGCPROn().  If you need
1773    to nest another level, use nngcpro1, nngcpro2, ... and use
1774    NNGCPROn().  If you need to nest yet another level, create
1775    the appropriate macros. */
1776
1777 #if 1
1778 #if defined HAVE_BDWGC && defined EF_USE_BDWGC
1779
1780 /* tricks to get over a myriad unused variable warnings */
1781 #define gcpro1          gcpro1 __attribute__((unused))
1782 #define gcpro2          gcpro2 __attribute__((unused))
1783 #define gcpro3          gcpro3 __attribute__((unused))
1784 #define gcpro4          gcpro4 __attribute__((unused))
1785 #define gcpro5          gcpro5 __attribute__((unused))
1786 #define gcpro6          gcpro6 __attribute__((unused))
1787 #define gcpro7          gcpro7 __attribute__((unused))
1788 #define gcpro8          gcpro8 __attribute__((unused))
1789
1790 #define ngcpro1         ngcpro1 __attribute__((unused))
1791 #define ngcpro2         ngcpro2 __attribute__((unused))
1792 #define ngcpro3         ngcpro3 __attribute__((unused))
1793 #define ngcpro4         ngcpro4 __attribute__((unused))
1794 #define ngcpro5         ngcpro5 __attribute__((unused))
1795 #define ngcpro6         ngcpro6 __attribute__((unused))
1796 #define ngcpro7         ngcpro7 __attribute__((unused))
1797 #define ngcpro8         ngcpro8 __attribute__((unused))
1798
1799 #define nngcpro1        nngcpro1 __attribute__((unused))
1800 #define nngcpro2        nngcpro2 __attribute__((unused))
1801 #define nngcpro3        nngcpro3 __attribute__((unused))
1802 #define nngcpro4        nngcpro4 __attribute__((unused))
1803 #define nngcpro5        nngcpro5 __attribute__((unused))
1804 #define nngcpro6        nngcpro6 __attribute__((unused))
1805 #define nngcpro7        nngcpro7 __attribute__((unused))
1806 #define nngcpro8        nngcpro8 __attribute__((unused))
1807
1808 #define GCPRO1(args...)
1809 #define GCPRO2(args...)
1810 #define GCPRO3(args...)
1811 #define GCPRO4(args...)
1812 #define GCPRO5(args...)
1813 #define GCPRO6(args...)
1814 #define GCPRO7(args...)
1815 #define GCPRO8(args...)
1816 #define GCPROn(args...)
1817 #define GCPRO1n(args...)
1818 #define GCPRO2n(args...)
1819 #define GCPRO3n(args...)
1820 #define GCPRO1nn(args...)
1821 #define UNGCPRO
1822
1823 #define NGCPRO1(args...)
1824 #define NGCPRO2(args...)
1825 #define NGCPRO3(args...)
1826 #define NGCPRO4(args...)
1827 #define NGCPRO5(args...)
1828 #define NGCPRO6(args...)
1829 #define NGCPRO7(args...)
1830 #define NGCPRO8(args...)
1831 #define NGCPROn(args...)
1832 #define NGCPRO1n(args...)
1833 #define NUNGCPRO
1834
1835 #define NNGCPRO1(args...)
1836 #define NNGCPRO2(args...)
1837 #define NNGCPRO3(args...)
1838 #define NNGCPRO4(args...)
1839 #define NNGCPRO5(args...)
1840 #define NNGCPRO6(args...)
1841 #define NNGCPRO7(args...)
1842 #define NNGCPRO8(args...)
1843 #define NNGCPROn(args...)
1844 #define NNUNGCPRO
1845
1846 #else  /* !BDWGC */
1847
1848 #define GCPRO1(var1)                                                    \
1849         ((void)(                                                        \
1850                 lock_allocator(),                                       \
1851                 gcpro1.next = _get_gcprolist(),                         \
1852                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1853                 _set_gcprolist(&gcpro1),                                \
1854                 unlock_allocator()))
1855
1856 #define GCPRO2(var1, var2)                                              \
1857         ((void)(                                                        \
1858                 lock_allocator(),                                       \
1859                 gcpro1.next = _get_gcprolist(),                         \
1860                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1861                 gcpro2.next = &gcpro1,                                  \
1862                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1863                 _set_gcprolist(&gcpro2),                                \
1864                 unlock_allocator()))
1865
1866 #define GCPRO3(var1, var2, var3)                                        \
1867         ((void)(                                                        \
1868                 lock_allocator(),                                       \
1869                 gcpro1.next = _get_gcprolist(),                         \
1870                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1871                 gcpro2.next = &gcpro1,                                  \
1872                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1873                 gcpro3.next = &gcpro2,                                  \
1874                 gcpro3.var = &var3, gcpro3.nvars = 1,                   \
1875                 _set_gcprolist(&gcpro3),                                \
1876                 unlock_allocator()))
1877
1878 #define GCPRO4(var1, var2, var3, var4)                                  \
1879         ((void)(                                                        \
1880                 lock_allocator(),                                       \
1881                 gcpro1.next = _get_gcprolist(),                         \
1882                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1883                 gcpro2.next = &gcpro1,                                  \
1884                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1885                 gcpro3.next = &gcpro2,                                  \
1886                 gcpro3.var = &var3, gcpro3.nvars = 1,                   \
1887                 gcpro4.next = &gcpro3,                                  \
1888                 gcpro4.var = &var4, gcpro4.nvars = 1,                   \
1889                 _set_gcprolist(&gcpro4),                                \
1890                 unlock_allocator()))
1891
1892 #define GCPRO5(var1, var2, var3, var4, var5)                            \
1893         ((void)(                                                        \
1894                 lock_allocator(),                                       \
1895                 gcpro1.next = _get_gcprolist(),                         \
1896                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1897                 gcpro2.next = &gcpro1,                                  \
1898                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1899                 gcpro3.next = &gcpro2,                                  \
1900                 gcpro3.var = &var3, gcpro3.nvars = 1,                   \
1901                 gcpro4.next = &gcpro3,                                  \
1902                 gcpro4.var = &var4, gcpro4.nvars = 1,                   \
1903                 gcpro5.next = &gcpro4,                                  \
1904                 gcpro5.var = &var5, gcpro5.nvars = 1,                   \
1905                 _set_gcprolist(&gcpro5),                                \
1906                 unlock_allocator()))
1907
1908 #define GCPRO6(var1, var2, var3, var4, var5, var6 )                     \
1909         ((void)(                                                        \
1910                 lock_allocator(),                                       \
1911                 gcpro1.next = _get_gcprolist(),                         \
1912                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1913                 gcpro2.next = &gcpro1,                                  \
1914                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1915                 gcpro3.next = &gcpro2,                                  \
1916                 gcpro3.var = &var3, gcpro3.nvars = 1,                   \
1917                 gcpro4.next = &gcpro3,                                  \
1918                 gcpro4.var = &var4, gcpro4.nvars = 1,                   \
1919                 gcpro5.next = &gcpro4,                                  \
1920                 gcpro5.var = &var5, gcpro5.nvars = 1,                   \
1921                 gcpro6.next = &gcpro5,                                  \
1922                 gcpro6.var = &var6, gcpro6.nvars = 1,                   \
1923                 _set_gcprolist(&gcpro6),                                \
1924                 unlock_allocator()))
1925
1926 #define GCPRO7(var1, var2, var3, var4, var5, var6, var7)                \
1927         ((void)(                                                        \
1928                 lock_allocator(),                                       \
1929                 gcpro1.next = _get_gcprolist(),                         \
1930                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1931                 gcpro2.next = &gcpro1,                                  \
1932                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1933                 gcpro3.next = &gcpro2,                                  \
1934                 gcpro3.var = &var3, gcpro3.nvars = 1,                   \
1935                 gcpro4.next = &gcpro3,                                  \
1936                 gcpro4.var = &var4, gcpro4.nvars = 1,                   \
1937                 gcpro5.next = &gcpro4,                                  \
1938                 gcpro5.var = &var5, gcpro5.nvars = 1,                   \
1939                 gcpro6.next = &gcpro5,                                  \
1940                 gcpro6.var = &var6, gcpro6.nvars = 1,                   \
1941                 gcpro7.next = &gcpro6,                                  \
1942                 gcpro7.var = &var7, gcpro7.nvars = 1,                   \
1943                 _set_gcprolist(&gcpro7),                                \
1944                 unlock_allocator()))
1945
1946 #define GCPRO8(var1, var2, var3, var4, var5, var6, var7, var8)          \
1947         ((void)(                                                        \
1948                 lock_allocator(),                                       \
1949                 gcpro1.next = _get_gcprolist(),                         \
1950                 gcpro1.var = &var1, gcpro1.nvars = 1,                   \
1951                 gcpro2.next = &gcpro1,                                  \
1952                 gcpro2.var = &var2, gcpro2.nvars = 1,                   \
1953                 gcpro3.next = &gcpro2,                                  \
1954                 gcpro3.var = &var3, gcpro3.nvars = 1,                   \
1955                 gcpro4.next = &gcpro3,                                  \
1956                 gcpro4.var = &var4, gcpro4.nvars = 1,                   \
1957                 gcpro5.next = &gcpro4,                                  \
1958                 gcpro5.var = &var5, gcpro5.nvars = 1,                   \
1959                 gcpro6.next = &gcpro5,                                  \
1960                 gcpro6.var = &var6, gcpro6.nvars = 1,                   \
1961                 gcpro7.next = &gcpro6,                                  \
1962                 gcpro7.var = &var7, gcpro7.nvars = 1,                   \
1963                 gcpro8.next = &gcpro7,                                  \
1964                 gcpro8.var = &var8, gcpro8.nvars = 1,                   \
1965                 _set_gcprolist(&gcpro8),                                \
1966                 unlock_allocator()))
1967
1968 #define GCPROn(_varp, _nvars)                   \
1969         ((void)(                                \
1970                 lock_allocator(),               \
1971                 gcpro1.next = _get_gcprolist(), \
1972                 gcpro1.var = _varp,             \
1973                 gcpro1.nvars = _nvars,          \
1974                 _set_gcprolist(&gcpro1),        \
1975                 unlock_allocator()))
1976
1977 #define GCPRO1n(_v1, _varp, _nvars)                                     \
1978         ((void)(                                                        \
1979                 lock_allocator(),                                       \
1980                 gcpro1.next = _get_gcprolist(),                         \
1981                 gcpro1.var = &_v1, gcpro1.nvars = 1,                    \
1982                 gcpro2.next = &gcpro1,                                  \
1983                 gcpro2.var = _varp, gcpro2.nvars = _nvars,              \
1984                 _set_gcprolist(&gcpro2),                                \
1985                 unlock_allocator()))
1986
1987 #define GCPRO2n(_v1, _v2, _varp, _nvars)                                \
1988         ((void)(                                                        \
1989                 lock_allocator(),                                       \
1990                 gcpro1.next = _get_gcprolist(),                         \
1991                 gcpro1.var = &_v1, gcpro1.nvars = 1,                    \
1992                 gcpro2.next = &gcpro1,                                  \
1993                 gcpro2.var = &_v2, gcpro2.nvars = 1,                    \
1994                 gcpro3.next = &gcpro2,                                  \
1995                 gcpro3.var = _varp, gcpro3.nvars = _nvars,              \
1996                 _set_gcprolist(&gcpro3),                                \
1997                 unlock_allocator()))
1998
1999 #define GCPRO3n(_v1, _v2, _v3, _varp, _nvars)                           \
2000         ((void)(                                                        \
2001                 lock_allocator(),                                       \
2002                 gcpro1.next = _get_gcprolist(),                         \
2003                 gcpro1.var = &_v1, gcpro1.nvars = 1,                    \
2004                 gcpro2.next = &gcpro1,                                  \
2005                 gcpro2.var = &_v2, gcpro2.nvars = 1,                    \
2006                 gcpro3.next = &gcpro2,                                  \
2007                 gcpro3.var = &_v3, gcpro3.nvars = 1,                    \
2008                 gcpro4.next = &gcpro3,                                  \
2009                 gcpro4.var = _varp, gcpro4.nvars = _nvars,              \
2010                 _set_gcprolist(&gcpro4),                                \
2011                 unlock_allocator()))
2012
2013 #define GCPRO1nn(_v1, _varp1, _nv1, _varp2, _nv2)                       \
2014         ((void)(                                                        \
2015                 lock_allocator(),                                       \
2016                 gcpro1.next = _get_gcprolist(),                         \
2017                 gcpro1.var = &_v1, gcpro1.nvars = 1,                    \
2018                 gcpro2.next = &gcpro1,                                  \
2019                 gcpro2.var = _varp1, gcpro2.nvars = _nv1,               \
2020                 gcpro3.next = &gcpro2,                                  \
2021                 gcpro3.var = _varp2, gcpro3.nvars = _nv2,               \
2022                 _set_gcprolist(&gcpro3),                                \
2023                 unlock_allocator()))
2024
2025 #define UNGCPRO                                         \
2026         ((void)(                                        \
2027                 lock_allocator(),                       \
2028                 _set_gcprolist(gcpro1.next),            \
2029                 unlock_allocator()))
2030
2031 #define NGCPRO1(var1)                                                   \
2032         ((void) (                                                       \
2033                 lock_allocator(),                                       \
2034                 ngcpro1.next = _get_gcprolist(),                        \
2035                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2036                 _set_gcprolist(&ngcpro1),                               \
2037                 unlock_allocator()))
2038
2039 #define NGCPRO2(var1, var2)                                             \
2040         ((void) (                                                       \
2041                 lock_allocator(),                                       \
2042                 ngcpro1.next = _get_gcprolist(),                        \
2043                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2044                 ngcpro2.next = &ngcpro1,                                \
2045                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2046                 _set_gcprolist(&ngcpro2),                               \
2047                 unlock_allocator()))
2048
2049 #define NGCPRO3(var1, var2, var3)                                       \
2050         ((void) (                                                       \
2051                 lock_allocator(),                                       \
2052                 ngcpro1.next = _get_gcprolist(),                        \
2053                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2054                 ngcpro2.next = &ngcpro1,                                \
2055                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2056                 ngcpro3.next = &ngcpro2,                                \
2057                 ngcpro3.var = &var3, ngcpro3.nvars = 1,                 \
2058                 _set_gcprolist(&ngcpro3),                               \
2059                 unlock_allocator()))
2060
2061 #define NGCPRO4(var1, var2, var3, var4)                                 \
2062         ((void) (                                                       \
2063                 lock_allocator(),                                       \
2064                 ngcpro1.next = _get_gcprolist(),                        \
2065                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2066                 ngcpro2.next = &ngcpro1,                                \
2067                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2068                 ngcpro3.next = &ngcpro2,                                \
2069                 ngcpro3.var = &var3, ngcpro3.nvars = 1,                 \
2070                 ngcpro4.next = &ngcpro3,                                \
2071                 ngcpro4.var = &var4, ngcpro4.nvars = 1,                 \
2072                 _set_gcprolist(&ngcpro4),                               \
2073                 unlock_allocator()))
2074
2075 #define NGCPRO5(var1, var2, var3, var4, var5)                           \
2076         ((void) (                                                       \
2077                 lock_allocator(),                                       \
2078                 ngcpro1.next = _get_gcprolist(),                        \
2079                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2080                 ngcpro2.next = &ngcpro1,                                \
2081                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2082                 ngcpro3.next = &ngcpro2,                                \
2083                 ngcpro3.var = &var3, ngcpro3.nvars = 1,                 \
2084                 ngcpro4.next = &ngcpro3,                                \
2085                 ngcpro4.var = &var4, ngcpro4.nvars = 1,                 \
2086                 ngcpro5.next = &ngcpro4,                                \
2087                 ngcpro5.var = &var5, ngcpro5.nvars = 1,                 \
2088                 _set_gcprolist(&ngcpro5),                               \
2089                 unlock_allocator()))
2090
2091 #define NGCPRO6(var1, var2, var3, var4, var5, var6 )                    \
2092         ((void) (                                                       \
2093                 lock_allocator(),                                       \
2094                 ngcpro1.next = _get_gcprolist(),                        \
2095                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2096                 ngcpro2.next = &ngcpro1,                                \
2097                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2098                 ngcpro3.next = &ngcpro2,                                \
2099                 ngcpro3.var = &var3, ngcpro3.nvars = 1,                 \
2100                 ngcpro4.next = &ngcpro3,                                \
2101                 ngcpro4.var = &var4, ngcpro4.nvars = 1,                 \
2102                 ngcpro5.next = &ngcpro4,                                \
2103                 ngcpro5.var = &var5, ngcpro5.nvars = 1,                 \
2104                 ngcpro6.next = &ngcpro5,                                \
2105                 ngcpro6.var = &var6, ngcpro6.nvars = 1,                 \
2106                 _set_gcprolist(&ngcpro6),                               \
2107                 unlock_allocator()))
2108
2109 #define NGCPRO7(var1, var2, var3, var4, var5, var6, var7)               \
2110         ((void) (                                                       \
2111                 lock_allocator(),                                       \
2112                 ngcpro1.next = _get_gcprolist(),                        \
2113                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2114                 ngcpro2.next = &ngcpro1,                                \
2115                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2116                 ngcpro3.next = &ngcpro2,                                \
2117                 ngcpro3.var = &var3, ngcpro3.nvars = 1,                 \
2118                 ngcpro4.next = &ngcpro3,                                \
2119                 ngcpro4.var = &var4, ngcpro4.nvars = 1,                 \
2120                 ngcpro5.next = &ngcpro4,                                \
2121                 ngcpro5.var = &var5, ngcpro5.nvars = 1,                 \
2122                 ngcpro6.next = &ngcpro5,                                \
2123                 ngcpro6.var = &var6, ngcpro6.nvars = 1,                 \
2124                 ngcpro7.next = &ngcpro6,                                \
2125                 ngcpro7.var = &var7, ngcpro7.nvars = 1,                 \
2126                 _set_gcprolist(&ngcpro7),                               \
2127                 unlock_allocator()))
2128
2129 #define NGCPRO8(var1, var2, var3, var4, var5, var6, var7, var8)         \
2130         ((void) (                                                       \
2131                 lock_allocator(),                                       \
2132                 ngcpro1.next = _get_gcprolist(),                        \
2133                 ngcpro1.var = &var1, ngcpro1.nvars = 1,                 \
2134                 ngcpro2.next = &ngcpro1,                                \
2135                 ngcpro2.var = &var2, ngcpro2.nvars = 1,                 \
2136                 ngcpro3.next = &ngcpro2,                                \
2137                 ngcpro3.var = &var3, ngcpro3.nvars = 1,                 \
2138                 ngcpro4.next = &ngcpro3,                                \
2139                 ngcpro4.var = &var4, ngcpro4.nvars = 1,                 \
2140                 ngcpro5.next = &ngcpro4,                                \
2141                 ngcpro5.var = &var5, ngcpro5.nvars = 1,                 \
2142                 ngcpro6.next = &ngcpro5,                                \
2143                 ngcpro6.var = &var6, ngcpro6.nvars = 1,                 \
2144                 ngcpro7.next = &ngcpro6,                                \
2145                 ngcpro7.var = &var7, ngcpro7.nvars = 1,                 \
2146                 ngcpro8.next = &ngcpro7,                                \
2147                 ngcpro8.var = &var8, ngcpro8.nvars = 1,                 \
2148                 _set_gcprolist(&ngcpro8),                               \
2149                 unlock_allocator()))
2150
2151 #define NGCPROn(_varp, _nvars)                          \
2152         ((void)(                                        \
2153                 lock_allocator(),                       \
2154                 ngcpro1.next = _get_gcprolist(),        \
2155                 ngcpro1.var = _varp,                    \
2156                 ngcpro1.nvars = _nvars,                 \
2157                 _set_gcprolist(&ngcpro1),               \
2158                 unlock_allocator()))
2159
2160 #define NGCPRO1n(_v1, _varp, _nvars)                                    \
2161         ((void)(                                                        \
2162                 lock_allocator(),                                       \
2163                 ngcpro1.next = _get_gcprolist(),                        \
2164                 ngcpro1.var = &_v1, ngcpro1.nvars = 1,                  \
2165                 ngcpro2.next = &ngcpro1,                                \
2166                 ngcpro2.var = _varp, ngcpro2.nvars = _nvars,            \
2167                 _set_gcprolist(&ngcpro2),                               \
2168                 unlock_allocator()))
2169
2170 #define NUNGCPRO                                        \
2171         ((void) (                                       \
2172                 lock_allocator(),                       \
2173                 _set_gcprolist(ngcpro1.next),           \
2174                 unlock_allocator()))
2175
2176 #define NNGCPRO1(var1)                                                  \
2177         ((void) (                                                       \
2178                 lock_allocator(),                                       \
2179                 nngcpro1.next = _get_gcprolist(),                       \
2180                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2181                 _set_gcprolist(&nngcpro1),                              \
2182                 unlock_allocator()))
2183
2184 #define NNGCPRO2(var1, var2)                                            \
2185         ((void) (                                                       \
2186                 lock_allocator(),                                       \
2187                 nngcpro1.next = _get_gcprolist(),                       \
2188                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2189                 nngcpro2.next = &nngcpro1,                              \
2190                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2191                 _set_gcprolist(&nngcpro2),                              \
2192                 unlock_allocator()))
2193
2194 #define NNGCPRO3(var1, var2, var3)                                      \
2195         ((void) (                                                       \
2196                 lock_allocator(),                                       \
2197                 nngcpro1.next = _get_gcprolist(),                       \
2198                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2199                 nngcpro2.next = &nngcpro1,                              \
2200                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2201                 nngcpro3.next = &nngcpro2,                              \
2202                 nngcpro3.var = &var3, nngcpro3.nvars = 1,               \
2203                 _set_gcprolist(&nngcpro3),                              \
2204                 unlock_allocator()))
2205
2206 #define NNGCPRO4(var1, var2, var3, var4)                                \
2207         ((void) (                                                       \
2208                 lock_allocator(),                                       \
2209                 nngcpro1.next = _get_gcprolist(),                       \
2210                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2211                 nngcpro2.next = &nngcpro1,                              \
2212                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2213                 nngcpro3.next = &nngcpro2,                              \
2214                 nngcpro3.var = &var3, nngcpro3.nvars = 1,               \
2215                 nngcpro4.next = &nngcpro3,                              \
2216                 nngcpro4.var = &var4, nngcpro4.nvars = 1,               \
2217                 _set_gcprolist(&nngcpro4),                              \
2218                 unlock_allocator()))
2219
2220 #define NNGCPRO5(var1, var2, var3, var4, var5)                          \
2221         ((void) (                                                       \
2222                 lock_allocator(),                                       \
2223                 nngcpro1.next = _get_gcprolist(),                       \
2224                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2225                 nngcpro2.next = &nngcpro1,                              \
2226                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2227                 nngcpro3.next = &nngcpro2,                              \
2228                 nngcpro3.var = &var3, nngcpro3.nvars = 1,               \
2229                 nngcpro4.next = &nngcpro3,                              \
2230                 nngcpro4.var = &var4, nngcpro4.nvars = 1,               \
2231                 nngcpro5.next = &nngcpro4,                              \
2232                 nngcpro5.var = &var5, nngcpro5.nvars = 1,               \
2233                 _set_gcprolist(&nngcpro5),                              \
2234                 unlock_allocator()))
2235
2236 #define NNGCPRO6(var1, var2, var3, var4, var5, var6 )                   \
2237         ((void) (                                                       \
2238                 lock_allocator(),                                       \
2239                 nngcpro1.next = _get_gcprolist(),                       \
2240                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2241                 nngcpro2.next = &nngcpro1,                              \
2242                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2243                 nngcpro3.next = &nngcpro2,                              \
2244                 nngcpro3.var = &var3, nngcpro3.nvars = 1,               \
2245                 nngcpro4.next = &nngcpro3,                              \
2246                 nngcpro4.var = &var4, nngcpro4.nvars = 1,               \
2247                 nngcpro5.next = &nngcpro4,                              \
2248                 nngcpro5.var = &var5, nngcpro5.nvars = 1,               \
2249                 nngcpro6.next = &nngcpro5,                              \
2250                 nngcpro6.var = &var6, nngcpro6.nvars = 1,               \
2251                 _set_gcprolist(&nngcpro6),                              \
2252                 unlock_allocator()))
2253
2254 #define NNGCPRO7(var1, var2, var3, var4, var5, var6, var7)              \
2255         ((void) (                                                       \
2256                 lock_allocator(),                                       \
2257                 nngcpro1.next = _get_gcprolist(),                       \
2258                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2259                 nngcpro2.next = &nngcpro1,                              \
2260                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2261                 nngcpro3.next = &nngcpro2,                              \
2262                 nngcpro3.var = &var3, nngcpro3.nvars = 1,               \
2263                 nngcpro4.next = &nngcpro3,                              \
2264                 nngcpro4.var = &var4, nngcpro4.nvars = 1,               \
2265                 nngcpro5.next = &nngcpro4,                              \
2266                 nngcpro5.var = &var5, nngcpro5.nvars = 1,               \
2267                 nngcpro6.next = &nngcpro5,                              \
2268                 nngcpro6.var = &var6, nngcpro6.nvars = 1,               \
2269                 nngcpro7.next = &nngcpro6,                              \
2270                 nngcpro7.var = &var7, nngcpro7.nvars = 1,               \
2271                 _set_gcprolist(&nngcpro7),                              \
2272                 unlock_allocator()))
2273
2274 #define NNGCPRO8(var1, var2, var3, var4, var5, var6, var7, var8)        \
2275         ((void) (                                                       \
2276                 lock_allocator(),                                       \
2277                 nngcpro1.next = _get_gcprolist(),                       \
2278                 nngcpro1.var = &var1, nngcpro1.nvars = 1,               \
2279                 nngcpro2.next = &nngcpro1,                              \
2280                 nngcpro2.var = &var2, nngcpro2.nvars = 1,               \
2281                 nngcpro3.next = &nngcpro2,                              \
2282                 nngcpro3.var = &var3, nngcpro3.nvars = 1,               \
2283                 nngcpro4.next = &nngcpro3,                              \
2284                 nngcpro4.var = &var4, nngcpro4.nvars = 1,               \
2285                 nngcpro5.next = &nngcpro4,                              \
2286                 nngcpro5.var = &var5, nngcpro5.nvars = 1,               \
2287                 nngcpro6.next = &nngcpro5,                              \
2288                 nngcpro6.var = &var6, nngcpro6.nvars = 1,               \
2289                 nngcpro7.next = &nngcpro6,                              \
2290                 nngcpro7.var = &var7, nngcpro7.nvars = 1,               \
2291                 nngcpro8.next = &nngcpro7,                              \
2292                 nngcpro8.var = &var8, nngcpro8.nvars = 1,               \
2293                 _set_gcprolist(&nngcpro8),                              \
2294                 unlock_allocator()))
2295
2296 #define NNGCPROn(_varp, _nvars)                         \
2297         ((void)(                                        \
2298                 lock_allocator(),                       \
2299                 nngcpro1.next = _get_gcprolist(),       \
2300                 nngcpro1.var = _varp,                   \
2301                 nngcpro1.nvars = _nvars,                \
2302                 _set_gcprolist(&nngcpro1),              \
2303                 unlock_allocator()))
2304
2305 #define NNUNGCPRO                                       \
2306         ((void) (                                       \
2307                 lock_allocator(),                       \
2308                 _set_gcprolist(nngcpro1.next),          \
2309                 unlock_allocator()))
2310
2311 #endif  /* BDWGC */
2312
2313 #else /* defined(DEBUG_GCPRO) */
2314
2315 void debug_gcpro1(char *, int, struct gcpro *, Lisp_Object *);
2316 void debug_gcpro2(char *, int, struct gcpro *, struct gcpro *,
2317                   Lisp_Object *, Lisp_Object *);
2318 void debug_gcpro3(char *, int, struct gcpro *, struct gcpro *, struct gcpro *,
2319                   Lisp_Object *, Lisp_Object *, Lisp_Object *);
2320 void debug_gcpro4(char *, int, struct gcpro *, struct gcpro *, struct gcpro *,
2321                   struct gcpro *, Lisp_Object *, Lisp_Object *, Lisp_Object *,
2322                   Lisp_Object *);
2323 void debug_gcpro5(char *, int, struct gcpro *, struct gcpro *, struct gcpro *,
2324                   struct gcpro *, struct gcpro *, Lisp_Object *, Lisp_Object *,
2325                   Lisp_Object *, Lisp_Object *, Lisp_Object *);
2326 void debug_gcpro6(char *, int, struct gcpro *, struct gcpro *, struct gcpro *,
2327                   struct gcpro *, struct gcpro *, struct gcpro *, Lisp_Object *,
2328                   Lisp_Object *, Lisp_Object *, Lisp_Object *, Lisp_Object *,
2329                   Lisp_Object *);
2330 void debug_gcpro7(char *, int, struct gcpro *, struct gcpro *, struct gcpro *,
2331                   struct gcpro *, struct gcpro *, struct gcpro *, struct gcpro *,
2332                   Lisp_Object *, Lisp_Object *, Lisp_Object *, Lisp_Object *,
2333                   Lisp_Object *, Lisp_Object *, Lisp_Object *);
2334 void debug_gcpro8(char *, int, struct gcpro *, struct gcpro *, struct gcpro *,
2335                   struct gcpro *, struct gcpro *, struct gcpro *, struct gcpro *,
2336                   struct gcpro *, Lisp_Object *, Lisp_Object *,
2337                   Lisp_Object *, Lisp_Object *, Lisp_Object *, Lisp_Object *,
2338                   Lisp_Object *, Lisp_Object *);
2339 void debug_ungcpro(char *, int, struct gcpro *);
2340
2341 #define GCPRO1(v) \
2342  debug_gcpro1 (__FILE__, __LINE__,&gcpro1,&v)
2343 #define GCPRO2(v1,v2) \
2344  debug_gcpro2 (__FILE__, __LINE__,&gcpro1,&gcpro2,&v1,&v2)
2345 #define GCPRO3(v1,v2,v3) \
2346  debug_gcpro3 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&v1,&v2,&v3)
2347 #define GCPRO4(v1,v2,v3,v4) \
2348  debug_gcpro4 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,\
2349                &v1,&v2,&v3,&v4)
2350 #define GCPRO5(v1,v2,v3,v4,v5) \
2351  debug_gcpro5 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,&gcpro5,\
2352                &v1,&v2,&v3,&v4,&v5)
2353 #define GCPRO6(v1,v2,v3,v4,v5,v6)                                         \
2354   debug_gcpro6 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,&gcpro5,&gcpro6, \
2355                 &v1,&v2,&v3,&v4,&v5,&v6)
2356 #define GCPRO7(v1,v2,v3,v4,v5,v6,v7)                                      \
2357  debug_gcpro7 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,&gcpro5,&gcpro6,&gcpro7,\
2358                &v1,&v2,&v3,&v4,&v5,&v6,&v7)
2359 #define GCPRO8(v1,v2,v3,v4,v5,v6,v7,v8)                                   \
2360   debug_gcpro8 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,&gcpro5,&gcpro6,&gcpro7,&gcpro8, \
2361                 &v1,&v2,&v3,&v4,&v5,&v6,&v7,&v8)
2362 #define UNGCPRO \
2363  debug_ungcpro(__FILE__, __LINE__,&gcpro1)
2364
2365 #define NGCPRO1(v) \
2366  debug_gcpro1 (__FILE__, __LINE__,&ngcpro1,&v)
2367 #define NGCPRO2(v1,v2) \
2368  debug_gcpro2 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&v1,&v2)
2369 #define NGCPRO3(v1,v2,v3) \
2370  debug_gcpro3 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&ngcpro3,&v1,&v2,&v3)
2371 #define NGCPRO4(v1,v2,v3,v4) \
2372  debug_gcpro4 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&ngcpro3,&ngcpro4,\
2373                &v1,&v2,&v3,&v4)
2374 #define NGCPRO5(v1,v2,v3,v4,v5) \
2375  debug_gcpro5 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&ngcpro3,&ngcpro4,\
2376                &ngcpro5,&v1,&v2,&v3,&v4,&v5)
2377 #define NGCPRO6(v1,v2,v3,v4,v5,v6)                                         \
2378   debug_gcpro6 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&ngcpro3,&ngcpro4,&ngcpro5,&ngcpro6, \
2379                 &v1,&v2,&v3,&v4,&v5,&v6)
2380 #define NGCPRO7(v1,v2,v3,v4,v5,v6,v7)                                     \
2381  debug_gcpro7 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&ngcpro3,&ngcpro4,&ngcpro5,&ngcpro6,&ngcpro7,\
2382                &v1,&v2,&v3,&v4,&v5,&v6,&v7)
2383 #define NGCPRO8(v1,v2,v3,v4,v5,v6,v7,v8)                                  \
2384   debug_gcpro8 (__FILE__, __LINE__,&ngcpro1,&ngcpro2,&ngcpro3,&ngcpro4,&ngcpro5,&ngcpro6,&ngcpro7,&ngcpro8, \
2385                 &v1,&v2,&v3,&v4,&v5,&v6,&v7,&v8)
2386 #define NUNGCPRO \
2387  debug_ungcpro(__FILE__, __LINE__,&ngcpro1)
2388
2389 #define NNGCPRO1(v) \
2390  debug_gcpro1 (__FILE__, __LINE__,&nngcpro1,&v)
2391 #define NNGCPRO2(v1,v2) \
2392  debug_gcpro2 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&v1,&v2)
2393 #define NNGCPRO3(v1,v2,v3) \
2394  debug_gcpro3 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&nngcpro3,&v1,&v2,&v3)
2395 #define NNGCPRO4(v1,v2,v3,v4) \
2396  debug_gcpro4 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&nngcpro3,&nngcpro4,\
2397                &v1,&v2,&v3,&v4)
2398 #define NNGCPRO5(v1,v2,v3,v4,v5) \
2399  debug_gcpro5 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&nngcpro3,&nngcpro4,\
2400                &nngcpro5,&v1,&v2,&v3,&v4,&v5)
2401 #define NNGCPRO6(v1,v2,v3,v4,v5,v6)                                         \
2402   debug_gcpro6 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&nngcpro3,&nngcpro4,&nngcpro5,&nngcpro6, \
2403                 &v1,&v2,&v3,&v4,&v5,&v6)
2404 #define NNGCPRO7(v1,v2,v3,v4,v5,v6,v7)                                    \
2405  debug_gcpro7 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&nngcpro3,&nngcpro4,&nngcpro5,&nngcpro6,&nngcpro7,\
2406                &v1,&v2,&v3,&v4,&v5,&v6,&v7)
2407 #define NNGCPRO8(v1,v2,v3,v4,v5,v6,v7,v8)                                 \
2408   debug_gcpro8 (__FILE__, __LINE__,&nngcpro1,&nngcpro2,&nngcpro3,&nngcpro4,&nngcpro5,&nngcpro6,&nngcpro7,&nngcpro8, \
2409                 &v1,&v2,&v3,&v4,&v5,&v6,&v7,&v8)
2410 #define NNUNGCPRO \
2411  debug_ungcpro(__FILE__, __LINE__,&nngcpro1)
2412
2413 #endif                          /* DEBUG_GCPRO */
2414
2415 /* Another try to fix SunPro C compiler warnings */
2416 /* "end-of-loop code not reached" */
2417 /* "statement not reached */
2418 #if defined __SUNPRO_C || defined __USLC__
2419 #define RETURN_SANS_WARNINGS if (1) return
2420 #define RETURN_NOT_REACHED(value)
2421 #else
2422 #define RETURN_SANS_WARNINGS return
2423 #define RETURN_NOT_REACHED(value) return value;
2424 #endif
2425
2426 /* Evaluate expr, UNGCPRO, and then return the value of expr.  */
2427 #define RETURN_UNGCPRO(expr)                            \
2428         do {                                            \
2429                 Lisp_Object ret_ungc_val = (expr);      \
2430                 UNGCPRO;                                \
2431                 RETURN_SANS_WARNINGS ret_ungc_val;      \
2432         } while (0)
2433
2434 /* Evaluate expr, NUNGCPRO, UNGCPRO, and then return the value of expr.  */
2435 #define RETURN_NUNGCPRO(expr)                           \
2436         do {                                            \
2437                 Lisp_Object ret_ungc_val = (expr);      \
2438                 NUNGCPRO;                               \
2439                 UNGCPRO;                                \
2440                 RETURN_SANS_WARNINGS ret_ungc_val;      \
2441         } while (0)
2442
2443 /* Evaluate expr, NNUNGCPRO, NUNGCPRO, UNGCPRO, and then return the
2444    value of expr.  */
2445 #define RETURN_NNUNGCPRO(expr)                          \
2446         do {                                            \
2447                 Lisp_Object ret_ungc_val = (expr);      \
2448                 NNUNGCPRO;                              \
2449                 NUNGCPRO;                               \
2450                 UNGCPRO;                                \
2451                 RETURN_SANS_WARNINGS ret_ungc_val;      \
2452         } while (0)
2453
2454 /* Evaluate expr, return it if it's not Qunbound. */
2455 #define RETURN_IF_NOT_UNBOUND(expr)     \
2456         do {                                                    \
2457                 Lisp_Object ret_nunb_val = (expr);              \
2458                 if (!UNBOUNDP (ret_nunb_val))                   \
2459                         RETURN_SANS_WARNINGS ret_nunb_val;      \
2460         } while (0)
2461
2462 void register_post_gc_action(void (*fun) (void *), void *arg);
2463
2464 /* Call staticpro (&var) to protect static variable `var'. */
2465 void staticpro(Lisp_Object *);
2466
2467 #if defined HAVE_BDWGC && defined EF_USE_BDWGC
2468 #define staticpro_nodump(foo)
2469 #else
2470 /* Call staticpro_nodump (&var) to protect static variable `var'. */
2471 /* var will not be saved at dump time */
2472 void staticpro_nodump(Lisp_Object *);
2473 #endif  /* BDWGC */
2474
2475 /* allocation goodies */
2476 #include "opaque.h"
2477
2478 static inline EMACS_INT
2479 __attribute__((always_inline))
2480 __next_2power(EMACS_INT v)
2481 {
2482 /* compute the next 2-power of in */
2483         v--;
2484         v |= v >> 1;
2485         v |= v >> 2;
2486         v |= v >> 4;
2487         v |= v >> 8;
2488 #if SIZEOF_EMACS_INT >= 4
2489         v |= v >> 16;
2490 #endif  /* sizeof(EMACS_INT) >= 4 */
2491 #if SIZEOF_EMACS_INT >= 8
2492         v |= v >> 32;
2493 #endif  /* sizeof(EMACS_INT) >= 8 */
2494 #if SIZEOF_EMACS_INT >= 16
2495         v |= v >> 64;
2496 #endif  /* sizeof(EMACS_INT) >= 16 */
2497         v++;
2498         return v;
2499 }
2500
2501 /* also generally useful if you want to avoid arbitrary size limits
2502    but don't need a full dynamic array.  Assumes that BASEVAR points
2503    to a malloced array of TYPE objects (or possibly a NULL pointer,
2504    if SIZEVAR is 0), with the total size stored in SIZEVAR.  This
2505    macro will realloc BASEVAR as necessary so that it can hold at
2506    least NEEDED_SIZE objects.  The reallocing is done by doubling,
2507    which ensures constant amortized time per element. */
2508 static inline EMACS_INT
2509 __attribute__((always_inline))
2510 __alloc_size(EMACS_INT sz, EMACS_INT needed)
2511 {
2512         if (UNLIKELY(needed <= 32)) {
2513                 return 32;
2514         }
2515         return __next_2power(needed);
2516 }
2517
2518 #define DO_REALLOC(basevar, sizevar, needed_size, type)                 \
2519         do {                                                            \
2520                 EMACS_INT cache_needed_size = (needed_size);            \
2521                 if (LIKELY((sizevar) >= cache_needed_size)) {           \
2522                         break;                                          \
2523                 }                                                       \
2524                 (sizevar) = __alloc_size((sizevar), cache_needed_size); \
2525                 if (UNLIKELY((basevar) == NULL)) {                      \
2526                         (basevar) = xnew_array(type, (sizevar));        \
2527                 } else {                                                \
2528                         xrealloc_array(basevar, type, (sizevar));       \
2529                 }                                                       \
2530         } while (0)
2531
2532 #define DO_REALLOC_ATOMIC(basevar, sizevar, needed_size, type)          \
2533         do {                                                            \
2534                 EMACS_INT cache_needed_size = (needed_size);            \
2535                 if (LIKELY((sizevar) >= cache_needed_size)) {           \
2536                         break;                                          \
2537                 }                                                       \
2538                 (sizevar) = __alloc_size((sizevar), cache_needed_size); \
2539                 if (UNLIKELY((basevar) == NULL)) {                      \
2540                         (basevar) = xnew_atomic_array(type, (sizevar)); \
2541                 } else {                                                \
2542                         xrealloc_array(basevar, type, (sizevar));       \
2543                 }                                                       \
2544         } while (0)
2545
2546 #if defined HAVE_BDWGC && defined EF_USE_BDWGC && !defined GC_DEBUG_FLAG
2547 #define free_me         __free_me __attribute__((unused))
2548 #endif
2549
2550 static inline Lisp_Object
2551 free_malloced_ptr(Lisp_Object unwind_obj)
2552 {
2553         void *free_me = (void*)get_opaque_ptr(unwind_obj);
2554         xfree(free_me);
2555         free_opaque_ptr(unwind_obj);
2556         return Qnil;
2557 }
2558
2559 /* Don't use alloca for regions larger than this, lest we overflow
2560    the stack.  */
2561 #define MAX_ALLOCA 65536
2562
2563 /* We need to setup proper unwinding, because there is a number of
2564    ways these functions can blow up, and we don't want to have memory
2565    leaks in those cases.  */
2566 #define XMALLOC_OR_ALLOCA(ptr, len, type)                               \
2567         do {                                                            \
2568                 size_t XOA_len = (len);                                 \
2569                 if (XOA_len > MAX_ALLOCA) {                             \
2570                         ptr = xnew_array(type, XOA_len);                \
2571                         record_unwind_protect(free_malloced_ptr,        \
2572                                               make_opaque_ptr((void*)ptr)); \
2573                 } else {                                                \
2574                         ptr = alloca_array(type, XOA_len);              \
2575                 }                                                       \
2576         } while (0)
2577
2578 #define XMALLOC_ATOMIC_OR_ALLOCA(ptr, len, type)                        \
2579         do {                                                            \
2580                 size_t XOA_len = (len);                                 \
2581                 if (XOA_len > MAX_ALLOCA) {                             \
2582                         ptr = xnew_atomic_array(type, XOA_len);         \
2583                         record_unwind_protect(free_malloced_ptr,        \
2584                                               make_opaque_ptr((void*)ptr)); \
2585                 } else {                                                \
2586                         ptr = alloca_array(type, XOA_len);              \
2587                 }                                                       \
2588         } while (0)
2589
2590 #define XMALLOC_UNBIND(ptr, len, speccount)                             \
2591         do {                                                            \
2592                 if ((len) > MAX_ALLOCA) {                               \
2593                         unbind_to (speccount, Qnil);                    \
2594                 }                                                       \
2595         } while (0)
2596
2597 \f
2598 /* dump_add_root_struct_ptr (&var, &desc) dumps the structure pointed to by `var'. */
2599 #ifdef PDUMP
2600 void dump_add_root_struct_ptr(void *, const struct struct_description *);
2601 #else
2602 #define dump_add_root_struct_ptr(varaddr,descaddr) DO_NOTHING
2603 #endif
2604
2605 /* dump_add_opaque (&var, size) dumps the opaque static structure `var'. */
2606 #ifdef PDUMP
2607 void dump_add_opaque(void *, size_t);
2608 #else
2609 #define dump_add_opaque(varaddr,size) DO_NOTHING
2610 #endif
2611
2612 /* Call dump_add_opaque_int (&int_var) to dump `int_var', of type `int'. */
2613 #ifdef PDUMP
2614 #define dump_add_opaque_int(int_varaddr) do {   \
2615   int *dao_ = (int_varaddr); /* type check */   \
2616   dump_add_opaque (dao_, sizeof (*dao_));       \
2617 } while (0)
2618 #else
2619 #define dump_add_opaque_int(int_varaddr) DO_NOTHING
2620 #endif
2621
2622 /* Call dump_add_opaque_fixnum (&fixnum_var) to dump `fixnum_var', of type `Fixnum'. */
2623 #ifdef PDUMP
2624 #define dump_add_opaque_fixnum(fixnum_varaddr) do {     \
2625   Fixnum *dao_ = (fixnum_varaddr); /* type check */     \
2626   dump_add_opaque (dao_, sizeof (*dao_));               \
2627 } while (0)
2628 #else
2629 #define dump_add_opaque_fixnum(fixnum_varaddr) DO_NOTHING
2630 #endif
2631
2632 /* Call dump_add_root_object (&var) to ensure that var is properly updated after pdump. */
2633 #ifdef PDUMP
2634 void dump_add_root_object(Lisp_Object *);
2635 #else
2636 #define dump_add_root_object(varaddr) DO_NOTHING
2637 #endif
2638
2639 /* Call dump_add_root_object (&var) to ensure that var is properly updated after
2640    pdump.  var must point to a linked list of objects out of which
2641    some may not be dumped */
2642 #ifdef PDUMP
2643 void dump_add_weak_object_chain(Lisp_Object *);
2644 #else
2645 #define dump_add_weak_object_chain(varaddr) DO_NOTHING
2646 #endif
2647
2648 /* Nonzero means Emacs has already been initialized.
2649    Used during startup to detect startup of dumped Emacs.  */
2650 extern int initialized;
2651
2652 #ifdef MEMORY_USAGE_STATS
2653
2654 /* This structure is used to keep statistics on the amount of memory
2655    in use.
2656
2657    WAS_REQUESTED stores the actual amount of memory that was requested
2658    of the allocation function.  The *_OVERHEAD fields store the
2659    additional amount of memory that was grabbed by the functions to
2660    facilitate allocation, reallocation, etc.  MALLOC_OVERHEAD is for
2661    memory allocated with malloc(); DYNARR_OVERHEAD is for dynamic
2662    arrays; GAP_OVERHEAD is for gap arrays.  Note that for (e.g.)
2663    dynamic arrays, there is both MALLOC_OVERHEAD and DYNARR_OVERHEAD
2664    memory: The dynamic array allocates memory above and beyond what
2665    was asked of it, and when it in turns allocates memory using
2666    malloc(), malloc() allocates memory beyond what it was asked
2667    to allocate.
2668
2669    Functions that accept a structure of this sort do not initialize
2670    the fields to 0, and add any existing values to whatever was there
2671    before; this way, you can get a cumulative effect. */
2672
2673 struct overhead_stats {
2674         int was_requested;
2675         int malloc_overhead;
2676         int dynarr_overhead;
2677         int gap_overhead;
2678 };
2679
2680 #endif                          /* MEMORY_USAGE_STATS */
2681
2682 #ifndef DIRECTORY_SEP
2683 #define DIRECTORY_SEP '/'
2684 #endif
2685 #ifndef IS_DIRECTORY_SEP
2686 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
2687 #endif
2688 #ifndef IS_DEVICE_SEP
2689 #ifndef DEVICE_SEP
2690 #define IS_DEVICE_SEP(c) 0
2691 #else
2692 #define IS_DEVICE_SEP(c) ((c) == DEVICE_SEP)
2693 #endif
2694 #endif
2695 #ifndef IS_ANY_SEP
2696 #define IS_ANY_SEP(c) IS_DIRECTORY_SEP (c)
2697 #endif
2698
2699 #ifdef HAVE_INTTYPES_H
2700 #include <inttypes.h>
2701 #elif SIZEOF_VOID_P == SIZEOF_INT
2702 typedef int intptr_t;
2703 typedef unsigned int uintptr_t;
2704 #elif SIZEOF_VOID_P == SIZEOF_LONG
2705 typedef long intptr_t;
2706 typedef unsigned long uintptr_t;
2707 #elif SIZEOF_VOID_P == SIZEOF_LONG_LONG_INT
2708 typedef long long intptr_t;
2709 typedef unsigned long long uintptr_t;
2710 #else
2711 /* Just pray. May break, may not. */
2712 typedef long intptr_t;
2713 typedef unsigned long uintptr_t;
2714 #endif
2715 \f
2716 /************************************************************************/
2717 /*                            Misc definitions                  */
2718 /************************************************************************/
2719 #include "dllist.h"
2720 \f
2721 /************************************************************************/
2722 /*                           Other numeric types                        */
2723 /************************************************************************/
2724
2725 /* more allocation goodies, C99 wise */
2726 extern size_t sys_stk_sz;
2727 extern char *stack_bottom;
2728 extern_inline size_t
2729 __sys_stk_free(void)
2730         __attribute__((always_inline));
2731 extern_inline size_t
2732 __sys_stk_free(void)
2733 {
2734         char probe;
2735         return sys_stk_sz - (stack_bottom - &probe);
2736 }
2737
2738 \f
2739 /************************************************************************/
2740 /*                              prototypes                              */
2741 /************************************************************************/
2742
2743 /* NOTE: Prototypes should go HERE, not in various header files, unless
2744    they specifically reference a type that's not defined in lisp.h.
2745    (And even then, you might consider adding the type to lisp.h.)
2746
2747    The idea is that header files typically contain the innards of objects,
2748    and we want to minimize the number of "dependencies" of one file on
2749    the specifics of such objects.  Putting prototypes here minimizes the
2750    number of header files that need to be included -- good for a number
2751    of reasons. --ben */
2752
2753 /*--------------- prototypes for various public c functions ------------*/
2754
2755 /* Prototypes for all init/syms_of/vars_of initialization functions. */
2756 #include "symsinit.h"
2757
2758 /* Defined in alloc.c */
2759 void release_breathing_space(void);
2760 Lisp_Object noseeum_cons(Lisp_Object, Lisp_Object);
2761 Lisp_Object make_vector(size_t, Lisp_Object);
2762 Lisp_Object vector1(Lisp_Object);
2763 Lisp_Object vector2(Lisp_Object, Lisp_Object);
2764 Lisp_Object vector3(Lisp_Object, Lisp_Object, Lisp_Object);
2765 Lisp_Object make_bit_vector(size_t, Lisp_Object);
2766 Lisp_Object make_bit_vector_from_byte_vector(unsigned char *, size_t);
2767 Lisp_Object noseeum_make_marker(void);
2768 void garbage_collect_1(void);
2769 Lisp_Object acons(Lisp_Object, Lisp_Object, Lisp_Object);
2770 Lisp_Object cons3(Lisp_Object, Lisp_Object, Lisp_Object);
2771 Lisp_Object list1(Lisp_Object);
2772 Lisp_Object list2(Lisp_Object, Lisp_Object);
2773 Lisp_Object list3(Lisp_Object, Lisp_Object, Lisp_Object);
2774 Lisp_Object list4(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
2775 Lisp_Object list5(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
2776                   Lisp_Object);
2777 Lisp_Object list6(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
2778                   Lisp_Object, Lisp_Object);
2779 DECLARE_DOESNT_RETURN(memory_full(void));
2780 void disksave_object_finalization(void);
2781 extern int purify_flag;
2782 extern int gc_currently_forbidden;
2783 Lisp_Object restore_gc_inhibit(Lisp_Object);
2784 extern EMACS_INT gc_generation_number[1];
2785 int c_readonly(Lisp_Object);
2786 int lisp_readonly(Lisp_Object);
2787 Lisp_Object build_string(const char *);
2788 Lisp_Object build_ext_string(const char*, Lisp_Object);
2789 Lisp_Object build_translated_string(const char*);
2790 Lisp_Object make_string(const Bufbyte*, Bytecount);
2791 Lisp_Object make_ext_string(const Extbyte*, EMACS_INT, Lisp_Object);
2792 Lisp_Object make_uninit_string(Bytecount);
2793 Lisp_Object make_string_nocopy(Bufbyte*, Bytecount);
2794 void free_cons(Lisp_Cons *);
2795 void free_list(Lisp_Object);
2796 void free_alist(Lisp_Object);
2797 void mark_conses_in_list(Lisp_Object);
2798 void free_marker(Lisp_Marker *);
2799 int object_dead_p(Lisp_Object);
2800 void mark_object(Lisp_Object obj);
2801 int marked_p(Lisp_Object obj);
2802
2803 #ifdef MEMORY_USAGE_STATS
2804 size_t malloced_storage_size(void *, size_t, struct overhead_stats *);
2805 size_t fixed_type_block_overhead(size_t);
2806 #endif
2807 #ifdef PDUMP
2808 int pdump_load(const char *);
2809
2810 extern char *pdump_start, *pdump_end;
2811 #define DUMPEDP(adr) ((((char *)(adr)) < pdump_end) && (((char *)(adr)) >= pdump_start))
2812 #else
2813 #define DUMPEDP(adr) 0
2814 #endif
2815
2816 /* Defined in buffer.c */
2817 Lisp_Object make_buffer(struct buffer *);
2818 Lisp_Object get_truename_buffer(Lisp_Object);
2819 void switch_to_buffer(Lisp_Object, Lisp_Object);
2820 extern int find_file_compare_truenames;
2821 extern int find_file_use_truenames;
2822
2823 /* Defined in callproc.c */
2824 char *egetenv(const char *);
2825
2826 /* Defined in console.c */
2827 void stuff_buffered_input(Lisp_Object);
2828
2829 /* Defined in console-msw.c */
2830 EXFUN(Fmswindows_message_box, 3);
2831 extern int mswindows_message_outputted;
2832
2833 /* Defined in data.c */
2834 DECLARE_DOESNT_RETURN(c_write_error(Lisp_Object));
2835 DECLARE_DOESNT_RETURN(lisp_write_error(Lisp_Object));
2836 DECLARE_DOESNT_RETURN(args_out_of_range(Lisp_Object, Lisp_Object));
2837 DECLARE_DOESNT_RETURN(args_out_of_range_3(Lisp_Object, Lisp_Object,
2838                                           Lisp_Object));
2839 Lisp_Object wrong_type_argument(Lisp_Object, Lisp_Object);
2840 DECLARE_DOESNT_RETURN(dead_wrong_type_argument(Lisp_Object, Lisp_Object));
2841 void check_int_range(EMACS_INT, EMACS_INT, EMACS_INT);
2842
2843 #if 0
2844 /* superseded by ent-binary-rel stuff */
2845 enum arith_comparison {
2846         arith_equal,
2847         arith_notequal,
2848         arith_less,
2849         arith_grtr,
2850         arith_less_or_equal,
2851         arith_grtr_or_equal
2852 };
2853 Lisp_Object arithcompare(Lisp_Object, Lisp_Object, enum arith_comparison);
2854 #endif
2855
2856 /* Do NOT use word_to_lisp or wasteful_word_to_lisp to decode time_t's
2857    unless you KNOW arg is non-negative.  They cannot return negative
2858    values!  Use make_time.  */
2859 Lisp_Object word_to_lisp(unsigned int);
2860 unsigned int lisp_to_word(Lisp_Object);
2861
2862 /* Defined in dired.c */
2863 Lisp_Object make_directory_hash_table(const char *);
2864 Lisp_Object wasteful_word_to_lisp(unsigned int);
2865
2866 /* Defined in doc.c */
2867 Lisp_Object unparesseuxify_doc_string(int, EMACS_INT, char *, Lisp_Object);
2868 Lisp_Object read_doc_string(Lisp_Object);
2869
2870 /* Defined in doprnt.c */
2871 Bytecount emacs_doprnt_c(Lisp_Object, const Bufbyte *, Lisp_Object,
2872                          Bytecount, ...);
2873 Bytecount emacs_doprnt_va(Lisp_Object, const Bufbyte *, Lisp_Object,
2874                           Bytecount, va_list);
2875 Bytecount emacs_doprnt_lisp(Lisp_Object, const Bufbyte *, Lisp_Object,
2876                             Bytecount, int, const Lisp_Object *);
2877 Bytecount emacs_doprnt_lisp_2(Lisp_Object, const Bufbyte *, Lisp_Object,
2878                               Bytecount, int, ...);
2879 Lisp_Object emacs_doprnt_string_c(const Bufbyte *, Lisp_Object, Bytecount, ...);
2880 Lisp_Object emacs_doprnt_string_va(const Bufbyte *, Lisp_Object,
2881                                    Bytecount, va_list);
2882 Lisp_Object emacs_doprnt_string_lisp(const Bufbyte *, Lisp_Object,
2883                                      Bytecount, int, const Lisp_Object *);
2884 Lisp_Object emacs_doprnt_string_lisp_2(const Bufbyte *, Lisp_Object,
2885                                        Bytecount, int, ...);
2886
2887 /* Defined in editfns.c */
2888 void uncache_home_directory(void);
2889 Extbyte *get_home_directory(void);
2890 char *user_login_name(uid_t *);
2891 char *user_group_name(gid_t *);
2892 Bufpos bufpos_clip_to_bounds(Bufpos, Bufpos, Bufpos);
2893 Bytind bytind_clip_to_bounds(Bytind, Bytind, Bytind);
2894 void buffer_insert1(struct buffer *, Lisp_Object);
2895 Lisp_Object make_string_from_buffer(struct buffer *, Bufpos, Charcount);
2896 Lisp_Object make_string_from_buffer_no_extents(struct buffer *, Bufpos,
2897                                                Charcount);
2898 Lisp_Object make_time(time_t);
2899 Lisp_Object save_excursion_save(void);
2900 Lisp_Object save_restriction_save(void);
2901 Lisp_Object save_excursion_restore(Lisp_Object);
2902 Lisp_Object save_restriction_restore(Lisp_Object);
2903
2904 /* Defined in emacsfns.c */
2905 Lisp_Object save_current_buffer_restore(Lisp_Object);
2906
2907 /* Defined in emacs.c */
2908 DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(fatal(const char *,
2909                                                        ...), 1, 2);
2910 int stderr_out(const char *, ...) PRINTF_ARGS(1, 2);
2911 int stdout_out(const char *, ...) PRINTF_ARGS(1, 2);
2912 SIGTYPE fatal_error_signal(int);
2913 Lisp_Object make_arg_list(int, Extbyte **);
2914 void make_argc_argv(Lisp_Object, int *, Extbyte ***);
2915 void free_argc_argv(Extbyte **);
2916 Lisp_Object decode_env_path(const char *, /*const*/ char *);
2917 Lisp_Object decode_path(/*const*/ char *);
2918 /* Nonzero means don't do interactive redisplay and don't change tty modes */
2919 extern int noninteractive, noninteractive1;
2920 extern int fatal_error_in_progress;
2921 extern int inhibit_non_essential_printing_operations;
2922 extern int preparing_for_armageddon;
2923 extern Fixnum emacs_priority;
2924 extern int running_asynch_code;
2925 extern int suppress_early_error_handler_backtrace;
2926 void debug_break(void);
2927 int debug_can_access_memory(void *ptr, Bytecount len);
2928
2929 /* Defined in eval.c */
2930 DECLARE_DOESNT_RETURN(signal_error(Lisp_Object, Lisp_Object));
2931 void maybe_signal_error(Lisp_Object, Lisp_Object, Lisp_Object, Error_behavior);
2932 Lisp_Object maybe_signal_continuable_error(Lisp_Object, Lisp_Object,
2933                                            Lisp_Object, Error_behavior);
2934 DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(type_error(Lisp_Object,
2935                                                             const char *,
2936                                                             ...), 2, 3);
2937 void maybe_type_error(Lisp_Object, Lisp_Object, Error_behavior, const char *,
2938                       ...) PRINTF_ARGS(4, 5);
2939 Lisp_Object continuable_type_error(Lisp_Object, const char *, ...)
2940 PRINTF_ARGS(2, 3);
2941 Lisp_Object maybe_continuable_type_error(Lisp_Object, Lisp_Object,
2942                                          Error_behavior,
2943                                          const char *, ...) PRINTF_ARGS(4, 5);
2944 DECLARE_DOESNT_RETURN(signal_type_error(Lisp_Object, const char *,
2945                                         Lisp_Object));
2946 void maybe_signal_type_error(Lisp_Object, const char *, Lisp_Object,
2947                              Lisp_Object, Error_behavior);
2948 Lisp_Object signal_type_continuable_error(Lisp_Object, const char *,
2949                                           Lisp_Object);
2950 Lisp_Object maybe_signal_type_continuable_error(Lisp_Object, const char *,
2951                                                 Lisp_Object,
2952                                                 Lisp_Object, Error_behavior);
2953 DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(type_error_with_frob
2954                                                  (Lisp_Object, Lisp_Object,
2955                                                   const char *, ...), 3, 4);
2956 void maybe_type_error_with_frob(Lisp_Object, Lisp_Object, Lisp_Object,
2957                                 Error_behavior,
2958                                 const char *, ...) PRINTF_ARGS(5, 6);
2959 Lisp_Object continuable_type_error_with_frob(Lisp_Object, Lisp_Object,
2960                                              const char *,
2961                                              ...) PRINTF_ARGS(3, 4);
2962 Lisp_Object maybe_continuable_type_error_with_frob
2963     (Lisp_Object, Lisp_Object, Lisp_Object, Error_behavior, const char *, ...)
2964 PRINTF_ARGS(5, 6);
2965 DECLARE_DOESNT_RETURN(signal_type_error_2(Lisp_Object, const char *,
2966                                           Lisp_Object, Lisp_Object));
2967 void maybe_signal_type_error_2(Lisp_Object, const char *, Lisp_Object,
2968                                Lisp_Object, Lisp_Object, Error_behavior);
2969 Lisp_Object signal_type_continuable_error_2(Lisp_Object, const char *,
2970                                             Lisp_Object, Lisp_Object);
2971 Lisp_Object maybe_signal_type_continuable_error_2(Lisp_Object, const char *,
2972                                                   Lisp_Object, Lisp_Object,
2973                                                   Lisp_Object, Error_behavior);
2974 DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(error(const char *,
2975                                                        ...), 1, 2);
2976 void maybe_error(Lisp_Object, Error_behavior, const char *,
2977                  ...) PRINTF_ARGS(3, 4);
2978 Lisp_Object continuable_error(const char *, ...) PRINTF_ARGS(1, 2);
2979 Lisp_Object maybe_continuable_error(Lisp_Object, Error_behavior,
2980                                     const char *, ...) PRINTF_ARGS(3, 4);
2981 DECLARE_DOESNT_RETURN(signal_simple_error(const char *, Lisp_Object));
2982 void maybe_signal_simple_error(const char *, Lisp_Object,
2983                                Lisp_Object, Error_behavior);
2984 Lisp_Object signal_simple_continuable_error(const char *, Lisp_Object);
2985 Lisp_Object maybe_signal_simple_continuable_error(const char *, Lisp_Object,
2986                                                   Lisp_Object, Error_behavior);
2987 DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(error_with_frob
2988                                                  (Lisp_Object, const char *,
2989                                                   ...), 2, 3);
2990 void maybe_error_with_frob(Lisp_Object, Lisp_Object, Error_behavior,
2991                            const char *, ...) PRINTF_ARGS(4, 5);
2992 Lisp_Object continuable_error_with_frob(Lisp_Object, const char *,
2993                                         ...) PRINTF_ARGS(2, 3);
2994 Lisp_Object maybe_continuable_error_with_frob
2995     (Lisp_Object, Lisp_Object, Error_behavior, const char *, ...) PRINTF_ARGS(4,
2996                                                                               5);
2997 DECLARE_DOESNT_RETURN(signal_simple_error_2
2998                       (const char *, Lisp_Object, Lisp_Object));
2999 void maybe_signal_simple_error_2(const char *, Lisp_Object, Lisp_Object,
3000                                  Lisp_Object, Error_behavior);
3001 Lisp_Object signal_simple_continuable_error_2(const char *, Lisp_Object,
3002                                               Lisp_Object);
3003 Lisp_Object maybe_signal_simple_continuable_error_2(const char *, Lisp_Object,
3004                                                     Lisp_Object, Lisp_Object,
3005                                                     Error_behavior);
3006 DECLARE_DOESNT_RETURN(signal_malformed_list_error(Lisp_Object));
3007 DECLARE_DOESNT_RETURN(signal_malformed_property_list_error(Lisp_Object));
3008 DECLARE_DOESNT_RETURN(signal_circular_list_error(Lisp_Object));
3009 DECLARE_DOESNT_RETURN(signal_circular_property_list_error(Lisp_Object));
3010
3011 DECLARE_DOESNT_RETURN(syntax_error(const char *reason, Lisp_Object frob));
3012 DECLARE_DOESNT_RETURN(syntax_error_2(const char *reason, Lisp_Object frob1,
3013                                      Lisp_Object frob2));
3014 DECLARE_DOESNT_RETURN(invalid_argument(const char *reason, Lisp_Object frob));
3015 DECLARE_DOESNT_RETURN(invalid_argument_2(const char *reason,
3016                                          Lisp_Object frob1, Lisp_Object frob2));
3017 DECLARE_DOESNT_RETURN(invalid_operation(const char *reason, Lisp_Object frob));
3018 DECLARE_DOESNT_RETURN(invalid_operation_2(const char *reason,
3019                                           Lisp_Object frob1,
3020                                           Lisp_Object frob2));
3021 DECLARE_DOESNT_RETURN(invalid_change(const char *reason, Lisp_Object frob));
3022 DECLARE_DOESNT_RETURN(invalid_change_2(const char *reason,
3023                                        Lisp_Object frob1, Lisp_Object frob2));
3024
3025 Lisp_Object signal_void_function_error(Lisp_Object);
3026 Lisp_Object signal_invalid_function_error(Lisp_Object);
3027 Lisp_Object signal_wrong_number_of_arguments_error(Lisp_Object, int);
3028
3029 Lisp_Object run_hook_with_args_in_buffer(struct buffer *, int, Lisp_Object *,
3030                                          enum run_hooks_condition);
3031 Lisp_Object run_hook_with_args(int, Lisp_Object *, enum run_hooks_condition);
3032 void va_run_hook_with_args(Lisp_Object, int, ...);
3033 void va_run_hook_with_args_in_buffer(struct buffer *, Lisp_Object, int, ...);
3034 Lisp_Object run_hook(Lisp_Object);
3035 Lisp_Object apply1(Lisp_Object, Lisp_Object);
3036 Lisp_Object call0(Lisp_Object);
3037 Lisp_Object call1(Lisp_Object, Lisp_Object);
3038 Lisp_Object call2(Lisp_Object, Lisp_Object, Lisp_Object);
3039 Lisp_Object call3(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3040 Lisp_Object call4(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3041                   Lisp_Object);
3042 Lisp_Object call5(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3043                   Lisp_Object, Lisp_Object);
3044 Lisp_Object call6(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3045                   Lisp_Object, Lisp_Object, Lisp_Object);
3046 Lisp_Object call7(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3047                   Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3048 Lisp_Object call8(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3049                   Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3050                   Lisp_Object);
3051 Lisp_Object call0_in_buffer(struct buffer *, Lisp_Object);
3052 Lisp_Object call1_in_buffer(struct buffer *, Lisp_Object, Lisp_Object);
3053 Lisp_Object call2_in_buffer(struct buffer *, Lisp_Object, Lisp_Object,
3054                             Lisp_Object);
3055 Lisp_Object call3_in_buffer(struct buffer *, Lisp_Object, Lisp_Object,
3056                             Lisp_Object, Lisp_Object);
3057 Lisp_Object call4_in_buffer(struct buffer *, Lisp_Object, Lisp_Object,
3058                             Lisp_Object, Lisp_Object, Lisp_Object);
3059 Lisp_Object call5_in_buffer(struct buffer *, Lisp_Object, Lisp_Object,
3060                             Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
3061 Lisp_Object call6_in_buffer(struct buffer *, Lisp_Object, Lisp_Object,
3062                             Lisp_Object, Lisp_Object, Lisp_Object,
3063                             Lisp_Object, Lisp_Object);
3064 Lisp_Object eval_in_buffer(struct buffer *, Lisp_Object);
3065 Lisp_Object call0_with_handler(Lisp_Object, Lisp_Object);
3066 Lisp_Object call1_with_handler(Lisp_Object, Lisp_Object, Lisp_Object);
3067 Lisp_Object eval_in_buffer_trapping_errors(char*, struct buffer *, Lisp_Object);
3068 Lisp_Object run_hook_trapping_errors(char*, Lisp_Object);
3069 Lisp_Object safe_run_hook_trapping_errors(char*, Lisp_Object, int);
3070 Lisp_Object call0_trapping_errors(char*, Lisp_Object);
3071 Lisp_Object call1_trapping_errors(char*, Lisp_Object, Lisp_Object);
3072 Lisp_Object call2_trapping_errors(char*,
3073                                   Lisp_Object, Lisp_Object, Lisp_Object);
3074 Lisp_Object call3_trapping_errors(char*,
3075                                   Lisp_Object, Lisp_Object, Lisp_Object,
3076                                   Lisp_Object);
3077 Lisp_Object call_with_suspended_errors(lisp_fn_t, volatile Lisp_Object,
3078                                        Lisp_Object, Error_behavior, int, ...);
3079 /* C Code should be using internal_catch, record_unwind_p, condition_case_1 */
3080 Lisp_Object internal_catch(Lisp_Object, Lisp_Object(*)(Lisp_Object),
3081                            Lisp_Object, int *volatile);
3082 Lisp_Object condition_case_1(Lisp_Object,
3083                              Lisp_Object(*)(Lisp_Object),
3084                              Lisp_Object,
3085                              Lisp_Object(*)(Lisp_Object, Lisp_Object),
3086                              Lisp_Object);
3087 Lisp_Object condition_case_3(Lisp_Object, Lisp_Object, Lisp_Object);
3088 Lisp_Object unbind_to(int, Lisp_Object);
3089 void specbind(Lisp_Object, Lisp_Object);
3090 void record_unwind_protect(Lisp_Object(*)(Lisp_Object), Lisp_Object);
3091 void do_autoload(Lisp_Object, Lisp_Object);
3092 Lisp_Object un_autoload(Lisp_Object);
3093 void warn_when_safe_lispobj(Lisp_Object, Lisp_Object, Lisp_Object);
3094 void warn_when_safe(Lisp_Object, Lisp_Object, const char *,
3095                     ...) PRINTF_ARGS(3, 4);
3096
3097 /* Defined in event-stream.c */
3098 void wait_delaying_user_input(int (*)(void *), void *);
3099 int detect_input_pending(void);
3100 void reset_this_command_keys(Lisp_Object, int);
3101 Lisp_Object enqueue_misc_user_event(Lisp_Object, Lisp_Object, Lisp_Object);
3102 Lisp_Object enqueue_misc_user_event_pos(Lisp_Object, Lisp_Object,
3103                                         Lisp_Object, int, int, int, int);
3104 extern int modifier_keys_are_sticky;
3105
3106 /* Defined in event-Xt.c */
3107 void enqueue_Xt_dispatch_event(Lisp_Object event);
3108 void signal_special_Xt_user_event(Lisp_Object, Lisp_Object, Lisp_Object);
3109
3110 /* Defined in events.c */
3111 void clear_event_resource(void);
3112 Lisp_Object allocate_event(void);
3113
3114 /* Defined in fileio.c */
3115 void record_auto_save(void);
3116 void force_auto_save_soon(void);
3117 DECLARE_DOESNT_RETURN(report_file_error(const char *, Lisp_Object));
3118 void maybe_report_file_error(const char *, Lisp_Object,
3119                              Lisp_Object, Error_behavior);
3120 DECLARE_DOESNT_RETURN(signal_file_error(const char *, Lisp_Object));
3121 void maybe_signal_file_error(const char *, Lisp_Object,
3122                              Lisp_Object, Error_behavior);
3123 DECLARE_DOESNT_RETURN(signal_double_file_error(const char *, const char *,
3124                                                Lisp_Object));
3125 void maybe_signal_double_file_error(const char *, const char *,
3126                                     Lisp_Object, Lisp_Object, Error_behavior);
3127 DECLARE_DOESNT_RETURN(signal_double_file_error_2(const char *, const char *,
3128                                                  Lisp_Object, Lisp_Object));
3129 void maybe_signal_double_file_error_2(const char *, const char *,
3130                                       Lisp_Object, Lisp_Object, Lisp_Object,
3131                                       Error_behavior);
3132 Lisp_Object lisp_strerror(int);
3133 Lisp_Object expand_and_dir_to_file(Lisp_Object, Lisp_Object);
3134 ssize_t read_allowing_quit(int, void *, size_t);
3135 ssize_t write_allowing_quit(int, const void *, size_t);
3136 int internal_delete_file(Lisp_Object);
3137
3138 /* Defined in filelock.c */
3139 void lock_file(Lisp_Object);
3140 void unlock_file(Lisp_Object);
3141 void unlock_all_files(void);
3142 void unlock_buffer(struct buffer *);
3143
3144 /* Defined in filemode.c */
3145 void filemodestring(struct stat *, char *);
3146
3147 /* Defined in fns.c */
3148 Lisp_Object list_sort(Lisp_Object, Lisp_Object,
3149                       int (*)(Lisp_Object, Lisp_Object, Lisp_Object));
3150 Lisp_Object merge(Lisp_Object, Lisp_Object, Lisp_Object);
3151
3152 void bump_string_modiff(Lisp_Object);
3153 Lisp_Object memq_no_quit(Lisp_Object, Lisp_Object);
3154 Lisp_Object assoc_no_quit(Lisp_Object, Lisp_Object);
3155 Lisp_Object assq_no_quit(Lisp_Object, Lisp_Object);
3156 Lisp_Object rassq_no_quit(Lisp_Object, Lisp_Object);
3157 Lisp_Object delq_no_quit(Lisp_Object, Lisp_Object);
3158 Lisp_Object delq_no_quit_and_free_cons(Lisp_Object, Lisp_Object);
3159 Lisp_Object remassoc_no_quit(Lisp_Object, Lisp_Object);
3160 Lisp_Object remassq_no_quit(Lisp_Object, Lisp_Object);
3161 Lisp_Object remrassq_no_quit(Lisp_Object, Lisp_Object);
3162
3163 int plists_differ(Lisp_Object, Lisp_Object, int, int, int);
3164 Lisp_Object internal_plist_get(Lisp_Object, Lisp_Object);
3165 void internal_plist_put(Lisp_Object *, Lisp_Object, Lisp_Object);
3166 int internal_remprop(Lisp_Object *, Lisp_Object);
3167 Lisp_Object external_plist_get(Lisp_Object *, Lisp_Object, int, Error_behavior);
3168 void external_plist_put(Lisp_Object *, Lisp_Object,
3169                         Lisp_Object, int, Error_behavior);
3170 int external_remprop(Lisp_Object *, Lisp_Object, int, Error_behavior);
3171 int internal_equal(Lisp_Object, Lisp_Object, int);
3172 Lisp_Object concat2(Lisp_Object, Lisp_Object);
3173 Lisp_Object concat3(Lisp_Object, Lisp_Object, Lisp_Object);
3174 Lisp_Object vconcat2(Lisp_Object, Lisp_Object);
3175 Lisp_Object vconcat3(Lisp_Object, Lisp_Object, Lisp_Object);
3176 Lisp_Object nconc2(Lisp_Object, Lisp_Object);
3177 Lisp_Object bytecode_nconc2(Lisp_Object *);
3178 void check_losing_bytecode(const char *, Lisp_Object);
3179
3180 /* Defined in glyphs.c */
3181 Error_behavior decode_error_behavior_flag(Lisp_Object);
3182 Lisp_Object encode_error_behavior_flag(Error_behavior);
3183
3184 /* Defined in indent.c */
3185 int bi_spaces_at_point(struct buffer *, Bytind);
3186 int column_at_point(struct buffer *, Bufpos, int);
3187 int string_column_at_point(Lisp_String *, Bufpos, int);
3188 int current_column(struct buffer *);
3189 void invalidate_current_column(void);
3190 Bufpos vmotion(struct window *, Bufpos, int, int *);
3191 Bufpos vmotion_pixels(Lisp_Object, Bufpos, int, int, int *);
3192
3193 /* Defined in keymap.c */
3194 void where_is_to_char(Lisp_Object, char *);
3195
3196 /* Defined in lread.c */
3197 void ebolify_bytecode_constants(Lisp_Object);
3198 void close_load_descs(void);
3199 int locate_file(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object *, int);
3200 EXFUN(Flocate_file_clear_hashing, 1);
3201 int isfloat_string(const char *);
3202 #if defined HAVE_MPQ && defined WITH_GMP
3203 int isbigq_string(const char *);
3204 #endif
3205 #if defined HAVE_MPC && defined WITH_MPC ||     \
3206         defined HAVE_PSEUC && defined WITH_PSEUC
3207 int isbigc_string(const char *);
3208 #endif
3209 #if defined HAVE_PSEUG && defined WITH_PSEUG
3210 int isgaussian_string(const char *);
3211 #endif
3212
3213 /* Well, I've decided to enable this. -- ben */
3214 /* And I've decided to make it work right.  -- sb */
3215 #define LOADHIST
3216 /* Define the following symbol to enable load history of dumped files */
3217 #define LOADHIST_DUMPED
3218 /* Define the following symbol to enable load history of C source */
3219 #define LOADHIST_BUILTIN
3220
3221 #ifdef LOADHIST                 /* this is just a stupid idea */
3222 #define LOADHIST_ATTACH(x) \
3223  do { if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); } \
3224  while (0)
3225 #else                           /*! LOADHIST */
3226 # define LOADHIST_ATTACH(x)
3227 #endif                          /*! LOADHIST */
3228
3229 /* Defined in marker.c */
3230 Bytind bi_marker_position(Lisp_Object);
3231 Bufpos marker_position(Lisp_Object);
3232 void set_bi_marker_position(Lisp_Object, Bytind);
3233 void set_marker_position(Lisp_Object, Bufpos);
3234 void unchain_marker(Lisp_Object);
3235 Lisp_Object noseeum_copy_marker(Lisp_Object, Lisp_Object);
3236 Lisp_Object set_marker_restricted(Lisp_Object, Lisp_Object, Lisp_Object);
3237 #ifdef MEMORY_USAGE_STATS
3238 int compute_buffer_marker_usage(struct buffer *, struct overhead_stats *);
3239 #endif
3240
3241 /* Defined in menubar.c */
3242 extern int popup_menu_up_p;
3243 extern int menubar_show_keybindings;
3244 extern int popup_menu_titles;
3245
3246 /* Defined in minibuf.c */
3247 extern int minibuf_level;
3248 Charcount scmp_1(const Bufbyte *, const Bufbyte *, Charcount, int);
3249 #define scmp(s1, s2, len) scmp_1 (s1, s2, len, completion_ignore_case)
3250 extern int completion_ignore_case;
3251 int regexp_ignore_completion_p(const Bufbyte *, Lisp_Object,
3252                                Bytecount, Bytecount);
3253 Lisp_Object clear_echo_area(struct frame *, Lisp_Object, int);
3254 Lisp_Object clear_echo_area_from_print(struct frame *, Lisp_Object, int);
3255 void echo_area_append(struct frame *, const Bufbyte *, Lisp_Object,
3256                       Bytecount, Bytecount, Lisp_Object);
3257 void echo_area_message(struct frame *, const Bufbyte *, Lisp_Object,
3258                        Bytecount, Bytecount, Lisp_Object);
3259 Lisp_Object echo_area_status(struct frame *);
3260 int echo_area_active(struct frame *);
3261 Lisp_Object echo_area_contents(struct frame *);
3262 void message_internal(const Bufbyte *, Lisp_Object, Bytecount, Bytecount);
3263 void message_append_internal(const Bufbyte *, Lisp_Object,
3264                              Bytecount, Bytecount);
3265 void message(const char *, ...) PRINTF_ARGS(1, 2);
3266 void message_append(const char *, ...) PRINTF_ARGS(1, 2);
3267 void message_no_translate(const char *, ...) PRINTF_ARGS(1, 2);
3268 void clear_message(void);
3269
3270 /* Defined in print.c */
3271 void write_string_to_stdio_stream(FILE *, struct console *,
3272                                   const Bufbyte *, Bytecount, Bytecount,
3273                                   Lisp_Object, int);
3274 void debug_print(Lisp_Object);
3275 void debug_short_backtrace(int);
3276 void temp_output_buffer_setup(Lisp_Object);
3277 void temp_output_buffer_show(Lisp_Object, Lisp_Object);
3278 /* NOTE: Do not call this with the data of a Lisp_String.  Use princ.
3279  * Note: stream should be defaulted before calling
3280  *  (eg Qnil means stdout, not Vstandard_output, etc) */
3281 void write_c_string(const char *, Lisp_Object);
3282 void write_hex_ptr(void*, Lisp_Object);
3283 int write_fmt_str(Lisp_Object,const char *,...) PRINTF_ARGS(2, 3);
3284 int write_fmt_string(Lisp_Object,const char *,...) PRINTF_ARGS(2, 3);
3285 /* Same goes for this function. */
3286 void write_string_1(const Bufbyte *, Bytecount, Lisp_Object);
3287 void print_cons(Lisp_Object, Lisp_Object, int);
3288 void print_vector(Lisp_Object, Lisp_Object, int);
3289 void print_string(Lisp_Object, Lisp_Object, int);
3290 char *long_to_string(char *, long, int);
3291 void print_internal(Lisp_Object, Lisp_Object, int);
3292 void print_symbol(Lisp_Object, Lisp_Object, int);
3293 /* The number of bytes required to store the decimal printed
3294  * representation of an integral type.  Add a few bytes for truncation,
3295  * optional sign prefix, and null byte terminator.
3296  * 2.40824 == log (256) / log (10).
3297  *
3298  * We don't use floating point since Sun cc (buggily?) cannot use
3299  * floating point computations to define a compile-time integral
3300  * constant.
3301  */
3302 #define DECIMAL_PRINT_SIZE(integral_type) \
3303 (((2410824 * sizeof (integral_type)) / 1000000) + 3)
3304 extern int print_escape_newlines;
3305 extern int print_readably;
3306 Lisp_Object internal_with_output_to_temp_buffer(Lisp_Object,
3307                                                 Lisp_Object(*)(Lisp_Object),
3308                                                 Lisp_Object, Lisp_Object);
3309 void internal_object_printer(Lisp_Object, Lisp_Object, int);
3310
3311 /* Defined in profile.c */
3312 void mark_profiling_info(void);
3313 void profile_increase_call_count(Lisp_Object);
3314 extern int profiling_active;
3315 extern int profiling_redisplay_flag;
3316
3317 /* Defined in rangetab.c */
3318 void put_range_table(Lisp_Object, EMACS_INT, EMACS_INT, Lisp_Object);
3319 int unified_range_table_bytes_needed(Lisp_Object);
3320 int unified_range_table_bytes_used(const void*);
3321 void unified_range_table_copy_data(Lisp_Object, void *);
3322 Lisp_Object unified_range_table_lookup(void *, EMACS_INT, Lisp_Object);
3323 int unified_range_table_nentries(void*);
3324 void unified_range_table_get_range(void *, int, EMACS_INT *, EMACS_INT *,
3325                                    Lisp_Object *);
3326
3327 /* Defined in search.c */
3328 struct re_pattern_buffer;
3329 struct re_registers;
3330 Bufpos scan_buffer(struct buffer *, Emchar, Bufpos, Bufpos, EMACS_INT,
3331                    EMACS_INT *, int);
3332 Bufpos find_next_newline(struct buffer *, Bufpos, int);
3333 Bufpos find_next_newline_no_quit(struct buffer *, Bufpos, int);
3334 Bytind bi_find_next_newline_no_quit(struct buffer *, Bytind, int);
3335 Bytind bi_find_next_emchar_in_string(Lisp_String *, Emchar, Bytind, EMACS_INT);
3336 Bufpos find_before_next_newline(struct buffer *, Bufpos, Bufpos, int);
3337 struct re_pattern_buffer *compile_pattern(Lisp_Object, struct re_registers *,
3338                                           Lisp_Object, int, Error_behavior);
3339 Bytecount fast_string_match(Lisp_Object, const Bufbyte *,
3340                             Lisp_Object, Bytecount,
3341                             Bytecount, int, Error_behavior, int);
3342 Bytecount fast_lisp_string_match(Lisp_Object, Lisp_Object);
3343 void restore_match_data(void);
3344
3345 /* Defined in signal.c */
3346 void init_interrupts_late(void);
3347 extern int dont_check_for_quit;
3348 void begin_dont_check_for_quit(void);
3349 void emacs_sleep(int);
3350
3351 /* Defined in sound.c */
3352 void init_device_sound(struct device *);
3353
3354 /* Defined in specifier.c */
3355 Lisp_Object specifier_instance(Lisp_Object, Lisp_Object, Lisp_Object,
3356                                Error_behavior, int, int, Lisp_Object);
3357 Lisp_Object specifier_instance_no_quit(Lisp_Object, Lisp_Object, Lisp_Object,
3358                                        Error_behavior, int, Lisp_Object);
3359
3360 /* Defined in symbols.c */
3361 long unsigned int hash_string(const Bufbyte*, Bytecount);
3362 Lisp_Object intern(const char *);
3363 Lisp_Object oblookup(Lisp_Object, const Bufbyte *, Bytecount);
3364 void map_obarray(Lisp_Object, int (*)(Lisp_Object, void *), void *);
3365 Lisp_Object indirect_function(Lisp_Object, int);
3366 Lisp_Object symbol_value_in_buffer(Lisp_Object, Lisp_Object);
3367 void kill_buffer_local_variables(struct buffer *);
3368 int symbol_value_buffer_local_info(Lisp_Object, struct buffer *);
3369 Lisp_Object find_symbol_value(Lisp_Object);
3370 Lisp_Object find_symbol_value_quickly(Lisp_Object, int);
3371 Lisp_Object top_level_value(Lisp_Object);
3372 void reject_constant_symbols(Lisp_Object sym, Lisp_Object newval,
3373                              int function_p,
3374                              Lisp_Object follow_past_lisp_magic);
3375
3376 /* Defined in syntax.c */
3377 Bufpos scan_words(struct buffer *, Bufpos, int);
3378
3379 /* Defined in undo.c */
3380 Lisp_Object truncate_undo_list(Lisp_Object, int, int);
3381 void record_extent(Lisp_Object, int);
3382 void record_insert(struct buffer *, Bufpos, Charcount);
3383 void record_delete(struct buffer *, Bufpos, Charcount);
3384 void record_change(struct buffer *, Bufpos, Charcount);
3385
3386 /* Defined in unex*.c */
3387 int unexec(char *, char *, uintptr_t, uintptr_t, uintptr_t);
3388 #ifdef RUN_TIME_REMAP
3389 int run_time_remap(char *);
3390 #endif
3391
3392 /* Defined in vm-limit.c */
3393 void memory_warnings(void *, void (*)(const char *));
3394
3395 /* Defined in window.c */
3396 Lisp_Object save_window_excursion_unwind(Lisp_Object);
3397 Lisp_Object display_buffer(Lisp_Object, Lisp_Object, Lisp_Object);
3398
3399 /*--------------- prototypes for Lisp primitives in C ------------*/
3400
3401 /* The following were machine generated 19980312 */
3402
3403 EXFUN(Faccept_process_output, 3);
3404 EXFUN(Fadd1, 1);
3405 EXFUN(Fadd_spec_to_specifier, 5);
3406 EXFUN(Fadd_timeout, 4);
3407 EXFUN(Fappend, MANY);
3408 EXFUN(Fapply, MANY);
3409 EXFUN(Faref, 2);
3410 EXFUN(Faset, 3);
3411 EXFUN(Fassoc, 2);
3412 EXFUN(Fassq, 2);
3413 EXFUN(Fbacktrace, 2);
3414 EXFUN(Fbeginning_of_line, 2);
3415 EXFUN(Fbobp, 1);
3416 EXFUN(Fbolp, 1);
3417 EXFUN(Fboundp, 1);
3418 EXFUN(Fbuffer_substring, 3);
3419 EXFUN(Fbuilt_in_variable_type, 1);
3420 EXFUN(Fbyte_code, 3);
3421 EXFUN(Fcall_interactively, 3);
3422 EXFUN(Fcanonicalize_lax_plist, 2);
3423 EXFUN(Fcanonicalize_plist, 2);
3424 EXFUN(Fcar, 1);
3425 EXFUN(Fcar_safe, 1);
3426 EXFUN(Fcdr, 1);
3427 EXFUN (Fcdr_safe, 1);
3428 EXFUN(Fchar_after, 2);
3429 EXFUN(Fchar_to_string, 1);
3430 EXFUN(Fcheck_valid_plist, 1);
3431 EXFUN(Fvalid_plist_p, 1);
3432 EXFUN(Fclear_range_table, 1);
3433 EXFUN(Fcoding_category_list, 0);
3434 EXFUN(Fcoding_category_system, 1);
3435 EXFUN(Fcoding_priority_list, 0);
3436 EXFUN(Fcoding_system_charset, 2);
3437 EXFUN(Fcoding_system_doc_string, 1);
3438 EXFUN(Fcoding_system_list, 0);
3439 EXFUN(Fcoding_system_name, 1);
3440 EXFUN(Fcoding_system_p, 1);
3441 EXFUN(Fcoding_system_property, 2);
3442 EXFUN(Fcoding_system_type, 1);
3443 EXFUN(Fcommand_execute, 3);
3444 EXFUN(Fcommandp, 1);
3445 EXFUN(Fconcat, MANY);
3446 EXFUN(Fcons, 2);
3447 EXFUN(Fcopy_alist, 1);
3448 EXFUN(Fcopy_coding_system, 2);
3449 EXFUN(Fcopy_event, 2);
3450 EXFUN(Fcopy_list, 1);
3451 EXFUN(Fcopy_marker, 2);
3452 EXFUN(Fcopy_sequence, 1);
3453 EXFUN(Fcopy_tree, 2);
3454 EXFUN(Fcurrent_window_configuration, 1);
3455 EXFUN(Fdecode_big5_char, 1);
3456 EXFUN(Fdecode_coding_region, 4);
3457 EXFUN(Fdecode_shift_jis_char, 1);
3458 EXFUN(Fdefault_boundp, 1);
3459 EXFUN(Fdefault_value, 1);
3460 EXFUN(Fdefine_key, 3);
3461 EXFUN(Fdelete, 2);
3462 EXFUN(Fdelete_region, 3);
3463 EXFUN(Fdelete_process, 1);
3464 EXFUN(Fdelq, 2);
3465 EXFUN(Fdestructive_alist_to_plist, 1);
3466 EXFUN(Fdetect_coding_region, 3);
3467 EXFUN(Fdgettext, 2);
3468 EXFUN(Fding, 3);
3469 EXFUN(Fdirectory_file_name, 1);
3470 EXFUN(Fdisable_timeout, 1);
3471 EXFUN(Fdiscard_input, 0);
3472 EXFUN(Fdispatch_event, 1);
3473 EXFUN(Fdisplay_error, 2);
3474 EXFUN(Fdo_auto_save, 2);
3475 EXFUN(Fdowncase, 2);
3476 EXFUN(Felt, 2);
3477 EXFUN(Fencode_big5_char, 1);
3478 EXFUN(Fencode_coding_region, 4);
3479 EXFUN(Fencode_shift_jis_char, 1);
3480 EXFUN(Fend_of_line, 2);
3481 EXFUN(Fenqueue_eval_event, 2);
3482 EXFUN(Feobp, 1);
3483 EXFUN(Feolp, 1);
3484 EXFUN(Fequal, 2);
3485 EXFUN(Ferror_message_string, 1);
3486 EXFUN(Feval, 1);
3487 EXFUN(Fevent_to_character, 4);
3488 EXFUN(Fexecute_kbd_macro, 2);
3489 EXFUN(Fexpand_abbrev, 0);
3490 EXFUN(Fexpand_file_name, 2);
3491 EXFUN(Fextent_at, 5);
3492 EXFUN(Fextent_property, 3);
3493 EXFUN(Ffboundp, 1);
3494 EXFUN(Ffile_accessible_directory_p, 1);
3495 EXFUN(Ffile_directory_p, 1);
3496 EXFUN(Ffile_executable_p, 1);
3497 EXFUN(Ffile_exists_p, 1);
3498 EXFUN(Ffile_name_absolute_p, 1);
3499 EXFUN(Ffile_name_as_directory, 1);
3500 EXFUN(Ffile_name_directory, 1);
3501 EXFUN(Ffile_name_nondirectory, 1);
3502 EXFUN(Ffile_readable_p, 1);
3503 EXFUN(Ffile_symlink_p, 1);
3504 EXFUN(Ffile_truename, 2);
3505 EXFUN(Ffind_coding_system, 1);
3506 EXFUN(Ffind_file_name_handler, 2);
3507 EXFUN(Ffollowing_char, 1);
3508 EXFUN(Fformat, MANY);
3509 EXFUN(Fforward_char, 2);
3510 EXFUN(Fforward_line, 2);
3511 EXFUN(Ffset, 2);
3512 EXFUN(Ffuncall, MANY);
3513 EXFUN(Ffunctionp, 1);
3514 EXFUN(Fgeq, MANY);
3515 EXFUN(Fget, 3);
3516 EXFUN(Fget_buffer_process, 1);
3517 EXFUN(Fget_coding_system, 1);
3518 EXFUN(Fget_process, 1);
3519 EXFUN(Fget_range_table, 3);
3520 EXFUN(Fgettext, 1);
3521 EXFUN(Fgoto_char, 2);
3522 EXFUN(Fgtr, MANY);
3523 EXFUN(Findent_to, 3);
3524 EXFUN(Findirect_function, 1);
3525 EXFUN(Finsert, MANY);
3526 EXFUN(Finsert_buffer_substring, 3);
3527 EXFUN(Finsert_char, 4);
3528 EXFUN(Finsert_file_contents_internal, 7);
3529 EXFUN(Finteractive_p, 0);
3530 EXFUN(Fintern, 2);
3531 EXFUN(Fintern_soft, 2);
3532 EXFUN(Fkey_description, 1);
3533 EXFUN(Fkill_emacs, 1);
3534 EXFUN(Fkill_local_variable, 1);
3535 EXFUN(Flast, 2);
3536 EXFUN(Flax_plist_get, 3);
3537 EXFUN(Flax_plist_remprop, 2);
3538 EXFUN(Flength, 1);
3539 EXFUN(Fleq, MANY);
3540 EXFUN(Flist, MANY);
3541 EXFUN(Flistp, 1);
3542 EXFUN(Flist_modules, 0);
3543 EXFUN(Fload_module, 3);
3544 EXFUN(Flookup_key, 3);
3545 EXFUN(Flss, MANY);
3546 EXFUN(Fmake_byte_code, MANY);
3547 EXFUN(Fmake_coding_system, 4);
3548 EXFUN(Fmake_glyph_internal, 1);
3549 EXFUN(Fmake_list, 2);
3550 EXFUN(Fmake_marker, 0);
3551 EXFUN(Fmake_range_table, 0);
3552 EXFUN(Fmake_sparse_keymap, 1);
3553 EXFUN(Fmake_string, 2);
3554 EXFUN(Fmake_symbol, 1);
3555 EXFUN(Fmake_vector, 2);
3556 EXFUN(Fmapcar, 2);
3557 EXFUN(Fmarker_buffer, 1);
3558 EXFUN(Fmarker_position, 1);
3559 EXFUN(Fmatch_beginning, 1);
3560 EXFUN(Fmatch_end, 1);
3561 EXFUN(Fmax, MANY);
3562 EXFUN(Fmember, 2);
3563 EXFUN(Fmemq, 2);
3564 EXFUN(Fmin, MANY);
3565 EXFUN(Fminus, MANY);
3566 EXFUN(Fnarrow_to_region, 3);
3567 EXFUN(Fnconc, MANY);
3568 EXFUN(Fnext_event, 2);
3569 EXFUN(Fnonnegativep, 1);
3570 EXFUN(Fnreverse, 1);
3571 EXFUN(Fnthcdr, 2);
3572 EXFUN(Fnumber_to_string, 1);
3573 EXFUN(Fold_assq, 2);
3574 EXFUN(Fold_equal, 2);
3575 EXFUN(Fold_member, 2);
3576 EXFUN(Fold_memq, 2);
3577 EXFUN(Fplist_get, 3);
3578 EXFUN(Fplist_member, 2);
3579 EXFUN(Fplist_put, 3);
3580 EXFUN(Fpoint, 1);
3581 EXFUN(Fpoint_marker, 2);
3582 EXFUN(Fpoint_max, 1);
3583 EXFUN(Fpoint_min, 1);
3584 EXFUN(Fpow, 2);
3585 EXFUN(Fpreceding_char, 1);
3586 EXFUN(Fprefix_numeric_value, 1);
3587 EXFUN(Fprin1, 2);
3588 EXFUN(Fprin1_to_string, 2);
3589 EXFUN(Fprinc, 2);
3590 EXFUN(Fprint, 2);
3591 EXFUN(Fprocess_status, 1);
3592 EXFUN(Fprogn, UNEVALLED);
3593 EXFUN(Fprovide, 1);
3594 EXFUN(Fput, 3);
3595 EXFUN(Fput_range_table, 4);
3596 EXFUN(Fput_text_property, 5);
3597 EXFUN(Fquo, MANY);
3598 EXFUN(Frassq, 2);
3599 EXFUN(Fread, 1);
3600 EXFUN(Fread_key_sequence, 3);
3601 EXFUN(Freally_free, 1);
3602 EXFUN(Frem, 2);
3603 EXFUN(Fremassq, 2);
3604 EXFUN(Freplace_list, 2);
3605 EXFUN(Frevoke, 1);
3606 EXFUN(Fselected_frame, 1);
3607 EXFUN(Fset, 2);
3608 EXFUN(Fset_coding_category_system, 2);
3609 EXFUN(Fset_coding_priority_list, 1);
3610 EXFUN(Fset_default, 2);
3611 EXFUN(Fset_marker, 3);
3612 EXFUN(Fset_standard_case_table, 1);
3613 EXFUN(Fsetcar, 2);
3614 EXFUN(Fsetcdr, 2);
3615 EXFUN(Fsignal, 2);
3616 EXFUN(Fsit_for, 2);
3617 EXFUN(Fskip_chars_backward, 3);
3618 EXFUN(Fskip_chars_forward, 3);
3619 EXFUN(Fsleep_for, 1);
3620 EXFUN(Fsort, 2);
3621 EXFUN(Fspecifier_spec_list, 4);
3622 EXFUN(Fstring_equal, 2);
3623 EXFUN(Fstring_lessp, 2);
3624 EXFUN(Fstring_match, 4);
3625 EXFUN(Fsub1, 1);
3626 EXFUN(Fsubr_max_args, 1);
3627 EXFUN(Fsubr_min_args, 1);
3628 EXFUN(Fsubsidiary_coding_system, 2);
3629 EXFUN(Fsubstitute_command_keys, 1);
3630 EXFUN(Fsubstitute_in_file_name, 1);
3631 EXFUN(Fsubstring, 3);
3632 EXFUN(Fsymbol_function, 1);
3633 EXFUN(Fsymbol_name, 1);
3634 EXFUN(Fsymbol_plist, 1);
3635 EXFUN(Fsymbol_value, 1);
3636 EXFUN(Fsystem_name, 0);
3637 EXFUN(Fthrow, 2);
3638 EXFUN(Ftimes, MANY);
3639 EXFUN(Ftruncate, 1);
3640 EXFUN(Fundo_boundary, 0);
3641 EXFUN(Funhandled_file_name_directory, 1);
3642 EXFUN(Funlock_buffer, 0);
3643 EXFUN(Fupcase, 2);
3644 EXFUN(Fupcase_initials, 2);
3645 EXFUN(Fupcase_initials_region, 3);
3646 EXFUN(Fupcase_region, 3);
3647 EXFUN(Fuser_home_directory, 0);
3648 EXFUN(Fuser_login_name, 1);
3649 EXFUN(Fuser_group_name, 1);
3650 EXFUN(Fvector, MANY);
3651 EXFUN(Fverify_visited_file_modtime, 1);
3652 EXFUN(Fvertical_motion, 3);
3653 EXFUN(Fwiden, 1);
3654
3655 /*--------------- prototypes for constant symbols  ------------*/
3656
3657 extern Lisp_Object Q_style;
3658 extern Lisp_Object Qactivate_menubar_hook;
3659 extern Lisp_Object Qafter_change_major_mode_hook;
3660 extern Lisp_Object Qarith_error;
3661 extern Lisp_Object Qarrayp, Qautoload;
3662 extern Lisp_Object Qbackground, Qbackground_pixmap;
3663 extern Lisp_Object Qbeginning_of_buffer, Qbig5;
3664 extern Lisp_Object Qbitp, Qblinking;
3665 extern Lisp_Object Qbuffer_glyph_p, Qbuffer_live_p, Qbuffer_read_only;
3666 extern Lisp_Object Qbyte_code, Qcall_interactively;
3667 extern Lisp_Object Qcategory_designator_p, Qcategory_table_value_p, Qccl, Qcdr;
3668 extern Lisp_Object Qchar_or_string_p, Qcharacterp;
3669 extern Lisp_Object Qcharset_g0, Qcharset_g1, Qcharset_g2, Qcharset_g3;
3670 extern Lisp_Object Qcircular_list, Qcircular_property_list;
3671 extern Lisp_Object Qcoding_system_error;
3672 extern Lisp_Object Qcolor_pixmap_image_instance_p;
3673 extern Lisp_Object Qcommandp, Qcompletion_ignore_case;
3674 extern Lisp_Object Qconsole_live_p, Qconst_specifier, Qcr;
3675 extern Lisp_Object Qcrlf, Qcurrent_menubar, Qctext;
3676 extern Lisp_Object Qcyclic_variable_indirection, Qdecode;
3677 extern Lisp_Object Qdefun, Qdevice_live_p;
3678 extern Lisp_Object Qdictp;
3679 extern Lisp_Object Qdim, Qdisabled, Qdisplay_table;
3680 extern Lisp_Object Qdomain_error;
3681 extern Lisp_Object Qediting_error;
3682 extern Lisp_Object Qencode, Qend_of_buffer, Qend_of_file, Qend_open;
3683 extern Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf, Qeol_type;
3684 extern Lisp_Object Qerror, Qerror_conditions, Qerror_message, Qescape_quoted;
3685 extern Lisp_Object Qevent_live_p, Qexit, Qextent_live_p;
3686 extern Lisp_Object Qexternal_debugging_output, Qfeaturep;
3687 extern Lisp_Object Qfile_error;
3688 extern Lisp_Object Qforce_g0_on_output, Qforce_g1_on_output;
3689 extern Lisp_Object Qforce_g2_on_output, Qforce_g3_on_output, Qforeground;
3690 extern Lisp_Object Qformat, Qframe_live_p;
3691 extern Lisp_Object Qicon_glyph_p, Qidentity;
3692 extern Lisp_Object Qinhibit_quit, Qinhibit_read_only;
3693 extern Lisp_Object Qinput_charset_conversion;
3694 extern Lisp_Object Qinteger_char_or_marker_p, Qinteger_or_char_p;
3695 extern Lisp_Object Qinteger_or_marker_p, Qintegerp, Qinteractive;
3696 extern Lisp_Object Qinternal_error, Qinvalid_argument;
3697 extern Lisp_Object Qinvalid_change, Qinvalid_function, Qinvalid_operation;
3698 extern Lisp_Object Qinvalid_byte_code, Qinvalid_read_syntax, Qinvalid_state;
3699 extern Lisp_Object Qio_error;
3700 extern Lisp_Object Qiso2022;
3701 extern Lisp_Object Qip_any;
3702 extern Lisp_Object Qlambda, Qlayout;
3703 extern Lisp_Object Qlf;
3704 extern Lisp_Object Qlist_formation_error;
3705 extern Lisp_Object Qlistp, Qload, Qlocalhost, Qlock_shift, Qmacro;
3706 extern Lisp_Object Qmakunbound, Qmalformed_list, Qmalformed_property_list;
3707 extern Lisp_Object Qmark;
3708 extern Lisp_Object Qmnemonic;
3709 extern Lisp_Object Qmono_pixmap_image_instance_p;
3710 extern Lisp_Object Qmouse_leave_buffer_hook;
3711 extern Lisp_Object Qnas, Qnatnump, Qnative_layout;
3712 extern Lisp_Object Qno_ascii_cntl, Qno_ascii_eol, Qno_catch;
3713 extern Lisp_Object Qno_conversion, Qno_iso6429;
3714 extern Lisp_Object Qnonnegativep, Qnothing_image_instance_p;
3715 extern Lisp_Object Qnumber_char_or_marker_p, Qnumberp;
3716 extern Lisp_Object Qoutput_charset_conversion;
3717 extern Lisp_Object Qoverflow_error, Qpoint, Qpointer_glyph_p;
3718 extern Lisp_Object Qpointer_image_instance_p, Qpositivep, Qpost_read_conversion;
3719 extern Lisp_Object Qpre_write_conversion, Qprint_length;
3720 extern Lisp_Object Qprint_string_length, Qprogn, Qquit;
3721 extern Lisp_Object Qquote, Qrange_error, Qread_char;
3722 extern Lisp_Object Qread_from_minibuffer, Qreally_early_error_handler;
3723 extern Lisp_Object Qregion_beginning, Qregion_end;
3724 extern Lisp_Object Qrun_hooks, Qsans_modifiers;
3725 extern Lisp_Object Qsave_buffers_kill_emacs;
3726 extern Lisp_Object Qself_insert_command, Qself_insert_defer_undo;
3727 extern Lisp_Object Qsequencep, Qset, Qsetting_constant;
3728 extern Lisp_Object Qseven, Qshift_jis;
3729 extern Lisp_Object Qsingularity_error;
3730 extern Lisp_Object Qstandard_input, Qstandard_output;
3731 extern Lisp_Object Qstart_open;
3732 extern Lisp_Object Qstring_greaterp, Qstring_lessp, Qsubwindow;
3733 extern Lisp_Object Qsubwindow_image_instance_p;
3734 extern Lisp_Object Qsyntax_error, Qt;
3735 extern Lisp_Object Qtext_image_instance_p;
3736 extern Lisp_Object Qtop_level;
3737 extern Lisp_Object Qtrue_list_p;
3738 extern Lisp_Object Qunbound, Qunderflow_error;
3739 extern Lisp_Object Qunderline, Quser_files_and_directories;
3740 extern Lisp_Object Qvalues;
3741 extern Lisp_Object Qvariable_documentation, Qvariable_domain;
3742 extern Lisp_Object Qvoid_function, Qvoid_variable;
3743 extern Lisp_Object Qwindow_live_p, Qwrong_number_of_arguments;
3744 extern Lisp_Object Qwrong_type_argument, Qyes_or_no_p;
3745
3746 #define SYMBOL(fou) extern Lisp_Object fou
3747 #define SYMBOL_KEYWORD(la_cle_est_fou) extern Lisp_Object la_cle_est_fou
3748 #define SYMBOL_GENERAL(tout_le_monde, est_fou) \
3749   extern Lisp_Object tout_le_monde
3750
3751 #include "general-slots.h"
3752
3753 #undef SYMBOL
3754 #undef SYMBOL_KEYWORD
3755 #undef SYMBOL_GENERAL
3756
3757 /*--------------- prototypes for variables of type Lisp_Object  ------------*/
3758
3759 extern Lisp_Object Vactivate_menubar_hook;
3760 extern Lisp_Object Vafter_change_major_mode_hook;
3761 extern Lisp_Object Vautoload_queue, Vblank_menubar;
3762 extern Lisp_Object Vcharset_ascii, Vcharset_composite, Vcharset_control_1;
3763 extern Lisp_Object Vcoding_system_for_read, Vcoding_system_for_write;
3764 extern Lisp_Object Vcoding_system_hash_table, Vcommand_history;
3765 extern Lisp_Object Vcommand_line_args, Vconfigure_info_directory;
3766 extern Lisp_Object Vconfigure_site_module_directory;
3767 extern Lisp_Object Vconsole_list, Vcontrolling_terminal;
3768 extern Lisp_Object Vcurrent_compiled_function_annotation, Vcurrent_load_list;
3769 extern Lisp_Object Vcurrent_mouse_event, Vcurrent_prefix_arg, Vdata_directory;
3770 extern Lisp_Object Vdirectory_sep_char, Vdisabled_command_hook;
3771 extern Lisp_Object Vdoc_directory, Vinternal_doc_file_name;
3772 extern Lisp_Object Vecho_area_buffer, Vemacs_major_version;
3773 extern Lisp_Object Vemacs_minor_version, Vexec_directory, Vexec_path;
3774 extern Lisp_Object Vexecuting_macro, Vfeatures, Vfile_domain;
3775 extern Lisp_Object Vfile_name_coding_system, Vinhibit_quit;
3776 extern Lisp_Object Vinvocation_directory, Vinvocation_name;
3777 extern Lisp_Object Vkeyboard_coding_system, Vlast_command, Vlast_command_char;
3778 extern Lisp_Object Vlast_command_event, Vlast_input_event;
3779 extern Lisp_Object Vload_file_name_internal;
3780 extern Lisp_Object Vload_file_name_internal_the_purecopy, Vload_history;
3781 extern Lisp_Object Vload_path, Vmark_even_if_inactive, Vmenubar_configuration;
3782 extern Lisp_Object Vminibuf_preprompt, Vminibuf_prompt, Vminibuffer_zero;
3783 extern Lisp_Object Vmodule_directory, Vmswindows_downcase_file_names;
3784 extern Lisp_Object Vmswindows_get_true_file_attributes, Vobarray;
3785 extern Lisp_Object Vprint_length, Vprint_level, Vprocess_environment;
3786 extern Lisp_Object Vquit_flag;
3787 extern Lisp_Object Vrecent_keys_ring, Vshell_file_name;
3788 extern Lisp_Object Vsite_module_directory;
3789 extern Lisp_Object Vstandard_input, Vstandard_output, Vstdio_str;
3790 extern Lisp_Object Vsynchronous_sounds, Vsystem_name, Vterminal_coding_system;
3791 extern Lisp_Object Vthis_command_keys, Vunread_command_event;
3792 extern Lisp_Object Vx_initial_argv_list;
3793
3794 #endif                          /* INCLUDED_lisp_h_ */