Put interrupt input blocking in a separate file from xterm.h.
authorJim Blandy <jimb@redhat.com>
Wed, 31 Mar 1993 10:55:33 +0000 (10:55 +0000)
committerJim Blandy <jimb@redhat.com>
Wed, 31 Mar 1993 10:55:33 +0000 (10:55 +0000)
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.

23 files changed:
src/alloc.c
src/blockinput.h
src/buffer.c
src/dispnew.c
src/doc.c
src/doprnt.c
src/emacs.c
src/eval.c
src/fileio.c
src/hftctl.c
src/insdel.c
src/keyboard.c
src/keymap.c
src/lisp.h
src/lread.c
src/search.c
src/sysdep.c
src/term.c
src/xfns.c
src/xmenu.c
src/xselect.c
src/xterm.c
src/xterm.h

index bf4d189..46941e5 100644 (file)
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "buffer.h"
 #include "window.h"
 #include "frame.h"
+#include "blockinput.h"
 #endif
 
 #include "syssignal.h"
@@ -43,7 +44,7 @@ do                                                            \
     XSET (val, Lisp_Cons, (char *) address + size);            \
     if ((char *) XCONS (val) != (char *) address + size)       \
       {                                                                \
-       free (address);                                         \
+       xfree (address);                                        \
        memory_full ();                                         \
       }                                                                \
   } while (0)
@@ -149,7 +150,7 @@ memory_full ()
   error ("Memory exhausted");
 }
 
-/* like malloc and realloc but check for no memory left */
+/* like malloc routines but check for no memory and block interrupt input.  */
 
 long *
 xmalloc (size)
