obstack.h
001: 
002: 
003: 
004: 
005: 
006: 
007: 
008: 
009: 
010: 
011: 
012: 
013: 
014: 
015: 
016: 
017: 
018: 
019: 
020: 
021: 
022: 
023: 
024: 
025: 
026: 
027: 
028: 
029: 
030: 
031: 
032: 
033: 
034: 
035: 
036: 
037: 
038: 
039: 
040: 
041: 
042: 
043: 
044: 
045: 
046: 
047: 
048: 
049: 
050: 
051: 
052: 
053: 
054: 
055: 
056: 
057: 
058: 
059: 
060: 
061: 
062: 
063: 
064: 
065: 
066: 
067: 
068: 
069: 
070: 
071: 
072: 
073: 
074: 
075: 
076: 
077: 
078: 
079: 
080: 
081: 
082: 
083: 
084: 
085: 
086: 
087: 
088: 
089: 
090: 
091: 
092: 
093: 
094: 
095: 
096: 
097: 
098: 
099: 
100: 
101: 
102: 
103: 
104: 
105: 
106: #ifndef _OBSTACK_H
107: #define _OBSTACK_H 1
108: 
109: #ifdef __cplusplus
110: extern "C" {
111: #endif
112: 
113: 
114: 
115: 
116: 
117: 
118: #ifdef __PTRDIFF_TYPE__
119: # define PTR_INT_TYPE __PTRDIFF_TYPE__
120: #else
121: # include <stddef.h>
122: # define PTR_INT_TYPE ptrdiff_t
123: #endif
124: 
125: 
126: 
127: 
128: 
129: #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
130: 
131: 
132: 
133: 
134: 
135: 
136: 
137: 
138: #define __PTR_ALIGN(B, P, A)                                                \
139:   __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
140:                 P, A)
141: 
142: #include <string.h>
143: 
144: struct _obstack_chunk           
145: {
146:   char  *limit;                 
147:   struct _obstack_chunk *prev;  
148:   char  contents[4];            
149: };
150: 
151: struct obstack          
152: {
153:   long  chunk_size;             
154:   struct _obstack_chunk *chunk; 
155:   char  *object_base;           
156:   char  *next_free;             
157:   char  *chunk_limit;           
158:   union
159:   {
160:     PTR_INT_TYPE tempint;
161:     void *tempptr;
162:   } temp;                       
163:   int   alignment_mask;         
164:   
165: 
166: 
167:   struct _obstack_chunk *(*chunkfun) (void *, long);
168:   void (*freefun) (void *, struct _obstack_chunk *);
169:   void *extra_arg;              
170:   unsigned use_extra_arg:1;     
171:   unsigned maybe_empty_object:1;
172: 
173: 
174: 
175:   unsigned alloc_failed:1;      
176: 
177: 
178: };
179: 
180: 
181: 
182: extern void _obstack_newchunk (struct obstack *, int);
183: extern int _obstack_begin (struct obstack *, int, int,
184:                             void *(*) (long), void (*) (void *));
185: extern int _obstack_begin_1 (struct obstack *, int, int,
186:                              void *(*) (void *, long),
187:                              void (*) (void *, void *), void *);
188: extern int _obstack_memory_used (struct obstack *);
189: 
190: void obstack_free (struct obstack *__obstack, void *__block);
191: 
192: 
193: 
194: 
195: 
196: 
197: extern void (*obstack_alloc_failed_handler) (void);
198: 
199: 
200: extern int obstack_exit_failure;
201: 
202: 
203: 
204: 
205: 
206: #define obstack_base(h) ((void *) (h)->object_base)
207: 
208: 
209: 
210: #define obstack_chunk_size(h) ((h)->chunk_size)
211: 
212: 
213: 
214: #define obstack_next_free(h)    ((h)->next_free)
215: 
216: 
217: 
218: #define obstack_alignment_mask(h) ((h)->alignment_mask)
219: 
220: 
221: #define obstack_init(h)                                         \
222:   _obstack_begin ((h), 0, 0,                                    \
223:                   (void *(*) (long)) obstack_chunk_alloc,       \
224:                   (void (*) (void *)) obstack_chunk_free)
225: 
226: #define obstack_begin(h, size)                                  \
227:   _obstack_begin ((h), (size), 0,                               \
228:                   (void *(*) (long)) obstack_chunk_alloc,       \
229:                   (void (*) (void *)) obstack_chunk_free)
230: 
231: #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun)  \
232:   _obstack_begin ((h), (size), (alignment),                                \
233:                   (void *(*) (long)) (chunkfun),                           \
234:                   (void (*) (void *)) (freefun))
235: 
236: #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
237:   _obstack_begin_1 ((h), (size), (alignment),                           \
238:                     (void *(*) (void *, long)) (chunkfun),              \
239:                     (void (*) (void *, void *)) (freefun), (arg))
240: 
241: #define obstack_chunkfun(h, newchunkfun) \
242:   ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
243: 
244: #define obstack_freefun(h, newfreefun) \
245:   ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
246: 
247: #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
248: 
249: #define obstack_blank_fast(h,n) ((h)->next_free += (n))
250: 
251: #define obstack_memory_used(h) _obstack_memory_used (h)
252: 
253: #if defined __GNUC__ && defined __STDC__ && __STDC__
254: 
255: 
256: 
257: # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
258: #  define __extension__
259: # endif
260: 
261: 
262: 
263: 
264: 
265: 
266: # define obstack_object_size(OBSTACK)                                   \
267:   __extension__                                                         \
268:   ({ struct obstack const *__o = (OBSTACK);                             \
269:      (unsigned) (__o->next_free - __o->object_base); })
270: 
271: # define obstack_room(OBSTACK)                                          \
272:   __extension__                                                         \
273:   ({ struct obstack const *__o = (OBSTACK);                             \
274:      (unsigned) (__o->chunk_limit - __o->next_free); })
275: 
276: # define obstack_make_room(OBSTACK,length)                              \
277: __extension__                                                           \
278: ({ struct obstack *__o = (OBSTACK);                                     \
279:    int __len = (length);                                                \
280:    if (__o->chunk_limit - __o->next_free < __len)                       \
281:      _obstack_newchunk (__o, __len);                                    \
282:    (void) 0; })
283: 
284: # define obstack_empty_p(OBSTACK)                                       \
285:   __extension__                                                         \
286:   ({ struct obstack const *__o = (OBSTACK);                             \
287:      (__o->chunk->prev == 0                                             \
288:       && __o->next_free == __PTR_ALIGN ((char *) __o->chunk,            \
289:                                         __o->chunk->contents,           \
290:                                         __o->alignment_mask)); })
291: 
292: # define obstack_grow(OBSTACK,where,length)                             \
293: __extension__                                                           \
294: ({ struct obstack *__o = (OBSTACK);                                     \
295:    int __len = (length);                                                \
296:    if (__o->next_free + __len > __o->chunk_limit)                       \
297:      _obstack_newchunk (__o, __len);                                    \
298:    memcpy (__o->next_free, where, __len);                               \
299:    __o->next_free += __len;                                             \
300:    (void) 0; })
301: 
302: # define obstack_grow0(OBSTACK,where,length)                            \
303: __extension__                                                           \
304: ({ struct obstack *__o = (OBSTACK);                                     \
305:    int __len = (length);                                                \
306:    if (__o->next_free + __len + 1 > __o->chunk_limit)                   \
307:      _obstack_newchunk (__o, __len + 1);                                \
308:    memcpy (__o->next_free, where, __len);                               \
309:    __o->next_free += __len;                                             \
310:    *(__o->next_free)++ = 0;                                             \
311:    (void) 0; })
312: 
313: # define obstack_1grow(OBSTACK,datum)                                   \
314: __extension__                                                           \
315: ({ struct obstack *__o = (OBSTACK);                                     \
316:    if (__o->next_free + 1 > __o->chunk_limit)                           \
317:      _obstack_newchunk (__o, 1);                                        \
318:    obstack_1grow_fast (__o, datum);                                     \
319:    (void) 0; })
320: 
321: 
322: 
323: 
324: 
325: # define obstack_ptr_grow(OBSTACK,datum)                                \
326: __extension__                                                           \
327: ({ struct obstack *__o = (OBSTACK);                                     \
328:    if (__o->next_free + sizeof (void *) > __o->chunk_limit)             \
329:      _obstack_newchunk (__o, sizeof (void *));                          \
330:    obstack_ptr_grow_fast (__o, datum); })                               \
331: 
332: # define obstack_int_grow(OBSTACK,datum)                                \
333: __extension__                                                           \
334: ({ struct obstack *__o = (OBSTACK);                                     \
335:    if (__o->next_free + sizeof (int) > __o->chunk_limit)                \
336:      _obstack_newchunk (__o, sizeof (int));                             \
337:    obstack_int_grow_fast (__o, datum); })
338: 
339: # define obstack_ptr_grow_fast(OBSTACK,aptr)                            \
340: __extension__                                                           \
341: ({ struct obstack *__o1 = (OBSTACK);                                    \
342:    *(const void **) __o1->next_free = (aptr);                           \
343:    __o1->next_free += sizeof (const void *);                            \
344:    (void) 0; })
345: 
346: # define obstack_int_grow_fast(OBSTACK,aint)                            \
347: __extension__                                                           \
348: ({ struct obstack *__o1 = (OBSTACK);                                    \
349:    *(int *) __o1->next_free = (aint);                                   \
350:    __o1->next_free += sizeof (int);                                     \
351:    (void) 0; })
352: 
353: # define obstack_blank(OBSTACK,length)                                  \
354: __extension__                                                           \
355: ({ struct obstack *__o = (OBSTACK);                                     \
356:    int __len = (length);                                                \
357:    if (__o->chunk_limit - __o->next_free < __len)                       \
358:      _obstack_newchunk (__o, __len);                                    \
359:    obstack_blank_fast (__o, __len);                                     \
360:    (void) 0; })
361: 
362: # define obstack_alloc(OBSTACK,length)                                  \
363: __extension__                                                           \
364: ({ struct obstack *__h = (OBSTACK);                                     \
365:    obstack_blank (__h, (length));                                       \
366:    obstack_finish (__h); })
367: 
368: # define obstack_copy(OBSTACK,where,length)                             \
369: __extension__                                                           \
370: ({ struct obstack *__h = (OBSTACK);                                     \
371:    obstack_grow (__h, (where), (length));                               \
372:    obstack_finish (__h); })
373: 
374: # define obstack_copy0(OBSTACK,where,length)                            \
375: __extension__                                                           \
376: ({ struct obstack *__h = (OBSTACK);                                     \
377:    obstack_grow0 (__h, (where), (length));                              \
378:    obstack_finish (__h); })
379: 
380: 
381: 
382: # define obstack_finish(OBSTACK)                                        \
383: __extension__                                                           \
384: ({ struct obstack *__o1 = (OBSTACK);                                    \
385:    void *__value = (void *) __o1->object_base;                          \
386:    if (__o1->next_free == __value)                                      \
387:      __o1->maybe_empty_object = 1;                                      \
388:    __o1->next_free                                                      \
389:      = __PTR_ALIGN (__o1->object_base, __o1->next_free,                 \
390:                     __o1->alignment_mask);                              \
391:    if (__o1->next_free - (char *)__o1->chunk                            \
392:        > __o1->chunk_limit - (char *)__o1->chunk)                       \
393:      __o1->next_free = __o1->chunk_limit;                               \
394:    __o1->object_base = __o1->next_free;                                 \
395:    __value; })
396: 
397: # define obstack_free(OBSTACK, OBJ)                                     \
398: __extension__                                                           \
399: ({ struct obstack *__o = (OBSTACK);                                     \
400:    void *__obj = (OBJ);                                                 \
401:    if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit)  \
402:      __o->next_free = __o->object_base = (char *)__obj;                 \
403:    else (obstack_free) (__o, __obj); })
404: 
405: #else 
406: 
407: # define obstack_object_size(h) \
408:  (unsigned) ((h)->next_free - (h)->object_base)
409: 
410: # define obstack_room(h)                \
411:  (unsigned) ((h)->chunk_limit - (h)->next_free)
412: 
413: # define obstack_empty_p(h) \
414:  ((h)->chunk->prev == 0                                                 \
415:   && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk,                \
416:                                     (h)->chunk->contents,               \
417:                                     (h)->alignment_mask))
418: 
419: 
420: 
421: 
422: 
423: 
424: 
425: # define obstack_make_room(h,length)                                    \
426: ( (h)->temp.tempint = (length),                                         \
427:   (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)              \
428:    ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
429: 
430: # define obstack_grow(h,where,length)                                   \
431: ( (h)->temp.tempint = (length),                                         \
432:   (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)              \
433:    ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),              \
434:   memcpy ((h)->next_free, where, (h)->temp.tempint),                    \
435:   (h)->next_free += (h)->temp.tempint)
436: 
437: # define obstack_grow0(h,where,length)                                  \
438: ( (h)->temp.tempint = (length),                                         \
439:   (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit)          \
440:    ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0),          \
441:   memcpy ((h)->next_free, where, (h)->temp.tempint),                    \
442:   (h)->next_free += (h)->temp.tempint,                                  \
443:   *((h)->next_free)++ = 0)
444: 
445: # define obstack_1grow(h,datum)                                         \
446: ( (((h)->next_free + 1 > (h)->chunk_limit)                              \
447:    ? (_obstack_newchunk ((h), 1), 0) : 0),                              \
448:   obstack_1grow_fast (h, datum))
449: 
450: # define obstack_ptr_grow(h,datum)                                      \
451: ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit)                \
452:    ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0),                \
453:   obstack_ptr_grow_fast (h, datum))
454: 
455: # define obstack_int_grow(h,datum)                                      \
456: ( (((h)->next_free + sizeof (int) > (h)->chunk_limit)                   \
457:    ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0),                   \
458:   obstack_int_grow_fast (h, datum))
459: 
460: # define obstack_ptr_grow_fast(h,aptr)                                  \
461:   (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
462: 
463: # define obstack_int_grow_fast(h,aint)                                  \
464:   (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
465: 
466: # define obstack_blank(h,length)                                        \
467: ( (h)->temp.tempint = (length),                                         \
468:   (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint)              \
469:    ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),              \
470:   obstack_blank_fast (h, (h)->temp.tempint))
471: 
472: # define obstack_alloc(h,length)                                        \
473:  (obstack_blank ((h), (length)), obstack_finish ((h)))
474: 
475: # define obstack_copy(h,where,length)                                   \
476:  (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
477: 
478: # define obstack_copy0(h,where,length)                                  \
479:  (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
480: 
481: # define obstack_finish(h)                                              \
482: ( ((h)->next_free == (h)->object_base                                   \
483:    ? (((h)->maybe_empty_object = 1), 0)                                 \
484:    : 0),                                                                \
485:   (h)->temp.tempptr = (h)->object_base,                                 \
486:   (h)->next_free                                                        \
487:     = __PTR_ALIGN ((h)->object_base, (h)->next_free,                    \
488:                    (h)->alignment_mask),                                \
489:   (((h)->next_free - (char *) (h)->chunk                                \
490:     > (h)->chunk_limit - (char *) (h)->chunk)                           \
491:    ? ((h)->next_free = (h)->chunk_limit) : 0),                          \
492:   (h)->object_base = (h)->next_free,                                    \
493:   (h)->temp.tempptr)
494: 
495: # define obstack_free(h,obj)                                            \
496: ( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,             \
497:   ((((h)->temp.tempint > 0                                              \
498:     && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))     \
499:    ? (((h)->next_free = (h)->object_base                                \
500:        = (h)->temp.tempint + (char *) (h)->chunk), 0)                   \
501:    : ((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0)))
502: 
503: #endif 
504: 
505: #ifdef __cplusplus
506: }       
507: #endif
508: 
509: #endif 
510: 
      
      
      
      
   
      
      
         
            
            © Andrew Scott 2006 -
            2025, 
            All Rights Reserved