changeset 95112:0835cb21d60e

* lisp.h (indirect_variable): * data.c (indirect_variable, let_shadows_buffer_binding_p): Use Lisp_Symbol pointers rather than Lisp_Object. Adjust callers. * buffer.c (buffer_slot_type_mismatch): Use wrong-type-argument. To this end, change calling-convention.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 19 May 2008 18:38:55 +0000
parents f3a094e70d91
children 032aad659f02
files src/ChangeLog src/buffer.c src/data.c src/lisp.h
diffstat 4 files changed, 107 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon May 19 16:29:33 2008 +0000
+++ b/src/ChangeLog	Mon May 19 18:38:55 2008 +0000
@@ -1,13 +1,20 @@
+2008-05-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* lisp.h (indirect_variable):
+	* data.c (indirect_variable, let_shadows_buffer_binding_p):
+	Use Lisp_Symbol pointers rather than Lisp_Object.
+	Adjust callers.
+	* buffer.c (buffer_slot_type_mismatch): Use wrong-type-argument.
+	To this end, change calling-convention.
+
+	* minibuf.c (Finternal_complete_buffer): Only strip out hidden buffers
+	if some non-hidden buffers are selected by string&pred.
+
 2008-05-19  Chong Yidong  <cyd@stupidchicken.com>
 
 	* process.c (wait_reading_process_output): Always check status
 	when in batch mode.
 
-2008-05-19  Stefan Monnier  <monnier@iro.umontreal.ca>
-
-	* minibuf.c (Finternal_complete_buffer): Only strip out hidden buffers
-	if some non-hidden buffers are selected by string&pred.
-
 2008-05-19  Kenichi Handa  <handa@m17n.org>
 
 	* font.c (font_list_entities): Fix handling of cache.
