Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/alloca.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    2222   your main control loop, etc. to force garbage collection.  */
    2323
     24/*
     25
     26@deftypefn Replacement void* alloca (size_t @var{size})
     27
     28This function allocates memory which will be automatically reclaimed
     29after the procedure exits.  The @libib{} implementation does not free
     30the memory immediately but will do so eventually during subsequent
     31calls to this function.  Memory is allocated using @code{xmalloc} under
     32normal circumstances.
     33
     34The header file @file{alloca-conf.h} can be used in conjunction with the
     35GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make
     36available this function.  The @code{AC_FUNC_ALLOCA} test requires that
     37client code use a block of preprocessor code to be safe (see the Autoconf
     38manual for more); this header incorporates that logic and more, including
     39the possibility of a GCC built-in function.
     40
     41@end deftypefn
     42
     43*/
     44
    2445#ifdef HAVE_CONFIG_H
    2546#include <config.h>
    2647#endif
    2748
     49#include <libiberty.h>
     50
    2851#ifdef HAVE_STRING_H
    2952#include <string.h>
     
    3356#endif
    3457
    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.  */
     60const char *libiberty_optr;
     61char *libiberty_nptr;
     62unsigned long libiberty_len;
    6063
    6164/* If your stack is a linked list of frames, you have to
     
    6366
    6467#if defined (CRAY) && defined (CRAY_STACKSEG_END)
    65 long i00afunc ();
     68static long i00afunc ();
    6669#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
    6770#else
     
    6972#endif
    7073
    71 #if __STDC__
    72 typedef void *pointer;
    73 #else
    74 typedef char *pointer;
    75 #endif
    76 
    7774#ifndef NULL
    7875#define NULL    0
    7976#endif
    80 
    81 /* Different portions of Emacs need to call different versions of
    82    malloc.  The Emacs executable needs alloca to call xmalloc, because
    83    ordinary malloc isn't protected from input signals.  On the other
    84    hand, the utilities in lib-src need alloca to call malloc; some of
    85    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 emacs
    92 #define malloc xmalloc
    93 #endif
    94 extern pointer malloc ();
    9577
    9678/* Define STACK_DIRECTION if you know the direction of stack
     
    169151   implementations of C, for example under Gould's UTX/32.  */
    170152
    171 pointer
    172 alloca (size)
    173      unsigned size;
     153/* @undocumented C_alloca */
     154
     155PTR
     156C_alloca (size)
     157     size_t size;
    174158{
    175159  auto char probe;              /* Probes stack depth: */
     
    186170  {
    187171    register header *hp;        /* Traverses linked list.  */
    188 
    189 #ifdef emacs
    190     BLOCK_INPUT;
    191 #endif
    192172
    193173    for (hp = last_alloca_header; hp != NULL;)
     
    197177          register header *np = hp->h.next;
    198178
    199           free ((pointer) hp);  /* Collect garbage.  */
     179          free ((PTR) hp);      /* Collect garbage.  */
    200180
    201181          hp = np;              /* -> next header.  */
     
    205185
    206186    last_alloca_header = hp;    /* -> last valid storage.  */
    207 
    208 #ifdef emacs
    209     UNBLOCK_INPUT;
    210 #endif
    211187  }
    212188
     
    217193
    218194  {
    219     register pointer new = malloc (sizeof (header) + size);
     195    register PTR new = xmalloc (sizeof (header) + size);
    220196    /* Address of header.  */
    221197
     
    230206    /* User storage begins just after header.  */
    231207
    232     return (pointer) ((char *) new + sizeof (header));
     208    return (PTR) ((char *) new + sizeof (header));
    233209  }
    234210}
     
    501477#endif /* not CRAY2 */
    502478#endif /* CRAY */
    503 
    504 #endif /* no alloca */
    505 #endif /* not GCC version 2 */
Note: See TracChangeset for help on using the changeset viewer.