changeset 3250:2b8bb4938bb4

[xemacs-hg @ 2006-02-21 11:33:41 by stephent] Commit syntax-cache fixes. <87oe11ne10.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Tue, 21 Feb 2006 11:33:46 +0000
parents 7a5e3aea74e3
children 4ae19a15d5b0
files src/ChangeLog src/extents.c src/insdel.c src/lisp.h src/syntax.c src/syntax.h
diffstat 6 files changed, 92 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Feb 20 22:51:12 2006 +0000
+++ b/src/ChangeLog	Tue Feb 21 11:33:46 2006 +0000
@@ -1,3 +1,34 @@
+2006-02-19  Stephen J. Turnbull  <stephen@xemacs.org>
+
+	Fix crash (cf. Holger Schauer <yxz7j7xzk97.fsf@gimli.holgi.priv>).
+	Improve nomenclature (some identifiers were misnamed with
+	"syntax_table" although they are purely related to syntax cache).
+	Add lots of comments explaining logic and use of arguments.
+
+	* syntax.c (setup_syntax_cache):  Fix broken logic that
+	initialized prev_change and next_change members to Qnil for syntax
+	caches associated with buffers, triggering an assertion because
+	the update functions expect those members to markers.
+
+	* syntax.c (signal_syntax_cache_extent_changed):
+	* syntax.c (reset_buffer_syntax_cache_range):
+	Rename reset_buffer_cache_range to reset_buffer_syntax_cache_range.
+
+	* lisp.h (signal_syntax_cache_extent_changed):
+	* syntax.c (signal_syntax_cache_extent_changed)
+	* syntax.c (update_syntax_cache):
+	* extents.c (signal_single_extent_changed):
+	Rename signal_syntax_table_extent_changed to
+	signal_syntax_cache_extent_changed.
+
+	* lisp.h (signal_syntax_cache_extent_adjust):
+	* syntax.c (signal_syntax_cache_extent_adjust):
+	* insdel.c (buffer_delete_range, buffer_insert_string_1):
+	Rename signal_syntax_table_extent_adjust to
+	signal_syntax_cache_extent_adjust.
+
+	* syntax.h (update_syntax_cache): Fix typo in comment.
+
 2006-02-16  Marcus Crestani  <crestani@xemacs.org>
 
 	* xgccache.c (gc_cache_lookup): Remove "Cache full" warning.
--- a/src/extents.c	Mon Feb 20 22:51:12 2006 +0000
+++ b/src/extents.c	Tue Feb 21 11:33:46 2006 +0000
@@ -1922,7 +1922,7 @@
   if (NILP (property) ? !NILP (Fextent_property (wrap_extent (extent),
 						 Qsyntax_table, Qnil)) :
       EQ (property, Qsyntax_table))
