diff src/search.c @ 10032:f689803caa92

Added code for automatically saving and restoring the match data when a filter or sentinel tries to modify it.
author Francesco Potortì <pot@gnu.org>
date Mon, 21 Nov 1994 12:50:27 +0000
parents c41ce96785a8
children cb713218845a
line wrap: on
line diff
--- a/src/search.c	Sun Nov 20 21:55:55 1994 +0000
+++ b/src/search.c	Mon Nov 21 12:50:27 1994 +0000
@@ -206,6 +206,9 @@
   register int i;
   struct re_pattern_buffer *bufp;
 
+  if (running_asynch_code)
+    save_search_regs ();
+
   CHECK_STRING (string, 0);
   bufp = compile_pattern (string, &search_regs,
 			  (!NILP (current_buffer->case_fold_search)
@@ -284,6 +287,9 @@
   int s;
   struct re_pattern_buffer *bufp;
 
+  if (running_asynch_code)
+    save_search_regs ();
+
   CHECK_STRING (regexp, 0);
   CHECK_STRING (string, 1);
 
@@ -928,6 +934,9 @@
   unsigned char *p1, *p2;
   int s1, s2;
 
+  if (running_asynch_code)
+    save_search_regs ();
+
   /* Null string is found at starting position.  */
   if (len == 0)
     {
@@ -1845,6 +1854,9 @@
   register int i;
   register Lisp_Object marker;
 
+  if (running_asynch_code)
+    save_search_regs ();
+
   if (!CONSP (list) && !NILP (list))
     list = wrong_type_argument (Qconsp, list);
 
@@ -1914,6 +1926,46 @@
   return Qnil;  
 }
 
+/* If non-zero the match data have been saved in saved_search_regs
+   during the execution of a sentinel or filter. */
+static int search_regs_saved = 0;
+static struct re_registers saved_search_regs;
+
+/* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
+   if asynchronous code (filter or sentinel) is running. */
+static void
+save_search_regs ()
+{
+  if (!search_regs_saved)
+    {
+      saved_search_regs.num_regs = search_regs.num_regs;
+      saved_search_regs.start = search_regs.start;
+      saved_search_regs.end = search_regs.end;
+      search_regs.num_regs = 0;
+
+      search_regs_saved = 1;
+    }
+}
+
+/* Called upon exit from filters and sentinels. */
+void
+restore_match_data ()
+{
+  if (search_regs_saved)
+    {
+      if (search_regs.num_regs > 0)
+	{
+	  xfree (search_regs.start);
+	  xfree (search_regs.end);
+	}
+      search_regs.num_regs = saved_search_regs.num_regs;
+      search_regs.start = saved_search_regs.start;
+      search_regs.end = saved_search_regs.end;
+
+      search_regs_saved = 0;
+    }
+}
+
 /* Quote a string to inactivate reg-expr chars */
 
 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,