]> git.eshelyaron.com Git - emacs.git/commitdiff
Generalize marker debugging code under MARKER_DEBUG and use eassert.
authorDmitry Antipov <dmantipov@yandex.ru>
Sun, 29 Jul 2012 11:20:43 +0000 (15:20 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Sun, 29 Jul 2012 11:20:43 +0000 (15:20 +0400)
* 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.

src/ChangeLog
src/insdel.c
src/marker.c

index 21ba05adf6d025d114b2536dcf960e2162a58624..4b811b79a9b94693ddabd310d31629bf153a52f1 100644 (file)
@@ -1,3 +1,12 @@
+2012-07-29  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       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.
+
 2012-07-29  Paul Eggert  <eggert@cs.ucla.edu>
 
        Don't use the abbreviation "win" to refer to Windows (Bug#10421).
index 2074916cfdeb7774128df90c28bbae1ed258a301..9646507bc4bca7adaeea23c0b99ae200ec8bb0ee 100644 (file)
@@ -59,14 +59,10 @@ static Lisp_Object combine_after_change_buffer;
 Lisp_Object Qinhibit_modification_hooks;
 
 static void signal_before_change (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
-\f
-#define CHECK_MARKERS()                                \
-  do                                           \
-    {                                          \
-      if (check_markers_debug_flag)            \
-       check_markers ();                       \
-    }                                          \
-  while (0)
+
+/* Also used in marker.c to enable expensive marker checks.  */
+
+#ifdef MARKER_DEBUG
 
 static void
 check_markers (void)
@@ -86,7 +82,13 @@ check_markers (void)
        abort ();
     }
 }
-\f
+
+#else /* not MARKER_DEBUG */
+
+#define check_markers() do { } while (0)
+
+#endif /* MARKER_DEBUG */
+
 /* Move gap to position CHARPOS.
    Note that this can quit!  */
 
@@ -158,8 +160,7 @@ gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap)
      was specified or may be where a quit was detected.  */
   GPT_BYTE = bytepos;
   GPT = charpos;
-  if (bytepos < charpos)
-    abort ();
+  eassert (charpos <= bytepos);
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   QUIT;
 }
@@ -209,8 +210,7 @@ gap_right (ptrdiff_t charpos, ptrdiff_t bytepos)
 
   GPT = charpos;
   GPT_BYTE = bytepos;
-  if (bytepos < charpos)
-    abort ();
+  eassert (charpos <= bytepos);
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   QUIT;
 }
@@ -233,9 +233,7 @@ adjust_markers_for_delete (ptrdiff_t from, ptrdiff_t from_byte,
   for (m = BUF_MARKERS (current_buffer); m; m = m->next)
     {
       charpos = m->charpos;
-
-      if (charpos > Z)
-       abort ();
+      eassert (charpos <= Z);
 
       /* If the marker is after the deletion,
         relocate by number of chars / bytes deleted.  */
@@ -375,7 +373,7 @@ adjust_markers_for_replace (ptrdiff_t from, ptrdiff_t from_byte,
        }
     }
 
-  CHECK_MARKERS ();
+  check_markers ();
 }
 
 \f
@@ -835,8 +833,7 @@ insert_1_both (const char *string,
   Z_BYTE += nbytes;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   /* The insert may have been in the unchanged region, so check again. */
   if (Z - GPT < END_UNCHANGED)
@@ -856,7 +853,7 @@ insert_1_both (const char *string,
 
   adjust_point (nchars, nbytes);
 
-  CHECK_MARKERS ();
+  check_markers ();
 }
 \f
 /* 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,
   Z_BYTE += outgoing_nbytes;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   /* The insert may have been in the unchanged region, so check again. */
   if (Z - GPT < END_UNCHANGED)
@@ -991,7 +987,7 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
 
   adjust_point (nchars, outgoing_nbytes);
 
-  CHECK_MARKERS ();
+  check_markers ();
 }
 \f
 /* Insert a sequence of NCHARS chars which occupy NBYTES bytes
@@ -1015,8 +1011,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
   Z_BYTE += nbytes;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   adjust_overlays_for_insert (GPT - nchars, nchars);
   adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes,
@@ -1032,7 +1027,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
   if (GPT - nchars < PT)
     adjust_point (nchars, nbytes);
 
-  CHECK_MARKERS ();
+  check_markers ();
 }
 \f
 /* Insert text from BUF, NCHARS characters starting at CHARPOS, into the
@@ -1151,8 +1146,7 @@ insert_from_buffer_1 (struct buffer *buf,
   Z_BYTE += outgoing_nbytes;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   /* The insert may have been in the unchanged region, so check again. */
   if (Z - GPT < END_UNCHANGED)
