OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [final_interface/] [gdb-5.0/] [include/] [objalloc.h] - Diff between revs 114 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 114 Rev 1765
/* objalloc.h -- routines to allocate memory for objects
/* objalloc.h -- routines to allocate memory for objects
   Copyright 1997 Free Software Foundation, Inc.
   Copyright 1997 Free Software Foundation, Inc.
   Written by Ian Lance Taylor, Cygnus Solutions.
   Written by Ian Lance Taylor, Cygnus Solutions.
 
 
This program is free software; you can redistribute it and/or modify it
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
Free Software Foundation; either version 2, or (at your option) any
later version.
later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */
Boston, MA 02111-1307, USA.  */
 
 
#ifndef OBJALLOC_H
#ifndef OBJALLOC_H
#define OBJALLOC_H
#define OBJALLOC_H
 
 
#include "ansidecl.h"
#include "ansidecl.h"
 
 
/* These routines allocate space for an object.  The assumption is
/* These routines allocate space for an object.  The assumption is
   that the object will want to allocate space as it goes along, but
   that the object will want to allocate space as it goes along, but
   will never want to free any particular block.  There is a function
   will never want to free any particular block.  There is a function
   to free a block, which also frees all more recently allocated
   to free a block, which also frees all more recently allocated
   blocks.  There is also a function to free all the allocated space.
   blocks.  There is also a function to free all the allocated space.
 
 
   This is essentially a specialization of obstacks.  The main
   This is essentially a specialization of obstacks.  The main
   difference is that a block may not be allocated a bit at a time.
   difference is that a block may not be allocated a bit at a time.
   Another difference is that these routines are always built on top
   Another difference is that these routines are always built on top
   of malloc, and always pass an malloc failure back to the caller,
   of malloc, and always pass an malloc failure back to the caller,
   unlike more recent versions of obstacks.  */
   unlike more recent versions of obstacks.  */
 
 
/* This is what an objalloc structure looks like.  Callers should not
/* This is what an objalloc structure looks like.  Callers should not
   refer to these fields, nor should they allocate these structure
   refer to these fields, nor should they allocate these structure
   themselves.  Instead, they should only create them via
   themselves.  Instead, they should only create them via
   objalloc_init, and only access them via the functions and macros
   objalloc_init, and only access them via the functions and macros
   listed below.  The structure is only defined here so that we can
   listed below.  The structure is only defined here so that we can
   access it via macros.  */
   access it via macros.  */
 
 
struct objalloc
struct objalloc
{
{
  char *current_ptr;
  char *current_ptr;
  unsigned int current_space;
  unsigned int current_space;
  PTR chunks;
  PTR chunks;
};
};
 
 
/* Work out the required alignment.  */
/* Work out the required alignment.  */
 
 
struct objalloc_align { char x; double d; };
struct objalloc_align { char x; double d; };
 
 
#if defined (__STDC__) && __STDC__
#if defined (__STDC__) && __STDC__
#ifndef offsetof
#ifndef offsetof
#include <stddef.h>
#include <stddef.h>
#endif
#endif
#define OBJALLOC_ALIGN \
#define OBJALLOC_ALIGN \
  ((ptrdiff_t) ((char *) &((struct objalloc_align *) 0)->d - (char *) 0))
  ((ptrdiff_t) ((char *) &((struct objalloc_align *) 0)->d - (char *) 0))
#else
#else
#define OBJALLOC_ALIGN \
#define OBJALLOC_ALIGN \
  ((long) ((char *) &((struct objalloc_align *) 0)->d - (char *) 0))
  ((long) ((char *) &((struct objalloc_align *) 0)->d - (char *) 0))
#endif
#endif
 
 
/* Create an objalloc structure.  Returns NULL if malloc fails.  */
/* Create an objalloc structure.  Returns NULL if malloc fails.  */
 
 
extern struct objalloc *objalloc_create PARAMS ((void));
extern struct objalloc *objalloc_create PARAMS ((void));
 
 
/* Allocate space from an objalloc structure.  Returns NULL if malloc
/* Allocate space from an objalloc structure.  Returns NULL if malloc
   fails.  */
   fails.  */
 
 
extern PTR _objalloc_alloc PARAMS ((struct objalloc *, unsigned long));
extern PTR _objalloc_alloc PARAMS ((struct objalloc *, unsigned long));
 
 
/* The macro version of objalloc_alloc.  We only define this if using
/* The macro version of objalloc_alloc.  We only define this if using
   gcc, because otherwise we would have to evaluate the arguments
   gcc, because otherwise we would have to evaluate the arguments
   multiple times, or use a temporary field as obstack.h does.  */
   multiple times, or use a temporary field as obstack.h does.  */
 
 
#if defined (__GNUC__) && defined (__STDC__) && __STDC__
#if defined (__GNUC__) && defined (__STDC__) && __STDC__
 
 
/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
   does not implement __extension__.  But that compiler doesn't define
   does not implement __extension__.  But that compiler doesn't define
   __GNUC_MINOR__.  */
   __GNUC_MINOR__.  */
#if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
#if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
#define __extension__
#define __extension__
#endif
#endif
 
 
#define objalloc_alloc(o, l)                                            \
#define objalloc_alloc(o, l)                                            \
  __extension__                                                         \
  __extension__                                                         \
  ({ struct objalloc *__o = (o);                                        \
  ({ struct objalloc *__o = (o);                                        \
     unsigned long __len = (l);                                         \
     unsigned long __len = (l);                                         \
     if (__len == 0)                                                     \
     if (__len == 0)                                                     \
       __len = 1;                                                       \
       __len = 1;                                                       \
     __len = (__len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1);      \
     __len = (__len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1);      \
     (__len <= __o->current_space                                       \
     (__len <= __o->current_space                                       \
      ? (__o->current_ptr += __len,                                     \
      ? (__o->current_ptr += __len,                                     \
         __o->current_space -= __len,                                   \
         __o->current_space -= __len,                                   \
         (PTR) (__o->current_ptr - __len))                              \
         (PTR) (__o->current_ptr - __len))                              \
      : _objalloc_alloc (__o, __len)); })
      : _objalloc_alloc (__o, __len)); })
 
 
#else /* ! __GNUC__ */
#else /* ! __GNUC__ */
 
 
#define objalloc_alloc(o, l) _objalloc_alloc ((o), (l))
#define objalloc_alloc(o, l) _objalloc_alloc ((o), (l))
 
 
#endif /* ! __GNUC__ */
#endif /* ! __GNUC__ */
 
 
/* Free an entire objalloc structure.  */
/* Free an entire objalloc structure.  */
 
 
extern void objalloc_free PARAMS ((struct objalloc *));
extern void objalloc_free PARAMS ((struct objalloc *));
 
 
/* Free a block allocated by objalloc_alloc.  This also frees all more
/* Free a block allocated by objalloc_alloc.  This also frees all more
   recently allocated blocks.  */
   recently allocated blocks.  */
 
 
extern void objalloc_free_block PARAMS ((struct objalloc *, PTR));
extern void objalloc_free_block PARAMS ((struct objalloc *, PTR));
 
 
#endif /* OBJALLOC_H */
#endif /* OBJALLOC_H */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.