aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-17 13:12:24 +0400
committerDmitry Antipov2012-07-17 13:12:24 +0400
commitcce7fefcabe5794120d08714cbef6bba0c264226 (patch)
tree1b9368a12f1ea3193bc8c534729e83080ea415d6 /src
parentefc26dbecd1b548d6f44267ce13b56dbad8ab783 (diff)
downloademacs-cce7fefcabe5794120d08714cbef6bba0c264226.tar.gz
emacs-cce7fefcabe5794120d08714cbef6bba0c264226.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/alloc.c4
-rw-r--r--src/intervals.c144
-rw-r--r--src/intervals.h7
-rw-r--r--src/textprop.c27
5 files changed, 38 insertions, 160 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 82bedfdf2c4..b169bcca880 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12012-07-17 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Cleanup and convert miscellaneous checks to eassert.
4 * alloc.c (mark_interval): Fix comment, partially rephrase
5 old comment from intervals.h (see below).
6 * intervals.c (find_interval, adjust_intervals_for_insertion)
7 (delete_interval, adjust_intervals_for_deletion)
8 (graft_intervals_into_buffer, temp_set_point_both, copy_intervals):
9 Convert to eassert.
10 (adjust_intervals_for_insertion, make_new_interval):
11 Remove obsolete and unused code.
12 * intervals.h (struct interval): Remove obsolete comment.
13 * textprotp.c (erase_properties): Remove unused code.
14 (Fadd_text_properties, set_text_properties_1, Fremove_text_properties)
15 (Fremove_list_of_text_properties): Convert to eassert.
16
12012-07-17 Chong Yidong <cyd@gnu.org> 172012-07-17 Chong Yidong <cyd@gnu.org>
2 18
3 * editfns.c (Finsert_char): Doc fix. 19 * editfns.c (Finsert_char): Doc fix.
diff --git a/src/alloc.c b/src/alloc.c
index 6cbd63f716c..67ff3459e71 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1533,7 +1533,9 @@ make_interval (void)
1533static void 1533static void
1534mark_interval (register INTERVAL i, Lisp_Object dummy) 1534mark_interval (register INTERVAL i, Lisp_Object dummy)
1535{ 1535{
1536 eassert (!i->gcmarkbit); /* Intervals are never shared. */ 1536 /* Intervals should never be shared. So, if extra internal checking is
1537 enabled, GC aborts if it seems to have visited an interval twice. */
1538 eassert (!i->gcmarkbit);
1537 i->gcmarkbit = 1; 1539 i->gcmarkbit = 1;
1538 mark_object (i->plist); 1540 mark_object (i->plist);
1539} 1541}
diff --git a/src/intervals.c b/src/intervals.c
index 2c652cd9ad9..5b8d44e8ced 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -629,8 +629,7 @@ find_interval (register INTERVAL tree, register ptrdiff_t position)
629 relative_position -= BUF_BEG (XBUFFER (parent)); 629 relative_position -= BUF_BEG (XBUFFER (parent));
630 } 630 }
631 631
632 if (relative_position > TOTAL_LENGTH (tree)) 632 eassert (relative_position <= TOTAL_LENGTH (tree));
633 abort (); /* Paranoia */
634 633
635 if (!handling_signal) 634 if (!handling_signal)
636 tree = balance_possible_root_interval (tree); 635 tree = balance_possible_root_interval (tree);
@@ -785,68 +784,6 @@ update_interval (register INTERVAL i, ptrdiff_t pos)
785 } 784 }
786} 785}
787 786
788
789#if 0
790/* Traverse a path down the interval tree TREE to the interval
791 containing POSITION, adjusting all nodes on the path for
792 an addition of LENGTH characters. Insertion between two intervals
793 (i.e., point == i->position, where i is second interval) means
794 text goes into second interval.
795
796 Modifications are needed to handle the hungry bits -- after simply
797 finding the interval at position (don't add length going down),
798 if it's the beginning of the interval, get the previous interval
799 and check the hungry bits of both. Then add the length going back up
800 to the root. */
801
802static INTERVAL
803adjust_intervals_for_insertion (INTERVAL tree, ptrdiff_t position,
804 ptrdiff_t length)
805{
806 register ptrdiff_t relative_position;
807 register INTERVAL this;
808
809 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */
810 abort ();
811
812 /* If inserting at point-max of a buffer, that position
813 will be out of range */
814 if (position > TOTAL_LENGTH (tree))
815 position = TOTAL_LENGTH (tree);
816 relative_position = position;
817 this = tree;
818
819 while (1)
820 {
821 if (relative_position <= LEFT_TOTAL_LENGTH (this))
822 {
823 this->total_length += length;
824 CHECK_TOTAL_LENGTH (this);
825 this = this->left;
826 }
827 else if (relative_position > (TOTAL_LENGTH (this)
828 - RIGHT_TOTAL_LENGTH (this)))
829 {
830 relative_position -= (TOTAL_LENGTH (this)
831 - RIGHT_TOTAL_LENGTH (this));
832 this->total_length += length;
833 CHECK_TOTAL_LENGTH (this);
834 this = this->right;
835 }
836 else
837 {
838 /* If we are to use zero-length intervals as buffer pointers,
839 then this code will have to change. */
840 this->total_length += length;
841 CHECK_TOTAL_LENGTH (this);
842 this->position = LEFT_TOTAL_LENGTH (this)
843 + position - relative_position + 1;
844 return tree;
845 }
846 }
847}
848#endif
849
850/* Effect an adjustment corresponding to the addition of LENGTH characters 787/* Effect an adjustment corresponding to the addition of LENGTH characters
851 of text. Do this by finding the interval containing POSITION in the 788 of text. Do this by finding the interval containing POSITION in the
852 interval tree TREE, and then adjusting all of its ancestors by adding 789 interval tree TREE, and then adjusting all of its ancestors by adding
@@ -870,8 +807,7 @@ adjust_intervals_for_insertion (INTERVAL tree,
870 Lisp_Object parent; 807 Lisp_Object parent;
871 ptrdiff_t offset; 808 ptrdiff_t offset;
872 809
873 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ 810 eassert (TOTAL_LENGTH (tree) > 0);
874 abort ();
875 811
876 GET_INTERVAL_OBJECT (parent, tree); 812 GET_INTERVAL_OBJECT (parent, tree);
877 offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0); 813 offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0);
@@ -1262,8 +1198,7 @@ delete_interval (register INTERVAL i)
1262 register INTERVAL parent; 1198 register INTERVAL parent;
1263 ptrdiff_t amt = LENGTH (i); 1199 ptrdiff_t amt = LENGTH (i);
1264 1200
1265 if (amt > 0) /* Only used on zero-length intervals now. */ 1201 eassert (amt == 0); /* Only used on zero-length intervals now. */
1266 abort ();
1267 1202
1268 if (ROOT_INTERVAL_P (i)) 1203 if (ROOT_INTERVAL_P (i))
1269 { 1204 {
@@ -1386,9 +1321,8 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1386 if (NULL_INTERVAL_P (tree)) 1321 if (NULL_INTERVAL_P (tree))
1387 return; 1322 return;
1388 1323
1389 if (start > offset + TOTAL_LENGTH (tree) 1324 eassert (start <= offset + TOTAL_LENGTH (tree)
1390 || start + length > offset + TOTAL_LENGTH (tree)) 1325 && start + length <= offset + TOTAL_LENGTH (tree));
1391 abort ();
1392 1326
1393 if (length == TOTAL_LENGTH (tree)) 1327 if (length == TOTAL_LENGTH (tree))
1394 { 1328 {
@@ -1592,49 +1526,6 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent)
1592 1526
1593 return t; 1527 return t;
1594} 1528}
1595
1596#if 0
1597/* Nobody calls this. Perhaps it's a vestige of an earlier design. */
1598
1599/* Make a new interval of length LENGTH starting at START in the
1600 group of intervals INTERVALS, which is actually an interval tree.
1601 Returns the new interval.
1602
1603 Generate an error if the new positions would overlap an existing
1604 interval. */
1605
1606static INTERVAL
1607make_new_interval (INTERVAL intervals, ptrdiff_t start, ptrdiff_t length)
1608{
1609 INTERVAL slot;
1610
1611 slot = find_interval (intervals, start);
1612 if (start + length > slot->position + LENGTH (slot))
1613 error ("Interval would overlap");
1614
1615 if (start == slot->position && length == LENGTH (slot))
1616 return slot;
1617
1618 if (slot->position == start)
1619 {
1620 /* New right node. */
1621 split_interval_right (slot, length);
1622 return slot;
1623 }
1624
1625 if (slot->position + LENGTH (slot) == start + length)
1626 {
1627 /* New left node. */
1628 split_interval_left (slot, LENGTH (slot) - length);
1629 return slot;
1630 }
1631
1632 /* Convert interval SLOT into three intervals. */
1633 split_interval_left (slot, start - slot->position);
1634 split_interval_right (slot, length);
1635 return slot;
1636}
1637#endif
1638 1529
1639/* Insert the intervals of SOURCE into BUFFER at POSITION. 1530/* Insert the intervals of SOURCE into BUFFER at POSITION.
1640 LENGTH is the length of the text in SOURCE. 1531 LENGTH is the length of the text in SOURCE.
@@ -1725,14 +1616,12 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
1725 XSETBUFFER (buf, buffer); 1616 XSETBUFFER (buf, buffer);
1726 tree = create_root_interval (buf); 1617 tree = create_root_interval (buf);
1727 } 1618 }
1728 /* Paranoia -- the text has already been added, so this buffer 1619 /* Paranoia -- the text has already been added, so
1729 should be of non-zero length. */ 1620 this buffer should be of non-zero length. */
1730 else if (TOTAL_LENGTH (tree) == 0) 1621 eassert (TOTAL_LENGTH (tree) > 0);
1731 abort ();
1732 1622
1733 this = under = find_interval (tree, position); 1623 this = under = find_interval (tree, position);
1734 if (NULL_INTERVAL_P (under)) /* Paranoia. */ 1624 eassert (!NULL_INTERVAL_P (under));
1735 abort ();
1736 over = find_interval (source, interval_start_pos (source)); 1625 over = find_interval (source, interval_start_pos (source));
1737 1626
1738 /* Here for insertion in the middle of an interval. 1627 /* Here for insertion in the middle of an interval.
@@ -1867,15 +1756,11 @@ temp_set_point_both (struct buffer *buffer,
1867 ptrdiff_t charpos, ptrdiff_t bytepos) 1756 ptrdiff_t charpos, ptrdiff_t bytepos)
1868{ 1757{
1869 /* In a single-byte buffer, the two positions must be equal. */ 1758 /* In a single-byte buffer, the two positions must be equal. */
1870 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer) 1759 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer))
1871 && charpos != bytepos) 1760 eassert (charpos == bytepos);
1872 abort ();
1873
1874 if (charpos > bytepos)
1875 abort ();
1876 1761
1877 if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer)) 1762 eassert (charpos <= bytepos);
1878 abort (); 1763 eassert (charpos <= BUF_ZV (buffer) || BUF_BEGV (buffer) <= charpos);
1879 1764
1880 SET_BUF_PT_BOTH (buffer, charpos, bytepos); 1765 SET_BUF_PT_BOTH (buffer, charpos, bytepos);
1881} 1766}
@@ -2340,8 +2225,7 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length)
2340 return NULL_INTERVAL; 2225 return NULL_INTERVAL;
2341 2226
2342 i = find_interval (tree, start); 2227 i = find_interval (tree, start);
2343 if (NULL_INTERVAL_P (i) || LENGTH (i) == 0) 2228 eassert (!NULL_INTERVAL_P (i) && LENGTH (i) > 0);
2344 abort ();
2345 2229
2346 /* If there is only one interval and it's the default, return nil. */ 2230 /* If there is only one interval and it's the default, return nil. */
2347 if ((start - i->position + 1 + length) < LENGTH (i) 2231 if ((start - i->position + 1 + length) < LENGTH (i)
diff --git a/src/intervals.h b/src/intervals.h
index 8d2ee8346cf..d78289d897e 100644
--- a/src/intervals.h
+++ b/src/intervals.h
@@ -56,12 +56,7 @@ struct interval
56 unsigned int front_sticky : 1; /* Non-zero means text inserted just 56 unsigned int front_sticky : 1; /* Non-zero means text inserted just
57 before this interval goes into it. */ 57 before this interval goes into it. */
58 unsigned int rear_sticky : 1; /* Likewise for just after it. */ 58 unsigned int rear_sticky : 1; /* Likewise for just after it. */
59 59 Lisp_Object plist; /* Other properties. */
60 /* Properties of this interval.
61 The mark bit on this field says whether this particular interval
62 tree node has been visited. Since intervals should never be
63 shared, GC aborts if it seems to have visited an interval twice. */
64 Lisp_Object plist;
65}; 60};
66 61
67/* These are macros for dealing with the interval tree. */ 62/* These are macros for dealing with the interval tree. */
diff --git a/src/textprop.c b/src/textprop.c
index efce7259ce5..8aa52bebe5b 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -487,21 +487,6 @@ remove_properties (Lisp_Object plist, Lisp_Object list, INTERVAL i, Lisp_Object
487 i->plist = current_plist; 487 i->plist = current_plist;
488 return changed; 488 return changed;
489} 489}
490
491#if 0
492/* Remove all properties from interval I. Return non-zero
493 if this changes the interval. */
494
495static inline int
496erase_properties (INTERVAL i)
497{
498 if (NILP (i->plist))
499 return 0;
500
501 i->plist = Qnil;
502 return 1;
503}
504#endif
505 490
506/* Returns the interval of POSITION in OBJECT. 491/* Returns the interval of POSITION in OBJECT.
507 POSITION is BEG-based. */ 492 POSITION is BEG-based. */
@@ -1183,8 +1168,7 @@ Return t if any property value actually changed, nil otherwise. */)
1183 /* We are at the beginning of interval I, with LEN chars to scan. */ 1168 /* We are at the beginning of interval I, with LEN chars to scan. */
1184 for (;;) 1169 for (;;)
1185 { 1170 {
1186 if (i == 0) 1171 eassert (i != 0);
1187 abort ();
1188 1172
1189 if (LENGTH (i) >= len) 1173 if (LENGTH (i) >= len)
1190 { 1174 {
@@ -1383,8 +1367,7 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie
1383 /* We are starting at the beginning of an interval I. LEN is positive. */ 1367 /* We are starting at the beginning of an interval I. LEN is positive. */
1384 do 1368 do
1385 { 1369 {
1386 if (i == 0) 1370 eassert (i != 0);
1387 abort ();
1388 1371
1389 if (LENGTH (i) >= len) 1372 if (LENGTH (i) >= len)
1390 { 1373 {
@@ -1472,8 +1455,7 @@ Use `set-text-properties' if you want to remove all text properties. */)
1472 /* We are at the beginning of an interval, with len to scan */ 1455 /* We are at the beginning of an interval, with len to scan */
1473 for (;;) 1456 for (;;)
1474 { 1457 {
1475 if (i == 0) 1458 eassert (i != 0);
1476 abort ();
1477 1459
1478 if (LENGTH (i) >= len) 1460 if (LENGTH (i) >= len)
1479 { 1461 {
@@ -1562,8 +1544,7 @@ Return t if any property was actually removed, nil otherwise. */)
1562 and we call signal_after_change before returning if modified != 0. */ 1544 and we call signal_after_change before returning if modified != 0. */
1563 for (;;) 1545 for (;;)
1564 { 1546 {
1565 if (i == 0) 1547 eassert (i != 0);
1566 abort ();
1567 1548
1568 if (LENGTH (i) >= len) 1549 if (LENGTH (i) >= len)
1569 { 1550 {