XEmacs 21.4.4 "Artificial Intelligence".
[chise/xemacs-chise.git.1] / src / lisp.h
index 7d4b7fc..4aee0e1 100644 (file)
@@ -70,6 +70,9 @@ void Dynarr_free (void *d);
   ((dynarr_type *) Dynarr_newf (sizeof (type)))
 #define Dynarr_at(d, pos) ((d)->base[pos])
 #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos))
+#define Dynarr_begin(d) Dynarr_atp (d, 0)
+#define Dynarr_end(d) Dynarr_atp (d, Dynarr_length (d))
+#define Dynarr_sizeof(d) ((d)->cur * (d)->elsize)
 #define Dynarr_length(d) ((d)->cur)
 #define Dynarr_largest(d) ((d)->largest)
 #define Dynarr_reset(d) ((d)->cur = 0)
@@ -190,20 +193,42 @@ void xfree (void *);
 # endif /* GNUC */
 #endif
 
+/* No type has a greater alignment requirement than max_align_t.
+   (except perhaps for types we don't use, like long double) */
+typedef union
+{
+  struct { long l; } l;
+  struct { void *p; } p;
+  struct { void (*f)(void); } f;
+  struct { double d; } d;
+} max_align_t;
+
 #ifndef ALIGNOF
 # if defined (__GNUC__) && (__GNUC__ >= 2)
-#  define ALIGNOF(x) __alignof__ (x)
+/* gcc has an extension that gives us exactly what we want. */
+#  define ALIGNOF(type) __alignof__ (type)
+# elif ! defined (__cplusplus)
+/* The following is mostly portable, except that:
+   - it doesn't work for inside out declarations like void (*) (void).
+     (so just call ALIGNOF with a typedef'ed name)
+   - it doesn't work with C++.  The C++ committee has decided,
+     in its infinite wisdom, that:
+     "Types must be declared in declarations, not in expressions." */
+#  define ALIGNOF(type) offsetof (struct { char c; type member; }, member)
 # else
-#  define ALIGNOF(x) sizeof (x)
+/* C++ is annoying, but it has a big bag of tricks.
+   The following doesn't have the "inside out" declaration bug C does. */
+template<typename T> struct alignment_trick { char c; T member; };
+#  define ALIGNOF(type) offsetof (alignment_trick<type>, member)
 # endif
-#endif
+#endif /* ALIGNOF */
 
 #define ALIGN_SIZE(len, unit) \
   ((((len) + (unit) - 1) / (unit)) * (unit))
 
 /* #### Yuck, this is kind of evil */
 #define ALIGN_PTR(ptr, unit) \
-  ((void *) ALIGN_SIZE ((long) (ptr), unit))
+  ((void *) ALIGN_SIZE ((size_t) (ptr), unit))
 
 #ifndef DO_NOTHING
 #define DO_NOTHING do {} while (0)