@@ -157,7 +158,9 @@ xmalloc (size)
 {
   register long *val;
 
+  BLOCK_INPUT;
   val = (long *) malloc (size);
+  UNBLOCK_INPUT;
 
   if (!val && size) memory_full ();
   return val;
@@ -170,16 +173,99 @@ xrealloc (block, size)
 {
   register long *val;
 
+  BLOCK_INPUT;
   /* We must call malloc explicitly when BLOCK is 0, since some
      reallocs don't do this.  */
   if (! block)
     val = (long *) malloc (size);
   else
     val = (long *) realloc (block, size);
+  UNBLOCK_INPUT;
 
   if (!val && size) memory_full ();
   return val;
 }
+
+void
+xfree (block)
+     long *block;
+{
+  BLOCK_INPUT;
+  free (block);
+  UNBLOCK_INPUT;
+}
+
+\f
+/* Arranging to disable input signals while we're in malloc.
+
+   This only works with GNU malloc.  To help out systems which can't
+   use GNU malloc, all the calls to malloc, realloc, and free
+   elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT
+   pairs; unfortunately, we have no idea what C library functions
+   might call malloc, so we can't really protect them unless you're
+   using GNU malloc.  Fortunately, most of the major operating can use
+   GNU malloc.  */
+
+#ifndef SYSTEM_MALLOC
+static void (*__malloc_hook) (),  (*old_malloc_hook) ();
+static void (*__realloc_hook) (), (*old_realloc_hook) ();
+static void (*__free_hook) (),    (*old_free_hook) ();
+
+static void
+emacs_blocked_free (ptr)
+     void *ptr;
+{
+  BLOCK_INPUT;
+  __free_hook = old_free_hook;
+  free (ptr);
+  __free_hook = &emacs_blocked_free;
+  UNBLOCK_INPUT;
+}
+
+static void *
+emacs_blocked_malloc (size)
+     unsigned size;
+{
+  void *value;
+
+  BLOCK_INPUT;
+  __malloc_hook = old_malloc_hook;
+  value = malloc (size);
+  __malloc_hook = &emacs_blocked_malloc;
+  UNBLOCK_INPUT;
+
+  return value;
+}
+
+static void *
+emacs_blocked_realloc (ptr, size)
+     void *ptr;
+     unsigned size;
+{
+  void *value;
+
+  BLOCK_INPUT;
+  __realloc_hook = old_realloc_hook;
+  value = realloc (ptr, size);
+  __realloc_hook = &emacs_blocked_realloc;
+  UNBLOCK_INPUT;
+
+  return value;
+}
+
+void
+uninterrupt_malloc ()
+{
+  old_free_hook = __free_hook;
+  __free_hook = &emacs_blocked_free;
+
+  old_malloc_hook = __malloc_hook;
+  __malloc_hook = &emacs_blocked_malloc;
+
+  old_realloc_hook = __realloc_hook;
+  __realloc_hook = &emacs_blocked_realloc;
+}
+#endif
 \f
 /* Interval allocation.  */
 
@@ -226,10 +312,7 @@ make_interval ()
       if (interval_block_index == INTERVAL_BLOCK_SIZE)
        {
          register struct interval_block *newi
-           = (struct interval_block *) malloc (sizeof (struct interval_block));
-
-         if (!newi)
-           memory_full ();
+           = (struct interval_block *) xmalloc (sizeof (struct interval_block));
 
          VALIDATE_LISP_STORAGE (newi, sizeof *newi);
          newi->next = interval_block;
@@ -352,8 +435,7 @@ make_float (float_value)
     {
       if (float_block_index == FLOAT_BLOCK_SIZE)
        {
-         register struct float_block *new = (struct float_block *) malloc (sizeof (struct float_block));
-         if (!new) memory_full ();
+         register struct float_block *new = (struct float_block *) xmalloc (sizeof (struct float_block));
          VALIDATE_LISP_STORAGE (new, sizeof *new);
          new->next = float_block;
          float_block = new;
@@ -427,8 +509,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
     {
       if (cons_block_index == CONS_BLOCK_SIZE)
        {
-         register struct cons_block *new = (struct cons_block *) malloc (sizeof (struct cons_block));
-         if (!new) memory_full ();
+         register struct cons_block *new = (struct cons_block *) xmalloc (sizeof (struct cons_block));
          VALIDATE_LISP_STORAGE (new, sizeof *new);
          new->next = cons_block;
          cons_block = new;
@@ -498,9 +579,7 @@ See also the function `vector'.")
     length = wrong_type_argument (Qnatnump, length);
   sizei = XINT (length);
 
-  p = (struct Lisp_Vector *) malloc (sizeof (struct Lisp_Vector) + (sizei - 1) * sizeof (Lisp_Object));
-  if (p == 0)
-    memory_full ();
+  p = (struct Lisp_Vector *) xmalloc (sizeof (struct Lisp_Vector) + (sizei - 1) * sizeof (Lisp_Object));
   VALIDATE_LISP_STORAGE (p, 0);
 
   XSET (vector, Lisp_Vector, p);
@@ -617,8 +696,7 @@ Its value and function definition are void, and its property list is nil.")
     {
       if (symbol_block_index == SYMBOL_BLOCK_SIZE)
        {
-         struct symbol_block *new = (struct symbol_block *) malloc (sizeof (struct symbol_block));
-         if (!new) memory_full ();
+         struct symbol_block *new = (struct symbol_block *) xmalloc (sizeof (struct symbol_block));
          VALIDATE_LISP_STORAGE (new, sizeof *new);
          new->next = symbol_block;
          symbol_block = new;
@@ -680,8 +758,7 @@ DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0,
     {
       if (marker_block_index == MARKER_BLOCK_SIZE)
        {
-         struct marker_block *new = (struct marker_block *) malloc (sizeof (struct marker_block));
-         if (!new) memory_full ();
+         struct marker_block *new = (struct marker_block *) xmalloc (sizeof (struct marker_block));
          VALIDATE_LISP_STORAGE (new, sizeof *new);
          new->next = marker_block;
          marker_block = new;
@@ -830,9 +907,8 @@ make_uninit_string (length)
     /* This string gets its own string block */
     {
       register struct string_block *new
-       = (struct string_block *) malloc (sizeof (struct string_block_head) + fullsize);
+       = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize);
       VALIDATE_LISP_STORAGE (new, 0);
-      if (!new) memory_full ();
       consing_since_gc += sizeof (struct string_block_head) + fullsize;
       new->pos = fullsize;
       new->next = large_string_blocks;
@@ -844,8 +920,7 @@ make_uninit_string (length)
     /* Make a new current string block and start it off with this string */
     {
       register struct string_block *new
-       = (struct string_block *) malloc (sizeof (struct string_block));
-      if (!new) memory_full ();
+       = (struct string_block *) xmalloc (sizeof (struct string_block));
       VALIDATE_LISP_STORAGE (new, sizeof *new);
       consing_since_gc += sizeof (struct string_block);
       current_string_block->next = new;
@@ -1149,9 +1224,9 @@ Garbage collection happens automatically if you cons more than\n\
       if (i < MAX_SAVE_STACK)
        {
          if (stack_copy == 0)
-           stack_copy = (char *) malloc (stack_copy_size = i);
+           stack_copy = (char *) xmalloc (stack_copy_size = i);
          else if (stack_copy_size < i)
-           stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i));
+           stack_copy = (char *) xrealloc (stack_copy, (stack_copy_size = i));
          if (stack_copy)
            {
              if ((int) (&stack_top_variable - stack_bottom) > 0)
@@ -1804,7 +1879,7 @@ gc_sweep ()
          else
            all_buffers = buffer->next;
          next = buffer->next;
-         free (buffer);
+         xfree (buffer);
          buffer = next;
        }
       else
@@ -1845,7 +1920,7 @@ gc_sweep ()
          else
            all_vectors = vector->next;
          next = vector->next;
-         free (vector);
+         xfree (vector);
          vector = next;
        }
       else
@@ -1868,7 +1943,7 @@ gc_sweep ()
          else
            large_string_blocks = sb->next;
          next = sb->next;
-         free (sb);
+         xfree (sb);
          sb = next;
        }
       else
@@ -1983,7 +2058,7 @@ compact_strings ()
   while (from_sb)
     {
       to_sb = from_sb->next;
-      free (from_sb);
+      xfree (from_sb);
       from_sb = to_sb;
     }
 
@@ -1998,7 +2073,7 @@ compact_strings ()
        {
          if (from_sb->next = to_sb->next)
            from_sb->next->prev = from_sb;
-         free (to_sb);
+         xfree (to_sb);
        }
       else
        from_sb = to_sb;
index c4c4979..f02cb5c 100644 (file)
@@ -1,4 +1,4 @@
-/* Interface to blocking complicated interrupt-driven input.
+/* blockinput.h - interface to blocking complicated interrupt-driven input.
    Copyright (C) 1989, 1993 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
index edf04aa..ddfab45 100644 (file)
@@ -197,12 +197,12 @@ The value is never nil.")
   if (!NILP (buf))
     return buf;
 
-  b = (struct buffer *) malloc (sizeof (struct buffer));
-  if (!b)
-    memory_full ();
+  b = (struct buffer *) xmalloc (sizeof (struct buffer));
 
   BUF_GAP_SIZE (b) = 20;
+  BLOCK_INPUT;
   BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b));
+  UNBLOCK_INPUT;
   if (! BUF_BEG_ADDR (b))
     memory_full ();
 
@@ -750,7 +750,9 @@ with `delete-process'.")
   /* Perhaps we should explicitly free the interval tree here... */
 
   b->name = Qnil;
+  BLOCK_INPUT;
   BUFFER_FREE (BUF_BEG_ADDR (b));
+  UNBLOCK_INPUT;
   b->undo_list = Qnil;
 
   return Qt;
@@ -1513,7 +1515,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
   /* Make a list of them all.  */
   result = Flist (noverlays, overlay_vec);
 
-  free (overlay_vec);
+  xfree (overlay_vec);
   return result;
 }
 
@@ -1553,7 +1555,7 @@ DEFUN ("next-overlay-change", Fnext_overlay_change, Snext_overlay_change,
        endpos = oendpos;
     }
 
-  free (overlay_vec);
+  xfree (overlay_vec);
   return make_number (endpos);
 }
 \f
index a7a1fa5..b1f15f2 100644 (file)
@@ -285,26 +285,26 @@ free_frame_glyphs (frame, glyphs)
      struct frame_glyphs *glyphs;
 {
   if (glyphs->total_contents)
-    free (glyphs->total_contents);
+    xfree (glyphs->total_contents);
 
-  free (glyphs->used);
-  free (glyphs->glyphs);
-  free (glyphs->highlight);
-  free (glyphs->enable);
-  free (glyphs->bufp);
+  xfree (glyphs->used);
+  xfree (glyphs->glyphs);
+  xfree (glyphs->highlight);
+  xfree (glyphs->enable);
+  xfree (glyphs->bufp);
 
 #ifdef HAVE_X_WINDOWS
   if (FRAME_X_P (frame))
     {
-      free (glyphs->top_left_x);
-      free (glyphs->top_left_y);
-      free (glyphs->pix_width);
-      free (glyphs->pix_height);
-      free (glyphs->max_ascent);
+      xfree (glyphs->top_left_x);
+      xfree (glyphs->top_left_y);
+      xfree (glyphs->pix_width);
+      xfree (glyphs->pix_height);
+      xfree (glyphs->max_ascent);
     }
 #endif
 
-  free (glyphs);
+  xfree (glyphs);
 }
 
 static void
index 13c261b..fc8c996 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -512,7 +512,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
     tem = make_string (buf, bufp - buf);
   else
     tem = str;
-  free (buf);
+  xfree (buf);
   RETURN_UNGCPRO (tem);
 }
 \f
index 0258455..2fe45cf 100644 (file)
@@ -178,7 +178,7 @@ doprnt (buffer, bufsize, format, format_end, nargs, args)
 
   /* If we had to malloc something, free it.  */
   if (big_buffer)
-    free (big_buffer);
+    xfree (big_buffer);
 
   *bufptr = 0;         /* Make sure our string end with a '\0' */
   return bufptr - buffer;
index ac4f391..8143498 100644 (file)
@@ -311,7 +311,14 @@ main (argc, argv, envp)
 
 #ifndef SYSTEM_MALLOC
   if (! initialized)
-    memory_warnings (0, malloc_warning);
+    {
+      /* Arrange to get warning messages as memory fills up.  */
+      memory_warnings (0, malloc_warning);
+
+      /* Arrange to disable interrupt input while malloc and friends are
+        running.  */
+      uninterrupt_malloc ();
+    }
 #endif /* not SYSTEM_MALLOC */
 
 #ifdef PRIO_PROCESS
index 7726aad..e1f56c0 100644 (file)
@@ -20,9 +20,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "config.h"
 #include "lisp.h"
-#ifdef HAVE_X_WINDOWS
-#include "xterm.h"
-#endif
+#include "blockinput.h"
 
 #ifndef standalone
 #include "commands.h"
index f994392..05cc467 100644 (file)
@@ -2046,16 +2046,16 @@ Otherwise returns NIL.")
       valsize = readlink (XSTRING (filename)->data, buf, bufsize);
       if (valsize < bufsize) break;
       /* Buffer was not long enough */
-      free (buf);
+      xfree (buf);
       bufsize *= 2;
     }
   if (valsize == -1)
     {
-      free (buf);
+      xfree (buf);
       return Qnil;
     }
   val = make_string (buf, valsize);
-  free (buf);
+  xfree (buf);
   return val;
 #else /* not S_IFLNK */
   return Qnil;
index 6ba1e2f..1b46050 100644 (file)
@@ -79,7 +79,7 @@ typedef int    (*FUNC)();     /* pointer to a function        */
 
 static int              hfqry();
 static int              hfskbd();
-       char            *malloc();
+       char            *xmalloc();
 
 extern int              errno;
 static jmp_buf          hftenv;
@@ -319,7 +319,7 @@ WR_REQ (fd, request, cmdlen, cmd, resplen)
   if (cmdlen)                  /* if arg structure to pass    */
     {
       size = sizeof (struct hfctlreq) + cmdlen;
-      if ((p.c = malloc(size)) == NULL) /* malloc one area            */
+      if ((p.c = xmalloc(size)) == NULL) /* malloc one area            */
        return (-1);
 
       memcpy (p.c, &req, sizeof (req)); /* copy CTL REQ struct         */
@@ -334,7 +334,7 @@ WR_REQ (fd, request, cmdlen, cmd, resplen)
   /* write request to terminal   */
   if (write(fd,p.c,size) == -1) return (-1);
   if (p.req != &req)           /* free if allocated           */
-    free (p.c);
+    xfree (p.c);
   return (0);
 
 }
index bfbf768..647c4be 100644 (file)
@@ -245,7 +245,10 @@ make_gap (increment)
   /* If we have to get more space, get enough to last a while.  */
   increment += 2000;
 
+  BLOCK_INPUT;
   result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment));
