1*a9fa9459Szrj /* obstack.c - subroutines used implicitly by object stack macros
2*a9fa9459Szrj    Copyright (C) 1988-2015 Free Software Foundation, Inc.
3*a9fa9459Szrj    This file is part of the GNU C Library.
4*a9fa9459Szrj 
5*a9fa9459Szrj    The GNU C Library is free software; you can redistribute it and/or
6*a9fa9459Szrj    modify it under the terms of the GNU Lesser General Public
7*a9fa9459Szrj    License as published by the Free Software Foundation; either
8*a9fa9459Szrj    version 2.1 of the License, or (at your option) any later version.
9*a9fa9459Szrj 
10*a9fa9459Szrj    The GNU C Library is distributed in the hope that it will be useful,
11*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*a9fa9459Szrj    Lesser General Public License for more details.
14*a9fa9459Szrj 
15*a9fa9459Szrj    You should have received a copy of the GNU Lesser General Public
16*a9fa9459Szrj    License along with the GNU C Library; if not, see
17*a9fa9459Szrj    <http://www.gnu.org/licenses/>.  */
18*a9fa9459Szrj 
19*a9fa9459Szrj 
20*a9fa9459Szrj #ifdef _LIBC
21*a9fa9459Szrj # include <obstack.h>
22*a9fa9459Szrj #else
23*a9fa9459Szrj # include <config.h>
24*a9fa9459Szrj # include "obstack.h"
25*a9fa9459Szrj #endif
26*a9fa9459Szrj 
27*a9fa9459Szrj /* NOTE BEFORE MODIFYING THIS FILE: _OBSTACK_INTERFACE_VERSION in
28*a9fa9459Szrj    obstack.h must be incremented whenever callers compiled using an old
29*a9fa9459Szrj    obstack.h can no longer properly call the functions in this file.  */
30*a9fa9459Szrj 
31*a9fa9459Szrj /* Comment out all this code if we are using the GNU C Library, and are not
32*a9fa9459Szrj    actually compiling the library itself, and the installed library
33*a9fa9459Szrj    supports the same library interface we do.  This code is part of the GNU
34*a9fa9459Szrj    C Library, but also included in many other GNU distributions.  Compiling
35*a9fa9459Szrj    and linking in this code is a waste when using the GNU C library
36*a9fa9459Szrj    (especially if it is a shared library).  Rather than having every GNU
37*a9fa9459Szrj    program understand 'configure --with-gnu-libc' and omit the object
38*a9fa9459Szrj    files, it is simpler to just do this in the source for each such file.  */
39*a9fa9459Szrj #if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
40*a9fa9459Szrj # include <gnu-versions.h>
41*a9fa9459Szrj # if (_GNU_OBSTACK_INTERFACE_VERSION == _OBSTACK_INTERFACE_VERSION	      \
42*a9fa9459Szrj       || (_GNU_OBSTACK_INTERFACE_VERSION == 1				      \
43*a9fa9459Szrj           && _OBSTACK_INTERFACE_VERSION == 2				      \
44*a9fa9459Szrj           && defined SIZEOF_INT && defined SIZEOF_SIZE_T		      \
45*a9fa9459Szrj           && SIZEOF_INT == SIZEOF_SIZE_T))
46*a9fa9459Szrj #  define _OBSTACK_ELIDE_CODE
47*a9fa9459Szrj # endif
48*a9fa9459Szrj #endif
49*a9fa9459Szrj 
50*a9fa9459Szrj #ifndef _OBSTACK_ELIDE_CODE
51*a9fa9459Szrj /* If GCC, or if an oddball (testing?) host that #defines __alignof__,
52*a9fa9459Szrj    use the already-supplied __alignof__.  Otherwise, this must be Gnulib
53*a9fa9459Szrj    (as glibc assumes GCC); defer to Gnulib's alignof_type.  */
54*a9fa9459Szrj # if !defined __GNUC__ && !defined __IBM__ALIGNOF__ && !defined __alignof__
55*a9fa9459Szrj #  if defined __cplusplus
56*a9fa9459Szrj template <class type> struct alignof_helper { char __slot1; type __slot2; };
57*a9fa9459Szrj #   define __alignof__(type) offsetof (alignof_helper<type>, __slot2)
58*a9fa9459Szrj #  else
59*a9fa9459Szrj #   define __alignof__(type)						      \
60*a9fa9459Szrj   offsetof (struct { char __slot1; type __slot2; }, __slot2)
61*a9fa9459Szrj #  endif
62*a9fa9459Szrj # endif
63*a9fa9459Szrj # include <stdlib.h>
64*a9fa9459Szrj # include <stdint.h>
65*a9fa9459Szrj 
66*a9fa9459Szrj # ifndef MAX
67*a9fa9459Szrj #  define MAX(a,b) ((a) > (b) ? (a) : (b))
68*a9fa9459Szrj # endif
69*a9fa9459Szrj 
70*a9fa9459Szrj /* Determine default alignment.  */
71*a9fa9459Szrj 
72*a9fa9459Szrj /* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
73*a9fa9459Szrj    But in fact it might be less smart and round addresses to as much as
74*a9fa9459Szrj    DEFAULT_ROUNDING.  So we prepare for it to do that.
75*a9fa9459Szrj 
76*a9fa9459Szrj    DEFAULT_ALIGNMENT cannot be an enum constant; see gnulib's alignof.h.  */
77*a9fa9459Szrj #define DEFAULT_ALIGNMENT MAX (__alignof__ (long double),		      \
78*a9fa9459Szrj                                MAX (__alignof__ (uintmax_t),		      \
79*a9fa9459Szrj                                     __alignof__ (void *)))
80*a9fa9459Szrj #define DEFAULT_ROUNDING MAX (sizeof (long double),			      \
81*a9fa9459Szrj                                MAX (sizeof (uintmax_t),			      \
82*a9fa9459Szrj                                     sizeof (void *)))
83*a9fa9459Szrj 
84*a9fa9459Szrj /* Call functions with either the traditional malloc/free calling
85*a9fa9459Szrj    interface, or the mmalloc/mfree interface (that adds an extra first
86*a9fa9459Szrj    argument), based on the value of use_extra_arg.  */
87*a9fa9459Szrj 
88*a9fa9459Szrj static void *
call_chunkfun(struct obstack * h,size_t size)89*a9fa9459Szrj call_chunkfun (struct obstack *h, size_t size)
90*a9fa9459Szrj {
91*a9fa9459Szrj   if (h->use_extra_arg)
92*a9fa9459Szrj     return h->chunkfun.extra (h->extra_arg, size);
93*a9fa9459Szrj   else
94*a9fa9459Szrj     return h->chunkfun.plain (size);
95*a9fa9459Szrj }
96*a9fa9459Szrj 
97*a9fa9459Szrj static void
call_freefun(struct obstack * h,void * old_chunk)98*a9fa9459Szrj call_freefun (struct obstack *h, void *old_chunk)
99*a9fa9459Szrj {
100*a9fa9459Szrj   if (h->use_extra_arg)
101*a9fa9459Szrj     h->freefun.extra (h->extra_arg, old_chunk);
102*a9fa9459Szrj   else
103*a9fa9459Szrj     h->freefun.plain (old_chunk);
104*a9fa9459Szrj }
105*a9fa9459Szrj 
106*a9fa9459Szrj 
107*a9fa9459Szrj /* Initialize an obstack H for use.  Specify chunk size SIZE (0 means default).
108*a9fa9459Szrj    Objects start on multiples of ALIGNMENT (0 means use default).
109*a9fa9459Szrj 
110*a9fa9459Szrj    Return nonzero if successful, calls obstack_alloc_failed_handler if
111*a9fa9459Szrj    allocation fails.  */
112*a9fa9459Szrj 
113*a9fa9459Szrj static int
_obstack_begin_worker(struct obstack * h,_OBSTACK_SIZE_T size,_OBSTACK_SIZE_T alignment)114*a9fa9459Szrj _obstack_begin_worker (struct obstack *h,
115*a9fa9459Szrj                        _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment)
116*a9fa9459Szrj {
117*a9fa9459Szrj   struct _obstack_chunk *chunk; /* points to new chunk */
118*a9fa9459Szrj 
119*a9fa9459Szrj   if (alignment == 0)
120*a9fa9459Szrj     alignment = DEFAULT_ALIGNMENT;
121*a9fa9459Szrj   if (size == 0)
122*a9fa9459Szrj     /* Default size is what GNU malloc can fit in a 4096-byte block.  */
123*a9fa9459Szrj     {
124*a9fa9459Szrj       /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
125*a9fa9459Szrj          Use the values for range checking, because if range checking is off,
126*a9fa9459Szrj          the extra bytes won't be missed terribly, but if range checking is on
127*a9fa9459Szrj          and we used a larger request, a whole extra 4096 bytes would be
128*a9fa9459Szrj          allocated.
129*a9fa9459Szrj 
130*a9fa9459Szrj          These number are irrelevant to the new GNU malloc.  I suspect it is
131*a9fa9459Szrj          less sensitive to the size of the request.  */
132*a9fa9459Szrj       int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
133*a9fa9459Szrj                     + 4 + DEFAULT_ROUNDING - 1)
134*a9fa9459Szrj                    & ~(DEFAULT_ROUNDING - 1));
135*a9fa9459Szrj       size = 4096 - extra;
136*a9fa9459Szrj     }
137*a9fa9459Szrj 
138*a9fa9459Szrj   h->chunk_size = size;
139*a9fa9459Szrj   h->alignment_mask = alignment - 1;
140*a9fa9459Szrj 
141*a9fa9459Szrj   chunk = (struct _obstack_chunk *) call_chunkfun (h, h->chunk_size);
142*a9fa9459Szrj   if (!chunk)
143*a9fa9459Szrj     (*obstack_alloc_failed_handler) ();
144*a9fa9459Szrj   h->chunk = chunk;
145*a9fa9459Szrj   h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
146*a9fa9459Szrj                                                alignment - 1);
147*a9fa9459Szrj   h->chunk_limit = chunk->limit = (char *) chunk + h->chunk_size;
148*a9fa9459Szrj   chunk->prev = 0;
149*a9fa9459Szrj   /* The initial chunk now contains no empty object.  */
150*a9fa9459Szrj   h->maybe_empty_object = 0;
151*a9fa9459Szrj   h->alloc_failed = 0;
152*a9fa9459Szrj   return 1;
153*a9fa9459Szrj }
154*a9fa9459Szrj 
155*a9fa9459Szrj int
_obstack_begin(struct obstack * h,_OBSTACK_SIZE_T size,_OBSTACK_SIZE_T alignment,void * (* chunkfun)(size_t),void (* freefun)(void *))156*a9fa9459Szrj _obstack_begin (struct obstack *h,
157*a9fa9459Szrj                 _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment,
158*a9fa9459Szrj                 void *(*chunkfun) (size_t),
159*a9fa9459Szrj                 void (*freefun) (void *))
160*a9fa9459Szrj {
161*a9fa9459Szrj   h->chunkfun.plain = chunkfun;
162*a9fa9459Szrj   h->freefun.plain = freefun;
163*a9fa9459Szrj   h->use_extra_arg = 0;
164*a9fa9459Szrj   return _obstack_begin_worker (h, size, alignment);
165*a9fa9459Szrj }
166*a9fa9459Szrj 
167*a9fa9459Szrj int
_obstack_begin_1(struct obstack * h,_OBSTACK_SIZE_T size,_OBSTACK_SIZE_T alignment,void * (* chunkfun)(void *,size_t),void (* freefun)(void *,void *),void * arg)168*a9fa9459Szrj _obstack_begin_1 (struct obstack *h,
169*a9fa9459Szrj                   _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment,
170*a9fa9459Szrj                   void *(*chunkfun) (void *, size_t),
171*a9fa9459Szrj                   void (*freefun) (void *, void *),
172*a9fa9459Szrj                   void *arg)
173*a9fa9459Szrj {
174*a9fa9459Szrj   h->chunkfun.extra = chunkfun;
175*a9fa9459Szrj   h->freefun.extra = freefun;
176*a9fa9459Szrj   h->extra_arg = arg;
177*a9fa9459Szrj   h->use_extra_arg = 1;
178*a9fa9459Szrj   return _obstack_begin_worker (h, size, alignment);
179*a9fa9459Szrj }
180*a9fa9459Szrj 
181*a9fa9459Szrj /* Allocate a new current chunk for the obstack *H
182*a9fa9459Szrj    on the assumption that LENGTH bytes need to be added
183*a9fa9459Szrj    to the current object, or a new object of length LENGTH allocated.
184*a9fa9459Szrj    Copies any partial object from the end of the old chunk
185*a9fa9459Szrj    to the beginning of the new one.  */
186*a9fa9459Szrj 
187*a9fa9459Szrj void
_obstack_newchunk(struct obstack * h,_OBSTACK_SIZE_T length)188*a9fa9459Szrj _obstack_newchunk (struct obstack *h, _OBSTACK_SIZE_T length)
189*a9fa9459Szrj {
190*a9fa9459Szrj   struct _obstack_chunk *old_chunk = h->chunk;
191*a9fa9459Szrj   struct _obstack_chunk *new_chunk = 0;
192*a9fa9459Szrj   size_t obj_size = h->next_free - h->object_base;
193*a9fa9459Szrj   char *object_base;
194*a9fa9459Szrj 
195*a9fa9459Szrj   /* Compute size for new chunk.  */
196*a9fa9459Szrj   size_t sum1 = obj_size + length;
197*a9fa9459Szrj   size_t sum2 = sum1 + h->alignment_mask;
198*a9fa9459Szrj   size_t new_size = sum2 + (obj_size >> 3) + 100;
199*a9fa9459Szrj   if (new_size < sum2)
200*a9fa9459Szrj     new_size = sum2;
201*a9fa9459Szrj   if (new_size < h->chunk_size)
202*a9fa9459Szrj     new_size = h->chunk_size;
203*a9fa9459Szrj 
204*a9fa9459Szrj   /* Allocate and initialize the new chunk.  */
205*a9fa9459Szrj   if (obj_size <= sum1 && sum1 <= sum2)
206*a9fa9459Szrj     new_chunk = (struct _obstack_chunk *) call_chunkfun (h, new_size);
207*a9fa9459Szrj   if (!new_chunk)
208*a9fa9459Szrj     (*obstack_alloc_failed_handler)();
209*a9fa9459Szrj   h->chunk = new_chunk;
210*a9fa9459Szrj   new_chunk->prev = old_chunk;
211*a9fa9459Szrj   new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
212*a9fa9459Szrj 
213*a9fa9459Szrj   /* Compute an aligned object_base in the new chunk */
214*a9fa9459Szrj   object_base =
215*a9fa9459Szrj     __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
216*a9fa9459Szrj 
217*a9fa9459Szrj   /* Move the existing object to the new chunk.  */
218*a9fa9459Szrj   memcpy (object_base, h->object_base, obj_size);
219*a9fa9459Szrj 
220*a9fa9459Szrj   /* If the object just copied was the only data in OLD_CHUNK,
221*a9fa9459Szrj      free that chunk and remove it from the chain.
222*a9fa9459Szrj      But not if that chunk might contain an empty object.  */
223*a9fa9459Szrj   if (!h->maybe_empty_object
224*a9fa9459Szrj       && (h->object_base
225*a9fa9459Szrj           == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
226*a9fa9459Szrj                           h->alignment_mask)))
227*a9fa9459Szrj     {
228*a9fa9459Szrj       new_chunk->prev = old_chunk->prev;
229*a9fa9459Szrj       call_freefun (h, old_chunk);
230*a9fa9459Szrj     }
231*a9fa9459Szrj 
232*a9fa9459Szrj   h->object_base = object_base;
233*a9fa9459Szrj   h->next_free = h->object_base + obj_size;
234*a9fa9459Szrj   /* The new chunk certainly contains no empty object yet.  */
235*a9fa9459Szrj   h->maybe_empty_object = 0;
236*a9fa9459Szrj }
237*a9fa9459Szrj 
238*a9fa9459Szrj /* Return nonzero if object OBJ has been allocated from obstack H.
239*a9fa9459Szrj    This is here for debugging.
240*a9fa9459Szrj    If you use it in a program, you are probably losing.  */
241*a9fa9459Szrj 
242*a9fa9459Szrj /* Suppress -Wmissing-prototypes warning.  We don't want to declare this in
243*a9fa9459Szrj    obstack.h because it is just for debugging.  */
244*a9fa9459Szrj int _obstack_allocated_p (struct obstack *h, void *obj) __attribute_pure__;
245*a9fa9459Szrj 
246*a9fa9459Szrj int
_obstack_allocated_p(struct obstack * h,void * obj)247*a9fa9459Szrj _obstack_allocated_p (struct obstack *h, void *obj)
248*a9fa9459Szrj {
249*a9fa9459Szrj   struct _obstack_chunk *lp;    /* below addr of any objects in this chunk */
250*a9fa9459Szrj   struct _obstack_chunk *plp;   /* point to previous chunk if any */
251*a9fa9459Szrj 
252*a9fa9459Szrj   lp = (h)->chunk;
253*a9fa9459Szrj   /* We use >= rather than > since the object cannot be exactly at
254*a9fa9459Szrj      the beginning of the chunk but might be an empty object exactly
255*a9fa9459Szrj      at the end of an adjacent chunk.  */
256*a9fa9459Szrj   while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
257*a9fa9459Szrj     {
258*a9fa9459Szrj       plp = lp->prev;
259*a9fa9459Szrj       lp = plp;
260*a9fa9459Szrj     }
261*a9fa9459Szrj   return lp != 0;
262*a9fa9459Szrj }
263*a9fa9459Szrj 
264*a9fa9459Szrj /* Free objects in obstack H, including OBJ and everything allocate
265*a9fa9459Szrj    more recently than OBJ.  If OBJ is zero, free everything in H.  */
266*a9fa9459Szrj 
267*a9fa9459Szrj void
_obstack_free(struct obstack * h,void * obj)268*a9fa9459Szrj _obstack_free (struct obstack *h, void *obj)
269*a9fa9459Szrj {
270*a9fa9459Szrj   struct _obstack_chunk *lp;    /* below addr of any objects in this chunk */
271*a9fa9459Szrj   struct _obstack_chunk *plp;   /* point to previous chunk if any */
272*a9fa9459Szrj 
273*a9fa9459Szrj   lp = h->chunk;
274*a9fa9459Szrj   /* We use >= because there cannot be an object at the beginning of a chunk.
275*a9fa9459Szrj      But there can be an empty object at that address
276*a9fa9459Szrj      at the end of another chunk.  */
277*a9fa9459Szrj   while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
278*a9fa9459Szrj     {
279*a9fa9459Szrj       plp = lp->prev;
280*a9fa9459Szrj       call_freefun (h, lp);
281*a9fa9459Szrj       lp = plp;
282*a9fa9459Szrj       /* If we switch chunks, we can't tell whether the new current
283*a9fa9459Szrj          chunk contains an empty object, so assume that it may.  */
284*a9fa9459Szrj       h->maybe_empty_object = 1;
285*a9fa9459Szrj     }
286*a9fa9459Szrj   if (lp)
287*a9fa9459Szrj     {
288*a9fa9459Szrj       h->object_base = h->next_free = (char *) (obj);
289*a9fa9459Szrj       h->chunk_limit = lp->limit;
290*a9fa9459Szrj       h->chunk = lp;
291*a9fa9459Szrj     }
292*a9fa9459Szrj   else if (obj != 0)
293*a9fa9459Szrj     /* obj is not in any of the chunks! */
294*a9fa9459Szrj     abort ();
295*a9fa9459Szrj }
296*a9fa9459Szrj 
297*a9fa9459Szrj _OBSTACK_SIZE_T
_obstack_memory_used(struct obstack * h)298*a9fa9459Szrj _obstack_memory_used (struct obstack *h)
299*a9fa9459Szrj {
300*a9fa9459Szrj   struct _obstack_chunk *lp;
301*a9fa9459Szrj   _OBSTACK_SIZE_T nbytes = 0;
302*a9fa9459Szrj 
303*a9fa9459Szrj   for (lp = h->chunk; lp != 0; lp = lp->prev)
304*a9fa9459Szrj     {
305*a9fa9459Szrj       nbytes += lp->limit - (char *) lp;
306*a9fa9459Szrj     }
307*a9fa9459Szrj   return nbytes;
308*a9fa9459Szrj }
309*a9fa9459Szrj 
310*a9fa9459Szrj # ifndef _OBSTACK_NO_ERROR_HANDLER
311*a9fa9459Szrj /* Define the error handler.  */
312*a9fa9459Szrj #  include <stdio.h>
313*a9fa9459Szrj 
314*a9fa9459Szrj /* Exit value used when 'print_and_abort' is used.  */
315*a9fa9459Szrj #  ifdef _LIBC
316*a9fa9459Szrj int obstack_exit_failure = EXIT_FAILURE;
317*a9fa9459Szrj #  else
318*a9fa9459Szrj #   ifndef EXIT_FAILURE
319*a9fa9459Szrj #    define EXIT_FAILURE 1
320*a9fa9459Szrj #   endif
321*a9fa9459Szrj #   define obstack_exit_failure EXIT_FAILURE
322*a9fa9459Szrj #  endif
323*a9fa9459Szrj 
324*a9fa9459Szrj #  if defined _LIBC || (HAVE_LIBINTL_H && ENABLE_NLS)
325*a9fa9459Szrj #   include <libintl.h>
326*a9fa9459Szrj #   ifndef _
327*a9fa9459Szrj #    define _(msgid) gettext (msgid)
328*a9fa9459Szrj #   endif
329*a9fa9459Szrj #  else
330*a9fa9459Szrj #   ifndef _
331*a9fa9459Szrj #    define _(msgid) (msgid)
332*a9fa9459Szrj #   endif
333*a9fa9459Szrj #  endif
334*a9fa9459Szrj 
335*a9fa9459Szrj #  if !(defined _Noreturn						      \
336*a9fa9459Szrj         || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112))
337*a9fa9459Szrj #   if ((defined __GNUC__						      \
338*a9fa9459Szrj 	 && (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)))	      \
339*a9fa9459Szrj 	|| (defined __SUNPRO_C && __SUNPRO_C >= 0x5110))
340*a9fa9459Szrj #    define _Noreturn __attribute__ ((__noreturn__))
341*a9fa9459Szrj #   elif defined _MSC_VER && _MSC_VER >= 1200
342*a9fa9459Szrj #    define _Noreturn __declspec (noreturn)
343*a9fa9459Szrj #   else
344*a9fa9459Szrj #    define _Noreturn
345*a9fa9459Szrj #   endif
346*a9fa9459Szrj #  endif
347*a9fa9459Szrj 
348*a9fa9459Szrj #  ifdef _LIBC
349*a9fa9459Szrj #   include <libio/iolibio.h>
350*a9fa9459Szrj #  endif
351*a9fa9459Szrj 
352*a9fa9459Szrj static _Noreturn void
print_and_abort(void)353*a9fa9459Szrj print_and_abort (void)
354*a9fa9459Szrj {
355*a9fa9459Szrj   /* Don't change any of these strings.  Yes, it would be possible to add
356*a9fa9459Szrj      the newline to the string and use fputs or so.  But this must not
357*a9fa9459Szrj      happen because the "memory exhausted" message appears in other places
358*a9fa9459Szrj      like this and the translation should be reused instead of creating
359*a9fa9459Szrj      a very similar string which requires a separate translation.  */
360*a9fa9459Szrj #  ifdef _LIBC
361*a9fa9459Szrj   (void) __fxprintf (NULL, "%s\n", _("memory exhausted"));
362*a9fa9459Szrj #  else
363*a9fa9459Szrj   fprintf (stderr, "%s\n", _("memory exhausted"));
364*a9fa9459Szrj #  endif
365*a9fa9459Szrj   exit (obstack_exit_failure);
366*a9fa9459Szrj }
367*a9fa9459Szrj 
368*a9fa9459Szrj /* The functions allocating more room by calling 'obstack_chunk_alloc'
369*a9fa9459Szrj    jump to the handler pointed to by 'obstack_alloc_failed_handler'.
370*a9fa9459Szrj    This can be set to a user defined function which should either
371*a9fa9459Szrj    abort gracefully or use longjump - but shouldn't return.  This
372*a9fa9459Szrj    variable by default points to the internal function
373*a9fa9459Szrj    'print_and_abort'.  */
374*a9fa9459Szrj void (*obstack_alloc_failed_handler) (void) = print_and_abort;
375*a9fa9459Szrj # endif /* !_OBSTACK_NO_ERROR_HANDLER */
376*a9fa9459Szrj #endif /* !_OBSTACK_ELIDE_CODE */
377