Back to index

glibc  2.9
Classes | Defines | Functions | Variables
obstack.h File Reference
#include <stddef.h>
#include <string.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _obstack_chunk
struct  obstack
union  obstack.temp

Defines

#define PTR_INT_TYPE   ptrdiff_t
#define __BPTR_ALIGN(B, P, A)   ((B) + (((P) - (B) + (A)) & ~(A)))
#define __PTR_ALIGN(B, P, A)
#define obstack_base(h)   ((void *) (h)->object_base)
#define obstack_chunk_size(h)   ((h)->chunk_size)
#define obstack_next_free(h)   ((h)->next_free)
#define obstack_alignment_mask(h)   ((h)->alignment_mask)
#define obstack_init(h)
#define obstack_begin(h, size)
#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun)
#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg)
#define obstack_chunkfun(h, newchunkfun)   ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
#define obstack_freefun(h, newfreefun)   ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
#define obstack_1grow_fast(h, achar)   (*((h)->next_free)++ = (achar))
#define obstack_blank_fast(h, n)   ((h)->next_free += (n))
#define obstack_memory_used(h)   _obstack_memory_used (h)
#define obstack_object_size(h)   (unsigned) ((h)->next_free - (h)->object_base)
#define obstack_room(h)   (unsigned) ((h)->chunk_limit - (h)->next_free)
#define obstack_empty_p(h)
#define obstack_make_room(h, length)
#define obstack_grow(h, where, length)
#define obstack_grow0(h, where, length)
#define obstack_1grow(h, datum)
#define obstack_ptr_grow(h, datum)
#define obstack_int_grow(h, datum)
#define obstack_ptr_grow_fast(h, aptr)   (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
#define obstack_int_grow_fast(h, aint)   (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
#define obstack_blank(h, length)
#define obstack_alloc(h, length)   (obstack_blank ((h), (length)), obstack_finish ((h)))
#define obstack_copy(h, where, length)   (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
#define obstack_copy0(h, where, length)   (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
#define obstack_finish(h)
#define obstack_free(h, obj)

Functions

void _obstack_newchunk (struct obstack *, int)
int _obstack_begin (struct obstack *, int, int, void *(*)(long), void(*)(void *))
int _obstack_begin_1 (struct obstack *, int, int, void *(*)(void *, long), void(*)(void *, void *), void *)
int _obstack_memory_used (struct obstack *)
void obstack_free (struct obstack *obstack, void *block)

Variables

void(* obstack_alloc_failed_handler )(void)
int obstack_exit_failure

Class Documentation

struct _obstack_chunk

Definition at line 144 of file obstack.h.

Collaboration diagram for _obstack_chunk:
Class Members
char contents
char * limit
struct _obstack_chunk * prev
union obstack.temp

Definition at line 158 of file obstack.h.

Class Members
PTR_INT_TYPE tempint
void * tempptr

Define Documentation

#define __BPTR_ALIGN (   B,
  P,
  A 
)    ((B) + (((P) - (B) + (A)) & ~(A)))

Definition at line 129 of file obstack.h.

#define __PTR_ALIGN (   B,
  P,
  A 
)
Value:
__BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
              P, A)

Definition at line 138 of file obstack.h.

#define obstack_1grow (   h,
  datum 
)
Value:
( (((h)->next_free + 1 > (h)->chunk_limit)                            \
   ? (_obstack_newchunk ((h), 1), 0) : 0),                            \
  obstack_1grow_fast (h, datum))

Definition at line 445 of file obstack.h.

#define obstack_1grow_fast (   h,
  achar 
)    (*((h)->next_free)++ = (achar))

Definition at line 247 of file obstack.h.

#define obstack_alignment_mask (   h)    ((h)->alignment_mask)

Definition at line 218 of file obstack.h.

#define obstack_alloc (   h,
  length 
)    (obstack_blank ((h), (length)), obstack_finish ((h)))

Definition at line 472 of file obstack.h.

#define obstack_base (   h)    ((void *) (h)->object_base)

Definition at line 206 of file obstack.h.

#define obstack_begin (   h,
  size 
)
Value:
_obstack_begin ((h), (size), 0,                         \
                (void *(*) (long)) obstack_chunk_alloc, \
                (void (*) (void *)) obstack_chunk_free)

Definition at line 226 of file obstack.h.

#define obstack_blank (   h,
  length 
)
Value:
( (h)->temp.tempint = (length),                                       \
  (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint)            \
   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),            \
  obstack_blank_fast (h, (h)->temp.tempint))