+  UNBLOCK_INPUT;
+
   if (result == 0)
     memory_full ();
   BEG_ADDR = result;
index 91e4ee1..30b78f8 100644 (file)
@@ -36,6 +36,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "dispextern.h"
 #include "keyboard.h"
 #include "intervals.h"
+#include "blockinput.h"
 #include <setjmp.h>
 #include <errno.h>
 
@@ -49,6 +50,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 extern int errno;
 
+/* Variables for blockinput.h: */
+
+/* Non-zero if interrupt input is blocked right now.  */
+extern int interrupt_input_blocked;
+
+/* Nonzero means an input interrupt has arrived
+   during the current critical section.  */
+extern int interrupt_input_pending;
+
+
 #ifdef HAVE_X_WINDOWS
 extern Lisp_Object Vmouse_grabbed;
 
@@ -1158,12 +1169,9 @@ int polling_for_input;
 SIGTYPE
 input_poll_signal ()
 {
-#ifdef HAVE_X_WINDOWS
-  extern int x_input_blocked;
-  if (x_input_blocked == 0)
-#endif
-    if (!waiting_for_input)
-      read_avail_input (0);
+  if (interrupt_input_blocked == 0
+      && !waiting_for_input)
+    read_avail_input (0);
   signal (SIGALRM, input_poll_signal);
   alarm (polling_period);
 }
