* buffer.h (BSET): Remove.
[bpt/emacs.git] / src / data.c
index fe7b942..ea51182 100644 (file)
@@ -83,12 +83,12 @@ Lisp_Object Qoverflow_error, Qunderflow_error;
 Lisp_Object Qfloatp;
 Lisp_Object Qnumberp, Qnumber_or_marker_p;
 
-Lisp_Object Qinteger;
-static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
+Lisp_Object Qinteger, Qinterval, Qfloat, Qvector;
+Lisp_Object Qsymbol, Qstring, Qcons, Qmisc;
 Lisp_Object Qwindow;
-static Lisp_Object Qfloat, Qwindow_configuration;
-static Lisp_Object Qprocess;
-static Lisp_Object Qcompiled_function, Qframe, Qvector;
+static Lisp_Object Qoverlay, Qwindow_configuration;
+static Lisp_Object Qprocess, Qmarker;
+static Lisp_Object Qcompiled_function, Qframe;
 Lisp_Object Qbuffer;
 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
 static Lisp_Object Qsubrp, Qmany, Qunevalled;
@@ -543,7 +543,7 @@ DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0,
        else
          {
            swap_in_symval_forwarding (sym, blv);
-           valcontents = BLV_VALUE (blv);
+           valcontents = blv_value (blv);
          }
        break;
       }
@@ -562,7 +562,7 @@ DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0,
   (register Lisp_Object symbol)
 {
   CHECK_SYMBOL (symbol);
-  return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt);
+  return EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt;
 }
 
 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0,
@@ -585,7 +585,7 @@ Return SYMBOL.  */)
   CHECK_SYMBOL (symbol);
   if (NILP (symbol) || EQ (symbol, Qt))
     xsignal1 (Qsetting_constant, symbol);
-  XSYMBOL (symbol)->function = Qunbound;
+  set_symbol_function (symbol, Qunbound);
   return symbol;
 }
 
@@ -636,7 +636,7 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
   if (CONSP (function) && EQ (XCAR (function), Qautoload))
     Fput (symbol, Qautoload, XCDR (function));
 
-  XSYMBOL (symbol)->function = definition;
+  set_symbol_function (symbol, definition);
   /* Handle automatic advice activation.  */
   if (CONSP (XSYMBOL (symbol)->plist)
       && !NILP (Fget (symbol, Qad_advice_info)))
@@ -679,7 +679,7 @@ DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
   (register Lisp_Object symbol, Lisp_Object newplist)
 {
   CHECK_SYMBOL (symbol);
-  XSYMBOL (symbol)->plist = newplist;
+  set_symbol_plist (symbol, newplist);
   return newplist;
 }
 
@@ -761,7 +761,7 @@ Value, if non-nil, is a list \(interactive SPEC).  */)
        {
          struct gcpro gcpro1;
          GCPRO1 (cmd);
-         do_autoload (fun, cmd);
+         Fautoload_do_load (fun, cmd, Qnil);
          UNGCPRO;
          return Finteractive_form (cmd);
        }
