Remove src/m/*.
[bpt/emacs.git] / src / lisp.h
index 8aa3660..bb9e6ed 100644 (file)
@@ -1,5 +1,5 @@
 /* Fundamental definitions for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985-1987, 1993-1995, 1997-2011
+   Copyright (C) 1985-1987, 1993-1995, 1997-2012
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -23,6 +23,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdarg.h>
 #include <stddef.h>
 #include <inttypes.h>
+#include <limits.h>
 
 #include <intprops.h>
 
@@ -40,24 +41,67 @@ extern void check_cons_list (void);
    Build with CFLAGS='-DWIDE_EMACS_INT' to try them out.  */
 /* #undef WIDE_EMACS_INT */
 
-/* These are default choices for the types to use.  */
+/* EMACS_INT - signed integer wide enough to hold an Emacs value
+   EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
+   pI - printf length modifier for EMACS_INT
+   EMACS_UINT - unsigned variant of EMACS_INT */
 #ifndef EMACS_INT
-# if BITS_PER_LONG < BITS_PER_LONG_LONG && defined WIDE_EMACS_INT
+# if LONG_MAX < LLONG_MAX && defined WIDE_EMACS_INT
 #  define EMACS_INT long long
-#  define BITS_PER_EMACS_INT BITS_PER_LONG_LONG
+#  define EMACS_INT_MAX LLONG_MAX
 #  define pI "ll"
-# elif BITS_PER_INT < BITS_PER_LONG
+# elif INT_MAX < LONG_MAX
 #  define EMACS_INT long
-#  define BITS_PER_EMACS_INT BITS_PER_LONG
+#  define EMACS_INT_MAX LONG_MAX
 #  define pI "l"
 # else
 #  define EMACS_INT int
-#  define BITS_PER_EMACS_INT BITS_PER_INT
+#  define EMACS_INT_MAX INT_MAX
 #  define pI ""
 # endif
 #endif
-#ifndef EMACS_UINT
-# define EMACS_UINT unsigned EMACS_INT
+#define EMACS_UINT unsigned EMACS_INT
+
+/* Number of bits in some machine integer types.  */
+enum
+  {
+    BITS_PER_CHAR      = CHAR_BIT,
+    BITS_PER_SHORT     = CHAR_BIT * sizeof (short),
+    BITS_PER_INT       = CHAR_BIT * sizeof (int),
+    BITS_PER_LONG      = CHAR_BIT * sizeof (long int),
+    BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
+  };
+
+/* printmax_t and uprintmax_t are types for printing large integers.
+   These are the widest integers that are supported for printing.
+   pMd etc. are conversions for printing them.
+   On C99 hosts, there's no problem, as even the widest integers work.
+   Fall back on EMACS_INT on pre-C99 hosts.  */
+#ifdef PRIdMAX
+typedef intmax_t printmax_t;
+typedef uintmax_t uprintmax_t;
+# define pMd PRIdMAX
+# define pMu PRIuMAX
+#else
+typedef EMACS_INT printmax_t;
+typedef EMACS_UINT uprintmax_t;
+# define pMd pI"d"
+# define pMu pI"u"
+#endif
+
+/* Use pD to format ptrdiff_t values, which suffice for indexes into
+   buffers and strings.  Emacs never allocates objects larger than
+   PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
+   In C99, pD can always be "t"; configure it here for the sake of
+   pre-C99 libraries such as glibc 2.0 and Solaris 8.  */
+#if PTRDIFF_MAX == INT_MAX
+# define pD ""
+#elif PTRDIFF_MAX == LONG_MAX
+# define pD "l"
+#elif PTRDIFF_MAX == LLONG_MAX
+# define pD "ll"
+#else
+# define pD "t"
 #endif
 
 /* Extra internal type checking?  */
@@ -99,9 +143,9 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
 #define eassert(X) ((void) (0 && (X))) /* Check that X compiles.  */
 #else /* ENABLE_CHECKING */
 #if defined (__GNUC__) && __GNUC__ >= 2 && defined (__STDC__)
-#define eassert(cond) CHECK(cond,"assertion failed: " #cond)
+#define eassert(cond) CHECK (cond, "assertion failed: " #cond)
 #else
-#define eassert(cond) CHECK(cond,"assertion failed")
+#define eassert(cond) CHECK (cond, "assertion failed")
 #endif
 #endif /* ENABLE_CHECKING */
 \f
@@ -129,12 +173,28 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
 
 /* First, try and define DECL_ALIGN(type,var) which declares a static
    variable VAR of type TYPE with the added requirement that it be
-   TYPEBITS-aligned. */
+   TYPEBITS-aligned.  */
+
+#define GCTYPEBITS 3
+#define VALBITS (BITS_PER_EMACS_INT - GCTYPEBITS)
+
+/* The maximum value that can be stored in a EMACS_INT, assuming all
+   bits other than the type bits contribute to a nonnegative signed value.
+   This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below.  */
+#define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
+
 #ifndef NO_DECL_ALIGN
 # ifndef DECL_ALIGN
 #  if HAVE_ATTRIBUTE_ALIGNED
 #   define DECL_ALIGN(type, var) \
      type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var
+#  elif defined(_MSC_VER)
+#   define ALIGN_GCTYPEBITS 8
+#   if (1 << GCTYPEBITS) != ALIGN_GCTYPEBITS
+#    error ALIGN_GCTYPEBITS is wrong!
+#   endif
+#   define DECL_ALIGN(type, var) \
+     type __declspec(align(ALIGN_GCTYPEBITS)) var
 #  else
      /* What directives do other compilers use?  */
 #  endif
@@ -146,7 +206,14 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
      || defined DARWIN_OS || defined __sun)
 /* We also need to be able to specify mult-of-8 alignment on static vars.  */
 # if defined DECL_ALIGN
-#  define USE_LSB_TAG
+/* On hosts where pointers-as-ints do not exceed VAL_MAX,
+   USE_LSB_TAG is:
+    a. unnecessary, because the top bits of an EMACS_INT are unused, and
+    b. slower, because it typically requires extra masking.
+   So, define USE_LSB_TAG only on hosts where it might be useful.  */
+#  if VAL_MAX < UINTPTR_MAX
+#   define USE_LSB_TAG
+#  endif
 # endif
 #endif
 
@@ -192,6 +259,15 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
 # endif
 #endif
 
+/* Stolen from GDB.  The only known compiler that doesn't support
+   enums in bitfields is MSVC.  */
+#ifdef _MSC_VER
+#define ENUM_BF(TYPE) unsigned int
+#else
+#define ENUM_BF(TYPE) enum TYPE
+#endif
+
+
 enum Lisp_Type
   {
     /* Integer.  XINT (obj) is the integer value.  */
@@ -255,15 +331,6 @@ enum Lisp_Fwd_Type
     Lisp_Fwd_Kboard_Obj,       /* Fwd to a Lisp_Object field of kboards.  */
   };
 
-#ifndef GCTYPEBITS
-#define GCTYPEBITS 3
-#endif
-
-/* These values are overridden by the m- file on some machines.  */
-#ifndef VALBITS
-#define VALBITS (BITS_PER_EMACS_INT - GCTYPEBITS)
-#endif
-
 #ifdef USE_LISP_UNION_TYPE
 
 #ifndef WORDS_BIGENDIAN
@@ -275,19 +342,19 @@ union Lisp_Object
   {
     /* Used for comparing two Lisp_Objects;
        also, positive integers can be accessed fast this way.  */
-    EMACS_UINT i;
+    EMACS_INT i;
 
     struct
       {
-       /* Use explict signed, the signedness of a bit-field of type
+       /* Use explicit signed, the signedness of a bit-field of type
           int is implementation defined.  */
        signed EMACS_INT val  : VALBITS;
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
       } s;
     struct
       {
        EMACS_UINT val : VALBITS;
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
       } u;
   }
 Lisp_Object;
