summaryrefslogtreecommitdiff
path: root/libiberty/alloca.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2001-03-06 19:03:36 +0000
committerDJ Delorie <dj@delorie.com>2001-03-06 19:03:36 +0000
commit19896453e4f961633def38c018073447a6134305 (patch)
tree1dc3e799149264dd93c9457b770913458a53cb79 /libiberty/alloca.c
parentc39ef5090839ec0aed6a9b8541daa8054d60d25d (diff)
downloadbinutils-redhat-19896453e4f961633def38c018073447a6134305.tar.gz
merge from gcc
Diffstat (limited to 'libiberty/alloca.c')
-rw-r--r--libiberty/alloca.c74
1 files changed, 9 insertions, 65 deletions
diff --git a/libiberty/alloca.c b/libiberty/alloca.c
index 0f8a21511d..bf105d80f0 100644
--- a/libiberty/alloca.c
+++ b/libiberty/alloca.c
@@ -25,6 +25,8 @@
#include <config.h>
#endif
+#include <libiberty.h>
+
#ifdef HAVE_STRING_H
#include <string.h>
#endif
@@ -32,67 +34,20 @@
#include <stdlib.h>
#endif
-#ifdef emacs
-#include "blockinput.h"
-#endif
-
-/* If compiling with GCC 2, this file's not needed. Except of course if
- the C alloca is explicitly requested. */
-#if defined (USE_C_ALLOCA) || !defined (__GNUC__) || __GNUC__ < 2
-
-/* If someone has defined alloca as a macro,
- there must be some other way alloca is supposed to work. */
-#ifndef alloca
-
-#ifdef emacs
-#ifdef static
-/* actually, only want this if static is defined as ""
- -- this is for usg, in which emacs must undefine static
- in order to make unexec workable
- */
-#ifndef STACK_DIRECTION
-you
-lose
--- must know STACK_DIRECTION at compile-time
-#endif /* STACK_DIRECTION undefined */
-#endif /* static */
-#endif /* emacs */
-
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
-long i00afunc ();
+static long i00afunc ();
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
#else
#define ADDRESS_FUNCTION(arg) &(arg)
#endif
-#if __STDC__
-typedef void *pointer;
-#else
-typedef char *pointer;
-#endif
-
#ifndef NULL
#define NULL 0
#endif
-/* Different portions of Emacs need to call different versions of
- malloc. The Emacs executable needs alloca to call xmalloc, because
- ordinary malloc isn't protected from input signals. On the other
- hand, the utilities in lib-src need alloca to call malloc; some of
- them are very simple, and don't have an xmalloc routine.
-
- Non-Emacs programs expect this to call use xmalloc.
-
- Callers below should use malloc. */
-
-#ifndef emacs
-#define malloc xmalloc
-#endif
-extern pointer malloc ();
-
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
@@ -168,9 +123,9 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
-pointer
-alloca (size)
- unsigned size;
+PTR
+C_alloca (size)
+ size_t size;
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
@@ -186,17 +141,13 @@ alloca (size)
{
register header *hp; /* Traverses linked list. */
-#ifdef emacs
- BLOCK_INPUT;
-#endif
-
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
- free ((pointer) hp); /* Collect garbage. */
+ free ((PTR) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
@@ -204,10 +155,6 @@ alloca (size)
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
-
-#ifdef emacs
- UNBLOCK_INPUT;
-#endif
}
if (size == 0)
@@ -216,7 +163,7 @@ alloca (size)
/* Allocate combined header + user data storage. */
{
- register pointer new = malloc (sizeof (header) + size);
+ register PTR new = xmalloc (sizeof (header) + size);
/* Address of header. */
if (new == 0)
@@ -229,7 +176,7 @@ alloca (size)
/* User storage begins just after header. */
- return (pointer) ((char *) new + sizeof (header));
+ return (PTR) ((char *) new + sizeof (header));
}
}
@@ -500,6 +447,3 @@ i00afunc (long address)
#endif /* not CRAY2 */
#endif /* CRAY */
-
-#endif /* no alloca */
-#endif /* not GCC version 2 */