index 62861bd..b2eb948 100644 (file)
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "buffer.h"
 #include "keyboard.h"
 #include "termhooks.h"
+#include "blockinput.h"
 
 #define min(a, b) ((a) < (b) ? (a) : (b))
 
@@ -707,13 +708,17 @@ current_minor_maps (modeptr, mapptr)
 
            if (cmm_maps)
              {
+               BLOCK_INPUT;
                newmodes = (Lisp_Object *) realloc (cmm_modes, cmm_size *= 2);
                newmaps  = (Lisp_Object *) realloc (cmm_maps,  cmm_size);
+               UNBLOCK_INPUT;
              }
            else
              {
+               BLOCK_INPUT;
                newmodes = (Lisp_Object *) malloc (cmm_size = 30);
                newmaps  = (Lisp_Object *) malloc (cmm_size);
+               UNBLOCK_INPUT;
              }
 
            if (newmaps && newmodes)
index 2d62363..4e2b86e 100644 (file)
@@ -1244,5 +1244,6 @@ extern void debugger ();
 
 extern char *malloc (), *realloc (), *getenv (), *ctime (), *getwd ();
 extern long *xmalloc (), *xrealloc ();
+extern void xfree ();
 
 extern char *egetenv ();
index 62e702e..5769fba 100644 (file)
@@ -417,7 +417,7 @@ load_unwind (stream)  /* used as unwind-protect function in load */
      Lisp_Object stream;
 {
   fclose (*(FILE **) XSTRING (stream));
-  free (XPNTR (stream));
+  xfree (XPNTR (stream));
   if (--load_in_progress < 0) load_in_progress = 0;
   return Qnil;
 }
