(HAVE_INDEX, HAVE_RINDEX, HAVE_STRINGS_H): Add undefs.
[bpt/emacs.git] / src / data.c
index f2dd583..0e393bf 100644 (file)
@@ -1,5 +1,5 @@
 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,88,93,94,95,97,98,99,2000 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,32 +19,19 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 
-#include <signal.h>
-
 #include <config.h>
-
-/* Put this before lisp.h so that lisp.h can define DBL_DIG if not defined.  */
-#ifdef LISP_FLOAT_TYPE
-#ifdef STDC_HEADERS
-#include <float.h>
-#endif
-#endif
-
+#include <signal.h>
+#include <stdio.h>
 #include "lisp.h"
 #include "puresize.h"
 #include "charset.h"
-
-#ifndef standalone
 #include "buffer.h"
 #include "keyboard.h"
-#endif
-
+#include "frame.h"
 #include "syssignal.h"
 
-#ifdef LISP_FLOAT_TYPE
-
 #ifdef STDC_HEADERS
-#include <stdlib.h>
+#include <float.h>
 #endif
 
 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
@@ -68,7 +55,6 @@ Boston, MA 02111-1307, USA.  */
 #endif
 
 #include <math.h>
-#endif /* LISP_FLOAT_TYPE */
 
 #if !defined (atof)
 extern double atof ();
@@ -82,29 +68,29 @@ Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
+Lisp_Object Qtext_read_only;
 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp;
 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
-Lisp_Object Qbuffer_or_string_p;
+Lisp_Object Qbuffer_or_string_p, Qkeywordp;
 Lisp_Object Qboundp, Qfboundp;
 Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
 
 Lisp_Object Qcdr;
-Lisp_Object Qad_advice_info, Qad_activate;
+Lisp_Object Qad_advice_info, Qad_activate_internal;
 
 Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
 Lisp_Object Qoverflow_error, Qunderflow_error;
 
-#ifdef LISP_FLOAT_TYPE
 Lisp_Object Qfloatp;
 Lisp_Object Qnumberp, Qnumber_or_marker_p;
-#endif
 
 static Lisp_Object Qinteger, Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
 static Lisp_Object Qfloat, Qwindow_configuration, Qwindow;
 Lisp_Object Qprocess;
 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
-static Lisp_Object Qchar_table, Qbool_vector;
+static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
+static Lisp_Object Qsubrp, Qmany, Qunevalled;
 
 static Lisp_Object swap_in_symval_forwarding ();
 
@@ -138,6 +124,7 @@ wrong_type_argument (predicate, value)
   return value;
 }
 
+void
 pure_write_error ()
 {
   error ("Attempt to modify read-only object");
@@ -179,7 +166,7 @@ sign_extend_lisp_int (num)
 /* Data type predicates */
 
 DEFUN ("eq", Feq, Seq, 2, 2, 0,
-  "T if the two args are the same Lisp object.")
+  "Return t if the two args are the same Lisp object.")
   (obj1, obj2)
      Lisp_Object obj1, obj2;
 {
@@ -188,7 +175,7 @@ DEFUN ("eq", Feq, Seq, 2, 2, 0,
   return Qnil;
 }
 
-DEFUN ("null", Fnull, Snull, 1, 1, 0, "T if OBJECT is nil.")
+DEFUN ("null", Fnull, Snull, 1, 1, 0, "Return t if OBJECT is nil.")
   (object)
      Lisp_Object object;
 {
@@ -249,19 +236,19 @@ for example, (type-of 1) returns `integer'.")
        return Qbool_vector;
       if (GC_FRAMEP (object))
        return Qframe;
+      if (GC_HASH_TABLE_P (object))
+       return Qhash_table;
       return Qvector;
 
-#ifdef LISP_FLOAT_TYPE
     case Lisp_Float:
       return Qfloat;
-#endif
 
     default:
       abort ();
     }
 }
 
-DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.")
+DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "Return t if OBJECT is a cons cell.")
   (object)
      Lisp_Object object;
 {
@@ -270,7 +257,8 @@ DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.")
   return Qnil;
 }
 
-DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell.  This includes nil.")
+DEFUN ("atom", Fatom, Satom, 1, 1, 0,
+       "Return t if OBJECT is not a cons cell.  This includes nil.")
   (object)
      Lisp_Object object;
 {
@@ -279,7 +267,8 @@ DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell.  This inc
   return Qt;
 }
 
-DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list.  This includes nil.")
+DEFUN ("listp", Flistp, Slistp, 1, 1, 0,
+       "Return t if OBJECT is a list.  This includes nil.")
   (object)
      Lisp_Object object;
 {
@@ -288,7 +277,8 @@ DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list.  This includes
   return Qnil;
 }
 
-DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list.  Lists include nil.")
+DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0,
+       "Return t if OBJECT is not a list.  Lists include nil.")
   (object)
      Lisp_Object object;
 {
@@ -297,7 +287,8 @@ DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list.  Lists i
   return Qt;
 }
 \f
-DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.")
+DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
+       "Return t if OBJECT is a symbol.")
   (object)
      Lisp_Object object;
 {
@@ -306,7 +297,24 @@ DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.")
   return Qnil;
 }
 
-DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.")
+/* Define this in C to avoid unnecessarily consing up the symbol
+   name.  */
+DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0,
+       "Return t if OBJECT is a keyword.\n\
+This means that it is a symbol with a print name beginning with `:'\n\
+interned in the initial obarray.")
+  (object)
+     Lisp_Object object;
+{
+  if (SYMBOLP (object)
+      && XSYMBOL (object)->name->data[0] == ':'
+      && EQ (XSYMBOL (object)->obarray, initial_obarray))
+    return Qt;
+  return Qnil;
+}
+
+DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0,
+       "Return t if OBJECT is a vector.")
   (object)
      Lisp_Object object;
 {
@@ -315,7 +323,8 @@ DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.")
   return Qnil;
 }
 
-DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.")
+DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0,
+       "Return t if OBJECT is a string.")
   (object)
      Lisp_Object object;
 {
@@ -324,7 +333,18 @@ DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.")
   return Qnil;
 }
 
-DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0, "T if OBJECT is a char-table.")
+DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p,
+       1, 1, 0, "Return t if OBJECT is a multibyte string.")
+  (object)
+     Lisp_Object object;
+{
+  if (STRINGP (object) && STRING_MULTIBYTE (object))
+    return Qt;
+  return Qnil;
+}
+
+DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0,
+       "Return t if OBJECT is a char-table.")
   (object)
      Lisp_Object object;
 {
@@ -335,7 +355,7 @@ DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0, "T if OBJECT is a
 
 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
        Svector_or_char_table_p, 1, 1, 0,
-       "T if OBJECT is a char-table or vector.")
+       "Return t if OBJECT is a char-table or vector.")
   (object)
      Lisp_Object object;
 {
@@ -344,7 +364,7 @@ DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
   return Qnil;
 }
 
-DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0, "T if OBJECT is a bool-vector.")
+DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0, "Return t if OBJECT is a bool-vector.")
   (object)
      Lisp_Object object;
 {
@@ -353,7 +373,7 @@ DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0, "T if OBJECT is
   return Qnil;
 }
 
-DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "T if OBJECT is an array (string or vector).")
+DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "Return t if OBJECT is an array (string or vector).")
   (object)
      Lisp_Object object;
 {
@@ -364,7 +384,7 @@ DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "T if OBJECT is an array (string or
 }
 
 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
-  "T if OBJECT is a sequence (list or array).")
+  "Return t if OBJECT is a sequence (list or array).")
   (object)
      register Lisp_Object object;
 {
@@ -374,7 +394,7 @@ DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
   return Qnil;
 }
 
-DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.")
+DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "Return t if OBJECT is an editor buffer.")
   (object)
      Lisp_Object object;
 {
@@ -383,7 +403,7 @@ DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.
   return Qnil;
 }
 
-DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
+DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "Return t if OBJECT is a marker (editor pointer).")
   (object)
      Lisp_Object object;
 {
@@ -392,7 +412,7 @@ DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor
   return Qnil;
 }
 
-DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.")
+DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "Return t if OBJECT is a built-in function.")
   (object)
      Lisp_Object object;
 {
@@ -402,7 +422,7 @@ DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.")
 }
 
 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
-       1, 1, 0, "T if OBJECT is a byte-compiled function object.")
+       1, 1, 0, "Return t if OBJECT is a byte-compiled function object.")
   (object)
      Lisp_Object object;
 {
@@ -412,7 +432,7 @@ DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
 }
 
 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
-  "T if OBJECT is a character (an integer) or a string.")
+  "Return t if OBJECT is a character (an integer) or a string.")
   (object)
      register Lisp_Object object;
 {
@@ -421,7 +441,7 @@ DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
   return Qnil;
 }
 \f
-DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is an integer.")
+DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "Return t if OBJECT is an integer.")
   (object)
      Lisp_Object object;
 {
@@ -431,7 +451,7 @@ DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is an integer.")
 }
 
 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
-  "T if OBJECT is an integer or a marker (editor pointer).")
+  "Return t if OBJECT is an integer or a marker (editor pointer).")
   (object)
      register Lisp_Object object;
 {
@@ -441,7 +461,7 @@ DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1,
 }
 
 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
-  "T if OBJECT is a nonnegative integer.")
+  "Return t if OBJECT is a nonnegative integer.")
   (object)
      Lisp_Object object;
 {
@@ -451,7 +471,7 @@ DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
 }
 
 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
-       "T if OBJECT is a number (floating point or integer).")
+       "Return t if OBJECT is a number (floating point or integer).")
   (object)
      Lisp_Object object;
 {
@@ -463,7 +483,7 @@ DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
 
 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
        Snumber_or_marker_p, 1, 1, 0,
-       "T if OBJECT is a number or a marker.")
+       "Return t if OBJECT is a number or a marker.")
   (object)
      Lisp_Object object;
 {
@@ -472,9 +492,8 @@ DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
   return Qnil;
 }
 
-#ifdef LISP_FLOAT_TYPE
 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
-       "T if OBJECT is a floating point number.")
+       "Return t if OBJECT is a floating point number.")
   (object)
      Lisp_Object object;
 {
@@ -482,7 +501,7 @@ DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
     return Qt;
   return Qnil;
 }
-#endif /* LISP_FLOAT_TYPE */
+
 \f
 /* Extract and set components of lists */
 
@@ -495,7 +514,7 @@ Error if arg is not nil and not a cons cell.  See also `car-safe'.")
   while (1)
     {
       if (CONSP (list))
-       return XCONS (list)->car;
+       return XCAR (list);
       else if (EQ (list, Qnil))
        return Qnil;
       else
@@ -509,7 +528,7 @@ DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0,
      Lisp_Object object;
 {
   if (CONSP (object))
-    return XCONS (object)->car;
+    return XCAR (object);
   else
     return Qnil;
 }
@@ -524,7 +543,7 @@ Error if arg is not nil and not a cons cell.  See also `cdr-safe'.")
   while (1)
     {
       if (CONSP (list))
-       return XCONS (list)->cdr;
+       return XCDR (list);
       else if (EQ (list, Qnil))
        return Qnil;
       else
@@ -538,7 +557,7 @@ DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0,
      Lisp_Object object;
 {
   if (CONSP (object))
-    return XCONS (object)->cdr;
+    return XCDR (object);
   else
     return Qnil;
 }
@@ -552,7 +571,7 @@ DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
     cell = wrong_type_argument (Qconsp, cell);
 
   CHECK_IMPURE (cell);
-  XCONS (cell)->car = newcar;
+  XCAR (cell) = newcar;
   return newcar;
 }
 
@@ -565,13 +584,13 @@ DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
     cell = wrong_type_argument (Qconsp, cell);
 
   CHECK_IMPURE (cell);
-  XCONS (cell)->cdr = newcdr;
+  XCDR (cell) = newcdr;
   return newcdr;
 }
 \f
 /* Extract and set components of symbols */
 
-DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "T if SYMBOL's value is not void.")
+DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "Return t if SYMBOL's value is not void.")
   (symbol)
      register Lisp_Object symbol;
 {
@@ -587,7 +606,7 @@ DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "T if SYMBOL's value is not void.")
   return (EQ (valcontents, Qunbound) ? Qnil : Qt);
 }
 
-DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "T if SYMBOL's function definition is not void.")
+DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "Return t if SYMBOL's function definition is not void.")
   (symbol)
      register Lisp_Object symbol;
 {
@@ -600,7 +619,9 @@ DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, "Make SYMBOL's value be
      register Lisp_Object symbol;
 {
   CHECK_SYMBOL (symbol, 0);
-  if (NILP (symbol) || EQ (symbol, Qt))
+  if (NILP (symbol) || EQ (symbol, Qt)
+      || (XSYMBOL (symbol)->name->data[0] == ':'
+         && EQ (XSYMBOL (symbol)->obarray, initial_obarray)))
     return Fsignal (Qsetting_constant, Fcons (symbol, Qnil));
   Fset (symbol, Qunbound);
   return symbol;
@@ -662,7 +683,7 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
   /* Handle automatic advice activation */
   if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
     {
-      call2 (Qad_activate, symbol, Qnil);
+      call2 (Qad_activate_internal, symbol, Qnil);
       definition = XSYMBOL (symbol)->function;
     }
   return definition;
@@ -674,17 +695,7 @@ Associates the function with the current load file, if any.")
   (symbol, definition)
      register Lisp_Object symbol, definition;
 {
-  CHECK_SYMBOL (symbol, 0);
-  if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (symbol)->function, Qunbound))
-    Vautoload_queue = Fcons (Fcons (symbol, XSYMBOL (symbol)->function),
-                            Vautoload_queue);
-  XSYMBOL (symbol)->function = definition;
-  /* Handle automatic advice activation */
-  if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
-    {
-      call2 (Qad_activate, symbol, Qnil);
-      definition = XSYMBOL (symbol)->function;
-    }
+  definition = Ffset (symbol, definition);
   LOADHIST_ATTACH (symbol);
   return definition;
 }
@@ -699,6 +710,28 @@ DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
   return newplist;
 }
 
+DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0,
+  "Return minimum and maximum number of args allowed for SUBR.\n\
+SUBR must be a built-in function.\n\
+The returned value is a pair (MIN . MAX).  MIN is the minimum number\n\
+of args.  MAX is the maximum number or the symbol `many', for a\n\
+function with `&rest' args, or `unevalled' for a special form.")
+  (subr)
+     Lisp_Object subr;
+{
+  short minargs, maxargs;
+  if (!SUBRP (subr))
+    wrong_type_argument (Qsubrp, subr);
+  minargs = XSUBR (subr)->min_args;
+  maxargs = XSUBR (subr)->max_args;
+  if (maxargs == MANY)
+    return Fcons (make_number (minargs), Qmany);
+  else if (maxargs == UNEVALLED)
+    return Fcons (make_number (minargs), Qunevalled);
+  else
+    return Fcons (make_number (minargs), make_number (maxargs));
+}
+
 \f
 /* Getting and setting values of symbols */
 
@@ -728,7 +761,7 @@ do_symval_forwarding (valcontents)
 
       case Lisp_Misc_Buffer_Objfwd:
        offset = XBUFFER_OBJFWD (valcontents)->offset;
-       return *(Lisp_Object *)(offset + (char *)current_buffer);
+       return PER_BUFFER_VALUE (current_buffer, offset);
 
       case Lisp_Misc_Kboard_Objfwd:
        offset = XKBOARD_OBJFWD (valcontents)->offset;
@@ -773,12 +806,15 @@ store_symval_forwarding (symbol, valcontents, newval)
            int offset = XBUFFER_OBJFWD (valcontents)->offset;
            Lisp_Object type;
 
-           type = *(Lisp_Object *)(offset + (char *)&buffer_local_types);
+           type = PER_BUFFER_TYPE (offset);
+           if (XINT (type) == -1)
+             error ("Variable %s is read-only", XSYMBOL (symbol)->name->data);
+
            if (! NILP (type) && ! NILP (newval)
                && XTYPE (newval) != XINT (type))
              buffer_slot_type_mismatch (offset);
 
-           *(Lisp_Object *)(offset + (char *)current_buffer) = newval;
+           PER_BUFFER_VALUE (current_buffer, offset) = newval;
          }
          break;
 
@@ -798,55 +834,90 @@ store_symval_forwarding (symbol, valcontents, newval)
       valcontents = XSYMBOL (symbol)->value;
       if (BUFFER_LOCAL_VALUEP (valcontents)
          || SOME_BUFFER_LOCAL_VALUEP (valcontents))
-       XBUFFER_LOCAL_VALUE (valcontents)->car = newval;
+       XBUFFER_LOCAL_VALUE (valcontents)->realvalue = newval;
       else
        XSYMBOL (symbol)->value = newval;
     }
 }
 
-/* Set up the buffer-local symbol SYMBOL for validity in the current
-   buffer.  VALCONTENTS is the contents of its value cell.
-   Return the value forwarded one step past the buffer-local indicator.  */
+/* Set up SYMBOL to refer to its global binding.
+   This makes it safe to alter the status of other bindings.  */
 
