emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r109361: Use INTERNAL_FIELD for conse


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109361: Use INTERNAL_FIELD for conses and overlays.
Date: Wed, 01 Aug 2012 12:49:28 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109361
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2012-08-01 12:49:28 +0400
message:
  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.
added:
  admin/coccinelle/overlay.cocci
modified:
  admin/ChangeLog
  src/ChangeLog
  src/alloc.c
  src/buffer.c
  src/buffer.h
  src/fns.c
  src/lisp.h
=== modified file 'admin/ChangeLog'
--- a/admin/ChangeLog   2012-08-01 07:57:09 +0000
+++ b/admin/ChangeLog   2012-08-01 08:49:28 +0000
@@ -1,5 +1,10 @@
 2012-08-01  Dmitry Antipov  <address@hidden>
 
+       * coccinelle/overlay.cocci: Semantic patch to replace direct
+       access to Lisp_Object members of struct Lisp_Overlay to MVAR.
+
+2012-08-01  Dmitry Antipov  <address@hidden>
+
        * coccinelle/symbol.cocci: Semantic patch to replace direct
        access to Lisp_Object members of struct Lisp_Symbol to SVAR.
 

=== added file 'admin/coccinelle/overlay.cocci'
--- a/admin/coccinelle/overlay.cocci    1970-01-01 00:00:00 +0000
+++ b/admin/coccinelle/overlay.cocci    2012-08-01 08:49:28 +0000
@@ -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)
+)

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-08-01 07:57:09 +0000
+++ b/src/ChangeLog     2012-08-01 08:49:28 +0000
@@ -1,5 +1,14 @@
 2012-08-01  Dmitry Antipov  <address@hidden>
 
+       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  <address@hidden>
+
        Use INTERNAL_FIELD for symbols.
        * lisp.h (SVAR): New macro.  Adjust users.
        * alloc.c, bytecode.c, cmds.c, data.c, doc.c, eval.c:

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-08-01 07:57:09 +0000
+++ b/src/alloc.c       2012-08-01 08:49:28 +0000
@@ -2686,7 +2686,7 @@
 {
   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 @@
              && 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 @@
   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 @@
        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 @@
                        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

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2012-08-01 05:11:36 +0000
+++ b/src/buffer.c      2012-08-01 08:49:28 +0000
@@ -417,17 +417,17 @@
       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 @@
 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 @@
 {
   CHECK_OVERLAY (overlay);
 
-  return Fcopy_sequence (XOVERLAY (overlay)->plist);
+  return Fcopy_sequence (MVAR (XOVERLAY (overlay), plist));
 }
 
 
@@ -4062,7 +4063,7 @@
   (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 @@
 
   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 @@
       }
   /* 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))
     {

=== modified file 'src/buffer.h'
--- a/src/buffer.h      2012-07-31 12:36:19 +0000
+++ b/src/buffer.h      2012-08-01 08:49:28 +0000
@@ -986,15 +986,15 @@
 
 /* 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.  */

=== modified file 'src/fns.c'
--- a/src/fns.c 2012-08-01 07:57:09 +0000
+++ b/src/fns.c 2012-08-01 08:49:28 +0000
@@ -2053,8 +2053,8 @@
              || !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))

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2012-08-01 07:57:09 +0000
+++ b/src/lisp.h        2012-08-01 08:49:28 +0000
@@ -637,17 +637,22 @@
 #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 @@
    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 @@
 
 #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 @@
     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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]