X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libiberty%2Falloca.c;h=9b2e9cb12b63b494b2de76ba74ec9a04629e8202;hb=b3d7d7e2d670a5a4acd817d3ae770f2b66ba96ee;hp=822c1dc2307d8ff901f999795cef2782d270b12a;hpb=add62f6afea7118bc01b8ca9dfabf1062fb65031;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libiberty/alloca.c b/libiberty/alloca.c index 822c1dc2307..9b2e9cb12b6 100644 --- a/libiberty/alloca.c +++ b/libiberty/alloca.c @@ -21,6 +21,27 @@ allocating any. It is a good idea to use alloca(0) in your main control loop, etc. to force garbage collection. */ +/* + +@deftypefn Replacement void* alloca (size_t @var{size}) + +This function allocates memory which will be automatically reclaimed +after the procedure exits. The @libib{} implementation does not free +the memory immediately but will do so eventually during subsequent +calls to this function. Memory is allocated using @code{xmalloc} under +normal circumstances. + +The header file @file{alloca-conf.h} can be used in conjunction with the +GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make +available this function. The @code{AC_FUNC_ALLOCA} test requires that +client code use a block of preprocessor code to be safe (see the Autoconf +manual for more); this header incorporates that logic and more, including +the possibility of a GCC built-in function. + +@end deftypefn + +*/ + #ifdef HAVE_CONFIG_H #include #endif @@ -36,9 +57,15 @@ /* These variables are used by the ASTRDUP implementation that relies on C_alloca. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ const char *libiberty_optr; char *libiberty_nptr; unsigned long libiberty_len; +#ifdef __cplusplus +} +#endif /* __cplusplus */ /* If your stack is a linked list of frames, you have to provide an "address metric" ADDRESS_FUNCTION macro. */ @@ -76,7 +103,7 @@ static int stack_dir; /* 1 or -1 once known. */ #define STACK_DIR stack_dir static void -find_stack_direction () +find_stack_direction (void) { static char *addr = NULL; /* Address of first `dummy', once known. */ auto char dummy; /* To get stack address. */ @@ -129,9 +156,10 @@ 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. */ +/* @undocumented C_alloca */ + PTR -C_alloca (size) - size_t size; +C_alloca (size_t size) { auto char probe; /* Probes stack depth: */ register char *depth = ADDRESS_FUNCTION (probe); @@ -169,20 +197,20 @@ C_alloca (size) /* Allocate combined header + user data storage. */ { - register PTR new = xmalloc (sizeof (header) + size); + register void *new_storage = XNEWVEC (char, sizeof (header) + size); /* Address of header. */ - if (new == 0) + if (new_storage == 0) abort(); - ((header *) new)->h.next = last_alloca_header; - ((header *) new)->h.deep = depth; + ((header *) new_storage)->h.next = last_alloca_header; + ((header *) new_storage)->h.deep = depth; - last_alloca_header = (header *) new; + last_alloca_header = (header *) new_storage; /* User storage begins just after header. */ - return (PTR) ((char *) new + sizeof (header)); + return (PTR) ((char *) new_storage + sizeof (header)); } }