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