-static Lisp_Object
-swap_in_symval_forwarding (symbol, valcontents)
-     Lisp_Object symbol, valcontents;
+void
+swap_in_global_binding (symbol)
+     Lisp_Object symbol;
 {
-  /* valcontents is a pointer to a struct resembling the cons
-     (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
+  Lisp_Object valcontents, cdr;
+  
+  valcontents = XSYMBOL (symbol)->value;
+  if (!BUFFER_LOCAL_VALUEP (valcontents)
+      && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
+    abort ();
+  cdr = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
+
+  /* Unload the previously loaded binding.  */
+  Fsetcdr (XCAR (cdr),
+          do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
+  
+  /* Select the global binding in the symbol.  */
+  XCAR (cdr) = cdr;
+  store_symval_forwarding (symbol, valcontents, XCDR (cdr));
 
-     CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
-     local_var_alist, that being the element whose car is this
-     variable.  Or it can be a pointer to the
-     (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
-     an element in its alist for this variable.
+  /* Indicate that the global binding is set up now.  */
+  XBUFFER_LOCAL_VALUE (valcontents)->frame = Qnil;
+  XBUFFER_LOCAL_VALUE (valcontents)->buffer = Qnil;
+  XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
+  XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
+}
 
-     If the current buffer is not BUFFER, we store the current
-     REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
-     appropriate alist element for the buffer now current and set up
-     CURRENT-ALIST-ELEMENT.  Then we set REALVALUE out of that
-     element, and store into BUFFER.
+/* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
+   VALCONTENTS is the contents of its value cell,
+   which points to a struct Lisp_Buffer_Local_Value.
 
-     Note that REALVALUE can be a forwarding pointer. */
+   Return the value forwarded one step past the buffer-local stage.
+   This could be another forwarding pointer.  */
 
+static Lisp_Object
+swap_in_symval_forwarding (symbol, valcontents)
+     Lisp_Object symbol, valcontents;
+{
   register Lisp_Object tem1;
-  tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
+  tem1 = XBUFFER_LOCAL_VALUE (valcontents)->buffer;
 
-  if (NILP (tem1) || current_buffer != XBUFFER (tem1))
+  if (NILP (tem1)
+      || current_buffer != XBUFFER (tem1)
+      || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
+         && ! EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)))
     {
-      tem1 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+      /* Unload the previously loaded binding.  */
+      tem1 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
       Fsetcdr (tem1,
-              do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car));
+              do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
+      /* Choose the new binding.  */
       tem1 = assq_no_quit (symbol, current_buffer->local_var_alist);
+      XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
+      XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
       if (NILP (tem1))
-       tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
-      XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car = tem1;
-      XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car,
-                 current_buffer);
-      store_symval_forwarding (symbol, XBUFFER_LOCAL_VALUE (valcontents)->car,
+       {
+         if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
+           tem1 = assq_no_quit (symbol, XFRAME (selected_frame)->param_alist);
+         if (! NILP (tem1))
+           XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1;
+         else
+           tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
+       }
+      else
+       XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
+
+      /* Load the new binding.  */
+      XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) = tem1;
+      XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, current_buffer);
+      XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame;
+      store_symval_forwarding (symbol,
+                              XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
                               Fcdr (tem1));
     }
-  return XBUFFER_LOCAL_VALUE (valcontents)->car;
+  return XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
 }
 \f
 /* Find the value of a symbol, returning Qunbound if it's not bound.
@@ -859,14 +930,15 @@ Lisp_Object
 find_symbol_value (symbol)
      Lisp_Object symbol;
 {
-  register Lisp_Object valcontents, tem1;
+  register Lisp_Object valcontents;
   register Lisp_Object val;
   CHECK_SYMBOL (symbol, 0);
   valcontents = XSYMBOL (symbol)->value;
 
   if (BUFFER_LOCAL_VALUEP (valcontents)
       || SOME_BUFFER_LOCAL_VALUEP (valcontents))
-    valcontents = swap_in_symval_forwarding (symbol, valcontents);
+    valcontents = swap_in_symval_forwarding (symbol, valcontents,
+                                            current_buffer);
 
   if (MISCP (valcontents))
     {
@@ -883,8 +955,8 @@ find_symbol_value (symbol)
          return *XOBJFWD (valcontents)->objvar;
 
        case Lisp_Misc_Buffer_Objfwd:
-         return *(Lisp_Object *)(XBUFFER_OBJFWD (valcontents)->offset
-                                 + (char *)current_buffer);
+         return PER_BUFFER_VALUE (current_buffer,
+                                    XBUFFER_OBJFWD (valcontents)->offset);
 
        case Lisp_Misc_Kboard_Objfwd:
          return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
@@ -914,90 +986,106 @@ DEFUN ("set", Fset, Sset, 2, 2, 0,
   (symbol, newval)
      register Lisp_Object symbol, newval;
 {
-  return set_internal (symbol, newval, 0);
+  return set_internal (symbol, newval, current_buffer, 0);
 }
 
-/* Stpre the value NEWVAL into SYMBOL.
+/* Return 1 if SYMBOL currently has a let-binding
+   which was made in the buffer that is now current.  */
+
+static int
+let_shadows_buffer_binding_p (symbol)
+     Lisp_Object symbol;
+{
+  struct specbinding *p;
+
+  for (p = specpdl_ptr - 1; p >= specpdl; p--)
+    if (p->func == 0
+       && CONSP (p->symbol)
+       && EQ (symbol, XCAR (p->symbol))
+       && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
+      return 1;
+
+  return 0;
+}
+
+/* Store the value NEWVAL into SYMBOL.
+   If buffer-locality is an issue, BUF specifies which buffer to use.
+   (0 stands for the current buffer.)
+
    If BINDFLAG is zero, then if this symbol is supposed to become
    local in every buffer where it is set, then we make it local.
    If BINDFLAG is nonzero, we don't do that.  */
 
 Lisp_Object
-set_internal (symbol, newval, bindflag)
+set_internal (symbol, newval, buf, bindflag)
      register Lisp_Object symbol, newval;
+     struct buffer *buf;
      int bindflag;
 {
   int voide = EQ (newval, Qunbound);
 
-  register Lisp_Object valcontents, tem1, current_alist_element;
+  register Lisp_Object valcontents, innercontents, tem1, current_alist_element;
+
+  if (buf == 0)
+    buf = current_buffer;
+
+  /* If restoring in a dead buffer, do nothing.  */
+  if (NILP (buf->name))
+    return newval;
 
   CHECK_SYMBOL (symbol, 0);
-  if (NILP (symbol) || EQ (symbol, Qt))
+  if (NILP (symbol) || EQ (symbol, Qt)
+      || (XSYMBOL (symbol)->name->data[0] == ':'
+         && EQ (XSYMBOL (symbol)->obarray, initial_obarray)
+         && !EQ (newval, symbol)))
     return Fsignal (Qsetting_constant, Fcons (symbol, Qnil));
-  valcontents = XSYMBOL (symbol)->value;
+
+  innercontents = valcontents = XSYMBOL (symbol)->value;
 
   if (BUFFER_OBJFWDP (valcontents))
     {
-      register int idx = XBUFFER_OBJFWD (valcontents)->offset;
-      register int mask = XINT (*((Lisp_Object *)
-                                 (idx + (char *)&buffer_local_flags)));
-      if (mask > 0)
-       current_buffer->local_var_flags |= mask;
+      int offset = XBUFFER_OBJFWD (valcontents)->offset;
+      int idx = PER_BUFFER_IDX (offset);
+      if (idx > 0
+         && !bindflag
+         && !let_shadows_buffer_binding_p (symbol))
+       SET_PER_BUFFER_VALUE_P (buf, idx, 1);
     }
 
   else if (BUFFER_LOCAL_VALUEP (valcontents)
           || SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
-      /* valcontents is actually a pointer to a struct resembling a cons,
-        with contents something like:
-        (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE).
-
-        BUFFER is the last buffer for which this symbol's value was
-        made up to date.
-
-        CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
-        local_var_alist, that being the element whose car is this
-        variable.  Or it can be a pointer to the
-        (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not
-        have an element in its alist for this variable (that is, if
-        BUFFER sees the default value of this variable).
-
-        If we want to examine or set the value and BUFFER is current,
-        we just examine or set REALVALUE. If BUFFER is not current, we
-        store the current REALVALUE value into CURRENT-ALIST-ELEMENT,
-        then find the appropriate alist element for the buffer now
-        current and set up CURRENT-ALIST-ELEMENT.  Then we set
-        REALVALUE out of that element, and store into BUFFER.
-
-        If we are setting the variable and the current buffer does
-        not have an alist entry for this variable, an alist entry is
-        created.
-
-        Note that REALVALUE can be a forwarding pointer.  Each time
-        it is examined or set, forwarding must be done.  */
-
-      /* What value are we caching right now?  */
-      current_alist_element =
-       XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+      /* valcontents is a struct Lisp_Buffer_Local_Value.   */
+
+      /* What binding is loaded right now?  */
+      current_alist_element
+       = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
 
       /* If the current buffer is not the buffer whose binding is
-        currently cached, or if it's a Lisp_Buffer_Local_Value and
-        we're looking at the default value, the cache is invalid; we
-        need to write it out, and find the new CURRENT-ALIST-ELEMENT.  */
-      if ((current_buffer
-          != XBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car))
+        loaded, or if there may be frame-local bindings and the frame
+        isn't the right one, or if it's a Lisp_Buffer_Local_Value and
+        the default binding is loaded, the loaded binding may be the
+        wrong one.  */
+      if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents)->buffer)
+         || buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer)
+         || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
+             && !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame))
          || (BUFFER_LOCAL_VALUEP (valcontents)
-             && EQ (XCONS (current_alist_element)->car,
+             && EQ (XCAR (current_alist_element),
                     current_alist_element)))
        {
-         /* Write out the cached value for the old buffer; copy it
-            back to its alist element.  This works if the current
-            buffer only sees the default value, too.  */
+         /* The currently loaded binding is not necessarily valid.
+            We need to unload it, and choose a new binding.  */
+
+         /* Write out `realvalue' to the old loaded binding.  */
           Fsetcdr (current_alist_element,
-                  do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car));
+                  do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
+
+         /* Find the new binding.  */
+         tem1 = Fassq (symbol, buf->local_var_alist);
+         XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
+         XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
 