Definition at line 466 of file obstack.h.

#define obstack_blank_fast (   h,
  n 
)    ((h)->next_free += (n))

Definition at line 249 of file obstack.h.

#define obstack_chunk_size (   h)    ((h)->chunk_size)

Definition at line 210 of file obstack.h.

#define obstack_chunkfun (   h,
  newchunkfun 
)    ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))

Definition at line 241 of file obstack.h.

#define obstack_copy (   h,
  where,
  length 
)    (obstack_grow ((h), (where), (length)), obstack_finish ((h)))

Definition at line 475 of file obstack.h.

#define obstack_copy0 (   h,
  where,
  length 
)    (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))

Definition at line 478 of file obstack.h.

#define obstack_empty_p (   h)
Value:
((h)->chunk->prev == 0                                                \
  && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk,              \
                                (h)->chunk->contents,          \
                                (h)->alignment_mask))

Definition at line 413 of file obstack.h.

#define obstack_finish (   h)
Value:
( ((h)->next_free == (h)->object_base                                 \
   ? (((h)->maybe_empty_object = 1), 0)                               \
   : 0),                                                       \
  (h)->temp.tempptr = (h)->object_base,                               \
  (h)->next_free                                               \
    = __PTR_ALIGN ((h)->object_base, (h)->next_free,                  \
                 (h)->alignment_mask),                         \
  (((h)->next_free - (char *) (h)->chunk                       \
    > (h)->chunk_limit - (char *) (h)->chunk)                         \
   ? ((h)->next_free = (h)->chunk_limit) : 0),                        \
  (h)->object_base = (h)->next_free,                                  \
  (h)->temp.tempptr)

Definition at line 481 of file obstack.h.

#define obstack_free (   h,
  obj 
)
Value:
( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,           \
  ((((h)->temp.tempint > 0                                     \
    && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))   \
   ? (int) ((h)->next_free = (h)->object_base                         \
           = (h)->temp.tempint + (char *) (h)->chunk)                 \
   : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))

Definition at line 495 of file obstack.h.

#define obstack_freefun (   h,
  newfreefun 
)    ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))

Definition at line 244 of file obstack.h.

#define obstack_grow (   h,
  where,
  length 
)
Value:
( (h)->temp.tempint = (length),                                       \
  (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)            \
   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),            \
  memcpy ((h)->next_free, where, (h)->temp.tempint),                  \
  (h)->next_free += (h)->temp.tempint)

Definition at line 430 of file obstack.h.

#define obstack_grow0 (   h,
  where,
  length 
)
Value:
( (h)->temp.tempint = (length),                                       \
  (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit)        \
   ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0),        \
  memcpy ((h)->next_free, where, (h)->temp.tempint),                  \
  (h)->next_free += (h)->temp.tempint,                                \
  *((h)->next_free)++ = 0)

Definition at line 437 of file obstack.h.

#define obstack_init (   h)
Value:
_obstack_begin ((h), 0, 0,                              \
                (void *(*) (long)) obstack_chunk_alloc, \
                (void (*) (void *)) obstack_chunk_free)

Definition at line 221 of file obstack.h.

#define obstack_int_grow (   h,
  datum 
)
Value:
( (((h)->next_free + sizeof (int) > (h)->chunk_limit)                 \
   ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0),                 \
  obstack_int_grow_fast (h, datum))

Definition at line 455 of file obstack.h.

#define obstack_int_grow_fast (   h,
  aint 
)    (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))

Definition at line 463 of file obstack.h.

#define obstack_make_room (   h,
  length 
)
Value:
( (h)->temp.tempint = (length),                                       \
  (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)            \
   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))

Definition at line 425 of file obstack.h.

Definition at line 251 of file obstack.h.

#define obstack_next_free (   h)    ((h)->next_free)

Definition at line 214 of file obstack.h.

#define obstack_object_size (   h)    (unsigned) ((h)->next_free - (h)->object_base)

Definition at line 407 of file obstack.h.

#define obstack_ptr_grow (   h,
  datum 
)
Value:
( (((h)->next_free + sizeof (char *) > (h)->chunk_limit)              \
   ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0),              \
  obstack_ptr_grow_fast (h, datum))

Definition at line 450 of file obstack.h.

#define obstack_ptr_grow_fast (   h,
  aptr 
)    (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))

Definition at line 460 of file obstack.h.

#define obstack_room (   h)    (unsigned) ((h)->chunk_limit - (h)->next_free)

