aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1993-03-31 10:55:33 +0000
committerJim Blandy1993-03-31 10:55:33 +0000
commit9ac0d9e04198806161ea21e49b0be04e5253fa57 (patch)
tree66bd402e5ebbb6f362446a2baee28245cd953c8f /src
parent357f32fcd0e00337a3c1359a4919e716ed81fe52 (diff)
downloademacs-9ac0d9e04198806161ea21e49b0be04e5253fa57.tar.gz
emacs-9ac0d9e04198806161ea21e49b0be04e5253fa57.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c131
-rw-r--r--src/blockinput.h2
-rw-r--r--src/buffer.c12
-rw-r--r--src/dispnew.c24
-rw-r--r--src/doc.c2
-rw-r--r--src/doprnt.c2
-rw-r--r--src/emacs.c9
-rw-r--r--src/eval.c4
-rw-r--r--src/fileio.c6
-rw-r--r--src/hftctl.c6
-rw-r--r--src/insdel.c3
-rw-r--r--src/keyboard.c20
-rw-r--r--src/keymap.c5
-rw-r--r--src/lisp.h1
-rw-r--r--src/lread.c2
-rw-r--r--src/search.c21
-rw-r--r--src/sysdep.c18
-rw-r--r--src/term.c8
-rw-r--r--src/xfns.c5
-rw-r--r--src/xmenu.c23
-rw-r--r--src/xselect.c1
-rw-r--r--src/xterm.c23
-rw-r--r--src/xterm.h29
23 files changed, 224 insertions, 133 deletions
diff --git a/src/alloc.c b/src/alloc.c
index bf4d1898cda..46941e58181 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26#include "buffer.h" 26#include "buffer.h"
27#include "window.h" 27#include "window.h"
28#include "frame.h" 28#include "frame.h"
29#include "blockinput.h"
29#endif 30#endif
30 31
31#include "syssignal.h" 32#include "syssignal.h"
@@ -43,7 +44,7 @@ do \
43 XSET (val, Lisp_Cons, (char *) address + size); \ 44 XSET (val, Lisp_Cons, (char *) address + size); \
44 if ((char *) XCONS (val) != (char *) address + size) \ 45 if ((char *) XCONS (val) != (char *) address + size) \
45 { \ 46 { \
46 free (address); \ 47 xfree (address); \
47 memory_full (); \ 48 memory_full (); \
48 } \ 49 } \
49 } while (0) 50 } while (0)
@@ -149,7 +150,7 @@ memory_full ()
149 error ("Memory exhausted"); 150 error ("Memory exhausted");
150} 151}
151 152
152/* like malloc and realloc but check for no memory left */ 153/* like malloc routines but check for no memory and block interrupt input. */
153 154
154long * 155long *
155xmalloc (size) 156xmalloc (size)
@@ -157,7 +158,9 @@ xmalloc (size)
157{ 158{
158 register long *val; 159 register long *val;
159 160
161 BLOCK_INPUT;
160 val = (long *) malloc (size); 162 val = (long *) malloc (size);
163 UNBLOCK_INPUT;
161 164
162 if (!val && size) memory_full (); 165 if (!val && size) memory_full ();
163 return val; 166 return val;
@@ -170,16 +173,99 @@ xrealloc (block, size)
170{ 173{
171 register long *val; 174 register long *val;
172 175
176 BLOCK_INPUT;
173 /* We must call malloc explicitly when BLOCK is 0, since some 177 /* We must call malloc explicitly when BLOCK is 0, since some
174 reallocs don't do this. */ 178 reallocs don't do this. */
175 if (! block) 179 if (! block)
176 val = (long *) malloc (size); 180 val = (long *) malloc (size);
177 else 181 else
178 val = (long *) realloc (block, size); 182 val = (long *) realloc (block, size);
183 UNBLOCK_INPUT;
179 184
180 if (!val && size) memory_full (); 185 if (!val && size) memory_full ();
181 return val; 186 return val;
182} 187}
188
189void
190xfree (block)
191 long *block;
192{
193 BLOCK_INPUT;
194 free (block);
195 UNBLOCK_INPUT;
196}
197
198
199/* Arranging to disable input signals while we're in malloc.
200
201 This only works with GNU malloc. To help out systems which can't
202 use GNU malloc, all the calls to malloc, realloc, and free
203 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT
204 pairs; unfortunately, we have no idea what C library functions
205 might call malloc, so we can't really protect them unless you're
206 using GNU malloc. Fortunately, most of the major operating can use
207 GNU malloc. */
208
209#ifndef SYSTEM_MALLOC
210static void (*__malloc_hook) (), (*old_malloc_hook) ();
211static void (*__realloc_hook) (), (*old_realloc_hook) ();
212static void (*__free_hook) (), (*old_free_hook) ();
213
214static void
215emacs_blocked_free (ptr)
216 void *ptr;
217{
218 BLOCK_INPUT;
219 __free_hook = old_free_hook;
220 free (ptr);
221 __free_hook = &emacs_blocked_free;
222 UNBLOCK_INPUT;
223}
224
225static void *
226emacs_blocked_malloc (size)
227 unsigned size;
228{
229 void *value;
230
231 BLOCK_INPUT;
232 __malloc_hook = old_malloc_hook;
233 value = malloc (size);
234 __malloc_hook = &emacs_blocked_malloc;
235 UNBLOCK_INPUT;
236
237 return value;
238}
239
240static void *
241emacs_blocked_realloc (ptr, size)
242 void *ptr;
243 unsigned size;
244{
245 void *value;
246
247 BLOCK_INPUT;
248 __realloc_hook = old_realloc_hook;
249 value = realloc (ptr, size);
250 __realloc_hook = &emacs_blocked_realloc;
251 UNBLOCK_INPUT;
252
253 return value;
254}
255
256void
257uninterrupt_malloc ()
258{
259 old_free_hook = __free_hook;
260 __free_hook = &emacs_blocked_free;
261
262 old_malloc_hook = __malloc_hook;
263 __malloc_hook = &emacs_blocked_malloc;
264
265 old_realloc_hook = __realloc_hook;
266 __realloc_hook = &emacs_blocked_realloc;
267}
268#endif
183 269
184/* Interval allocation. */ 270/* Interval allocation. */
185 271
@@ -226,10 +312,7 @@ make_interval ()
226 if (interval_block_index == INTERVAL_BLOCK_SIZE) 312 if (interval_block_index == INTERVAL_BLOCK_SIZE)
227 { 313 {
228 register struct interval_block *newi 314 register struct interval_block *newi
229 = (struct interval_block *) malloc (sizeof (struct interval_block)); 315 = (struct interval_block *) xmalloc (sizeof (struct interval_block));
230
231 if (!newi)
232 memory_full ();
233 316
234 VALIDATE_LISP_STORAGE (newi, sizeof *newi); 317 VALIDATE_LISP_STORAGE (newi, sizeof *newi);
235 newi->next = interval_block; 318 newi->next = interval_block;
@@ -352,8 +435,7 @@ make_float (float_value)
352 { 435 {
353 if (float_block_index == FLOAT_BLOCK_SIZE) 436 if (float_block_index == FLOAT_BLOCK_SIZE)
354 { 437 {
355 register struct float_block *new = (struct float_block *) malloc (sizeof (struct float_block)); 438 register struct float_block *new = (struct float_block *) xmalloc (sizeof (struct float_block));
356 if (!new) memory_full ();
357 VALIDATE_LISP_STORAGE (new, sizeof *new); 439 VALIDATE_LISP_STORAGE (new, sizeof *new);
358 new->next = float_block; 440 new->next = float_block;
359 float_block = new; 441 float_block = new;
@@ -427,8 +509,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
427 { 509 {
428 if (cons_block_index == CONS_BLOCK_SIZE) 510 if (cons_block_index == CONS_BLOCK_SIZE)
429 { 511 {
430 register struct cons_block *new = (struct cons_block *) malloc (sizeof (struct cons_block)); 512 register struct cons_block *new = (struct cons_block *) xmalloc (sizeof (struct cons_block));
431 if (!new) memory_full ();
432 VALIDATE_LISP_STORAGE (new, sizeof *new); 513 VALIDATE_LISP_STORAGE (new, sizeof *new);
433 new->next = cons_block; 514 new->next = cons_block;
434 cons_block = new; 515 cons_block = new;
@@ -498,9 +579,7 @@ See also the function `vector'.")
498 length = wrong_type_argument (Qnatnump, length); 579 length = wrong_type_argument (Qnatnump, length);
499 sizei = XINT (length); 580 sizei = XINT (length);
500 581
501 p = (struct Lisp_Vector *) malloc (sizeof (struct Lisp_Vector) + (sizei - 1) * sizeof (Lisp_Object)); 582 p = (struct Lisp_Vector *) xmalloc (sizeof (struct Lisp_Vector) + (sizei - 1) * sizeof (Lisp_Object));
502 if (p == 0)
503 memory_full ();
504 VALIDATE_LISP_STORAGE (p, 0); 583 VALIDATE_LISP_STORAGE (p, 0);
505 584
506 XSET (vector, Lisp_Vector, p); 585 XSET (vector, Lisp_Vector, p);
@@ -617,8 +696,7 @@ Its value and function definition are void, and its property list is nil.")
617 { 696 {
618 if (symbol_block_index == SYMBOL_BLOCK_SIZE) 697 if (symbol_block_index == SYMBOL_BLOCK_SIZE)
619 { 698 {
620 struct symbol_block *new = (struct symbol_block *) malloc (sizeof (struct symbol_block)); 699 struct symbol_block *new = (struct symbol_block *) xmalloc (sizeof (struct symbol_block));
621 if (!new) memory_full ();
622 VALIDATE_LISP_STORAGE (new, sizeof *new); 700 VALIDATE_LISP_STORAGE (new, sizeof *new);
623 new->next = symbol_block; 701 new->next = symbol_block;
624 symbol_block = new; 702 symbol_block = new;
@@ -680,8 +758,7 @@ DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0,
680 { 758 {
681 if (marker_block_index == MARKER_BLOCK_SIZE) 759 if (marker_block_index == MARKER_BLOCK_SIZE)
682 { 760 {
683 struct marker_block *new = (struct marker_block *) malloc (sizeof (struct marker_block)); 761 struct marker_block *new = (struct marker_block *) xmalloc (sizeof (struct marker_block));
684 if (!new) memory_full ();
685 VALIDATE_LISP_STORAGE (new, sizeof *new); 762 VALIDATE_LISP_STORAGE (new, sizeof *new);
686 new->next = marker_block; 763 new->next = marker_block;
687 marker_block = new; 764 marker_block = new;
@@ -830,9 +907,8 @@ make_uninit_string (length)
830 /* This string gets its own string block */ 907 /* This string gets its own string block */
831 { 908 {
832 register struct string_block *new 909 register struct string_block *new
833 = (struct string_block *) malloc (sizeof (struct string_block_head) + fullsize); 910 = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize);
834 VALIDATE_LISP_STORAGE (new, 0); 911 VALIDATE_LISP_STORAGE (new, 0);
835 if (!new) memory_full ();
836 consing_since_gc += sizeof (struct string_block_head) + fullsize; 912 consing_since_gc += sizeof (struct string_block_head) + fullsize;
837 new->pos = fullsize; 913 new->pos = fullsize;
838 new->next = large_string_blocks; 914 new->next = large_string_blocks;
@@ -844,8 +920,7 @@ make_uninit_string (length)
844 /* Make a new current string block and start it off with this string */ 920 /* Make a new current string block and start it off with this string */
845 { 921 {
846 register struct string_block *new 922 register struct string_block *new
847 = (struct string_block *) malloc (sizeof (struct string_block)); 923 = (struct string_block *) xmalloc (sizeof (struct string_block));
848 if (!new) memory_full ();
849 VALIDATE_LISP_STORAGE (new, sizeof *new); 924 VALIDATE_LISP_STORAGE (new, sizeof *new);
850 consing_since_gc += sizeof (struct string_block); 925 consing_since_gc += sizeof (struct string_block);
851 current_string_block->next = new; 926 current_string_block->next = new;
@@ -1149,9 +1224,9 @@ Garbage collection happens automatically if you cons more than\n\
1149 if (i < MAX_SAVE_STACK) 1224 if (i < MAX_SAVE_STACK)
1150 { 1225 {
1151 if (stack_copy == 0) 1226 if (stack_copy == 0)
1152 stack_copy = (char *) malloc (stack_copy_size = i); 1227 stack_copy = (char *) xmalloc (stack_copy_size = i);
1153 else if (stack_copy_size < i) 1228 else if (stack_copy_size < i)
1154 stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i)); 1229 stack_copy = (char *) xrealloc (stack_copy, (stack_copy_size = i));
1155 if (stack_copy) 1230 if (stack_copy)
1156 { 1231 {
1157 if ((int) (&stack_top_variable - stack_bottom) > 0) 1232 if ((int) (&stack_top_variable - stack_bottom) > 0)
@@ -1804,7 +1879,7 @@ gc_sweep ()
1804 else 1879 else
1805 all_buffers = buffer->next; 1880 all_buffers = buffer->next;
1806 next = buffer->next; 1881 next = buffer->next;
1807 free (buffer); 1882 xfree (buffer);
1808 buffer = next; 1883 buffer = next;
1809 } 1884 }
1810 else 1885 else
@@ -1845,7 +1920,7 @@ gc_sweep ()
1845 else 1920 else
1846 all_vectors = vector->next; 1921 all_vectors = vector->next;
1847 next = vector->next; 1922 next = vector->next;
1848 free (vector); 1923 xfree (vector);
1849 vector = next; 1924 vector = next;
1850 } 1925 }
1851 else 1926 else
@@ -1868,7 +1943,7 @@ gc_sweep ()
1868 else 1943 else
1869 large_string_blocks = sb->next; 1944 large_string_blocks = sb->next;
1870 next = sb->next; 1945 next = sb->next;
1871 free (sb); 1946 xfree (sb);
1872 sb = next; 1947 sb = next;
1873 } 1948 }
1874 else 1949 else
@@ -1983,7 +2058,7 @@ compact_strings ()
1983 while (from_sb) 2058 while (from_sb)
1984 { 2059 {
1985 to_sb = from_sb->next; 2060 to_sb = from_sb->next;
1986 free (from_sb); 2061 xfree (from_sb);
1987 from_sb = to_sb; 2062 from_sb = to_sb;
1988 } 2063 }
1989 2064
@@ -1998,7 +2073,7 @@ compact_strings ()
1998 { 2073 {
1999 if (from_sb->next = to_sb->next) 2074 if (from_sb->next = to_sb->next)
2000 from_sb->next->prev = from_sb; 2075 from_sb->next->prev = from_sb;
2001 free (to_sb); 2076 xfree (to_sb);
2002 } 2077 }
2003 else 2078 else
2004 from_sb = to_sb; 2079 from_sb = to_sb;
diff --git a/src/blockinput.h b/src/blockinput.h
index c4c4979bcf4..f02cb5ce85e 100644
--- a/src/blockinput.h
+++ b/src/blockinput.h
@@ -1,4 +1,4 @@
1/* Interface to blocking complicated interrupt-driven input. 1/* blockinput.h - interface to blocking complicated interrupt-driven input.
2 Copyright (C) 1989, 1993 Free Software Foundation, Inc. 2 Copyright (C) 1989, 1993 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
diff --git a/src/buffer.c b/src/buffer.c
index edf04aa2e64..ddfab45d148 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -197,12 +197,12 @@ The value is never nil.")
197 if (!NILP (buf)) 197 if (!NILP (buf))
198 return buf; 198 return buf;
199 199
200 b = (struct buffer *) malloc (sizeof (struct buffer)); 200 b = (struct buffer *) xmalloc (sizeof (struct buffer));
201 if (!b)
202 memory_full ();
203 201
204 BUF_GAP_SIZE (b) = 20; 202 BUF_GAP_SIZE (b) = 20;
203 BLOCK_INPUT;
205 BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b)); 204 BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b));
205 UNBLOCK_INPUT;
206 if (! BUF_BEG_ADDR (b)) 206 if (! BUF_BEG_ADDR (b))
207 memory_full (); 207 memory_full ();
208 208
@@ -750,7 +750,9 @@ with `delete-process'.")
750 /* Perhaps we should explicitly free the interval tree here... */ 750 /* Perhaps we should explicitly free the interval tree here... */
751 751
752 b->name = Qnil; 752 b->name = Qnil;
753 BLOCK_INPUT;
753 BUFFER_FREE (BUF_BEG_ADDR (b)); 754 BUFFER_FREE (BUF_BEG_ADDR (b));
755 UNBLOCK_INPUT;
754 b->undo_list = Qnil; 756 b->undo_list = Qnil;
755 757
756 return Qt; 758 return Qt;
@@ -1513,7 +1515,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
1513 /* Make a list of them all. */ 1515 /* Make a list of them all. */
1514 result = Flist (noverlays, overlay_vec); 1516 result = Flist (noverlays, overlay_vec);
1515 1517
1516 free (overlay_vec); 1518 xfree (overlay_vec);
1517 return result; 1519 return result;
1518} 1520}
1519 1521
@@ -1553,7 +1555,7 @@ DEFUN ("next-overlay-change", Fnext_overlay_change, Snext_overlay_change,
1553 endpos = oendpos; 1555 endpos = oendpos;
1554 } 1556 }
1555 1557
1556 free (overlay_vec); 1558 xfree (overlay_vec);
1557 return make_number (endpos); 1559 return make_number (endpos);
1558} 1560}
1559 1561
diff --git a/src/dispnew.c b/src/dispnew.c
index a7a1fa5c800..b1f15f2ee8e 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -285,26 +285,26 @@ free_frame_glyphs (frame, glyphs)
285 struct frame_glyphs *glyphs; 285 struct frame_glyphs *glyphs;
286{ 286{
287 if (glyphs->total_contents) 287 if (glyphs->total_contents)
288 free (glyphs->total_contents); 288 xfree (glyphs->total_contents);
289 289
290 free (glyphs->used); 290 xfree (glyphs->used);
291 free (glyphs->glyphs); 291 xfree (glyphs->glyphs);
292 free (glyphs->highlight); 292 xfree (glyphs->highlight);
293 free (glyphs->enable); 293 xfree (glyphs->enable);
294 free (glyphs->bufp); 294 xfree (glyphs->bufp);
295 295
296#ifdef HAVE_X_WINDOWS 296#ifdef HAVE_X_WINDOWS
297 if (FRAME_X_P (frame)) 297 if (FRAME_X_P (frame))
298 { 298 {
299 free (glyphs->top_left_x); 299 xfree (glyphs->top_left_x);
300 free (glyphs->top_left_y); 300 xfree (glyphs->top_left_y);
301 free (glyphs->pix_width); 301 xfree (glyphs->pix_width);
302 free (glyphs->pix_height); 302 xfree (glyphs->pix_height);
303 free (glyphs->max_ascent); 303 xfree (glyphs->max_ascent);
304 } 304 }
305#endif 305#endif
306 306
307 free (glyphs); 307 xfree (glyphs);
308} 308}
309 309
310static void 310static void
diff --git a/src/doc.c b/src/doc.c
index 13c261bb495..fc8c996efb3 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -512,7 +512,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
512 tem = make_string (buf, bufp - buf); 512 tem = make_string (buf, bufp - buf);
513 else 513 else
514 tem = str; 514 tem = str;
515 free (buf); 515 xfree (buf);
516 RETURN_UNGCPRO (tem); 516 RETURN_UNGCPRO (tem);
517} 517}
518 518
diff --git a/src/doprnt.c b/src/doprnt.c
index 02584554577..2fe45cf7975 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -178,7 +178,7 @@ doprnt (buffer, bufsize, format, format_end, nargs, args)
178 178
179 /* If we had to malloc something, free it. */ 179 /* If we had to malloc something, free it. */
180 if (big_buffer) 180 if (big_buffer)
181 free (big_buffer); 181 xfree (big_buffer);
182 182
183 *bufptr = 0; /* Make sure our string end with a '\0' */ 183 *bufptr = 0; /* Make sure our string end with a '\0' */
184 return bufptr - buffer; 184 return bufptr - buffer;
diff --git a/src/emacs.c b/src/emacs.c
index ac4f391681a..8143498a104 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -311,7 +311,14 @@ main (argc, argv, envp)
311 311
312#ifndef SYSTEM_MALLOC 312#ifndef SYSTEM_MALLOC
313 if (! initialized) 313 if (! initialized)
314 memory_warnings (0, malloc_warning); 314 {
315 /* Arrange to get warning messages as memory fills up. */
316 memory_warnings (0, malloc_warning);
317
318 /* Arrange to disable interrupt input while malloc and friends are
319 running. */
320 uninterrupt_malloc ();
321 }
315#endif /* not SYSTEM_MALLOC */ 322#endif /* not SYSTEM_MALLOC */
316 323
317#ifdef PRIO_PROCESS 324#ifdef PRIO_PROCESS
diff --git a/src/eval.c b/src/eval.c
index 7726aadcb31..e1f56c0c3d0 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -20,9 +20,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 20
21#include "config.h" 21#include "config.h"
22#include "lisp.h" 22#include "lisp.h"
23#ifdef HAVE_X_WINDOWS 23#include "blockinput.h"
24#include "xterm.h"
25#endif
26 24
27#ifndef standalone 25#ifndef standalone
28#include "commands.h" 26#include "commands.h"
diff --git a/src/fileio.c b/src/fileio.c
index f9943927ca2..05cc4677b64 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2046,16 +2046,16 @@ Otherwise returns NIL.")
2046 valsize = readlink (XSTRING (filename)->data, buf, bufsize); 2046 valsize = readlink (XSTRING (filename)->data, buf, bufsize);
2047 if (valsize < bufsize) break; 2047 if (valsize < bufsize) break;
2048 /* Buffer was not long enough */ 2048 /* Buffer was not long enough */
2049 free (buf); 2049 xfree (buf);
2050 bufsize *= 2; 2050 bufsize *= 2;
2051 } 2051 }
2052 if (valsize == -1) 2052 if (valsize == -1)
2053 { 2053 {
2054 free (buf); 2054 xfree (buf);
2055 return Qnil; 2055 return Qnil;
2056 } 2056 }
2057 val = make_string (buf, valsize); 2057 val = make_string (buf, valsize);
2058 free (buf); 2058 xfree (buf);
2059 return val; 2059 return val;
2060#else /* not S_IFLNK */ 2060#else /* not S_IFLNK */
2061 return Qnil; 2061 return Qnil;
diff --git a/src/hftctl.c b/src/hftctl.c
index 6ba1e2fb7fd..1b460500b0c 100644
--- a/src/hftctl.c
+++ b/src/hftctl.c
@@ -79,7 +79,7 @@ typedef int (*FUNC)(); /* pointer to a function */
79 79
80static int hfqry(); 80static int hfqry();
81static int hfskbd(); 81static int hfskbd();
82 char *malloc(); 82 char *xmalloc();
83 83
84extern int errno; 84extern int errno;
85static jmp_buf hftenv; 85static jmp_buf hftenv;
@@ -319,7 +319,7 @@ WR_REQ (fd, request, cmdlen, cmd, resplen)
319 if (cmdlen) /* if arg structure to pass */ 319 if (cmdlen) /* if arg structure to pass */
320 { 320 {
321 size = sizeof (struct hfctlreq) + cmdlen; 321 size = sizeof (struct hfctlreq) + cmdlen;
322 if ((p.c = malloc(size)) == NULL) /* malloc one area */ 322 if ((p.c = xmalloc(size)) == NULL) /* malloc one area */
323 return (-1); 323 return (-1);
324 324
325 memcpy (p.c, &req, sizeof (req)); /* copy CTL REQ struct */ 325 memcpy (p.c, &req, sizeof (req)); /* copy CTL REQ struct */
@@ -334,7 +334,7 @@ WR_REQ (fd, request, cmdlen, cmd, resplen)
334 /* write request to terminal */ 334 /* write request to terminal */
335 if (write(fd,p.c,size) == -1) return (-1); 335 if (write(fd,p.c,size) == -1) return (-1);
336 if (p.req != &req) /* free if allocated */ 336 if (p.req != &req) /* free if allocated */
337 free (p.c); 337 xfree (p.c);
338 return (0); 338 return (0);
339 339
340} 340}
diff --git a/src/insdel.c b/src/insdel.c
index bfbf76861f2..647c4beb3a4 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -245,7 +245,10 @@ make_gap (increment)
245 /* If we have to get more space, get enough to last a while. */ 245 /* If we have to get more space, get enough to last a while. */
246 increment += 2000; 246 increment += 2000;
247 247
248 BLOCK_INPUT;
248 result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment)); 249 result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment));
250 UNBLOCK_INPUT;
251
249 if (result == 0) 252 if (result == 0)
250 memory_full (); 253 memory_full ();
251 BEG_ADDR = result; 254 BEG_ADDR = result;
diff --git a/src/keyboard.c b/src/keyboard.c
index 91e4ee1f477..30b78f8e0b1 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -36,6 +36,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
36#include "dispextern.h" 36#include "dispextern.h"
37#include "keyboard.h" 37#include "keyboard.h"
38#include "intervals.h" 38#include "intervals.h"
39#include "blockinput.h"
39#include <setjmp.h> 40#include <setjmp.h>
40#include <errno.h> 41#include <errno.h>
41 42
@@ -49,6 +50,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
49 50
50extern int errno; 51extern int errno;
51 52
53/* Variables for blockinput.h: */
54
55/* Non-zero if interrupt input is blocked right now. */
56extern int interrupt_input_blocked;
57
58/* Nonzero means an input interrupt has arrived
59 during the current critical section. */
60extern int interrupt_input_pending;
61
62
52#ifdef HAVE_X_WINDOWS 63#ifdef HAVE_X_WINDOWS
53extern Lisp_Object Vmouse_grabbed; 64extern Lisp_Object Vmouse_grabbed;
54 65
@@ -1158,12 +1169,9 @@ int polling_for_input;
1158SIGTYPE 1169SIGTYPE
1159input_poll_signal () 1170input_poll_signal ()
1160{ 1171{
1161#ifdef HAVE_X_WINDOWS 1172 if (interrupt_input_blocked == 0
1162 extern int x_input_blocked; 1173 && !waiting_for_input)
1163 if (x_input_blocked == 0) 1174 read_avail_input (0);
1164#endif
1165 if (!waiting_for_input)
1166 read_avail_input (0);
1167 signal (SIGALRM, input_poll_signal); 1175 signal (SIGALRM, input_poll_signal);
1168 alarm (polling_period); 1176 alarm (polling_period);
1169} 1177}
diff --git a/src/keymap.c b/src/keymap.c
index 62861bd72cb..b2eb948be92 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26#include "buffer.h" 26#include "buffer.h"
27#include "keyboard.h" 27#include "keyboard.h"
28#include "termhooks.h" 28#include "termhooks.h"
29#include "blockinput.h"
29 30
30#define min(a, b) ((a) < (b) ? (a) : (b)) 31#define min(a, b) ((a) < (b) ? (a) : (b))
31 32
@@ -707,13 +708,17 @@ current_minor_maps (modeptr, mapptr)
707 708
708 if (cmm_maps) 709 if (cmm_maps)
709 { 710 {
711 BLOCK_INPUT;
710 newmodes = (Lisp_Object *) realloc (cmm_modes, cmm_size *= 2); 712 newmodes = (Lisp_Object *) realloc (cmm_modes, cmm_size *= 2);
711 newmaps = (Lisp_Object *) realloc (cmm_maps, cmm_size); 713 newmaps = (Lisp_Object *) realloc (cmm_maps, cmm_size);
714 UNBLOCK_INPUT;
712 } 715 }
713 else 716 else
714 { 717 {
718 BLOCK_INPUT;
715 newmodes = (Lisp_Object *) malloc (cmm_size = 30); 719 newmodes = (Lisp_Object *) malloc (cmm_size = 30);
716 newmaps = (Lisp_Object *) malloc (cmm_size); 720 newmaps = (Lisp_Object *) malloc (cmm_size);
721 UNBLOCK_INPUT;
717 } 722 }
718 723
719 if (newmaps && newmodes) 724 if (newmaps && newmodes)
diff --git a/src/lisp.h b/src/lisp.h
index 2d62363e413..4e2b86e57ec 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1244,5 +1244,6 @@ extern void debugger ();
1244 1244
1245extern char *malloc (), *realloc (), *getenv (), *ctime (), *getwd (); 1245extern char *malloc (), *realloc (), *getenv (), *ctime (), *getwd ();
1246extern long *xmalloc (), *xrealloc (); 1246extern long *xmalloc (), *xrealloc ();
1247extern void xfree ();
1247 1248
1248extern char *egetenv (); 1249extern char *egetenv ();
diff --git a/src/lread.c b/src/lread.c
index 62e702e8abb..5769fba3644 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -417,7 +417,7 @@ load_unwind (stream) /* used as unwind-protect function in load */
417 Lisp_Object stream; 417 Lisp_Object stream;
418{ 418{
419 fclose (*(FILE **) XSTRING (stream)); 419 fclose (*(FILE **) XSTRING (stream));
420 free (XPNTR (stream)); 420 xfree (XPNTR (stream));
421 if (--load_in_progress < 0) load_in_progress = 0; 421 if (--load_in_progress < 0) load_in_progress = 0;
422 return Qnil; 422 return Qnil;
423} 423}
diff --git a/src/search.c b/src/search.c
index 03ed61fcd0d..fdf19fe656e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -23,6 +23,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
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"
@@ -97,9 +98,11 @@ compile_pattern (pattern, bufp, regp, translate)
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);
@@ -111,8 +114,10 @@ compile_pattern (pattern, bufp, regp, translate)
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}
@@ -167,9 +172,11 @@ data if you want to preserve them.")
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
@@ -217,9 +224,11 @@ matched by parenthesis constructs in the pattern.")
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)
@@ -240,9 +249,11 @@ fast_string_match (regexp, string)
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}
@@ -659,10 +670,12 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
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)
@@ -687,9 +700,11 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
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)
@@ -882,9 +897,11 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
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]
@@ -957,9 +974,11 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
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]
@@ -1390,8 +1409,10 @@ LIST should have been created by calling `match-data' previously.")
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
diff --git a/src/sysdep.c b/src/sysdep.c
index 89cda7d1c65..45226ed6159 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -23,6 +23,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 23
24#include "config.h" 24#include "config.h"
25#include "lisp.h" 25#include "lisp.h"
26#include "blockinput.h"
26#undef NULL 27#undef NULL
27 28
28#define min(x,y) ((x) > (y) ? (y) : (x)) 29#define min(x,y) ((x) > (y) ? (y) : (x))
@@ -487,7 +488,7 @@ sys_suspend ()
487 else 488 else
488 parent_id = getppid (); 489 parent_id = getppid ();
489 490
490 free (fpid_string); /* On VMS, this was malloc'd */ 491 xfree (fpid_string); /* On VMS, this was malloc'd */
491 492
492 if (parent_id && parent_id != 0xffffffff) 493 if (parent_id && parent_id != 0xffffffff)
493 { 494 {
@@ -2357,6 +2358,7 @@ getwd (pathname)
2357 char *npath, *spath; 2358 char *npath, *spath;
2358 extern char *getcwd (); 2359 extern char *getcwd ();
2359 2360
2361 BLOCK_INPUT; /* getcwd uses malloc */
2360 spath = npath = getcwd ((char *) 0, MAXPATHLEN); 2362 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
2361 /* On Altos 3068, getcwd can return @hostname/dir, so discard 2363 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2362 up to first slash. Should be harmless on other systems. */ 2364 up to first slash. Should be harmless on other systems. */
@@ -2364,6 +2366,7 @@ getwd (pathname)
2364 npath++; 2366 npath++;
2365 strcpy (pathname, npath); 2367 strcpy (pathname, npath);
2366 free (spath); /* getcwd uses malloc */ 2368 free (spath); /* getcwd uses malloc */
2369 UNBLOCK_INPUT;
2367 return pathname; 2370 return pathname;
2368} 2371}
2369 2372
@@ -2613,8 +2616,8 @@ closedir (dirp)
2613 register DIR *dirp; /* stream from opendir */ 2616 register DIR *dirp; /* stream from opendir */
2614{ 2617{
2615 sys_close (dirp->dd_fd); 2618 sys_close (dirp->dd_fd);
2616 free ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */ 2619 xfree ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */
2617 free ((char *) dirp); 2620 xfree ((char *) dirp);
2618} 2621}
2619#endif /* not AIX */ 2622#endif /* not AIX */
2620#endif /* SYSV_SYSTEM_DIR */ 2623#endif /* SYSV_SYSTEM_DIR */
@@ -2633,13 +2636,16 @@ opendir (filename)
2633 if (fd < 0) 2636 if (fd < 0)
2634 return 0; 2637 return 0;
2635 2638
2639 BLOCK_INPUT;
2636 if (fstat (fd, &sbuf) < 0 2640 if (fstat (fd, &sbuf) < 0
2637 || (sbuf.st_mode & S_IFMT) != S_IFDIR 2641 || (sbuf.st_mode & S_IFMT) != S_IFDIR
2638 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0) 2642 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
2639 { 2643 {
2640 sys_close (fd); 2644 sys_close (fd);
2645 UNBLOCK_INPUT;
2641 return 0; /* bad luck today */ 2646 return 0; /* bad luck today */
2642 } 2647 }
2648 UNBLOCK_INPUT;
2643 2649
2644 dirp->dd_fd = fd; 2650 dirp->dd_fd = fd;
2645 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ 2651 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
@@ -2652,7 +2658,7 @@ closedir (dirp)
2652 register DIR *dirp; /* stream from opendir */ 2658 register DIR *dirp; /* stream from opendir */
2653{ 2659{
2654 sys_close (dirp->dd_fd); 2660 sys_close (dirp->dd_fd);
2655 free ((char *) dirp); 2661 xfree ((char *) dirp);
2656} 2662}
2657 2663
2658 2664
@@ -3116,10 +3122,10 @@ getwd (pathname)
3116 3122
3117#define MAXPATHLEN 1024 3123#define MAXPATHLEN 1024
3118 3124
3119 ptr = malloc (MAXPATHLEN); 3125 ptr = xmalloc (MAXPATHLEN);
3120 getcwd (ptr, MAXPATHLEN); 3126 getcwd (ptr, MAXPATHLEN);
3121 strcpy (pathname, ptr); 3127 strcpy (pathname, ptr);
3122 free (ptr); 3128 xfree (ptr);
3123 3129
3124 return pathname; 3130 return pathname;
3125} 3131}
diff --git a/src/term.c b/src/term.c
index ffc8f83c886..0b59e13b9fc 100644
--- a/src/term.c
+++ b/src/term.c
@@ -382,7 +382,7 @@ set_scroll_region (start, stop)
382 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_WIDTH (selected_frame)); 382 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_WIDTH (selected_frame));
383 } 383 }
384 OUTPUT (buf); 384 OUTPUT (buf);
385 free (buf); 385 xfree (buf);
386 losecursor (); 386 losecursor ();
387} 387}
388 388
@@ -787,7 +787,7 @@ insert_glyphs (start, len)
787 { 787 {
788 buf = tparam (TS_ins_multi_chars, 0, 0, len); 788 buf = tparam (TS_ins_multi_chars, 0, 0, len);
789 OUTPUT1 (buf); 789 OUTPUT1 (buf);
790 free (buf); 790 xfree (buf);
791 if (start) 791 if (start)
792 write_glyphs (start, len); 792 write_glyphs (start, len);
793 return; 793 return;
@@ -851,7 +851,7 @@ delete_glyphs (n)
851 { 851 {
852 buf = tparam (TS_del_multi_chars, 0, 0, n); 852 buf = tparam (TS_del_multi_chars, 0, 0, n);
853 OUTPUT1 (buf); 853 OUTPUT1 (buf);
854 free (buf); 854 xfree (buf);
855 } 855 }
856 else 856 else
857 for (i = 0; i < n; i++) 857 for (i = 0; i < n; i++)
@@ -896,7 +896,7 @@ ins_del_lines (vpos, n)
896 background_highlight (); 896 background_highlight ();
897 buf = tparam (multi, 0, 0, i); 897 buf = tparam (multi, 0, 0, i);
898 OUTPUT (buf); 898 OUTPUT (buf);
899 free (buf); 899 xfree (buf);
900 } 900 }
901 else if (single) 901 else if (single)
902 { 902 {
diff --git a/src/xfns.c b/src/xfns.c
index 6b43d198667..98987b33fba 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -33,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
33#include "buffer.h" 33#include "buffer.h"
34#include "dispextern.h" 34#include "dispextern.h"
35#include "keyboard.h" 35#include "keyboard.h"
36#include "blockinput.h"
36 37
37#ifdef HAVE_X_WINDOWS 38#ifdef HAVE_X_WINDOWS
38extern void abort (); 39extern void abort ();
@@ -2038,7 +2039,7 @@ be shared by the new frame.")
2038 BLOCK_INPUT; 2039 BLOCK_INPUT;
2039 XGetWindowInfo (FRAME_X_WINDOW (f), &wininfo); 2040 XGetWindowInfo (FRAME_X_WINDOW (f), &wininfo);
2040 XQueryTree (FRAME_X_WINDOW (f), &parent, &nchildren, &children); 2041 XQueryTree (FRAME_X_WINDOW (f), &parent, &nchildren, &children);
2041 free (children); 2042 xfree (children);
2042 UNBLOCK_INPUT; 2043 UNBLOCK_INPUT;
2043 2044
2044 height = PIXEL_TO_CHAR_HEIGHT (f, wininfo.height); 2045 height = PIXEL_TO_CHAR_HEIGHT (f, wininfo.height);
@@ -2287,7 +2288,7 @@ x_rubber_band (f, x, y, width, height, geo, str, hscroll, vscroll)
2287 *x -= wininfo.x; 2288 *x -= wininfo.x;
2288 *y -= wininfo.y; 2289 *y -= wininfo.y;
2289 XQueryTree (tempwindow, &tempwindow, &nchildren, &children); 2290 XQueryTree (tempwindow, &tempwindow, &nchildren, &children);
2290 free (children); 2291 xfree (children);
2291 } 2292 }
2292 2293
2293 UNBLOCK_INPUT; 2294 UNBLOCK_INPUT;
diff --git a/src/xmenu.c b/src/xmenu.c
index 452b4b9e298..f8417be039f 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -35,6 +35,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
35#include "frame.h" 35#include "frame.h"
36#include "window.h" 36#include "window.h"
37#include "keyboard.h" 37#include "keyboard.h"
38#include "blockinput.h"
38 39
39/* This may include sys/types.h, and that somehow loses 40/* This may include sys/types.h, and that somehow loses
40 if this is not done before the other system files. */ 41 if this is not done before the other system files. */
@@ -276,15 +277,15 @@ in the menu.")
276 /* now free up the strings */ 277 /* now free up the strings */
277 for (i = 0; i < number_of_panes; i++) 278 for (i = 0; i < number_of_panes; i++)
278 { 279 {
279 free (names[i]); 280 xfree (names[i]);
280 free (enables[i]); 281 xfree (enables[i]);
281 free (obj_list[i]); 282 xfree (obj_list[i]);
282 } 283 }
283 free (menus); 284 xfree (menus);
284 free (obj_list); 285 xfree (obj_list);
285 free (names); 286 xfree (names);
286 free (enables); 287 xfree (enables);
287 free (items); 288 xfree (items);
288 /* free (title); */ 289 /* free (title); */
289 if (error_name) error (error_name); 290 if (error_name) error (error_name);
290 return XMenu_return; 291 return XMenu_return;
@@ -633,9 +634,9 @@ single_keymap_panes (keymap, panes, vector, names, enables, items,
633 /* If we just made an empty pane, get rid of it. */ 634 /* If we just made an empty pane, get rid of it. */
634 if (i == 0) 635 if (i == 0)
635 { 636 {
636 free ((*vector)[*p_ptr]); 637 xfree ((*vector)[*p_ptr]);
637 free ((*names)[*p_ptr]); 638 xfree ((*names)[*p_ptr]);
638 free ((*enables)[*p_ptr]); 639 xfree ((*enables)[*p_ptr]);
639 } 640 }
640 /* Otherwise, advance past it. */ 641 /* Otherwise, advance past it. */
641 else 642 else
diff --git a/src/xselect.c b/src/xselect.c
index 66812bda044..51592fe7282 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -33,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
33#include "xterm.h" /* for all of the X includes */ 33#include "xterm.h" /* for all of the X includes */
34#include "dispextern.h" /* frame.h seems to want this */ 34#include "dispextern.h" /* frame.h seems to want this */
35#include "frame.h" /* Need this to get the X window of selected_frame */ 35#include "frame.h" /* Need this to get the X window of selected_frame */
36#include "blockinput.h"
36 37
37#define xfree free 38#define xfree free
38 39
diff --git a/src/xterm.c b/src/xterm.c
index f1dc6a24d12..c84bd6ebd7f 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -32,6 +32,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
32#ifdef HAVE_X_WINDOWS 32#ifdef HAVE_X_WINDOWS
33 33
34#include "lisp.h" 34#include "lisp.h"
35#include "blockinput.h"
35 36
36/* On 4.3 these lose if they come after xterm.h. */ 37/* On 4.3 these lose if they come after xterm.h. */
37#include <stdio.h> 38#include <stdio.h>
@@ -132,20 +133,10 @@ static struct event_queue x_expose_queue;
132struct event_queue x_mouse_queue; 133struct event_queue x_mouse_queue;
133#endif /* HAVE_X11 */ 134#endif /* HAVE_X11 */
134 135
135/* Nonzero after BLOCK_INPUT; prevents input events from being
136 processed until later. */
137
138int x_input_blocked;
139
140#if defined (SIGIO) && defined (FIONREAD) 136#if defined (SIGIO) && defined (FIONREAD)
141int BLOCK_INPUT_mask; 137int BLOCK_INPUT_mask;
142#endif /* ! defined (SIGIO) && defined (FIONREAD) */ 138#endif /* ! defined (SIGIO) && defined (FIONREAD) */
143 139
144/* Nonzero if input events came in while x_input_blocked was nonzero.
145 UNBLOCK_INPUT checks for this. */
146
147int x_pending_input;
148
149/* The id of a bitmap used for icon windows. 140/* The id of a bitmap used for icon windows.
150 One such map is shared by all Emacs icon windows. 141 One such map is shared by all Emacs icon windows.
151 This is zero if we have not yet had a need to create the bitmap. */ 142 This is zero if we have not yet had a need to create the bitmap. */
@@ -2482,13 +2473,13 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
2482 int prefix; 2473 int prefix;
2483 Lisp_Object part; 2474 Lisp_Object part;
2484 2475
2485 if (x_input_blocked) 2476 if (interrupt_input_blocked)
2486 { 2477 {
2487 x_pending_input = 1; 2478 interrupt_input_pending = 1;
2488 return -1; 2479 return -1;
2489 } 2480 }
2490 2481
2491 x_pending_input = 0; 2482 interrupt_input_pending = 0;
2492 BLOCK_INPUT; 2483 BLOCK_INPUT;
2493 2484
2494 if (numchars <= 0) 2485 if (numchars <= 0)
@@ -3765,7 +3756,7 @@ x_check_errors (format)
3765 char buf[256]; 3756 char buf[256];
3766 3757
3767 sprintf (buf, format, *x_caught_error_message); 3758 sprintf (buf, format, *x_caught_error_message);
3768 free (x_caught_error_message); 3759 xfree (x_caught_error_message);
3769 3760
3770 x_uncatch_errors (); 3761 x_uncatch_errors ();
3771 error (buf); 3762 error (buf);
@@ -3775,7 +3766,7 @@ x_check_errors (format)
3775void 3766void
3776x_uncatch_errors () 3767x_uncatch_errors ()
3777{ 3768{
3778 free (x_caught_error_message); 3769 xfree (x_caught_error_message);
3779 XHandleError (x_error_quitter); 3770 XHandleError (x_error_quitter);
3780} 3771}
3781 3772
@@ -4285,7 +4276,7 @@ x_destroy_window (f)
4285 XDestroyWindow (XDISPLAY f->display.x->window_desc); 4276 XDestroyWindow (XDISPLAY f->display.x->window_desc);
4286 XFlushQueue (); 4277 XFlushQueue ();
4287 4278
4288 free (f->display.x); 4279 xfree (f->display.x);
4289 f->display.x = 0; 4280 f->display.x = 0;
4290 if (f == x_focus_frame) 4281 if (f == x_focus_frame)
4291 x_focus_frame = 0; 4282 x_focus_frame = 0;
diff --git a/src/xterm.h b/src/xterm.h
index eccaadcc734..8a25d077632 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -171,35 +171,6 @@ struct event_queue
171/* Queue for mouse clicks. */ 171/* Queue for mouse clicks. */
172extern struct event_queue x_mouse_queue; 172extern struct event_queue x_mouse_queue;
173 173
174/* Mechanism for interlocking between main program level
175 and input interrupt level. */
176
177/* Nonzero during a critical section. At such a time, an input interrupt
178 does nothing but set `x_pending_input'. */
179extern int x_input_blocked;
180
181/* Nonzero means an input interrupt has arrived
182 during the current critical section. */
183extern int x_pending_input;
184
185/* Begin critical section. */
186#define BLOCK_INPUT (x_input_blocked++)
187
188/* End critical section. */
189#ifdef SIGIO
190/* If doing interrupt input, and an interrupt came in when input was blocked,
191 reinvoke the interrupt handler now to deal with it. */
192#define UNBLOCK_INPUT \
193 ((x_input_blocked--, (x_input_blocked < 0 ? (abort (), 0) : 0)), \
194 (x_input_blocked == 0 && x_pending_input != 0 ? (kill (0, SIGIO), 0) : 0))
195#else
196#define UNBLOCK_INPUT \
197 (x_input_blocked--, (x_input_blocked < 0 ? (abort (), 0) : 0))
198#endif
199
200#define TOTALLY_UNBLOCK_INPUT (x_input_blocked = 0)
201#define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT
202
203/* This is the X connection that we are using. */ 174/* This is the X connection that we are using. */
204 175
205extern Display *x_current_display; 176extern Display *x_current_display;