104530d9ru/* obstack.c - subroutines used implicitly by object stack macros
204530d9ru   Copyright (C) 1988-1994,96,97,98,99 Free Software Foundation, Inc.
33f3aac9obrien
404530d9ru   This file is part of the GNU C Library.  Its master source is NOT part of
53f3aac9obrien   the C library, however.  The master source lives in /gd/gnu/lib.
63f3aac9obrien
704530d9ru   The GNU C Library is free software; you can redistribute it and/or
804530d9ru   modify it under the terms of the GNU Library General Public License as
904530d9ru   published by the Free Software Foundation; either version 2 of the
1004530d9ru   License, or (at your option) any later version.
115354776peter
1204530d9ru   The GNU C Library is distributed in the hope that it will be useful,
1304530d9ru   but WITHOUT ANY WARRANTY; without even the implied warranty of
1404530d9ru   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1504530d9ru   Library General Public License for more details.
165354776peter
1704530d9ru   You should have received a copy of the GNU Library General Public
1804530d9ru   License along with the GNU C Library; see the file COPYING.LIB.  If not,
1904530d9ru   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
2004530d9ru   Boston, MA 02111-1307, USA.  */
213f3aac9obrien
223f3aac9obrien#ifdef HAVE_CONFIG_H
233f3aac9obrien#include <config.h>
243f3aac9obrien#endif
255354776peter
265354776peter#include "obstack.h"
275354776peter
283f3aac9obrien/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
293f3aac9obrien   incremented whenever callers compiled using an old obstack.h can no
303f3aac9obrien   longer properly call the functions in this obstack.c.  */
313f3aac9obrien#define OBSTACK_INTERFACE_VERSION 1
325354776peter
335354776peter/* Comment out all this code if we are using the GNU C Library, and are not
343f3aac9obrien   actually compiling the library itself, and the installed library
353f3aac9obrien   supports the same library interface we do.  This code is part of the GNU
363f3aac9obrien   C Library, but also included in many other GNU distributions.  Compiling
375354776peter   and linking in this code is a waste when using the GNU C library
385354776peter   (especially if it is a shared library).  Rather than having every GNU
393f3aac9obrien   program understand `configure --with-gnu-libc' and omit the object
403f3aac9obrien   files, it is simpler to just do this in the source for each such file.  */
413f3aac9obrien
423f3aac9obrien#include <stdio.h>		/* Random thing to get __GNU_LIBRARY__.  */
433f3aac9obrien#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
443f3aac9obrien#include <gnu-versions.h>
453f3aac9obrien#if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
463f3aac9obrien#define ELIDE_CODE
473f3aac9obrien#endif
483f3aac9obrien#endif
493f3aac9obrien
505354776peter
513f3aac9obrien#ifndef ELIDE_CODE
525354776peter
535354776peter
543f3aac9obrien#if defined (__STDC__) && __STDC__
555354776peter#define POINTER void *
565354776peter#else
575354776peter#define POINTER char *
585354776peter#endif
595354776peter
605354776peter/* Determine default alignment.  */
615354776peterstruct fooalign {char x; double d;};
625354776peter#define DEFAULT_ALIGNMENT  \
633f3aac9obrien  ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
645354776peter/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
655354776peter   But in fact it might be less smart and round addresses to as much as
665354776peter   DEFAULT_ROUNDING.  So we prepare for it to do that.  */
675354776peterunion fooround {long x; double d;};
685354776peter#define DEFAULT_ROUNDING (sizeof (union fooround))
695354776peter
705354776peter/* When we copy a long block of data, this is the unit to do it with.
715354776peter   On some machines, copying successive ints does not work;
725354776peter   in such a case, redefine COPYING_UNIT to `long' (if that works)
735354776peter   or `char' as a last resort.  */
745354776peter#ifndef COPYING_UNIT
755354776peter#define COPYING_UNIT int
765354776peter#endif
775354776peter
783f3aac9obrien
793f3aac9obrien/* The functions allocating more room by calling `obstack_chunk_alloc'
803f3aac9obrien   jump to the handler pointed to by `obstack_alloc_failed_handler'.
8104530d9ru   This can be set to a user defined function which should either
8204530d9ru   abort gracefully or use longjump - but shouldn't return.  This
8304530d9ru   variable by default points to the internal function
843f3aac9obrien   `print_and_abort'.  */
853f3aac9obrien#if defined (__STDC__) && __STDC__
863f3aac9obrienstatic void print_and_abort (void);
873f3aac9obrienvoid (*obstack_alloc_failed_handler) (void) = print_and_abort;
883f3aac9obrien#else
893f3aac9obrienstatic void print_and_abort ();
903f3aac9obrienvoid (*obstack_alloc_failed_handler) () = print_and_abort;
913f3aac9obrien#endif
923f3aac9obrien
933f3aac9obrien/* Exit value used when `print_and_abort' is used.  */
943f3aac9obrien#if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
953f3aac9obrien#include <stdlib.h>
963f3aac9obrien#endif
973f3aac9obrien#ifndef EXIT_FAILURE
983f3aac9obrien#define EXIT_FAILURE 1
993f3aac9obrien#endif
1003f3aac9obrienint obstack_exit_failure = EXIT_FAILURE;
1013f3aac9obrien
1025354776peter/* The non-GNU-C macros copy the obstack into this global variable
1035354776peter   to avoid multiple evaluation.  */
1045354776peter
1055354776peterstruct obstack *_obstack;
1065354776peter
1075354776peter/* Define a macro that either calls functions with the traditional malloc/free
1085354776peter   calling interface, or calls functions with the mmalloc/mfree interface
1095354776peter   (that adds an extra first argument), based on the state of use_extra_arg.
1105354776peter   For free, do not use ?:, since some compilers, like the MIPS compilers,
1115354776peter   do not allow (expr) ? void : void.  */
1125354776peter
1133f3aac9obrien#if defined (__STDC__) && __STDC__
1145354776peter#define CALL_CHUNKFUN(h, size) \
1155354776peter  (((h) -> use_extra_arg) \
1165354776peter   ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
1173f3aac9obrien   : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
1185354776peter
1195354776peter#define CALL_FREEFUN(h, old_chunk) \
1205354776peter  do { \
1215354776peter    if ((h) -> use_extra_arg) \
1225354776peter      (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
1235354776peter    else \
1243f3aac9obrien      (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
1255354776peter  } while (0)
1263f3aac9obrien#else
1273f3aac9obrien#define CALL_CHUNKFUN(h, size) \
1283f3aac9obrien  (((h) -> use_extra_arg) \
1293f3aac9obrien   ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
1303f3aac9obrien   : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size)))
1313f3aac9obrien
1323f3aac9obrien#define CALL_FREEFUN(h, old_chunk) \
1333f3aac9obrien  do { \
1343f3aac9obrien    if ((h) -> use_extra_arg) \
1353f3aac9obrien      (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
1363f3aac9obrien    else \
1373f3aac9obrien      (*(void (*) ()) (h)->freefun) ((old_chunk)); \
1383f3aac9obrien  } while (0)
1393f3aac9obrien#endif
1405354776peter
1415354776peter
1425354776peter/* Initialize an obstack H for use.  Specify chunk size SIZE (0 means default).
1435354776peter   Objects start on multiples of ALIGNMENT (0 means use default).
1445354776peter   CHUNKFUN is the function to use to allocate chunks,
1453f3aac9obrien   and FREEFUN the function to free them.
1465354776peter
14704530d9ru   Return nonzero if successful, calls obstack_alloc_failed_handler if
14804530d9ru   allocation fails.  */
1493f3aac9obrien
1503f3aac9obrienint
1515354776peter_obstack_begin (h, size, alignment, chunkfun, freefun)
1525354776peter     struct obstack *h;
1535354776peter     int size;
1545354776peter     int alignment;
1553f3aac9obrien#if defined (__STDC__) && __STDC__
1563f3aac9obrien     POINTER (*chunkfun) (long);
1573f3aac9obrien     void (*freefun) (void *);
1583f3aac9obrien#else
1595354776peter     POINTER (*chunkfun) ();
1605354776peter     void (*freefun) ();
1613f3aac9obrien#endif
1625354776peter{
1633f3aac9obrien  register struct _obstack_chunk *chunk; /* points to new chunk */
1645354776peter
1655354776peter  if (alignment == 0)
1663f3aac9obrien    alignment = (int) DEFAULT_ALIGNMENT;
1675354776peter  if (size == 0)
1685354776peter    /* Default size is what GNU malloc can fit in a 4096-byte block.  */
1695354776peter    {
1705354776peter      /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
1715354776peter	 Use the values for range checking, because if range checking is off,
1725354776peter	 the extra bytes won't be missed terribly, but if range checking is on
1735354776peter	 and we used a larger request, a whole extra 4096 bytes would be
1745354776peter	 allocated.
1755354776peter
1765354776peter	 These number are irrelevant to the new GNU malloc.  I suspect it is
1775354776peter	 less sensitive to the size of the request.  */
1785354776peter      int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
1795354776peter		    + 4 + DEFAULT_ROUNDING - 1)
1805354776peter		   & ~(DEFAULT_ROUNDING - 1));
1815354776peter      size = 4096 - extra;
1825354776peter    }
1835354776peter
1843f3aac9obrien#if defined (__STDC__) && __STDC__
1853f3aac9obrien  h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
1863f3aac9obrien  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
1873f3aac9obrien#else
1885354776peter  h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
1895354776peter  h->freefun = freefun;
1903f3aac9obrien#endif
1915354776peter  h->chunk_size = size;
1925354776peter  h->alignment_mask = alignment - 1;
1935354776peter  h->use_extra_arg = 0;
1945354776peter
1955354776peter  chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
1963f3aac9obrien  if (!chunk)
1973f3aac9obrien    (*obstack_alloc_failed_handler) ();
1985354776peter  h->next_free = h->object_base = chunk->contents;
1995354776peter  h->chunk_limit = chunk->limit
2005354776peter    = (char *) chunk + h->chunk_size;
2015354776peter  chunk->prev = 0;
2025354776peter  /* The initial chunk now contains no empty object.  */
2035354776peter  h->maybe_empty_object = 0;
2043f3aac9obrien  h->alloc_failed = 0;
2053f3aac9obrien  return 1;
2065354776peter}
2075354776peter
2083f3aac9obrienint
2095354776peter_obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
2105354776peter     struct obstack *h;
2115354776peter     int size;
2125354776peter     int alignment;
2133f3aac9obrien#if defined (__STDC__) && __STDC__
2143f3aac9obrien     POINTER (*chunkfun) (POINTER, long);
2153f3aac9obrien     void (*freefun) (POINTER, POINTER);
2163f3aac9obrien#else
2175354776peter     POINTER (*chunkfun) ();
2185354776peter     void (*freefun) ();
2193f3aac9obrien#endif
2205354776peter     POINTER arg;
2215354776peter{
2223f3aac9obrien  register struct _obstack_chunk *chunk; /* points to new chunk */
2235354776peter
2245354776peter  if (alignment == 0)
2253f3aac9obrien    alignment = (int) DEFAULT_ALIGNMENT;
2265354776peter  if (size == 0)
2275354776peter    /* Default size is what GNU malloc can fit in a 4096-byte block.  */
2285354776peter    {
2295354776peter      /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
2305354776peter	 Use the values for range checking, because if range checking is off,
2315354776peter	 the extra bytes won't be missed terribly, but if range checking is on
2325354776peter	 and we used a larger request, a whole extra 4096 bytes would be
2335354776peter	 allocated.
2345354776peter
2355354776peter	 These number are irrelevant to the new GNU malloc.  I suspect it is
2365354776peter	 less sensitive to the size of the request.  */
2375354776peter      int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
2385354776peter		    + 4 + DEFAULT_ROUNDING - 1)
2395354776peter		   & ~(DEFAULT_ROUNDING - 1));
2405354776peter      size = 4096 - extra;
2415354776peter    }
2425354776peter
2433f3aac9obrien#if defined(__STDC__) && __STDC__
2443f3aac9obrien  h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
2453f3aac9obrien  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
2463f3aac9obrien#else
2475354776peter  h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
2485354776peter  h->freefun = freefun;
2493f3aac9obrien#endif
2505354776peter  h->chunk_size = size;
2515354776peter  h->alignment_mask = alignment - 1;
2525354776peter  h->extra_arg = arg;
2535354776peter  h->use_extra_arg = 1;
2545354776peter
2555354776peter  chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
2563f3aac9obrien  if (!chunk)
2573f3aac9obrien    (*obstack_alloc_failed_handler) ();
2585354776peter  h->next_free = h->object_base = chunk->contents;
2595354776peter  h->chunk_limit = chunk->limit
2605354776peter    = (char *) chunk + h->chunk_size;
2615354776peter  chunk->prev = 0;
2625354776peter  /* The initial chunk now contains no empty object.  */
2635354776peter  h->maybe_empty_object = 0;
2643f3aac9obrien  h->alloc_failed = 0;
2653f3aac9obrien  return 1;
2665354776peter}
2675354776peter
2685354776peter/* Allocate a new current chunk for the obstack *H
2695354776peter   on the assumption that LENGTH bytes need to be added
2705354776peter   to the current object, or a new object of length LENGTH allocated.
2715354776peter   Copies any partial object from the end of the old chunk
2725354776peter   to the beginning of the new one.  */
2735354776peter
2745354776petervoid
2755354776peter_obstack_newchunk (h, length)
2765354776peter     struct obstack *h;
2775354776peter     int length;
2785354776peter{
2793f3aac9obrien  register struct _obstack_chunk *old_chunk = h->chunk;
2803f3aac9obrien  register struct _obstack_chunk *new_chunk;
2815354776peter  register long	new_size;
2823f3aac9obrien  register long obj_size = h->next_free - h->object_base;
2833f3aac9obrien  register long i;
2843f3aac9obrien  long already;
2855354776peter
2865354776peter  /* Compute size for new chunk.  */
2875354776peter  new_size = (obj_size + length) + (obj_size >> 3) + 100;
2885354776peter  if (new_size < h->chunk_size)
2895354776peter    new_size = h->chunk_size;
2905354776peter
2915354776peter  /* Allocate and initialize the new chunk.  */
2923f3aac9obrien  new_chunk = CALL_CHUNKFUN (h, new_size);
2933f3aac9obrien  if (!new_chunk)
2943f3aac9obrien    (*obstack_alloc_failed_handler) ();
2953f3aac9obrien  h->chunk = new_chunk;
2965354776peter  new_chunk->prev = old_chunk;
2975354776peter  new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
2985354776peter
2995354776peter  /* Move the existing object to the new chunk.
3005354776peter     Word at a time is fast and is safe if the object
3015354776peter     is sufficiently aligned.  */
3025354776peter  if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
3035354776peter    {
3045354776peter      for (i = obj_size / sizeof (COPYING_UNIT) - 1;
3055354776peter	   i >= 0; i--)
3065354776peter	((COPYING_UNIT *)new_chunk->contents)[i]
3075354776peter	  = ((COPYING_UNIT *)h->object_base)[i];
3085354776peter      /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
3095354776peter	 but that can cross a page boundary on a machine
3105354776peter	 which does not do strict alignment for COPYING_UNITS.  */
3115354776peter      already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
3125354776peter    }
3135354776peter  else
3145354776peter    already = 0;
3155354776peter  /* Copy remaining bytes one by one.  */
3165354776peter  for (i = already; i < obj_size; i++)
3175354776peter    new_chunk->contents[i] = h->object_base[i];
3185354776peter
3195354776peter  /* If the object just copied was the only data in OLD_CHUNK,
3205354776peter     free that chunk and remove it from the chain.
3215354776peter     But not if that chunk might contain an empty object.  */
3225354776peter  if (h->object_base == old_chunk->contents && ! h->maybe_empty_object)
3235354776peter    {
3245354776peter      new_chunk->prev = old_chunk->prev;
3255354776peter      CALL_FREEFUN (h, old_chunk);
3265354776peter    }
3275354776peter
3285354776peter  h->object_base = new_chunk->contents;
3295354776peter  h->next_free = h->object_base + obj_size;
3305354776peter  /* The new chunk certainly contains no empty object yet.  */
3315354776peter  h->maybe_empty_object = 0;
3325354776peter}
3335354776peter
3345354776peter/* Return nonzero if object OBJ has been allocated from obstack H.
3355354776peter   This is here for debugging.
3365354776peter   If you use it in a program, you are probably losing.  */
3375354776peter
3383f3aac9obrien#if defined (__STDC__) && __STDC__
3393f3aac9obrien/* Suppress -Wmissing-prototypes warning.  We don't want to declare this in
3403f3aac9obrien   obstack.h because it is just for debugging.  */
3413f3aac9obrienint _obstack_allocated_p (struct obstack *h, POINTER obj);
3423f3aac9obrien#endif
3433f3aac9obrien
3445354776peterint
3455354776peter_obstack_allocated_p (h, obj)
3465354776peter     struct obstack *h;
3475354776peter     POINTER obj;
3485354776peter{
3493f3aac9obrien  register struct _obstack_chunk *lp;	/* below addr of any objects in this chunk */
3503f3aac9obrien  register struct _obstack_chunk *plp;	/* point to previous chunk if any */
3515354776peter
3525354776peter  lp = (h)->chunk;
3535354776peter  /* We use >= rather than > since the object cannot be exactly at
3545354776peter     the beginning of the chunk but might be an empty object exactly
3553f3aac9obrien     at the end of an adjacent chunk.  */
3563f3aac9obrien  while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
3575354776peter    {
3585354776peter      plp = lp->prev;
3595354776peter      lp = plp;
3605354776peter    }
3615354776peter  return lp != 0;
3625354776peter}
3635354776peter
3645354776peter/* Free objects in obstack H, including OBJ and everything allocate
3655354776peter   more recently than OBJ.  If OBJ is zero, free everything in H.  */
3665354776peter
3675354776peter#undef obstack_free
3685354776peter
3695354776peter/* This function has two names with identical definitions.
3705354776peter   This is the first one, called from non-ANSI code.  */
3715354776peter
3725354776petervoid
3735354776peter_obstack_free (h, obj)
3745354776peter     struct obstack *h;
3755354776peter     POINTER obj;
3765354776peter{
3773f3aac9obrien  register struct _obstack_chunk *lp;	/* below addr of any objects in this chunk */
3783f3aac9obrien  register struct _obstack_chunk *plp;	/* point to previous chunk if any */
3795354776peter
3805354776peter  lp = h->chunk;
3815354776peter  /* We use >= because there cannot be an object at the beginning of a chunk.
3825354776peter     But there can be an empty object at that address
3835354776peter     at the end of another chunk.  */
3843f3aac9obrien  while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
3855354776peter    {
3865354776peter      plp = lp->prev;
3875354776peter      CALL_FREEFUN (h, lp);
3885354776peter      lp = plp;
3895354776peter      /* If we switch chunks, we can't tell whether the new current
3905354776peter	 chunk contains an empty object, so assume that it may.  */
3915354776peter      h->maybe_empty_object = 1;
3925354776peter    }
3935354776peter  if (lp)
3945354776peter    {
3953f3aac9obrien      h->object_base = h->next_free = (char *) (obj);
3965354776peter      h->chunk_limit = lp->limit;
3975354776peter      h->chunk = lp;
3985354776peter    }
3995354776peter  else if (obj != 0)
4005354776peter    /* obj is not in any of the chunks! */
4015354776peter    abort ();
4025354776peter}
4035354776peter
4045354776peter/* This function is used from ANSI code.  */
4055354776peter
4065354776petervoid
4075354776peterobstack_free (h, obj)
4085354776peter     struct obstack *h;
4095354776peter     POINTER obj;
4105354776peter{
4113f3aac9obrien  register struct _obstack_chunk *lp;	/* below addr of any objects in this chunk */
4123f3aac9obrien  register struct _obstack_chunk *plp;	/* point to previous chunk if any */
4135354776peter
4145354776peter  lp = h->chunk;
4155354776peter  /* We use >= because there cannot be an object at the beginning of a chunk.
4165354776peter     But there can be an empty object at that address
4175354776peter     at the end of another chunk.  */
4183f3aac9obrien  while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
4195354776peter    {
4205354776peter      plp = lp->prev;
4215354776peter      CALL_FREEFUN (h, lp);
4225354776peter      lp = plp;
4235354776peter      /* If we switch chunks, we can't tell whether the new current
4245354776peter	 chunk contains an empty object, so assume that it may.  */
4255354776peter      h->maybe_empty_object = 1;
4265354776peter    }
4275354776peter  if (lp)
4285354776peter    {
4293f3aac9obrien      h->object_base = h->next_free = (char *) (obj);
4305354776peter      h->chunk_limit = lp->limit;
4315354776peter      h->chunk = lp;
4325354776peter    }
4335354776peter  else if (obj != 0)
4345354776peter    /* obj is not in any of the chunks! */
4355354776peter    abort ();
4365354776peter}
4375354776peter
4383f3aac9obrienint
4393f3aac9obrien_obstack_memory_used (h)
4403f3aac9obrien     struct obstack *h;
4413f3aac9obrien{
4423f3aac9obrien  register struct _obstack_chunk* lp;
4433f3aac9obrien  register int nbytes = 0;
4443f3aac9obrien
4453f3aac9obrien  for (lp = h->chunk; lp != 0; lp = lp->prev)
4463f3aac9obrien    {
4473f3aac9obrien      nbytes += lp->limit - (char *) lp;
4483f3aac9obrien    }
4493f3aac9obrien  return nbytes;
4503f3aac9obrien}
4513f3aac9obrien
4523f3aac9obrien/* Define the error handler.  */
4533f3aac9obrien#ifndef _
4543f3aac9obrien# ifdef HAVE_LIBINTL_H
4553f3aac9obrien#  include <libintl.h>
4563f3aac9obrien#  ifndef _
4573f3aac9obrien#   define _(Str) gettext (Str)
4583f3aac9obrien#  endif
4593f3aac9obrien# else
4603f3aac9obrien#  define _(Str) (Str)
4613f3aac9obrien# endif
4623f3aac9obrien#endif
46304530d9ru#if defined _LIBC && defined USE_IN_LIBIO
46404530d9ru# include <libio/iolibio.h>
46504530d9ru# define fputs(s, f) _IO_fputs (s, f)
46604530d9ru#endif
4673f3aac9obrien
4683f3aac9obrienstatic void
4693f3aac9obrienprint_and_abort ()
4703f3aac9obrien{
47104530d9ru  fputs (_("memory exhausted"), stderr);
47204530d9ru  fputc ('\n', stderr);
4733f3aac9obrien  exit (obstack_exit_failure);
4743f3aac9obrien}
4753f3aac9obrien
4765354776peter#if 0
4775354776peter/* These are now turned off because the applications do not use it
4785354776peter   and it uses bcopy via obstack_grow, which causes trouble on sysV.  */
4795354776peter
4805354776peter/* Now define the functional versions of the obstack macros.
4815354776peter   Define them to simply use the corresponding macros to do the job.  */
4825354776peter
4833f3aac9obrien#if defined (__STDC__) && __STDC__
4845354776peter/* These function definitions do not work with non-ANSI preprocessors;
4855354776peter   they won't pass through the macro names in parentheses.  */
4865354776peter
4875354776peter/* The function names appear in parentheses in order to prevent
4885354776peter   the macro-definitions of the names from being expanded there.  */
4895354776peter
4905354776peterPOINTER (obstack_base) (obstack)
4915354776peter     struct obstack *obstack;
4925354776peter{
4935354776peter  return obstack_base (obstack);
4945354776peter}
4955354776peter
4965354776peterPOINTER (obstack_next_free) (obstack)
4975354776peter     struct obstack *obstack;
4985354776peter{
4995354776peter  return obstack_next_free (obstack);
5005354776peter}
5015354776peter
5025354776peterint (obstack_object_size) (obstack)
5035354776peter     struct obstack *obstack;
5045354776peter{
5055354776peter  return obstack_object_size (obstack);
5065354776peter}
5075354776peter
5085354776peterint (obstack_room) (obstack)
5095354776peter     struct obstack *obstack;
5105354776peter{
5115354776peter  return obstack_room (obstack);
5125354776peter}
5135354776peter
5143f3aac9obrienint (obstack_make_room) (obstack, length)
5153f3aac9obrien     struct obstack *obstack;
5163f3aac9obrien     int length;
5173f3aac9obrien{
5183f3aac9obrien  return obstack_make_room (obstack, length);
5193f3aac9obrien}
5203f3aac9obrien
5215354776petervoid (obstack_grow) (obstack, pointer, length)
5225354776peter     struct obstack *obstack;
5235354776peter     POINTER pointer;
5245354776peter     int length;
5255354776peter{
5265354776peter  obstack_grow (obstack, pointer, length);
5275354776peter}
5285354776peter
5295354776petervoid (obstack_grow0) (obstack, pointer, length)
5305354776peter     struct obstack *obstack;
5315354776peter     POINTER pointer;
5325354776peter     int length;
5335354776peter{
5345354776peter  obstack_grow0 (obstack, pointer, length);
5355354776peter}
5365354776peter
5375354776petervoid (obstack_1grow) (obstack, character)
5385354776peter     struct obstack *obstack;
5395354776peter     int character;
5405354776peter{
5415354776peter  obstack_1grow (obstack, character);
5425354776peter}
5435354776peter
5445354776petervoid (obstack_blank) (obstack, length)
5455354776peter     struct obstack *obstack;
5465354776peter     int length;
5475354776peter{
5485354776peter  obstack_blank (obstack, length);
5495354776peter}
5505354776peter
5515354776petervoid (obstack_1grow_fast) (obstack, character)
5525354776peter     struct obstack *obstack;
5535354776peter     int character;
5545354776peter{
5555354776peter  obstack_1grow_fast (obstack, character);
5565354776peter}
5575354776peter
5585354776petervoid (obstack_blank_fast) (obstack, length)
5595354776peter     struct obstack *obstack;
5605354776peter     int length;
5615354776peter{
5625354776peter  obstack_blank_fast (obstack, length);
5635354776peter}
5645354776peter
5655354776peterPOINTER (obstack_finish) (obstack)
5665354776peter     struct obstack *obstack;
5675354776peter{
5685354776peter  return obstack_finish (obstack);
5695354776peter}
5705354776peter
5715354776peterPOINTER (obstack_alloc) (obstack, length)
5725354776peter     struct obstack *obstack;
5735354776peter     int length;
5745354776peter{
5755354776peter  return obstack_alloc (obstack, length);
5765354776peter}
5775354776peter
5785354776peterPOINTER (obstack_copy) (obstack, pointer, length)
5795354776peter     struct obstack *obstack;
5805354776peter     POINTER pointer;
5815354776peter     int length;
5825354776peter{
5835354776peter  return obstack_copy (obstack, pointer, length);
5845354776peter}
5855354776peter
5865354776peterPOINTER (obstack_copy0) (obstack, pointer, length)
5875354776peter     struct obstack *obstack;
5885354776peter     POINTER pointer;
5895354776peter     int length;
5905354776peter{
5915354776peter  return obstack_copy0 (obstack, pointer, length);
5925354776peter}
5935354776peter
5945354776peter#endif /* __STDC__ */
5955354776peter
5965354776peter#endif /* 0 */
5975354776peter
5983f3aac9obrien#endif	/* !ELIDE_CODE */
599