Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
alloca.c File Reference
#include <php_config.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 char * pointer
typedef union hdr header

Functions

static void find_stack_direction ()
pointer alloca (size_t size)

Variables

static int stack_dir
static headerlast_alloca_header = NULL

Class Documentation

union hdr

Definition at line 138 of file alloca.c.

Class Members
char align
struct hdr h
struct hdr.h

Definition at line 141 of file alloca.c.

Class Members
char * deep
union hdr * next

Define Documentation

#define ADDRESS_FUNCTION (   arg)    &(arg)

Definition at line 69 of file alloca.c.

#define ALIGN_SIZE   sizeof(double)

Definition at line 135 of file alloca.c.

#define NULL   0

Definition at line 79 of file alloca.c.

#define STACK_DIR   stack_dir

Definition at line 101 of file alloca.c.

#define STACK_DIRECTION   0 /* Direction unknown. */

Definition at line 91 of file alloca.c.


Typedef Documentation

typedef union hdr header
typedef char* pointer

Definition at line 75 of file alloca.c.


Function Documentation

pointer alloca ( size_t  size)

Definition at line 158 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.  */

#ifdef emacs
    BLOCK_INPUT;
#endif

    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 ((pointer) hp);      /* Collect garbage.  */

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

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

#ifdef emacs
    UNBLOCK_INPUT;
#endif
  }

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

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

  {
    register pointer new = malloc (sizeof (header) + size);
    /* Address of header.  */

    if (new == 0)
      abort();

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

    last_alloca_header = (header *) new;

    /* User storage begins just after header.  */

    return (pointer) ((char *) new + sizeof (header));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void find_stack_direction ( ) [static]

Definition at line 104 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 148 of file alloca.c.

int stack_dir [static]

Definition at line 100 of file alloca.c.