@@ -242,7 +267,11 @@ void assert_failed (const char *, int, const char *);
 
 /* EMACS_INT is the underlying integral type into which a Lisp_Object must fit.
    In particular, it must be large enough to contain a pointer.
-   config.h can override this, e.g. to use `long long' for bigger lisp ints. */
+   config.h can override this, e.g. to use `long long' for bigger lisp ints.
+
+   #### In point of fact, it would NOT be a good idea for config.h to mess
+   with EMACS_INT.  A lot of code makes the basic assumption that EMACS_INT
+   is the size of a pointer. */
 
 #ifndef SIZEOF_EMACS_INT
 # define SIZEOF_EMACS_INT SIZEOF_VOID_P
@@ -280,17 +309,16 @@ void assert_failed (const char *, int, const char *);
 /*     basic char/int typedefs     */
 /* ------------------------------- */
 
-/* The definitions we put here use typedefs to convey additional meaning to
-   types that by themselves are pretty general.  Stuff pointed to by a
+/* The definitions we put here use typedefs to attribute specific meaning
+   to types that by themselves are pretty general.  Stuff pointed to by a
    char * or unsigned char * will nearly always be one of four types:
    a) pointer to internally-formatted text; b) pointer to text in some
    external format, which can be defined as all formats other than the
    internal one; c) pure ASCII text; d) binary data that is not meant to
    be interpreted as text. [A fifth possible type "e) a general pointer
-   to memory" should be replaced with void *.] By using these more specific
-   types in lieu of the general ones, you clear up greatly the confusions
-   that inevitably will occur when it's not clearly known the semantics of
-   a char * argument being studied. */
+   to memory" should be replaced with void *.]  Using these more specific
+   types rather than the general ones helps avoid the confusions that
+   occur when the semantics of a char * argument being studied are unclear. */
 
 typedef unsigned char UChar;
 
@@ -304,19 +332,14 @@ typedef UChar UBufbyte;
 typedef char  SBufbyte;
 
 /* The data representing a string in "external" format (binary or any
-   external encoding) is logically a set of Extbytes, declared as follows. */
-
-typedef UChar Extbyte; /* #### I REALLY think this should be a char.  This
-                         is more logical and will fix enough char-UChar
-                         inconsistencies that maybe we'll be able to stop
-                         turning off those warnings. --ben */
+   external encoding) is logically a set of Extbytes, declared as
+   follows.  Extbyte is guaranteed to be just a char, so for example
+   strlen (Extbyte *) is OK.  Extbyte is only a documentation device
+   for referring to external text. */
 
-/* Explicitly signed or unsigned versions: */
-typedef UChar UExtbyte;
-typedef char  SExtbyte;
+typedef char Extbyte;
 
 /* A byte in a string in binary format: */
-
 typedef char Char_Binary;
 typedef UChar UChar_Binary;
 
@@ -335,7 +358,7 @@ typedef UChar UChar_ASCII;
 typedef int Emchar;
 
 /* Different ways of referring to a position in a buffer.  We use
-   the typedefs in preference to 'int' to make it clearer what
+   the typedefs in preference to 'EMACS_INT' to make it clearer what
    sort of position is being used.  See extents.c for a description
    of the different positions.  We put them here instead of in
    buffer.h (where they rightfully belong) to avoid syntax errors
@@ -357,6 +380,10 @@ typedef EMACS_INT Extcount;
 /*     structure/other typedefs    */
 /* ------------------------------- */
 
+/* Counts of bytes or array elements */
+typedef EMACS_INT Memory_count;
+typedef EMACS_INT Element_count;
+
 typedef struct lstream Lstream;
 
 typedef unsigned int face_index;
@@ -558,7 +585,7 @@ enum Lisp_Type
 
 #define INT_VALBITS (BITS_PER_EMACS_INT - INT_GCBITS)
 #define VALBITS (BITS_PER_EMACS_INT - GCBITS)
-#define EMACS_INT_MAX ((EMACS_INT) ((1UL << INT_VALBITS) -1UL))
+#define EMACS_INT_MAX ((EMACS_INT) ((1UL << (INT_VALBITS - 1)) -1UL))
 #define EMACS_INT_MIN (-(EMACS_INT_MAX) - 1)
 
 #ifdef USE_UNION_TYPE
@@ -576,6 +603,11 @@ typedef struct
   Dynarr_declare (Lisp_Object);
 } Lisp_Object_dynarr;
 
+typedef struct
+{
+  Dynarr_declare (Lisp_Object *);
+} Lisp_Object_ptr_dynarr;
+
 /* Close your eyes now lest you vomit or spontaneously combust ... */
 
 #define HACKEQ_UNSAFE(obj1, obj2)                              \
@@ -808,24 +840,20 @@ PRIVATE_EXTERNAL_LIST_LOOP_6 (elt, list, len, tail,                       \
                      tortoise_##elt, CIRCULAR_LIST_SUSPICION_LENGTH)
 
 
-#define PRIVATE_EXTERNAL_LIST_LOOP_6(elt, list, len, hare,     \
-                             tortoise, suspicion_length)       \
-  for (tortoise = hare = list, len = 0;                                \
-                                                               \
-       (CONSP (hare) ? ((elt = XCAR (hare)), 1) :              \
-       (NILP (hare) ? 0 :                                      \
-        (signal_malformed_list_error (list), 0)));             \
-                                                               \
-       hare = XCDR (hare),                                     \
-        ((++len < suspicion_length) ?                          \
-         ((void) 0) :                                          \
-         (((len & 1) ?                                         \
-           ((void) (tortoise = XCDR (tortoise))) :             \
-           ((void) 0))                                         \
-          ,                                                    \
-          (EQ (hare, tortoise) ?                               \
-           ((void) signal_circular_list_error (list)) :        \
-           ((void) 0)))))
+#define PRIVATE_EXTERNAL_LIST_LOOP_6(elt, list, len, hare,             \
+                                    tortoise, suspicion_length)        \
+  for (tortoise = hare = list, len = 0;                                        \
+                                                                       \
+       (CONSP (hare) ? ((elt = XCAR (hare)), 1) :                      \
+       (NILP (hare) ? 0 :                                              \
+        (signal_malformed_list_error (list), 0)));                     \
+                                                                       \
+       hare = XCDR (hare),                                             \
+        (void)                                                         \
+        ((++len > suspicion_length)                                    \
+         &&                                                            \
+         ((((len & 1) != 0) && (tortoise = XCDR (tortoise), 0)),       \
+          (EQ (hare, tortoise) && (signal_circular_list_error (list), 0)))))
 
 /* GET_LIST_LENGTH and GET_EXTERNAL_LIST_LENGTH:
 
@@ -1180,14 +1208,28 @@ void set_string_char (Lisp_String *s, Charcount i, Emchar c);
 
 #endif /* not MULE */
 
-/* Return the true size of a struct with a variable-length array field.  */
-#define FLEXIBLE_ARRAY_STRUCT_SIZEOF(flexible_array_structtype,                \
-                                    flexible_array_field,              \
-                                    flexible_array_length)             \
-  (offsetof (flexible_array_structtype, flexible_array_field) +                \
-   (offsetof (flexible_array_structtype, flexible_array_field[1]) -    \
-    offsetof (flexible_array_structtype, flexible_array_field[0])) *   \
-   (flexible_array_length))
+/* Return the true aligned size of a struct whose last member is a
+   variable-length array field.  (this is known as the "struct hack") */
+/* Implementation: in practice, structtype and fieldtype usually have
+   the same alignment, but we can't be sure.  We need to use
+   ALIGN_SIZE to be absolutely sure of getting the correct alignment.
+   To help the compiler's optimizer, we use a ternary expression that
+   only a very stupid compiler would fail to correctly simplify. */
+#define FLEXIBLE_ARRAY_STRUCT_SIZEOF(structtype,       \
+                                    fieldtype,         \
+                                    fieldname,         \
+                                    array_length)      \
+(ALIGNOF (structtype) == ALIGNOF (fieldtype)           \
+ ? (offsetof (structtype, fieldname) +                 \
+    (offsetof (structtype, fieldname[1]) -             \
+     offsetof (structtype, fieldname[0])) *            \
+    (array_length))                                    \
+ : (ALIGN_SIZE                                         \
+    ((offsetof (structtype, fieldname) +               \
+      (offsetof (structtype, fieldname[1]) -           \
+       offsetof (structtype, fieldname[0])) *          \
+      (array_length)),                                 \
+     ALIGNOF (structtype))))
 
 /*------------------------------ vector --------------------------------*/
 
@@ -1869,7 +1911,7 @@ extern EMACS_INT consing_since_gc;
 
 /* threshold for doing another gc */
 
-extern EMACS_INT gc_cons_threshold;
+extern Fixnum gc_cons_threshold;
 
 /* Structure for recording stack slots that need marking */
 
@@ -2107,6 +2149,8 @@ void debug_ungcpro(char *, int, struct gcpro *);
     RETURN_SANS_WARNINGS ret_nunb_val; \
 } while (0)
 
+extern Lisp_Object_ptr_dynarr *staticpros;
+
 /* Call staticpro (&var) to protect static variable `var'. */
 void staticpro (Lisp_Object *);
 