-         /* Find the new value for CURRENT-ALIST-ELEMENT.  */
-         tem1 = Fassq (symbol, current_buffer->local_var_alist);
          if (NILP (tem1))
            {
              /* This buffer still sees the default value.  */
@@ -1005,29 +1093,45 @@ set_internal (symbol, newval, bindflag)
              /* If the variable is a Lisp_Some_Buffer_Local_Value,
                 or if this is `let' rather than `set',
                 make CURRENT-ALIST-ELEMENT point to itself,
-                indicating that we're seeing the default value.  */
-             if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents))
-               tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
+                indicating that we're seeing the default value.
+                Likewise if the variable has been let-bound
+                in the current buffer.  */
+             if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents)
+                 || let_shadows_buffer_binding_p (symbol))
+               {
+                 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
+
+                 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
+                   tem1 = Fassq (symbol,
+                                 XFRAME (selected_frame)->param_alist);
 
+                 if (! NILP (tem1))
+                   XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1;
+                 else
+                   tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
+               }
              /* If it's a Lisp_Buffer_Local_Value, being set not bound,
-                give this buffer a new assoc for a local value and set
-                CURRENT-ALIST-ELEMENT to point to that.  */
+                and we're not within a let that was made for this buffer,
+                create a new buffer-local binding for the variable.
+                That means, give this buffer a new assoc for a local value
+                and load that binding.  */
              else
                {
                  tem1 = Fcons (symbol, Fcdr (current_alist_element));
-                 current_buffer->local_var_alist =
-                   Fcons (tem1, current_buffer->local_var_alist);
+                 buf->local_var_alist
+                   = Fcons (tem1, buf->local_var_alist);
                }
            }
-         /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT.  */
-         XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car
+
+         /* Record which binding is now loaded.  */
+         XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr)
            = tem1;
 
-         /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate.  */
-         XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car,
-                     current_buffer);
+         /* Set `buffer' and `frame' slots for thebinding now loaded.  */
+         XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, buf);
+         XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame;
        }
-      valcontents = XBUFFER_LOCAL_VALUE (valcontents)->car;
+      innercontents = XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
     }
 
   /* If storing void (making the symbol void), forward only through
@@ -1035,7 +1139,26 @@ set_internal (symbol, newval, bindflag)
   if (voide)
     store_symval_forwarding (symbol, Qnil, newval);
   else
-    store_symval_forwarding (symbol, valcontents, newval);
+    store_symval_forwarding (symbol, innercontents, newval);
+
+  /* If we just set a variable whose current binding is frame-local,
+     store the new value in the frame parameter too.  */
+
+  if (BUFFER_LOCAL_VALUEP (valcontents)
+      || SOME_BUFFER_LOCAL_VALUEP (valcontents))
+    {
+      /* What binding is loaded right now?  */
+      current_alist_element
+       = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
+
+      /* If the current buffer is not the buffer whose binding is
+        loaded, or if there may be frame-local bindings and the frame
+        isn't the right one, or if it's a Lisp_Buffer_Local_Value and
+        the default binding is loaded, the loaded binding may be the
+        wrong one.  */
+      if (XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
+       XCDR (current_alist_element) = newval;
+    }
 
   return newval;
 }
@@ -1058,10 +1181,9 @@ default_value (symbol)
      rather than letting do_symval_forwarding get the current value.  */
   if (BUFFER_OBJFWDP (valcontents))
     {
-      register int idx = XBUFFER_OBJFWD (valcontents)->offset;
-
-      if (XINT (*(Lisp_Object *) (idx + (char *) &buffer_local_flags)) != 0)
-       return *(Lisp_Object *)(idx + (char *) &buffer_defaults);
+      int offset = XBUFFER_OBJFWD (valcontents)->offset;
+      if (PER_BUFFER_IDX (offset) != 0)
+       return PER_BUFFER_DEFAULT (offset);
     }
 
   /* Handle user-created local variables.  */
@@ -1070,23 +1192,23 @@ default_value (symbol)
     {
       /* If var is set up for a buffer that lacks a local value for it,
         the current value is nominally the default value.
-        But the current value slot may be more up to date, since
+        But the `realvalue' slot may be more up to date, since
         ordinary setq stores just that slot.  So use that.  */
       Lisp_Object current_alist_element, alist_element_car;
       current_alist_element
-       = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
-      alist_element_car = XCONS (current_alist_element)->car;
+       = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
+      alist_element_car = XCAR (current_alist_element);
       if (EQ (alist_element_car, current_alist_element))
-       return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car);
+       return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue);
       else
-       return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->cdr;
+       return XCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
     }
   /* For other variables, get the current value.  */
   return do_symval_forwarding (valcontents);
 }
 
 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
-  "Return T if SYMBOL has a non-void default value.\n\
+  "Return t if SYMBOL has a non-void default value.\n\
 This is the value that is seen in buffers that do not have their own values\n\
 for this variable.")
   (symbol)
@@ -1131,17 +1253,20 @@ for this variable.")
      variables.  */
   if (BUFFER_OBJFWDP (valcontents))
     {
-      register int idx = XBUFFER_OBJFWD (valcontents)->offset;
-      register struct buffer *b;
-      register int mask = XINT (*((Lisp_Object *)
-                                 (idx + (char *)&buffer_local_flags)));
+      int offset = XBUFFER_OBJFWD (valcontents)->offset;
+      int idx = PER_BUFFER_IDX (offset);
 
-      if (mask > 0)
+      PER_BUFFER_DEFAULT (offset) = value;
+
+      /* If this variable is not always local in all buffers,
+        set it in the buffers that don't nominally have a local value.  */
+      if (idx > 0)
        {
-         *(Lisp_Object *)(idx + (char *) &buffer_defaults) = value;
+         struct buffer *b;
+         
          for (b = all_buffers; b; b = b->next)
-           if (!(b->local_var_flags & mask))
-             *(Lisp_Object *)(idx + (char *) b) = value;
+           if (!PER_BUFFER_VALUE_P (b, idx))
+             PER_BUFFER_VALUE (b, offset) = value;
        }
       return value;
     }
@@ -1150,15 +1275,15 @@ for this variable.")
       && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
     return Fset (symbol, value);
 
-  /* Store new value into the DEFAULT-VALUE slot */
-  XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->cdr = value;
+  /* Store new value into the DEFAULT-VALUE slot */
+  XCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr) = value;
 
-  /* If that slot is current, we must set the REALVALUE slot too */
+  /* If the default binding is now loaded, set the REALVALUE slot too.  */
   current_alist_element
-    = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+    = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
   alist_element_buffer = Fcar (current_alist_element);
   if (EQ (alist_element_buffer, current_alist_element))
