Commit 8271d590 authored by Dmitry Antipov's avatar Dmitry Antipov

Use INTERNAL_FIELD for symbols.

* src/lisp.h (SVAR): New macro.  Adjust users.
* src/alloc.c, src/bytecode.c, src/cmds.c, src/data.c, src/doc.c, src/eval.c:
* src/fns.c, src/keyboard.c, src/lread.c, src/xterm.c: Users changed.
* admin/coccinelle/symbol.cocci: Semantic patch to replace direct
access to Lisp_Object members of struct Lisp_Symbol to SVAR.
parent 0d26d7c4
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
* coccinelle/symbol.cocci: Semantic patch to replace direct
access to Lisp_Object members of struct Lisp_Symbol to SVAR.
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
* coccinelle/process.cocci: Semantic patch to replace direct
......
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
Use INTERNAL_FIELD for symbols.
* lisp.h (SVAR): New macro. Adjust users.
* alloc.c, bytecode.c, cmds.c, data.c, doc.c, eval.c:
* fns.c, keyboard.c, lread.c, xterm.c: Users changed.
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
Use INTERNAL_FIELD for processes.
......
......@@ -3518,11 +3518,11 @@ Its value and function definition are void, and its property list is nil. */)
MALLOC_UNBLOCK_INPUT;
p = XSYMBOL (val);
p->xname = name;
p->plist = Qnil;
SVAR (p, xname) = name;
SVAR (p, plist) = Qnil;
p->redirect = SYMBOL_PLAINVAL;
SET_SYMBOL_VAL (p, Qunbound);
p->function = Qunbound;
SVAR (p, function) = Qunbound;
p->next = NULL;
p->gcmarkbit = 0;
p->interned = SYMBOL_UNINTERNED;
......@@ -4321,7 +4321,7 @@ live_symbol_p (struct mem_node *m, void *p)
&& offset < (SYMBOL_BLOCK_SIZE * sizeof b->symbols[0])
&& (b != symbol_block
|| offset / sizeof b->symbols[0] < symbol_block_index)
&& !EQ (((struct Lisp_Symbol *) p)->function, Vdead));
&& !EQ (SVAR (((struct Lisp_Symbol *)p), function), Vdead));
}
else
return 0;
......@@ -6073,8 +6073,8 @@ mark_object (Lisp_Object arg)
break;
CHECK_ALLOCATED_AND_LIVE (live_symbol_p);
ptr->gcmarkbit = 1;
mark_object (ptr->function);
mark_object (ptr->plist);
mark_object (SVAR (ptr, function));
mark_object (SVAR (ptr, plist));
switch (ptr->redirect)
{
case SYMBOL_PLAINVAL: mark_object (SYMBOL_VAL (ptr)); break;
......@@ -6105,9 +6105,9 @@ mark_object (Lisp_Object arg)
break;
default: abort ();
}
if (!PURE_POINTER_P (XSTRING (ptr->xname)))
MARK_STRING (XSTRING (ptr->xname));
MARK_INTERVAL_TREE (STRING_INTERVALS (ptr->xname));
if (!PURE_POINTER_P (XSTRING (SVAR (ptr, xname))))
MARK_STRING (XSTRING (SVAR (ptr, xname)));
MARK_INTERVAL_TREE (STRING_INTERVALS (SVAR (ptr, xname)));
ptr = ptr->next;
if (ptr)
......@@ -6473,7 +6473,7 @@ gc_sweep (void)
/* Check if the symbol was created during loadup. In such a case
it might be pointed to by pure bytecode which we don't trace,
so we conservatively assume that it is live. */
int pure_p = PURE_POINTER_P (XSTRING (sym->s.xname));
int pure_p = PURE_POINTER_P (XSTRING (sym->s.INTERNAL_FIELD (xname)));
if (!sym->s.gcmarkbit && !pure_p)
{
......@@ -6482,7 +6482,7 @@ gc_sweep (void)
sym->s.next = symbol_free_list;
symbol_free_list = &sym->s;
#if GC_MARK_STACK
symbol_free_list->function = Vdead;
SVAR (symbol_free_list, function) = Vdead;
#endif
++this_free;
}
......@@ -6490,7 +6490,7 @@ gc_sweep (void)
{
++num_used;
if (!pure_p)
UNMARK_STRING (XSTRING (sym->s.xname));
UNMARK_STRING (XSTRING (sym->s.INTERNAL_FIELD (xname)));
sym->s.gcmarkbit = 0;
}
}
......@@ -6675,10 +6675,10 @@ which_symbols (Lisp_Object obj, EMACS_INT find_max)
XSETSYMBOL (tem, sym);
val = find_symbol_value (tem);
if (EQ (val, obj)
|| EQ (sym->function, obj)
|| (!NILP (sym->function)
&& COMPILEDP (sym->function)
&& EQ (AREF (sym->function, COMPILED_BYTECODE), obj))
|| EQ (SVAR (sym, function), obj)
|| (!NILP (SVAR (sym, function))
&& COMPILEDP (SVAR (sym, function))
&& EQ (AREF (SVAR (sym, function), COMPILED_BYTECODE), obj))
|| (!NILP (val)
&& COMPILEDP (val)
&& EQ (AREF (val, COMPILED_BYTECODE), obj)))
......
......@@ -818,7 +818,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
&& !EQ (val, Qunbound)
&& !XSYMBOL (sym)->redirect
&& !SYMBOL_CONSTANT_P (sym))
XSYMBOL (sym)->val.value = val;
SVAR (XSYMBOL (sym), val.value) = val;
else
{
BEFORE_POTENTIAL_GC ();
......
......@@ -446,11 +446,13 @@ internal_self_insert (int c, EMACS_INT n)
/* If we expanded an abbrev which has a hook,
and the hook has a non-nil `no-self-insert' property,
return right away--don't really self-insert. */
if (SYMBOLP (sym) && ! NILP (sym) && ! NILP (XSYMBOL (sym)->function)
&& SYMBOLP (XSYMBOL (sym)->function))
if (SYMBOLP (sym) && ! NILP (sym)
&& ! NILP (SVAR (XSYMBOL (sym), function))
&& SYMBOLP (SVAR (XSYMBOL (sym), function)))
{
Lisp_Object prop;
prop = Fget (XSYMBOL (sym)->function, intern ("no-self-insert"));
prop = Fget (SVAR (XSYMBOL (sym), function),
intern ("no-self-insert"));
if (! NILP (prop))
return 1;
}
......
......@@ -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 (SVAR (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;
SVAR (XSYMBOL (symbol), function) = Qunbound;
return symbol;
}
......@@ -594,8 +594,8 @@ DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
(register Lisp_Object symbol)
{
CHECK_SYMBOL (symbol);
if (!EQ (XSYMBOL (symbol)->function, Qunbound))
return XSYMBOL (symbol)->function;
if (!EQ (SVAR (XSYMBOL (symbol), function), Qunbound))
return SVAR (XSYMBOL (symbol), function);
xsignal1 (Qvoid_function, symbol);
}
......@@ -604,7 +604,7 @@ DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0,
(register Lisp_Object symbol)
{
CHECK_SYMBOL (symbol);
return XSYMBOL (symbol)->plist;
return SVAR (XSYMBOL (symbol), plist);
}
DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0,
......@@ -628,7 +628,7 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
if (NILP (symbol) || EQ (symbol, Qt))
xsignal1 (Qsetting_constant, symbol);
function = XSYMBOL (symbol)->function;
function = SVAR (XSYMBOL (symbol), function);
if (!NILP (Vautoload_queue) && !EQ (function, Qunbound))
Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
......@@ -636,13 +636,13 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
if (CONSP (function) && EQ (XCAR (function), Qautoload))
Fput (symbol, Qautoload, XCDR (function));
XSYMBOL (symbol)->function = definition;
SVAR (XSYMBOL (symbol), function) = definition;
/* Handle automatic advice activation. */
if (CONSP (XSYMBOL (symbol)->plist)
if (CONSP (SVAR (XSYMBOL (symbol), plist))
&& !NILP (Fget (symbol, Qad_advice_info)))
{
call2 (Qad_activate_internal, symbol, Qnil);
definition = XSYMBOL (symbol)->function;
definition = SVAR (XSYMBOL (symbol), function);
}
return definition;
}
......@@ -657,8 +657,8 @@ The return value is undefined. */)
(register Lisp_Object symbol, Lisp_Object definition, Lisp_Object docstring)
{
CHECK_SYMBOL (symbol);
if (CONSP (XSYMBOL (symbol)->function)
&& EQ (XCAR (XSYMBOL (symbol)->function), Qautoload))
if (CONSP (SVAR (XSYMBOL (symbol), function))
&& EQ (XCAR (SVAR (XSYMBOL (symbol), function)), Qautoload))
LOADHIST_ATTACH (Fcons (Qt, symbol));
if (!NILP (Vpurify_flag)
/* If `definition' is a keymap, immutable (and copying) is wrong. */
......@@ -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;
SVAR (XSYMBOL (symbol), plist) = newplist;
return newplist;
}
......@@ -2019,12 +2019,12 @@ indirect_function (register Lisp_Object object)
{
if (!SYMBOLP (hare) || EQ (hare, Qunbound))
break;
hare = XSYMBOL (hare)->function;
hare = SVAR (XSYMBOL (hare), function);
if (!SYMBOLP (hare) || EQ (hare, Qunbound))
break;
hare = XSYMBOL (hare)->function;
hare = SVAR (XSYMBOL (hare), function);
tortoise = XSYMBOL (tortoise)->function;
tortoise = SVAR (XSYMBOL (tortoise), function);
if (EQ (hare, tortoise))
xsignal1 (Qcyclic_function_indirection, object);
......@@ -2048,7 +2048,7 @@ function chain of symbols. */)
/* Optimize for no indirection. */
result = object;
if (SYMBOLP (result) && !EQ (result, Qunbound)
&& (result = XSYMBOL (result)->function, SYMBOLP (result)))
&& (result = SVAR (XSYMBOL (result), function), SYMBOLP (result)))
result = indirect_function (result);
if (!EQ (result, Qunbound))
return result;
......@@ -3197,7 +3197,7 @@ syms_of_data (void)
defsubr (&Ssubr_arity);
defsubr (&Ssubr_name);
XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
SVAR (XSYMBOL (Qwholenump), function) = SVAR (XSYMBOL (Qnatnump), function);
DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum,
doc: /* The largest value that is representable in a Lisp integer. */);
......
......@@ -508,7 +508,7 @@ store_function_docstring (Lisp_Object obj, ptrdiff_t offset)
{
/* Don't use indirect_function here, or defaliases will apply their
docstrings to the base functions (Bug#2603). */
Lisp_Object fun = SYMBOLP (obj) ? XSYMBOL (obj)->function : obj;
Lisp_Object fun = SYMBOLP (obj) ? SVAR (XSYMBOL (obj), function) : obj;
/* The type determines where the docstring is stored. */
......
......@@ -976,7 +976,7 @@ definitions to shadow the loaded ones for use in file byte-compilation. */)
tem = Fassq (sym, environment);
if (NILP (tem))
{
def = XSYMBOL (sym)->function;
def = SVAR (XSYMBOL (sym), function);
if (!EQ (def, Qunbound))
continue;
}
......@@ -1893,9 +1893,9 @@ this does nothing and returns nil. */)
CHECK_STRING (file);
/* If function is defined and not as an autoload, don't override. */
if (!EQ (XSYMBOL (function)->function, Qunbound)
&& !(CONSP (XSYMBOL (function)->function)
&& EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
if (!EQ (SVAR (XSYMBOL (function), function), Qunbound)
&& !(CONSP (SVAR (XSYMBOL (function), function))
&& EQ (XCAR (SVAR (XSYMBOL (function), function)), Qautoload)))
return Qnil;
if (NILP (Vpurify_flag))
......@@ -2081,7 +2081,7 @@ eval_sub (Lisp_Object form)
/* Optimize for no indirection. */
fun = original_fun;
if (SYMBOLP (fun) && !EQ (fun, Qunbound)
&& (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
&& (fun = SVAR (XSYMBOL (fun), function), SYMBOLP (fun)))
fun = indirect_function (fun);
if (SUBRP (fun))
......@@ -2266,7 +2266,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
/* Optimize for no indirection. */
if (SYMBOLP (fun) && !EQ (fun, Qunbound)
&& (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
&& (fun = SVAR (XSYMBOL (fun), function), SYMBOLP (fun)))
fun = indirect_function (fun);
if (EQ (fun, Qunbound))
{
......@@ -2771,7 +2771,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
/* Optimize for no indirection. */
fun = original_fun;
if (SYMBOLP (fun) && !EQ (fun, Qunbound)
&& (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
&& (fun = SVAR (XSYMBOL (fun), function), SYMBOLP (fun)))
fun = indirect_function (fun);
if (SUBRP (fun))
......
......@@ -1868,7 +1868,7 @@ This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */)
(Lisp_Object symbol, Lisp_Object propname)
{
CHECK_SYMBOL (symbol);
return Fplist_get (XSYMBOL (symbol)->plist, propname);
return Fplist_get (SVAR (XSYMBOL (symbol), plist), propname);
}
DEFUN ("plist-put", Fplist_put, Splist_put, 3, 3, 0,
......@@ -1910,8 +1910,8 @@ It can be retrieved with `(get SYMBOL PROPNAME)'. */)
(Lisp_Object symbol, Lisp_Object propname, Lisp_Object value)
{
CHECK_SYMBOL (symbol);
XSYMBOL (symbol)->plist
= Fplist_put (XSYMBOL (symbol)->plist, propname, value);
SVAR (XSYMBOL (symbol), plist)
= Fplist_put (SVAR (XSYMBOL (symbol), plist), propname, value);
return value;
}
......
......@@ -7894,7 +7894,8 @@ parse_menu_item (Lisp_Object item, int inmenubar)
/* If the command is an alias for another
(such as lmenu.el set it up), check if the
original command matches the cached command. */
&& !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function))))
&& !(SYMBOLP (def)
&& EQ (tem, SVAR (XSYMBOL (def), function)))))
keys = Qnil;
}
......@@ -8823,9 +8824,9 @@ access_keymap_keyremap (Lisp_Object map, Lisp_Object key, Lisp_Object prompt,
/* Handle a symbol whose function definition is a keymap
or an array. */
if (SYMBOLP (next) && !NILP (Ffboundp (next))
&& (ARRAYP (XSYMBOL (next)->function)
|| KEYMAPP (XSYMBOL (next)->function)))
next = Fautoload_do_load (XSYMBOL (next)->function, next, Qnil);
&& (ARRAYP (SVAR (XSYMBOL (next), function))
|| KEYMAPP (SVAR (XSYMBOL (next), function))))
next = Fautoload_do_load (SVAR (XSYMBOL (next), function), next, Qnil);
/* If the keymap gives a function, not an
array, then call the function with one arg and use
......
......@@ -1039,6 +1039,11 @@ enum symbol_redirect
SYMBOL_FORWARDED = 3
};
/* Most code should use this macro to access
Lisp fields in struct Lisp_Symbol. */
#define SVAR(sym, field) ((sym)->INTERNAL_FIELD (field))
struct Lisp_Symbol
{
unsigned gcmarkbit : 1;
......@@ -1066,22 +1071,22 @@ struct Lisp_Symbol
/* The symbol's name, as a Lisp string.
The name "xname" is used to intentionally break code referring to
the old field "name" of type pointer to struct Lisp_String. */
Lisp_Object xname;
Lisp_Object INTERNAL_FIELD (xname);
/* Value of the symbol or Qunbound if unbound. Which alternative of the
union is used depends on the `redirect' field above. */
union {
Lisp_Object value;
Lisp_Object INTERNAL_FIELD (value);
struct Lisp_Symbol *alias;
struct Lisp_Buffer_Local_Value *blv;
union Lisp_Fwd *fwd;
} val;
/* Function value of the symbol or Qunbound if not fboundp. */
Lisp_Object function;
Lisp_Object INTERNAL_FIELD (function);
/* The symbol's property list. */
Lisp_Object plist;
Lisp_Object INTERNAL_FIELD (plist);
/* Next symbol in obarray bucket, if the symbol is interned. */
struct Lisp_Symbol *next;
......@@ -1090,7 +1095,7 @@ struct Lisp_Symbol
/* Value is name of symbol. */
#define SYMBOL_VAL(sym) \
(eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value)
(eassert ((sym)->redirect == SYMBOL_PLAINVAL), SVAR (sym, val.value))
#define SYMBOL_ALIAS(sym) \
(eassert ((sym)->redirect == SYMBOL_VARALIAS), (sym)->val.alias)
#define SYMBOL_BLV(sym) \
......@@ -1098,7 +1103,7 @@ struct Lisp_Symbol
#define SYMBOL_FWD(sym) \
(eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd)
#define SET_SYMBOL_VAL(sym, v) \
(eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value = (v))
(eassert ((sym)->redirect == SYMBOL_PLAINVAL), SVAR (sym, val.value) = (v))
#define SET_SYMBOL_ALIAS(sym, v) \
(eassert ((sym)->redirect == SYMBOL_VARALIAS), (sym)->val.alias = (v))
#define SET_SYMBOL_BLV(sym, v) \
......@@ -1107,7 +1112,7 @@ struct Lisp_Symbol
(eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd = (v))
#define SYMBOL_NAME(sym) \
LISP_MAKE_RVALUE (XSYMBOL (sym)->xname)
LISP_MAKE_RVALUE (SVAR (XSYMBOL (sym), xname))
/* Value is non-zero if SYM is an interned symbol. */
......
......@@ -3922,13 +3922,13 @@ init_obarray (void)
/* Fmake_symbol inits fields of new symbols with Qunbound and Qnil,
so those two need to be fixed manually. */
SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound);
XSYMBOL (Qunbound)->function = Qunbound;
XSYMBOL (Qunbound)->plist = Qnil;
SVAR (XSYMBOL (Qunbound), function) = Qunbound;
SVAR (XSYMBOL (Qunbound), plist) = Qnil;
/* XSYMBOL (Qnil)->function = Qunbound; */
SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil);
XSYMBOL (Qnil)->constant = 1;
XSYMBOL (Qnil)->declared_special = 1;
XSYMBOL (Qnil)->plist = Qnil;
SVAR (XSYMBOL (Qnil), plist) = Qnil;
Qt = intern_c_string ("t");
SET_SYMBOL_VAL (XSYMBOL (Qt), Qt);
......@@ -3950,7 +3950,7 @@ defsubr (struct Lisp_Subr *sname)
Lisp_Object sym;
sym = intern_c_string (sname->symbol_name);
XSETTYPED_PVECTYPE (sname, size, PVEC_SUBR);
XSETSUBR (XSYMBOL (sym)->function, sname);
XSETSUBR (SVAR (XSYMBOL (sym), function), sname);
}
#ifdef NOTDEF /* Use fset in subr.el now! */
......
......@@ -10117,7 +10117,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
terminal->kboard->next_kboard = all_kboards;
all_kboards = terminal->kboard;
if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound))
if (!EQ (SVAR (XSYMBOL (Qvendor_specific_keysyms), function), Qunbound))
{
char *vendor = ServerVendor (dpy);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment