emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r108907: Compile marker debugging cod


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108907: Compile marker debugging code only if ENABLE_CHECKING is defined.
Date: Fri, 06 Jul 2012 13:20:41 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108907
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Fri 2012-07-06 13:20:41 +0400
message:
  Compile marker debugging code only if ENABLE_CHECKING is defined.
  * marker.c (byte_char_debug_check, count_markers): Use
  only if ENABLE_CHECKING is defined.
  (byte_debug_flag): Remove.
  (CONSIDER, buf_charpos_to_bytepos, buf_bytepos_to_charpos):
  Always call byte_char_debug_check if ENABLE_CHECKING is defined.
modified:
  src/ChangeLog
  src/marker.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-07-06 08:53:15 +0000
+++ b/src/ChangeLog     2012-07-06 09:20:41 +0000
@@ -1,5 +1,14 @@
 2012-07-06  Dmitry Antipov  <address@hidden>
 
+       Compile marker debugging code only if ENABLE_CHECKING is defined.
+       * marker.c (byte_char_debug_check, count_markers): Use
+       only if ENABLE_CHECKING is defined.
+       (byte_debug_flag): Remove.
+       (CONSIDER, buf_charpos_to_bytepos, buf_bytepos_to_charpos):
+       Always call byte_char_debug_check if ENABLE_CHECKING is defined.
+
+2012-07-06  Dmitry Antipov  <address@hidden>
+
        Avoid code repetition in marker-related functions.
        * marker.c (attach_marker): New function.
        (Fset_marker, set_marker_restricted, set_marker_both)

=== modified file 'src/marker.c'
--- a/src/marker.c      2012-07-06 08:53:15 +0000
+++ b/src/marker.c      2012-07-06 09:20:41 +0000
@@ -31,8 +31,36 @@
 static struct buffer *cached_buffer;
 static int cached_modiff;
 
-static void byte_char_debug_check (struct buffer *, ptrdiff_t, ptrdiff_t);
-
+#ifdef ENABLE_CHECKING
+
+extern int count_markers (struct buffer *) EXTERNALLY_VISIBLE;
+
+static void
+byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
+{
+  ptrdiff_t nchars = 0;
+
+  if (bytepos > BUF_GPT_BYTE (b))
+    {
+      nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
+                                       BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b));
+      nchars += multibyte_chars_in_text (BUF_GAP_END_ADDR (b),
+                                        bytepos - BUF_GPT_BYTE (b));
+    }
+  else
+    nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
+                                     bytepos - BUF_BEG_BYTE (b));
+
+  if (charpos - 1 != nchars)
+    abort ();
+}
+
+#else /* not ENABLE_CHECKING */
+
+#define byte_char_debug_check(b,charpos,bytepos) do { } while (0)
+
+#endif /* ENABLE_CHECKING */
+ 
 void
 clear_charpos_cache (struct buffer *b)
 {
@@ -61,8 +89,8 @@
   if (this_charpos == charpos)                                         \
     {                                                                  \
       ptrdiff_t value = (BYTEPOS);                                     \
-      if (byte_debug_flag)                                             \
-       byte_char_debug_check (b, charpos, value);                      \
+                                                                       \
+      byte_char_debug_check (b, charpos, value);                       \
       return value;                                                    \
     }                                                                  \
   else if (this_charpos > charpos)                                     \
@@ -86,33 +114,13 @@
       if (best_above - best_below == best_above_byte - best_below_byte)        
\
         {                                                              \
          ptrdiff_t value = best_below_byte + (charpos - best_below);   \
-         if (byte_debug_flag)                                          \
-           byte_char_debug_check (b, charpos, value);                  \
+                                                                       \
+         byte_char_debug_check (b, charpos, value);                    \
          return value;                                                 \
        }                                                               \
     }                                                                  \
 }
 