@@ -1243,7 +1237,7 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
   if (Z - GPT < END_UNCHANGED)
     END_UNCHANGED = Z - GPT;
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   if (len == 0)
     evaporate_overlays (from);
@@ -1296,7 +1290,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
   ptrdiff_t outgoing_insbytes = insbytes;
   Lisp_Object deletion;
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   GCPRO1 (new);
   deletion = Qnil;
@@ -1357,8 +1351,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
   GPT_BYTE = from_byte;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   if (GPT - BEG < BEG_UNCHANGED)
     BEG_UNCHANGED = GPT - BEG;
@@ -1404,8 +1397,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
   Z_BYTE += outgoing_insbytes;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   /* Adjust the overlay center as needed.  This must be done after
      adjusting the markers that bound the overlays.  */
@@ -1435,7 +1427,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
   if (outgoing_insbytes == 0)
     evaporate_overlays (from);
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   MODIFF++;
   CHARS_MODIFF = MODIFF;
@@ -1465,7 +1457,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
 {
   ptrdiff_t nbytes_del, nchars_del;
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   nchars_del = to - from;
   nbytes_del = to_byte - from_byte;
@@ -1488,8 +1480,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
   GPT_BYTE = from_byte;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   if (GPT - BEG < BEG_UNCHANGED)
     BEG_UNCHANGED = GPT - BEG;
@@ -1522,8 +1513,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
   Z_BYTE += insbytes;
   if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   /* Adjust the overlay center as needed.  This must be done after
      adjusting the markers that bound the overlays.  */
@@ -1554,7 +1544,7 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
   if (insbytes == 0)
     evaporate_overlays (from);
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   MODIFF++;
   CHARS_MODIFF = MODIFF;
@@ -1705,7 +1695,7 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
   register ptrdiff_t nbytes_del, nchars_del;
   Lisp_Object deletion;
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   nchars_del = to - from;
   nbytes_del = to_byte - from_byte;
@@ -1761,15 +1751,14 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
        needs to access the previous gap contents.  */
     *(GPT_ADDR) = 0;
 
-  if (GPT_BYTE < GPT)
-    abort ();
+  eassert (GPT <= GPT_BYTE);
 
   if (GPT - BEG < BEG_UNCHANGED)
     BEG_UNCHANGED = GPT - BEG;
   if (Z - GPT < END_UNCHANGED)
     END_UNCHANGED = Z - GPT;
 
-  CHECK_MARKERS ();
+  check_markers ();
 
   evaporate_overlays (from);
 
@@ -2201,9 +2190,6 @@ syms_of_insdel (void)
   combine_after_change_list = Qnil;
   combine_after_change_buffer = Qnil;
 
-  DEFVAR_BOOL ("check-markers-debug-flag", check_markers_debug_flag,
-              doc: /* Non-nil means enable debugging checks for invalid marker positions.  */);
-  check_markers_debug_flag = 0;
   DEFVAR_LISP ("combine-after-change-calls", Vcombine_after_change_calls,
               doc: /* Used internally by the `combine-after-change-calls' macro.  */);
   Vcombine_after_change_calls = Qnil;
index 0a93f4c180fb4e145075de8418551ad1d0384249..4ea06c7cd570403f6c3024620a4b474563aa4488 100644 (file)
@@ -64,7 +64,7 @@ byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
 
 #else /* not MARKER_DEBUG */
 
-#define byte_char_debug_check(b,charpos,bytepos) do { } while (0)
+#define byte_char_debug_check(b, charpos, bytepos) do { } while (0)
 
 #endif /* MARKER_DEBUG */