--- a/src/buffer.c	Mon May 19 16:29:33 2008 +0000
+++ b/src/buffer.c	Mon May 19 18:38:55 2008 +0000
@@ -927,12 +927,14 @@
 {
   register struct buffer *buf;
   register Lisp_Object result;
+  struct Lisp_Symbol *sym;
 
   CHECK_SYMBOL (variable);
   CHECK_BUFFER (buffer);
   buf = XBUFFER (buffer);
 
-  variable = indirect_variable (variable);
+  sym = indirect_variable (XSYMBOL (variable));
+  XSETSYMBOL (variable, sym);
 
   /* Look in local_var_list */
   result = Fassoc (variable, buf->local_var_alist);
@@ -969,7 +971,7 @@
       Lisp_Object current_alist_element;
 
       /* What binding is loaded right now?  */
-      valcontents = SYMBOL_VALUE (variable);
+      valcontents = sym->value;
       current_alist_element
 	= XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
 
@@ -4550,32 +4552,21 @@
    in the slot with offset OFFSET.  */
 
 void
-buffer_slot_type_mismatch (sym, type)
-     Lisp_Object sym;
+buffer_slot_type_mismatch (newval, type)
+     Lisp_Object newval;
      int type;
 {
-  char *type_name;
+  Lisp_Object predicate;
 
   switch (type)
     {
-    case Lisp_Int:
-      type_name = "integers";
-      break;
-
-    case Lisp_String:
-      type_name = "strings";
-      break;
-
-    case Lisp_Symbol:
-      type_name = "symbols";
-      break;
-
-    default:
-      abort ();
+    case Lisp_Int:    predicate = Qintegerp; break;
+    case Lisp_String: predicate = Qstringp;  break;
+    case Lisp_Symbol: predicate = Qsymbolp;  break;
+    default: abort ();
     }
 
-  error ("Only %s should be stored in the buffer-local variable %s",
-	 type_name, SDATA (SYMBOL_NAME (sym)));
+  wrong_type_argument (predicate, newval);
 }
 
 
--- a/src/data.c	Mon May 19 16:29:33 2008 +0000
+++ b/src/data.c	Mon May 19 18:38:55 2008 +0000
@@ -813,25 +813,29 @@
    `cyclic-variable-indirection' if SYMBOL's chain of variable
    indirections contains a loop.  */
 
-Lisp_Object
+struct Lisp_Symbol *
 indirect_variable (symbol)
-     Lisp_Object symbol;
+     struct Lisp_Symbol *symbol;
 {
-  Lisp_Object tortoise, hare;
+  struct Lisp_Symbol *tortoise, *hare;
 
   hare = tortoise = symbol;
 
-  while (XSYMBOL (hare)->indirect_variable)
+  while (hare->indirect_variable)
     {
-      hare = XSYMBOL (hare)->value;
-      if (!XSYMBOL (hare)->indirect_variable)
+      hare = XSYMBOL (hare->value);
+      if (!hare->indirect_variable)
 	break;
 
-      hare = XSYMBOL (hare)->value;
-      tortoise = XSYMBOL (tortoise)->value;
-
-      if (EQ (hare, tortoise))
-	xsignal1 (Qcyclic_variable_indirection, symbol);
+      hare = XSYMBOL (hare->value);
+      tortoise = XSYMBOL (tortoise->value);
+
+      if (hare == tortoise)
+	{
+	  Lisp_Object tem;
+	  XSETSYMBOL (tem, symbol);
+	  xsignal1 (Qcyclic_variable_indirection, tem);
+	}
     }
 
   return hare;
@@ -848,7 +852,7 @@
      Lisp_Object object;
 {
   if (SYMBOLP (object))
-    object = indirect_variable (object);
+    XSETSYMBOL (object,  indirect_variable (XSYMBOL (object)));
   return object;
 }
 
@@ -972,7 +976,7 @@
 
 	    if (! NILP (type) && ! NILP (newval)
 		&& XTYPE (newval) != XINT (type))
-	      buffer_slot_type_mismatch (symbol, XINT (type));
+	      buffer_slot_type_mismatch (newval, XINT (type));
 
 	    if (buf == NULL)
 	      buf = current_buffer;
@@ -1049,8 +1053,12 @@
       || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
 	  && ! EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)))
     {
-      if (XSYMBOL (symbol)->indirect_variable)
-	symbol = indirect_variable (symbol);
+      struct Lisp_Symbol *sym = XSYMBOL (symbol);
+      if (sym->indirect_variable)
+	{
+	  sym = indirect_variable (sym);
+	  XSETSYMBOL (symbol, sym);
+	}
 
       /* Unload the previously loaded binding.  */
       tem1 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
@@ -1132,7 +1140,7 @@
 
 static int
 let_shadows_buffer_binding_p (symbol)
-     Lisp_Object symbol;
+     struct Lisp_Symbol *symbol;
 {
   volatile struct specbinding *p;
 
@@ -1140,10 +1148,10 @@
     if (p->func == NULL
 	&& CONSP (p->symbol))
       {
-	Lisp_Object let_bound_symbol = XCAR (p->symbol);
-	if ((EQ (symbol, let_bound_symbol)
-	     || (XSYMBOL (let_bound_symbol)->indirect_variable
-		 && EQ (symbol, indirect_variable (let_bound_symbol))))
+	struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol));
+	if ((symbol == let_bound_symbol
+	     || (let_bound_symbol->indirect_variable
+		 && symbol == indirect_variable (let_bound_symbol)))
 	    && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
 	  break;
       }
@@ -1197,7 +1205,7 @@
     {
       /* valcontents is a struct Lisp_Buffer_Local_Value.   */
       if (XSYMBOL (symbol)->indirect_variable)
-	symbol = indirect_variable (symbol);
+	XSETSYMBOL (symbol, indirect_variable (XSYMBOL (symbol)));
 
       /* What binding is loaded right now?  */
       current_alist_element
@@ -1239,7 +1247,7 @@
 		 Likewise if the variable has been let-bound
 		 in the current buffer.  */
 	      if (bindflag || !XBUFFER_LOCAL_VALUE (valcontents)->local_if_set
-		  || let_shadows_buffer_binding_p (symbol))
+		  || let_shadows_buffer_binding_p (XSYMBOL (symbol)))
 		{
 		  XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
 
@@ -1473,13 +1481,14 @@
      register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents, newval;
+  struct Lisp_Symbol *sym;
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
-
-  valcontents = SYMBOL_VALUE (variable);
-  if (XSYMBOL (variable)->constant || KBOARD_OBJFWDP (valcontents))
-    error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
+  sym = indirect_variable (XSYMBOL (variable));
+
+  valcontents = sym->value;
+  if (sym->constant || KBOARD_OBJFWDP (valcontents))
+    error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
 
   if (BUFFER_OBJFWDP (valcontents))
     return variable;
@@ -1488,19 +1497,19 @@
   else
     {
       if (EQ (valcontents, Qunbound))
-	SET_SYMBOL_VALUE (variable, Qnil);
+	sym->value = Qnil;
       tem = Fcons (Qnil, Fsymbol_value (variable));
       XSETCAR (tem, tem);
       newval = allocate_misc ();
       XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
-      XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable);
+      XBUFFER_LOCAL_VALUE (newval)->realvalue = sym->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;
-      SET_SYMBOL_VALUE (variable, newval);
+      sym->value = newval;
     }
   XBUFFER_LOCAL_VALUE (newval)->local_if_set = 1;
   return variable;
@@ -1530,13 +1539,14 @@
      register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents;
+  struct Lisp_Symbol *sym;
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
-
-  valcontents = SYMBOL_VALUE (variable);
-  if (XSYMBOL (variable)->constant || KBOARD_OBJFWDP (valcontents))
-    error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
+  sym = indirect_variable (XSYMBOL (variable));
+
+  valcontents = sym->value;
+  if (sym->constant || KBOARD_OBJFWDP (valcontents))
+    error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
 
   if ((BUFFER_LOCAL_VALUEP (valcontents)
        && XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
@@ -1557,7 +1567,7 @@
       XSETCAR (tem, tem);
       newval = allocate_misc ();
       XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
-      XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable);
+      XBUFFER_LOCAL_VALUE (newval)->realvalue = sym->value;
       XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
       XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
       XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
@@ -1565,9 +1575,10 @@
       XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
       XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
       XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
-      SET_SYMBOL_VALUE (variable, newval);
+      sym->value = newval;
     }
   /* Make sure this buffer has its own value of symbol.  */
+  XSETSYMBOL (variable, sym);	/* Propagate variable indirections.  */
   tem = Fassq (variable, current_buffer->local_var_alist);
   if (NILP (tem))
     {
@@ -1577,7 +1588,7 @@
       find_symbol_value (variable);
 
       current_buffer->local_var_alist
-        = Fcons (Fcons (variable, XCDR (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable))->cdr)),
+        = Fcons (Fcons (variable, XCDR (XBUFFER_LOCAL_VALUE (sym->value)->cdr)),
 		 current_buffer->local_var_alist);
 
       /* Make sure symbol does not think it is set up for this buffer;
@@ -1585,7 +1596,7 @@
       {
 	Lisp_Object *pvalbuf;
 
-	valcontents = SYMBOL_VALUE (variable);
+	valcontents = sym->value;
 
 	pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
 	if (current_buffer == XBUFFER (*pvalbuf))
@@ -1598,9 +1609,9 @@
      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 (SYMBOL_VALUE (variable))->realvalue;
+  valcontents = XBUFFER_LOCAL_VALUE (sym->value)->realvalue;
   if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
-    swap_in_symval_forwarding (variable, SYMBOL_VALUE (variable));
+    swap_in_symval_forwarding (variable, sym->value);
 
   return variable;
 }
@@ -1613,11 +1624,12 @@
      register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents;
+  struct Lisp_Symbol *sym;
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
-
-  valcontents = SYMBOL_VALUE (variable);
+  sym = indirect_variable (XSYMBOL (variable));
+
+  valcontents = sym->value;
 
   if (BUFFER_OBJFWDP (valcontents))
     {
@@ -1637,7 +1649,7 @@
     return variable;
 
   /* Get rid of this buffer's alist element, if any.  */
-
+  XSETSYMBOL (variable, sym);	/* Propagate variable indirection.  */
   tem = Fassq (variable, current_buffer->local_var_alist);
   if (!NILP (tem))
     current_buffer->local_var_alist
@@ -1648,7 +1660,7 @@
      forwarded objects won't work right.  */
   {
     Lisp_Object *pvalbuf, buf;
-    valcontents = SYMBOL_VALUE (variable);
+    valcontents = sym->value;
     pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
     XSETBUFFER (buf, current_buffer);
     if (EQ (buf, *pvalbuf))
@@ -1685,14 +1697,15 @@
      register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents, newval;
+  struct Lisp_Symbol *sym;
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
-
-  valcontents = SYMBOL_VALUE (variable);
-  if (XSYMBOL (variable)->constant || KBOARD_OBJFWDP (valcontents)
+  sym = indirect_variable (XSYMBOL (variable));
+
+  valcontents = sym->value;
+  if (sym->constant || KBOARD_OBJFWDP (valcontents)
       || BUFFER_OBJFWDP (valcontents))
-    error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable)));
+    error ("Symbol %s may not be frame-local", SDATA (sym->xname));
 
   if (BUFFER_LOCAL_VALUEP (valcontents))
     {
@@ -1701,12 +1714,12 @@
     }
 
   if (EQ (valcontents, Qunbound))
-    SET_SYMBOL_VALUE (variable, Qnil);
+    sym->value = Qnil;
   tem = Fcons (Qnil, Fsymbol_value (variable));
   XSETCAR (tem, tem);
   newval = allocate_misc ();
   XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
-  XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable);
+  XBUFFER_LOCAL_VALUE (newval)->realvalue = sym->value;
   XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
   XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
   XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
@@ -1714,7 +1727,7 @@
   XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
   XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
   XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
-  SET_SYMBOL_VALUE (variable, newval);
+  sym->value = newval;
   return variable;
 }
 
@@ -1727,6 +1740,7 @@
 {
   Lisp_Object valcontents;
   register struct buffer *buf;
+  struct Lisp_Symbol *sym;
 
   if (NILP (buffer))
     buf = current_buffer;
@@ -1737,9 +1751,10 @@
     }
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
-
-  valcontents = SYMBOL_VALUE (variable);
+  sym = indirect_variable (XSYMBOL (variable));
+  XSETSYMBOL (variable, sym);
+  
+  valcontents = sym->value;
   if (BUFFER_LOCAL_VALUEP (valcontents))
     {
       Lisp_Object tail, elt;
@@ -1774,6 +1789,7 @@
 {
   Lisp_Object valcontents;
   register struct buffer *buf;
+  struct Lisp_Symbol *sym;
 
   if (NILP (buffer))
     buf = current_buffer;
@@ -1784,9 +1800,10 @@
     }
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
-
-  valcontents = SYMBOL_VALUE (variable);
+  sym = indirect_variable (XSYMBOL (variable));
+  XSETSYMBOL (variable, sym);
+
+  valcontents = sym->value;
 
   if (BUFFER_OBJFWDP (valcontents))
     /* All these slots become local if they are set.  */
@@ -1816,14 +1833,15 @@
      register Lisp_Object variable;
 {
   Lisp_Object valcontents;
+  struct Lisp_Symbol *sym;
 
   CHECK_SYMBOL (variable);
-  variable = indirect_variable (variable);
+  sym = indirect_variable (XSYMBOL (variable));
 
   /* Make sure the current binding is actually swapped in.  */
   find_symbol_value (variable);
 
-  valcontents = XSYMBOL (variable)->value;
+  valcontents = sym->value;
 
   if (BUFFER_LOCAL_VALUEP (valcontents)
       || BUFFER_OBJFWDP (valcontents))
--- a/src/lisp.h	Mon May 19 16:29:33 2008 +0000
+++ b/src/lisp.h	Mon May 19 18:38:55 2008 +0000
@@ -993,7 +993,7 @@
 
 #define SYMBOL_VALUE(sym)			\
    (XSYMBOL (sym)->indirect_variable		\
-    ? XSYMBOL (indirect_variable (sym))->value	\
+    ? indirect_variable (XSYMBOL (sym))->value	\
     : XSYMBOL (sym)->value)
 
 /* Set SYM's value to VAL, taking defvaralias into account.  */
@@ -1001,7 +1001,7 @@
 #define SET_SYMBOL_VALUE(sym, val)				\
      do {							\
        if (XSYMBOL (sym)->indirect_variable)			\
-	 XSYMBOL (indirect_variable ((sym)))->value = (val);	\
+	 indirect_variable (XSYMBOL (sym))->value = (val);	\
        else							\
 	 XSYMBOL (sym)->value = (val);				\
      } while (0)
@@ -2263,7 +2263,7 @@
 EXFUN (Fsub1, 1);
 EXFUN (Fmake_variable_buffer_local, 1);
 
-extern Lisp_Object indirect_variable P_ ((Lisp_Object));
+extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
 extern Lisp_Object long_to_cons P_ ((unsigned long));
 extern unsigned long cons_to_long P_ ((Lisp_Object));
 extern void args_out_of_range P_ ((Lisp_Object, Lisp_Object)) NO_RETURN;