aboutsummaryrefslogtreecommitdiffstats
path: root/src/marker.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-06 13:20:41 +0400
committerDmitry Antipov2012-07-06 13:20:41 +0400
commit90fc47863786e39b2000866592402a7af05f3dfb (patch)
treeeb9bd2cd6dbf1d0a4e51d6fa74f5a78a18b204dc /src/marker.c
parent4e57b342c5713d900b93ffde70cf7bb9150ca8fd (diff)
downloademacs-90fc47863786e39b2000866592402a7af05f3dfb.tar.gz
emacs-90fc47863786e39b2000866592402a7af05f3dfb.zip
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.
Diffstat (limited to 'src/marker.c')
-rw-r--r--src/marker.c87
1 files changed, 45 insertions, 42 deletions
diff --git a/src/marker.c b/src/marker.c
index 47a3e85e582..ac444fcec08 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -31,8 +31,36 @@ static ptrdiff_t cached_bytepos;
31static struct buffer *cached_buffer; 31static struct buffer *cached_buffer;
32static int cached_modiff; 32static int cached_modiff;
33 33
34static void byte_char_debug_check (struct buffer *, ptrdiff_t, ptrdiff_t); 34#ifdef ENABLE_CHECKING
35 35
36extern int count_markers (struct buffer *) EXTERNALLY_VISIBLE;
37
38static void
39byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
40{
41 ptrdiff_t nchars = 0;
42
43 if (bytepos > BUF_GPT_BYTE (b))
44 {
45 nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
46 BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b));
47 nchars += multibyte_chars_in_text (BUF_GAP_END_ADDR (b),
48 bytepos - BUF_GPT_BYTE (b));
49 }
50 else
51 nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
52 bytepos - BUF_BEG_BYTE (b));
53
54 if (charpos - 1 != nchars)
55 abort ();
56}
57
58#else /* not ENABLE_CHECKING */
59
60#define byte_char_debug_check(b,charpos,bytepos) do { } while (0)
61
62#endif /* ENABLE_CHECKING */
63
36void 64void
37clear_charpos_cache (struct buffer *b) 65clear_charpos_cache (struct buffer *b)
38{ 66{
@@ -61,8 +89,8 @@ clear_charpos_cache (struct buffer *b)
61 if (this_charpos == charpos) \ 89 if (this_charpos == charpos) \
62 { \ 90 { \
63 ptrdiff_t value = (BYTEPOS); \ 91 ptrdiff_t value = (BYTEPOS); \
64 if (byte_debug_flag) \ 92 \
65 byte_char_debug_check (b, charpos, value); \ 93 byte_char_debug_check (b, charpos, value); \
66 return value; \ 94 return value; \
67 } \ 95 } \
68 else if (this_charpos > charpos) \ 96 else if (this_charpos > charpos) \
@@ -86,33 +114,13 @@ clear_charpos_cache (struct buffer *b)
86 if (best_above - best_below == best_above_byte - best_below_byte) \ 114 if (best_above - best_below == best_above_byte - best_below_byte) \
87 { \ 115 { \
88 ptrdiff_t value = best_below_byte + (charpos - best_below); \ 116 ptrdiff_t value = best_below_byte + (charpos - best_below); \
89 if (byte_debug_flag) \ 117 \
90 byte_char_debug_check (b, charpos, value); \ 118 byte_char_debug_check (b, charpos, value); \
91 return value; \ 119 return value; \
92 } \ 120 } \
93 } \ 121 } \
94} 122}
95 123
96static void
97byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
98{
99 ptrdiff_t nchars = 0;
100
101 if (bytepos > BUF_GPT_BYTE (b))
102 {
103 nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
104 BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b));
105 nchars += multibyte_chars_in_text (BUF_GAP_END_ADDR (b),
106 bytepos - BUF_GPT_BYTE (b));
107 }
108 else
109 nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
110 bytepos - BUF_BEG_BYTE (b));
111
112 if (charpos - 1 != nchars)
113 abort ();
114}
115
116ptrdiff_t 124ptrdiff_t
117charpos_to_bytepos (ptrdiff_t charpos) 125charpos_to_bytepos (ptrdiff_t charpos)
118{ 126{
@@ -189,8 +197,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
189 if (record) 197 if (record)
190 build_marker (b, best_below, best_below_byte); 198 build_marker (b, best_below, best_below_byte);
191 199
192 if (byte_debug_flag) 200 byte_char_debug_check (b, charpos, best_below_byte);
193 byte_char_debug_check (b, charpos, best_below_byte);
194 201
195 cached_buffer = b; 202 cached_buffer = b;
196 cached_modiff = BUF_MODIFF (b); 203 cached_modiff = BUF_MODIFF (b);
@@ -215,8 +222,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
215 if (record) 222 if (record)
216 build_marker (b, best_above, best_above_byte); 223 build_marker (b, best_above, best_above_byte);
217 224
218 if (byte_debug_flag) 225 byte_char_debug_check (b, charpos, best_above_byte);
219 byte_char_debug_check (b, charpos, best_above_byte);
220 226
221 cached_buffer = b; 227 cached_buffer = b;
222 cached_modiff = BUF_MODIFF (b); 228 cached_modiff = BUF_MODIFF (b);
@@ -262,8 +268,8 @@ verify_bytepos (ptrdiff_t charpos)
262 if (this_bytepos == bytepos) \ 268 if (this_bytepos == bytepos) \
263 { \ 269 { \
264 ptrdiff_t value = (CHARPOS); \ 270 ptrdiff_t value = (CHARPOS); \
265 if (byte_debug_flag) \ 271 \
266 byte_char_debug_check (b, value, bytepos); \ 272 byte_char_debug_check (b, value, bytepos); \
267 return value; \ 273 return value; \
268 } \ 274 } \
269 else if (this_bytepos > bytepos) \ 275 else if (this_bytepos > bytepos) \
@@ -287,8 +293,8 @@ verify_bytepos (ptrdiff_t charpos)
287 if (best_above - best_below == best_above_byte - best_below_byte) \ 293 if (best_above - best_below == best_above_byte - best_below_byte) \
288 { \ 294 { \
289 ptrdiff_t value = best_below + (bytepos - best_below_byte); \ 295 ptrdiff_t value = best_below + (bytepos - best_below_byte); \
290 if (byte_debug_flag) \ 296 \
291 byte_char_debug_check (b, value, bytepos); \ 297 byte_char_debug_check (b, value, bytepos); \
292 return value; \ 298 return value; \
293 } \ 299 } \
294 } \ 300 } \
@@ -357,8 +363,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
357 if (record && BUF_MARKERS (b)) 363 if (record && BUF_MARKERS (b))
358 build_marker (b, best_below, best_below_byte); 364 build_marker (b, best_below, best_below_byte);
359 365
360 if (byte_debug_flag) 366 byte_char_debug_check (b, best_below, bytepos);
361 byte_char_debug_check (b, best_below, bytepos);
362 367
363 cached_buffer = b; 368 cached_buffer = b;
364 cached_modiff = BUF_MODIFF (b); 369 cached_modiff = BUF_MODIFF (b);
@@ -385,8 +390,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
385 if (record && BUF_MARKERS (b)) 390 if (record && BUF_MARKERS (b))
386 build_marker (b, best_above, best_above_byte); 391 build_marker (b, best_above, best_above_byte);
387 392
388 if (byte_debug_flag) 393 byte_char_debug_check (b, best_above, bytepos);
389 byte_char_debug_check (b, best_above, bytepos);
390 394
391 cached_buffer = b; 395 cached_buffer = b;
392 cached_modiff = BUF_MODIFF (b); 396 cached_modiff = BUF_MODIFF (b);
@@ -775,9 +779,10 @@ DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at,
775 return Qnil; 779 return Qnil;
776} 780}
777 781
782#ifdef ENABLE_CHECKING
783
778/* For debugging -- count the markers in buffer BUF. */ 784/* For debugging -- count the markers in buffer BUF. */
779 785
780extern int count_markers (struct buffer *) EXTERNALLY_VISIBLE;
781int 786int
782count_markers (struct buffer *buf) 787count_markers (struct buffer *buf)
783{ 788{
@@ -789,6 +794,8 @@ count_markers (struct buffer *buf)
789 794
790 return total; 795 return total;
791} 796}
797
798#endif /* ENABLE_CHECKING */
792 799
793void 800void
794syms_of_marker (void) 801syms_of_marker (void)
@@ -800,8 +807,4 @@ syms_of_marker (void)
800 defsubr (&Smarker_insertion_type); 807 defsubr (&Smarker_insertion_type);
801 defsubr (&Sset_marker_insertion_type); 808 defsubr (&Sset_marker_insertion_type);
802 defsubr (&Sbuffer_has_markers_at); 809 defsubr (&Sbuffer_has_markers_at);
803
804 DEFVAR_BOOL ("byte-debug-flag", byte_debug_flag,
805 doc: /* Non-nil enables debugging checks in byte/char position conversions. */);
806 byte_debug_flag = 0;
807} 810}