aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-29 15:20:43 +0400
committerDmitry Antipov2012-07-29 15:20:43 +0400
commite2688e4ac71bd3c1f7d22f28175c4ca81eb87e43 (patch)
treec84bad8ef03f6eb995a08afdac5eb1b954c1655e /src
parent93131e119fa0f1fe44ccbccd0b8edcf8707a892d (diff)
downloademacs-e2688e4ac71bd3c1f7d22f28175c4ca81eb87e43.tar.gz
emacs-e2688e4ac71bd3c1f7d22f28175c4ca81eb87e43.zip
Generalize marker debugging code under MARKER_DEBUG and use eassert.
* insdel.c (CHECK_MARKERS, check_markers_debug_flag): Remove. (gap_left, gap_right, adjust_markers_for_delete, insert_1_both) (insert_from_string_1, insert_from_gap, insert_from_buffer_1) (replace_range, replace_range_2, del_range_2): Change to eassert. * marker.c (byte_char_debug_check): Adjust style.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/insdel.c82
-rw-r--r--src/marker.c2
3 files changed, 44 insertions, 49 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 21ba05adf6d..4b811b79a9b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12012-07-29 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Generalize marker debugging code under MARKER_DEBUG and use eassert.
4 * insdel.c (CHECK_MARKERS, check_markers_debug_flag): Remove.
5 (gap_left, gap_right, adjust_markers_for_delete, insert_1_both)
6 (insert_from_string_1, insert_from_gap, insert_from_buffer_1)
7 (replace_range, replace_range_2, del_range_2): Change to eassert.
8 * marker.c (byte_char_debug_check): Adjust style.
9
12012-07-29 Paul Eggert <eggert@cs.ucla.edu> 102012-07-29 Paul Eggert <eggert@cs.ucla.edu>
2 11
3 Don't use the abbreviation "win" to refer to Windows (Bug#10421). 12 Don't use the abbreviation "win" to refer to Windows (Bug#10421).
diff --git a/src/insdel.c b/src/insdel.c
index 2074916cfde..9646507bc4b 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -59,14 +59,10 @@ static Lisp_Object combine_after_change_buffer;
59Lisp_Object Qinhibit_modification_hooks; 59Lisp_Object Qinhibit_modification_hooks;
60 60
61static void signal_before_change (ptrdiff_t, ptrdiff_t, ptrdiff_t *); 61static void signal_before_change (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
62 62
63#define CHECK_MARKERS() \ 63/* Also used in marker.c to enable expensive marker checks. */
64 do \ 64
65 { \ 65#ifdef MARKER_DEBUG
66 if (check_markers_debug_flag) \
67 check_markers (); \
68 } \
69 while (0)
70 66
71static void 67static void
72check_markers (void) 68check_markers (void)
@@ -86,7 +82,13 @@ check_markers (void)
86 abort (); 82 abort ();
87 } 83 }
88} 84}
89 85
86#else /* not MARKER_DEBUG */
87
88#define check_markers() do { } while (0)
89
90#endif /* MARKER_DEBUG */
91
90/* Move gap to position CHARPOS. 92/* Move gap to position CHARPOS.
91 Note that this can quit! */ 93 Note that this can quit! */
92 94
@@ -158,8 +160,7 @@ gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap)
158 was specified or may be where a quit was detected. */ 160 was specified or may be where a quit was detected. */
159 GPT_BYTE = bytepos; 161 GPT_BYTE = bytepos;
160 GPT = charpos; 162 GPT = charpos;
161 if (bytepos < charpos) 163 eassert (charpos <= bytepos);
162 abort ();
163 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 164 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
164 QUIT; 165 QUIT;
165} 166}
@@ -209,8 +210,7 @@ gap_right (ptrdiff_t charpos, ptrdiff_t bytepos)
209 210
210 GPT = charpos; 211 GPT = charpos;
211 GPT_BYTE = bytepos; 212 GPT_BYTE = bytepos;
212 if (bytepos < charpos) 213 eassert (charpos <= bytepos);
213 abort ();
214 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 214 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
215 QUIT; 215 QUIT;
216} 216}
@@ -233,9 +233,7 @@ adjust_markers_for_delete (ptrdiff_t from, ptrdiff_t from_byte,
233 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 233 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
234 { 234 {
235 charpos = m->charpos; 235 charpos = m->charpos;
236 236 eassert (charpos <= Z);
237 if (charpos > Z)
238 abort ();
239 237
240 /* If the marker is after the deletion, 238 /* If the marker is after the deletion,
241 relocate by number of chars / bytes deleted. */ 239 relocate by number of chars / bytes deleted. */
@@ -375,7 +373,7 @@ adjust_markers_for_replace (ptrdiff_t from, ptrdiff_t from_byte,
375 } 373 }
376 } 374 }
377 375
378 CHECK_MARKERS (); 376 check_markers ();
379} 377}
380 378
381 379
@@ -835,8 +833,7 @@ insert_1_both (const char *string,
835 Z_BYTE += nbytes; 833 Z_BYTE += nbytes;
836 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 834 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
837 835
838 if (GPT_BYTE < GPT) 836 eassert (GPT <= GPT_BYTE);
839 abort ();
840 837
841 /* The insert may have been in the unchanged region, so check again. */ 838 /* The insert may have been in the unchanged region, so check again. */
842 if (Z - GPT < END_UNCHANGED) 839 if (Z - GPT < END_UNCHANGED)
@@ -856,7 +853,7 @@ insert_1_both (const char *string,
856 853
857 adjust_point (nchars, nbytes); 854 adjust_point (nchars, nbytes);
858 855
859 CHECK_MARKERS (); 856 check_markers ();
860} 857}
861 858
862/* Insert the part of the text of STRING, a Lisp object assumed to be 859/* Insert the part of the text of STRING, a Lisp object assumed to be
@@ -966,8 +963,7 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
966 Z_BYTE += outgoing_nbytes; 963 Z_BYTE += outgoing_nbytes;
967 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 964 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
968 965
969 if (GPT_BYTE < GPT) 966 eassert (GPT <= GPT_BYTE);
970 abort ();
971 967
972 /* The insert may have been in the unchanged region, so check again. */ 968 /* The insert may have been in the unchanged region, so check again. */
973 if (Z - GPT < END_UNCHANGED) 969 if (Z - GPT < END_UNCHANGED)
@@ -991,7 +987,7 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
991 987
992 adjust_point (nchars, outgoing_nbytes); 988 adjust_point (nchars, outgoing_nbytes);
993 989
994 CHECK_MARKERS (); 990 check_markers ();
995} 991}
996 992
997/* Insert a sequence of NCHARS chars which occupy NBYTES bytes 993/* Insert a sequence of NCHARS chars which occupy NBYTES bytes
@@ -1015,8 +1011,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
1015 Z_BYTE += nbytes; 1011 Z_BYTE += nbytes;
1016 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1012 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1017 1013
1018 if (GPT_BYTE < GPT) 1014 eassert (GPT <= GPT_BYTE);
1019 abort ();
1020 1015
1021 adjust_overlays_for_insert (GPT - nchars, nchars); 1016 adjust_overlays_for_insert (GPT - nchars, nchars);
1022 adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes, 1017 adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes,
@@ -1032,7 +1027,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
1032 if (GPT - nchars < PT) 1027 if (GPT - nchars < PT)
1033 adjust_point (nchars, nbytes); 1028 adjust_point (nchars, nbytes);
1034 1029
1035 CHECK_MARKERS (); 1030 check_markers ();
1036} 1031}
1037 1032
1038/* Insert text from BUF, NCHARS characters starting at CHARPOS, into the 1033/* Insert text from BUF, NCHARS characters starting at CHARPOS, into the
@@ -1151,8 +1146,7 @@ insert_from_buffer_1 (struct buffer *buf,
1151 Z_BYTE += outgoing_nbytes; 1146 Z_BYTE += outgoing_nbytes;
1152 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1147 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1153 1148
1154 if (GPT_BYTE < GPT) 1149 eassert (GPT <= GPT_BYTE);
1155 abort ();
1156 1150
1157 /* The insert may have been in the unchanged region, so check again. */ 1151 /* The insert may have been in the unchanged region, so check again. */
1158 if (Z - GPT < END_UNCHANGED) 1152 if (Z - GPT < END_UNCHANGED)
@@ -1243,7 +1237,7 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
1243 if (Z - GPT < END_UNCHANGED) 1237 if (Z - GPT < END_UNCHANGED)
1244 END_UNCHANGED = Z - GPT; 1238 END_UNCHANGED = Z - GPT;
1245 1239
1246 CHECK_MARKERS (); 1240 check_markers ();
1247 1241
1248 if (len == 0) 1242 if (len == 0)
1249 evaporate_overlays (from); 1243 evaporate_overlays (from);
@@ -1296,7 +1290,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1296 ptrdiff_t outgoing_insbytes = insbytes; 1290 ptrdiff_t outgoing_insbytes = insbytes;
1297 Lisp_Object deletion; 1291 Lisp_Object deletion;
1298 1292
1299 CHECK_MARKERS (); 1293 check_markers ();
1300 1294
1301 GCPRO1 (new); 1295 GCPRO1 (new);
1302 deletion = Qnil; 1296 deletion = Qnil;
@@ -1357,8 +1351,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1357 GPT_BYTE = from_byte; 1351 GPT_BYTE = from_byte;
1358 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1352 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1359 1353
1360 if (GPT_BYTE < GPT) 1354 eassert (GPT <= GPT_BYTE);
1361 abort ();
1362 1355
1363 if (GPT - BEG < BEG_UNCHANGED) 1356 if (GPT - BEG < BEG_UNCHANGED)
1364 BEG_UNCHANGED = GPT - BEG; 1357 BEG_UNCHANGED = GPT - BEG;
@@ -1404,8 +1397,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1404 Z_BYTE += outgoing_insbytes; 1397 Z_BYTE += outgoing_insbytes;
1405 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1398 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1406 1399
1407 if (GPT_BYTE < GPT) 1400 eassert (GPT <= GPT_BYTE);
1408 abort ();
1409 1401
1410 /* Adjust the overlay center as needed. This must be done after 1402 /* Adjust the overlay center as needed. This must be done after
1411 adjusting the markers that bound the overlays. */ 1403 adjusting the markers that bound the overlays. */
@@ -1435,7 +1427,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1435 if (outgoing_insbytes == 0) 1427 if (outgoing_insbytes == 0)
1436 evaporate_overlays (from); 1428 evaporate_overlays (from);
1437 1429
1438 CHECK_MARKERS (); 1430 check_markers ();
1439 1431
1440 MODIFF++; 1432 MODIFF++;
1441 CHARS_MODIFF = MODIFF; 1433 CHARS_MODIFF = MODIFF;
@@ -1465,7 +1457,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1465{ 1457{
1466 ptrdiff_t nbytes_del, nchars_del; 1458 ptrdiff_t nbytes_del, nchars_del;
1467 1459
1468 CHECK_MARKERS (); 1460 check_markers ();
1469 1461
1470 nchars_del = to - from; 1462 nchars_del = to - from;
1471 nbytes_del = to_byte - from_byte; 1463 nbytes_del = to_byte - from_byte;
@@ -1488,8 +1480,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1488 GPT_BYTE = from_byte; 1480 GPT_BYTE = from_byte;
1489 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1481 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1490 1482
1491 if (GPT_BYTE < GPT) 1483 eassert (GPT <= GPT_BYTE);
1492 abort ();
1493 1484
1494 if (GPT - BEG < BEG_UNCHANGED) 1485 if (GPT - BEG < BEG_UNCHANGED)
1495 BEG_UNCHANGED = GPT - BEG; 1486 BEG_UNCHANGED = GPT - BEG;
@@ -1522,8 +1513,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1522 Z_BYTE += insbytes; 1513 Z_BYTE += insbytes;
1523 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1514 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1524 1515
1525 if (GPT_BYTE < GPT) 1516 eassert (GPT <= GPT_BYTE);
1526 abort ();
1527 1517
1528 /* Adjust the overlay center as needed. This must be done after 1518 /* Adjust the overlay center as needed. This must be done after
1529 adjusting the markers that bound the overlays. */ 1519 adjusting the markers that bound the overlays. */
@@ -1554,7 +1544,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1554 if (insbytes == 0) 1544 if (insbytes == 0)
1555 evaporate_overlays (from); 1545 evaporate_overlays (from);
1556 1546
1557 CHECK_MARKERS (); 1547 check_markers ();
1558 1548
1559 MODIFF++; 1549 MODIFF++;
1560 CHARS_MODIFF = MODIFF; 1550 CHARS_MODIFF = MODIFF;
@@ -1705,7 +1695,7 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1705 register ptrdiff_t nbytes_del, nchars_del; 1695 register ptrdiff_t nbytes_del, nchars_del;
1706 Lisp_Object deletion; 1696 Lisp_Object deletion;
1707 1697
1708 CHECK_MARKERS (); 1698 check_markers ();
1709 1699
1710 nchars_del = to - from; 1700 nchars_del = to - from;
1711 nbytes_del = to_byte - from_byte; 1701 nbytes_del = to_byte - from_byte;
@@ -1761,15 +1751,14 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1761 needs to access the previous gap contents. */ 1751 needs to access the previous gap contents. */
1762 *(GPT_ADDR) = 0; 1752 *(GPT_ADDR) = 0;
1763 1753
1764 if (GPT_BYTE < GPT) 1754 eassert (GPT <= GPT_BYTE);
1765 abort ();
1766 1755
1767 if (GPT - BEG < BEG_UNCHANGED) 1756 if (GPT - BEG < BEG_UNCHANGED)
1768 BEG_UNCHANGED = GPT - BEG; 1757 BEG_UNCHANGED = GPT - BEG;
1769 if (Z - GPT < END_UNCHANGED) 1758 if (Z - GPT < END_UNCHANGED)
1770 END_UNCHANGED = Z - GPT; 1759 END_UNCHANGED = Z - GPT;
1771 1760
1772 CHECK_MARKERS (); 1761 check_markers ();
1773 1762
1774 evaporate_overlays (from); 1763 evaporate_overlays (from);
1775 1764
@@ -2201,9 +2190,6 @@ syms_of_insdel (void)
2201 combine_after_change_list = Qnil; 2190 combine_after_change_list = Qnil;
2202 combine_after_change_buffer = Qnil; 2191 combine_after_change_buffer = Qnil;
2203 2192
2204 DEFVAR_BOOL ("check-markers-debug-flag", check_markers_debug_flag,
2205 doc: /* Non-nil means enable debugging checks for invalid marker positions. */);
2206 check_markers_debug_flag = 0;
2207 DEFVAR_LISP ("combine-after-change-calls", Vcombine_after_change_calls, 2193 DEFVAR_LISP ("combine-after-change-calls", Vcombine_after_change_calls,
2208 doc: /* Used internally by the `combine-after-change-calls' macro. */); 2194 doc: /* Used internally by the `combine-after-change-calls' macro. */);
2209 Vcombine_after_change_calls = Qnil; 2195 Vcombine_after_change_calls = Qnil;
diff --git a/src/marker.c b/src/marker.c
index 0a93f4c180f..4ea06c7cd57 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -64,7 +64,7 @@ byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
64 64
65#else /* not MARKER_DEBUG */ 65#else /* not MARKER_DEBUG */
66 66
67#define byte_char_debug_check(b,charpos,bytepos) do { } while (0) 67#define byte_char_debug_check(b, charpos, bytepos) do { } while (0)
68 68
69#endif /* MARKER_DEBUG */ 69#endif /* MARKER_DEBUG */
70 70