index 03ed61f..fdf19fe 100644 (file)
@@ -23,6 +23,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "syntax.h"
 #include "buffer.h"
 #include "commands.h"
+#include "blockinput.h"
 
 #include <sys/types.h>
 #include "regex.h"
@@ -97,9 +98,11 @@ compile_pattern (pattern, bufp, regp, translate)
 
   last_regexp = Qnil;
   bufp->translate = translate;
+  BLOCK_INPUT;
   val = re_compile_pattern ((char *) XSTRING (pattern)->data,
                            XSTRING (pattern)->size,
                            bufp);
+  UNBLOCK_INPUT;
   if (val)
     {
       dummy = build_string (val);
@@ -111,8 +114,10 @@ compile_pattern (pattern, bufp, regp, translate)
 
   /* Advise the searching functions about the space we have allocated
      for register data.  */
+  BLOCK_INPUT;
   if (regp)
     re_set_registers (bufp, regp, regp->num_regs, regp->start, regp->end);
+  UNBLOCK_INPUT;
 
   return;
 }
@@ -167,9 +172,11 @@ data if you want to preserve them.")
       s2 = 0;
     }
   
+  BLOCK_INPUT;
   i = re_match_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2,
                  point - BEGV, &search_regs,
                  ZV - BEGV);
+  UNBLOCK_INPUT;
   if (i == -2)
     matcher_overflow ();
 
@@ -217,9 +224,11 @@ matched by parenthesis constructs in the pattern.")
   compile_pattern (regexp, &searchbuf, &search_regs,
                   !NILP (current_buffer->case_fold_search) ? DOWNCASE_TABLE : 0);
   immediate_quit = 1;
+  BLOCK_INPUT;
   val = re_search (&searchbuf, (char *) XSTRING (string)->data,
                   XSTRING (string)->size, s, XSTRING (string)->size - s,
                   &search_regs);