@@ -299,18 +366,18 @@ union Lisp_Object
   {
     /* Used for comparing two Lisp_Objects;
        also, positive integers can be accessed fast this way.  */
-    EMACS_UINT i;
+    EMACS_INT i;
 
     struct
       {
-       enum Lisp_Type type : GCTYPEBITS;
-       /* Use explict signed, the signedness of a bit-field of type
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
+       /* Use explicit signed, the signedness of a bit-field of type
           int is implementation defined.  */
        signed EMACS_INT val  : VALBITS;
       } s;
     struct
       {
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
        EMACS_UINT val : VALBITS;
       } u;
   }
@@ -419,10 +486,11 @@ enum pvec_type
      (var) = (type) | (intptr_t) (ptr))
 
 #define XPNTR(a) ((intptr_t) ((a) & ~TYPEMASK))
+#define XUNTAG(a, type) ((intptr_t) ((a) - (type)))
 
 #else  /* not USE_LSB_TAG */
 
-#define VALMASK ((((EMACS_INT) 1) << VALBITS) - 1)
+#define VALMASK VAL_MAX
 
 /* One need to override this if there must be high bits set in data space
    (doing the result of the below & ((1 << (GCTYPE + 1)) - 1) would work
@@ -478,8 +546,8 @@ enum pvec_type
 #ifdef USE_LSB_TAG
 
 # define XSET(var, vartype, ptr) \
-  (eassert ((((EMACS_UINT) (ptr)) & ((1 << GCTYPEBITS) - 1)) == 0),    \
-   (var).u.val = ((EMACS_UINT) (ptr)) >> GCTYPEBITS,                   \
+  (eassert ((((uintptr_t) (ptr)) & ((1 << GCTYPEBITS) - 1)) == 0),     \
+   (var).u.val = ((uintptr_t) (ptr)) >> GCTYPEBITS,                    \
    (var).u.type = ((char) (vartype)))
 
 /* Some versions of gcc seem to consider the bitfield width when issuing
@@ -496,7 +564,7 @@ enum pvec_type
 # define XSETFASTINT(a, b) ((a).i = (b))
 
 # define XSET(var, vartype, ptr) \
-   (((var).s.val = ((EMACS_INT) (ptr))), ((var).s.type = ((char) (vartype))))
+   (((var).s.val = ((intptr_t) (ptr))), ((var).s.type = ((char) (vartype))))
 
 #ifdef DATA_SEG_BITS
 /* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
@@ -525,6 +593,13 @@ extern Lisp_Object make_number (EMACS_INT);
 # define XSETFASTINT(a, b) (XSETINT (a, b))
 #endif
 
+/* Extract the pointer value of the Lisp object A, under the
+   assumption that A's type is TYPE.  This is a fallback
+   implementation if nothing faster is available.  */
+#ifndef XUNTAG
+# define XUNTAG(a, type) XPNTR (a)
+#endif
+
 #define EQ(x, y) (XHASH (x) == XHASH (y))
 
 /* Number of bits in a fixnum, including the sign bit.  */
@@ -551,20 +626,25 @@ extern Lisp_Object make_number (EMACS_INT);
 
 /* Extract a value or address from a Lisp_Object.  */
 
-#define XCONS(a) (eassert (CONSP(a)),(struct Lisp_Cons *) XPNTR(a))
-#define XVECTOR(a) (eassert (VECTORLIKEP(a)),(struct Lisp_Vector *) XPNTR(a))
-#define XSTRING(a) (eassert (STRINGP(a)),(struct Lisp_String *) XPNTR(a))
-#define XSYMBOL(a) (eassert (SYMBOLP(a)),(struct Lisp_Symbol *) XPNTR(a))
-#define XFLOAT(a) (eassert (FLOATP(a)),(struct Lisp_Float *) XPNTR(a))
+#define XCONS(a)   (eassert (CONSP (a)), \
+                   (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
+#define XVECTOR(a) (eassert (VECTORLIKEP (a)), \
+                   (struct Lisp_Vector *) XUNTAG (a, Lisp_Vectorlike))
+#define XSTRING(a) (eassert (STRINGP (a)), \
+                   (struct Lisp_String *) XUNTAG (a, Lisp_String))
+#define XSYMBOL(a) (eassert (SYMBOLP (a)), \
+                   (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol))
+#define XFLOAT(a)  (eassert (FLOATP (a)), \
+                   (struct Lisp_Float *) XUNTAG (a, Lisp_Float))
 
 /* Misc types.  */
 
-#define XMISC(a)   ((union Lisp_Misc *) XPNTR(a))
-#define XMISCANY(a)    (eassert (MISCP (a)), &(XMISC(a)->u_any))
+#define XMISC(a)       ((union Lisp_Misc *) XUNTAG (a, Lisp_Misc))
+#define XMISCANY(a)    (eassert (MISCP (a)), &(XMISC (a)->u_any))
 #define XMISCTYPE(a)   (XMISCANY (a)->type)
-#define XMARKER(a)     (eassert (MARKERP (a)), &(XMISC(a)->u_marker))
-#define XOVERLAY(a)    (eassert (OVERLAYP (a)), &(XMISC(a)->u_overlay))
-#define XSAVE_VALUE(a) (eassert (SAVE_VALUEP (a)), &(XMISC(a)->u_save_value))
+#define XMARKER(a)     (eassert (MARKERP (a)), &(XMISC (a)->u_marker))
+#define XOVERLAY(a)    (eassert (OVERLAYP (a)), &(XMISC (a)->u_overlay))
+#define XSAVE_VALUE(a) (eassert (SAVE_VALUEP (a)), &(XMISC (a)->u_save_value))
 
 /* Forwarding object types.  */
 
@@ -579,14 +659,24 @@ extern Lisp_Object make_number (EMACS_INT);
 
 /* Pseudovector types.  */
 
-#define XPROCESS(a) (eassert (PROCESSP(a)),(struct Lisp_Process *) XPNTR(a))
-#define XWINDOW(a) (eassert (WINDOWP(a)),(struct window *) XPNTR(a))
-#define XTERMINAL(a) (eassert (TERMINALP(a)),(struct terminal *) XPNTR(a))
-#define XSUBR(a) (eassert (SUBRP(a)),(struct Lisp_Subr *) XPNTR(a))
-#define XBUFFER(a) (eassert (BUFFERP(a)),(struct buffer *) XPNTR(a))
-#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), (struct Lisp_Char_Table *) XPNTR(a))
-#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), (struct Lisp_Sub_Char_Table *) XPNTR(a))
-#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), (struct Lisp_Bool_Vector *) XPNTR(a))
+#define XPROCESS(a) (eassert (PROCESSP (a)), \
+                    (struct Lisp_Process *) XUNTAG (a, Lisp_Vectorlike))
+#define XWINDOW(a) (eassert (WINDOWP (a)), \
+                   (struct window *) XUNTAG (a, Lisp_Vectorlike))
+#define XTERMINAL(a) (eassert (TERMINALP (a)), \
+                     (struct terminal *) XUNTAG (a, Lisp_Vectorlike))
+#define XSUBR(a) (eassert (SUBRP (a)), \
+                 (struct Lisp_Subr *) XUNTAG (a, Lisp_Vectorlike))
+#define XBUFFER(a) (eassert (BUFFERP (a)), \
+                   (struct buffer *) XUNTAG (a, Lisp_Vectorlike))
+#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), \
+                       (struct Lisp_Char_Table *) XUNTAG (a, Lisp_Vectorlike))
+#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), \
+                           ((struct Lisp_Sub_Char_Table *) \
+                            XUNTAG (a, Lisp_Vectorlike)))
+#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), \
+                        ((struct Lisp_Bool_Vector *) \
+                         XUNTAG (a, Lisp_Vectorlike)))
 
 /* Construct a Lisp_Object from a value or address.  */
 
