+/***********************************************************************
+ Getting and Setting Values of Symbols
+ ***********************************************************************/
+
+/* Return the symbol holding SYMBOL's value. Signal
+ `cyclic-variable-indirection' if SYMBOL's chain of variable
+ indirections contains a loop. */
+
+Lisp_Object
+indirect_variable (symbol)
+ Lisp_Object symbol;
+{
+ Lisp_Object tortoise, hare;
+
+ hare = tortoise = symbol;
+
+ while (XSYMBOL (hare)->indirect_variable)
+ {
+ hare = XSYMBOL (hare)->value;
+ if (!XSYMBOL (hare)->indirect_variable)
+ break;
+
+ hare = XSYMBOL (hare)->value;
+ tortoise = XSYMBOL (tortoise)->value;
+
+ if (EQ (hare, tortoise))
+ Fsignal (Qcyclic_variable_indirection, Fcons (symbol, Qnil));
+ }
+
+ return hare;
+}
+
+
+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. */)
+ (object)
+ Lisp_Object object;
+{
+ if (SYMBOLP (object))
+ object = indirect_variable (object);
+ return object;
+}
+