diff src/search.c @ 90614:8dd8c8286063

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 460-475) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 145-152) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-118
author Miles Bader <miles@gnu.org>
date Sun, 15 Oct 2006 02:54:13 +0000
parents bb0e318b7c53 5f8a28d018b2
children dbe3f29e61d6
line wrap: on
line diff
--- a/src/search.c	Thu Oct 05 12:20:23 2006 +0000
+++ b/src/search.c	Sun Oct 15 02:54:13 2006 +0000
@@ -43,7 +43,8 @@
   struct regexp_cache *next;
   Lisp_Object regexp, whitespace_regexp;
   /* Syntax table for which the regexp applies.  We need this because
-     of character classes.  */
+     of character classes.  If this is t, then the compiled pattern is valid
+     for any syntax-table.  */
   Lisp_Object syntax_table;
   struct re_pattern_buffer buf;
   char fastmap[0400];
@@ -137,7 +138,6 @@
   cp->buf.multibyte = STRING_MULTIBYTE (pattern);
   cp->buf.target_multibyte = multibyte;
   cp->whitespace_regexp = Vsearch_spaces_regexp;
-  cp->syntax_table = current_buffer->syntax_table;
   /* rms: I think BLOCK_INPUT is not needed here any more,
      because regex.c defines malloc to call xmalloc.
      Using BLOCK_INPUT here means the debugger won't run if an error occurs.
@@ -151,6 +151,10 @@
   val = (char *) re_compile_pattern ((char *) SDATA (pattern),
 				     SBYTES (pattern), &cp->buf);
 
+  /* If the compiled pattern hard codes some of the contents of the
+     syntax-table, it can only be reused with *this* syntax table.  */
+  cp->syntax_table = cp->buf.used_syntax ? current_buffer->syntax_table : Qt;
+
   re_set_whitespace_regexp (NULL);
 
   re_set_syntax (old);
@@ -178,7 +182,8 @@
     }
 }
 
-/* Clear the regexp cache.
+/* Clear the regexp cache w.r.t. a particular syntax table,
+   because it was changed.
    There is no danger of memory leak here because re_compile_pattern
    automagically manages the memory in each re_pattern_buffer struct,
    based on its `allocated' and `buffer' values.  */
@@ -188,7 +193,11 @@
   int i;
 
   for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
-    searchbufs[i].regexp = Qnil;
+    /* It's tempting to compare with the syntax-table we've actually changd,
+       but it's not sufficient because char-table inheritance mewans that
+       modifying one syntax-table can change others at the same time.  */
+    if (!EQ (searchbufs[i].syntax_table, Qt))
+      searchbufs[i].regexp = Qnil;
 }
 
 /* Compile a regexp if necessary, but first check to see if there's one in
@@ -227,10 +236,8 @@
 	  && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
 	  && cp->posix == posix
 	  && cp->buf.target_multibyte == multibyte
-	  /* TODO: Strictly speaking, we only need to match syntax
-	     tables when a character class like [[:space:]] occurs in
-	     the pattern. -- cyd*/
-	  && EQ (cp->syntax_table, current_buffer->syntax_table)
+	  && (EQ (cp->syntax_table, Qt)
+	      || EQ (cp->syntax_table, current_buffer->syntax_table))
 	  && !NILP (Fequal (cp->whitespace_regexp, Vsearch_spaces_regexp)))
 	break;