@@ -604,7 +694,7 @@ extern Lisp_Object make_number (EMACS_INT);
 
 /* Pseudovector types.  */
 
-#define XSETPVECTYPE(v, code) XSETTYPED_PVECTYPE(v, header.size, code)
+#define XSETPVECTYPE(v, code) XSETTYPED_PVECTYPE (v, header.size, code)
 #define XSETTYPED_PVECTYPE(v, size_member, code) \
   ((v)->size_member |= PSEUDOVECTOR_FLAG | (code))
 #define XSETPVECTYPESIZE(v, code, sizeval) \
@@ -613,7 +703,9 @@ extern Lisp_Object make_number (EMACS_INT);
 /* The cast to struct vectorlike_header * avoids aliasing issues.  */
 #define XSETPSEUDOVECTOR(a, b, code) \
   XSETTYPED_PSEUDOVECTOR(a, b,       \
-                        ((struct vectorlike_header *) XPNTR (a))->size, \
+                        (((struct vectorlike_header *) \
+                          XUNTAG (a, Lisp_Vectorlike)) \
+                         ->size),                      \
                         code)
 #define XSETTYPED_PSEUDOVECTOR(a, b, size, code)                       \
   (XSETVECTOR (a, b),                                                  \
@@ -716,8 +808,8 @@ struct Lisp_Cons
 #endif
 
 /* Use these from normal code.  */
-#define XCAR(c)        LISP_MAKE_RVALUE(XCAR_AS_LVALUE(c))
-#define XCDR(c) LISP_MAKE_RVALUE(XCDR_AS_LVALUE(c))
+#define XCAR(c)        LISP_MAKE_RVALUE (XCAR_AS_LVALUE (c))
+#define XCDR(c) LISP_MAKE_RVALUE (XCDR_AS_LVALUE (c))
 
 /* Use these to set the fields of a cons cell.
 
@@ -725,8 +817,8 @@ struct Lisp_Cons
    should not be read after 'c' is first modified.  Also, neither
    argument should be evaluated more than once; side effects are
    especially common in the second argument.  */
-#define XSETCAR(c,n) (XCAR_AS_LVALUE(c) = (n))
-#define XSETCDR(c,n) (XCDR_AS_LVALUE(c) = (n))
+#define XSETCAR(c,n) (XCAR_AS_LVALUE (c) = (n))
+#define XSETCDR(c,n) (XCDR_AS_LVALUE (c) = (n))
 
 /* Take the car or cdr of something whose type is not known.  */
 #define CAR(c)                                 \
@@ -765,11 +857,19 @@ extern EMACS_INT string_bytes (struct Lisp_String *);
 
 #endif /* not GC_CHECK_STRING_BYTES */
 
-/* A string cannot contain more bytes than a fixnum can represent,
-   nor can it be so long that C pointer arithmetic stops working on
-   the string plus a terminating null.  */
-#define STRING_BYTES_MAX  \
-  min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1)
+/* An upper bound on the number of bytes in a Lisp string, not
+   counting the terminating null.  This a tight enough bound to
+   prevent integer overflow errors that would otherwise occur during
+   string size calculations.  A string cannot contain more bytes than
+   a fixnum can represent, nor can it be so long that C pointer
+   arithmetic stops working on the string plus its terminating null.
+   Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
+   may be a bit smaller than STRING_BYTES_BOUND, calculating it here
+   would expose alloc.c internal details that we'd rather keep
+   private.  The cast to ptrdiff_t ensures that STRING_BYTES_BOUND is
+   signed.  */
+#define STRING_BYTES_BOUND  \
+  min (MOST_POSITIVE_FIXNUM, (ptrdiff_t) min (SIZE_MAX, PTRDIFF_MAX) - 1)
 
 /* Mark STR as a unibyte string.  */
 #define STRING_SET_UNIBYTE(STR)  \
@@ -809,7 +909,7 @@ struct Lisp_String
    <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>.  */
 struct vectorlike_header
   {
-    EMACS_UINT size;
+    EMACS_INT size;
 
     /* Pointer to the next vector-like object.  It is generally a buffer or a
        Lisp_Vector alias, so for convenience it is a union instead of a
@@ -831,14 +931,14 @@ struct Lisp_Vector
    of the shortest vector that would hold that struct.  */
 #define VECSIZE(type) ((sizeof (type)                                    \
                        - offsetof (struct Lisp_Vector, contents[0])      \
-                        + sizeof(Lisp_Object) - 1) /* round up */        \
+                        + sizeof (Lisp_Object) - 1) /* round up */       \
                       / sizeof (Lisp_Object))
 
 /* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
    at the end and we need to compute the number of Lisp_Object fields (the
    ones that the GC needs to trace).  */
 #define PSEUDOVECSIZE(type, nonlispfield) \
-  ((offsetof(type, nonlispfield) - offsetof(struct Lisp_Vector, contents[0])) \
+  ((offsetof (type, nonlispfield) - offsetof (struct Lisp_Vector, contents[0])) \
    / sizeof (Lisp_Object))
 
 /* A char-table is a kind of vectorlike, with contents are like a
@@ -888,8 +988,18 @@ struct Lisp_Vector
 
 #endif /* not __GNUC__ */
 
+/* Compute A OP B, using the unsigned comparison operator OP.  A and B
+   should be integer expressions.  This is not the same as
+   mathematical comparison; for example, UNSIGNED_CMP (0, <, -1)
+   returns 1.  For efficiency, prefer plain unsigned comparison if A
+   and B's sizes both fit (after integer promotion).  */
+#define UNSIGNED_CMP(a, op, b)                                         \
+  (max (sizeof ((a) + 0), sizeof ((b) + 0)) <= sizeof (unsigned)       \
+   ? ((a) + (unsigned) 0) op ((b) + (unsigned) 0)                      \
+   : ((a) + (uintmax_t) 0) op ((b) + (uintmax_t) 0))
+
 /* Nonzero iff C is an ASCII character.  */
-#define ASCII_CHAR_P(c) ((unsigned) (c) < 0x80)
+#define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
 
 /* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
    characters.  Do not check validity of CT.  */
@@ -908,8 +1018,7 @@ struct Lisp_Vector
 /* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
    8-bit European characters.  Do not check validity of CT.  */
 #define CHAR_TABLE_SET(CT, IDX, VAL)                                   \
-  (((IDX) >= 0 && ASCII_CHAR_P (IDX)                                   \
-    && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii))                     \
+  (ASCII_CHAR_P (IDX) && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii)    \
    ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] = VAL    \
    : char_table_set (CT, IDX, VAL))
 
@@ -980,7 +1089,7 @@ struct Lisp_Bool_Vector
        just the subtype information.  */
     struct vectorlike_header header;
     /* This is the size in bits.  */
-    EMACS_UINT size;
+    EMACS_INT size;
     /* This contains the actual bits, packed into bytes.  */
     unsigned char data[1];
   };
@@ -995,7 +1104,7 @@ struct Lisp_Bool_Vector
 
 struct Lisp_Subr
   {
-    EMACS_UINT size;
+    EMACS_INT size;
     union {
       Lisp_Object (*a0) (void);
       Lisp_Object (*a1) (Lisp_Object);
@@ -1007,7 +1116,7 @@ struct Lisp_Subr
       Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
       Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
       Lisp_Object (*aUNEVALLED) (Lisp_Object args);
-      Lisp_Object (*aMANY) (size_t, Lisp_Object *);
+      Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
     } function;
     short min_args, max_args;
     const char *symbol_name;
@@ -1034,11 +1143,9 @@ enum symbol_redirect
   SYMBOL_PLAINVAL  = 4,
   SYMBOL_VARALIAS  = 1,
   SYMBOL_LOCALIZED = 2,
-  SYMBOL_FORWARDED   = 3
+  SYMBOL_FORWARDED = 3
 };
 
