Mercurial > hg > xemacs-beta
comparison 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 |
comparison
equal
deleted
inserted
replaced
850:f915ad7befaf | 851:e7ee5f8bde58 |
---|---|
24 /* Synched up with: FSF 19.30. */ | 24 /* Synched up with: FSF 19.30. */ |
25 | 25 |
26 /* Authorship: | 26 /* Authorship: |
27 | 27 |
28 FSF: A long time ago. | 28 FSF: A long time ago. |
29 Very few changes for XEmacs. | 29 Some cleanups for XEmacs. |
30 */ | 30 */ |
31 | 31 |
32 #ifdef HAVE_CONFIG_H | 32 #ifdef HAVE_CONFIG_H |
33 #include <config.h> | 33 #include <config.h> |
34 #endif | 34 #endif |
35 | 35 |
36 /* XEmacs: If compiling with GCC 2, this file is theoretically not needed. | |
37 However, alloca() is broken under GCC 2 on many machines: you | |
38 cannot put a call to alloca() as part of an argument to a function. | |
39 */ | |
40 /* If someone has defined alloca as a macro, | |
41 there must be some other way alloca is supposed to work. */ | |
42 /* XEmacs sometimes uses the C alloca even when a builtin alloca is available, | |
43 because it's safer. */ | |
44 #if defined (EMACS_WANTS_C_ALLOCA) || (!defined (alloca) && (!defined (__GNUC__) || __GNUC__ < 2)) | |
45 | |
46 #ifdef emacs | 36 #ifdef emacs |
47 #ifdef static | 37 #include "lisp.h" |
48 /* actually, only want this if static is defined as "" | 38 #endif |
49 -- this is for usg, in which emacs must undefine static | |
50 in order to make unexec workable | |
51 */ | |
52 #ifndef STACK_DIRECTION | |
53 you | |
54 lose | |
55 -- must know STACK_DIRECTION at compile-time | |
56 #endif /* STACK_DIRECTION undefined */ | |
57 #endif /* static */ | |
58 #endif /* emacs */ | |
59 | 39 |
60 /* If your stack is a linked list of frames, you have to | 40 /* If your stack is a linked list of frames, you have to |
61 provide an "address metric" ADDRESS_FUNCTION macro. */ | 41 provide an "address metric" ADDRESS_FUNCTION macro. */ |
62 | 42 |
63 #if defined (CRAY) && defined (CRAY_STACKSEG_END) | 43 #if defined (CRAY) && defined (CRAY_STACKSEG_END) |
65 #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) | 45 #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) |
66 #else | 46 #else |
67 #define ADDRESS_FUNCTION(arg) &(arg) | 47 #define ADDRESS_FUNCTION(arg) &(arg) |
68 #endif | 48 #endif |
69 | 49 |
70 #ifdef __STDC__ /* XEmacs change */ | |
71 typedef void *pointer; | 50 typedef void *pointer; |
72 #else | |
73 typedef char *pointer; | |
74 #endif | |
75 | |
76 /* XEmacs: With ERROR_CHECK_MALLOC defined, there is no xfree -- it's | |
77 a macro that does some stuff to try and trap invalid frees, | |
78 and then calls xfree_1 to actually do the work. */ | |
79 | |
80 #ifdef emacs | |
81 # ifdef ERROR_CHECK_MALLOC | |
82 void xfree_1 (pointer); | |
83 # define xfree xfree_1 | |
84 # else | |
85 void xfree (pointer); | |
86 # endif | |
87 #endif | |
88 | 51 |
89 #ifndef NULL | 52 #ifndef NULL |
90 #define NULL 0 | 53 #define NULL 0 |
91 #endif | |
92 | |
93 /* Different portions of Emacs need to call different versions of | |
94 malloc. The Emacs executable needs alloca to call xmalloc, because | |
95 ordinary malloc isn't protected from input signals. On the other | |
96 hand, the utilities in lib-src need alloca to call malloc; some of | |
97 them are very simple, and don't have an xmalloc routine. | |
98 | |
99 Non-Emacs programs expect this to call use xmalloc. | |
100 | |
101 Callers below should use malloc. */ | |
102 | |
103 #ifdef emacs | |
104 #define malloc xmalloc | |
105 #endif | |
106 #ifndef WIN32_NATIVE | |
107 extern pointer malloc (); | |
108 #else | |
109 extern void *malloc(); | |
110 #endif | 54 #endif |
111 | 55 |
112 /* Define STACK_DIRECTION if you know the direction of stack | 56 /* Define STACK_DIRECTION if you know the direction of stack |
113 growth for your system; otherwise it will be automatically | 57 growth for your system; otherwise it will be automatically |
114 deduced at run-time. | 58 deduced at run-time. |
159 (b) keep track of stack depth. | 103 (b) keep track of stack depth. |
160 | 104 |
161 It is very important that sizeof(header) agree with malloc | 105 It is very important that sizeof(header) agree with malloc |
162 alignment chunk size. The following default should work okay. */ | 106 alignment chunk size. The following default should work okay. */ |
163 | 107 |
164 #ifndef ALIGN_SIZE | 108 #ifndef ALIGNMENT_SIZE |
165 #define ALIGN_SIZE sizeof(double) | 109 #define ALIGNMENT_SIZE sizeof(double) |
166 #endif | 110 #endif |
167 | 111 |
168 typedef union hdr | 112 typedef union hdr |
169 { | 113 { |
170 char align[ALIGN_SIZE]; /* To force sizeof(header). */ | 114 char align[ALIGNMENT_SIZE]; /* To force sizeof(header). */ |
171 struct | 115 struct |
172 { | 116 { |
173 union hdr *next; /* For chaining headers. */ | 117 union hdr *next; /* For chaining headers. */ |
174 char *deep; /* For stack depth measure. */ | 118 char *deep; /* For stack depth measure. */ |
175 } h; | 119 } h; |
183 was supposed to be taken from the current stack frame of the | 127 was supposed to be taken from the current stack frame of the |
184 caller, but that method cannot be made to work for some | 128 caller, but that method cannot be made to work for some |
185 implementations of C, for example under Gould's UTX/32. */ | 129 implementations of C, for example under Gould's UTX/32. */ |
186 | 130 |
187 pointer | 131 pointer |
188 #ifdef EMACS_WANTS_C_ALLOCA | 132 xemacs_c_alloca (unsigned int size) |
189 c_alloca (size) | |
190 #else | |
191 alloca (size) | |
192 #endif | |
193 unsigned size; | |
194 { | 133 { |
195 auto char probe; /* Probes stack depth: */ | 134 auto char probe; /* Probes stack depth: */ |
196 register char *depth = ADDRESS_FUNCTION (probe); | 135 register char *depth = ADDRESS_FUNCTION (probe); |
197 | 136 |
198 #if STACK_DIRECTION == 0 | 137 #if STACK_DIRECTION == 0 |
210 if ((STACK_DIR > 0 && hp->h.deep > depth) | 149 if ((STACK_DIR > 0 && hp->h.deep > depth) |
211 || (STACK_DIR < 0 && hp->h.deep < depth)) | 150 || (STACK_DIR < 0 && hp->h.deep < depth)) |
212 { | 151 { |
213 register header *np = hp->h.next; | 152 register header *np = hp->h.next; |
214 | 153 |
215 free ((pointer) hp); /* Collect garbage. */ | 154 #ifdef emacs |
155 xfree (hp); /* Collect garbage. */ | |
156 #else | |
157 free (hp); /* Collect garbage. */ | |
158 #endif | |
216 | 159 |
217 hp = np; /* -> next header. */ | 160 hp = np; /* -> next header. */ |
218 } | 161 } |
219 else | 162 else |
220 break; /* Rest are not deeper. */ | 163 break; /* Rest are not deeper. */ |
221 | 164 |
222 last_alloca_header = hp; /* -> last valid storage. */ | 165 last_alloca_header = hp; /* -> last valid storage. */ |
223 } | 166 } |
224 | 167 |
168 #ifdef emacs | |
169 need_to_check_c_alloca = size > 0 || last_alloca_header; | |
170 recompute_funcall_allocation_flag (); | |
171 #endif | |
172 | |
225 if (size == 0) | 173 if (size == 0) |
226 return NULL; /* No allocation required. */ | 174 return NULL; /* No allocation required. */ |
227 | 175 |
228 /* Allocate combined header + user data storage. */ | 176 /* Allocate combined header + user data storage. */ |
229 | 177 |
230 { | 178 { |
179 #ifdef emacs | |
180 register pointer new = xmalloc (sizeof (header) + size); | |
181 #else | |
231 register pointer new = malloc (sizeof (header) + size); | 182 register pointer new = malloc (sizeof (header) + size); |
183 #endif | |
232 /* Address of header. */ | 184 /* Address of header. */ |
233 | 185 |
234 ((header *) new)->h.next = last_alloca_header; | 186 ((header *) new)->h.next = last_alloca_header; |
235 ((header *) new)->h.deep = depth; | 187 ((header *) new)->h.deep = depth; |
236 | 188 |
507 return (result); | 459 return (result); |
508 } | 460 } |
509 | 461 |
510 #endif /* not CRAY2 */ | 462 #endif /* not CRAY2 */ |
511 #endif /* CRAY */ | 463 #endif /* CRAY */ |
512 | |
513 #endif /* complicated expression at top of file */ |