[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] extended xmalloc.c
From: |
Dave Love |
Subject: |
[Bug-gnulib] extended xmalloc.c |
Date: |
Thu, 25 Sep 2003 15:43:21 +0100 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.2 (gnu/linux) |
Could you include this so that I can sync alloca.c with Emacs. I
assume programs other than Emacs might want to block input anyhow, so
this may be more generally useful.
rms has agreed to drop K&R support in Emacs, so that problem has gone
away.
2003-09-25 Dave Love <address@hidden>
* xmalloc.c [DO_BLOCK_INPUT]: Include blockinput.h.
[!DO_BLOCK_INPUT]: Define BLOCK_INPUT, UNBLOCK_INPUT.
(xmalloc, xrealloc, xcalloc): Use them.
(xfree): New.
Index: xmalloc.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xmalloc.c,v
retrieving revision 1.27
diff -u -p -r1.27 xmalloc.c
--- xmalloc.c 12 Sep 2003 20:14:10 -0000 1.27
+++ xmalloc.c 25 Sep 2003 13:59:49 -0000
@@ -43,6 +43,18 @@
"you must run the autoconf test for a GNU libc compatible realloc"
#endif
+/* Programs like Emacs can define BLOCK_INPUT and UNBLOCK_INPUT in
+ blockinput.h to enter and exit critical sections around potentially
+ non-reentrant code like malloc and Xlib routines. (Emacs doesn't
+ actually use this file, but other programs might want to do
+ this.) */
+#ifdef DO_BLOCK_INPUT
+# include "blockinput.h"
+#else
+# define BLOCK_INPUT
+# define UNBLOCK_INPUT
+#endif
+
/* If non NULL, call this function when memory is exhausted. */
void (*xalloc_fail_func) (void) = 0;
@@ -69,8 +81,10 @@ xmalloc (size_t n)
{
void *p;
+ BLOCK_INPUT;
p = malloc (n);
- if (p == 0)
+ UNBLOCK_INPUT;
+ if (p == 0)
xalloc_die ();
return p;
}
@@ -81,7 +95,9 @@ xmalloc (size_t n)
void *
xrealloc (void *p, size_t n)
{
+ BLOCK_INPUT;
p = realloc (p, n);
+ UNBLOCK_INPUT;
if (p == 0)
xalloc_die ();
return p;
@@ -94,8 +110,20 @@ xcalloc (size_t n, size_t s)
{
void *p;
+ BLOCK_INPUT;
p = calloc (n, s);
+ UNBLOCK_INPUT;
if (p == 0)
xalloc_die ();
return p;
+}
+
+/* Like free but maybe block interrupt input. */
+
+void
+xfree (void *block)
+{
+ BLOCK_INPUT;
+ free (block);
+ UNBLOCK_INPUT;
}
- [Bug-gnulib] extended xmalloc.c,
Dave Love <=