-/* In a symbol, the markbit of the plist is used as the gc mark bit */
-
 struct Lisp_Symbol
 {
   unsigned gcmarkbit : 1;
@@ -1047,9 +1154,8 @@ struct Lisp_Symbol
      0 : it's a plain var, the value is in the `value' field.
      1 : it's a varalias, the value is really in the `alias' symbol.
      2 : it's a localized var, the value is in the `blv' object.
-     3 : it's a forwarding variable, the value is in `forward'.
-   */
-  enum symbol_redirect redirect : 3;
+     3 : it's a forwarding variable, the value is in `forward'.  */
+  ENUM_BF (symbol_redirect) redirect : 3;
 
   /* Non-zero means symbol is constant, i.e. changing its value
      should signal an error.  If the value is 3, then the var
@@ -1065,15 +1171,12 @@ struct Lisp_Symbol
   unsigned declared_special : 1;
 
   /* The symbol's name, as a Lisp string.
-
      The name "xname" is used to intentionally break code referring to
      the old field "name" of type pointer to struct Lisp_String.  */
   Lisp_Object xname;
 
-  /* Value of the symbol or Qunbound if unbound.  If this symbol is a
-     defvaralias, `alias' contains the symbol for which it is an
-     alias.  Use the SYMBOL_VALUE and SET_SYMBOL_VALUE macros to get
-     and set a symbol's value, to take defvaralias into account.  */
+  /* Value of the symbol or Qunbound if unbound.  Which alternative of the
+     union is used depends on the `redirect' field above.  */
   union {
     Lisp_Object value;
     struct Lisp_Symbol *alias;
@@ -1129,6 +1232,9 @@ struct Lisp_Symbol
 
 #define SYMBOL_CONSTANT_P(sym)   XSYMBOL (sym)->constant
 
+#define DEFSYM(sym, name)      \
+  do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0)
+
 \f
 /***********************************************************************
                             Hash Tables
@@ -1207,7 +1313,7 @@ struct Lisp_Hash_Table
 
 
 #define XHASH_TABLE(OBJ) \
-     ((struct Lisp_Hash_Table *) XPNTR (OBJ))
+     ((struct Lisp_Hash_Table *) XUNTAG (OBJ, Lisp_Vectorlike))
 
 #define XSET_HASH_TABLE(VAR, PTR) \
      (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
@@ -1262,16 +1368,14 @@ struct Lisp_Hash_Table
 
 struct Lisp_Misc_Any           /* Supertype of all Misc types.  */
 {
-  enum Lisp_Misc_Type type : 16;               /* = Lisp_Misc_??? */
+  ENUM_BF (Lisp_Misc_Type) type : 16;          /* = Lisp_Misc_??? */
   unsigned gcmarkbit : 1;
   int spacer : 15;
-  /* Make it as long as "Lisp_Free without padding". */
-  void *fill;
 };
 
 struct Lisp_Marker
 {
-  enum Lisp_Misc_Type type : 16;               /* = Lisp_Misc_Marker */
+  ENUM_BF (Lisp_Misc_Type) type : 16;          /* = Lisp_Misc_Marker */
   unsigned gcmarkbit : 1;
   int spacer : 13;
   /* This flag is temporarily used in the functions
@@ -1421,7 +1525,7 @@ struct Lisp_Overlay
    I.e. 9words plus 2 bits, 3words of which are for external linked lists.
 */
   {
-    enum Lisp_Misc_Type type : 16;     /* = Lisp_Misc_Overlay */
+    ENUM_BF (Lisp_Misc_Type) type : 16;        /* = Lisp_Misc_Overlay */
     unsigned gcmarkbit : 1;
     int spacer : 15;
     struct Lisp_Overlay *next;
@@ -1440,31 +1544,24 @@ struct Lisp_Kboard_Objfwd
    This type of object is used in the arg to record_unwind_protect.  */
 struct Lisp_Save_Value
   {
-    enum Lisp_Misc_Type type : 16;     /* = Lisp_Misc_Save_Value */
+    ENUM_BF (Lisp_Misc_Type) type : 16;        /* = Lisp_Misc_Save_Value */
     unsigned gcmarkbit : 1;
     int spacer : 14;
     /* If DOGC is set, POINTER is the address of a memory
        area containing INTEGER potential Lisp_Objects.  */
     unsigned int dogc : 1;
     void *pointer;
-    int integer;
+    ptrdiff_t integer;
   };
 
 
 /* A miscellaneous object, when it's on the free list.  */
 struct Lisp_Free
   {
-    enum Lisp_Misc_Type type : 16;     /* = Lisp_Misc_Free */
+    ENUM_BF (Lisp_Misc_Type) type : 16;        /* = Lisp_Misc_Free */
     unsigned gcmarkbit : 1;
     int spacer : 15;
     union Lisp_Misc *chain;
-#ifdef USE_LSB_TAG
-    /* Try to make sure that sizeof(Lisp_Misc) preserves TYPEBITS-alignment.
-       This assumes that Lisp_Marker is the largest of the alternatives and
-       that Lisp_Misc_Any has the same size as "Lisp_Free w/o padding".  */
-    char padding[((((sizeof (struct Lisp_Marker) - 1) >> GCTYPEBITS) + 1)
-                 << GCTYPEBITS) - sizeof (struct Lisp_Misc_Any)];
-#endif
   };
 
 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
@@ -1473,19 +1570,19 @@ struct Lisp_Free
 union Lisp_Misc
   {
     struct Lisp_Misc_Any u_any;           /* Supertype of all Misc types.  */
-    struct Lisp_Free u_free;      /* Includes padding to force alignment.  */
-    struct Lisp_Marker u_marker;                        /* 5 */
-    struct Lisp_Overlay u_overlay;                      /* 5 */
-    struct Lisp_Save_Value u_save_value;                /* 3 */
+    struct Lisp_Free u_free;
+    struct Lisp_Marker u_marker;
+    struct Lisp_Overlay u_overlay;
+    struct Lisp_Save_Value u_save_value;
   };
 
 union Lisp_Fwd
   {
-    struct Lisp_Intfwd u_intfwd;                        /* 2 */
-    struct Lisp_Boolfwd u_boolfwd;                      /* 2 */
-    struct Lisp_Objfwd u_objfwd;                        /* 2 */
-    struct Lisp_Buffer_Objfwd u_buffer_objfwd;          /* 2 */
-    struct Lisp_Kboard_Objfwd u_kboard_objfwd;          /* 2 */
+    struct Lisp_Intfwd u_intfwd;
+    struct Lisp_Boolfwd u_boolfwd;
+    struct Lisp_Objfwd u_objfwd;
+    struct Lisp_Buffer_Objfwd u_buffer_objfwd;
+    struct Lisp_Kboard_Objfwd u_kboard_objfwd;
   };
 \f
 /* Lisp floating point type */
@@ -1546,16 +1643,6 @@ typedef unsigned char UCHAR;
    itself.  */
 #define CHARACTERBITS 22
 
-/* The maximum byte size consumed by push_key_description.
-   All callers should assure that at least this size of memory is
-   allocated at the place pointed by the second argument.
-
-   There are 6 modifiers, each consumes 2 chars.
-   The octal form of a character code consumes
-   (1 + CHARACTERBITS / 3 + 1) chars (including backslash at the head).
-   We need one more byte for string terminator `\0'.  */
-#define KEY_DESCRIPTION_SIZE ((2 * 6) + 1 + (CHARACTERBITS / 3) + 1 + 1)
-
 \f
 /* The glyph datatype, used to represent characters on the display.
    It consists of a char code and a face id.  */
@@ -1576,7 +1663,7 @@ typedef struct {
 #define SET_GLYPH(glyph, char, face) ((glyph).ch = (char), (glyph).face_id = (face))
 
 /* Return 1 if GLYPH contains valid character code.  */
-#define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph), 1)
+#define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph))
 
 
 /* Glyph Code from a display vector may either be an integer which
@@ -1590,7 +1677,7 @@ typedef struct {
   (CONSP (gc) ? XINT (XCDR (gc)) : INTEGERP (gc) ? (XINT (gc) >> CHARACTERBITS) : DEFAULT_FACE_ID)
 
 /* Return 1 if glyph code from display vector contains valid character code.  */
-#define GLYPH_CODE_CHAR_VALID_P(gc) CHAR_VALID_P (GLYPH_CODE_CHAR (gc), 1)
+#define GLYPH_CODE_CHAR_VALID_P(gc) CHAR_VALID_P (GLYPH_CODE_CHAR (gc))
 
 #define GLYPH_CODE_P(gc) ((CONSP (gc) && INTEGERP (XCAR (gc)) && INTEGERP (XCDR (gc))) || INTEGERP (gc))
 
@@ -1651,6 +1738,11 @@ typedef struct {
 #define NUMBERP(x) (INTEGERP (x) || FLOATP (x))
 #define NATNUMP(x) (INTEGERP (x) && XINT (x) >= 0)
 
+#define RANGED_INTEGERP(lo, x, hi) \
+  (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi))
+#define TYPE_RANGED_INTEGERP(type, x) \
+  RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type))
+
 #define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x))))
 #define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
 #define MISCP(x) (XTYPE ((x)) == Lisp_Misc)
@@ -1679,7 +1771,7 @@ typedef struct {
    code is CODE.  */
 #define TYPED_PSEUDOVECTORP(x, t, code)                                \
   (VECTORLIKEP (x)                                             \
-   && (((((struct t *) XPNTR (x))->size                                \
+   && (((((struct t *) XUNTAG (x, Lisp_Vectorlike))->size      \
         & (PSEUDOVECTOR_FLAG | (code))))                       \
        == (PSEUDOVECTOR_FLAG | (code))))
 
@@ -1823,9 +1915,6 @@ typedef struct {
     CHECK_NATNUM (tmp);                        \
     XSETCDR ((x), tmp);                        \
   } while (0)
-
-/* Cast pointers to this type to compare them.  */
-#define PNTR_COMPARISON_TYPE uintptr_t
 \f
 /* Define a built-in function for calling from Lisp.
  `lname' should be the name to give the function in Lisp,
@@ -1854,17 +1943,27 @@ typedef struct {
 
 /* This version of DEFUN declares a function prototype with the right
    arguments, so we can catch errors with maxargs at compile-time.  */
-#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
-  Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                          \
-  static DECL_ALIGN (struct Lisp_Subr, sname) =                                \
-    { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),    \
-      { .a ## maxargs = fnname },                              \
-      minargs, maxargs, lname, intspec, 0};                            \
-  Lisp_Object fnname
+#ifdef _MSC_VER
+#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)    \
+   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                         \
+   static DECL_ALIGN (struct Lisp_Subr, sname) =                       \
+     { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),   \
+      { (Lisp_Object (__cdecl *)(void))fnname },                        \
+       minargs, maxargs, lname, intspec, 0};                           \
+   Lisp_Object fnname
+#else  /* not _MSC_VER */
+#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)    \
+   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                         \
+   static DECL_ALIGN (struct Lisp_Subr, sname) =                       \
+     { PVEC_SUBR,                                                      \
+      { .a ## maxargs = fnname },                                      \
+       minargs, maxargs, lname, intspec, 0};                           \
+   Lisp_Object fnname
+#endif
 
 /* Note that the weird token-substitution semantics of ANSI C makes
    this work for MANY and UNEVALLED.  */
-#define DEFUN_ARGS_MANY                (size_t, Lisp_Object *)
+#define DEFUN_ARGS_MANY                (ptrdiff_t, Lisp_Object *)
 #define DEFUN_ARGS_UNEVALLED   (Lisp_Object)
 #define DEFUN_ARGS_0   (void)
 #define DEFUN_ARGS_1   (Lisp_Object)
@@ -1947,10 +2046,7 @@ extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int);
 #define DEFVAR_KBOARD(lname, vname, doc)                       \
   do {                                                         \
     static struct Lisp_Kboard_Objfwd ko_fwd;                   \
-    defvar_kboard (&ko_fwd,                                    \
-                  lname,                                       \
-                  (int)((char *)(&current_kboard->vname ## _)  \
-                        - (char *)current_kboard));            \
+    defvar_kboard (&ko_fwd, lname, offsetof (KBOARD, vname ## _)); \
   } while (0)
 
 
@@ -2065,7 +2161,10 @@ extern char *stack_bottom;
    Exception: if you set immediate_quit to nonzero,
    then the handler that responds to the C-g does the quit itself.
    This is a good thing to do around a loop that has no side effects
-   and (in particular) cannot call arbitrary Lisp code.  */
+   and (in particular) cannot call arbitrary Lisp code.
+
+   If quit-flag is set to `kill-emacs' the SIGINT handler has received
+   a request to exit Emacs when it is safe to do.  */
 
 #ifdef SYNC_INPUT
 extern void process_pending_signals (void);
@@ -2077,16 +2176,11 @@ extern int pending_signals;
 #define ELSE_PENDING_SIGNALS
 #endif /* not SYNC_INPUT */
 
+extern void process_quit_flag (void);
 #define QUIT                                           \
   do {                                                 \
     if (!NILP (Vquit_flag) && NILP (Vinhibit_quit))    \
-      {                                                        \
-        Lisp_Object flag = Vquit_flag;                 \
-       Vquit_flag = Qnil;                              \
-       if (EQ (Vthrow_on_input, flag))                 \
-         Fthrow (Vthrow_on_input, Qt);                 \
-       Fsignal (Qquit, Qnil);                          \
-      }                                                        \
+      process_quit_flag ();                            \
     ELSE_PENDING_SIGNALS                               \
   } while (0)
 
@@ -2129,7 +2223,7 @@ struct gcpro
   volatile Lisp_Object *var;
 
   /* Number of consecutive protected variables.  */
-  size_t nvars;
+  ptrdiff_t nvars;
 
 #ifdef DEBUG_GCPRO
   int level;
@@ -2152,7 +2246,7 @@ struct gcpro
 #define GC_USE_GCPROS_CHECK_ZOMBIES    3
 
 #ifndef GC_MARK_STACK
-#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE
+#define GC_MARK_STACK GC_MAKE_GCPROS_NOOPS
 #endif
 
 /* Whether we do the stack marking manually.  */
@@ -2160,143 +2254,127 @@ struct gcpro
                          || GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS)
 
 
-#define GCPRO1(var) \
-  GCPRO1_VAR (var, gcpro)
-#define GCPRO2(var1, var2) \
-  GCPRO2_VAR (var1, var2, gcpro)
-#define GCPRO3(var1, var2, var3) \
-  GCPRO3_VAR (var1, var2, var3, gcpro)
-#define GCPRO4(var1, var2, var3, var4) \
-  GCPRO4_VAR (var1, var2, var3, var4, gcpro)
-#define GCPRO5(var1, var2, var3, var4, var5) \
-  GCPRO5_VAR (var1, var2, var3, var4, var5, gcpro)
-#define GCPRO6(var1, var2, var3, var4, var5, var6) \
-  GCPRO6_VAR (var1, var2, var3, var4, var5, var6, gcpro)
-#define UNGCPRO UNGCPRO_VAR (gcpro)
-
 #if GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS
 
 /* Do something silly with gcproN vars just so gcc shuts up.  */
 /* You get warnings from MIPSPro...  */
 
-#define GCPRO1_VAR(var, gcpro) ((void) gcpro##1)
-#define GCPRO2_VAR(var1, var2, gcpro) \
-  ((void) gcpro##2, (void) gcpro##1)
-#define GCPRO3_VAR(var1, var2, var3, gcpro) \
-  ((void) gcpro##3, (void) gcpro##2, (void) gcpro##1)
-#define GCPRO4_VAR(var1, var2, var3, var4, gcpro) \
-  ((void) gcpro##4, (void) gcpro##3, (void) gcpro##2, (void) gcpro##1)
-#define GCPRO5_VAR(var1, var2, var3, var4, var5, gcpro) \
-  ((void) gcpro##5, (void) gcpro##4, (void) gcpro##3, (void) gcpro##2, \
-   (void) gcpro##1)
-#define GCPRO6_VAR(var1, var2, var3, var4, var5, var6, gcpro) \
-  ((void) gcpro##6, (void) gcpro##5, (void) gcpro##4, (void) gcpro##3, \
-   (void) gcpro##2, (void) gcpro##1)
-#define UNGCPRO_VAR(gcpro) ((void) 0)
+#define GCPRO1(varname) ((void) gcpro1)
+#define GCPRO2(varname1, varname2) ((void) gcpro2, (void) gcpro1)
+#define GCPRO3(varname1, varname2, varname3) \
+  ((void) gcpro3, (void) gcpro2, (void) gcpro1)
+#define GCPRO4(varname1, varname2, varname3, varname4) \
+  ((void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
+#define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
+  ((void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, (void) gcpro1)
+#define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
+  ((void) gcpro6, (void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, \
+   (void) gcpro1)
+#define UNGCPRO ((void) 0)
 
 #else /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
 
 #ifndef DEBUG_GCPRO
 
-#define GCPRO1_VAR(var, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var; gcpro##1.nvars = 1; \
-  gcprolist = &gcpro##1; }
-
-#define GCPRO2_VAR(var1, var2, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcprolist = &gcpro##2; }
-
-#define GCPRO3_VAR(var1, var2, var3, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcprolist = &gcpro##3; }
-
-#define GCPRO4_VAR(var1, var2, var3, var4, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##4.next = &gcpro##3; gcpro##4.var = &var4; gcpro##4.nvars = 1; \
-  gcprolist = &gcpro##4; }
-
-#define GCPRO5_VAR(var1, var2, var3, var4, var5, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##4.next = &gcpro##3; gcpro##4.var = &var4; gcpro##4.nvars = 1; \
-  gcpro##5.next = &gcpro##4; gcpro##5.var = &var5; gcpro##5.nvars = 1; \
-  gcprolist = &gcpro##5; }
-
-#define GCPRO6_VAR(var1, var2, var3, var4, var5, var6, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##4.next = &gcpro##3; gcpro##4.var = &var4; gcpro##4.nvars = 1; \
-  gcpro##5.next = &gcpro##4; gcpro##5.var = &var5; gcpro##5.nvars = 1; \
-  gcpro##6.next = &gcpro##5; gcpro##6.var = &var6; gcpro##6.nvars = 1; \
-  gcprolist = &gcpro##6; }
-
-#define UNGCPRO_VAR(gcpro) (gcprolist = gcpro##1.next)
+#define GCPRO1(varname) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
+  gcprolist = &gcpro1; }
+
+#define GCPRO2(varname1, varname2) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcprolist = &gcpro2; }
+
+#define GCPRO3(varname1, varname2, varname3) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcprolist = &gcpro3; }
+
+#define GCPRO4(varname1, varname2, varname3, varname4) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
+  gcprolist = &gcpro4; }
+
+#define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
+  gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
+  gcprolist = &gcpro5; }
+
+#define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
+  gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
+  gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
+  gcprolist = &gcpro6; }
+
+#define UNGCPRO (gcprolist = gcpro1.next)
 
 #else
 
 extern int gcpro_level;
 
-#define GCPRO1_VAR(var, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var; gcpro##1.nvars = 1; \
-  gcpro##1.level = gcpro_level++; \
-  gcprolist = &gcpro##1; }
-
-#define GCPRO2_VAR(var1, var2, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##1.level = gcpro_level; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##2.level = gcpro_level++; \
-  gcprolist = &gcpro##2; }
-
-#define GCPRO3_VAR(var1, var2, var3, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##1.level = gcpro_level; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##3.level = gcpro_level++; \
-  gcprolist = &gcpro##3; }
-
-#define GCPRO4_VAR(var1, var2, var3, var4, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##1.level = gcpro_level; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##4.next = &gcpro##3; gcpro##4.var = &var4; gcpro##4.nvars = 1; \
-  gcpro##4.level = gcpro_level++; \
-  gcprolist = &gcpro##4; }
-
-#define GCPRO5_VAR(var1, var2, var3, var4, var5, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##1.level = gcpro_level; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##4.next = &gcpro##3; gcpro##4.var = &var4; gcpro##4.nvars = 1; \
-  gcpro##5.next = &gcpro##4; gcpro##5.var = &var5; gcpro##5.nvars = 1; \
-  gcpro##5.level = gcpro_level++; \
-  gcprolist = &gcpro##5; }
-
-#define GCPRO6_VAR(var1, var2, var3, var4, var5, var6, gcpro) \
- {gcpro##1.next = gcprolist; gcpro##1.var = &var1; gcpro##1.nvars = 1; \
-  gcpro##1.level = gcpro_level; \
-  gcpro##2.next = &gcpro##1; gcpro##2.var = &var2; gcpro##2.nvars = 1; \
-  gcpro##3.next = &gcpro##2; gcpro##3.var = &var3; gcpro##3.nvars = 1; \
-  gcpro##4.next = &gcpro##3; gcpro##4.var = &var4; gcpro##4.nvars = 1; \
-  gcpro##5.next = &gcpro##4; gcpro##5.var = &var5; gcpro##5.nvars = 1; \
-  gcpro##6.next = &gcpro##5; gcpro##6.var = &var6; gcpro##6.nvars = 1; \
-  gcpro##6.level = gcpro_level++; \
-  gcprolist = &gcpro##6; }
-
-#define UNGCPRO_VAR(gcpro) \
- ((--gcpro_level != gcpro##1.level) \
-  ? (abort (), 0) \
-  : ((gcprolist = gcpro##1.next), 0))
+#define GCPRO1(varname) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
+  gcpro1.level = gcpro_level++; \
+  gcprolist = &gcpro1; }
+
+#define GCPRO2(varname1, varname2) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro1.level = gcpro_level; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro2.level = gcpro_level++; \
+  gcprolist = &gcpro2; }
+
+#define GCPRO3(varname1, varname2, varname3) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro1.level = gcpro_level; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro3.level = gcpro_level++; \
+  gcprolist = &gcpro3; }
+
+#define GCPRO4(varname1, varname2, varname3, varname4) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro1.level = gcpro_level; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
+  gcpro4.level = gcpro_level++; \
+  gcprolist = &gcpro4; }
+
+#define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro1.level = gcpro_level; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
+  gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
+  gcpro5.level = gcpro_level++; \
+  gcprolist = &gcpro5; }
+
+#define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
+ {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
+  gcpro1.level = gcpro_level; \
+  gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
+  gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
+  gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
+  gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
+  gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
+  gcpro6.level = gcpro_level++; \
+  gcprolist = &gcpro6; }
+
+#define UNGCPRO                                        \
+ ((--gcpro_level != gcpro1.level)              \
+  ? (abort (), 0)                              \
+  : ((gcprolist = gcpro1.next), 0))
 
 #endif /* DEBUG_GCPRO */
 #endif /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
@@ -2335,7 +2413,7 @@ extern Lisp_Object Qerror, Qquit, Qargs_out_of_range;
 extern Lisp_Object Qvoid_variable, Qvoid_function;
 extern Lisp_Object Qinvalid_read_syntax;
 extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
-extern Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
+extern Lisp_Object Quser_error, Qend_of_file, Qarith_error, Qmark_inactive;
 extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
 extern Lisp_Object Qtext_read_only;
 extern Lisp_Object Qinteractive_form;
@@ -2501,18 +2579,20 @@ extern void syms_of_syntax (void);
 
 /* Defined in fns.c */
 extern Lisp_Object QCrehash_size, QCrehash_threshold;
+enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
 extern EMACS_INT next_almost_prime (EMACS_INT);
 extern Lisp_Object larger_vector (Lisp_Object, EMACS_INT, Lisp_Object);
 extern void sweep_weak_hash_tables (void);
 extern Lisp_Object Qcursor_in_echo_area;
 extern Lisp_Object Qstring_lessp;
 extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql;
+EMACS_UINT hash_string (char const *, ptrdiff_t);
 EMACS_UINT sxhash (Lisp_Object, int);
 Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object,
                              Lisp_Object, Lisp_Object, Lisp_Object,
                              Lisp_Object);
-EMACS_INT hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
-EMACS_INT hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
+ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
+ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
                    EMACS_UINT);
 void init_weak_hash_tables (void);
 extern void init_fns (void);
@@ -2595,7 +2675,7 @@ extern void init_fringe_once (void);
 /* Defined in image.c */
 extern Lisp_Object QCascent, QCmargin, QCrelief;
 extern Lisp_Object QCconversion;
-extern int x_bitmap_mask (struct frame *, int);
+extern int x_bitmap_mask (struct frame *, ptrdiff_t);
 extern void syms_of_image (void);
 extern void init_image (void);
 
@@ -2603,6 +2683,7 @@ extern void init_image (void);
 extern Lisp_Object Qinhibit_modification_hooks;
 extern void move_gap (EMACS_INT);
 extern void move_gap_both (EMACS_INT, EMACS_INT);
+extern void buffer_overflow (void) NO_RETURN;
 extern void make_gap (EMACS_INT);
 extern EMACS_INT copy_text (const unsigned char *, unsigned char *,
                            EMACS_INT, int, int);
@@ -2710,7 +2791,7 @@ extern int pos_visible_p (struct window *, EMACS_INT, int *,
 extern void syms_of_xsettings (void);
 
 /* Defined in vm-limit.c.  */
-extern void memory_warnings (POINTER_TYPE *, void (*warnfun) (const char *));
+extern void memory_warnings (void *, void (*warnfun) (const char *));
 
 /* Defined in alloc.c */
 extern void check_pure_size (void);
@@ -2778,7 +2859,7 @@ extern int abort_on_gc;
 extern Lisp_Object make_float (double);
 extern void display_malloc_warning (void);
 extern int inhibit_garbage_collection (void);
-extern Lisp_Object make_save_value (void *, int);
+extern Lisp_Object make_save_value (void *, ptrdiff_t);
 extern void free_marker (Lisp_Object);
 extern void free_cons (struct Lisp_Cons *);
 extern void init_alloc_once (void);
@@ -2787,6 +2868,14 @@ extern void syms_of_alloc (void);
 extern struct buffer * allocate_buffer (void);
 extern int valid_lisp_object_p (Lisp_Object);
 
+#ifdef REL_ALLOC
+/* Defined in ralloc.c */
+extern void *r_alloc (void **, size_t);
+extern void r_alloc_free (void **);
+extern void *r_re_alloc (void **, size_t);
+extern void r_alloc_reset_variable (void **, void **);
+#endif
+
 /* Defined in chartab.c */
 EXFUN (Fmake_char_table, 2);
 EXFUN (Fset_char_table_parent, 2);
@@ -2809,6 +2898,7 @@ extern void map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Ob
                                        Lisp_Object, Lisp_Object,
                                        Lisp_Object, struct charset *,
                                        unsigned, unsigned);
+extern Lisp_Object uniprop_table (Lisp_Object);
 extern void syms_of_chartab (void);
 
 /* Defined in print.c */
@@ -2834,7 +2924,16 @@ extern void float_to_string (char *, double);
 extern void syms_of_print (void);
 
 /* Defined in doprnt.c */
-extern size_t doprnt (char *, size_t, const char *, const char *, va_list);
+extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
+                        va_list);
+extern ptrdiff_t esprintf (char *, char const *, ...)
+  ATTRIBUTE_FORMAT_PRINTF (2, 3);
+extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
+                          char const *, ...)
+  ATTRIBUTE_FORMAT_PRINTF (5, 6);
+extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
+                           char const *, va_list)
+  ATTRIBUTE_FORMAT_PRINTF (5, 0);
 
 /* Defined in lread.c.  */
 extern Lisp_Object Qvariable_documentation, Qstandard_input;
@@ -2873,6 +2972,7 @@ extern Lisp_Object Qinhibit_quit, Qclosure;
 extern Lisp_Object Qand_rest;
 extern Lisp_Object Vautoload_queue;
 extern Lisp_Object Vsignaling_function;
+extern Lisp_Object inhibit_lisp_code;
 extern int handling_signal;
 #if BYTE_MARK_STACK
 extern struct catchtag *catchlist;
@@ -2890,9 +2990,9 @@ EXFUN (Frun_hooks, MANY);
 EXFUN (Frun_hook_with_args, MANY);
 EXFUN (Frun_hook_with_args_until_failure, MANY);
 extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
-extern Lisp_Object run_hook_with_args (size_t nargs, Lisp_Object *args,
+extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
                                       Lisp_Object (*funcall)
-                                      (size_t nargs, Lisp_Object *args));
+                                      (ptrdiff_t nargs, Lisp_Object *args));
 EXFUN (Fprogn, UNEVALLED);
 EXFUN (Finteractive_p, 0);
 EXFUN (Fthrow, 2) NO_RETURN;
@@ -2924,7 +3024,7 @@ extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_
 extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
 extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
 extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
-extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (size_t, Lisp_Object *), size_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object));
+extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object));
 extern void specbind (Lisp_Object, Lisp_Object);
 extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
 extern Lisp_Object unbind_to (int, Lisp_Object);
@@ -2934,7 +3034,7 @@ extern void verror (const char *, va_list)
 extern void do_autoload (Lisp_Object, Lisp_Object);
 extern Lisp_Object un_autoload (Lisp_Object);
 extern void init_eval_once (void);
-extern Lisp_Object safe_call (size_t, Lisp_Object *);
+extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object *);
 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
 extern void init_eval (void);
@@ -3081,10 +3181,6 @@ extern void syms_of_fileio (void);
 extern Lisp_Object make_temp_name (Lisp_Object, int);
 extern Lisp_Object Qdelete_file;
 
-/* Defined in abbrev.c */
-
-extern void syms_of_abbrev (void);
-
 /* Defined in search.c */
 extern void shrink_regexp_cache (void);
 EXFUN (Fstring_match, 3);
@@ -3126,7 +3222,7 @@ EXFUN (Fread_minibuffer, 2);
 EXFUN (Feval_minibuffer, 2);
 EXFUN (Fread_string, 5);
 EXFUN (Fassoc_string, 3);
-extern Lisp_Object get_minibuffer (int);
+extern Lisp_Object get_minibuffer (EMACS_INT);
 extern void init_minibuf_once (void);
 extern void syms_of_minibuf (void);
 
@@ -3190,8 +3286,6 @@ extern void force_auto_save_soon (void);
 extern void init_keyboard (void);
 extern void syms_of_keyboard (void);
 extern void keys_of_keyboard (void);
-extern char *push_key_description (unsigned int, char *, int);
-
 
 /* Defined in indent.c */
 EXFUN (Fvertical_motion, 2);
@@ -3228,7 +3322,7 @@ extern void syms_of_frame (void);
 /* Defined in emacs.c */
 extern char **initial_argv;
 extern int initial_argc;
-#if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
+#if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
 extern int display_arg;
 #endif
 extern Lisp_Object decode_env_path (const char *, const char *);
@@ -3237,6 +3331,7 @@ extern Lisp_Object Qfile_name_handler_alist;
 #ifdef FLOAT_CATCH_SIGILL
 extern void fatal_error_signal (int);
 #endif
+extern Lisp_Object Qkill_emacs;
 EXFUN (Fkill_emacs, 1) NO_RETURN;
 #if HAVE_SETLOCALE
 void fixup_locale (void);
@@ -3316,7 +3411,7 @@ extern void mark_byte_stack (void);
 #endif
 extern void unmark_byte_stack (void);
 extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
-                                  Lisp_Object, int, Lisp_Object *);
+                                  Lisp_Object, ptrdiff_t, Lisp_Object *);
 
 /* Defined in macros.c */
 extern Lisp_Object Qexecute_kbd_macro;
@@ -3395,18 +3490,6 @@ extern EMACS_INT emacs_read (int, char *, EMACS_INT);
 extern EMACS_INT emacs_write (int, const char *, EMACS_INT);
 enum { READLINK_BUFSIZE = 1024 };
 extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]);
-#ifndef HAVE_MEMSET
-extern void *memset (void *, int, size_t);
-#endif
-#ifndef HAVE_MEMCPY
-extern void *memcpy (void *, void *, size_t);
-#endif
-#ifndef HAVE_MEMMOVE
-extern void *memmove (void *, void *, size_t);
-#endif
-#ifndef HAVE_MEMCMP
-extern int memcmp (void *, void *, size_t);
-#endif
 
 EXFUN (Funlock_buffer, 0);
 extern void unlock_all_files (void);
@@ -3501,6 +3584,7 @@ EXFUN (Fmsdos_downcase_filename, 1);
 #ifdef HAVE_LIBXML2
 /* Defined in xml.c */
 extern void syms_of_xml (void);
+extern void xml_cleanup_parser (void);
 #endif
 
 #ifdef HAVE_MENUS
@@ -3524,9 +3608,12 @@ extern int initialized;
 
 extern int immediate_quit;         /* Nonzero means ^G can quit instantly */
 
-extern POINTER_TYPE *xmalloc (size_t);
-extern POINTER_TYPE *xrealloc (POINTER_TYPE *, size_t);
-extern void xfree (POINTER_TYPE *);
+extern void *xmalloc (size_t);
+extern void *xrealloc (void *, size_t);
+extern void xfree (void *);
+extern void *xnmalloc (ptrdiff_t, ptrdiff_t);
+extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
+extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
 
 extern char *xstrdup (const char *);
 
@@ -3556,29 +3643,19 @@ extern void init_system_name (void);
 
 #define SWITCH_ENUM_CAST(x) (x)
 
-/* Loop over Lisp list LIST.  Signal an error if LIST is not a proper
-   list, or if it contains circles.
-
-   HARE and TORTOISE should be the names of Lisp_Object variables, and
-   N should be the name of an EMACS_INT variable declared in the
-   function where the macro is used.  Each nested loop should use
-   its own variables.
+/* Use this to suppress gcc's warnings.  */
+#ifdef lint
 
-   In the loop body, HARE is set to each cons of LIST, and N is the
-   length of the list processed so far.  */
+/* Use CODE only if lint checking is in effect.  */
+# define IF_LINT(Code) Code
 
-#define LIST_END_P(list, obj)                          \
-  (NILP (obj)                                          \
-   ? 1                                                 \
-   : (CONSP (obj)                                      \
-      ? 0                                              \
-      : (wrong_type_argument (Qlistp, (list))), 1))
+/* Assume that the expression COND is true.  This differs in intent
+   from 'assert', as it is a message from the programmer to the compiler.  */
+# define lint_assume(cond) ((cond) ? (void) 0 : abort ())
 
-/* Use this to suppress gcc's `...may be used before initialized' warnings. */
-#ifdef lint
-# define IF_LINT(Code) Code
 #else
 # define IF_LINT(Code) /* empty */
+# define lint_assume(cond) ((void) (0 && (cond)))
 #endif
 
 /* The ubiquitous min and max macros.  */
@@ -3593,7 +3670,7 @@ extern void init_system_name (void);
 /* We used to use `abs', but that clashes with system headers on some
    platforms, and using a name reserved by Standard C is a bad idea
    anyway.  */
-#if !defined(eabs)
+#if !defined (eabs)
 #define eabs(x)         ((x) < 0 ? -(x) : (x))
 #endif
 
@@ -3601,9 +3678,7 @@ extern void init_system_name (void);
    fixnum.  */
 
 #define make_fixnum_or_float(val) \
-   (FIXNUM_OVERFLOW_P (val) \
-    ? make_float (val) \
-    : make_number ((EMACS_INT)(val)))
+   (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
 
 
 /* Checks the `cycle check' variable CHECK to see if it indicates that
@@ -3656,6 +3731,23 @@ extern Lisp_Object safe_alloca_unwind (Lisp_Object);
       }                                                          \
   } while (0)
 
+/* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
+   NITEMS items, each of the same type as *BUF.  MULTIPLIER must
+   positive.  The code is tuned for MULTIPLIER being a constant.  */
+
+#define SAFE_NALLOCA(buf, multiplier, nitems)                  \
+  do {                                                         \
+    if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \
+      (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems));        \
+    else                                                       \
+      {                                                                 \
+       (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \
+       sa_must_free = 1;                                        \
+       record_unwind_protect (safe_alloca_unwind,               \
+                              make_save_value (buf, 0));        \
+      }                                                                 \
+  } while (0)
+
 /* SAFE_FREE frees xmalloced memory and enables GC as needed.  */
 
 #define SAFE_FREE()                    \
@@ -3671,18 +3763,19 @@ extern Lisp_Object safe_alloca_unwind (Lisp_Object);
 
 #define SAFE_ALLOCA_LISP(buf, nelt)                      \
   do {                                                   \
-    int size_ = (nelt) * sizeof (Lisp_Object);           \
-    if (size_ < MAX_ALLOCA)                              \
-      buf = (Lisp_Object *) alloca (size_);              \
-    else                                                 \
+    if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object))      \
+      buf = (Lisp_Object *) alloca ((nelt) * sizeof (Lisp_Object));    \
+    else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
       {                                                          \
        Lisp_Object arg_;                                 \
-       buf = (Lisp_Object *) xmalloc (size_);            \
+       buf = (Lisp_Object *) xmalloc ((nelt) * sizeof (Lisp_Object));  \
        arg_ = make_save_value (buf, nelt);               \
        XSAVE_VALUE (arg_)->dogc = 1;                     \
        sa_must_free = 1;                                 \
        record_unwind_protect (safe_alloca_unwind, arg_); \
       }                                                          \
+    else                                                 \
+      memory_full (SIZE_MAX);                            \
   } while (0)