diff options
author | Dmitry Antipov <dmantipov@yandex.ru> | 2012-08-01 12:49:28 +0400 |
---|---|---|
committer | Dmitry Antipov <dmantipov@yandex.ru> | 2012-08-01 12:49:28 +0400 |
commit | d8a05828fd9f78c6cadddd8b47b53d83833c3917 (patch) | |
tree | e79a8e7e0a0abc277d5f928835abb0b64d7dcae7 | |
parent | 015a2738eb575f9dc07ea5e589eb88c8e071930a (diff) | |
download | emacs-d8a05828fd9f78c6cadddd8b47b53d83833c3917.tar.gz |
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.
-rw-r--r-- | admin/ChangeLog | 5 | ||||
-rw-r--r-- | admin/coccinelle/overlay.cocci | 28 | ||||
-rw-r--r-- | src/ChangeLog | 9 | ||||
-rw-r--r-- | src/alloc.c | 20 | ||||
-rw-r--r-- | src/buffer.c | 29 | ||||
-rw-r--r-- | src/buffer.h | 6 | ||||
-rw-r--r-- | src/fns.c | 4 | ||||
-rw-r--r-- | src/lisp.h | 31 |
8 files changed, 93 insertions, 39 deletions
diff --git a/admin/ChangeLog b/admin/ChangeLog index 8ca17e58b30..54ac7b4edd7 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog @@ -1,5 +1,10 @@ 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 access to Lisp_Object members of struct Lisp_Symbol to SVAR. diff --git a/admin/coccinelle/overlay.cocci b/admin/coccinelle/overlay.cocci new file mode 100644 index 00000000000..2be141e8332 --- /dev/null +++ b/admin/coccinelle/overlay.cocci @@ -0,0 +1,28 @@ +// 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) +) diff --git a/src/ChangeLog b/src/ChangeLog index 3bb9c2b4eef..a6913d1ad78 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 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. * lisp.h (SVAR): New macro. Adjust users. * alloc.c, bytecode.c, cmds.c, data.c, doc.c, eval.c: diff --git a/src/alloc.c b/src/alloc.c index 8207f022a12..2d5149a6772 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -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 diff --git a/src/buffer.c b/src/buffer.c index e70360f5173..8b7f524e27a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -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)) { diff --git a/src/buffer.h b/src/buffer.h index b9a2c9c7dce..cf571e06b53 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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. */ diff --git a/src/fns.c b/src/fns.c index 0ff2877ea5e..a8c8cb283b0 100644 --- a/src/fns.c +++ b/src/fns.c @@ -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)) diff --git a/src/lisp.h b/src/lisp.h index 5e2195ce01d..2928f92df37 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -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. |