-static void
-byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
-{
-  ptrdiff_t nchars = 0;
-
-  if (bytepos > BUF_GPT_BYTE (b))
-    {
-      nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
-                                       BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b));
-      nchars += multibyte_chars_in_text (BUF_GAP_END_ADDR (b),
-                                        bytepos - BUF_GPT_BYTE (b));
-    }
-  else
-    nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
-                                     bytepos - BUF_BEG_BYTE (b));
-
-  if (charpos - 1 != nchars)
-    abort ();
-}
-
 ptrdiff_t
 charpos_to_bytepos (ptrdiff_t charpos)
 {
@@ -189,8 +197,7 @@
       if (record)
        build_marker (b, best_below, best_below_byte);
 
-      if (byte_debug_flag)
-       byte_char_debug_check (b, charpos, best_below_byte);
+      byte_char_debug_check (b, charpos, best_below_byte);
 
       cached_buffer = b;
       cached_modiff = BUF_MODIFF (b);
@@ -215,8 +222,7 @@
       if (record)
        build_marker (b, best_above, best_above_byte);
 
-      if (byte_debug_flag)
-       byte_char_debug_check (b, charpos, best_above_byte);
+      byte_char_debug_check (b, charpos, best_above_byte);
 
       cached_buffer = b;
       cached_modiff = BUF_MODIFF (b);
@@ -262,8 +268,8 @@
   if (this_bytepos == bytepos)                                         \
     {                                                                  \
       ptrdiff_t value = (CHARPOS);                                     \
-      if (byte_debug_flag)                                             \
-       byte_char_debug_check (b, value, bytepos);                      \
+                                                                       \
+      byte_char_debug_check (b, value, bytepos);                       \
       return value;                                                    \
     }                                                                  \
   else if (this_bytepos > bytepos)                                     \
@@ -287,8 +293,8 @@
       if (best_above - best_below == best_above_byte - best_below_byte)        
\
        {                                                               \
          ptrdiff_t value = best_below + (bytepos - best_below_byte);   \
-         if (byte_debug_flag)                                          \
-           byte_char_debug_check (b, value, bytepos);                  \
+                                                                       \
+         byte_char_debug_check (b, value, bytepos);                    \
          return value;                                                 \
        }                                                               \
     }                                                                  \
@@ -357,8 +363,7 @@
       if (record && BUF_MARKERS (b))
        build_marker (b, best_below, best_below_byte);
 
-      if (byte_debug_flag)
-       byte_char_debug_check (b, best_below, bytepos);
+      byte_char_debug_check (b, best_below, bytepos);
 
       cached_buffer = b;
       cached_modiff = BUF_MODIFF (b);
@@ -385,8 +390,7 @@
       if (record && BUF_MARKERS (b))
        build_marker (b, best_above, best_above_byte);
 
-      if (byte_debug_flag)
-       byte_char_debug_check (b, best_above, bytepos);
+      byte_char_debug_check (b, best_above, bytepos);
 
       cached_buffer = b;
       cached_modiff = BUF_MODIFF (b);
@@ -775,9 +779,10 @@
   return Qnil;
 }
 
+#ifdef ENABLE_CHECKING
+
 /* For debugging -- count the markers in buffer BUF.  */
 
-extern int count_markers (struct buffer *) EXTERNALLY_VISIBLE;
 int
 count_markers (struct buffer *buf)
 {
@@ -789,6 +794,8 @@
 
   return total;
 }
+
+#endif /* ENABLE_CHECKING */
 
 void
 syms_of_marker (void)
@@ -800,8 +807,4 @@
   defsubr (&Smarker_insertion_type);
   defsubr (&Sset_marker_insertion_type);
   defsubr (&Sbuffer_has_markers_at);
-
-  DEFVAR_BOOL ("byte-debug-flag", byte_debug_flag,
-              doc: /* Non-nil enables debugging checks in byte/char position 
conversions.  */);
-  byte_debug_flag = 0;
 }


reply via email to

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