Changeset 3553 for branches/2.2/src/alloca.c
- Timestamp:
- 11/21/04 09:53:25 (4 years ago)
- Files:
-
- branches/2.2/src/alloca.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.2/src/alloca.c
r3104 r3553 1 1 /* alloca.c -- allocate automatically reclaimed memory 2 2 (Mostly) portable public-domain implementation -- D A Gwyn 3 4 NOTE: The canonical source of this file is maintained with gnulib. 5 Bugs can be reported to bug-gnulib@gnu.org. 3 6 4 7 This implementation of the PWB library alloca function, … … 23 26 24 27 #ifdef HAVE_CONFIG_H 25 # include <config.h>28 # include <config.h> 26 29 #endif 27 30 28 31 #ifdef HAVE_STRING_H 29 # include <string.h>32 # include <string.h> 30 33 #endif 31 34 #ifdef HAVE_STDLIB_H 32 # include <stdlib.h>35 # include <stdlib.h> 33 36 #endif 34 37 35 #ifdef emacs 36 #include "lisp.h" 37 #include "blockinput.h" 38 #ifdef DO_BLOCK_INPUT 39 # include "blockinput.h" 38 40 #endif 39 41 … … 43 45 /* If someone has defined alloca as a macro, 44 46 there must be some other way alloca is supposed to work. */ 45 # ifndef alloca46 47 # ifdef emacs48 # ifdef static47 # ifndef alloca 48 49 # ifdef emacs 50 # ifdef static 49 51 /* actually, only want this if static is defined as "" 50 52 -- this is for usg, in which emacs must undefine static 51 53 in order to make unexec workable 52 54 */ 53 #ifndef STACK_DIRECTION 54 #error "Must know STACK_DIRECTION at compile-time" 55 #endif /* STACK_DIRECTION undefined */ 56 #endif /* static */ 57 #endif /* emacs */ 55 # ifndef STACK_DIRECTION 56 you 57 lose 58 -- must know STACK_DIRECTION at compile-time 59 /* Using #error here is not wise since this file should work for 60 old and obscure compilers. 61 62 As far as I know, using it is OK if it's indented -- at least for 63 pcc-based processors. -- fx */ 64 # endif /* STACK_DIRECTION undefined */ 65 # endif /* static */ 66 # endif /* emacs */ 58 67 59 68 /* If your stack is a linked list of frames, you have to 60 69 provide an "address metric" ADDRESS_FUNCTION macro. */ 61 70 62 # if defined (CRAY) && defined (CRAY_STACKSEG_END)71 # if defined (CRAY) && defined (CRAY_STACKSEG_END) 63 72 long i00afunc (); 64 #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) 65 #else 66 #define ADDRESS_FUNCTION(arg) &(arg) 67 #endif 68 69 #ifdef POINTER_TYPE 73 # define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) 74 # else 75 # define ADDRESS_FUNCTION(arg) &(arg) 76 # endif 77 78 # ifndef POINTER_TYPE 79 # ifdef __STDC__ 80 # define POINTER_TYPE void 81 # else 82 # define POINTER_TYPE char 83 # endif 84 # endif 70 85 typedef POINTER_TYPE *pointer; 71 #else 72 #if __STDC__ 73 typedef void *pointer; 74 #else 75 typedef char *pointer; 76 #endif /*__STDC__*/ 77 #endif /*POINTER_TYPE*/ 78 79 80 #ifndef NULL 81 #define NULL 0 82 #endif 83 84 /* Different portions of Emacs need to call different versions of 85 malloc. The Emacs executable needs alloca to call xmalloc, because 86 ordinary malloc isn't protected from input signals. On the other 87 hand, the utilities in lib-src need alloca to call malloc; some of 88 them are very simple, and don't have an xmalloc routine. 89 90 Non-Emacs programs expect this to call use xmalloc. 86 87 # ifndef NULL 88 # define NULL 0 89 # endif 90 91 /* The Emacs executable needs alloca to call xmalloc, because ordinary 92 malloc isn't protected from input signals. xmalloc also checks for 93 out-of-memory errors, so we should use it generally. 91 94 92 95 Callers below should use malloc. */ 93 96 94 # ifdef emacs95 # define malloc xmalloc96 # ifdef EMACS_FREE97 # define free EMACS_FREE98 #endif 99 #endif 100 extern pointer malloc ();97 # undef malloc 98 # define malloc xmalloc 99 # undef free 100 # define free xfree 101 102 void *xmalloc _P ((size_t)); 103 void xfree _P ((void *)); 101 104 102 105 /* Define STACK_DIRECTION if you know the direction of stack … … 108 111 STACK_DIRECTION = 0 => direction of growth unknown */ 109 112 110 # ifndef STACK_DIRECTION111 # defineSTACK_DIRECTION 0 /* Direction unknown. */112 # endif113 114 # if STACK_DIRECTION != 0115 116 # defineSTACK_DIR STACK_DIRECTION /* Known at compile-time. */117 118 # else /* STACK_DIRECTION == 0; need run-time code. */113 # ifndef STACK_DIRECTION 114 # define STACK_DIRECTION 0 /* Direction unknown. */ 115 # endif 116 117 # if STACK_DIRECTION != 0 118 119 # define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ 120 121 # else /* STACK_DIRECTION == 0; need run-time code. */ 119 122 120 123 static int stack_dir; /* 1 or -1 once known. */ 121 # defineSTACK_DIR stack_dir124 # define STACK_DIR stack_dir 122 125 123 126 static void … … 143 146 } 144 147 145 # endif /* STACK_DIRECTION == 0 */148 # endif /* STACK_DIRECTION == 0 */ 146 149 147 150 /* An "alloca header" is used to: … … 152 155 alignment chunk size. The following default should work okay. */ 153 156 154 # ifndef ALIGN_SIZE155 # defineALIGN_SIZE sizeof(double)156 # endif157 # ifndef ALIGN_SIZE 158 # define ALIGN_SIZE sizeof(double) 159 # endif 157 160 158 161 typedef union hdr … … 177 180 pointer 178 181 alloca (size) 179 unsignedsize;182 size_t size; 180 183 { 181 184 auto char probe; /* Probes stack depth: */ 182 185 register char *depth = ADDRESS_FUNCTION (probe); 183 186 184 # if STACK_DIRECTION == 0187 # if STACK_DIRECTION == 0 185 188 if (STACK_DIR == 0) /* Unknown growth direction. */ 186 189 find_stack_direction (); 187 # endif190 # endif 188 191 189 192 /* Reclaim garbage, defined as all alloca'd storage that … … 193 196 register header *hp; /* Traverses linked list. */ 194 197 195 # ifdef emacs198 # ifdef DO_BLOCK_INPUT 196 199 BLOCK_INPUT; 197 # endif200 # endif 198 201 199 202 for (hp = last_alloca_header; hp != NULL;) … … 212 215 last_alloca_header = hp; /* -> last valid storage. */ 213 216 214 # ifdef emacs217 # ifdef DO_BLOCK_INPUT 215 218 UNBLOCK_INPUT; 216 # endif219 # endif 217 220 } 218 221 … … 223 226 224 227 { 228 /* Address of header. */ 225 229 register pointer new = malloc (sizeof (header) + size); 226 /* Address of header. */227 230 228 231 if (new == 0) … … 240 243 } 241 244 242 # if defined (CRAY) && defined (CRAY_STACKSEG_END)243 244 # ifdef DEBUG_I00AFUNC245 # include <stdio.h>246 # endif247 248 # ifndef CRAY_STACK249 # define CRAY_STACK250 # ifndef CRAY2245 # if defined (CRAY) && defined (CRAY_STACKSEG_END) 246 247 # ifdef DEBUG_I00AFUNC 248 # include <stdio.h> 249 # endif 250 251 # ifndef CRAY_STACK 252 # define CRAY_STACK 253 # ifndef CRAY2 251 254 /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ 252 255 struct stack_control_header … … 300 303 }; 301 304 302 # else /* CRAY2 */305 # else /* CRAY2 */ 303 306 /* The following structure defines the vector of words 304 307 returned by the STKSTAT library routine. */ … … 353 356 }; 354 357 355 # endif /* CRAY2 */356 # endif /* not CRAY_STACK */357 358 # ifdef CRAY2358 # endif /* CRAY2 */ 359 # endif /* not CRAY_STACK */ 360 361 # ifdef CRAY2 359 362 /* Determine a "stack measure" for an arbitrary ADDRESS. 360 363 I doubt that "lint" will like this much. */ … … 427 430 } 428 431 429 # else /* not CRAY2 */432 # else /* not CRAY2 */ 430 433 /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. 431 434 Determine the number of the cell within the stack, … … 472 475 while (!(this_segment <= address && address <= stkl)) 473 476 { 474 # ifdef DEBUG_I00AFUNC477 # ifdef DEBUG_I00AFUNC 475 478 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); 476 # endif479 # endif 477 480 if (pseg == 0) 478 481 break; … … 493 496 while (pseg != 0) 494 497 { 495 # ifdef DEBUG_I00AFUNC498 # ifdef DEBUG_I00AFUNC 496 499 fprintf (stderr, "%011o %011o\n", pseg, size); 497 # endif500 # endif 498 501 stkl = stkl - pseg; 499 502 ssptr = (struct stack_segment_linkage *) stkl; … … 505 508 } 506 509 507 # endif /* not CRAY2 */508 # endif /* CRAY */509 510 # endif /* no alloca */510 # endif /* not CRAY2 */ 511 # endif /* CRAY */ 512 513 # endif /* no alloca */ 511 514 #endif /* not GCC version 2 */ 515 516 /* arch-tag: 5c9901c8-3cd4-453e-bd66-d9035a175ee3 517 (do not change this comment) */