@@ -2114,19 +2158,55 @@ void staticpro (Lisp_Object *);
 /* var will not be saved at dump time */
 void staticpro_nodump (Lisp_Object *);
 
-/* Call dumpstruct(&var, &desc) to dump the structure pointed to by `var'. */
-void dumpstruct (void *, const struct struct_description *);
+/* dump_add_root_struct_ptr (&var, &desc) dumps the structure pointed to by `var'. */
+#ifdef PDUMP
+void dump_add_root_struct_ptr (void *, const struct struct_description *);
+#else
+#define dump_add_root_struct_ptr(varaddr,descaddr) DO_NOTHING
+#endif
+
+/* dump_add_opaque (&var, size) dumps the opaque static structure `var'. */
+#ifdef PDUMP
+void dump_add_opaque (void *, size_t);
+#else
+#define dump_add_opaque(varaddr,size) DO_NOTHING
+#endif
+
+/* Call dump_add_opaque_int (&int_var) to dump `int_var', of type `int'. */
+#ifdef PDUMP
+#define dump_add_opaque_int(int_varaddr) do {  \
+  int *dao_ = (int_varaddr); /* type check */  \
+  dump_add_opaque (dao_, sizeof (*dao_));      \
+} while (0)
+#else
+#define dump_add_opaque_int(int_varaddr) DO_NOTHING
+#endif
 
-/* Call dumpopaque(&var, size) to dump the opaque static structure `var'. */
-void dumpopaque (void *, size_t);
+/* Call dump_add_opaque_fixnum (&fixnum_var) to dump `fixnum_var', of type `Fixnum'. */
+#ifdef PDUMP
+#define dump_add_opaque_fixnum(fixnum_varaddr) do {    \
+  Fixnum *dao_ = (fixnum_varaddr); /* type check */    \
+  dump_add_opaque (dao_, sizeof (*dao_));              \
+} while (0)
+#else
+#define dump_add_opaque_fixnum(fixnum_varaddr) DO_NOTHING
+#endif
 
-/* Call pdump_wire(&var) to ensure that var is properly updated after pdump. */
-void pdump_wire (Lisp_Object *);
+/* Call dump_add_root_object (&var) to ensure that var is properly updated after pdump. */
+#ifdef PDUMP
+void dump_add_root_object (Lisp_Object *);
+#else
+#define dump_add_root_object(varaddr) DO_NOTHING
+#endif
 