+  UNBLOCK_INPUT;
   immediate_quit = 0;
   last_thing_searched = Qt;
   if (val == -2)
@@ -240,9 +249,11 @@ fast_string_match (regexp, string)
 
   compile_pattern (regexp, &searchbuf, 0, 0);
   immediate_quit = 1;
+  BLOCK_INPUT;
   val = re_search (&searchbuf, (char *) XSTRING (string)->data,
                   XSTRING (string)->size, 0, XSTRING (string)->size,
                   0);
+  UNBLOCK_INPUT;
   immediate_quit = 0;
   return val;
 }
@@ -659,10 +670,12 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
        }
       while (n < 0)
        {
+         BLOCK_INPUT;
          int val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2,
                                 pos - BEGV, lim - pos, &search_regs,
                                 /* Don't allow match past current point */
                                 pos - BEGV);
+         UNBLOCK_INPUT;
          if (val == -2)
            matcher_overflow ();
          if (val >= 0)
@@ -687,9 +700,11 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
        }
       while (n > 0)
        {
+         BLOCK_INPUT;
          int val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2,
                                 pos - BEGV, lim - pos, &search_regs,
                                 lim - BEGV);
+         UNBLOCK_INPUT;
          if (val == -2)
            matcher_overflow ();
          if (val >= 0)
@@ -882,9 +897,11 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
                            (regoff_t *) xmalloc (2 * sizeof (regoff_t));
                          ends =
                            (regoff_t *) xmalloc (2 * sizeof (regoff_t));
+                         BLOCK_INPUT;
                          re_set_registers (&searchbuf,
                                            &search_regs,
                                            2, starts, ends);
+                         UNBLOCK_INPUT;
                        }
 
                      search_regs.start[0]
@@ -957,9 +974,11 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
                            (regoff_t *) xmalloc (2 * sizeof (regoff_t));
                          ends =
                            (regoff_t *) xmalloc (2 * sizeof (regoff_t));
+                         BLOCK_INPUT;
                          re_set_registers (&searchbuf,
                                            &search_regs,
                                            2, starts, ends);
+                         UNBLOCK_INPUT;
                        }
 
                      search_regs.start[0]