-    store_symval_forwarding (symbol, XBUFFER_LOCAL_VALUE (valcontents)->car,
+    store_symval_forwarding (symbol, XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
                             value);
 
   return value;
@@ -1206,12 +1331,14 @@ of previous SYMs.")
 
 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
   1, 1, "vMake Variable Buffer Local: ",
-  "Make VARIABLE have a separate value for each buffer.\n\
-At any time, the value for the current buffer is in effect.\n\
-There is also a default value which is seen in any buffer which has not yet\n\
-set its own value.\n\
-Using `set' or `setq' to set the variable causes it to have a separate value\n\
-for the current buffer if it was previously using the default value.\n\
+  "Make VARIABLE become buffer-local whenever it is set.\n\
+At any time, the value for the current buffer is in effect,\n\
+unless the variable has never been set in this buffer,\n\
+in which case the default value is in effect.\n\
+Note that binding the variable with `let', or setting it while\n\
+a `let'-style binding made in this buffer is in effect,\n\
+does not make the variable buffer-local.\n\
+\n\
 The function `default-value' gets the default value and `set-default' sets it.")
   (variable)
      register Lisp_Object variable;
@@ -1234,11 +1361,16 @@ The function `default-value' gets the default value and `set-default' sets it.")
   if (EQ (valcontents, Qunbound))
     XSYMBOL (variable)->value = Qnil;
   tem = Fcons (Qnil, Fsymbol_value (variable));
-  XCONS (tem)->car = tem;
+  XCAR (tem) = tem;
   newval = allocate_misc ();
   XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
-  XBUFFER_LOCAL_VALUE (newval)->car = XSYMBOL (variable)->value;
-  XBUFFER_LOCAL_VALUE (newval)->cdr = Fcons (Fcurrent_buffer (), tem);
+  XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
+  XBUFFER_LOCAL_VALUE (newval)->buffer = Fcurrent_buffer ();
+  XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
+  XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
+  XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
   XSYMBOL (variable)->value = newval;
   return variable;
 }
@@ -1249,11 +1381,16 @@ DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
 Other buffers will continue to share a common default value.\n\
 \(The buffer-local value of VARIABLE starts out as the same value\n\
 VARIABLE previously had.  If VARIABLE was void, it remains void.\)\n\
-See also `make-variable-buffer-local'.\n\n\
+See also `make-variable-buffer-local'.\n\
+\n\
 If the variable is already arranged to become local when set,\n\
 this function causes a local value to exist for this buffer,\n\
 just as setting the variable would do.\n\
 \n\
+This function returns VARIABLE, and therefore\n\
+  (set (make-local-variable 'VARIABLE) VALUE-EXP)\n\
+works.\n\
+\n\
 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
 Use `make-local-hook' instead.")
   (variable)
@@ -1276,19 +1413,24 @@ Use `make-local-hook' instead.")
       Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
       return variable;
     }
-  /* Make sure symbol is set up to hold per-buffer values */
+  /* Make sure symbol is set up to hold per-buffer values */
   if (!SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
       Lisp_Object newval;
       tem = Fcons (Qnil, do_symval_forwarding (valcontents));
-      XCONS (tem)->car = tem;
+      XCAR (tem) = tem;
       newval = allocate_misc ();
       XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
-      XBUFFER_LOCAL_VALUE (newval)->car = XSYMBOL (variable)->value;
-      XBUFFER_LOCAL_VALUE (newval)->cdr = Fcons (Qnil, tem);
+      XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
+      XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
+      XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
+      XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
+      XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
+      XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
+      XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
       XSYMBOL (variable)->value = newval;
     }
-  /* Make sure this buffer has its own value of symbol */
+  /* Make sure this buffer has its own value of symbol */
   tem = Fassq (variable, current_buffer->local_var_alist);
   if (NILP (tem))
     {
@@ -1298,27 +1440,28 @@ Use `make-local-hook' instead.")
       find_symbol_value (variable);
 
       current_buffer->local_var_alist
-        = Fcons (Fcons (variable, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->cdr)->cdr)->cdr),
+        = Fcons (Fcons (variable, XCDR (XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->cdr)),
                 current_buffer->local_var_alist);
 
       /* Make sure symbol does not think it is set up for this buffer;
-        force it to look once again for this buffer's value */
+        force it to look once again for this buffer's value */
       {
        Lisp_Object *pvalbuf;
 
        valcontents = XSYMBOL (variable)->value;
 
-       pvalbuf = &XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
+       pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
        if (current_buffer == XBUFFER (*pvalbuf))
          *pvalbuf = Qnil;
+       XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
       }
     }
 
-  /* If the symbol forwards into a C variable, then swap in the
-     variable for this buffer immediately.  If C code modifies the
-     variable before we swap in, then that new value will clobber the
-     default value the next time we swap.  */
-  valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->car;
+  /* If the symbol forwards into a C variable, then load the binding
+     for this buffer now.  If C code modifies the variable before we
+     load the binding in, then that new value will clobber the default
+     binding the next time we unload it.  */
+  valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->realvalue;
   if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
     swap_in_symval_forwarding (variable, XSYMBOL (variable)->value);
 
@@ -1340,15 +1483,14 @@ From now on the default value will apply in this buffer.")
 
   if (BUFFER_OBJFWDP (valcontents))
     {
-      register int idx = XBUFFER_OBJFWD (valcontents)->offset;
-      register int mask = XINT (*((Lisp_Object*)
-                                 (idx + (char *)&buffer_local_flags)));
+      int offset = XBUFFER_OBJFWD (valcontents)->offset;
+      int idx = PER_BUFFER_IDX (offset);
 
-      if (mask > 0)
+      if (idx > 0)
        {
-         *(Lisp_Object *)(idx + (char *) current_buffer)
-           = *(Lisp_Object *)(idx + (char *) &buffer_defaults);
-         current_buffer->local_var_flags &= ~mask;
+         SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
+         PER_BUFFER_VALUE (current_buffer, offset)
+           = PER_BUFFER_DEFAULT (offset);
        }
       return variable;
     }
@@ -1357,23 +1499,24 @@ From now on the default value will apply in this buffer.")
       && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
     return variable;
 
-  /* Get rid of this buffer's alist element, if any */
+  /* Get rid of this buffer's alist element, if any */
 
   tem = Fassq (variable, current_buffer->local_var_alist);
   if (!NILP (tem))
     current_buffer->local_var_alist
       = Fdelq (tem, current_buffer->local_var_alist);
 
-  /* If the symbol is set up for the current buffer, recompute its
-     value.  We have to do it now, or else forwarded objects won't
-     work right. */
+  /* If the symbol is set up with the current buffer's binding
+     loaded, recompute its value.  We have to do it now, or else
+     forwarded objects won't work right.  */
   {
     Lisp_Object *pvalbuf;
     valcontents = XSYMBOL (variable)->value;
-    pvalbuf = &XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
+    pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
     if (current_buffer == XBUFFER (*pvalbuf))
       {
        *pvalbuf = Qnil;
+       XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
        find_symbol_value (variable);
       }
   }
@@ -1381,6 +1524,53 @@ From now on the default value will apply in this buffer.")
   return variable;
 }
 
+/* Lisp functions for creating and removing buffer-local variables.  */
+
+DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
+  1, 1, "vMake Variable Frame Local: ",
+  "Enable VARIABLE to have frame-local bindings.\n\
+When a frame-local binding exists in the current frame,\n\
+it is in effect whenever the current buffer has no buffer-local binding.\n\
+A frame-local binding is actual a frame parameter value;\n\
+thus, any given frame has a local binding for VARIABLE\n\
+if it has a value for the frame parameter named VARIABLE.\n\
+See `modify-frame-parameters'.")
+  (variable)
+     register Lisp_Object variable;
+{
+  register Lisp_Object tem, valcontents, newval;
+
+  CHECK_SYMBOL (variable, 0);
+
+  valcontents = XSYMBOL (variable)->value;
+  if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)
+      || BUFFER_OBJFWDP (valcontents))
+    error ("Symbol %s may not be frame-local", XSYMBOL (variable)->name->data);
+
+  if (BUFFER_LOCAL_VALUEP (valcontents)
+      || SOME_BUFFER_LOCAL_VALUEP (valcontents))
+    {
+      XBUFFER_LOCAL_VALUE (valcontents)->check_frame = 1;
+      return variable;
+    }
+
+  if (EQ (valcontents, Qunbound))
+    XSYMBOL (variable)->value = Qnil;
+  tem = Fcons (Qnil, Fsymbol_value (variable));
+  XCAR (tem) = tem;
+  newval = allocate_misc ();
+  XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
+  XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
+  XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
+  XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
+  XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
+  XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
+  XSYMBOL (variable)->value = newval;
+  return variable;
+}
+
 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
   1, 2, 0,
   "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
@@ -1406,18 +1596,18 @@ BUFFER defaults to the current buffer.")
       || SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
       Lisp_Object tail, elt;
-      for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
+      for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
        {
-         elt = XCONS (tail)->car;
-         if (EQ (variable, XCONS (elt)->car))
+         elt = XCAR (tail);
+         if (EQ (variable, XCAR (elt)))
            return Qt;
        }
     }
   if (BUFFER_OBJFWDP (valcontents))
     {
       int offset = XBUFFER_OBJFWD (valcontents)->offset;
-      int mask = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags));
-      if (mask == -1 || (buf->local_var_flags & mask))
+      int idx = PER_BUFFER_IDX (offset);
+      if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
        return Qt;
     }
   return Qnil;