-/* Call pdump_wire(&var) to ensure that var  is properly updated after
-   pdump.  var  must point to  a linked list  of  objects out of which
+/* Call dump_add_root_object (&var) to ensure that var is properly updated after
+   pdump.  var must point to a linked list of objects out of which
    some may not be dumped */
-void pdump_wire_list (Lisp_Object *);
+#ifdef PDUMP
+void dump_add_weak_object_chain (Lisp_Object *);
+#else
+#define dump_add_weak_object_chain(varaddr) DO_NOTHING
+#endif
 
 /* Nonzero means Emacs has already been initialized.
    Used during startup to detect startup of dumped Emacs.  */
@@ -2374,7 +2454,7 @@ Lisp_Object decode_path (const char *);
 extern int noninteractive, noninteractive1;
 extern int fatal_error_in_progress;
 extern int preparing_for_armageddon;
-extern int emacs_priority;
+extern Fixnum emacs_priority;
 extern int running_asynch_code;
 extern int suppress_early_error_handler_backtrace;
 
@@ -2739,7 +2819,7 @@ void write_string_1 (const Bufbyte *, Bytecount, Lisp_Object);
 void print_cons (Lisp_Object, Lisp_Object, int);
 void print_vector (Lisp_Object, Lisp_Object, int);
 void print_string (Lisp_Object, Lisp_Object, int);
-void long_to_string (char *, long);
+char *long_to_string (char *, long);
 void print_internal (Lisp_Object, Lisp_Object, int);
 void print_symbol (Lisp_Object, Lisp_Object, int);
 void print_float (Lisp_Object, Lisp_Object, int);
@@ -2777,7 +2857,7 @@ Bytind bi_find_next_newline_no_quit (struct buffer *, Bytind, int);
 Bytind bi_find_next_emchar_in_string (Lisp_String*, Emchar, Bytind, EMACS_INT);
 Bufpos find_before_next_newline (struct buffer *, Bufpos, Bufpos, int);
 struct re_pattern_buffer *compile_pattern (Lisp_Object, struct re_registers *,
-                                          char *, int, Error_behavior);
+                                          Lisp_Object, int, Error_behavior);
 Bytecount fast_string_match (Lisp_Object,  const Bufbyte *,
                             Lisp_Object, Bytecount,
                             Bytecount, int, Error_behavior, int);
@@ -3177,6 +3257,7 @@ extern Lisp_Object Qvariable_documentation, Qvariable_domain;
 extern Lisp_Object Qvoid_function, Qvoid_variable;
 extern Lisp_Object Qwindow_live_p, Qwrong_number_of_arguments;
 extern Lisp_Object Qwrong_type_argument, Qyes_or_no_p;
+extern Lisp_Object Qgtk;
 
 #define SYMBOL(fou) extern Lisp_Object fou
 #define SYMBOL_KEYWORD(la_cle_est_fou) extern Lisp_Object la_cle_est_fou
@@ -3191,9 +3272,8 @@ extern Lisp_Object Qwrong_type_argument, Qyes_or_no_p;
 
 /*--------------- prototypes for variables of type Lisp_Object  ------------*/
 
-extern Lisp_Object Vactivate_menubar_hook, Vascii_canon_table;
-extern Lisp_Object Vascii_downcase_table, Vascii_eqv_table;
-extern Lisp_Object Vascii_upcase_table, Vautoload_queue, Vblank_menubar;
+extern Lisp_Object Vactivate_menubar_hook;
+extern Lisp_Object Vautoload_queue, Vblank_menubar;
 extern Lisp_Object Vcharset_ascii, Vcharset_composite, Vcharset_control_1;
 extern Lisp_Object Vcoding_system_for_read, Vcoding_system_for_write;
 extern Lisp_Object Vcoding_system_hash_table, Vcommand_history;
@@ -3215,8 +3295,6 @@ extern Lisp_Object Vload_file_name_internal;
 extern Lisp_Object Vload_file_name_internal_the_purecopy, Vload_history;
 extern Lisp_Object Vload_path, Vmark_even_if_inactive, Vmenubar_configuration;
 extern Lisp_Object Vminibuf_preprompt, Vminibuf_prompt, Vminibuffer_zero;
-extern Lisp_Object Vmirror_ascii_canon_table, Vmirror_ascii_downcase_table;
-extern Lisp_Object Vmirror_ascii_eqv_table, Vmirror_ascii_upcase_table;
 extern Lisp_Object Vmodule_directory, Vmswindows_downcase_file_names;
 extern Lisp_Object Vmswindows_get_true_file_attributes, Vobarray;
 extern Lisp_Object Vprint_length, Vprint_level, Vprocess_environment;