obstack.h 22 KB

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