summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-01-16 09:53:28 +0000
committerJim Meyering <jim@meyering.net>2004-01-16 09:53:28 +0000
commit4d108ffc750e521ef027f4d7f1d9f4e69dfeb416 (patch)
tree3274f303e11ba5d1b636c7412df3e8b34fd48be5
parentfb64640678c2ef45ad96efbe2d3deb4410161f87 (diff)
downloadcoreutils-4d108ffc750e521ef027f4d7f1d9f4e69dfeb416.tar.xz
Remove dependency on xalloc module.
(xalloc_die): Remove. (memory_full) [!defined emacs]: New macro. [!defined emacs]: Don't include xalloc.h. (alloca): Invoke memory_full, not xalloc_die, if malloc fails or address arithmetic overflows. Change datatypes a bit to avoid unnecessary casts.
-rw-r--r--lib/alloca.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/alloca.c b/lib/alloca.c
index 5e2521b36..a58007869 100644
--- a/lib/alloca.c
+++ b/lib/alloca.c
@@ -31,13 +31,12 @@
#ifdef emacs
# include "lisp.h"
# include "blockinput.h"
-# define xalloc_die() memory_full ()
# ifdef EMACS_FREE
# undef free
# define free EMACS_FREE
# endif
#else
-# include <xalloc.h>
+# define memory_full() abort ()
#endif
/* If compiling with GCC 2, this file's not needed. */
@@ -196,22 +195,25 @@ alloca (size_t size)
{
/* Address of header. */
- register void *new;
+ register header *new;
size_t combined_size = sizeof (header) + size;
if (combined_size < sizeof (header))
- xalloc_die ();
+ memory_full ();
- new = xmalloc (combined_size);
+ new = malloc (combined_size);
- ((header *) new)->h.next = last_alloca_header;
- ((header *) new)->h.deep = depth;
+ if (! new)
+ memory_full ();
- last_alloca_header = (header *) new;
+ new->h.next = last_alloca_header;
+ new->h.deep = depth;
+
+ last_alloca_header = new;
/* User storage begins just after header. */
- return (void *) ((char *) new + sizeof (header));
+ return (void *) (new + 1);
}
}