comparison src/search.c @ 2439:b6c62e4abf59

Put interrupt input blocking in a separate file from xterm.h. This isn't specific to X, and it allows us to avoid #including xterm.h in files that don't really have anything to do with X. * blockinput.h: New file. * xterm.h (BLOCK_INPUT, UNBLOCK_INPUT, TOTALLY_UNBLOCK_INPUT, UNBLOCK_INPUT_RESIGNAL): These are now in blockinput.h. (x_input_blocked, x_pending_input): Deleted; there are analogs in blockinput.h called interrupt_input_blocked and interrupt_input_pending. * keyboard.c (interrupt_input_blocked, interrupt_input_pending): New variables, used by the macros in blockinput.h. * xterm.c: #include blockinput.h. (x_input_blocked, x_pending_input): Deleted. (XTread_socket): Test and set interrupt_input_blocked and interrupt_input_pending instead of the old variables. * alloc.c, xfaces.c, xfns.c, xmenu.c, xselect.c, keymap.c: #include blockinput.h. * eval.c: #include blockinput.h instead of xterm.h. * keyboard.c: #include blockinput.h. (input_poll_signal): Just test interrupt_input_blocked, instead of testing HAVE_X_WINDOWS and x_input_blocked. Block the processing of interrupt input while we're manipulating the malloc heap. * alloc.c: (xfree): New function, to make it easy to free things safely. (xmalloc, xrealloc): Block X input while doing the deed. (VALIDATE_LISP_STORAGE, gc_sweep, compact_strings): Use xfree instead of free. (uninterrupt_malloc): New function, to install input-blocking hooks into the GNU malloc routines. * emacs.c [not SYSTEM_MALLOC] (main): Call uninterrupt_malloc on startup. * alloc.c: (make_interval, make_float, Fcons, Fmake_vector, Fmake_symbol, Fmake_marker, make_uninit_string, Fgarbage_collect): Use xmalloc instead of malloc; don't bother to check if out of memory here. (Fgarbage_collect): Call xrealloc instead of realloc. * buffer.c: Use xmalloc and xfree instead of malloc and free; don't bother to check if out of memory here. (Fget_buffer_create): Put BLOCK_INPUT/UNBLOCK_INPUT pair around calls to ralloc routines. * insdel.c: Same. * lisp.h (xfree): New extern declaration. * xfaces.c (xfree): Don't #define this to be free; use the definition in alloc.c. * dispnew.c, doc.c, doprnt.c, fileio.c, lread.c, term.c, xfns.c, xmenu.c, xterm.c: Use xfree instead of free. * hftctl.c: Use xfree and xmalloc instead of free and malloc. * keymap.c (current_minor_maps): BLOCK_INPUT while calling realloc and malloc. * search.c: Since the regexp routines can malloc, BLOCK_INPUT while runing them. #include blockinput.h. * sysdep.c: #include blockinput.h. Call xfree and xmalloc instead of free and malloc. BLOCK_INPUT around routines which we know will call malloc. ymakefile (keyboard.o, keymap.o, search.o, sysdep.o, xfaces.o, xfns.o, xmenu.o, xterm.o, xselect.o, alloc.o, eval.o): Note that these depend on blockinput.h.
author Jim Blandy <jimb@redhat.com>
date Wed, 31 Mar 1993 10:55:33 +0000
parents a35d2c5cbb3b
children 052bbdf1b817
comparison
equal deleted inserted replaced
2438:b513de4de386 2439:b6c62e4abf59
21 #include "config.h" 21 #include "config.h"
22 #include "lisp.h" 22 #include "lisp.h"
23 #include "syntax.h" 23 #include "syntax.h"
24 #include "buffer.h" 24 #include "buffer.h"
25 #include "commands.h" 25 #include "commands.h"
26 #include "blockinput.h"
26 27
27 #include <sys/types.h> 28 #include <sys/types.h>
28 #include "regex.h" 29 #include "regex.h"
29 30
30 #define max(a, b) ((a) > (b) ? (a) : (b)) 31 #define max(a, b) ((a) > (b) ? (a) : (b))
95 && translate == bufp->translate) 96 && translate == bufp->translate)
96 return; 97 return;
97 98
98 last_regexp = Qnil; 99 last_regexp = Qnil;
99 bufp->translate = translate; 100 bufp->translate = translate;
101 BLOCK_INPUT;
100 val = re_compile_pattern ((char *) XSTRING (pattern)->data, 102 val = re_compile_pattern ((char *) XSTRING (pattern)->data,
101 XSTRING (pattern)->size, 103 XSTRING (pattern)->size,
102 bufp); 104 bufp);
105 UNBLOCK_INPUT;
103 if (val) 106 if (val)
104 { 107 {
105 dummy = build_string (val); 108 dummy = build_string (val);
106 while (1) 109 while (1)
107 Fsignal (Qinvalid_regexp, Fcons (dummy, Qnil)); 110 Fsignal (Qinvalid_regexp, Fcons (dummy, Qnil));
109 112
110 last_regexp = pattern; 113 last_regexp = pattern;
111 114
112 /* Advise the searching functions about the space we have allocated 115 /* Advise the searching functions about the space we have allocated
113 for register data. */ 116 for register data. */
117 BLOCK_INPUT;
114 if (regp) 118 if (regp)
115 re_set_registers (bufp, regp, regp->num_regs, regp->start, regp->end); 119 re_set_registers (bufp, regp, regp->num_regs, regp->start, regp->end);
120 UNBLOCK_INPUT;
116 121
117 return; 122 return;
118 } 123 }
119 124
120 /* Error condition used for failing searches */ 125 /* Error condition used for failing searches */
165 { 170 {
166 s1 = ZV - BEGV; 171 s1 = ZV - BEGV;
167 s2 = 0; 172 s2 = 0;
168 } 173 }
169 174
175 BLOCK_INPUT;
170 i = re_match_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2, 176 i = re_match_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2,
171 point - BEGV, &search_regs, 177 point - BEGV, &search_regs,
172 ZV - BEGV); 178 ZV - BEGV);
179 UNBLOCK_INPUT;
173 if (i == -2) 180 if (i == -2)
174 matcher_overflow (); 181 matcher_overflow ();
175 182
176 val = (0 <= i ? Qt : Qnil); 183 val = (0 <= i ? Qt : Qnil);
177 for (i = 0; i < search_regs.num_regs; i++) 184 for (i = 0; i < search_regs.num_regs; i++)
215 } 222 }
216 223
217 compile_pattern (regexp, &searchbuf, &search_regs, 224 compile_pattern (regexp, &searchbuf, &search_regs,
218 !NILP (current_buffer->case_fold_search) ? DOWNCASE_TABLE : 0); 225 !NILP (current_buffer->case_fold_search) ? DOWNCASE_TABLE : 0);
219 immediate_quit = 1; 226 immediate_quit = 1;
227 BLOCK_INPUT;
220 val = re_search (&searchbuf, (char *) XSTRING (string)->data, 228 val = re_search (&searchbuf, (char *) XSTRING (string)->data,
221 XSTRING (string)->size, s, XSTRING (string)->size - s, 229 XSTRING (string)->size, s, XSTRING (string)->size - s,
222 &search_regs); 230 &search_regs);
231 UNBLOCK_INPUT;
223 immediate_quit = 0; 232 immediate_quit = 0;
224 last_thing_searched = Qt; 233 last_thing_searched = Qt;
225 if (val == -2) 234 if (val == -2)
226 matcher_overflow (); 235 matcher_overflow ();
227 if (val < 0) return Qnil; 236 if (val < 0) return Qnil;
238 { 247 {
239 int val; 248 int val;
240 249
241 compile_pattern (regexp, &searchbuf, 0, 0); 250 compile_pattern (regexp, &searchbuf, 0, 0);
242 immediate_quit = 1; 251 immediate_quit = 1;
252 BLOCK_INPUT;
243 val = re_search (&searchbuf, (char *) XSTRING (string)->data, 253 val = re_search (&searchbuf, (char *) XSTRING (string)->data,
244 XSTRING (string)->size, 0, XSTRING (string)->size, 254 XSTRING (string)->size, 0, XSTRING (string)->size,
245 0); 255 0);
256 UNBLOCK_INPUT;
246 immediate_quit = 0; 257 immediate_quit = 0;
247 return val; 258 return val;
248 } 259 }
249 260
250 /* Search for COUNT instances of the character TARGET, starting at START. 261 /* Search for COUNT instances of the character TARGET, starting at START.
657 s1 = ZV - BEGV; 668 s1 = ZV - BEGV;
658 s2 = 0; 669 s2 = 0;
659 } 670 }
660 while (n < 0) 671 while (n < 0)
661 { 672 {
673 BLOCK_INPUT;
662 int val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2, 674 int val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2,
663 pos - BEGV, lim - pos, &search_regs, 675 pos - BEGV, lim - pos, &search_regs,
664 /* Don't allow match past current point */ 676 /* Don't allow match past current point */
665 pos - BEGV); 677 pos - BEGV);
678 UNBLOCK_INPUT;
666 if (val == -2) 679 if (val == -2)
667 matcher_overflow (); 680 matcher_overflow ();
668 if (val >= 0) 681 if (val >= 0)
669 { 682 {
670 j = BEGV; 683 j = BEGV;
685 } 698 }
686 n++; 699 n++;
687 } 700 }
688 while (n > 0) 701 while (n > 0)
689 { 702 {
703 BLOCK_INPUT;
690 int val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2, 704 int val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2,
691 pos - BEGV, lim - pos, &search_regs, 705 pos - BEGV, lim - pos, &search_regs,
692 lim - BEGV); 706 lim - BEGV);
707 UNBLOCK_INPUT;
693 if (val == -2) 708 if (val == -2)
694 matcher_overflow (); 709 matcher_overflow ();
695 if (val >= 0) 710 if (val >= 0)
696 { 711 {
697 j = BEGV; 712 j = BEGV;
880 895
881 starts = 896 starts =
882 (regoff_t *) xmalloc (2 * sizeof (regoff_t)); 897 (regoff_t *) xmalloc (2 * sizeof (regoff_t));
883 ends = 898 ends =
884 (regoff_t *) xmalloc (2 * sizeof (regoff_t)); 899 (regoff_t *) xmalloc (2 * sizeof (regoff_t));
900 BLOCK_INPUT;
885 re_set_registers (&searchbuf, 901 re_set_registers (&searchbuf,
886 &search_regs, 902 &search_regs,
887 2, starts, ends); 903 2, starts, ends);
904 UNBLOCK_INPUT;
888 } 905 }
889 906
890 search_regs.start[0] 907 search_regs.start[0]
891 = pos + cursor - p2 + ((direction > 0) 908 = pos + cursor - p2 + ((direction > 0)
892 ? 1 - len : 0); 909 ? 1 - len : 0);
955 972
956 starts = 973 starts =
957 (regoff_t *) xmalloc (2 * sizeof (regoff_t)); 974 (regoff_t *) xmalloc (2 * sizeof (regoff_t));
958 ends = 975 ends =
959 (regoff_t *) xmalloc (2 * sizeof (regoff_t)); 976 (regoff_t *) xmalloc (2 * sizeof (regoff_t));
977 BLOCK_INPUT;
960 re_set_registers (&searchbuf, 978 re_set_registers (&searchbuf,
961 &search_regs, 979 &search_regs,
962 2, starts, ends); 980 2, starts, ends);
981 UNBLOCK_INPUT;
963 } 982 }
964 983
965 search_regs.start[0] 984 search_regs.start[0]
966 = pos + ((direction > 0) ? 1 - len : 0); 985 = pos + ((direction > 0) ? 1 - len : 0);
967 search_regs.end[0] = len + search_regs.start[0]; 986 search_regs.end[0] = len + search_regs.start[0];
1388 search_regs.end 1407 search_regs.end
1389 = (regoff_t *) xrealloc (search_regs.end, 1408 = (regoff_t *) xrealloc (search_regs.end,
1390 length * sizeof (regoff_t)); 1409 length * sizeof (regoff_t));
1391 } 1410 }
1392 1411
1412 BLOCK_INPUT;
1393 re_set_registers (&searchbuf, &search_regs, length, 1413 re_set_registers (&searchbuf, &search_regs, length,
1394 search_regs.start, search_regs.end); 1414 search_regs.start, search_regs.end);
1415 UNBLOCK_INPUT;
1395 } 1416 }
1396 } 1417 }
1397 1418
1398 for (i = 0; i < search_regs.num_regs; i++) 1419 for (i = 0; i < search_regs.num_regs; i++)
1399 { 1420 {