@@ -1454,10 +1644,10 @@ BUFFER defaults to the current buffer.")
   if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
       Lisp_Object tail, elt;
-      for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
+      for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
        {
-         elt = XCONS (tail)->car;
-         if (EQ (variable, XCONS (elt)->car))
+         elt = XCAR (tail);
+         if (EQ (variable, XCAR (elt)))
            return Qt;
        }
     }
@@ -1535,11 +1725,17 @@ or a byte-code object.  IDX starts at 0.")
   idxval = XINT (idx);
   if (STRINGP (array))
     {
-      Lisp_Object val;
+      int c, idxval_byte;
+
       if (idxval < 0 || idxval >= XSTRING (array)->size)
        args_out_of_range (array, idx);
-      XSETFASTINT (val, (unsigned char) XSTRING (array)->data[idxval]);
-      return val;
+      if (! STRING_MULTIBYTE (array))
+       return make_number ((unsigned char) XSTRING (array)->data[idxval]);
+      idxval_byte = string_char_to_byte (array, idxval);
+
+      c = STRING_CHAR (&XSTRING (array)->data[idxval_byte],
+                      STRING_BYTES (XSTRING (array)) - idxval_byte);
+      return make_number (c);
     }
   else if (BOOL_VECTOR_P (array))
     {
@@ -1557,7 +1753,7 @@ or a byte-code object.  IDX starts at 0.")
 
       if (idxval < 0)
        args_out_of_range (array, idx);
-      if (idxval < CHAR_TABLE_SINGLE_BYTE_SLOTS)
+      if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
        {
          /* For ASCII and 8-bit European characters, the element is
              stored in the top table.  */
@@ -1580,12 +1776,10 @@ or a byte-code object.  IDX starts at 0.")
          int code[4], i;
          Lisp_Object sub_table;
 
-         SPLIT_NON_ASCII_CHAR (idxval, code[0], code[1], code[2]);
-         if (code[0] != CHARSET_COMPOSITION)
-           {
-             if (code[1] < 32) code[1] = -1;
-             else if (code[2] < 32) code[2] = -1;
-           }
+         SPLIT_CHAR (idxval, code[0], code[1], code[2]);
+         if (code[1] < 32) code[1] = -1;
+         else if (code[2] < 32) code[2] = -1;
+
          /* Here, the possible range of CODE[0] (== charset ID) is
            128..MAX_CHARSET.  Since the top level char table contains
            data for multibyte characters after 256th element, we must
@@ -1641,6 +1835,11 @@ or a byte-code object.  IDX starts at 0.")
     }
 }
 
+/* Don't use alloca for relocating string data larger than this, lest
+   we overflow their stack.  The value is the same as what used in
+   fns.c for base64 handling.  */
+#define MAX_ALLOCA 16*1024
+
 DEFUN ("aset", Faset, Saset, 3, 3, 0,
   "Store into the element of ARRAY at index IDX the value NEWELT.\n\
 ARRAY may be a vector, a string, a char-table or a bool-vector.\n\
@@ -1681,23 +1880,19 @@ IDX starts at 0.")
     }
   else if (CHAR_TABLE_P (array))
     {
-      Lisp_Object val;
-
       if (idxval < 0)
        args_out_of_range (array, idx);
-      if (idxval < CHAR_TABLE_SINGLE_BYTE_SLOTS)
+      if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
        XCHAR_TABLE (array)->contents[idxval] = newelt;
       else
        {
          int code[4], i;
          Lisp_Object val;
 
-         SPLIT_NON_ASCII_CHAR (idxval, code[0], code[1], code[2]);
-         if (code[0] != CHARSET_COMPOSITION)
-           {
-             if (code[1] < 32) code[1] = -1;
-             else if (code[2] < 32) code[2] = -1;
-           }
+         SPLIT_CHAR (idxval, code[0], code[1], code[2]);
+         if (code[1] < 32) code[1] = -1;
+         else if (code[2] < 32) code[2] = -1;
+
          /* See the comment of the corresponding part in Faref.  */
          code[0] += 128;
          code[3] = -1;         /* anchor */
@@ -1707,23 +1902,100 @@ IDX starts at 0.")
              if (SUB_CHAR_TABLE_P (val))
                array = val;
              else
-               /* VAL is a leaf.  Create a sub char table with the
-                  default value VAL or XCHAR_TABLE (array)->defalt
-                  and look into it.  */
-               array = (XCHAR_TABLE (array)->contents[code[i]]
-                        = make_sub_char_table (NILP (val)
-                                               ? XCHAR_TABLE (array)->defalt
-                                               : val));
+               {
+                 Lisp_Object temp;
+
+                 /* VAL is a leaf.  Create a sub char table with the
+                    default value VAL or XCHAR_TABLE (array)->defalt
+                    and look into it.  */
+
+                 temp = make_sub_char_table (NILP (val)
+                                             ? XCHAR_TABLE (array)->defalt
+                                             : val);
+                 XCHAR_TABLE (array)->contents[code[i]] = temp;
+                 array = temp;
+               }
            }
          XCHAR_TABLE (array)->contents[code[i]] = newelt;
        }
     }
+  else if (STRING_MULTIBYTE (array))
+    {
+      int idxval_byte, prev_bytes, new_bytes;
+      unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
+
+      if (idxval < 0 || idxval >= XSTRING (array)->size)
+       args_out_of_range (array, idx);
+      CHECK_NUMBER (newelt, 2);
+
+      idxval_byte = string_char_to_byte (array, idxval);
+      p1 = &XSTRING (array)->data[idxval_byte];
+      PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes);
+      new_bytes = CHAR_STRING (XINT (newelt), p0);
+      if (prev_bytes != new_bytes)
+       {
+         /* We must relocate the string data.  */
+         int nchars = XSTRING (array)->size;
+         int nbytes = STRING_BYTES (XSTRING (array));
+         unsigned char *str;
+
+         str = (nbytes <= MAX_ALLOCA
+                ? (unsigned char *) alloca (nbytes)
+                : (unsigned char *) xmalloc (nbytes));
+         bcopy (XSTRING (array)->data, str, nbytes);
+         allocate_string_data (XSTRING (array), nchars,
+                               nbytes + new_bytes - prev_bytes);
+         bcopy (str, XSTRING (array)->data, idxval_byte);
+         p1 = XSTRING (array)->data + idxval_byte;
+         bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes,
+                nbytes - (idxval_byte + prev_bytes));
+         if (nbytes > MAX_ALLOCA)
+           xfree (str);
+         clear_string_char_byte_cache ();
+       }
+      while (new_bytes--)
+       *p1++ = *p0++;
+    }
   else
     {
       if (idxval < 0 || idxval >= XSTRING (array)->size)
        args_out_of_range (array, idx);
       CHECK_NUMBER (newelt, 2);
-      XSTRING (array)->data[idxval] = XINT (newelt);
+
+      if (XINT (newelt) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt)))
+       XSTRING (array)->data[idxval] = XINT (newelt);
+      else
+       {
+         /* We must relocate the string data while converting it to
+            multibyte.  */
+         int idxval_byte, prev_bytes, new_bytes;
+         unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
+         unsigned char *origstr = XSTRING (array)->data, *str;
+         int nchars, nbytes;
+
+         nchars = XSTRING (array)->size;
+         nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval);
+         nbytes += count_size_as_multibyte (origstr + idxval,
+                                            nchars - idxval);
+         str = (nbytes <= MAX_ALLOCA
+                ? (unsigned char *) alloca (nbytes)
+                : (unsigned char *) xmalloc (nbytes));
+         copy_text (XSTRING (array)->data, str, nchars, 0, 1);
+         PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte,
+                              prev_bytes);
+         new_bytes = CHAR_STRING (XINT (newelt), p0);
+         allocate_string_data (XSTRING (array), nchars,
+                               nbytes + new_bytes - prev_bytes);
+         bcopy (str, XSTRING (array)->data, idxval_byte);
+         p1 = XSTRING (array)->data + idxval_byte;
+         while (new_bytes--)
+           *p1++ = *p0++;
+         bcopy (str + idxval_byte + prev_bytes, p1,
+                nbytes - (idxval_byte + prev_bytes));
+         if (nbytes > MAX_ALLOCA)
+           xfree (str);
+         clear_string_char_byte_cache ();
+       }
     }
 
   return newelt;
@@ -1741,20 +2013,15 @@ arithcompare (num1, num2, comparison)
   double f1, f2;
   int floatp = 0;
 
-#ifdef LISP_FLOAT_TYPE
   CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0);
   CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 0);
 
   if (FLOATP (num1) || FLOATP (num2))
     {
       floatp = 1;
-      f1 = (FLOATP (num1)) ? XFLOAT (num1)->data : XINT (num1);
-      f2 = (FLOATP (num2)) ? XFLOAT (num2)->data : XINT (num2);
+      f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1);
+      f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2);
     }
