From cce7fefcabe5794120d08714cbef6bba0c264226 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 17 Jul 2012 13:12:24 +0400 Subject: [PATCH] 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. --- src/ChangeLog | 16 +++++++ src/alloc.c | 4 +- src/intervals.c | 144 ++++++-------------------------------------------------- src/intervals.h | 7 +-- src/textprop.c | 27 ++--------- 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 @@ +2012-07-17 Dmitry Antipov + + 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 * 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) 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); } 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) 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 @@ update_interval (register INTERVAL i, ptrdiff_t pos) } } - -#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 @@ adjust_intervals_for_insertion (INTERVAL tree, 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 @@ delete_interval (register INTERVAL i) 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 @@ adjust_intervals_for_deletion (struct buffer *buffer, 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 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent) 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 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, 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 @@ temp_set_point_both (struct buffer *buffer, 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 (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer)) + eassert (charpos == bytepos); - if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer)) - abort (); + eassert (charpos <= bytepos); + eassert (charpos <= BUF_ZV (buffer) || BUF_BEGV (buffer) <= charpos); SET_BUF_PT_BOTH (buffer, charpos, bytepos); } @@ -2340,8 +2225,7 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length) 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) 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 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. */ 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 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 @@ Return t if any property value actually changed, nil otherwise. */) /* 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 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie /* 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 @@ Use `set-text-properties' if you want to remove all text properties. */) /* 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 @@ Return t if any property was actually removed, nil otherwise. */) and we call signal_after_change before returning if modified != 0. */ for (;;) { - if (i == 0) - abort (); + eassert (i != 0); if (LENGTH (i) >= len) { -- 2.11.4.GIT