emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r109118: Cleanup and convert miscella


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109118: Cleanup and convert miscellaneous checks to eassert.
Date: Tue, 17 Jul 2012 13:12:24 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109118
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Tue 2012-07-17 13:12:24 +0400
message:
  Cleanup and convert miscellaneous checks to eassert.
  * alloc.c (mark_interval): Fix comment, partially rephrase
  old comment from intervals.h (see below).
  * intervals.c (find_interval, adjust_intervals_for_insertion)
  (delete_interval, adjust_intervals_for_deletion)
  (graft_intervals_into_buffer, temp_set_point_both, copy_intervals):
  Convert to eassert.
  (adjust_intervals_for_insertion, make_new_interval):
  Remove obsolete and unused code.
  * intervals.h (struct interval): Remove obsolete comment.
  * textprotp.c (erase_properties): Remove unused code.
  (Fadd_text_properties, set_text_properties_1, Fremove_text_properties)
  (Fremove_list_of_text_properties): Convert to eassert.
modified:
  src/ChangeLog
  src/alloc.c
  src/intervals.c
  src/intervals.h
  src/textprop.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-07-17 07:43:01 +0000
+++ b/src/ChangeLog     2012-07-17 09:12:24 +0000
@@ -1,3 +1,19 @@
+2012-07-17  Dmitry Antipov  <address@hidden>
+
+       Cleanup and convert miscellaneous checks to eassert.
+       * alloc.c (mark_interval): Fix comment, partially rephrase
+       old comment from intervals.h (see below).
+       * intervals.c (find_interval, adjust_intervals_for_insertion)
+       (delete_interval, adjust_intervals_for_deletion)
+       (graft_intervals_into_buffer, temp_set_point_both, copy_intervals):
+       Convert to eassert.
+       (adjust_intervals_for_insertion, make_new_interval):
+       Remove obsolete and unused code.
+       * intervals.h (struct interval): Remove obsolete comment.
+       * textprotp.c (erase_properties): Remove unused code.
+       (Fadd_text_properties, set_text_properties_1, Fremove_text_properties)
+       (Fremove_list_of_text_properties): Convert to eassert.
+
 2012-07-17  Chong Yidong  <address@hidden>
 
        * editfns.c (Finsert_char): Doc fix.

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-07-17 07:15:50 +0000
+++ b/src/alloc.c       2012-07-17 09:12:24 +0000
@@ -1533,7 +1533,9 @@
 static void
 mark_interval (register INTERVAL i, Lisp_Object dummy)
 {
-  eassert (!i->gcmarkbit);             /* Intervals are never shared.  */
+  /* Intervals should never be shared.  So, if extra internal checking is
+     enabled, GC aborts if it seems to have visited an interval twice.  */
+  eassert (!i->gcmarkbit);
   i->gcmarkbit = 1;
   mark_object (i->plist);
 }

=== modified file 'src/intervals.c'
--- a/src/intervals.c   2012-06-16 12:24:15 +0000
+++ b/src/intervals.c   2012-07-17 09:12:24 +0000
@@ -629,8 +629,7 @@
        relative_position -= BUF_BEG (XBUFFER (parent));
     }
 
-  if (relative_position > TOTAL_LENGTH (tree))
-    abort ();                  /* Paranoia */
+  eassert (relative_position <= TOTAL_LENGTH (tree));
 
   if (!handling_signal)
     tree = balance_possible_root_interval (tree);
@@ -785,68 +784,6 @@
     }
 }
 
