diff options
author | Francesco Potortì <pot@gnu.org> | 1994-11-21 12:50:27 +0000 |
---|---|---|
committer | Francesco Potortì <pot@gnu.org> | 1994-11-21 12:50:27 +0000 |
commit | 7074fde6640c88db886be0fcc4182e3790936d7d (patch) | |
tree | ebcb295249beee68ca1d0f0274e190875c79931b /src/search.c | |
parent | 827342364655e5ac2ae80d9b34b8abb20c186a0f (diff) | |
download | emacs-7074fde6640c88db886be0fcc4182e3790936d7d.tar.gz |
Added code for automatically saving and restoring the match data
when a filter or sentinel tries to modify it.
Diffstat (limited to 'src/search.c')
-rw-r--r-- | src/search.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/search.c b/src/search.c index 622df821c70..2aa645047c6 100644 --- a/src/search.c +++ b/src/search.c @@ -206,6 +206,9 @@ looking_at_1 (string, posix) 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 @@ string_match_1 (regexp, string, start, posix) 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 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt, posix) 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 @@ LIST should have been created by calling `match-data' previously.") 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 @@ LIST should have been created by calling `match-data' previously.") 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, |