xref: /dflybsd-src/contrib/gcc-8.0/include/obstack.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* obstack.h - object stack macros
2*38fd1498Szrj    Copyright (C) 1988-2018 Free Software Foundation, Inc.
3*38fd1498Szrj    This file is part of the GNU C Library.
4*38fd1498Szrj 
5*38fd1498Szrj    The GNU C Library is free software; you can redistribute it and/or
6*38fd1498Szrj    modify it under the terms of the GNU Lesser General Public
7*38fd1498Szrj    License as published by the Free Software Foundation; either
8*38fd1498Szrj    version 2.1 of the License, or (at your option) any later version.
9*38fd1498Szrj 
10*38fd1498Szrj    The GNU C Library is distributed in the hope that it will be useful,
11*38fd1498Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*38fd1498Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*38fd1498Szrj    Lesser General Public License for more details.
14*38fd1498Szrj 
15*38fd1498Szrj    You should have received a copy of the GNU Lesser General Public
16*38fd1498Szrj    License along with the GNU C Library; if not, see
17*38fd1498Szrj    <http://www.gnu.org/licenses/>.  */
18*38fd1498Szrj 
19*38fd1498Szrj /* Summary:
20*38fd1498Szrj 
21*38fd1498Szrj    All the apparent functions defined here are macros. The idea
22*38fd1498Szrj    is that you would use these pre-tested macros to solve a
23*38fd1498Szrj    very specific set of problems, and they would run fast.
24*38fd1498Szrj    Caution: no side-effects in arguments please!! They may be
25*38fd1498Szrj    evaluated MANY times!!
26*38fd1498Szrj 
27*38fd1498Szrj    These macros operate a stack of objects.  Each object starts life
28*38fd1498Szrj    small, and may grow to maturity.  (Consider building a word syllable
29*38fd1498Szrj    by syllable.)  An object can move while it is growing.  Once it has
30*38fd1498Szrj    been "finished" it never changes address again.  So the "top of the
31*38fd1498Szrj    stack" is typically an immature growing object, while the rest of the
32*38fd1498Szrj    stack is of mature, fixed size and fixed address objects.
33*38fd1498Szrj 
34*38fd1498Szrj    These routines grab large chunks of memory, using a function you
35*38fd1498Szrj    supply, called 'obstack_chunk_alloc'.  On occasion, they free chunks,
36*38fd1498Szrj    by calling 'obstack_chunk_free'.  You must define them and declare
37*38fd1498Szrj    them before using any obstack macros.
38*38fd1498Szrj 
39*38fd1498Szrj    Each independent stack is represented by a 'struct obstack'.
40*38fd1498Szrj    Each of the obstack macros expects a pointer to such a structure
41*38fd1498Szrj    as the first argument.
42*38fd1498Szrj 
43*38fd1498Szrj    One motivation for this package is the problem of growing char strings
44*38fd1498Szrj    in symbol tables.  Unless you are "fascist pig with a read-only mind"
45*38fd1498Szrj    --Gosper's immortal quote from HAKMEM item 154, out of context--you
46*38fd1498Szrj    would not like to put any arbitrary upper limit on the length of your
47*38fd1498Szrj    symbols.
48*38fd1498Szrj 
49*38fd1498Szrj    In practice this often means you will build many short symbols and a
50*38fd1498Szrj    few long symbols.  At the time you are reading a symbol you don't know
51*38fd1498Szrj    how long it is.  One traditional method is to read a symbol into a
52*38fd1498Szrj    buffer, realloc()ating the buffer every time you try to read a symbol
53*38fd1498Szrj    that is longer than the buffer.  This is beaut, but you still will
54*38fd1498Szrj    want to copy the symbol from the buffer to a more permanent
55*38fd1498Szrj    symbol-table entry say about half the time.
56*38fd1498Szrj 
57*38fd1498Szrj    With obstacks, you can work differently.  Use one obstack for all symbol
58*38fd1498Szrj    names.  As you read a symbol, grow the name in the obstack gradually.
59*38fd1498Szrj    When the name is complete, finalize it.  Then, if the symbol exists already,
60*38fd1498Szrj    free the newly read name.
61*38fd1498Szrj 
62*38fd1498Szrj    The way we do this is to take a large chunk, allocating memory from
63*38fd1498Szrj    low addresses.  When you want to build a symbol in the chunk you just
64*38fd1498Szrj    add chars above the current "high water mark" in the chunk.  When you
65*38fd1498Szrj    have finished adding chars, because you got to the end of the symbol,
66*38fd1498Szrj    you know how long the chars are, and you can create a new object.
67*38fd1498Szrj    Mostly the chars will not burst over the highest address of the chunk,
68*38fd1498Szrj    because you would typically expect a chunk to be (say) 100 times as
69*38fd1498Szrj    long as an average object.
70*38fd1498Szrj 
71*38fd1498Szrj    In case that isn't clear, when we have enough chars to make up
72*38fd1498Szrj    the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
73*38fd1498Szrj    so we just point to it where it lies.  No moving of chars is
74*38fd1498Szrj    needed and this is the second win: potentially long strings need
75*38fd1498Szrj    never be explicitly shuffled. Once an object is formed, it does not
76*38fd1498Szrj    change its address during its lifetime.
77*38fd1498Szrj 
78*38fd1498Szrj    When the chars burst over a chunk boundary, we allocate a larger
79*38fd1498Szrj    chunk, and then copy the partly formed object from the end of the old
80*38fd1498Szrj    chunk to the beginning of the new larger chunk.  We then carry on
81*38fd1498Szrj    accreting characters to the end of the object as we normally would.
82*38fd1498Szrj 
83*38fd1498Szrj    A special macro is provided to add a single char at a time to a
84*38fd1498Szrj    growing object.  This allows the use of register variables, which
85*38fd1498Szrj    break the ordinary 'growth' macro.
86*38fd1498Szrj 
87*38fd1498Szrj    Summary:
88*38fd1498Szrj         We allocate large chunks.
89*38fd1498Szrj         We carve out one object at a time from the current chunk.
90*38fd1498Szrj         Once carved, an object never moves.
91*38fd1498Szrj         We are free to append data of any size to the currently
92*38fd1498Szrj           growing object.
93*38fd1498Szrj         Exactly one object is growing in an obstack at any one time.
94*38fd1498Szrj         You can run one obstack per control block.
95*38fd1498Szrj         You may have as many control blocks as you dare.
96*38fd1498Szrj         Because of the way we do it, you can "unwind" an obstack
97*38fd1498Szrj           back to a previous state. (You may remove objects much
98*38fd1498Szrj           as you would with a stack.)
99*38fd1498Szrj  */
100*38fd1498Szrj 
101*38fd1498Szrj 
102*38fd1498Szrj /* Don't do the contents of this file more than once.  */
103*38fd1498Szrj 
104*38fd1498Szrj #ifndef _OBSTACK_H
105*38fd1498Szrj #define _OBSTACK_H 1
106*38fd1498Szrj 
107*38fd1498Szrj #ifndef _OBSTACK_INTERFACE_VERSION
108*38fd1498Szrj # define _OBSTACK_INTERFACE_VERSION 2
109*38fd1498Szrj #endif
110*38fd1498Szrj 
111*38fd1498Szrj #include <stddef.h>             /* For size_t and ptrdiff_t.  */
112*38fd1498Szrj #include <string.h>             /* For __GNU_LIBRARY__, and memcpy.  */
113*38fd1498Szrj 
114*38fd1498Szrj #if _OBSTACK_INTERFACE_VERSION == 1
115*38fd1498Szrj /* For binary compatibility with obstack version 1, which used "int"
116*38fd1498Szrj    and "long" for these two types.  */
117*38fd1498Szrj # define _OBSTACK_SIZE_T unsigned int
118*38fd1498Szrj # define _CHUNK_SIZE_T unsigned long
119*38fd1498Szrj # define _OBSTACK_CAST(type, expr) ((type) (expr))
120*38fd1498Szrj #else
121*38fd1498Szrj /* Version 2 with sane types, especially for 64-bit hosts.  */
122*38fd1498Szrj # define _OBSTACK_SIZE_T size_t
123*38fd1498Szrj # define _CHUNK_SIZE_T size_t
124*38fd1498Szrj # define _OBSTACK_CAST(type, expr) (expr)
125*38fd1498Szrj #endif
126*38fd1498Szrj 
127*38fd1498Szrj /* If B is the base of an object addressed by P, return the result of
128*38fd1498Szrj    aligning P to the next multiple of A + 1.  B and P must be of type
129*38fd1498Szrj    char *.  A + 1 must be a power of 2.  */
130*38fd1498Szrj 
131*38fd1498Szrj #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
132*38fd1498Szrj 
133*38fd1498Szrj /* Similar to __BPTR_ALIGN (B, P, A), except optimize the common case
134*38fd1498Szrj    where pointers can be converted to integers, aligned as integers,
135*38fd1498Szrj    and converted back again.  If ptrdiff_t is narrower than a
136*38fd1498Szrj    pointer (e.g., the AS/400), play it safe and compute the alignment
137*38fd1498Szrj    relative to B.  Otherwise, use the faster strategy of computing the
138*38fd1498Szrj    alignment relative to 0.  */
139*38fd1498Szrj 
140*38fd1498Szrj #define __PTR_ALIGN(B, P, A)						      \
141*38fd1498Szrj   __BPTR_ALIGN (sizeof (ptrdiff_t) < sizeof (void *) ? (B) : (char *) 0,      \
142*38fd1498Szrj                 P, A)
143*38fd1498Szrj 
144*38fd1498Szrj #ifndef __attribute_pure__
145*38fd1498Szrj # if defined __GNUC_MINOR__ && __GNUC__ * 1000 + __GNUC_MINOR__ >= 2096
146*38fd1498Szrj #  define __attribute_pure__ __attribute__ ((__pure__))
147*38fd1498Szrj # else
148*38fd1498Szrj #  define __attribute_pure__
149*38fd1498Szrj # endif
150*38fd1498Szrj #endif
151*38fd1498Szrj 
152*38fd1498Szrj #ifdef __cplusplus
153*38fd1498Szrj extern "C" {
154*38fd1498Szrj #endif
155*38fd1498Szrj 
156*38fd1498Szrj struct _obstack_chunk           /* Lives at front of each chunk. */
157*38fd1498Szrj {
158*38fd1498Szrj   char *limit;                  /* 1 past end of this chunk */
159*38fd1498Szrj   struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
160*38fd1498Szrj   char contents[4];             /* objects begin here */
161*38fd1498Szrj };
162*38fd1498Szrj 
163*38fd1498Szrj struct obstack          /* control current object in current chunk */
164*38fd1498Szrj {
165*38fd1498Szrj   _CHUNK_SIZE_T chunk_size;     /* preferred size to allocate chunks in */
166*38fd1498Szrj   struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */
167*38fd1498Szrj   char *object_base;            /* address of object we are building */
168*38fd1498Szrj   char *next_free;              /* where to add next char to current object */
169*38fd1498Szrj   char *chunk_limit;            /* address of char after current chunk */
170*38fd1498Szrj   union
171*38fd1498Szrj   {
172*38fd1498Szrj     _OBSTACK_SIZE_T i;
173*38fd1498Szrj     void *p;
174*38fd1498Szrj   } temp;                       /* Temporary for some macros.  */
175*38fd1498Szrj   _OBSTACK_SIZE_T alignment_mask;  /* Mask of alignment for each object. */
176*38fd1498Szrj 
177*38fd1498Szrj   /* These prototypes vary based on 'use_extra_arg'.  */
178*38fd1498Szrj   union
179*38fd1498Szrj   {
180*38fd1498Szrj     void *(*plain) (size_t);
181*38fd1498Szrj     void *(*extra) (void *, size_t);
182*38fd1498Szrj   } chunkfun;
183*38fd1498Szrj   union
184*38fd1498Szrj   {
185*38fd1498Szrj     void (*plain) (void *);
186*38fd1498Szrj     void (*extra) (void *, void *);
187*38fd1498Szrj   } freefun;
188*38fd1498Szrj 
189*38fd1498Szrj   void *extra_arg;              /* first arg for chunk alloc/dealloc funcs */
190*38fd1498Szrj   unsigned use_extra_arg : 1;     /* chunk alloc/dealloc funcs take extra arg */
191*38fd1498Szrj   unsigned maybe_empty_object : 1; /* There is a possibility that the current
192*38fd1498Szrj                                       chunk contains a zero-length object.  This
193*38fd1498Szrj                                       prevents freeing the chunk if we allocate
194*38fd1498Szrj                                       a bigger chunk to replace it. */
195*38fd1498Szrj   unsigned alloc_failed : 1;      /* No longer used, as we now call the failed
196*38fd1498Szrj                                      handler on error, but retained for binary
197*38fd1498Szrj                                      compatibility.  */
198*38fd1498Szrj };
199*38fd1498Szrj 
200*38fd1498Szrj /* Declare the external functions we use; they are in obstack.c.  */
201*38fd1498Szrj 
202*38fd1498Szrj extern void _obstack_newchunk (struct obstack *, _OBSTACK_SIZE_T);
203*38fd1498Szrj extern void _obstack_free (struct obstack *, void *);
204*38fd1498Szrj extern int _obstack_begin (struct obstack *,
205*38fd1498Szrj                            _OBSTACK_SIZE_T, _OBSTACK_SIZE_T,
206*38fd1498Szrj                            void *(*) (size_t), void (*) (void *));
207*38fd1498Szrj extern int _obstack_begin_1 (struct obstack *,
208*38fd1498Szrj                              _OBSTACK_SIZE_T, _OBSTACK_SIZE_T,
209*38fd1498Szrj                              void *(*) (void *, size_t),
210*38fd1498Szrj                              void (*) (void *, void *), void *);
211*38fd1498Szrj extern _OBSTACK_SIZE_T _obstack_memory_used (struct obstack *)
212*38fd1498Szrj   __attribute_pure__;
213*38fd1498Szrj 
214*38fd1498Szrj 
215*38fd1498Szrj /* Error handler called when 'obstack_chunk_alloc' failed to allocate
216*38fd1498Szrj    more memory.  This can be set to a user defined function which
217*38fd1498Szrj    should either abort gracefully or use longjump - but shouldn't
218*38fd1498Szrj    return.  The default action is to print a message and abort.  */
219*38fd1498Szrj extern void (*obstack_alloc_failed_handler) (void);
220*38fd1498Szrj 
221*38fd1498Szrj /* Exit value used when 'print_and_abort' is used.  */
222*38fd1498Szrj extern int obstack_exit_failure;
223*38fd1498Szrj 
224*38fd1498Szrj /* Pointer to beginning of object being allocated or to be allocated next.
225*38fd1498Szrj    Note that this might not be the final address of the object
226*38fd1498Szrj    because a new chunk might be needed to hold the final size.  */
227*38fd1498Szrj 
228*38fd1498Szrj #define obstack_base(h) ((void *) (h)->object_base)
229*38fd1498Szrj 
230*38fd1498Szrj /* Size for allocating ordinary chunks.  */
231*38fd1498Szrj 
232*38fd1498Szrj #define obstack_chunk_size(h) ((h)->chunk_size)
233*38fd1498Szrj 
234*38fd1498Szrj /* Pointer to next byte not yet allocated in current chunk.  */
235*38fd1498Szrj 
236*38fd1498Szrj #define obstack_next_free(h) ((void *) (h)->next_free)
237*38fd1498Szrj 
238*38fd1498Szrj /* Mask specifying low bits that should be clear in address of an object.  */
239*38fd1498Szrj 
240*38fd1498Szrj #define obstack_alignment_mask(h) ((h)->alignment_mask)
241*38fd1498Szrj 
242*38fd1498Szrj /* To prevent prototype warnings provide complete argument list.  */
243*38fd1498Szrj #define obstack_init(h)							      \
244*38fd1498Szrj   _obstack_begin ((h), 0, 0,						      \
245*38fd1498Szrj                   _OBSTACK_CAST (void *(*) (size_t), obstack_chunk_alloc),    \
246*38fd1498Szrj                   _OBSTACK_CAST (void (*) (void *), obstack_chunk_free))
247*38fd1498Szrj 
248*38fd1498Szrj #define obstack_begin(h, size)						      \
249*38fd1498Szrj   _obstack_begin ((h), (size), 0,					      \
250*38fd1498Szrj                   _OBSTACK_CAST (void *(*) (size_t), obstack_chunk_alloc), \
251*38fd1498Szrj                   _OBSTACK_CAST (void (*) (void *), obstack_chunk_free))
252*38fd1498Szrj 
253*38fd1498Szrj #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun)     \
254*38fd1498Szrj   _obstack_begin ((h), (size), (alignment),				      \
255*38fd1498Szrj                   _OBSTACK_CAST (void *(*) (size_t), chunkfun),		      \
256*38fd1498Szrj                   _OBSTACK_CAST (void (*) (void *), freefun))
257*38fd1498Szrj 
258*38fd1498Szrj #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
259*38fd1498Szrj   _obstack_begin_1 ((h), (size), (alignment),				      \
260*38fd1498Szrj                     _OBSTACK_CAST (void *(*) (void *, size_t), chunkfun),     \
261*38fd1498Szrj                     _OBSTACK_CAST (void (*) (void *, void *), freefun), arg)
262*38fd1498Szrj 
263*38fd1498Szrj #define obstack_chunkfun(h, newchunkfun)				      \
264*38fd1498Szrj   ((void) ((h)->chunkfun.extra = (void *(*) (void *, size_t)) (newchunkfun)))
265*38fd1498Szrj 
266*38fd1498Szrj #define obstack_freefun(h, newfreefun)					      \
267*38fd1498Szrj   ((void) ((h)->freefun.extra = (void *(*) (void *, void *)) (newfreefun)))
268*38fd1498Szrj 
269*38fd1498Szrj #define obstack_1grow_fast(h, achar) ((void) (*((h)->next_free)++ = (achar)))
270*38fd1498Szrj 
271*38fd1498Szrj #define obstack_blank_fast(h, n) ((void) ((h)->next_free += (n)))
272*38fd1498Szrj 
273*38fd1498Szrj #define obstack_memory_used(h) _obstack_memory_used (h)
274*38fd1498Szrj 
275*38fd1498Szrj #if defined __GNUC__
276*38fd1498Szrj # if !defined __GNUC_MINOR__ || __GNUC__ * 1000 + __GNUC_MINOR__ < 2008
277*38fd1498Szrj #  define __extension__
278*38fd1498Szrj # endif
279*38fd1498Szrj 
280*38fd1498Szrj /* For GNU C, if not -traditional,
281*38fd1498Szrj    we can define these macros to compute all args only once
282*38fd1498Szrj    without using a global variable.
283*38fd1498Szrj    Also, we can avoid using the 'temp' slot, to make faster code.  */
284*38fd1498Szrj 
285*38fd1498Szrj # define obstack_object_size(OBSTACK)					      \
286*38fd1498Szrj   __extension__								      \
287*38fd1498Szrj     ({ struct obstack const *__o = (OBSTACK);				      \
288*38fd1498Szrj        (_OBSTACK_SIZE_T) (__o->next_free - __o->object_base); })
289*38fd1498Szrj 
290*38fd1498Szrj /* The local variable is named __o1 to avoid a shadowed variable
291*38fd1498Szrj    warning when invoked from other obstack macros.  */
292*38fd1498Szrj # define obstack_room(OBSTACK)						      \
293*38fd1498Szrj   __extension__								      \
294*38fd1498Szrj     ({ struct obstack const *__o1 = (OBSTACK);				      \
295*38fd1498Szrj        (_OBSTACK_SIZE_T) (__o1->chunk_limit - __o1->next_free); })
296*38fd1498Szrj 
297*38fd1498Szrj # define obstack_make_room(OBSTACK, length)				      \
298*38fd1498Szrj   __extension__								      \
299*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
300*38fd1498Szrj        _OBSTACK_SIZE_T __len = (length);				      \
301*38fd1498Szrj        if (obstack_room (__o) < __len)					      \
302*38fd1498Szrj          _obstack_newchunk (__o, __len);				      \
303*38fd1498Szrj        (void) 0; })
304*38fd1498Szrj 
305*38fd1498Szrj # define obstack_empty_p(OBSTACK)					      \
306*38fd1498Szrj   __extension__								      \
307*38fd1498Szrj     ({ struct obstack const *__o = (OBSTACK);				      \
308*38fd1498Szrj        (__o->chunk->prev == 0						      \
309*38fd1498Szrj         && __o->next_free == __PTR_ALIGN ((char *) __o->chunk,		      \
310*38fd1498Szrj                                           __o->chunk->contents,		      \
311*38fd1498Szrj                                           __o->alignment_mask)); })
312*38fd1498Szrj 
313*38fd1498Szrj # define obstack_grow(OBSTACK, where, length)				      \
314*38fd1498Szrj   __extension__								      \
315*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
316*38fd1498Szrj        _OBSTACK_SIZE_T __len = (length);				      \
317*38fd1498Szrj        if (obstack_room (__o) < __len)					      \
318*38fd1498Szrj          _obstack_newchunk (__o, __len);				      \
319*38fd1498Szrj        memcpy (__o->next_free, where, __len);				      \
320*38fd1498Szrj        __o->next_free += __len;						      \
321*38fd1498Szrj        (void) 0; })
322*38fd1498Szrj 
323*38fd1498Szrj # define obstack_grow0(OBSTACK, where, length)				      \
324*38fd1498Szrj   __extension__								      \
325*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
326*38fd1498Szrj        _OBSTACK_SIZE_T __len = (length);				      \
327*38fd1498Szrj        if (obstack_room (__o) < __len + 1)				      \
328*38fd1498Szrj          _obstack_newchunk (__o, __len + 1);				      \
329*38fd1498Szrj        memcpy (__o->next_free, where, __len);				      \
330*38fd1498Szrj        __o->next_free += __len;						      \
331*38fd1498Szrj        *(__o->next_free)++ = 0;						      \
332*38fd1498Szrj        (void) 0; })
333*38fd1498Szrj 
334*38fd1498Szrj # define obstack_1grow(OBSTACK, datum)					      \
335*38fd1498Szrj   __extension__								      \
336*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
337*38fd1498Szrj        if (obstack_room (__o) < 1)					      \
338*38fd1498Szrj          _obstack_newchunk (__o, 1);					      \
339*38fd1498Szrj        obstack_1grow_fast (__o, datum); })
340*38fd1498Szrj 
341*38fd1498Szrj /* These assume that the obstack alignment is good enough for pointers
342*38fd1498Szrj    or ints, and that the data added so far to the current object
343*38fd1498Szrj    shares that much alignment.  */
344*38fd1498Szrj 
345*38fd1498Szrj # define obstack_ptr_grow(OBSTACK, datum)				      \
346*38fd1498Szrj   __extension__								      \
347*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
348*38fd1498Szrj        if (obstack_room (__o) < sizeof (void *))			      \
349*38fd1498Szrj          _obstack_newchunk (__o, sizeof (void *));			      \
350*38fd1498Szrj        obstack_ptr_grow_fast (__o, datum); })
351*38fd1498Szrj 
352*38fd1498Szrj # define obstack_int_grow(OBSTACK, datum)				      \
353*38fd1498Szrj   __extension__								      \
354*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
355*38fd1498Szrj        if (obstack_room (__o) < sizeof (int))				      \
356*38fd1498Szrj          _obstack_newchunk (__o, sizeof (int));				      \
357*38fd1498Szrj        obstack_int_grow_fast (__o, datum); })
358*38fd1498Szrj 
359*38fd1498Szrj # define obstack_ptr_grow_fast(OBSTACK, aptr)				      \
360*38fd1498Szrj   __extension__								      \
361*38fd1498Szrj     ({ struct obstack *__o1 = (OBSTACK);				      \
362*38fd1498Szrj        void *__p1 = __o1->next_free;					      \
363*38fd1498Szrj        *(const void **) __p1 = (aptr);					      \
364*38fd1498Szrj        __o1->next_free += sizeof (const void *);			      \
365*38fd1498Szrj        (void) 0; })
366*38fd1498Szrj 
367*38fd1498Szrj # define obstack_int_grow_fast(OBSTACK, aint)				      \
368*38fd1498Szrj   __extension__								      \
369*38fd1498Szrj     ({ struct obstack *__o1 = (OBSTACK);				      \
370*38fd1498Szrj        void *__p1 = __o1->next_free;					      \
371*38fd1498Szrj        *(int *) __p1 = (aint);						      \
372*38fd1498Szrj        __o1->next_free += sizeof (int);					      \
373*38fd1498Szrj        (void) 0; })
374*38fd1498Szrj 
375*38fd1498Szrj # define obstack_blank(OBSTACK, length)					      \
376*38fd1498Szrj   __extension__								      \
377*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
378*38fd1498Szrj        _OBSTACK_SIZE_T __len = (length);				      \
379*38fd1498Szrj        if (obstack_room (__o) < __len)					      \
380*38fd1498Szrj          _obstack_newchunk (__o, __len);				      \
381*38fd1498Szrj        obstack_blank_fast (__o, __len); })
382*38fd1498Szrj 
383*38fd1498Szrj # define obstack_alloc(OBSTACK, length)					      \
384*38fd1498Szrj   __extension__								      \
385*38fd1498Szrj     ({ struct obstack *__h = (OBSTACK);					      \
386*38fd1498Szrj        obstack_blank (__h, (length));					      \
387*38fd1498Szrj        obstack_finish (__h); })
388*38fd1498Szrj 
389*38fd1498Szrj # define obstack_copy(OBSTACK, where, length)				      \
390*38fd1498Szrj   __extension__								      \
391*38fd1498Szrj     ({ struct obstack *__h = (OBSTACK);					      \
392*38fd1498Szrj        obstack_grow (__h, (where), (length));				      \
393*38fd1498Szrj        obstack_finish (__h); })
394*38fd1498Szrj 
395*38fd1498Szrj # define obstack_copy0(OBSTACK, where, length)				      \
396*38fd1498Szrj   __extension__								      \
397*38fd1498Szrj     ({ struct obstack *__h = (OBSTACK);					      \
398*38fd1498Szrj        obstack_grow0 (__h, (where), (length));				      \
399*38fd1498Szrj        obstack_finish (__h); })
400*38fd1498Szrj 
401*38fd1498Szrj /* The local variable is named __o1 to avoid a shadowed variable
402*38fd1498Szrj    warning when invoked from other obstack macros, typically obstack_free.  */
403*38fd1498Szrj # define obstack_finish(OBSTACK)					      \
404*38fd1498Szrj   __extension__								      \
405*38fd1498Szrj     ({ struct obstack *__o1 = (OBSTACK);				      \
406*38fd1498Szrj        void *__value = (void *) __o1->object_base;			      \
407*38fd1498Szrj        if (__o1->next_free == __value)					      \
408*38fd1498Szrj          __o1->maybe_empty_object = 1;					      \
409*38fd1498Szrj        __o1->next_free							      \
410*38fd1498Szrj          = __PTR_ALIGN (__o1->object_base, __o1->next_free,		      \
411*38fd1498Szrj                         __o1->alignment_mask);				      \
412*38fd1498Szrj        if ((size_t) (__o1->next_free - (char *) __o1->chunk)		      \
413*38fd1498Szrj            > (size_t) (__o1->chunk_limit - (char *) __o1->chunk))	      \
414*38fd1498Szrj          __o1->next_free = __o1->chunk_limit;				      \
415*38fd1498Szrj        __o1->object_base = __o1->next_free;				      \
416*38fd1498Szrj        __value; })
417*38fd1498Szrj 
418*38fd1498Szrj # define obstack_free(OBSTACK, OBJ)					      \
419*38fd1498Szrj   __extension__								      \
420*38fd1498Szrj     ({ struct obstack *__o = (OBSTACK);					      \
421*38fd1498Szrj        void *__obj = (void *) (OBJ);					      \
422*38fd1498Szrj        if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit)  \
423*38fd1498Szrj          __o->next_free = __o->object_base = (char *) __obj;		      \
424*38fd1498Szrj        else								      \
425*38fd1498Szrj          _obstack_free (__o, __obj); })
426*38fd1498Szrj 
427*38fd1498Szrj #else /* not __GNUC__ */
428*38fd1498Szrj 
429*38fd1498Szrj # define obstack_object_size(h)						      \
430*38fd1498Szrj   ((_OBSTACK_SIZE_T) ((h)->next_free - (h)->object_base))
431*38fd1498Szrj 
432*38fd1498Szrj # define obstack_room(h)						      \
433*38fd1498Szrj   ((_OBSTACK_SIZE_T) ((h)->chunk_limit - (h)->next_free))
434*38fd1498Szrj 
435*38fd1498Szrj # define obstack_empty_p(h)						      \
436*38fd1498Szrj   ((h)->chunk->prev == 0						      \
437*38fd1498Szrj    && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk,		      \
438*38fd1498Szrj                                      (h)->chunk->contents,		      \
439*38fd1498Szrj                                      (h)->alignment_mask))
440*38fd1498Szrj 
441*38fd1498Szrj /* Note that the call to _obstack_newchunk is enclosed in (..., 0)
442*38fd1498Szrj    so that we can avoid having void expressions
443*38fd1498Szrj    in the arms of the conditional expression.
444*38fd1498Szrj    Casting the third operand to void was tried before,
445*38fd1498Szrj    but some compilers won't accept it.  */
446*38fd1498Szrj 
447*38fd1498Szrj # define obstack_make_room(h, length)					      \
448*38fd1498Szrj   ((h)->temp.i = (length),						      \
449*38fd1498Szrj    ((obstack_room (h) < (h)->temp.i)					      \
450*38fd1498Szrj     ? (_obstack_newchunk (h, (h)->temp.i), 0) : 0),			      \
451*38fd1498Szrj    (void) 0)
452*38fd1498Szrj 
453*38fd1498Szrj # define obstack_grow(h, where, length)					      \
454*38fd1498Szrj   ((h)->temp.i = (length),						      \
455*38fd1498Szrj    ((obstack_room (h) < (h)->temp.i)					      \
456*38fd1498Szrj    ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0),			      \
457*38fd1498Szrj    memcpy ((h)->next_free, where, (h)->temp.i),				      \
458*38fd1498Szrj    (h)->next_free += (h)->temp.i,					      \
459*38fd1498Szrj    (void) 0)
460*38fd1498Szrj 
461*38fd1498Szrj # define obstack_grow0(h, where, length)				      \
462*38fd1498Szrj   ((h)->temp.i = (length),						      \
463*38fd1498Szrj    ((obstack_room (h) < (h)->temp.i + 1)				      \
464*38fd1498Szrj    ? (_obstack_newchunk ((h), (h)->temp.i + 1), 0) : 0),		      \
465*38fd1498Szrj    memcpy ((h)->next_free, where, (h)->temp.i),				      \
466*38fd1498Szrj    (h)->next_free += (h)->temp.i,					      \
467*38fd1498Szrj    *((h)->next_free)++ = 0,						      \
468*38fd1498Szrj    (void) 0)
469*38fd1498Szrj 
470*38fd1498Szrj # define obstack_1grow(h, datum)					      \
471*38fd1498Szrj   (((obstack_room (h) < 1)						      \
472*38fd1498Szrj     ? (_obstack_newchunk ((h), 1), 0) : 0),				      \
473*38fd1498Szrj    obstack_1grow_fast (h, datum))
474*38fd1498Szrj 
475*38fd1498Szrj # define obstack_ptr_grow(h, datum)					      \
476*38fd1498Szrj   (((obstack_room (h) < sizeof (char *))				      \
477*38fd1498Szrj     ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0),		      \
478*38fd1498Szrj    obstack_ptr_grow_fast (h, datum))
479*38fd1498Szrj 
480*38fd1498Szrj # define obstack_int_grow(h, datum)					      \
481*38fd1498Szrj   (((obstack_room (h) < sizeof (int))					      \
482*38fd1498Szrj     ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0),			      \
483*38fd1498Szrj    obstack_int_grow_fast (h, datum))
484*38fd1498Szrj 
485*38fd1498Szrj # define obstack_ptr_grow_fast(h, aptr)					      \
486*38fd1498Szrj   (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr),	      \
487*38fd1498Szrj    (void) 0)
488*38fd1498Szrj 
489*38fd1498Szrj # define obstack_int_grow_fast(h, aint)					      \
490*38fd1498Szrj   (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint),		      \
491*38fd1498Szrj    (void) 0)
492*38fd1498Szrj 
493*38fd1498Szrj # define obstack_blank(h, length)					      \
494*38fd1498Szrj   ((h)->temp.i = (length),						      \
495*38fd1498Szrj    ((obstack_room (h) < (h)->temp.i)					      \
496*38fd1498Szrj    ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0),			      \
497*38fd1498Szrj    obstack_blank_fast (h, (h)->temp.i))
498*38fd1498Szrj 
499*38fd1498Szrj # define obstack_alloc(h, length)					      \
500*38fd1498Szrj   (obstack_blank ((h), (length)), obstack_finish ((h)))
501*38fd1498Szrj 
502*38fd1498Szrj # define obstack_copy(h, where, length)					      \
503*38fd1498Szrj   (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
504*38fd1498Szrj 
505*38fd1498Szrj # define obstack_copy0(h, where, length)				      \
506*38fd1498Szrj   (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
507*38fd1498Szrj 
508*38fd1498Szrj # define obstack_finish(h)						      \
509*38fd1498Szrj   (((h)->next_free == (h)->object_base					      \
510*38fd1498Szrj     ? (((h)->maybe_empty_object = 1), 0)				      \
511*38fd1498Szrj     : 0),								      \
512*38fd1498Szrj    (h)->temp.p = (h)->object_base,					      \
513*38fd1498Szrj    (h)->next_free							      \
514*38fd1498Szrj      = __PTR_ALIGN ((h)->object_base, (h)->next_free,			      \
515*38fd1498Szrj                     (h)->alignment_mask),				      \
516*38fd1498Szrj    (((size_t) ((h)->next_free - (char *) (h)->chunk)			      \
517*38fd1498Szrj      > (size_t) ((h)->chunk_limit - (char *) (h)->chunk))		      \
518*38fd1498Szrj    ? ((h)->next_free = (h)->chunk_limit) : 0),				      \
519*38fd1498Szrj    (h)->object_base = (h)->next_free,					      \
520*38fd1498Szrj    (h)->temp.p)
521*38fd1498Szrj 
522*38fd1498Szrj # define obstack_free(h, obj)						      \
523*38fd1498Szrj   ((h)->temp.p = (void *) (obj),					      \
524*38fd1498Szrj    (((h)->temp.p > (void *) (h)->chunk					      \
525*38fd1498Szrj      && (h)->temp.p < (void *) (h)->chunk_limit)			      \
526*38fd1498Szrj     ? (void) ((h)->next_free = (h)->object_base = (char *) (h)->temp.p)       \
527*38fd1498Szrj     : _obstack_free ((h), (h)->temp.p)))
528*38fd1498Szrj 
529*38fd1498Szrj #endif /* not __GNUC__ */
530*38fd1498Szrj 
531*38fd1498Szrj #ifdef __cplusplus
532*38fd1498Szrj }       /* C++ */
533*38fd1498Szrj #endif
534*38fd1498Szrj 
535*38fd1498Szrj #endif /* _OBSTACK_H */
536