@@ -808,10 +808,12 @@ indirect_variable (struct Lisp_Symbol *symbol)
 
 DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0,
        doc: /* Return the variable at the end of OBJECT's variable chain.
-If OBJECT is a symbol, follow all variable indirections and return the final
-variable.  If OBJECT is not a symbol, just return it.
-Signal a cyclic-variable-indirection error if there is a loop in the
-variable chain of symbols.  */)
+If OBJECT is a symbol, follow its variable indirections (if any), and
+return the variable at the end of the chain of aliases.  See Info node
+`(elisp)Variable Aliases'.
+
+If OBJECT is not a symbol, just return it.  If there is a loop in the
+chain of aliases, signal a `cyclic-variable-indirection' error.  */)
   (Lisp_Object object)
 {
   if (SYMBOLP (object))
@@ -928,7 +930,7 @@ store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newva
        Lisp_Object type = XBUFFER_OBJFWD (valcontents)->slottype;
 
        if (!(NILP (type) || NILP (newval)
-             || (XINT (type) == LISP_INT_TAG
+             || (XINT (type) == Lisp_Int0
                  ? INTEGERP (newval)
                  : XTYPE (newval) == XINT (type))))
          buffer_slot_type_mismatch (newval, XINT (type));
@@ -962,16 +964,16 @@ swap_in_global_binding (struct Lisp_Symbol *symbol)
 
   /* Unload the previously loaded binding.  */
   if (blv->fwd)
-    SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
+    set_blv_value (blv, do_symval_forwarding (blv->fwd));
 
   /* Select the global binding in the symbol.  */
-  blv->valcell = blv->defcell;
+  set_blv_valcell (blv, blv->defcell);
   if (blv->fwd)
     store_symval_forwarding (blv->fwd, XCDR (blv->defcell), NULL);
 
   /* Indicate that the global binding is set up now.  */
-  blv->where = Qnil;
-  SET_BLV_FOUND (blv, 0);
+  set_blv_where (blv, Qnil);
+  set_blv_found (blv, 0);
 }
 
 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
@@ -999,7 +1001,7 @@ swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_
       /* Unload the previously loaded binding.  */
       tem1 = blv->valcell;
       if (blv->fwd)
-       SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
+       set_blv_value (blv, do_symval_forwarding (blv->fwd));
       /* Choose the new binding.  */
       {
        Lisp_Object var;
@@ -1007,7 +1009,7 @@ swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_
        if (blv->frame_local)
          {
            tem1 = assq_no_quit (var, XFRAME (selected_frame)->param_alist);
-           blv->where = selected_frame;
+           set_blv_where (blv, selected_frame);
          }
        else
          {
@@ -1019,9 +1021,9 @@ swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_
        tem1 = blv->defcell;
 
       /* Load the new binding.  */
-      blv->valcell = tem1;
+      set_blv_valcell (blv, tem1);
       if (blv->fwd)
-       store_symval_forwarding (blv->fwd, BLV_VALUE (blv), NULL);
+       store_symval_forwarding (blv->fwd, blv_value (blv), NULL);
     }
 }
 \f
@@ -1048,7 +1050,7 @@ find_symbol_value (Lisp_Object symbol)
       {
        struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
        swap_in_symval_forwarding (sym, blv);
-       return blv->fwd ? do_symval_forwarding (blv->fwd) : BLV_VALUE (blv);
+       return blv->fwd ? do_symval_forwarding (blv->fwd) : blv_value (blv);
       }
       /* FALLTHROUGH */
     case SYMBOL_FORWARDED:
@@ -1173,7 +1175,7 @@ set_internal (register Lisp_Object symbol, register Lisp_Object newval, register
 
            /* Write out `realvalue' to the old loaded binding.  */
            if (blv->fwd)
-             SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
+             set_blv_value (blv, do_symval_forwarding (blv->fwd));
 
            /* Find the new binding.  */
            XSETSYMBOL (symbol, sym); /* May have changed via aliasing.  */
@@ -1181,8 +1183,8 @@ set_internal (register Lisp_Object symbol, register Lisp_Object newval, register
                          (blv->frame_local
                           ? XFRAME (where)->param_alist
                           : BVAR (XBUFFER (where), local_var_alist)));
-           blv->where = where;
-           blv->found = 1;
+           set_blv_where (blv, where);
+           set_blv_found (blv, 1);
 
            if (NILP (tem1))
              {
@@ -1197,7 +1199,7 @@ set_internal (register Lisp_Object symbol, register Lisp_Object newval, register
                if (bindflag || !blv->local_if_set
                    || let_shadows_buffer_binding_p (sym))
                  {
-                   blv->found = 0;
+                   set_blv_found (blv, 0);
                    tem1 = blv->defcell;
                  }
                /* If it's a local_if_set, being set not bound,
@@ -1211,17 +1213,18 @@ set_internal (register Lisp_Object symbol, register Lisp_Object newval, register
                       bindings, not for frame-local bindings.  */
                    eassert (!blv->frame_local);
                    tem1 = Fcons (symbol, XCDR (blv->defcell));
-                   BVAR (XBUFFER (where), local_var_alist)
-                     = Fcons (tem1, BVAR (XBUFFER (where), local_var_alist));
+                   bset_local_var_alist
+                     (XBUFFER (where),
+                      Fcons (tem1, BVAR (XBUFFER (where), local_var_alist)));
                  }
              }
 
            /* Record which binding is now loaded.  */
-           blv->valcell = tem1;
+           set_blv_valcell (blv, tem1);
          }
 
        /* Store the new value in the cons cell.  */
-       SET_BLV_VALUE (blv, newval);
+       set_blv_value (blv, newval);
 
        if (blv->fwd)
          {
@@ -1401,7 +1404,7 @@ for this variable.  */)
              {
                struct buffer *b;
 
-               for (b = all_buffers; b; b = b->header.next.buffer)
+               FOR_EACH_BUFFER (b)
                  if (!PER_BUFFER_VALUE_P (b, idx))
                    PER_BUFFER_VALUE (b, offset) = value;
              }
@@ -1463,8 +1466,7 @@ union Lisp_Val_Fwd
 static struct Lisp_Buffer_Local_Value *
 make_blv (struct Lisp_Symbol *sym, int forwarded, union Lisp_Val_Fwd valcontents)
 {
-  struct Lisp_Buffer_Local_Value *blv
-    = xmalloc (sizeof (struct Lisp_Buffer_Local_Value));
+  struct Lisp_Buffer_Local_Value *blv = xmalloc (sizeof *blv);
   Lisp_Object symbol;
   Lisp_Object tem;
 
@@ -1478,12 +1480,12 @@ make_blv (struct Lisp_Symbol *sym, int forwarded, union Lisp_Val_Fwd valcontents
   eassert (!(forwarded && BUFFER_OBJFWDP (valcontents.fwd)));
   eassert (!(forwarded && KBOARD_OBJFWDP (valcontents.fwd)));
   blv->fwd = forwarded ? valcontents.fwd : NULL;
-  blv->where = Qnil;
+  set_blv_where (blv, Qnil);
   blv->frame_local = 0;
   blv->local_if_set = 0;
-  blv->defcell = tem;
-  blv->valcell = tem;
-  SET_BLV_FOUND (blv, 0);
+  set_blv_defcell (blv, tem);
+  set_blv_valcell (blv, tem);
+  set_blv_found (blv, 0);
   return blv;
 }
 
@@ -1652,17 +1654,16 @@ Instead, use `add-hook' and specify t for the LOCAL argument.  */)
         default value.  */
       find_symbol_value (variable);
 
-      BVAR (current_buffer, local_var_alist)
-        = Fcons (Fcons (variable, XCDR (blv->defcell)),
-                BVAR (current_buffer, local_var_alist));
+      bset_local_var_alist
+       (current_buffer,
+        Fcons (Fcons (variable, XCDR (blv->defcell)),
+               BVAR (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.  */
       if (current_buffer == XBUFFER (blv->where))
-       blv->where = Qnil;
-      /* blv->valcell = blv->defcell;
-       * SET_BLV_FOUND (blv, 0); */
-      blv->found = 0;
+       set_blv_where (blv, Qnil);
+      set_blv_found (blv, 0);
     }
 
   /* If the symbol forwards into a C variable, then load the binding
@@ -1722,8 +1723,9 @@ From now on the default value will apply in this buffer.  Return VARIABLE.  */)
   XSETSYMBOL (variable, sym);  /* Propagate variable indirection.  */
   tem = Fassq (variable, BVAR (current_buffer, local_var_alist));
   if (!NILP (tem))
-    BVAR (current_buffer, local_var_alist)
-      = Fdelq (tem, BVAR (current_buffer, local_var_alist));
+    bset_local_var_alist
+      (current_buffer,
+       Fdelq (tem, BVAR (current_buffer, local_var_alist)));
 
   /* If the symbol is set up with the current buffer's binding
      loaded, recompute its value.  We have to do it now, or else
@@ -1732,10 +1734,8 @@ From now on the default value will apply in this buffer.  Return VARIABLE.  */)
     Lisp_Object buf; XSETBUFFER (buf, current_buffer);
     if (EQ (buf, blv->where))
       {
-       blv->where = Qnil;
-       /* blv->valcell = blv->defcell;
-        * SET_BLV_FOUND (blv, 0); */
-       blv->found = 0;
+       set_blv_where (blv, Qnil);
+       set_blv_found (blv, 0);
        find_symbol_value (variable);
       }
   }
@@ -1856,11 +1856,11 @@ BUFFER defaults to the current buffer.  */)
            if (EQ (variable, XCAR (elt)))
              {
                eassert (!blv->frame_local);
-               eassert (BLV_FOUND (blv) || !EQ (blv->where, tmp));
+               eassert (blv_found (blv) || !EQ (blv->where, tmp));
                return Qt;
              }
          }
-       eassert (!BLV_FOUND (blv) || !EQ (blv->where, tmp));
+       eassert (!blv_found (blv) || !EQ (blv->where, tmp));
        return Qnil;
       }
     case SYMBOL_FORWARDED:
@@ -1950,7 +1950,7 @@ If the current binding is global (the default), the value is nil.  */)
       if (!NILP (Flocal_variable_p (variable, Qnil)))
        return Fcurrent_buffer ();
       else if (sym->redirect == SYMBOL_LOCALIZED
-              && BLV_FOUND (SYMBOL_BLV (sym)))
+              && blv_found (SYMBOL_BLV (sym)))
        return SYMBOL_BLV (sym)->where;
       else
        return Qnil;
@@ -2060,7 +2060,7 @@ function chain of symbols.  */)
   return Qnil;
 }
 \f
-/* Extract and set vector and string elements */
+/* Extract and set vector and string elements */
 
 DEFUN ("aref", Faref, Saref, 2, 2, 0,
        doc: /* Return the element of ARRAY at index IDX.
@@ -2180,10 +2180,9 @@ bool-vector.  IDX starts at 0.  */)
            {
              /* We must relocate the string data.  */
              ptrdiff_t nchars = SCHARS (array);
-             unsigned char *str;
              USE_SAFE_ALLOCA;
+             unsigned char *str = SAFE_ALLOCA (nbytes);
 
-             SAFE_ALLOCA (str, unsigned char *, nbytes);
              memcpy (str, SDATA (array), nbytes);
              allocate_string_data (XSTRING (array), nchars,
                                    nbytes + new_bytes - prev_bytes);
@@ -2523,7 +2522,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
   ptrdiff_t ok_args;
   EMACS_INT ok_accum;
 
-  switch (SWITCH_ENUM_CAST (code))
+  switch (code)
     {
     case Alogior:
     case Alogxor:
@@ -2558,7 +2557,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
                                   nargs, args);
       args[argnum] = val;
       next = XINT (args[argnum]);
-      switch (SWITCH_ENUM_CAST (code))
+      switch (code)
        {
        case Aadd:
          if (INT_ADD_OVERFLOW (accum, next))
@@ -2644,7 +2643,7 @@ float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code,
          args[argnum] = val;    /* runs into a compiler bug. */
          next = XINT (args[argnum]);
        }
-      switch (SWITCH_ENUM_CAST (code))
+      switch (code)
        {
        case Aadd:
          accum += next;
@@ -3012,11 +3011,11 @@ syms_of_data (void)
   Fput (Qerror, Qerror_conditions,
        error_tail);
   Fput (Qerror, Qerror_message,
-       make_pure_c_string ("error"));
+       build_pure_c_string ("error"));
 
 #define PUT_ERROR(sym, tail, msg)                      \
   Fput (sym, Qerror_conditions, pure_cons (sym, tail)); \
-  Fput (sym, Qerror_message, make_pure_c_string (msg))
+  Fput (sym, Qerror_message, build_pure_c_string (msg))
 
   PUT_ERROR (Qquit, Qnil, "Quit");
 
@@ -3043,7 +3042,7 @@ syms_of_data (void)
 
   arith_tail = pure_cons (Qarith_error, error_tail);
   Fput (Qarith_error, Qerror_conditions, arith_tail);
-  Fput (Qarith_error, Qerror_message, make_pure_c_string ("Arithmetic error"));
+  Fput (Qarith_error, Qerror_message, build_pure_c_string ("Arithmetic error"));
 
   PUT_ERROR (Qbeginning_of_buffer, error_tail, "Beginning of buffer");
   PUT_ERROR (Qend_of_buffer, error_tail, "End of buffer");
@@ -3084,7 +3083,6 @@ syms_of_data (void)
   DEFSYM (Qwindow_configuration, "window-configuration");
   DEFSYM (Qprocess, "process");
   DEFSYM (Qwindow, "window");
-  /* DEFSYM (Qsubr, "subr"); */
   DEFSYM (Qcompiled_function, "compiled-function");
   DEFSYM (Qbuffer, "buffer");
   DEFSYM (Qframe, "frame");
@@ -3092,6 +3090,9 @@ syms_of_data (void)
   DEFSYM (Qchar_table, "char-table");
   DEFSYM (Qbool_vector, "bool-vector");
   DEFSYM (Qhash_table, "hash-table");
+  /* Used by Fgarbage_collect.  */
+  DEFSYM (Qinterval, "interval");
+  DEFSYM (Qmisc, "misc");
 
   DEFSYM (Qdefun, "defun");
 
@@ -3196,7 +3197,7 @@ syms_of_data (void)
   defsubr (&Ssubr_arity);
   defsubr (&Ssubr_name);
 
-  XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
+  set_symbol_function (Qwholenump, XSYMBOL (Qnatnump)->function);
 
   DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum,
               doc: /* The largest value that is representable in a Lisp integer.  */);