X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Falloca.c;h=f4c364a7251b9930fbca2ea6b4bf73e811396634;hb=24a2f092937bbbfdb21a9eedf909fca820154561;hp=10e5d65f01945193ae63b532c60a39278654c514;hpb=f629cb35ff2a467084745d8e635e41eb1f39f6d8;p=gnulib.git diff --git a/lib/alloca.c b/lib/alloca.c index 10e5d65f0..f4c364a72 100644 --- a/lib/alloca.c +++ b/lib/alloca.c @@ -25,8 +25,23 @@ # include #endif +#if HAVE_STRING_H +# include +#endif +#if HAVE_STDLIB_H +# include +#endif + #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. */ @@ -46,6 +61,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 */ @@ -60,31 +77,19 @@ long i00afunc (); # define ADDRESS_FUNCTION(arg) &(arg) # endif -# if __STDC__ -typedef void *pointer; -# else -typedef char *pointer; +# ifndef POINTER_TYPE +# ifdef __STDC__ +# define POINTER_TYPE void +# else +# define POINTER_TYPE char +# endif # endif +typedef POINTER_TYPE *pointer; # 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 -# 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. @@ -162,7 +167,7 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */ pointer alloca (size) - unsigned size; + size_t size; { auto char probe; /* Probes stack depth: */ register char *depth = ADDRESS_FUNCTION (probe); @@ -188,7 +193,7 @@ alloca (size) { register header *np = hp->h.next; - free ((pointer) hp); /* Collect garbage. */ + free (hp); /* Collect garbage. */ hp = np; /* -> next header. */ } @@ -208,8 +213,17 @@ alloca (size) /* Allocate combined header + user data storage. */ { - register pointer new = malloc (sizeof (header) + size); /* Address of header. */ + register pointer new; + + size_t combined_size = sizeof (header) + size; + if (combined_size < sizeof (header)) + xalloc_die (); + + new = xmalloc (combined_size); + + if (new == 0) + abort(); ((header *) new)->h.next = last_alloca_header; ((header *) new)->h.deep = depth;