X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Falloca.c;h=c4db187da555e7c1eaf383fb2631670db8520ab4;hb=55da53d0db0c7a9fd82b2abc809560b3089df6a5;hp=836c50319d3ed2c3527c1884cd22cf4492388058;hpb=702f288a1c0d2053385edfe9a47ed0e184a9f1fe;p=gnulib.git diff --git a/lib/alloca.c b/lib/alloca.c index 836c50319..c4db187da 100644 --- a/lib/alloca.c +++ b/lib/alloca.c @@ -25,15 +25,19 @@ # include #endif -#if HAVE_STRING_H -# include -#endif -#if HAVE_STDLIB_H -# include -#endif +#include +#include #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 #endif /* If compiling with GCC 2, this file's not needed. */ @@ -53,6 +57,8 @@ you lose -- must know STACK_DIRECTION at compile-time +/* Using #error here is not wise since this file should work for + old and obscure compilers. */ # endif /* STACK_DIRECTION undefined */ # endif /* static */ # endif /* emacs */ @@ -67,32 +73,6 @@ long i00afunc (); # 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 xmalloc. - - Callers below should use malloc. */ - -# ifndef emacs -# undef malloc -# 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. @@ -115,7 +95,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. */ @@ -168,8 +148,8 @@ 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 (unsigned size) +void * +alloca (size_t size) { auto char probe; /* Probes stack depth: */ register char *depth = ADDRESS_FUNCTION (probe); @@ -195,7 +175,7 @@ alloca (unsigned size) { register header *np = hp->h.next; - free ((pointer) hp); /* Collect garbage. */ + free (hp); /* Collect garbage. */ hp = np; /* -> next header. */ } @@ -215,8 +195,14 @@ alloca (unsigned size) /* Allocate combined header + user data storage. */ { - register pointer new = malloc (sizeof (header) + size); /* Address of header. */ + register void *new; + + size_t combined_size = sizeof (header) + size; + if (combined_size < sizeof (header)) + xalloc_die (); + + new = xmalloc (combined_size); if (new == 0) abort(); @@ -228,7 +214,7 @@ alloca (unsigned size) /* User storage begins just after header. */ - return (pointer) ((char *) new + sizeof (header)); + return (void *) ((char *) new + sizeof (header)); } }