Mercurial > hg > xemacs-beta
changeset 5543:fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
* * *
Refactor syntax cache initialization.
* * *
Refactor setup_syntax_cache.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Mon, 08 Aug 2011 13:57:20 +0900 |
parents | dab422055bab |
children | c2301b2c88c8 |
files | src/ChangeLog src/syntax.c tests/ChangeLog tests/automated/syntax-tests.el |
diffstat | 4 files changed, 65 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Mon Aug 08 13:57:20 2011 +0900 +++ b/src/ChangeLog Mon Aug 08 13:57:20 2011 +0900 @@ -1,3 +1,17 @@ +2011-08-06 Stephen J. Turnbull <stephen@xemacs.org> + + * syntax.c (reset_buffer_syntax_cache_range): + Rename to reset_syntax_cache_range. + + (setup_syntax_cache): + (init_buffer_syntax_cache): + (init_syntax_cache): + (reset_syntax_cache_range): + Refactor and document. + + (signal_syntax_cache_extent_changed): + Remove obsolete comment. + 2011-08-05 Stephen J. Turnbull <stephen@xemacs.org> There are only (octal) 0200 ASCII characters, and only 128 values
--- a/src/syntax.c Mon Aug 08 13:57:20 2011 +0900 +++ b/src/syntax.c Mon Aug 08 13:57:20 2011 +0900 @@ -284,56 +284,51 @@ } static void -reset_buffer_syntax_cache_range (struct syntax_cache *cache, - Lisp_Object buffer, int infinite) +reset_syntax_cache_range (struct syntax_cache *cache, /* initialized cache */ + Lisp_Object object) /* string or buffer */ { - Fset_marker (cache->start, make_int (1), buffer); - Fset_marker (cache->end, make_int (1), buffer); - Fset_marker_insertion_type (cache->start, Qt); - Fset_marker_insertion_type (cache->end, Qnil); - /* #### Should we "cache->no_syntax_table_prop = 1;" here? */ - /* #### Cf comment on INFINITE in init_syntax_cache. -- sjt */ - if (infinite) + /* reinitialize cache parameters */ + if (BUFFERP (object)) + { + /* make known region zero-length and reset insertion behavior */ + Fset_marker (cache->start, make_int (1), object); + Fset_marker (cache->end, make_int (1), object); + Fset_marker_insertion_type (cache->start, Qt); + Fset_marker_insertion_type (cache->end, Qnil); + } + else + { + /* invalidate the known region markers */ + Fset_marker (cache->start, Qnil, Qnil); + Fset_marker (cache->end, Qnil, Qnil); + } + cache->no_syntax_table_prop = 1; + if (lookup_syntax_properties) + { + cache->prev_change = -1; + cache->next_change = -1; + } + else { cache->prev_change = EMACS_INT_MIN; cache->next_change = EMACS_INT_MAX; } - else - { - cache->prev_change = -1; - cache->next_change = -1; - } } static void -init_syntax_cache (struct syntax_cache *cache, Lisp_Object object, - struct buffer *buffer, int infinite) +init_syntax_cache (struct syntax_cache *cache, /* cache must be zero'ed */ + Lisp_Object object, /* string or buffer */ + struct buffer *buffer) /* may not be NULL */ { - xzero (*cache); + /* initialize cache resources */ cache->object = object; cache->buffer = buffer; - cache->no_syntax_table_prop = 1; cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer); cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); - cache->start = Qnil; - cache->end = Qnil; - /* #### I'm not sure what INFINITE is for, but it's apparently needed by - setup_syntax_cache(). It looks like it's supposed to guarantee that - the test for POS outside of cache-valid range will never succeed, so - that update_syntax_cache won't get called, but it's hard to be sure. - Cf reset_buffer_syntax_cache_range. -- sjt */ - if (infinite) - { - cache->prev_change = EMACS_INT_MIN; - cache->next_change = EMACS_INT_MAX; - } - else - { - cache->prev_change = -1; - cache->next_change = -1; - } + cache->start = Fmake_marker(); + cache->end = Fmake_marker(); } /* external syntax cache API */ @@ -347,32 +342,23 @@ is associated with */ struct buffer *buffer, /* the buffer to use as source of the syntax table */ - Charxpos from, /* initial position of cache */ - int count) /* direction? see code */ + Charxpos UNUSED (from), /* initial position of cache */ + int UNUSED (count)) /* direction? see code */ { - /* If OBJECT is a buffer, use its cache. Initialize cache. Make it valid - for the whole buffer if the syntax-table property is not being respected. - Else if OBJECT is not a buffer, initialize the cache passed in CACHE. - If the syntax-table property is being respected, update the cache. */ + /* If OBJECT is a buffer, use its cache, otherwise use CACHE. + Initialize CACHE. Invalidate the cache if the syntax-table property is + being respected, otherwise make it valid for the whole object. */ if (BUFFERP (object)) { cache = XBUFFER (object)->syntax_cache; - if (!lookup_syntax_properties) - reset_buffer_syntax_cache_range (cache, object, 1); } else - init_syntax_cache (cache, object, buffer, 0); - if (lookup_syntax_properties) { - if (count <= 0) - { - from--; - from = buffer_or_string_clip_to_accessible_char (cache->object, - from); - } - if (!(from >= cache->prev_change && from < cache->next_change)) - update_syntax_cache (cache, from, count); + xzero (*cache); + init_syntax_cache (cache, object, buffer); } + reset_syntax_cache_range (cache, object); + #ifdef NOT_WORTH_THE_EFFORT update_mirror_syntax_if_dirty (cache->mirror_table); #endif /* NOT_WORTH_THE_EFFORT */ @@ -517,21 +503,14 @@ void init_buffer_syntax_cache (struct buffer *buf) { - struct syntax_cache *cache; #ifdef NEW_GC buf->syntax_cache = XSYNTAX_CACHE (ALLOC_NORMAL_LISP_OBJECT (syntax_cache)); #else /* not NEW_GC */ buf->syntax_cache = xnew_and_zero (struct syntax_cache); #endif /* not NEW_GC */ - cache = buf->syntax_cache; - cache->object = wrap_buffer (buf); - cache->buffer = buf; - cache->no_syntax_table_prop = 1; - cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer); - cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); - cache->start = Fmake_marker (); - cache->end = Fmake_marker (); - reset_buffer_syntax_cache_range (cache, cache->object, 0); + + init_syntax_cache (buf->syntax_cache, wrap_buffer(buf), buf); + reset_syntax_cache_range (buf->syntax_cache, wrap_buffer(buf)); } /* finalize the syntax cache for BUF */ @@ -561,12 +540,6 @@ Lisp_Object buffer = Fextent_object (wrap_extent (extent)); if (BUFFERP (buffer)) { - /* This was getting called with the buffer's start and end null, eg in - cperl mode, which triggers an assert in byte_marker_position. Cf - thread rooted at <yxz7j7xzk97.fsf@gimli.holgi.priv> on xemacs-beta. - <yxzfymklb6p.fsf@gimli.holgi.priv> has a recipe, but you also need - to delete or type SPC to get the crash. - #### Delete this comment when setup_syntax_cache is made sane. */ struct syntax_cache *cache = XBUFFER (buffer)->syntax_cache; /* #### would this be slower or less accurate in character terms? */ Bytexpos start = extent_endpoint_byte (extent, 0); @@ -576,7 +549,7 @@ /* If the extent is entirely before or entirely after the cache range, it doesn't overlap. Otherwise, invalidate the range. */ if (!(end < start2 || start > end2)) - reset_buffer_syntax_cache_range (cache, buffer, 0); + reset_syntax_cache_range (cache, buffer); } }
--- a/tests/ChangeLog Mon Aug 08 13:57:20 2011 +0900 +++ b/tests/ChangeLog Mon Aug 08 13:57:20 2011 +0900 @@ -1,3 +1,7 @@ +2011-08-06 Stephen J. Turnbull <stephen@xemacs.org> + + * automated/syntax-tests.el: Suggest test from old syntax-cache bug. + 2011-08-06 Stephen J. Turnbull <stephen@xemacs.org> * automated/os-tests.el:
--- a/tests/automated/syntax-tests.el Mon Aug 08 13:57:20 2011 +0900 +++ b/tests/automated/syntax-tests.el Mon Aug 08 13:57:20 2011 +0900 @@ -204,4 +204,8 @@ ;; special-case check that point didn't move (Assert (= (point) 25)))) +;; #### Add the recipe in <yxzfymklb6p.fsf@gimli.holgi.priv> on xemacs-beta. +;; You also need to do a DELETE or type SPC to get the crash in 21.5.24. +;http://list-archive.xemacs.org/pipermail/xemacs-beta/2006-February/008430.html + ;;; end of syntax-tests.el