Mercurial > hg > xemacs-beta
diff src/alloca.c @ 851:e7ee5f8bde58
[xemacs-hg @ 2002-05-23 11:46:08 by ben]
fix for raymond toy's crash, alloca crashes, some recover-session improvements
files.el: Recover-session improvements: Only show session files where some
files can actually be recovered, and show in chronological order.
subr.el, menubar-items.el: As promised to rms, the functionality in
truncate-string-with-continuation-dots has been merged into
truncate-string-to-width. Change callers in menubar-items.el.
select.el: Document some of these funs better. Fix problem where we were
doing own-clipboard twice.
Makefile.in.in: Add alloca.o. Ensure that alloca.s doesn't compile into alloca.o,
but allocax.o (not that it's currently used or anything.)
EmacsFrame.c, abbrev.c, alloc.c, alloca.c, callint.c, callproc.c, config.h.in, device-msw.c, device-x.c, dired.c, doc.c, editfns.c, emacs.c, emodules.c, eval.c, event-Xt.c, event-msw.c, event-stream.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-x.c, input-method-xlib.c, intl-win32.c, lisp.h, lread.c, menubar-gtk.c, menubar-msw.c, menubar.c, mule-wnnfns.c, nt.c, objects-msw.c, process-nt.c, realpath.c, redisplay-gtk.c, redisplay-output.c, redisplay-x.c, redisplay.c, search.c, select-msw.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: Fix Raymond Toy's crash. Repeat to self: 2^21 - 1 is NOT the
same as (2 << 21) - 1.
Fix crashes due to excessive alloca(). replace alloca() with
ALLOCA(), which calls the C alloca() [which uses xmalloc()]
when the size is too big. Insert in various places calls to
try to flush the C alloca() stored info if there is any.
Add MALLOC_OR_ALLOCA(), for places that expect to be alloca()ing
large blocks. This xmalloc()s when too large and records an
unwind-protect to free -- relying on the caller to unbind_to()
elsewhere in the function. Use it in concat().
Use MALLOC instead of ALLOCA in select-msw.c.
xemacs.mak: Add alloca.o.
author | ben |
---|---|
date | Thu, 23 May 2002 11:46:46 +0000 |
parents | 3078fd1074e8 |
children | 184461bc8de4 |
line wrap: on
line diff
--- a/src/alloca.c Tue May 21 23:47:40 2002 +0000 +++ b/src/alloca.c Thu May 23 11:46:46 2002 +0000 @@ -26,36 +26,16 @@ /* Authorship: FSF: A long time ago. - Very few changes for XEmacs. + Some cleanups for XEmacs. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif -/* XEmacs: If compiling with GCC 2, this file is theoretically not needed. - However, alloca() is broken under GCC 2 on many machines: you - cannot put a call to alloca() as part of an argument to a function. - */ -/* If someone has defined alloca as a macro, - there must be some other way alloca is supposed to work. */ -/* XEmacs sometimes uses the C alloca even when a builtin alloca is available, - because it's safer. */ -#if defined (EMACS_WANTS_C_ALLOCA) || (!defined (alloca) && (!defined (__GNUC__) || __GNUC__ < 2)) - #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 */ +#include "lisp.h" +#endif /* If your stack is a linked list of frames, you have to provide an "address metric" ADDRESS_FUNCTION macro. */ @@ -67,48 +47,12 @@ #define ADDRESS_FUNCTION(arg) &(arg) #endif -#ifdef __STDC__ /* XEmacs change */ typedef void *pointer; -#else -typedef char *pointer; -#endif - -/* XEmacs: With ERROR_CHECK_MALLOC defined, there is no xfree -- it's - a macro that does some stuff to try and trap invalid frees, - and then calls xfree_1 to actually do the work. */ - -#ifdef emacs -# ifdef ERROR_CHECK_MALLOC -void xfree_1 (pointer); -# define xfree xfree_1 -# else -void xfree (pointer); -# endif -#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. */ - -#ifdef emacs -#define malloc xmalloc -#endif -#ifndef WIN32_NATIVE -extern pointer malloc (); -#else -extern void *malloc(); -#endif - /* Define STACK_DIRECTION if you know the direction of stack growth for your system; otherwise it will be automatically deduced at run-time. @@ -161,13 +105,13 @@ It is very important that sizeof(header) agree with malloc alignment chunk size. The following default should work okay. */ -#ifndef ALIGN_SIZE -#define ALIGN_SIZE sizeof(double) +#ifndef ALIGNMENT_SIZE +#define ALIGNMENT_SIZE sizeof(double) #endif typedef union hdr { - char align[ALIGN_SIZE]; /* To force sizeof(header). */ + char align[ALIGNMENT_SIZE]; /* To force sizeof(header). */ struct { union hdr *next; /* For chaining headers. */ @@ -185,12 +129,7 @@ implementations of C, for example under Gould's UTX/32. */ pointer -#ifdef EMACS_WANTS_C_ALLOCA -c_alloca (size) -#else -alloca (size) -#endif - unsigned size; +xemacs_c_alloca (unsigned int size) { auto char probe; /* Probes stack depth: */ register char *depth = ADDRESS_FUNCTION (probe); @@ -212,7 +151,11 @@ { register header *np = hp->h.next; - free ((pointer) hp); /* Collect garbage. */ +#ifdef emacs + xfree (hp); /* Collect garbage. */ +#else + free (hp); /* Collect garbage. */ +#endif hp = np; /* -> next header. */ } @@ -222,13 +165,22 @@ last_alloca_header = hp; /* -> last valid storage. */ } +#ifdef emacs + need_to_check_c_alloca = size > 0 || last_alloca_header; + recompute_funcall_allocation_flag (); +#endif + if (size == 0) return NULL; /* No allocation required. */ /* Allocate combined header + user data storage. */ { +#ifdef emacs + register pointer new = xmalloc (sizeof (header) + size); +#else register pointer new = malloc (sizeof (header) + size); +#endif /* Address of header. */ ((header *) new)->h.next = last_alloca_header; @@ -509,5 +461,3 @@ #endif /* not CRAY2 */ #endif /* CRAY */ - -#endif /* complicated expression at top of file */