-    signal_syntax_table_extent_changed (extent);
+    signal_syntax_cache_extent_changed (extent);
 }
 
 /* Make note that a change has happened in EXTENT.  The change was either
--- a/src/insdel.c	Mon Feb 20 22:51:12 2006 +0000
+++ b/src/insdel.c	Tue Feb 21 11:33:46 2006 +0000
@@ -1265,7 +1265,7 @@
 
   MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
     {
-      signal_syntax_table_extent_adjust (mbuf);
+      signal_syntax_cache_extent_adjust (mbuf);
     }
 
   signal_after_change (buf, pos, pos, pos + cclen);
@@ -1546,7 +1546,7 @@
 
   MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
     {
-      signal_syntax_table_extent_adjust (mbuf);
+      signal_syntax_cache_extent_adjust (mbuf);
     }
 
   /* &&#### Here we consider converting the buffer from default to
--- a/src/lisp.h	Mon Feb 20 22:51:12 2006 +0000
+++ b/src/lisp.h	Tue Feb 21 11:33:46 2006 +0000
@@ -5279,8 +5279,8 @@
 EXFUN (Fchar_syntax, 2);
 EXFUN (Fforward_word, 2);
 extern Lisp_Object Vstandard_syntax_table;
-void signal_syntax_table_extent_changed (EXTENT extent);
-void signal_syntax_table_extent_adjust (struct buffer *buf);
+void signal_syntax_cache_extent_changed (EXTENT extent);
+void signal_syntax_cache_extent_adjust (struct buffer *buf);
 void init_buffer_syntax_cache (struct buffer *buf);
 void mark_buffer_syntax_cache (struct buffer *buf);
 void uninit_buffer_syntax_cache (struct buffer *buf);
--- a/src/syntax.c	Mon Feb 20 22:51:12 2006 +0000
+++ b/src/syntax.c	Tue Feb 21 11:33:46 2006 +0000
@@ -254,6 +254,11 @@
     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;
@@ -266,15 +271,29 @@
     }
 }
 
-struct syntax_cache *
-setup_syntax_cache (struct syntax_cache *cache, Lisp_Object object,
-		    struct buffer *buffer, Charxpos from, int count)
+/* #### This function and associated logic still needs work, and especially
+   documentation. */
+struct syntax_cache *		/* return CACHE or the cache of OBJECT */
+setup_syntax_cache (struct syntax_cache *cache,	/* syntax cache, may be NULL
+						   if OBJECT is a buffer */
+		    Lisp_Object object,	 	/* the object (if any) cache
+						   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 */
 {
+  /* 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 (BUFFERP (object))
-    cache = XBUFFER (object)->syntax_cache;
-  if (!lookup_syntax_properties)
-    init_syntax_cache (cache, object, buffer, 1);
-  else 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)
     {
@@ -339,14 +358,25 @@
 }
 
 static void
-reset_buffer_cache_range (struct syntax_cache *cache, Lisp_Object buffer)
+reset_buffer_syntax_cache_range (struct syntax_cache *cache,
+				 Lisp_Object buffer, int infinite)
 {
   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);
-  cache->prev_change = -1;
-  cache->next_change = -1;
+  /* #### Should we "cache->no_syntax_table_prop = 1;" here? */
+  /* #### Cf comment on INFINITE in init_syntax_cache. -- sjt */
+  if (infinite)
+    {
+      cache->prev_change = EMACS_INT_MIN;
+      cache->next_change = EMACS_INT_MAX;
+    }
+  else
+    {
+      cache->prev_change = -1;
+      cache->next_change = -1;
+    }
 }
 
 void
@@ -367,9 +397,10 @@
   cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
   cache->start = Fmake_marker ();
   cache->end = Fmake_marker ();
-  reset_buffer_cache_range (cache, cache->object);
+  reset_buffer_syntax_cache_range (cache, cache->object, 0);
 }
 
+/* finalize the syntax cache for BUF */
 void
 uninit_buffer_syntax_cache (struct buffer *buf)
 {
@@ -401,27 +432,34 @@
    the value of EXTENT's syntax-table property is changing. */
 
 void
-signal_syntax_table_extent_changed (EXTENT extent)
+signal_syntax_cache_extent_changed (EXTENT extent)
 {
   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);
       Bytexpos end = extent_endpoint_byte (extent, 1);
       Bytexpos start2 = byte_marker_position (cache->start);
       Bytexpos end2 = byte_marker_position (cache->end);
-      /* If the extent is entirely before or entirely after the cache range,
-	 it doesn't overlap.  Otherwise, invalidate the range. */
+      /* 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_cache_range (cache, buffer);
+	reset_buffer_syntax_cache_range (cache, buffer, 0);
     }
 }
 
 /* Extents have been adjusted for insertion or deletion, so we need to
    refetch the start and end position of the extent */
 void
-signal_syntax_table_extent_adjust (struct buffer *buf)
+signal_syntax_cache_extent_adjust (struct buffer *buf)
 {
   struct syntax_cache *cache = buf->syntax_cache;
   /* If the cache was invalid before, leave it that way.  We only want
@@ -499,7 +537,7 @@
 	 a zero-length `syntax-table' extent there (highly unlikely); if not,
 	 then we can safely make the end closed, so it will take in newly
 	 inserted text. (If such an extent is inserted, we will be informed
-	 through signal_syntax_table_extent_changed().) */
+	 through signal_syntax_cache_extent_changed().) */
       Fset_marker (cache->start, make_int (cache->prev_change), cache->object);
       Fset_marker_insertion_type
 	(cache->start,
--- a/src/syntax.h	Mon Feb 20 22:51:12 2006 +0000
+++ b/src/syntax.h	Tue Feb 21 11:33:46 2006 +0000
@@ -354,7 +354,7 @@
 extern const struct sized_memory_description syntax_cache_description;
 
 /* Note that the external interface to the syntax-cache uses charpos's, but
-   intnernally we use bytepos's, for speed. */
+   internally we use bytepos's, for speed. */
 
 void update_syntax_cache (struct syntax_cache *cache, Charxpos pos, int count);
 struct syntax_cache *setup_syntax_cache (struct syntax_cache *cache,