comparison src/alloca.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 3ecd8885ac67
children 3078fd1074e8
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
21 allocating any. It is a good idea to use alloca(0) in 21 allocating any. It is a good idea to use alloca(0) in
22 your main control loop, etc. to force garbage collection. */ 22 your main control loop, etc. to force garbage collection. */
23 23
24 /* Synched up with: FSF 19.30. */ 24 /* Synched up with: FSF 19.30. */
25 25
26 /* Authorsip: 26 /* Authorship:
27 27
28 FSF: A long time ago. 28 FSF: A long time ago.
29 Very few changes for XEmacs. 29 Very few changes for XEmacs.
30 */ 30 */
31 31
84 # else 84 # else
85 void xfree (pointer); 85 void xfree (pointer);
86 # endif 86 # endif
87 #endif 87 #endif
88 88
89 #ifndef WINDOWSNT 89 #ifndef NULL
90 #define NULL 0 90 #define NULL 0
91 #endif 91 #endif
92 92
93 /* Different portions of Emacs need to call different versions of 93 /* Different portions of Emacs need to call different versions of
94 malloc. The Emacs executable needs alloca to call xmalloc, because 94 malloc. The Emacs executable needs alloca to call xmalloc, because
101 Callers below should use malloc. */ 101 Callers below should use malloc. */
102 102
103 #ifndef emacs 103 #ifndef emacs
104 #define malloc xmalloc 104 #define malloc xmalloc
105 #endif 105 #endif
106 #ifndef WINDOWSNT 106 #ifndef WIN32_NATIVE
107 extern pointer malloc (); 107 extern pointer malloc ();
108 #else 108 #else
109 extern void *malloc(); 109 extern void *malloc();
110 #endif 110 #endif
111 111
191 alloca (size) 191 alloca (size)
192 #endif 192 #endif
193 unsigned size; 193 unsigned size;
194 { 194 {
195 auto char probe; /* Probes stack depth: */ 195 auto char probe; /* Probes stack depth: */
196 REGISTER char *depth = ADDRESS_FUNCTION (probe); 196 register char *depth = ADDRESS_FUNCTION (probe);
197 197
198 #if STACK_DIRECTION == 0 198 #if STACK_DIRECTION == 0
199 if (STACK_DIR == 0) /* Unknown growth direction. */ 199 if (STACK_DIR == 0) /* Unknown growth direction. */
200 find_stack_direction (); 200 find_stack_direction ();
201 #endif 201 #endif
202 202
203 /* Reclaim garbage, defined as all alloca'd storage that 203 /* Reclaim garbage, defined as all alloca'd storage that
204 was allocated from deeper in the stack than currently. */ 204 was allocated from deeper in the stack than currently. */
205 205
206 { 206 {
207 REGISTER header *hp; /* Traverses linked list. */ 207 register header *hp; /* Traverses linked list. */
208 208
209 for (hp = last_alloca_header; hp != NULL;) 209 for (hp = last_alloca_header; hp != NULL;)
210 if ((STACK_DIR > 0 && hp->h.deep > depth) 210 if ((STACK_DIR > 0 && hp->h.deep > depth)
211 || (STACK_DIR < 0 && hp->h.deep < depth)) 211 || (STACK_DIR < 0 && hp->h.deep < depth))
212 { 212 {
213 REGISTER header *np = hp->h.next; 213 register header *np = hp->h.next;
214 214
215 free ((pointer) hp); /* Collect garbage. */ 215 free ((pointer) hp); /* Collect garbage. */
216 216
217 hp = np; /* -> next header. */ 217 hp = np; /* -> next header. */
218 } 218 }
226 return NULL; /* No allocation required. */ 226 return NULL; /* No allocation required. */
227 227
228 /* Allocate combined header + user data storage. */ 228 /* Allocate combined header + user data storage. */
229 229
230 { 230 {
231 REGISTER pointer new = malloc (sizeof (header) + size); 231 register pointer new = malloc (sizeof (header) + size);
232 /* Address of header. */ 232 /* Address of header. */
233 233
234 ((header *) new)->h.next = last_alloca_header; 234 ((header *) new)->h.next = last_alloca_header;
235 ((header *) new)->h.deep = depth; 235 ((header *) new)->h.deep = depth;
236 236