@@ -1390,8 +1409,10 @@ LIST should have been created by calling `match-data' previously.")
                                       length * sizeof (regoff_t));
          }
 
+       BLOCK_INPUT;
        re_set_registers (&searchbuf, &search_regs, length,
                          search_regs.start, search_regs.end);
+       UNBLOCK_INPUT;
       }
   }
 
index 89cda7d..45226ed 100644 (file)
@@ -23,6 +23,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "config.h"
 #include "lisp.h"
+#include "blockinput.h"
 #undef NULL
 
 #define min(x,y) ((x) > (y) ? (y) : (x))
@@ -487,7 +488,7 @@ sys_suspend ()
   else
     parent_id = getppid ();
 
-  free (fpid_string);          /* On VMS, this was malloc'd */
+  xfree (fpid_string);         /* On VMS, this was malloc'd */
 
   if (parent_id && parent_id != 0xffffffff)
     {
@@ -2357,6 +2358,7 @@ getwd (pathname)
   char *npath, *spath;
   extern char *getcwd ();
 
+  BLOCK_INPUT;                 /* getcwd uses malloc */
   spath = npath = getcwd ((char *) 0, MAXPATHLEN);
   /* On Altos 3068, getcwd can return @hostname/dir, so discard
      up to first slash.  Should be harmless on other systems.  */
@@ -2364,6 +2366,7 @@ getwd (pathname)
     npath++;
   strcpy (pathname, npath);
   free (spath);                        /* getcwd uses malloc */
+  UNBLOCK_INPUT;
   return pathname;
 }
 
@@ -2613,8 +2616,8 @@ closedir (dirp)
      register DIR *dirp;              /* stream from opendir */
 {
   sys_close (dirp->dd_fd);
-  free ((char *) dirp->dd_buf);       /* directory block defined in <dirent.h> */
-  free ((char *) dirp);
+  xfree ((char *) dirp->dd_buf);       /* directory block defined in <dirent.h> */
+  xfree ((char *) dirp);
 }
 #endif /* not AIX */
 #endif /* SYSV_SYSTEM_DIR */
@@ -2633,13 +2636,16 @@ opendir (filename)
   if (fd < 0)
     return 0;
 
+  BLOCK_INPUT;
   if (fstat (fd, &sbuf) < 0
       || (sbuf.st_mode & S_IFMT) != S_IFDIR
       || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
     {
       sys_close (fd);
+      UNBLOCK_INPUT;
       return 0;                /* bad luck today */
     }
+  UNBLOCK_INPUT;
 
   dirp->dd_fd = fd;
   dirp->dd_loc = dirp->dd_size = 0;    /* refill needed */
@@ -2652,7 +2658,7 @@ closedir (dirp)
      register DIR *dirp;               /* stream from opendir */
 {
   sys_close (dirp->dd_fd);
-  free ((char *) dirp);
+  xfree ((char *) dirp);
 }
 
 
@@ -3116,10 +3122,10 @@ getwd (pathname)
 
 #define MAXPATHLEN 1024
 
-  ptr = malloc (MAXPATHLEN);
+  ptr = xmalloc (MAXPATHLEN);
   getcwd (ptr, MAXPATHLEN);
   strcpy (pathname, ptr);
-  free (ptr);
+  xfree (ptr);
   
  return pathname;
 }
index ffc8f83..0b59e13 100644 (file)
@@ -382,7 +382,7 @@ set_scroll_region (start, stop)
       buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_WIDTH (selected_frame));
     }
   OUTPUT (buf);
-  free (buf);
+  xfree (buf);
   losecursor ();
 }
 \f
@@ -787,7 +787,7 @@ insert_glyphs (start, len)
     {
       buf = tparam (TS_ins_multi_chars, 0, 0, len);
       OUTPUT1 (buf);
-      free (buf);
+      xfree (buf);
       if (start)
        write_glyphs (start, len);
       return;
@@ -851,7 +851,7 @@ delete_glyphs (n)
     {
       buf = tparam (TS_del_multi_chars, 0, 0, n);
       OUTPUT1 (buf);
-      free (buf);
+      xfree (buf);
     }
   else
     for (i = 0; i < n; i++)
@@ -896,7 +896,7 @@ ins_del_lines (vpos, n)
       background_highlight ();
       buf = tparam (multi, 0, 0, i);
       OUTPUT (buf);
-      free (buf);
+      xfree (buf);
     }
   else if (single)
     {
index 6b43d19..98987b3 100644 (file)
@@ -33,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "buffer.h"
 #include "dispextern.h"
 #include "keyboard.h"
+#include "blockinput.h"
 
 #ifdef HAVE_X_WINDOWS
 extern void abort ();
@@ -2038,7 +2039,7 @@ be shared by the new frame.")
       BLOCK_INPUT;
       XGetWindowInfo (FRAME_X_WINDOW (f), &wininfo);
       XQueryTree (FRAME_X_WINDOW (f), &parent, &nchildren, &children);
-      free (children);
+      xfree (children);
       UNBLOCK_INPUT;
 
       height = PIXEL_TO_CHAR_HEIGHT (f, wininfo.height);
@@ -2287,7 +2288,7 @@ x_rubber_band (f, x, y, width, height, geo, str, hscroll, vscroll)
       *x -= wininfo.x;
       *y -= wininfo.y;
       XQueryTree (tempwindow, &tempwindow, &nchildren, &children);
-      free (children);
+      xfree (children);
     }
 
   UNBLOCK_INPUT;
index 452b4b9..f8417be 100644 (file)
@@ -35,6 +35,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "frame.h"
 #include "window.h"
 #include "keyboard.h"
+#include "blockinput.h"
 
 /* This may include sys/types.h, and that somehow loses
    if this is not done before the other system files.  */
@@ -276,15 +277,15 @@ in the menu.")
   /* now free up the strings */
   for (i = 0; i < number_of_panes; i++)
     {
-      free (names[i]);
-      free (enables[i]);
-      free (obj_list[i]);
+      xfree (names[i]);
+      xfree (enables[i]);
+      xfree (obj_list[i]);
     }
-  free (menus);
-  free (obj_list);
-  free (names);
-  free (enables);
-  free (items);
+  xfree (menus);
+  xfree (obj_list);
+  xfree (names);
+  xfree (enables);
+  xfree (items);
   /* free (title); */
   if (error_name) error (error_name);
   return XMenu_return;
@@ -633,9 +634,9 @@ single_keymap_panes (keymap, panes, vector, names, enables, items,
   /* If we just made an empty pane, get rid of it.  */
   if (i == 0)
     {
-      free ((*vector)[*p_ptr]);
-      free ((*names)[*p_ptr]);
-      free ((*enables)[*p_ptr]);
+      xfree ((*vector)[*p_ptr]);
+      xfree ((*names)[*p_ptr]);
+      xfree ((*enables)[*p_ptr]);
     }
   /* Otherwise, advance past it.  */
   else
index 66812bd..51592fe 100644 (file)
@@ -33,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "xterm.h"     /* for all of the X includes */
 #include "dispextern.h"        /* frame.h seems to want this */
 #include "frame.h"     /* Need this to get the X window of selected_frame */
+#include "blockinput.h"
 
 #define xfree free
 
index f1dc6a2..c84bd6e 100644 (file)
@@ -32,6 +32,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #ifdef HAVE_X_WINDOWS
 
 #include "lisp.h"
+#include "blockinput.h"
 
 /* On 4.3 these lose if they come after xterm.h.  */
 #include <stdio.h>
@@ -132,20 +133,10 @@ static struct event_queue x_expose_queue;
 struct event_queue x_mouse_queue;
 #endif /* HAVE_X11 */
 
-/* Nonzero after BLOCK_INPUT; prevents input events from being
-   processed until later.  */
-
-int x_input_blocked;
-
 #if defined (SIGIO) && defined (FIONREAD)
 int BLOCK_INPUT_mask;
 #endif /* ! defined (SIGIO) && defined (FIONREAD) */
 
-/* Nonzero if input events came in while x_input_blocked was nonzero.
-   UNBLOCK_INPUT checks for this.  */
-
-int x_pending_input;
-
 /* The id of a bitmap used for icon windows.
    One such map is shared by all Emacs icon windows.
    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)
   int prefix;
   Lisp_Object part;
 
-  if (x_input_blocked)
+  if (interrupt_input_blocked)
     {
-      x_pending_input = 1;
+      interrupt_input_pending = 1;
       return -1;
     }
 
-  x_pending_input = 0;
+  interrupt_input_pending = 0;
   BLOCK_INPUT;
        
   if (numchars <= 0)
@@ -3765,7 +3756,7 @@ x_check_errors (format)
       char buf[256];
 
       sprintf (buf, format, *x_caught_error_message);
-      free (x_caught_error_message);
+      xfree (x_caught_error_message);
 
       x_uncatch_errors ();
       error (buf);
@@ -3775,7 +3766,7 @@ x_check_errors (format)
 void
 x_uncatch_errors ()
 {
-  free (x_caught_error_message);
+  xfree (x_caught_error_message);
   XHandleError (x_error_quitter);
 }
 
@@ -4285,7 +4276,7 @@ x_destroy_window (f)
   XDestroyWindow (XDISPLAY f->display.x->window_desc);
   XFlushQueue ();
 
-  free (f->display.x);
+  xfree (f->display.x);
   f->display.x = 0;
   if (f == x_focus_frame)
     x_focus_frame = 0;
index eccaadc..8a25d07 100644 (file)
@@ -171,35 +171,6 @@ struct event_queue
 /* Queue for mouse clicks.  */
 extern struct event_queue x_mouse_queue;
 
-/* Mechanism for interlocking between main program level
-   and input interrupt level.  */
-
-/* Nonzero during a critical section.  At such a time, an input interrupt
-   does nothing but set `x_pending_input'.  */
-extern int x_input_blocked;
-
-/* Nonzero means an input interrupt has arrived
-   during the current critical section.  */
-extern int x_pending_input;
-
-/* Begin critical section. */
-#define BLOCK_INPUT (x_input_blocked++)
-
-/* End critical section. */
-#ifdef SIGIO
-/* If doing interrupt input, and an interrupt came in when input was blocked,
-   reinvoke the interrupt handler now to deal with it.  */
-#define UNBLOCK_INPUT \
-  ((x_input_blocked--, (x_input_blocked < 0 ? (abort (), 0) : 0)),     \
-   (x_input_blocked == 0 && x_pending_input != 0 ? (kill (0, SIGIO), 0) : 0))
-#else
-#define UNBLOCK_INPUT \
-  (x_input_blocked--, (x_input_blocked < 0 ? (abort (), 0) : 0))
-#endif
-
-#define TOTALLY_UNBLOCK_INPUT (x_input_blocked = 0)
-#define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT
-
 /* This is the X connection that we are using.  */
 
 extern Display *x_current_display;