Definition at line 410 of file obstack.h.

#define obstack_specify_allocation (   h,
  size,
  alignment,
  chunkfun,
  freefun 
)
Value:
_obstack_begin ((h), (size), (alignment),                         \
                (void *(*) (long)) (chunkfun),                    \
                (void (*) (void *)) (freefun))

Definition at line 231 of file obstack.h.

#define obstack_specify_allocation_with_arg (   h,
  size,
  alignment,
  chunkfun,
  freefun,
  arg 
)
Value:
_obstack_begin_1 ((h), (size), (alignment),                           \
                  (void *(*) (void *, long)) (chunkfun),              \
                  (void (*) (void *, void *)) (freefun), (arg))

Definition at line 236 of file obstack.h.

#define PTR_INT_TYPE   ptrdiff_t

Definition at line 122 of file obstack.h.


Function Documentation

int _obstack_begin ( struct obstack ,
int  ,
int  ,
void *  *)(long,
void(*)(void *)   
)
int _obstack_begin_1 ( struct obstack ,
int  ,
int  ,
void *  *)(void *, long,
void(*)(void *, void *)  ,
void *   
)

Definition at line 391 of file obstack.c.

{
  register struct _obstack_chunk* lp;
  register int nbytes = 0;

  for (lp = h->chunk; lp != 0; lp = lp->prev)
    {
      nbytes += lp->limit - (char *) lp;
    }
  return nbytes;
}
void _obstack_newchunk ( struct obstack ,
int   
)

Definition at line 255 of file obstack.c.

{
  register struct _obstack_chunk *old_chunk = h->chunk;
  register struct _obstack_chunk *new_chunk;
  register long      new_size;
  register long obj_size = h->next_free - h->object_base;
  register long i;
  long already;
  char *object_base;

  /* Compute size for new chunk.  */
  new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
  if (new_size < h->chunk_size)
    new_size = h->chunk_size;

  /* Allocate and initialize the new chunk.  */
  new_chunk = CALL_CHUNKFUN (h, new_size);
  if (!new_chunk)
    (*obstack_alloc_failed_handler) ();
  h->chunk = new_chunk;
  new_chunk->prev = old_chunk;
  new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;

  /* Compute an aligned object_base in the new chunk */
  object_base =
    __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);

  /* Move the existing object to the new chunk.
     Word at a time is fast and is safe if the object
     is sufficiently aligned.  */
  if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
    {
      for (i = obj_size / sizeof (COPYING_UNIT) - 1;
          i >= 0; i--)
       ((COPYING_UNIT *)object_base)[i]
         = ((COPYING_UNIT *)h->object_base)[i];
      /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
        but that can cross a page boundary on a machine
        which does not do strict alignment for COPYING_UNITS.  */
      already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
    }
  else
    already = 0;
  /* Copy remaining bytes one by one.  */
  for (i = already; i < obj_size; i++)
    object_base[i] = h->object_base[i];

  /* If the object just copied was the only data in OLD_CHUNK,
     free that chunk and remove it from the chain.
     But not if that chunk might contain an empty object.  */
  if (! h->maybe_empty_object
      && (h->object_base
         == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
                       h->alignment_mask)))
    {
      new_chunk->prev = old_chunk->prev;
      CALL_FREEFUN (h, old_chunk);
    }

  h->object_base = object_base;
  h->next_free = h->object_base + obj_size;
  /* The new chunk certainly contains no empty object yet.  */
  h->maybe_empty_object = 0;
}
void obstack_free ( struct obstack obstack,
void *  block 
)

Definition at line 355 of file obstack.c.

{
  register struct _obstack_chunk *lp;     /* below addr of any objects in this chunk */
  register struct _obstack_chunk *plp;    /* point to previous chunk if any */

  lp = h->chunk;
  /* We use >= because there cannot be an object at the beginning of a chunk.
     But there can be an empty object at that address
     at the end of another chunk.  */
  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    {
      plp = lp->prev;
      CALL_FREEFUN (h, lp);
      lp = plp;
      /* If we switch chunks, we can't tell whether the new current
        chunk contains an empty object, so assume that it may.  */
      h->maybe_empty_object = 1;
    }
  if (lp)
    {
      h->object_base = h->next_free = (char *) (obj);
      h->chunk_limit = lp->limit;
      h->chunk = lp;
    }
  else if (obj != 0)
    /* obj is not in any of the chunks! */
    abort ();
}

Here is the call graph for this function:


Variable Documentation

Definition at line 104 of file obstack.c.