-#else
-  CHECK_NUMBER_COERCE_MARKER (num1, 0);
-  CHECK_NUMBER_COERCE_MARKER (num2, 0);
-#endif /* LISP_FLOAT_TYPE */
 
   switch (comparison)
     {
@@ -1794,7 +2061,7 @@ arithcompare (num1, num2, comparison)
 }
 
 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
-  "T if two args, both numbers or markers, are equal.")
+  "Return t if two args, both numbers or markers, are equal.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
@@ -1802,7 +2069,7 @@ DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
 }
 
 DEFUN ("<", Flss, Slss, 2, 2, 0,
-  "T if first arg is less than second arg.  Both must be numbers or markers.")
+  "Return t if first arg is less than second arg.  Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
@@ -1810,7 +2077,7 @@ DEFUN ("<", Flss, Slss, 2, 2, 0,
 }
 
 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
-  "T if first arg is greater than second arg.  Both must be numbers or markers.")
+  "Return t if first arg is greater than second arg.  Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
@@ -1818,7 +2085,7 @@ DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
 }
 
 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
-  "T if first arg is less than or equal to second arg.\n\
+  "Return t if first arg is less than or equal to second arg.\n\
 Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
@@ -1827,7 +2094,7 @@ Both must be numbers or markers.")
 }
 
 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
-  "T if first arg is greater than or equal to second arg.\n\
+  "Return t if first arg is greater than or equal to second arg.\n\
 Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
@@ -1836,29 +2103,25 @@ Both must be numbers or markers.")
 }
 
 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
-  "T if first arg is not equal to second arg.  Both must be numbers or markers.")
+  "Return t if first arg is not equal to second arg.  Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
   return arithcompare (num1, num2, notequal);
 }
 
-DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.")
+DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "Return t if NUMBER is zero.")
   (number)
      register Lisp_Object number;
 {
-#ifdef LISP_FLOAT_TYPE
   CHECK_NUMBER_OR_FLOAT (number, 0);
 
   if (FLOATP (number))
     {
-      if (XFLOAT(number)->data == 0.0)
+      if (XFLOAT_DATA (number) == 0.0)
        return Qt;
       return Qnil;
     }
-#else
-  CHECK_NUMBER (number, 0);
-#endif /* LISP_FLOAT_TYPE */
 
   if (!XINT (number))
     return Qt;
@@ -1887,10 +2150,10 @@ cons_to_long (c)
   Lisp_Object top, bot;
   if (INTEGERP (c))
     return XINT (c);
-  top = XCONS (c)->car;
-  bot = XCONS (c)->cdr;
+  top = XCAR (c);
+  bot = XCDR (c);
   if (CONSP (bot))
-    bot = XCONS (bot)->car;
+    bot = XCAR (bot);
   return ((XINT (top) << 16) | XINT (bot));
 }
 \f
@@ -1903,24 +2166,20 @@ NUMBER may be an integer or a floating point number.")
 {
   char buffer[VALBITS];
 
-#ifndef LISP_FLOAT_TYPE
-  CHECK_NUMBER (number, 0);
-#else
   CHECK_NUMBER_OR_FLOAT (number, 0);
 
   if (FLOATP (number))
     {
       char pigbuf[350];        /* see comments in float_to_string */
 
-      float_to_string (pigbuf, XFLOAT(number)->data);
+      float_to_string (pigbuf, XFLOAT_DATA (number));
       return build_string (pigbuf);
     }
-#endif /* LISP_FLOAT_TYPE */
 
   if (sizeof (int) == sizeof (EMACS_INT))
     sprintf (buffer, "%d", XINT (number));
   else if (sizeof (long) == sizeof (EMACS_INT))
-    sprintf (buffer, "%ld", XINT (number));
+    sprintf (buffer, "%ld", (long) XINT (number));
   else
     abort ();
   return build_string (buffer);
@@ -1954,13 +2213,14 @@ It ignores leading spaces and tabs.\n\
 \n\
 If BASE, interpret STRING as a number in that base.  If BASE isn't\n\
 present, base 10 is used.  BASE must be between 2 and 16 (inclusive).\n\
-Floating point numbers always use base 10.")
+If the base used is not 10, floating point is not recognized.")
    (string, base)
      register Lisp_Object string, base;
 {
   register unsigned char *p;
-  register int b, digit, v = 0;
-  int negative = 1;
+  register int b;
+  int sign = 1;
+  Lisp_Object val;
 
   CHECK_STRING (string, 0);
 
@@ -1974,35 +2234,41 @@ Floating point numbers always use base 10.")
        Fsignal (Qargs_out_of_range, Fcons (base, Qnil));
     }
 
-  p = XSTRING (string)->data;
-
   /* Skip any whitespace at the front of the number.  Some versions of
      atoi do this anyway, so we might as well make Emacs lisp consistent.  */
+  p = XSTRING (string)->data;
   while (*p == ' ' || *p == '\t')
     p++;
 
   if (*p == '-')
     {
-      negative = -1;
+      sign = -1;
       p++;
     }
   else if (*p == '+')
     p++;
   
-#ifdef LISP_FLOAT_TYPE
-  if (isfloat_string (p))
-    return make_float (atof (p));
-#endif /* LISP_FLOAT_TYPE */
-
-  while (1)
+  if (isfloat_string (p) && b == 10)
+    val = make_float (sign * atof (p));
+  else
     {
-      int digit = digit_to_number (*p++, b);
-      if (digit < 0)
-       break;
-      v = v * b + digit;
+      double v = 0;
+
+      while (1)
+       {
+         int digit = digit_to_number (*p++, b);
+         if (digit < 0)
+           break;
+         v = v * b + digit;
+       }
+
+      if (v > (EMACS_UINT) (VALMASK >> 1))
+       val = make_float (sign * v);
+      else
+       val = make_number (sign * (int) v);
     }
-  
-  return make_number (negative * v);
+
+  return val;
 }
 
 \f
@@ -2039,24 +2305,18 @@ arith_driver (code, nargs, args)
   for (argnum = 0; argnum < nargs; argnum++)
     {
       val = args[argnum];    /* using args[argnum] as argument to CHECK_NUMBER_... */
-#ifdef LISP_FLOAT_TYPE
       CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum);
 
       if (FLOATP (val)) /* time to do serious math */
        return (float_arith_driver ((double) accum, argnum, code,
                                    nargs, args));
-#else
-      CHECK_NUMBER_COERCE_MARKER (val, argnum);
-#endif /* LISP_FLOAT_TYPE */
       args[argnum] = val;    /* runs into a compiler bug. */
       next = XINT (args[argnum]);
       switch (SWITCH_ENUM_CAST (code))
        {
        case Aadd: accum += next; break;
        case Asub:
-         if (!argnum && nargs != 1)
-           next = - next;
-         accum -= next;
+         accum = argnum ? accum - next : nargs == 1 ? - next : next;
          break;
        case Amult: accum *= next; break;
        case Adiv:
@@ -2083,8 +2343,6 @@ arith_driver (code, nargs, args)
 #undef isnan
 #define isnan(x) ((x) != (x))
 
-#ifdef LISP_FLOAT_TYPE
-
 Lisp_Object
 float_arith_driver (accum, argnum, code, nargs, args)
      double accum;
@@ -2103,7 +2361,7 @@ float_arith_driver (accum, argnum, code, nargs, args)
 
       if (FLOATP (val))
        {
-         next = XFLOAT (val)->data;
+         next = XFLOAT_DATA (val);
        }
       else
        {
@@ -2116,9 +2374,7 @@ float_arith_driver (accum, argnum, code, nargs, args)
          accum += next;
          break;
        case Asub:
-         if (!argnum && nargs != 1)
-           next = - next;
-         accum -= next;
+         accum = argnum ? accum - next : nargs == 1 ? - next : next;
          break;
        case Amult:
          accum *= next;
@@ -2150,7 +2406,7 @@ float_arith_driver (accum, argnum, code, nargs, args)
 
   return make_float (accum);
 }
-#endif /* LISP_FLOAT_TYPE */
+
 
 DEFUN ("+", Fplus, Splus, 0, MANY, 0,
   "Return sum of any number of arguments, which are numbers or markers.")
@@ -2242,18 +2498,12 @@ Both X and Y must be numbers or markers.")
   Lisp_Object val;
   EMACS_INT i1, i2;
 
-#ifdef LISP_FLOAT_TYPE
   CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x, 0);
   CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y, 1);
 
   if (FLOATP (x) || FLOATP (y))
     return fmod_float (x, y);
 