-
-#if 0
-/* Traverse a path down the interval tree TREE to the interval
-   containing POSITION, adjusting all nodes on the path for
-   an addition of LENGTH characters.  Insertion between two intervals
-   (i.e., point == i->position, where i is second interval) means
-   text goes into second interval.
-
-   Modifications are needed to handle the hungry bits -- after simply
-   finding the interval at position (don't add length going down),
-   if it's the beginning of the interval, get the previous interval
-   and check the hungry bits of both.  Then add the length going back up
-   to the root.  */
-
-static INTERVAL
-adjust_intervals_for_insertion (INTERVAL tree, ptrdiff_t position,
-                               ptrdiff_t length)
-{
-  register ptrdiff_t relative_position;
-  register INTERVAL this;
-
-  if (TOTAL_LENGTH (tree) == 0)        /* Paranoia */
-    abort ();
-
-  /* If inserting at point-max of a buffer, that position
-     will be out of range */
-  if (position > TOTAL_LENGTH (tree))
-    position = TOTAL_LENGTH (tree);
-  relative_position = position;
-  this = tree;
-
-  while (1)
-    {
-      if (relative_position <= LEFT_TOTAL_LENGTH (this))
-       {
-         this->total_length += length;
-         CHECK_TOTAL_LENGTH (this);
-         this = this->left;
-       }
-      else if (relative_position > (TOTAL_LENGTH (this)
-                                   - RIGHT_TOTAL_LENGTH (this)))
-       {
-         relative_position -= (TOTAL_LENGTH (this)
-                               - RIGHT_TOTAL_LENGTH (this));
-         this->total_length += length;
-         CHECK_TOTAL_LENGTH (this);
-         this = this->right;
-       }
-      else
-       {
-         /* If we are to use zero-length intervals as buffer pointers,
-            then this code will have to change.  */
-         this->total_length += length;
-         CHECK_TOTAL_LENGTH (this);
-         this->position = LEFT_TOTAL_LENGTH (this)
-                          + position - relative_position + 1;
-         return tree;
-       }
-    }
-}
-#endif
-
 /* Effect an adjustment corresponding to the addition of LENGTH characters
    of text.  Do this by finding the interval containing POSITION in the
    interval tree TREE, and then adjusting all of its ancestors by adding
@@ -870,8 +807,7 @@
   Lisp_Object parent;
   ptrdiff_t offset;
 
-  if (TOTAL_LENGTH (tree) == 0)        /* Paranoia */
-    abort ();
+  eassert (TOTAL_LENGTH (tree) > 0);
 
   GET_INTERVAL_OBJECT (parent, tree);
   offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0);
@@ -1262,8 +1198,7 @@
   register INTERVAL parent;
   ptrdiff_t amt = LENGTH (i);
 
-  if (amt > 0)                 /* Only used on zero-length intervals now.  */
-    abort ();
+  eassert (amt == 0);          /* Only used on zero-length intervals now.  */
 
   if (ROOT_INTERVAL_P (i))
     {
@@ -1386,9 +1321,8 @@
   if (NULL_INTERVAL_P (tree))
     return;
 
-  if (start > offset + TOTAL_LENGTH (tree)
-      || start + length > offset + TOTAL_LENGTH (tree))
-    abort ();
+  eassert (start <= offset + TOTAL_LENGTH (tree)
+          && start + length <= offset + TOTAL_LENGTH (tree));
 
   if (length == TOTAL_LENGTH (tree))
     {
@@ -1592,49 +1526,6 @@
 
   return t;
 }
-
-#if 0
-/* Nobody calls this.  Perhaps it's a vestige of an earlier design.  */
-
-/* Make a new interval of length LENGTH starting at START in the
-   group of intervals INTERVALS, which is actually an interval tree.
-   Returns the new interval.
-
-   Generate an error if the new positions would overlap an existing
-   interval.  */
-
-static INTERVAL
-make_new_interval (INTERVAL intervals, ptrdiff_t start, ptrdiff_t length)
-{
-  INTERVAL slot;
-
-  slot = find_interval (intervals, start);
-  if (start + length > slot->position + LENGTH (slot))
-    error ("Interval would overlap");
-
-  if (start == slot->position && length == LENGTH (slot))
-    return slot;
-
-  if (slot->position == start)
-    {
-      /* New right node.  */
-      split_interval_right (slot, length);
-      return slot;
-    }
-
-  if (slot->position + LENGTH (slot) == start + length)
-    {
-      /* New left node.  */
-      split_interval_left (slot, LENGTH (slot) - length);
-      return slot;
-    }
-
-  /* Convert interval SLOT into three intervals.  */
-  split_interval_left (slot, start - slot->position);
-  split_interval_right (slot, length);
-  return slot;
-}
-#endif
 
 /* Insert the intervals of SOURCE into BUFFER at POSITION.
    LENGTH is the length of the text in SOURCE.
@@ -1725,14 +1616,12 @@
        XSETBUFFER (buf, buffer);
        tree = create_root_interval (buf);
       }
-  /* Paranoia -- the text has already been added, so this buffer
-     should be of non-zero length.  */
-  else if (TOTAL_LENGTH (tree) == 0)
-    abort ();
+  /* Paranoia -- the text has already been added, so
+     this buffer should be of non-zero length.  */
+  eassert (TOTAL_LENGTH (tree) > 0);
 
   this = under = find_interval (tree, position);
-  if (NULL_INTERVAL_P (under)) /* Paranoia.  */
-    abort ();
+  eassert (!NULL_INTERVAL_P (under));
   over = find_interval (source, interval_start_pos (source));
 
   /* Here for insertion in the middle of an interval.
@@ -1867,15 +1756,11 @@
                     ptrdiff_t charpos, ptrdiff_t bytepos)
 {
   /* In a single-byte buffer, the two positions must be equal.  */
-  if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer)
-      && charpos != bytepos)
-    abort ();
-
-  if (charpos > bytepos)
-    abort ();
-
-  if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer))
-    abort ();
+  if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer))
+    eassert (charpos == bytepos);
+
+  eassert (charpos <= bytepos);
+  eassert (charpos <= BUF_ZV (buffer) || BUF_BEGV (buffer) <= charpos);
 
   SET_BUF_PT_BOTH (buffer, charpos, bytepos);
 }
