Commit d8a05828 authored by Dmitry Antipov's avatar Dmitry Antipov
Browse files

Use INTERNAL_FIELD for conses and overlays.

* src/lisp.h (struct Lisp_Cons): Use INTERNAL_FIELD.
Remove obsolete comment.
(MVAR): New macro.
(struct Lisp_Overlay): Use INTERNAL_FIELD.
* src/alloc.c, src/buffer.c, src/buffer.h, src/fns.c: Adjust users.
* admin/coccinelle/overlay.cocci: Semantic patch to replace direct
access to Lisp_Object members of struct Lisp_Overlay to MVAR.
parent 015a2738
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
* coccinelle/overlay.cocci: Semantic patch to replace direct
access to Lisp_Object members of struct Lisp_Overlay to MVAR.
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
* coccinelle/symbol.cocci: Semantic patch to replace direct
......
// Change direct access to Lisp_Object fields of struct
// Lisp_Overlay to MVAR. Beginning M denotes "misc", and
// MVAR is likely to be used for other second-class objects.
@@
struct Lisp_Overlay *V;
Lisp_Object O;
@@
(
- V->start
+ MVAR (V, start)
|
- V->end
+ MVAR (V, end)
|
- V->plist
+ MVAR (V, plist)
|
- XOVERLAY (O)->start
+ MVAR (XOVERLAY (O), start)
|
- XOVERLAY (O)->end
+ MVAR (XOVERLAY (O), end)
|
- XOVERLAY (O)->plist
+ MVAR (XOVERLAY (O), plist)
)
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
Use INTERNAL_FIELD for conses and overlays.
* lisp.h (struct Lisp_Cons): Use INTERNAL_FIELD.
Remove obsolete comment.
(MVAR): New macro.
(struct Lisp_Overlay): Use INTERNAL_FIELD.
* alloc.c, buffer.c, buffer.h, fns.c: Adjust users.
2012-08-01 Dmitry Antipov <dmantipov@yandex.ru>
Use INTERNAL_FIELD for symbols.
......
......@@ -2686,7 +2686,7 @@ free_cons (struct Lisp_Cons *ptr)
{
ptr->u.chain = cons_free_list;
#if GC_MARK_STACK
ptr->car = Vdead;
CVAR (ptr, car) = Vdead;
#endif
cons_free_list = ptr;
consing_since_gc -= sizeof *ptr;
......@@ -4295,7 +4295,7 @@ live_cons_p (struct mem_node *m, void *p)
&& offset < (CONS_BLOCK_SIZE * sizeof b->conses[0])
&& (b != cons_block
|| offset / sizeof b->conses[0] < cons_block_index)
&& !EQ (((struct Lisp_Cons *) p)->car, Vdead));
&& !EQ (CVAR ((struct Lisp_Cons *) p, car), Vdead));
}
else
return 0;
......@@ -5837,9 +5837,9 @@ mark_overlay (struct Lisp_Overlay *ptr)
for (; ptr && !ptr->gcmarkbit; ptr = ptr->next)
{
ptr->gcmarkbit = 1;
mark_object (ptr->start);
mark_object (ptr->end);
mark_object (ptr->plist);
mark_object (MVAR (ptr, start));
mark_object (MVAR (ptr, end));
mark_object (MVAR (ptr, plist));
}
}
......@@ -6169,14 +6169,14 @@ mark_object (Lisp_Object arg)
CHECK_ALLOCATED_AND_LIVE (live_cons_p);
CONS_MARK (ptr);
/* If the cdr is nil, avoid recursion for the car. */
if (EQ (ptr->u.cdr, Qnil))
if (EQ (CVAR (ptr, u.cdr), Qnil))
{
obj = ptr->car;
obj = CVAR (ptr, car);
cdr_count = 0;
goto loop;
}
mark_object (ptr->car);
obj = ptr->u.cdr;
mark_object (CVAR (ptr, car));
obj = CVAR (ptr, u.cdr);
cdr_count++;
if (cdr_count == mark_object_loop_halt)
abort ();
......@@ -6325,7 +6325,7 @@ gc_sweep (void)
cblk->conses[pos].u.chain = cons_free_list;
cons_free_list = &cblk->conses[pos];
#if GC_MARK_STACK
cons_free_list->car = Vdead;
CVAR (cons_free_list, car) = Vdead;
#endif
}
else
......
......@@ -417,17 +417,17 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
Lisp_Object overlay, start, end;
struct Lisp_Marker *m;
eassert (MARKERP (list->start));
m = XMARKER (list->start);
eassert (MARKERP (MVAR (list, start)));
m = XMARKER (MVAR (list, start));
start = build_marker (b, m->charpos, m->bytepos);
XMARKER (start)->insertion_type = m->insertion_type;
eassert (MARKERP (list->end));
m = XMARKER (list->end);
eassert (MARKERP (MVAR (list, end)));
m = XMARKER (MVAR (list, end));
end = build_marker (b, m->charpos, m->bytepos);
XMARKER (end)->insertion_type = m->insertion_type;
overlay = build_overlay (start, end, Fcopy_sequence (list->plist));
overlay = build_overlay (start, end, Fcopy_sequence (MVAR (list, plist)));
if (tail)
tail = tail->next = XOVERLAY (overlay);
else
......@@ -657,10 +657,11 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
static void
drop_overlay (struct buffer *b, struct Lisp_Overlay *ov)
{
eassert (b == XBUFFER (Fmarker_buffer (ov->start)));
modify_overlay (b, marker_position (ov->start), marker_position (ov->end));
Fset_marker (ov->start, Qnil, Qnil);
Fset_marker (ov->end, Qnil, Qnil);
eassert (b == XBUFFER (Fmarker_buffer (MVAR (ov, start))));
modify_overlay (b, marker_position (MVAR (ov, start)),
marker_position (MVAR (ov, end)));
Fset_marker (MVAR (ov, start), Qnil, Qnil);
Fset_marker (MVAR (ov, end), Qnil, Qnil);
}
......@@ -3886,7 +3887,7 @@ OVERLAY. */)
{
CHECK_OVERLAY (overlay);
return Fcopy_sequence (XOVERLAY (overlay)->plist);
return Fcopy_sequence (MVAR (XOVERLAY (overlay), plist));
}
......@@ -4062,7 +4063,7 @@ DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0,
(Lisp_Object overlay, Lisp_Object prop)
{
CHECK_OVERLAY (overlay);
return lookup_char_property (XOVERLAY (overlay)->plist, prop, 0);
return lookup_char_property (MVAR (XOVERLAY (overlay), plist), prop, 0);
}
DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0,
......@@ -4077,7 +4078,7 @@ VALUE will be returned.*/)
buffer = Fmarker_buffer (OVERLAY_START (overlay));
for (tail = XOVERLAY (overlay)->plist;
for (tail = MVAR (XOVERLAY (overlay), plist);
CONSP (tail) && CONSP (XCDR (tail));
tail = XCDR (XCDR (tail)))
if (EQ (XCAR (tail), prop))
......@@ -4088,8 +4089,8 @@ VALUE will be returned.*/)
}
/* It wasn't in the list, so add it to the front. */
changed = !NILP (value);
XOVERLAY (overlay)->plist
= Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist));
MVAR (XOVERLAY (overlay), plist)
= Fcons (prop, Fcons (value, MVAR (XOVERLAY (overlay), plist)));
found:
if (! NILP (buffer))
{
......
......@@ -986,15 +986,15 @@ BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
/* Return the marker that stands for where OV starts in the buffer. */
#define OVERLAY_START(OV) (XOVERLAY (OV)->start)
#define OVERLAY_START(OV) MVAR (XOVERLAY (OV), start)
/* Return the marker that stands for where OV ends in the buffer. */
#define OVERLAY_END(OV) (XOVERLAY (OV)->end)
#define OVERLAY_END(OV) MVAR (XOVERLAY (OV), end)
/* Return the plist of overlay OV. */
#define OVERLAY_PLIST(OV) XOVERLAY ((OV))->plist
#define OVERLAY_PLIST(OV) MVAR (XOVERLAY (OV), plist)
/* Return the actual buffer position for the marker P.
We assume you know which buffer it's pointing into. */
......
......@@ -2053,8 +2053,8 @@ internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int
|| !internal_equal (OVERLAY_END (o1), OVERLAY_END (o2),
depth + 1, props))
return 0;
o1 = XOVERLAY (o1)->plist;
o2 = XOVERLAY (o2)->plist;
o1 = MVAR (XOVERLAY (o1), plist);
o2 = MVAR (XOVERLAY (o2), plist);
goto tail_recurse;
}
if (MARKERP (o1))
......
......@@ -637,17 +637,22 @@ typedef struct interval *INTERVAL;
#define CHECK_STRING_OR_BUFFER(x) \
CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x)
/* In a cons, the markbit of the car is the gc mark bit */
/* Most code should use this macro to
access Lisp fields in struct Lisp_Cons. */
#define CVAR(cons, field) ((cons)->INTERNAL_FIELD (field))
struct Lisp_Cons
{
/* Please do not use the names of these elements in code other
than the core lisp implementation. Use XCAR and XCDR below. */
Lisp_Object car;
/* Car of this cons cell. */
Lisp_Object INTERNAL_FIELD (car);
union
{
Lisp_Object cdr;
/* Cdr of this cons cell. */
Lisp_Object INTERNAL_FIELD (cdr);
/* Used to chain conses on a free list. */
struct Lisp_Cons *chain;
} u;
};
......@@ -659,8 +664,8 @@ struct Lisp_Cons
fields are not accessible as lvalues. (What if we want to switch to
a copying collector someday? Cached cons cell field addresses may be
invalidated at arbitrary points.) */
#define XCAR_AS_LVALUE(c) (XCONS ((c))->car)
#define XCDR_AS_LVALUE(c) (XCONS ((c))->u.cdr)
#define XCAR_AS_LVALUE(c) (CVAR (XCONS (c), car))
#define XCDR_AS_LVALUE(c) (CVAR (XCONS (c), u.cdr))
/* Use these from normal code. */
#define XCAR(c) LISP_MAKE_RVALUE (XCAR_AS_LVALUE (c))
......@@ -1261,7 +1266,11 @@ enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
#define DEFAULT_REHASH_SIZE 1.5
/* Most code should use this macro to access
Lisp fields in a different misc objects. */
#define MVAR(misc, field) ((misc)->INTERNAL_FIELD (field))
/* These structures are used for various misc types. */
struct Lisp_Misc_Any /* Supertype of all Misc types. */
......@@ -1331,7 +1340,9 @@ struct Lisp_Overlay
unsigned gcmarkbit : 1;
int spacer : 15;
struct Lisp_Overlay *next;
Lisp_Object start, end, plist;
Lisp_Object INTERNAL_FIELD (start);
Lisp_Object INTERNAL_FIELD (end);
Lisp_Object INTERNAL_FIELD (plist);
};
/* Hold a C pointer for later use.
......
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