From 19e15828f69a5f47061de5e631fbe3fdbc666849 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 22 Oct 2003 05:10:04 +0000 Subject: [PATCH] Merge changes from glibc obstack; minor cleanups to make it easier to merge back in the future. --- lib/ChangeLog | 13 +++++++++++++ lib/obstack.c | 51 ++++++++++++++------------------------------------- lib/obstack.h | 22 +++++++++++----------- 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 22c4703a7..ecc0c9693 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,18 @@ 2003-10-21 Paul Eggert + * obstack.c: Merge from glibc. + [defined _LIBC]: Include , not "obstack.h". + Add libc_hidden_def (_obstack_newchunk). + (_obstack_free) [! defined _LIBC]: Remove. + [defined _LIBC]: Make a strong alias from obstack_free, rather than + a clone of the function body. + (fputs) [defined _LIBC && defined USE_IN_LIBIO]: Remove. + [defined _LIBC && !defined USE_IN_LIBIO]: Include . + + * obstack.h: Indenting cleanup, to make it easier to merge with glibc. + (obstack_grow, obstack_grow0): Remove unnecessary parentheses around + arg to memcpy. + * obstack.h (obstack_1grow_fast): Properly parenthesize arg. (obstack_ptr_grow_fast, obstack_int_grow_fast): Don't use lvalue casts, as GCC plans to remove support for them diff --git a/lib/obstack.c b/lib/obstack.c index bf6bba86c..d8bea0acd 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -21,7 +21,11 @@ # include #endif +#ifdef _LIBC +#include +#else #include "obstack.h" +#endif /* NOTE BEFORE MODIFYING THIS FILE: This version number must be incremented whenever callers compiled using an old obstack.h can no @@ -282,6 +286,9 @@ _obstack_newchunk (struct obstack *h, int length) /* The new chunk certainly contains no empty object yet. */ h->maybe_empty_object = 0; } +#ifdef _LIBC +libc_hidden_def (_obstack_newchunk) +#endif /* Return nonzero if object OBJ has been allocated from obstack H. This is here for debugging. @@ -314,41 +321,6 @@ _obstack_allocated_p (struct obstack *h, void *obj) # undef obstack_free -/* This function has two names with identical definitions. - This is the first one, called from non-ANSI code. */ - -void -_obstack_free (struct obstack *h, void *obj) -{ - register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk *plp; /* point to previous chunk if any */ - - lp = h->chunk; - /* We use >= because there cannot be an object at the beginning of a chunk. - But there can be an empty object at that address - at the end of another chunk. */ - while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj)) - { - plp = lp->prev; - CALL_FREEFUN (h, lp); - lp = plp; - /* If we switch chunks, we can't tell whether the new current - chunk contains an empty object, so assume that it may. */ - 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) - /* obj is not in any of the chunks! */ - abort (); -} - -/* This function is used from ANSI code. */ - void obstack_free (struct obstack *h, void *obj) { @@ -378,6 +350,12 @@ obstack_free (struct obstack *h, void *obj) /* obj is not in any of the chunks! */ abort (); } + +#ifdef _LIBC +/* Older versions of libc used a function _obstack_free intended to be + called by non-GCC compilers. */ +strong_alias (obstack_free, _obstack_free) +#endif int _obstack_memory_used (struct obstack *h) @@ -400,9 +378,8 @@ _obstack_memory_used (struct obstack *h) # endif # define _(msgid) gettext (msgid) -# if defined _LIBC && defined USE_IN_LIBIO +# ifdef _LIBC # include -# define fputs(s, f) _IO_fputs (s, f) # endif # ifndef __attribute__ diff --git a/lib/obstack.h b/lib/obstack.h index 2ce1f6416..1460f5d8d 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -248,30 +248,30 @@ extern int obstack_exit_failure; #define obstack_alignment_mask(h) ((h)->alignment_mask) /* To prevent prototype warnings provide complete argument list. */ -# define obstack_init(h) \ +#define obstack_init(h) \ _obstack_begin ((h), 0, 0, \ (void *(*) (long)) obstack_chunk_alloc, \ (void (*) (void *)) obstack_chunk_free) -# define obstack_begin(h, size) \ +#define obstack_begin(h, size) \ _obstack_begin ((h), (size), 0, \ (void *(*) (long)) obstack_chunk_alloc, \ (void (*) (void *)) obstack_chunk_free) -# define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ +#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ _obstack_begin ((h), (size), (alignment), \ (void *(*) (long)) (chunkfun), \ (void (*) (void *)) (freefun)) -# define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ +#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ _obstack_begin_1 ((h), (size), (alignment), \ (void *(*) (void *, long)) (chunkfun), \ (void (*) (void *, void *)) (freefun), (arg)) -# define obstack_chunkfun(h, newchunkfun) \ +#define obstack_chunkfun(h, newchunkfun) \ ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun)) -# define obstack_freefun(h, newfreefun) \ +#define obstack_freefun(h, newfreefun) \ ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun)) #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar)) @@ -322,7 +322,7 @@ __extension__ \ int __len = (length); \ if (__o->next_free + __len > __o->chunk_limit) \ _obstack_newchunk (__o, __len); \ - memcpy (__o->next_free, (where), __len); \ + memcpy (__o->next_free, where, __len); \ __o->next_free += __len; \ (void) 0; }) @@ -332,7 +332,7 @@ __extension__ \ int __len = (length); \ if (__o->next_free + __len + 1 > __o->chunk_limit) \ _obstack_newchunk (__o, __len + 1); \ - memcpy (__o->next_free, (where), __len); \ + memcpy (__o->next_free, where, __len); \ __o->next_free += __len; \ *(__o->next_free)++ = 0; \ (void) 0; }) @@ -456,14 +456,14 @@ __extension__ \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ - memcpy ((h)->next_free, (where), (h)->temp), \ + memcpy ((h)->next_free, where, (h)->temp), \ (h)->next_free += (h)->temp) # define obstack_grow0(h,where,length) \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ - memcpy ((h)->next_free, (where), (h)->temp), \ + memcpy ((h)->next_free, where, (h)->temp), \ (h)->next_free += (h)->temp, \ *((h)->next_free)++ = 0) @@ -517,7 +517,7 @@ __extension__ \ (h)->object_base = (h)->next_free, \ (void *) __INT_TO_PTR ((h)->temp)) -# define obstack_free(h,obj) \ +# 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 \ -- 2.11.0