127 |
|
|
128 |
/* We need the type of the resulting object. If __PTRDIFF_TYPE__ is |
/* We need the type of the resulting object. If __PTRDIFF_TYPE__ is |
129 |
defined, as with GNU C, use that; that way we don't pollute the |
defined, as with GNU C, use that; that way we don't pollute the |
130 |
namespace with <stddef.h>'s symbols. Otherwise, if <stddef.h> is |
namespace with <stddef.h>'s symbols. Otherwise, include <stddef.h> |
131 |
available, include it and use ptrdiff_t. In traditional C, long is |
and use ptrdiff_t. */ |
|
the best that we can do. */ |
|
132 |
|
|
133 |
#ifdef __PTRDIFF_TYPE__ |
#ifdef __PTRDIFF_TYPE__ |
134 |
# define PTR_INT_TYPE __PTRDIFF_TYPE__ |
# define PTR_INT_TYPE __PTRDIFF_TYPE__ |
135 |
#else |
#else |
136 |
# ifdef HAVE_STDDEF_H |
# include <stddef.h> |
137 |
# include <stddef.h> |
# define PTR_INT_TYPE ptrdiff_t |
|
# define PTR_INT_TYPE ptrdiff_t |
|
|
# else |
|
|
# define PTR_INT_TYPE long |
|
|
# endif |
|
138 |
#endif |
#endif |
139 |
|
|
140 |
#if defined _LIBC || defined HAVE_STRING_H |
#include <string.h> |
|
# include <string.h> |
|
|
# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) |
|
|
#else |
|
|
# ifdef memcpy |
|
|
# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) |
|
|
# else |
|
|
# define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N)) |
|
|
# endif |
|
|
#endif |
|
141 |
|
|
142 |
struct _obstack_chunk /* Lives at front of each chunk. */ |
struct _obstack_chunk /* Lives at front of each chunk. */ |
143 |
{ |
{ |
155 |
char *chunk_limit; /* address of char after current chunk */ |
char *chunk_limit; /* address of char after current chunk */ |
156 |
PTR_INT_TYPE temp; /* Temporary for some macros. */ |
PTR_INT_TYPE temp; /* Temporary for some macros. */ |
157 |
int alignment_mask; /* Mask of alignment for each object. */ |
int alignment_mask; /* Mask of alignment for each object. */ |
|
#if defined __STDC__ && __STDC__ |
|
158 |
/* These prototypes vary based on `use_extra_arg', and we use |
/* These prototypes vary based on `use_extra_arg', and we use |
159 |
casts to the prototypeless function type in all assignments, |
casts to the prototypeless function type in all assignments, |
160 |
but having prototypes here quiets -Wstrict-prototypes. */ |
but having prototypes here quiets -Wstrict-prototypes. */ |
161 |
struct _obstack_chunk *(*chunkfun) (void *, long); |
struct _obstack_chunk *(*chunkfun) (void *, long); |
162 |
void (*freefun) (void *, struct _obstack_chunk *); |
void (*freefun) (void *, struct _obstack_chunk *); |
163 |
void *extra_arg; /* first arg for chunk alloc/dealloc funcs */ |
void *extra_arg; /* first arg for chunk alloc/dealloc funcs */ |
|
#else |
|
|
struct _obstack_chunk *(*chunkfun) (); /* User's fcn to allocate a chunk. */ |
|
|
void (*freefun) (); /* User's function to free a chunk. */ |
|
|
char *extra_arg; /* first arg for chunk alloc/dealloc funcs */ |
|
|
#endif |
|
164 |
unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */ |
unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */ |
165 |
unsigned maybe_empty_object:1;/* There is a possibility that the current |
unsigned maybe_empty_object:1;/* There is a possibility that the current |
166 |
chunk contains a zero-length object. This |
chunk contains a zero-length object. This |
173 |
|
|
174 |
/* Declare the external functions we use; they are in obstack.c. */ |
/* Declare the external functions we use; they are in obstack.c. */ |
175 |
|
|
|
#if defined __STDC__ && __STDC__ |
|
176 |
extern void _obstack_newchunk (struct obstack *, int); |
extern void _obstack_newchunk (struct obstack *, int); |
177 |
extern void _obstack_free (struct obstack *, void *); |
extern void _obstack_free (struct obstack *, void *); |
178 |
extern int _obstack_begin (struct obstack *, int, int, |
extern int _obstack_begin (struct obstack *, int, int, |
181 |
void *(*) (void *, long), |
void *(*) (void *, long), |
182 |
void (*) (void *, void *), void *); |
void (*) (void *, void *), void *); |
183 |
extern int _obstack_memory_used (struct obstack *); |
extern int _obstack_memory_used (struct obstack *); |
|
#else |
|
|
extern void _obstack_newchunk (); |
|
|
extern void _obstack_free (); |
|
|
extern int _obstack_begin (); |
|
|
extern int _obstack_begin_1 (); |
|
|
extern int _obstack_memory_used (); |
|
|
#endif |
|
184 |
|
|
|
#if defined __STDC__ && __STDC__ |
|
|
|
|
185 |
/* Do the function-declarations after the structs |
/* Do the function-declarations after the structs |
186 |
but before defining the macros. */ |
but before defining the macros. */ |
187 |
|
|
220 |
int obstack_chunk_size (struct obstack *obstack); |
int obstack_chunk_size (struct obstack *obstack); |
221 |
int obstack_memory_used (struct obstack *obstack); |
int obstack_memory_used (struct obstack *obstack); |
222 |
|
|
|
#endif /* __STDC__ */ |
|
|
|
|
|
/* Non-ANSI C cannot really support alternative functions for these macros, |
|
|
so we do not declare them. */ |
|
|
|
|
223 |
/* Error handler called when `obstack_chunk_alloc' failed to allocate |
/* Error handler called when `obstack_chunk_alloc' failed to allocate |
224 |
more memory. This can be set to a user defined function which |
more memory. This can be set to a user defined function which |
225 |
should either abort gracefully or use longjump - but shouldn't |
should either abort gracefully or use longjump - but shouldn't |
226 |
return. The default action is to print a message and abort. */ |
return. The default action is to print a message and abort. */ |
|
#if defined __STDC__ && __STDC__ |
|
227 |
extern void (*obstack_alloc_failed_handler) (void); |
extern void (*obstack_alloc_failed_handler) (void); |
|
#else |
|
|
extern void (*obstack_alloc_failed_handler) (); |
|
|
#endif |
|
228 |
|
|
229 |
/* Exit value used when `print_and_abort' is used. */ |
/* Exit value used when `print_and_abort' is used. */ |
230 |
extern int obstack_exit_failure; |
extern int obstack_exit_failure; |
247 |
|
|
248 |
#define obstack_alignment_mask(h) ((h)->alignment_mask) |
#define obstack_alignment_mask(h) ((h)->alignment_mask) |
249 |
|
|
250 |
/* To prevent prototype warnings provide complete argument list in |
/* To prevent prototype warnings provide complete argument list. */ |
|
standard C version. */ |
|
|
#if defined __STDC__ && __STDC__ |
|
|
|
|
251 |
# define obstack_init(h) \ |
# define obstack_init(h) \ |
252 |
_obstack_begin ((h), 0, 0, \ |
_obstack_begin ((h), 0, 0, \ |
253 |
(void *(*) (long)) obstack_chunk_alloc, \ |
(void *(*) (long)) obstack_chunk_alloc, \ |
274 |
# define obstack_freefun(h, newfreefun) \ |
# define obstack_freefun(h, newfreefun) \ |
275 |
((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun)) |
((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun)) |
276 |
|
|
|
#else |
|
|
|
|
|
# define obstack_init(h) \ |
|
|
_obstack_begin ((h), 0, 0, \ |
|
|
(void *(*) ()) obstack_chunk_alloc, \ |
|
|
(void (*) ()) obstack_chunk_free) |
|
|
|
|
|
# define obstack_begin(h, size) \ |
|
|
_obstack_begin ((h), (size), 0, \ |
|
|
(void *(*) ()) obstack_chunk_alloc, \ |
|
|
(void (*) ()) obstack_chunk_free) |
|
|
|
|
|
# define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ |
|
|
_obstack_begin ((h), (size), (alignment), \ |
|
|
(void *(*) ()) (chunkfun), \ |
|
|
(void (*) ()) (freefun)) |
|
|
|
|
|
# define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ |
|
|
_obstack_begin_1 ((h), (size), (alignment), \ |
|
|
(void *(*) ()) (chunkfun), \ |
|
|
(void (*) ()) (freefun), (arg)) |
|
|
|
|
|
# define obstack_chunkfun(h, newchunkfun) \ |
|
|
((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun)) |
|
|
|
|
|
# define obstack_freefun(h, newfreefun) \ |
|
|
((h) -> freefun = (void (*)()) (newfreefun)) |
|
|
|
|
|
#endif |
|
|
|
|
277 |
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar) |
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar) |
278 |
|
|
279 |
#define obstack_blank_fast(h,n) ((h)->next_free += (n)) |
#define obstack_blank_fast(h,n) ((h)->next_free += (n)) |
322 |
int __len = (length); \ |
int __len = (length); \ |
323 |
if (__o->next_free + __len > __o->chunk_limit) \ |
if (__o->next_free + __len > __o->chunk_limit) \ |
324 |
_obstack_newchunk (__o, __len); \ |
_obstack_newchunk (__o, __len); \ |
325 |
_obstack_memcpy (__o->next_free, (where), __len); \ |
memcpy (__o->next_free, (where), __len); \ |
326 |
__o->next_free += __len; \ |
__o->next_free += __len; \ |
327 |
(void) 0; }) |
(void) 0; }) |
328 |
|
|
332 |
int __len = (length); \ |
int __len = (length); \ |
333 |
if (__o->next_free + __len + 1 > __o->chunk_limit) \ |
if (__o->next_free + __len + 1 > __o->chunk_limit) \ |
334 |
_obstack_newchunk (__o, __len + 1); \ |
_obstack_newchunk (__o, __len + 1); \ |
335 |
_obstack_memcpy (__o->next_free, (where), __len); \ |
memcpy (__o->next_free, (where), __len); \ |
336 |
__o->next_free += __len; \ |
__o->next_free += __len; \ |
337 |
*(__o->next_free)++ = 0; \ |
*(__o->next_free)++ = 0; \ |
338 |
(void) 0; }) |
(void) 0; }) |
450 |
( (h)->temp = (length), \ |
( (h)->temp = (length), \ |
451 |
(((h)->next_free + (h)->temp > (h)->chunk_limit) \ |
(((h)->next_free + (h)->temp > (h)->chunk_limit) \ |
452 |
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ |
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ |
453 |
_obstack_memcpy ((h)->next_free, (where), (h)->temp), \ |
memcpy ((h)->next_free, (where), (h)->temp), \ |
454 |
(h)->next_free += (h)->temp) |
(h)->next_free += (h)->temp) |
455 |
|
|
456 |
# define obstack_grow0(h,where,length) \ |
# define obstack_grow0(h,where,length) \ |
457 |
( (h)->temp = (length), \ |
( (h)->temp = (length), \ |
458 |
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ |
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ |
459 |
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ |
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ |
460 |
_obstack_memcpy ((h)->next_free, (where), (h)->temp), \ |
memcpy ((h)->next_free, (where), (h)->temp), \ |
461 |
(h)->next_free += (h)->temp, \ |
(h)->next_free += (h)->temp, \ |
462 |
*((h)->next_free)++ = 0) |
*((h)->next_free)++ = 0) |
463 |
|
|
511 |
(h)->object_base = (h)->next_free, \ |
(h)->object_base = (h)->next_free, \ |
512 |
(void *) __INT_TO_PTR ((h)->temp)) |
(void *) __INT_TO_PTR ((h)->temp)) |
513 |
|
|
|
# if defined __STDC__ && __STDC__ |
|
514 |
# define obstack_free(h,obj) \ |
# define obstack_free(h,obj) \ |
515 |
( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ |
( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ |
516 |
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ |
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ |
517 |
? (int) ((h)->next_free = (h)->object_base \ |
? (int) ((h)->next_free = (h)->object_base \ |
518 |
= (h)->temp + (char *) (h)->chunk) \ |
= (h)->temp + (char *) (h)->chunk) \ |
519 |
: (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0))) |
: (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0))) |
|
# else |
|
|
# define obstack_free(h,obj) \ |
|
|
( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ |
|
|
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ |
|
|
? (int) ((h)->next_free = (h)->object_base \ |
|
|
= (h)->temp + (char *) (h)->chunk) \ |
|
|
: (_obstack_free ((h), (h)->temp + (char *) (h)->chunk), 0))) |
|
|
# endif |
|
520 |
|
|
521 |
#endif /* not __GNUC__ or not __STDC__ */ |
#endif /* not __GNUC__ or not __STDC__ */ |
522 |
|
|