Changeset 609 for branches/GNU/src/binutils/libiberty/alloca.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/libiberty/alloca.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 22 22 your main control loop, etc. to force garbage collection. */ 23 23 24 /* 25 26 @deftypefn Replacement void* alloca (size_t @var{size}) 27 28 This function allocates memory which will be automatically reclaimed 29 after the procedure exits. The @libib{} implementation does not free 30 the memory immediately but will do so eventually during subsequent 31 calls to this function. Memory is allocated using @code{xmalloc} under 32 normal circumstances. 33 34 The header file @file{alloca-conf.h} can be used in conjunction with the 35 GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make 36 available this function. The @code{AC_FUNC_ALLOCA} test requires that 37 client code use a block of preprocessor code to be safe (see the Autoconf 38 manual for more); this header incorporates that logic and more, including 39 the possibility of a GCC built-in function. 40 41 @end deftypefn 42 43 */ 44 24 45 #ifdef HAVE_CONFIG_H 25 46 #include <config.h> 26 47 #endif 27 48 49 #include <libiberty.h> 50 28 51 #ifdef HAVE_STRING_H 29 52 #include <string.h> … … 33 56 #endif 34 57 35 #ifdef emacs 36 #include "blockinput.h" 37 #endif 38 39 /* If compiling with GCC 2, this file's not needed. Except of course if 40 the C alloca is explicitly requested. */ 41 #if defined (USE_C_ALLOCA) || !defined (__GNUC__) || __GNUC__ < 2 42 43 /* If someone has defined alloca as a macro, 44 there must be some other way alloca is supposed to work. */ 45 #ifndef alloca 46 47 #ifdef emacs 48 #ifdef static 49 /* actually, only want this if static is defined as "" 50 -- this is for usg, in which emacs must undefine static 51 in order to make unexec workable 52 */ 53 #ifndef STACK_DIRECTION 54 you 55 lose 56 -- must know STACK_DIRECTION at compile-time 57 #endif /* STACK_DIRECTION undefined */ 58 #endif /* static */ 59 #endif /* emacs */ 58 /* These variables are used by the ASTRDUP implementation that relies 59 on C_alloca. */ 60 const char *libiberty_optr; 61 char *libiberty_nptr; 62 unsigned long libiberty_len; 60 63 61 64 /* If your stack is a linked list of frames, you have to … … 63 66 64 67 #if defined (CRAY) && defined (CRAY_STACKSEG_END) 65 long i00afunc ();68 static long i00afunc (); 66 69 #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) 67 70 #else … … 69 72 #endif 70 73 71 #if __STDC__72 typedef void *pointer;73 #else74 typedef char *pointer;75 #endif76 77 74 #ifndef NULL 78 75 #define NULL 0 79 76 #endif 80 81 /* Different portions of Emacs need to call different versions of82 malloc. The Emacs executable needs alloca to call xmalloc, because83 ordinary malloc isn't protected from input signals. On the other84 hand, the utilities in lib-src need alloca to call malloc; some of85 them are very simple, and don't have an xmalloc routine.86 87 Non-Emacs programs expect this to call use xmalloc.88 89 Callers below should use malloc. */90 91 #ifndef emacs92 #define malloc xmalloc93 #endif94 extern pointer malloc ();95 77 96 78 /* Define STACK_DIRECTION if you know the direction of stack … … 169 151 implementations of C, for example under Gould's UTX/32. */ 170 152 171 pointer 172 alloca (size) 173 unsigned size; 153 /* @undocumented C_alloca */ 154 155 PTR 156 C_alloca (size) 157 size_t size; 174 158 { 175 159 auto char probe; /* Probes stack depth: */ … … 186 170 { 187 171 register header *hp; /* Traverses linked list. */ 188 189 #ifdef emacs190 BLOCK_INPUT;191 #endif192 172 193 173 for (hp = last_alloca_header; hp != NULL;) … … 197 177 register header *np = hp->h.next; 198 178 199 free (( pointer) hp); /* Collect garbage. */179 free ((PTR) hp); /* Collect garbage. */ 200 180 201 181 hp = np; /* -> next header. */ … … 205 185 206 186 last_alloca_header = hp; /* -> last valid storage. */ 207 208 #ifdef emacs209 UNBLOCK_INPUT;210 #endif211 187 } 212 188 … … 217 193 218 194 { 219 register pointer new =malloc (sizeof (header) + size);195 register PTR new = xmalloc (sizeof (header) + size); 220 196 /* Address of header. */ 221 197 … … 230 206 /* User storage begins just after header. */ 231 207 232 return ( pointer) ((char *) new + sizeof (header));208 return (PTR) ((char *) new + sizeof (header)); 233 209 } 234 210 } … … 501 477 #endif /* not CRAY2 */ 502 478 #endif /* CRAY */ 503 504 #endif /* no alloca */505 #endif /* not GCC version 2 */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.