@@ -2340,8 +2225,7 @@
     return NULL_INTERVAL;
 
   i = find_interval (tree, start);
-  if (NULL_INTERVAL_P (i) || LENGTH (i) == 0)
-    abort ();
+  eassert (!NULL_INTERVAL_P (i) && LENGTH (i) > 0);
 
   /* If there is only one interval and it's the default, return nil.  */
   if ((start - i->position + 1 + length) < LENGTH (i)

=== modified file 'src/intervals.h'
--- a/src/intervals.h   2012-07-03 18:24:42 +0000
+++ b/src/intervals.h   2012-07-17 09:12:24 +0000
@@ -56,12 +56,7 @@
   unsigned int front_sticky : 1;    /* Non-zero means text inserted just
                                       before this interval goes into it.  */
   unsigned int rear_sticky : 1;            /* Likewise for just after it.  */
-
-  /* Properties of this interval.
-     The mark bit on this field says whether this particular interval
-     tree node has been visited.  Since intervals should never be
-     shared, GC aborts if it seems to have visited an interval twice.  */
-  Lisp_Object plist;
+  Lisp_Object plist;               /* Other properties.  */
 };
 
 /* These are macros for dealing with the interval tree.  */

=== modified file 'src/textprop.c'
--- a/src/textprop.c    2012-07-10 16:53:26 +0000
+++ b/src/textprop.c    2012-07-17 09:12:24 +0000
@@ -487,21 +487,6 @@
     i->plist = current_plist;
   return changed;
 }
-
-#if 0
-/* Remove all properties from interval I.  Return non-zero
-   if this changes the interval.  */
-
-static inline int
-erase_properties (INTERVAL i)
-{
-  if (NILP (i->plist))
-    return 0;
-
-  i->plist = Qnil;
-  return 1;
-}
-#endif
 
 /* Returns the interval of POSITION in OBJECT.
    POSITION is BEG-based.  */
@@ -1183,8 +1168,7 @@
   /* We are at the beginning of interval I, with LEN chars to scan.  */
   for (;;)
     {
-      if (i == 0)
-       abort ();
+      eassert (i != 0);
 
       if (LENGTH (i) >= len)
        {
@@ -1383,8 +1367,7 @@
   /* We are starting at the beginning of an interval I.  LEN is positive.  */
   do
     {
-      if (i == 0)
-       abort ();
+      eassert (i != 0);
 
       if (LENGTH (i) >= len)
        {
@@ -1472,8 +1455,7 @@
   /* We are at the beginning of an interval, with len to scan */
   for (;;)
     {
-      if (i == 0)
-       abort ();
+      eassert (i != 0);
 
       if (LENGTH (i) >= len)
        {
@@ -1562,8 +1544,7 @@
      and we call signal_after_change before returning if modified != 0. */
   for (;;)
     {
-      if (i == 0)
-       abort ();
+      eassert (i != 0);
 
       if (LENGTH (i) >= len)
        {


reply via email to

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