-#else /* not LISP_FLOAT_TYPE */
-  CHECK_NUMBER_COERCE_MARKER (x, 0);
-  CHECK_NUMBER_COERCE_MARKER (y, 1);
-#endif /* not LISP_FLOAT_TYPE */
-
   i1 = XINT (x);
   i2 = XINT (y);
 
@@ -2332,8 +2582,12 @@ In this case, the sign bit is duplicated.")
   CHECK_NUMBER (value, 0);
   CHECK_NUMBER (count, 1);
 
-  if (XINT (count) > 0)
+  if (XINT (count) >= BITS_PER_EMACS_INT)
+    XSETINT (val, 0);
+  else if (XINT (count) > 0)
     XSETINT (val, XINT (value) << XFASTINT (count));
+  else if (XINT (count) <= -BITS_PER_EMACS_INT)
+    XSETINT (val, XINT (value) < 0 ? -1 : 0);
   else
     XSETINT (val, XINT (value) >> -XINT (count));
   return val;
@@ -2351,8 +2605,12 @@ In this case,  zeros are shifted in on the left.")
   CHECK_NUMBER (value, 0);
   CHECK_NUMBER (count, 1);
 
-  if (XINT (count) > 0)
+  if (XINT (count) >= BITS_PER_EMACS_INT)
+    XSETINT (val, 0);
+  else if (XINT (count) > 0)
     XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
+  else if (XINT (count) <= -BITS_PER_EMACS_INT)
+    XSETINT (val, 0);
   else
     XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
   return val;
@@ -2364,14 +2622,10 @@ Markers are converted to integers.")
   (number)
      register Lisp_Object number;
 {
-#ifdef LISP_FLOAT_TYPE
   CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number, 0);
 
   if (FLOATP (number))
-    return (make_float (1.0 + XFLOAT (number)->data));
-#else
-  CHECK_NUMBER_COERCE_MARKER (number, 0);
-#endif /* LISP_FLOAT_TYPE */
+    return (make_float (1.0 + XFLOAT_DATA (number)));
 
   XSETINT (number, XINT (number) + 1);
   return number;
@@ -2383,14 +2637,10 @@ Markers are converted to integers.")
   (number)
      register Lisp_Object number;
 {
-#ifdef LISP_FLOAT_TYPE
   CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number, 0);
 
   if (FLOATP (number))
-    return (make_float (-1.0 + XFLOAT (number)->data));
-#else
-  CHECK_NUMBER_COERCE_MARKER (number, 0);
-#endif /* LISP_FLOAT_TYPE */
+    return (make_float (-1.0 + XFLOAT_DATA (number)));
 
   XSETINT (number, XINT (number) - 1);
   return number;
@@ -2436,11 +2686,13 @@ syms_of_data ()
   Qbeginning_of_buffer = intern ("beginning-of-buffer");
   Qend_of_buffer = intern ("end-of-buffer");
   Qbuffer_read_only = intern ("buffer-read-only");
+  Qtext_read_only = intern ("text-read-only");
   Qmark_inactive = intern ("mark-inactive");
 
   Qlistp = intern ("listp");
   Qconsp = intern ("consp");
   Qsymbolp = intern ("symbolp");
+  Qkeywordp = intern ("keywordp");
   Qintegerp = intern ("integerp");
   Qnatnump = intern ("natnump");
   Qwholenump = intern ("wholenump");
@@ -2456,20 +2708,22 @@ syms_of_data ()
   Qboundp = intern ("boundp");
   Qfboundp = intern ("fboundp");
 
-#ifdef LISP_FLOAT_TYPE
   Qfloatp = intern ("floatp");
   Qnumberp = intern ("numberp");
   Qnumber_or_marker_p = intern ("number-or-marker-p");
-#endif /* LISP_FLOAT_TYPE */
 
   Qchar_table_p = intern ("char-table-p");
   Qvector_or_char_table_p = intern ("vector-or-char-table-p");
 
+  Qsubrp = intern ("subrp");
+  Qunevalled = intern ("unevalled");
+  Qmany = intern ("many");
+
   Qcdr = intern ("cdr");
 
   /* Handle automatic advice activation */
   Qad_advice_info = intern ("ad-advice-info");
-  Qad_activate = intern ("ad-activate");
+  Qad_activate_internal = intern ("ad-activate-internal");
 
   error_tail = Fcons (Qerror, Qnil);
 
@@ -2561,7 +2815,11 @@ syms_of_data ()
   Fput (Qbuffer_read_only, Qerror_message,
        build_string ("Buffer is read-only"));
 
-#ifdef LISP_FLOAT_TYPE
+  Fput (Qtext_read_only, Qerror_conditions,
+       Fcons (Qtext_read_only, error_tail));
+  Fput (Qtext_read_only, Qerror_message,
+       build_string ("Text is read-only"));
+
   Qrange_error = intern ("range-error");
   Qdomain_error = intern ("domain-error");
   Qsingularity_error = intern ("singularity-error");
@@ -2598,7 +2856,6 @@ syms_of_data ()
   staticpro (&Qsingularity_error);
   staticpro (&Qoverflow_error);
   staticpro (&Qunderflow_error);
-#endif /* LISP_FLOAT_TYPE */
 
   staticpro (&Qnil);
   staticpro (&Qt);
@@ -2627,11 +2884,13 @@ syms_of_data ()
   staticpro (&Qbeginning_of_buffer);
   staticpro (&Qend_of_buffer);
   staticpro (&Qbuffer_read_only);
+  staticpro (&Qtext_read_only);
   staticpro (&Qmark_inactive);
 
   staticpro (&Qlistp);
   staticpro (&Qconsp);
   staticpro (&Qsymbolp);
+  staticpro (&Qkeywordp);
   staticpro (&Qintegerp);
   staticpro (&Qnatnump);
   staticpro (&Qwholenump);
@@ -2644,19 +2903,20 @@ syms_of_data ()
   staticpro (&Qmarkerp);
   staticpro (&Qbuffer_or_string_p);
   staticpro (&Qinteger_or_marker_p);
-#ifdef LISP_FLOAT_TYPE
   staticpro (&Qfloatp);
   staticpro (&Qnumberp);
   staticpro (&Qnumber_or_marker_p);
-#endif /* LISP_FLOAT_TYPE */
   staticpro (&Qchar_table_p);
   staticpro (&Qvector_or_char_table_p);
+  staticpro (&Qsubrp);
+  staticpro (&Qmany);
+  staticpro (&Qunevalled);
 
   staticpro (&Qboundp);
   staticpro (&Qfboundp);
   staticpro (&Qcdr);
   staticpro (&Qad_advice_info);
-  staticpro (&Qad_activate);
+  staticpro (&Qad_activate_internal);
 
   /* Types that type-of returns.  */
   Qinteger = intern ("integer");
@@ -2676,6 +2936,7 @@ syms_of_data ()
   Qvector = intern ("vector");
   Qchar_table = intern ("char-table");
   Qbool_vector = intern ("bool-vector");
+  Qhash_table = intern ("hash-table");
 
   staticpro (&Qinteger);
   staticpro (&Qsymbol);
@@ -2694,6 +2955,7 @@ syms_of_data ()
   staticpro (&Qvector);
   staticpro (&Qchar_table);
   staticpro (&Qbool_vector);
+  staticpro (&Qhash_table);
 
   defsubr (&Seq);
   defsubr (&Snull);
@@ -2706,12 +2968,12 @@ syms_of_data ()
   defsubr (&Sinteger_or_marker_p);
   defsubr (&Snumberp);
   defsubr (&Snumber_or_marker_p);
-#ifdef LISP_FLOAT_TYPE
   defsubr (&Sfloatp);
-#endif /* LISP_FLOAT_TYPE */
   defsubr (&Snatnump);
   defsubr (&Ssymbolp);
+  defsubr (&Skeywordp);
   defsubr (&Sstringp);
+  defsubr (&Smultibyte_string_p);
   defsubr (&Svectorp);
   defsubr (&Schar_table_p);
   defsubr (&Svector_or_char_table_p);
@@ -2749,6 +3011,7 @@ syms_of_data ()
   defsubr (&Smake_variable_buffer_local);
   defsubr (&Smake_local_variable);
   defsubr (&Skill_local_variable);
+  defsubr (&Smake_variable_frame_local);
   defsubr (&Slocal_variable_p);
   defsubr (&Slocal_variable_if_set_p);
   defsubr (&Saref);
@@ -2778,6 +3041,7 @@ syms_of_data ()
   defsubr (&Sadd1);
   defsubr (&Ssub1);
   defsubr (&Slognot);
+  defsubr (&Ssubr_arity);
 
   XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
 }
@@ -2804,6 +3068,7 @@ arith_error (signo)
   Fsignal (Qarith_error, Qnil);
 }
 
+void
 init_data ()
 {
   /* Don't do this if just dumping out.