Ignore:
Timestamp:
Sep 19, 2024, 2:34:43 AM (10 months ago)
Author:
bird
Message:

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

Location:
trunk/src/sed
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sed

  • trunk/src/sed/lib/obstack.c

    r599 r3613  
    1 /* obstack.c - subroutines used implicitly by object stack macros -*- C -*-
    2    Copyright (C) 1988,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
    3 
    4    This file is part of the GNU C Library.  Its master source is NOT part of
    5    the C library, however.  The master source lives in /gd/gnu/lib.
    6 
    7    The GNU C Library is free software; you can redistribute it and/or
    8    modify it under the terms of the GNU Library General Public License as
    9    published by the Free Software Foundation; either version 2 of the
     1/* obstack.c - subroutines used implicitly by object stack macros
     2   Copyright (C) 1988-2022 Free Software Foundation, Inc.
     3   This file is part of the GNU C Library.
     4
     5   This file is free software: you can redistribute it and/or modify
     6   it under the terms of the GNU Lesser General Public License as
     7   published by the Free Software Foundation, either version 3 of the
    108   License, or (at your option) any later version.
    119
    12    The GNU C Library is distributed in the hope that it will be useful,
     10   This file is distributed in the hope that it will be useful,
    1311   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    15    Library General Public License for more details.
    16 
    17    You should have received a copy of the GNU Library General Public
    18    License along with the GNU C Library; see the file COPYING.LIB.  If not,
    19    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    20    Boston, MA 02110-1301, USA.  */
    21 
    22 #ifdef HAVE_CONFIG_H
    23 #include <config.h>
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU Lesser General Public License for more details.
     14
     15   You should have received a copy of the GNU Lesser General Public License
     16   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
     17
     18
     19#ifdef _LIBC
     20# include <obstack.h>
     21#else
     22# include <config.h>
     23# include "obstack.h"
    2424#endif
    2525
    26 #include "obstack.h"
    27 
    28 /* NOTE BEFORE MODIFYING THIS FILE: This version number must be
    29    incremented whenever callers compiled using an old obstack.h can no
    30    longer properly call the functions in this obstack.c.  */
    31 #define OBSTACK_INTERFACE_VERSION 1
     26/* NOTE BEFORE MODIFYING THIS FILE: _OBSTACK_INTERFACE_VERSION in
     27   obstack.h must be incremented whenever callers compiled using an old
     28   obstack.h can no longer properly call the functions in this file.  */
    3229
    3330/* Comment out all this code if we are using the GNU C Library, and are not
     
    3734   and linking in this code is a waste when using the GNU C library
    3835   (especially if it is a shared library).  Rather than having every GNU
    39    program understand `configure --with-gnu-libc' and omit the object
     36   program understand 'configure --with-gnu-libc' and omit the object
    4037   files, it is simpler to just do this in the source for each such file.  */
    41 
    42 #include <stdio.h>              /* Random thing to get __GNU_LIBRARY__.  */
    43 #if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
    44 #include <gnu-versions.h>
    45 #if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
    46 #define ELIDE_CODE
     38#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
     39# include <gnu-versions.h>
     40# if (_GNU_OBSTACK_INTERFACE_VERSION == _OBSTACK_INTERFACE_VERSION            \
     41      || (_GNU_OBSTACK_INTERFACE_VERSION == 1                                 \
     42          && _OBSTACK_INTERFACE_VERSION == 2                                  \
     43          && defined SIZEOF_INT && defined SIZEOF_SIZE_T                      \
     44          && SIZEOF_INT == SIZEOF_SIZE_T))
     45#  define _OBSTACK_ELIDE_CODE
     46# endif
    4747#endif
    48 #endif
    49 
    50 
    51 #ifndef ELIDE_CODE
    52 
    53 
    54 #if defined (__STDC__) && __STDC__
    55 #define POINTER void *
    56 #else
    57 #define POINTER char *
    58 #endif
     48
     49#ifndef _OBSTACK_ELIDE_CODE
     50/* If GCC, or if an oddball (testing?) host that #defines __alignof__,
     51   use the already-supplied __alignof__.  Otherwise, this must be Gnulib
     52   (as glibc assumes GCC); defer to Gnulib's alignof_type.  */
     53# if !defined __GNUC__ && !defined __alignof__
     54#  include <alignof.h>
     55#  define __alignof__(type) alignof_type (type)
     56# endif
     57# include <stdlib.h>
     58# include <stdint.h>
     59
     60# ifndef MAX
     61#  define MAX(a,b) ((a) > (b) ? (a) : (b))
     62# endif
    5963
    6064/* Determine default alignment.  */
    61 struct fooalign {char x; double d;};
    62 #define DEFAULT_ALIGNMENT  \
    63   ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
     65
    6466/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
    6567   But in fact it might be less smart and round addresses to as much as
    66    DEFAULT_ROUNDING.  So we prepare for it to do that.  */
    67 union fooround {long x; double d;};
    68 #define DEFAULT_ROUNDING (sizeof (union fooround))
    69 
    70 #ifdef original_glibc_code
    71 /**//* When we copy a long block of data, this is the unit to do it with. */
    72 /**//* On some machines, copying successive ints does not work; */
    73 /**//* in such a case, redefine COPYING_UNIT to `long' (if that works) */
    74 /**//* or `char' as a last resort.  */
    75 /**/#ifndef COPYING_UNIT
    76 /**/#define COPYING_UNIT int
    77 /**/#endif
    78 #endif
    79 
    80 /* The functions allocating more room by calling `obstack_chunk_alloc'
    81    jump to the handler pointed to by `obstack_alloc_failed_handler'.
    82    This variable by default points to the internal function
    83    `print_and_abort'.  */
    84 #if defined (__STDC__) && __STDC__
    85 static void print_and_abort (void);
    86 void (*obstack_alloc_failed_handler) (void) = print_and_abort;
    87 #else
    88 static void print_and_abort ();
    89 void (*obstack_alloc_failed_handler) () = print_and_abort;
    90 #endif
    91 
    92 /* Exit value used when `print_and_abort' is used.  */
    93 #if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
    94 #include <stdlib.h>
    95 #endif
    96 #ifndef EXIT_FAILURE
    97 #define EXIT_FAILURE 1
    98 #endif
    99 int obstack_exit_failure = EXIT_FAILURE;
    100 
    101 /* The non-GNU-C macros copy the obstack into this global variable
    102    to avoid multiple evaluation.  */
    103 
    104 struct obstack *_obstack;
    105 
    106 /* Define a macro that either calls functions with the traditional malloc/free
    107    calling interface, or calls functions with the mmalloc/mfree interface
    108    (that adds an extra first argument), based on the state of use_extra_arg.
    109    For free, do not use ?:, since some compilers, like the MIPS compilers,
    110    do not allow (expr) ? void : void.  */
    111 
    112 #if defined (__STDC__) && __STDC__
    113 #define CALL_CHUNKFUN(h, size) \
    114   (((h) -> use_extra_arg) \
    115    ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
    116    : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
    117 
    118 #define CALL_FREEFUN(h, old_chunk) \
    119   do { \
    120     if ((h) -> use_extra_arg) \
    121       (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
    122     else \
    123       (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
    124   } while (0)
    125 #else
    126 #define CALL_CHUNKFUN(h, size) \
    127   (((h) -> use_extra_arg) \
    128    ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
    129    : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size)))
    130 
    131 #define CALL_FREEFUN(h, old_chunk) \
    132   do { \
    133     if ((h) -> use_extra_arg) \
    134       (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
    135     else \
    136       (*(void (*) ()) (h)->freefun) ((old_chunk)); \
    137   } while (0)
    138 #endif
    139 
     68   DEFAULT_ROUNDING.  So we prepare for it to do that.
     69
     70   DEFAULT_ALIGNMENT cannot be an enum constant; see gnulib's alignof.h.  */
     71#define DEFAULT_ALIGNMENT MAX (__alignof__ (long double),                     \
     72                               MAX (__alignof__ (uintmax_t),                  \
     73                                    __alignof__ (void *)))
     74#define DEFAULT_ROUNDING MAX (sizeof (long double),                           \
     75                               MAX (sizeof (uintmax_t),                       \
     76                                    sizeof (void *)))
     77
     78/* Call functions with either the traditional malloc/free calling
     79   interface, or the mmalloc/mfree interface (that adds an extra first
     80   argument), based on the value of use_extra_arg.  */
     81
     82static void *
     83call_chunkfun (struct obstack *h, size_t size)
     84{
     85  if (h->use_extra_arg)
     86    return h->chunkfun.extra (h->extra_arg, size);
     87  else
     88    return h->chunkfun.plain (size);
     89}
     90
     91static void
     92call_freefun (struct obstack *h, void *old_chunk)
     93{
     94  if (h->use_extra_arg)
     95    h->freefun.extra (h->extra_arg, old_chunk);
     96  else
     97    h->freefun.plain (old_chunk);
     98}
    14099
    141100
    142101/* Initialize an obstack H for use.  Specify chunk size SIZE (0 means default).
    143102   Objects start on multiples of ALIGNMENT (0 means use default).
    144    CHUNKFUN is the function to use to allocate chunks,
    145    and FREEFUN the function to free them.
    146 
    147    Return nonzero if successful, zero if out of memory.
    148    To recover from an out of memory error,
    149    free up some memory, then call this again.  */
    150 
    151 int
    152 _obstack_begin (h, size, alignment, chunkfun, freefun)
    153      struct obstack *h;
    154      int size;
    155      int alignment;
    156 #if defined (__STDC__) && __STDC__
    157      POINTER (*chunkfun) (long);
    158      void (*freefun) (void *);
    159 #else
    160      POINTER (*chunkfun) ();
    161      void (*freefun) ();
    162 #endif
    163 {
    164   register struct _obstack_chunk *chunk; /* points to new chunk */
     103
     104   Return nonzero if successful, calls obstack_alloc_failed_handler if
     105   allocation fails.  */
     106
     107static int
     108_obstack_begin_worker (struct obstack *h,
     109                       _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment)
     110{
     111  struct _obstack_chunk *chunk; /* points to new chunk */
    165112
    166113  if (alignment == 0)
     
    170117    {
    171118      /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
    172         Use the values for range checking, because if range checking is off,
    173         the extra bytes won't be missed terribly, but if range checking is on
    174         and we used a larger request, a whole extra 4096 bytes would be
    175         allocated.
    176 
    177         These number are irrelevant to the new GNU malloc.  I suspect it is
    178         less sensitive to the size of the request.  */
     119        Use the values for range checking, because if range checking is off,
     120        the extra bytes won't be missed terribly, but if range checking is on
     121        and we used a larger request, a whole extra 4096 bytes would be
     122        allocated.
     123
     124        These number are irrelevant to the new GNU malloc.  I suspect it is
     125        less sensitive to the size of the request.  */
    179126      int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
    180                     + 4 + DEFAULT_ROUNDING - 1)
    181                    & ~(DEFAULT_ROUNDING - 1));
     127                    + 4 + DEFAULT_ROUNDING - 1)
     128                   & ~(DEFAULT_ROUNDING - 1));
    182129      size = 4096 - extra;
    183130    }
    184131
    185 #if defined (__STDC__) && __STDC__
    186   h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
    187   h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
    188 #else
    189   h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
    190   h->freefun = freefun;
    191 #endif
    192132  h->chunk_size = size;
    193133  h->alignment_mask = alignment - 1;
    194   h->use_extra_arg = 0;
    195 
    196   chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
     134
     135  chunk = h->chunk = call_chunkfun (h, h->chunk_size);
    197136  if (!chunk)
    198137    (*obstack_alloc_failed_handler) ();
    199   h->next_free = h->object_base = chunk->contents;
    200   h->chunk_limit = chunk->limit
    201     = (char *) chunk + h->chunk_size;
     138  h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
     139                                               alignment - 1);
     140  h->chunk_limit = chunk->limit = (char *) chunk + h->chunk_size;
    202141  chunk->prev = 0;
    203142  /* The initial chunk now contains no empty object.  */
     
    208147
    209148int
    210 _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
    211      struct obstack *h;
    212      int size;
    213      int alignment;
    214 #if defined (__STDC__) && __STDC__
    215      POINTER (*chunkfun) (POINTER, long);
    216      void (*freefun) (POINTER, POINTER);
    217 #else
    218      POINTER (*chunkfun) ();
    219      void (*freefun) ();
    220 #endif
    221      POINTER arg;
    222 {
    223   register struct _obstack_chunk *chunk; /* points to new chunk */
    224 
    225   if (alignment == 0)
    226     alignment = DEFAULT_ALIGNMENT;
    227   if (size == 0)
    228     /* Default size is what GNU malloc can fit in a 4096-byte block.  */
    229     {
    230       /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
    231          Use the values for range checking, because if range checking is off,
    232          the extra bytes won't be missed terribly, but if range checking is on
    233          and we used a larger request, a whole extra 4096 bytes would be
    234          allocated.
    235 
    236          These number are irrelevant to the new GNU malloc.  I suspect it is
    237          less sensitive to the size of the request.  */
    238       int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
    239                     + 4 + DEFAULT_ROUNDING - 1)
    240                    & ~(DEFAULT_ROUNDING - 1));
    241       size = 4096 - extra;
    242     }
    243 
    244 #if defined(__STDC__) && __STDC__
    245   h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
    246   h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
    247 #else
    248   h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
    249   h->freefun = freefun;
    250 #endif
    251   h->chunk_size = size;
    252   h->alignment_mask = alignment - 1;
     149_obstack_begin (struct obstack *h,
     150                _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment,
     151                void *(*chunkfun) (size_t),
     152                void (*freefun) (void *))
     153{
     154  h->chunkfun.plain = chunkfun;
     155  h->freefun.plain = freefun;
     156  h->use_extra_arg = 0;
     157  return _obstack_begin_worker (h, size, alignment);
     158}
     159
     160int
     161_obstack_begin_1 (struct obstack *h,
     162                  _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment,
     163                  void *(*chunkfun) (void *, size_t),
     164                  void (*freefun) (void *, void *),
     165                  void *arg)
     166{
     167  h->chunkfun.extra = chunkfun;
     168  h->freefun.extra = freefun;
    253169  h->extra_arg = arg;
    254170  h->use_extra_arg = 1;
    255 
    256   chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
    257   if (!chunk)
    258     (*obstack_alloc_failed_handler) ();
    259   h->next_free = h->object_base = chunk->contents;
    260   h->chunk_limit = chunk->limit
    261     = (char *) chunk + h->chunk_size;
    262   chunk->prev = 0;
    263   /* The initial chunk now contains no empty object.  */
    264   h->maybe_empty_object = 0;
    265   h->alloc_failed = 0;
    266   return 1;
     171  return _obstack_begin_worker (h, size, alignment);
    267172}
    268173
     
    274179
    275180void
    276 _obstack_newchunk (h, length)
    277      struct obstack *h;
    278      int length;
    279 {
    280   register struct _obstack_chunk *old_chunk = h->chunk;
    281   register struct _obstack_chunk *new_chunk;
    282   register long new_size;
    283   register int obj_size = h->next_free - h->object_base;
     181_obstack_newchunk (struct obstack *h, _OBSTACK_SIZE_T length)
     182{
     183  struct _obstack_chunk *old_chunk = h->chunk;
     184  struct _obstack_chunk *new_chunk = 0;
     185  size_t obj_size = h->next_free - h->object_base;
     186  char *object_base;
    284187
    285188  /* Compute size for new chunk.  */
    286   new_size = (obj_size + length) + (obj_size >> 3) + 100;
     189  size_t sum1 = obj_size + length;
     190  size_t sum2 = sum1 + h->alignment_mask;
     191  size_t new_size = sum2 + (obj_size >> 3) + 100;
     192  if (new_size < sum2)
     193    new_size = sum2;
    287194  if (new_size < h->chunk_size)
    288195    new_size = h->chunk_size;
    289196
    290197  /* Allocate and initialize the new chunk.  */
    291   new_chunk = CALL_CHUNKFUN (h, new_size);
     198  if (obj_size <= sum1 && sum1 <= sum2)
     199    new_chunk = call_chunkfun (h, new_size);
    292200  if (!new_chunk)
    293     (*obstack_alloc_failed_handler) ();
     201    (*obstack_alloc_failed_handler)();
    294202  h->chunk = new_chunk;
    295203  new_chunk->prev = old_chunk;
    296204  new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
    297205
    298   _obstack_memcpy(new_chunk->contents, h->object_base, obj_size);
    299 
    300   /* If the object just copied was the only data in OLD_CHUNK, */
    301   /* free that chunk and remove it from the chain. */
    302   /* But not if that chunk might contain an empty object.  */
    303   if (h->object_base == old_chunk->contents && ! h->maybe_empty_object)
     206  /* Compute an aligned object_base in the new chunk */
     207  object_base =
     208    __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
     209
     210  /* Move the existing object to the new chunk.  */
     211  memcpy (object_base, h->object_base, obj_size);
     212
     213  /* If the object just copied was the only data in OLD_CHUNK,
     214     free that chunk and remove it from the chain.
     215     But not if that chunk might contain an empty object.  */
     216  if (!h->maybe_empty_object
     217      && (h->object_base
     218          == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
     219                          h->alignment_mask)))
    304220    {
    305221      new_chunk->prev = old_chunk->prev;
    306       CALL_FREEFUN (h, old_chunk);
    307     }
    308 
    309   h->object_base = new_chunk->contents;
     222      call_freefun (h, old_chunk);
     223    }
     224
     225  h->object_base = object_base;
    310226  h->next_free = h->object_base + obj_size;
    311227  /* The new chunk certainly contains no empty object yet.  */
     
    317233   If you use it in a program, you are probably losing.  */
    318234
    319 #if defined (__STDC__) && __STDC__
    320235/* Suppress -Wmissing-prototypes warning.  We don't want to declare this in
    321236   obstack.h because it is just for debugging.  */
    322 int _obstack_allocated_p (struct obstack *h, POINTER obj);
    323 #endif
     237int _obstack_allocated_p (struct obstack *h, void *obj) __attribute_pure__;
    324238
    325239int
    326 _obstack_allocated_p (h, obj)
    327      struct obstack *h;
    328      POINTER obj;
    329 {
    330   register struct _obstack_chunk *lp;   /* below addr of any objects in this chunk */
    331   register struct _obstack_chunk *plp;  /* point to previous chunk if any */
     240_obstack_allocated_p (struct obstack *h, void *obj)
     241{
     242  struct _obstack_chunk *lp;    /* below addr of any objects in this chunk */
     243  struct _obstack_chunk *plp;   /* point to previous chunk if any */
    332244
    333245  lp = (h)->chunk;
     
    335247     the beginning of the chunk but might be an empty object exactly
    336248     at the end of an adjacent chunk.  */
    337   while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
     249  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    338250    {
    339251      plp = lp->prev;
     
    343255}
    344256
    345 
    346257/* Free objects in obstack H, including OBJ and everything allocate
    347258   more recently than OBJ.  If OBJ is zero, free everything in H.  */
    348259
    349 #undef obstack_free
    350 
    351 /* This function has two names with identical definitions.
    352    This is the first one, called from non-ANSI code.  */
    353 
    354260void
    355 _obstack_free (h, obj)
    356      struct obstack *h;
    357      POINTER obj;
    358 {
    359   register struct _obstack_chunk *lp;   /* below addr of any objects in this chunk */
    360   register struct _obstack_chunk *plp;  /* point to previous chunk if any */
     261_obstack_free (struct obstack *h, void *obj)
     262{
     263  struct _obstack_chunk *lp;    /* below addr of any objects in this chunk */
     264  struct _obstack_chunk *plp;   /* point to previous chunk if any */
    361265
    362266  lp = h->chunk;
     
    364268     But there can be an empty object at that address
    365269     at the end of another chunk.  */
    366   while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
     270  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    367271    {
    368272      plp = lp->prev;
    369       CALL_FREEFUN (h, lp);
     273      call_freefun (h, lp);
    370274      lp = plp;
    371275      /* If we switch chunks, we can't tell whether the new current
    372         chunk contains an empty object, so assume that it may.  */
     276        chunk contains an empty object, so assume that it may.  */
    373277      h->maybe_empty_object = 1;
    374278    }
     
    384288}
    385289
    386 /* This function is used from ANSI code.  */
    387 
    388 void
    389 obstack_free (h, obj)
    390      struct obstack *h;
    391      POINTER obj;
    392 {
    393   register struct _obstack_chunk *lp;   /* below addr of any objects in this chunk */
    394   register struct _obstack_chunk *plp;  /* point to previous chunk if any */
    395 
    396   lp = h->chunk;
    397   /* We use >= because there cannot be an object at the beginning of a chunk.
    398      But there can be an empty object at that address
    399      at the end of another chunk.  */
    400   while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
    401     {
    402       plp = lp->prev;
    403       CALL_FREEFUN (h, lp);
    404       lp = plp;
    405       /* If we switch chunks, we can't tell whether the new current
    406          chunk contains an empty object, so assume that it may.  */
    407       h->maybe_empty_object = 1;
    408     }
    409   if (lp)
    410     {
    411       h->object_base = h->next_free = (char *) (obj);
    412       h->chunk_limit = lp->limit;
    413       h->chunk = lp;
    414     }
    415   else if (obj != 0)
    416     /* obj is not in any of the chunks! */
    417     abort ();
    418 }
    419 
    420 
    421 int
    422 _obstack_memory_used (h)
    423      struct obstack *h;
    424 {
    425   register struct _obstack_chunk* lp;
    426   register int nbytes = 0;
     290_OBSTACK_SIZE_T
     291_obstack_memory_used (struct obstack *h)
     292{
     293  struct _obstack_chunk *lp;
     294  _OBSTACK_SIZE_T nbytes = 0;
    427295
    428296  for (lp = h->chunk; lp != 0; lp = lp->prev)
     
    433301}
    434302
    435 
     303# ifndef _OBSTACK_NO_ERROR_HANDLER
    436304/* Define the error handler.  */
    437 #ifndef _
    438 # ifdef HAVE_LIBINTL_H
    439 #  include <libintl.h>
     305#  include <stdio.h>
     306
     307/* Exit value used when 'print_and_abort' is used.  */
     308#  ifdef _LIBC
     309int obstack_exit_failure = EXIT_FAILURE;
     310#  else
     311#   include "exitfail.h"
     312#   define obstack_exit_failure exit_failure
     313#  endif
     314
     315#  ifdef _LIBC
     316#   include <libintl.h>
     317#  else
     318#   include "gettext.h"
     319#  endif
    440320#  ifndef _
    441 #   define _(Str) gettext (Str)
    442 #  endif
    443 # else
    444 #  define _(Str) (Str)
    445 # endif
    446 #endif
    447 
    448 static void
    449 print_and_abort ()
    450 {
    451   fputs (_("memory exhausted\n"), stderr);
     321#   define _(msgid) gettext (msgid)
     322#  endif
     323
     324#  ifdef _LIBC
     325#   include <libio/iolibio.h>
     326#  endif
     327
     328static __attribute_noreturn__ void
     329print_and_abort (void)
     330{
     331  /* Don't change any of these strings.  Yes, it would be possible to add
     332     the newline to the string and use fputs or so.  But this must not
     333     happen because the "memory exhausted" message appears in other places
     334     like this and the translation should be reused instead of creating
     335     a very similar string which requires a separate translation.  */
     336#  ifdef _LIBC
     337  (void) __fxprintf (NULL, "%s\n", _("memory exhausted"));
     338#  else
     339  fprintf (stderr, "%s\n", _("memory exhausted"));
     340#  endif
    452341  exit (obstack_exit_failure);
    453342}
    454343
    455 
    456 #if 0
    457 /* These are now turned off because the applications do not use it
    458    and it uses bcopy via obstack_grow, which causes trouble on sysV.  */
    459 
    460 /* Now define the functional versions of the obstack macros.
    461    Define them to simply use the corresponding macros to do the job.  */
    462 
    463 #if defined (__STDC__) && __STDC__
    464 /* These function definitions do not work with non-ANSI preprocessors;
    465    they won't pass through the macro names in parentheses.  */
    466 
    467 /* The function names appear in parentheses in order to prevent
    468    the macro-definitions of the names from being expanded there.  */
    469 
    470 POINTER (obstack_base) (obstack)
    471      struct obstack *obstack;
    472 {
    473   return obstack_base (obstack);
    474 }
    475 
    476 POINTER (obstack_next_free) (obstack)
    477      struct obstack *obstack;
    478 {
    479   return obstack_next_free (obstack);
    480 }
    481 
    482 int (obstack_object_size) (obstack)
    483      struct obstack *obstack;
    484 {
    485   return obstack_object_size (obstack);
    486 }
    487 
    488 int (obstack_room) (obstack)
    489      struct obstack *obstack;
    490 {
    491   return obstack_room (obstack);
    492 }
    493 
    494 int (obstack_make_room) (obstack, length)
    495      struct obstack *obstack;
    496      int length;
    497 {
    498   return obstack_make_room (obstack, length);
    499 }
    500 
    501 void (obstack_grow) (obstack, pointer, length)
    502      struct obstack *obstack;
    503      POINTER pointer;
    504      int length;
    505 {
    506   obstack_grow (obstack, pointer, length);
    507 }
    508 
    509 void (obstack_grow0) (obstack, pointer, length)
    510      struct obstack *obstack;
    511      POINTER pointer;
    512      int length;
    513 {
    514   obstack_grow0 (obstack, pointer, length);
    515 }
    516 
    517 void (obstack_1grow) (obstack, character)
    518      struct obstack *obstack;
    519      int character;
    520 {
    521   obstack_1grow (obstack, character);
    522 }
    523 
    524 void (obstack_blank) (obstack, length)
    525      struct obstack *obstack;
    526      int length;
    527 {
    528   obstack_blank (obstack, length);
    529 }
    530 
    531 void (obstack_1grow_fast) (obstack, character)
    532      struct obstack *obstack;
    533      int character;
    534 {
    535   obstack_1grow_fast (obstack, character);
    536 }
    537 
    538 void (obstack_blank_fast) (obstack, length)
    539      struct obstack *obstack;
    540      int length;
    541 {
    542   obstack_blank_fast (obstack, length);
    543 }
    544 
    545 POINTER (obstack_finish) (obstack)
    546      struct obstack *obstack;
    547 {
    548   return obstack_finish (obstack);
    549 }
    550 
    551 POINTER (obstack_alloc) (obstack, length)
    552      struct obstack *obstack;
    553      int length;
    554 {
    555   return obstack_alloc (obstack, length);
    556 }
    557 
    558 POINTER (obstack_copy) (obstack, pointer, length)
    559      struct obstack *obstack;
    560      POINTER pointer;
    561      int length;
    562 {
    563   return obstack_copy (obstack, pointer, length);
    564 }
    565 
    566 POINTER (obstack_copy0) (obstack, pointer, length)
    567      struct obstack *obstack;
    568      POINTER pointer;
    569      int length;
    570 {
    571   return obstack_copy0 (obstack, pointer, length);
    572 }
    573 
    574 #endif /* __STDC__ */
    575 
    576 #endif /* 0 */
    577 
    578 #endif  /* !ELIDE_CODE */
     344/* The functions allocating more room by calling 'obstack_chunk_alloc'
     345   jump to the handler pointed to by 'obstack_alloc_failed_handler'.
     346   This can be set to a user defined function which should either
     347   abort gracefully or use longjump - but shouldn't return.  This
     348   variable by default points to the internal function
     349   'print_and_abort'.  */
     350__attribute_noreturn__ void (*obstack_alloc_failed_handler) (void)
     351  = print_and_abort;
     352# endif /* !_OBSTACK_NO_ERROR_HANDLER */
     353#endif /* !_OBSTACK_ELIDE_CODE */
Note: See TracChangeset for help on using the changeset viewer.