aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrancesco Potortì1994-11-21 12:50:27 +0000
committerFrancesco Potortì1994-11-21 12:50:27 +0000
commit7074fde6640c88db886be0fcc4182e3790936d7d (patch)
treeebcb295249beee68ca1d0f0274e190875c79931b /src
parent827342364655e5ac2ae80d9b34b8abb20c186a0f (diff)
downloademacs-7074fde6640c88db886be0fcc4182e3790936d7d.tar.gz
emacs-7074fde6640c88db886be0fcc4182e3790936d7d.zip
Added code for automatically saving and restoring the match data
when a filter or sentinel tries to modify it.
Diffstat (limited to 'src')
-rw-r--r--src/emacs.c5
-rw-r--r--src/lisp.h3
-rw-r--r--src/process.c9
-rw-r--r--src/search.c52
4 files changed, 68 insertions, 1 deletions
diff --git a/src/emacs.c b/src/emacs.c
index bfc83b87087..ae13412fc80 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -98,6 +98,10 @@ int inhibit_window_system;
98 priority; Those functions have their own extern declaration. */ 98 priority; Those functions have their own extern declaration. */
99int emacs_priority; 99int emacs_priority;
100 100
101/* If non-zero a filter or a sentinel is running. Tested to save the match
102 data on the first attempt to change it inside asynchronous code. */
103int running_asynch_code;
104
101#ifdef BSD_PGRPS 105#ifdef BSD_PGRPS
102/* See sysdep.c. */ 106/* See sysdep.c. */
103extern int inherited_pgroup; 107extern int inherited_pgroup;
@@ -697,6 +701,7 @@ Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\
697 init_alloc (); 701 init_alloc ();
698 init_eval (); 702 init_eval ();
699 init_data (); 703 init_data ();
704 running_asynch_code = 0;
700 705
701#ifdef MSDOS 706#ifdef MSDOS
702 /* Call early 'cause init_environment needs it. */ 707 /* Call early 'cause init_environment needs it. */
diff --git a/src/lisp.h b/src/lisp.h
index 1b773b2fa65..f946da5e5f4 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1404,6 +1404,7 @@ extern Lisp_Object Vfundamental_mode_abbrev_table;
1404/* defined in search.c */ 1404/* defined in search.c */
1405extern Lisp_Object Fstring_match (); 1405extern Lisp_Object Fstring_match ();
1406extern Lisp_Object Fscan_buffer (); 1406extern Lisp_Object Fscan_buffer ();
1407extern void restore_match_data ();
1407 1408
1408/* defined in minibuf.c */ 1409/* defined in minibuf.c */
1409 1410
@@ -1499,6 +1500,8 @@ void shut_down_emacs ( /* int signal, int no_x, Lisp_Object stuff */ );
1499extern int noninteractive; 1500extern int noninteractive;
1500/* Nonzero means don't do use window-system-specific display code */ 1501/* Nonzero means don't do use window-system-specific display code */
1501extern int inhibit_window_system; 1502extern int inhibit_window_system;
1503/* Nonzero means that a filter or a sentinel is running. */
1504extern int running_asynch_code;
1502 1505
1503/* defined in process.c */ 1506/* defined in process.c */
1504extern Lisp_Object Fget_process (), Fget_buffer_process (), Fprocessp (); 1507extern Lisp_Object Fget_process (), Fget_buffer_process (), Fprocessp ();
diff --git a/src/process.c b/src/process.c
index db4b31ad57c..526f46f0db2 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2350,13 +2350,17 @@ read_process_output (proc, channel)
2350 specbind (Qinhibit_quit, Qt); 2350 specbind (Qinhibit_quit, Qt);
2351 specbind (Qlast_nonmenu_event, Qt); 2351 specbind (Qlast_nonmenu_event, Qt);
2352 2352
2353 running_asynch_code = 1;
2353 internal_condition_case_1 (read_process_output_call, 2354 internal_condition_case_1 (read_process_output_call,
2354 Fcons (outstream, 2355 Fcons (outstream,
2355 Fcons (proc, 2356 Fcons (proc,
2356 Fcons (make_string (chars, nchars), 2357 Fcons (make_string (chars,
2358 nchars),
2357 Qnil))), 2359 Qnil))),
2358 !NILP (Vdebug_on_error) ? Qnil : Qerror, 2360 !NILP (Vdebug_on_error) ? Qnil : Qerror,
2359 read_process_output_error_handler); 2361 read_process_output_error_handler);
2362 running_asynch_code = 0;
2363 restore_match_data ();
2360 2364
2361 /* Handling the process output should not deactivate the mark. */ 2365 /* Handling the process output should not deactivate the mark. */
2362 Vdeactivate_mark = odeactivate; 2366 Vdeactivate_mark = odeactivate;
@@ -3233,11 +3237,14 @@ exec_sentinel (proc, reason)
3233 specbind (Qinhibit_quit, Qt); 3237 specbind (Qinhibit_quit, Qt);
3234 specbind (Qlast_nonmenu_event, Qt); 3238 specbind (Qlast_nonmenu_event, Qt);
3235 3239
3240 running_asynch_code = 1;
3236 internal_condition_case_1 (read_process_output_call, 3241 internal_condition_case_1 (read_process_output_call,
3237 Fcons (sentinel, 3242 Fcons (sentinel,
3238 Fcons (proc, Fcons (reason, Qnil))), 3243 Fcons (proc, Fcons (reason, Qnil))),
3239 !NILP (Vdebug_on_error) ? Qnil : Qerror, 3244 !NILP (Vdebug_on_error) ? Qnil : Qerror,
3240 exec_sentinel_error_handler); 3245 exec_sentinel_error_handler);
3246 running_asynch_code = 0;
3247 restore_match_data ();
3241 3248
3242 Vdeactivate_mark = odeactivate; 3249 Vdeactivate_mark = odeactivate;
3243 if (! EQ (Fcurrent_buffer (), obuffer)) 3250 if (! EQ (Fcurrent_buffer (), obuffer))
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)
206 register int i; 206 register int i;
207 struct re_pattern_buffer *bufp; 207 struct re_pattern_buffer *bufp;
208 208
209 if (running_asynch_code)
210 save_search_regs ();
211
209 CHECK_STRING (string, 0); 212 CHECK_STRING (string, 0);
210 bufp = compile_pattern (string, &search_regs, 213 bufp = compile_pattern (string, &search_regs,
211 (!NILP (current_buffer->case_fold_search) 214 (!NILP (current_buffer->case_fold_search)
@@ -284,6 +287,9 @@ string_match_1 (regexp, string, start, posix)
284 int s; 287 int s;
285 struct re_pattern_buffer *bufp; 288 struct re_pattern_buffer *bufp;
286 289
290 if (running_asynch_code)
291 save_search_regs ();
292
287 CHECK_STRING (regexp, 0); 293 CHECK_STRING (regexp, 0);
288 CHECK_STRING (string, 1); 294 CHECK_STRING (string, 1);
289 295
@@ -928,6 +934,9 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt, posix)
928 unsigned char *p1, *p2; 934 unsigned char *p1, *p2;
929 int s1, s2; 935 int s1, s2;
930 936
937 if (running_asynch_code)
938 save_search_regs ();
939
931 /* Null string is found at starting position. */ 940 /* Null string is found at starting position. */
932 if (len == 0) 941 if (len == 0)
933 { 942 {
@@ -1845,6 +1854,9 @@ LIST should have been created by calling `match-data' previously.")
1845 register int i; 1854 register int i;
1846 register Lisp_Object marker; 1855 register Lisp_Object marker;
1847 1856
1857 if (running_asynch_code)
1858 save_search_regs ();
1859
1848 if (!CONSP (list) && !NILP (list)) 1860 if (!CONSP (list) && !NILP (list))
1849 list = wrong_type_argument (Qconsp, list); 1861 list = wrong_type_argument (Qconsp, list);
1850 1862
@@ -1914,6 +1926,46 @@ LIST should have been created by calling `match-data' previously.")
1914 return Qnil; 1926 return Qnil;
1915} 1927}
1916 1928
1929/* If non-zero the match data have been saved in saved_search_regs
1930 during the execution of a sentinel or filter. */
1931static int search_regs_saved = 0;
1932static struct re_registers saved_search_regs;
1933
1934/* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
1935 if asynchronous code (filter or sentinel) is running. */
1936static void
1937save_search_regs ()
1938{
1939 if (!search_regs_saved)
1940 {
1941 saved_search_regs.num_regs = search_regs.num_regs;
1942 saved_search_regs.start = search_regs.start;
1943 saved_search_regs.end = search_regs.end;
1944 search_regs.num_regs = 0;
1945
1946 search_regs_saved = 1;
1947 }
1948}
1949
1950/* Called upon exit from filters and sentinels. */
1951void
1952restore_match_data ()
1953{
1954 if (search_regs_saved)
1955 {
1956 if (search_regs.num_regs > 0)
1957 {
1958 xfree (search_regs.start);
1959 xfree (search_regs.end);
1960 }
1961 search_regs.num_regs = saved_search_regs.num_regs;
1962 search_regs.start = saved_search_regs.start;
1963 search_regs.end = saved_search_regs.end;
1964
1965 search_regs_saved = 0;
1966 }
1967}
1968
1917/* Quote a string to inactivate reg-expr chars */ 1969/* Quote a string to inactivate reg-expr chars */
1918 1970
1919DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, 1971DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,