Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions | Variables
alloca.c File Reference
#include <libiberty.h>

Go to the source code of this file.

Classes

union  hdr
struct  hdr.h

Defines

#define ADDRESS_FUNCTION(arg)   &(arg)
#define NULL   0
#define STACK_DIRECTION   0 /* Direction unknown. */
#define STACK_DIR   stack_dir
#define ALIGN_SIZE   sizeof(double)

Typedefs

typedef union hdr header

Functions

static void find_stack_direction (void)
PTR C_alloca (size_t size)

Variables

const char * libiberty_optr
char * libiberty_nptr
unsigned long libiberty_len
static int stack_dir
static headerlast_alloca_header = NULL

Class Documentation

union hdr

Definition at line 140 of file alloca.c.

Class Members
char align
struct hdr h
struct hdr.h

Definition at line 143 of file alloca.c.

Class Members
char * deep
union hdr * next

Define Documentation

#define ADDRESS_FUNCTION (   arg)    &(arg)

Definition at line 77 of file alloca.c.

#define ALIGN_SIZE   sizeof(double)

Definition at line 137 of file alloca.c.

#define NULL   0

Definition at line 81 of file alloca.c.

#define STACK_DIR   stack_dir

Definition at line 103 of file alloca.c.

#define STACK_DIRECTION   0 /* Direction unknown. */

Definition at line 93 of file alloca.c.


Typedef Documentation

typedef union hdr header

Function Documentation

PTR C_alloca ( size_t  size)

Definition at line 162 of file alloca.c.

{
  auto char probe;          /* Probes stack depth: */
  register char *depth = ADDRESS_FUNCTION (probe);

#if STACK_DIRECTION == 0
  if (STACK_DIR == 0)              /* Unknown growth direction.  */
    find_stack_direction ();
#endif

  /* Reclaim garbage, defined as all alloca'd storage that
     was allocated from deeper in the stack than currently.  */

  {
    register header *hp;    /* Traverses linked list.  */

    for (hp = last_alloca_header; hp != NULL;)
      if ((STACK_DIR > 0 && hp->h.deep > depth)
         || (STACK_DIR < 0 && hp->h.deep < depth))
       {
         register header *np = hp->h.next;

         free ((PTR) hp);   /* Collect garbage.  */

         hp = np;           /* -> next header.  */
       }
      else
       break;               /* Rest are not deeper.  */

    last_alloca_header = hp;       /* -> last valid storage.  */
  }

  if (size == 0)
    return NULL;            /* No allocation required.  */

  /* Allocate combined header + user data storage.  */

  {
    register void *new_storage = XNEWVEC (char, sizeof (header) + size);
    /* Address of header.  */

    if (new_storage == 0)
      abort();

    ((header *) new_storage)->h.next = last_alloca_header;
    ((header *) new_storage)->h.deep = depth;

    last_alloca_header = (header *) new_storage;

    /* User storage begins just after header.  */

    return (PTR) ((char *) new_storage + sizeof (header));
  }
}

Here is the call graph for this function:

static void find_stack_direction ( void  ) [static]

Definition at line 106 of file alloca.c.

{
  static char *addr = NULL; /* Address of first `dummy', once known.  */
  auto char dummy;          /* To get stack address.  */

  if (addr == NULL)
    {                       /* Initial entry.  */
      addr = ADDRESS_FUNCTION (dummy);

      find_stack_direction ();     /* Recurse once.  */
    }
  else
    {
      /* Second entry.  */
      if (ADDRESS_FUNCTION (dummy) > addr)
       stack_dir = 1;              /* Stack grew upward.  */
      else
       stack_dir = -1;             /* Stack grew downward.  */
    }
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 150 of file alloca.c.

Definition at line 65 of file alloca.c.

Definition at line 64 of file alloca.c.

Definition at line 63 of file alloca.c.

int stack_dir [static]

Definition at line 102 of file alloca.c.