123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- #define __FORCE_GLIBC 1
- #include <locale.h>
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include <obstack.h>
- #define OBSTACK_INTERFACE_VERSION 1
- #include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
- #if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
- # include <gnu-versions.h>
- # if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
- # define ELIDE_CODE
- # endif
- #endif
- #if (defined _LIBC && defined USE_IN_LIBIO) || defined __UCLIBC_HAS_WCHAR__
- # include <wchar.h>
- #endif
- #ifndef ELIDE_CODE
- # if defined __STDC__ && __STDC__
- # define POINTER void *
- # else
- # define POINTER char *
- # endif
- struct fooalign {char x; double d;};
- # define DEFAULT_ALIGNMENT \
- ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
- union fooround {long x; double d;};
- # define DEFAULT_ROUNDING (sizeof (union fooround))
- # ifndef COPYING_UNIT
- # define COPYING_UNIT int
- # endif
- # if defined __STDC__ && __STDC__
- static void print_and_abort (void);
- void (*obstack_alloc_failed_handler) (void) = print_and_abort;
- # else
- static void print_and_abort ();
- void (*obstack_alloc_failed_handler) () = print_and_abort;
- # endif
- # if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
- # include <stdlib.h>
- # endif
- # ifndef EXIT_FAILURE
- # define EXIT_FAILURE 1
- # endif
- libc_hidden_proto(fprintf)
- libc_hidden_proto(abort)
- libc_hidden_proto(exit)
- #ifdef __UCLIBC_HAS_WCHAR__
- libc_hidden_proto(fwprintf)
- #endif
- int obstack_exit_failure = EXIT_FAILURE;
- struct obstack *_obstack;
- # if defined __STDC__ && __STDC__
- # define CALL_CHUNKFUN(h, size) \
- (((h) -> use_extra_arg) \
- ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
- : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
- # define CALL_FREEFUN(h, old_chunk) \
- do { \
- if ((h) -> use_extra_arg) \
- (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
- else \
- (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
- } while (0)
- # else
- # define CALL_CHUNKFUN(h, size) \
- (((h) -> use_extra_arg) \
- ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
- : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size)))
- # define CALL_FREEFUN(h, old_chunk) \
- do { \
- if ((h) -> use_extra_arg) \
- (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
- else \
- (*(void (*) ()) (h)->freefun) ((old_chunk)); \
- } while (0)
- # endif
- int
- _obstack_begin (
- struct obstack *h,
- int size,
- int alignment,
- # if defined __STDC__ && __STDC__
- POINTER (*chunkfun) (long),
- void (*freefun) (void *)
- # else
- POINTER (*chunkfun) (),
- void (*freefun) ()
- # endif
- )
- {
- register struct _obstack_chunk *chunk;
- if (alignment == 0)
- alignment = (int) DEFAULT_ALIGNMENT;
- if (size == 0)
-
- {
-
- int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
- + 4 + DEFAULT_ROUNDING - 1)
- & ~(DEFAULT_ROUNDING - 1));
- size = 4096 - extra;
- }
- # if defined __STDC__ && __STDC__
- h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
- h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
- # else
- h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
- h->freefun = freefun;
- # endif
- h->chunk_size = size;
- h->alignment_mask = alignment - 1;
- h->use_extra_arg = 0;
- chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
- if (!chunk)
- (*obstack_alloc_failed_handler) ();
- h->next_free = h->object_base = chunk->contents;
- h->chunk_limit = chunk->limit
- = (char *) chunk + h->chunk_size;
- chunk->prev = 0;
-
- h->maybe_empty_object = 0;
- h->alloc_failed = 0;
- return 1;
- }
- int
- _obstack_begin_1 (
- struct obstack *h,
- int size,
- int alignment,
- # if defined __STDC__ && __STDC__
- POINTER (*chunkfun) (POINTER, long),
- void (*freefun) (POINTER, POINTER),
- # else
- POINTER (*chunkfun) (),
- void (*freefun) (),
- # endif
- POINTER arg)
- {
- register struct _obstack_chunk *chunk;
- if (alignment == 0)
- alignment = (int) DEFAULT_ALIGNMENT;
- if (size == 0)
-
- {
-
- int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
- + 4 + DEFAULT_ROUNDING - 1)
- & ~(DEFAULT_ROUNDING - 1));
- size = 4096 - extra;
- }
- # if defined __STDC__ && __STDC__
- h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
- h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
- # else
- h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
- h->freefun = freefun;
- # endif
- h->chunk_size = size;
- h->alignment_mask = alignment - 1;
- h->extra_arg = arg;
- h->use_extra_arg = 1;
- chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
- if (!chunk)
- (*obstack_alloc_failed_handler) ();
- h->next_free = h->object_base = chunk->contents;
- h->chunk_limit = chunk->limit
- = (char *) chunk + h->chunk_size;
- chunk->prev = 0;
-
- h->maybe_empty_object = 0;
- h->alloc_failed = 0;
- return 1;
- }
- void
- _obstack_newchunk (
- struct obstack *h,
- int length)
- {
- register struct _obstack_chunk *old_chunk = h->chunk;
- register struct _obstack_chunk *new_chunk;
- register long new_size;
- register long obj_size = h->next_free - h->object_base;
- register long i;
- long already;
- char *object_base;
-
- new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
- if (new_size < h->chunk_size)
- new_size = h->chunk_size;
-
- new_chunk = CALL_CHUNKFUN (h, new_size);
- if (!new_chunk)
- (*obstack_alloc_failed_handler) ();
- h->chunk = new_chunk;
- new_chunk->prev = old_chunk;
- new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
-
- object_base =
- __INT_TO_PTR ((__PTR_TO_INT (new_chunk->contents) + h->alignment_mask)
- & ~ (h->alignment_mask));
-
- if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
- {
- for (i = obj_size / sizeof (COPYING_UNIT) - 1;
- i >= 0; i--)
- ((COPYING_UNIT *)object_base)[i]
- = ((COPYING_UNIT *)h->object_base)[i];
-
- already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
- }
- else
- already = 0;
-
- for (i = already; i < obj_size; i++)
- object_base[i] = h->object_base[i];
-
- if (h->object_base == old_chunk->contents && ! h->maybe_empty_object)
- {
- new_chunk->prev = old_chunk->prev;
- CALL_FREEFUN (h, old_chunk);
- }
- h->object_base = object_base;
- h->next_free = h->object_base + obj_size;
-
- h->maybe_empty_object = 0;
- }
- # if defined __STDC__ && __STDC__
- int _obstack_allocated_p (struct obstack *h, POINTER obj);
- # endif
- int
- _obstack_allocated_p (
- struct obstack *h,
- POINTER obj)
- {
- register struct _obstack_chunk *lp;
- register struct _obstack_chunk *plp;
- lp = (h)->chunk;
-
- while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
- {
- plp = lp->prev;
- lp = plp;
- }
- return lp != 0;
- }
- # undef obstack_free
- void
- _obstack_free (
- struct obstack *h,
- POINTER obj)
- {
- register struct _obstack_chunk *lp;
- register struct _obstack_chunk *plp;
- lp = h->chunk;
-
- while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
- {
- plp = lp->prev;
- CALL_FREEFUN (h, lp);
- lp = plp;
-
- h->maybe_empty_object = 1;
- }
- if (lp)
- {
- h->object_base = h->next_free = (char *) (obj);
- h->chunk_limit = lp->limit;
- h->chunk = lp;
- }
- else if (obj != 0)
-
- abort ();
- }
- void
- obstack_free (
- struct obstack *h,
- POINTER obj)
- {
- register struct _obstack_chunk *lp;
- register struct _obstack_chunk *plp;
- lp = h->chunk;
-
- while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
- {
- plp = lp->prev;
- CALL_FREEFUN (h, lp);
- lp = plp;
-
- h->maybe_empty_object = 1;
- }
- if (lp)
- {
- h->object_base = h->next_free = (char *) (obj);
- h->chunk_limit = lp->limit;
- h->chunk = lp;
- }
- else if (obj != 0)
-
- abort ();
- }
- int
- _obstack_memory_used (
- struct obstack *h)
- {
- register struct _obstack_chunk* lp;
- register int nbytes = 0;
- for (lp = h->chunk; lp != 0; lp = lp->prev)
- {
- nbytes += lp->limit - (char *) lp;
- }
- return nbytes;
- }
- # ifndef _
- # ifdef __UCLIBC_HAS_GETTEXT_AWARENESS__
- # include <libintl.h>
- # ifndef _
- # define _(Str) __dcgettext (NULL, Str, LC_MESSAGES)
- # endif
- # else
- # define _(Str) (Str)
- # endif
- # endif
- # if defined _LIBC && defined USE_IN_LIBIO
- # include <libio/iolibio.h>
- # define fputs(s, f) _IO_fputs (s, f)
- # endif
- static void
- attribute_noreturn
- print_and_abort (void)
- {
-
- # if defined _LIBC && defined USE_IN_LIBIO
- if (_IO_fwide (stderr, 0) > 0)
- fwprintf (stderr, L"%s\n", _("memory exhausted"));
- else
- # endif
- fprintf (stderr, "%s\n", _("memory exhausted"));
- exit (obstack_exit_failure);
- }
- # if 0
- # if defined __STDC__ && __STDC__
- POINTER (obstack_base) (obstack)
- struct obstack *obstack;
- {
- return obstack_base (obstack);
- }
- POINTER (obstack_next_free) (obstack)
- struct obstack *obstack;
- {
- return obstack_next_free (obstack);
- }
- int (obstack_object_size) (obstack)
- struct obstack *obstack;
- {
- return obstack_object_size (obstack);
- }
- int (obstack_room) (obstack)
- struct obstack *obstack;
- {
- return obstack_room (obstack);
- }
- int (obstack_make_room) (obstack, length)
- struct obstack *obstack;
- int length;
- {
- return obstack_make_room (obstack, length);
- }
- void (obstack_grow) (obstack, data, length)
- struct obstack *obstack;
- const POINTER data;
- int length;
- {
- obstack_grow (obstack, data, length);
- }
- void (obstack_grow0) (obstack, data, length)
- struct obstack *obstack;
- const POINTER data;
- int length;
- {
- obstack_grow0 (obstack, data, length);
- }
- void (obstack_1grow) (obstack, character)
- struct obstack *obstack;
- int character;
- {
- obstack_1grow (obstack, character);
- }
- void (obstack_blank) (obstack, length)
- struct obstack *obstack;
- int length;
- {
- obstack_blank (obstack, length);
- }
- void (obstack_1grow_fast) (obstack, character)
- struct obstack *obstack;
- int character;
- {
- obstack_1grow_fast (obstack, character);
- }
- void (obstack_blank_fast) (obstack, length)
- struct obstack *obstack;
- int length;
- {
- obstack_blank_fast (obstack, length);
- }
- POINTER (obstack_finish) (obstack)
- struct obstack *obstack;
- {
- return obstack_finish (obstack);
- }
- POINTER (obstack_alloc) (obstack, length)
- struct obstack *obstack;
- int length;
- {
- return obstack_alloc (obstack, length);
- }
- POINTER (obstack_copy) (obstack, address, length)
- struct obstack *obstack;
- const POINTER address;
- int length;
- {
- return obstack_copy (obstack, address, length);
- }
- POINTER (obstack_copy0) (obstack, address, length)
- struct obstack *obstack;
- const POINTER address;
- int length;
- {
- return obstack_copy0 (obstack, address, length);
- }
- # endif
- # endif
- #endif
|