diff options
author | Wojciech Polak <polak@gnu.org> | 2004-12-17 22:46:57 +0000 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2004-12-17 22:46:57 +0000 |
commit | e9f48dc1f8fd7ab78f5b25ef0513e2635d37b707 (patch) | |
tree | ca46f7d1cd7be8f094759aaa88a99320db7e7a84 /lib | |
parent | c88a01ddf42f53f7a12c2e3baebad5a52d65212a (diff) | |
download | anubis-e9f48dc1f8fd7ab78f5b25ef0513e2635d37b707.tar.gz anubis-e9f48dc1f8fd7ab78f5b25ef0513e2635d37b707.tar.bz2 |
Provide newer version.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/obstack.c | 84 | ||||
-rw-r--r-- | lib/obstack.h | 151 |
2 files changed, 122 insertions, 113 deletions
diff --git a/lib/obstack.c b/lib/obstack.c index d8bea0a..25cb9ab 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -3,3 +3,4 @@ Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, - 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, + Inc. @@ -24,5 +25,6 @@ #ifdef _LIBC -#include <obstack.h> +# include <obstack.h> +# include <shlib-compat.h> #else -#include "obstack.h" +# include "obstack.h" #endif @@ -55,2 +57,4 @@ +#include <stddef.h> + #ifndef ELIDE_CODE @@ -58,6 +62,16 @@ +# if HAVE_INTTYPES_H +# include <inttypes.h> +# endif +# if HAVE_STDINT_H || defined _LIBC +# include <stdint.h> +# endif + /* Determine default alignment. */ -struct fooalign {char x; double d;}; -# define DEFAULT_ALIGNMENT \ - ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0)) +union fooround +{ + uintmax_t i; + long double d; + void *p; +}; /* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT. @@ -65,4 +79,7 @@ struct fooalign {char x; double d;}; DEFAULT_ROUNDING. So we prepare for it to do that. */ -union fooround {long x; double d;}; -# define DEFAULT_ROUNDING (sizeof (union fooround)) +enum + { + DEFAULT_ALIGNMENT = offsetof (struct { char c; union fooround u; }, u), + DEFAULT_ROUNDING = sizeof (union fooround) + }; @@ -88,11 +105,18 @@ void (*obstack_alloc_failed_handler) (void) = print_and_abort; # include <stdlib.h> -# ifndef _LIBC -# include "exit.h" -# endif +# ifdef _LIBC int obstack_exit_failure = EXIT_FAILURE; +# else +# include "exitfail.h" +# define obstack_exit_failure exit_failure +# endif -/* The non-GNU-C macros copy the obstack into this global variable - to avoid multiple evaluation. */ - -struct obstack *_obstack; +# ifdef _LIBC +# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4) +/* A looong time ago (before 1994, anyway; we're not sure) this global variable + was used by non-GNU-C macros to avoid multiple evaluation. The GNU C + library still exports it because somebody might use it. */ +struct obstack *_obstack_compat; +compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0); +# endif +# endif @@ -135,3 +159,3 @@ _obstack_begin (struct obstack *h, if (alignment == 0) - alignment = (int) DEFAULT_ALIGNMENT; + alignment = DEFAULT_ALIGNMENT; if (size == 0) @@ -162,3 +186,4 @@ _obstack_begin (struct obstack *h, (*obstack_alloc_failed_handler) (); - h->next_free = h->object_base = chunk->contents; + h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, + alignment - 1); h->chunk_limit = chunk->limit @@ -181,3 +206,3 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment, if (alignment == 0) - alignment = (int) DEFAULT_ALIGNMENT; + alignment = DEFAULT_ALIGNMENT; if (size == 0) @@ -209,3 +234,4 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment, (*obstack_alloc_failed_handler) (); - h->next_free = h->object_base = chunk->contents; + h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, + alignment - 1); h->chunk_limit = chunk->limit @@ -251,4 +277,3 @@ _obstack_newchunk (struct obstack *h, int length) object_base = - __INT_TO_PTR ((__PTR_TO_INT (new_chunk->contents) + h->alignment_mask) - & ~ (h->alignment_mask)); + __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask); @@ -277,3 +302,6 @@ _obstack_newchunk (struct obstack *h, int length) But not if that chunk might contain an empty object. */ - if (h->object_base == old_chunk->contents && ! h->maybe_empty_object) + if (! h->maybe_empty_object + && (h->object_base + == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents, + h->alignment_mask))) { @@ -288,5 +316,5 @@ _obstack_newchunk (struct obstack *h, int length) } -#ifdef _LIBC +# ifdef _LIBC libc_hidden_def (_obstack_newchunk) -#endif +# endif @@ -353,3 +381,3 @@ obstack_free (struct obstack *h, void *obj) -#ifdef _LIBC +# ifdef _LIBC /* Older versions of libc used a function _obstack_free intended to be @@ -357,3 +385,3 @@ obstack_free (struct obstack *h, void *obj) strong_alias (obstack_free, _obstack_free) -#endif +# endif @@ -378,3 +406,5 @@ _obstack_memory_used (struct obstack *h) # endif -# define _(msgid) gettext (msgid) +# ifndef _ +# define _(msgid) gettext (msgid) +# endif diff --git a/lib/obstack.h b/lib/obstack.h index 1460f5d..46a1cb7 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -1,3 +1,3 @@ /* obstack.h - object stack macros - Copyright (C) 1988,89,90,91,92,93,94,96,97,98,99,2003 Free Software Foundation, Inc. + Copyright (C) 1988-1994,1996-1999,2003,2004 Free Software Foundation, Inc. @@ -115,15 +115,3 @@ extern "C" { -/* We use subtraction of (char *) 0 instead of casting to int - because on word-addressable machines a simple cast to int - may ignore the byte-within-word field of the pointer. */ - -#ifndef __PTR_TO_INT -# define __PTR_TO_INT(P) ((P) - (char *) 0) -#endif - -#ifndef __INT_TO_PTR -# define __INT_TO_PTR(P) ((P) + (char *) 0) -#endif - -/* We need the type of the resulting object. If __PTRDIFF_TYPE__ is +/* We need the type of a pointer subtraction. If __PTRDIFF_TYPE__ is defined, as with GNU C, use that; that way we don't pollute the @@ -139,2 +127,19 @@ extern "C" { +/* If B is the base of an object addressed by P, return the result of + aligning P to the next multiple of A + 1. B and P must be of type + char *. A + 1 must be a power of 2. */ + +#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A))) + +/* Similiar to _BPTR_ALIGN (B, P, A), except optimize the common case + where pointers can be converted to integers, aligned as integers, + and converted back again. If PTR_INT_TYPE is narrower than a + pointer (e.g., the AS/400), play it safe and compute the alignment + relative to B. Otherwise, use the faster strategy of computing the + alignment relative to 0. */ + +#define __PTR_ALIGN(B, P, A) \ + __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \ + P, A) + #include <string.h> @@ -155,3 +160,7 @@ struct obstack /* control current object in current chunk */ char *chunk_limit; /* address of char after current chunk */ - PTR_INT_TYPE temp; /* Temporary for some macros. */ + union + { + PTR_INT_TYPE tempint; + void *tempptr; + } temp; /* Temporary for some macros. */ int alignment_mask; /* Mask of alignment for each object. */ @@ -176,3 +185,2 @@ struct obstack /* control current object in current chunk */ extern void _obstack_newchunk (struct obstack *, int); -extern void _obstack_free (struct obstack *, void *); extern int _obstack_begin (struct obstack *, int, int, @@ -183,12 +191,2 @@ extern int _obstack_begin_1 (struct obstack *, int, int, extern int _obstack_memory_used (struct obstack *); - -/* Do the function-declarations after the structs - but before defining the macros. */ - -void obstack_init (struct obstack *obstack); - -void * obstack_alloc (struct obstack *obstack, int size); - -void * obstack_copy (struct obstack *obstack, const void *address, int size); -void * obstack_copy0 (struct obstack *obstack, const void *address, int size); @@ -196,28 +194,3 @@ void obstack_free (struct obstack *obstack, void *block); -void obstack_blank (struct obstack *obstack, int size); - -void obstack_grow (struct obstack *obstack, const void *data, int size); -void obstack_grow0 (struct obstack *obstack, const void *data, int size); - -void obstack_1grow (struct obstack *obstack, int data_char); -void obstack_ptr_grow (struct obstack *obstack, const void *data); -void obstack_int_grow (struct obstack *obstack, int data); - -void * obstack_finish (struct obstack *obstack); - -int obstack_object_size (struct obstack *obstack); - -int obstack_room (struct obstack *obstack); -void obstack_make_room (struct obstack *obstack, int size); -void obstack_1grow_fast (struct obstack *obstack, int data_char); -void obstack_ptr_grow_fast (struct obstack *obstack, const void *data); -void obstack_int_grow_fast (struct obstack *obstack, int data); -void obstack_blank_fast (struct obstack *obstack, int size); - -void * obstack_base (struct obstack *obstack); -void * obstack_next_free (struct obstack *obstack); -int obstack_alignment_mask (struct obstack *obstack); -int obstack_chunk_size (struct obstack *obstack); -int obstack_memory_used (struct obstack *obstack); - + /* Error handler called when `obstack_chunk_alloc' failed to allocate @@ -235,3 +208,3 @@ extern int obstack_exit_failure; -#define obstack_base(h) ((h)->object_base) +#define obstack_base(h) ((void *) (h)->object_base) @@ -316,3 +289,6 @@ __extension__ \ ({ struct obstack const *__o = (OBSTACK); \ - (__o->chunk->prev == 0 && __o->next_free - __o->chunk->contents == 0); }) + (__o->chunk->prev == 0 \ + && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \ + __o->chunk->contents, \ + __o->alignment_mask)); }) @@ -411,9 +387,8 @@ __extension__ \ ({ struct obstack *__o1 = (OBSTACK); \ - void *value; \ - value = (void *) __o1->object_base; \ - if (__o1->next_free == value) \ + void *__value = (void *) __o1->object_base; \ + if (__o1->next_free == __value) \ __o1->maybe_empty_object = 1; \ __o1->next_free \ - = __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\ - & ~ (__o1->alignment_mask)); \ + = __PTR_ALIGN (__o1->object_base, __o1->next_free, \ + __o1->alignment_mask); \ if (__o1->next_free - (char *)__o1->chunk \ @@ -422,3 +397,3 @@ __extension__ \ __o1->object_base = __o1->next_free; \ - value; }) + __value; }) @@ -441,3 +416,6 @@ __extension__ \ # define obstack_empty_p(h) \ - ((h)->chunk->prev == 0 && (h)->next_free - (h)->chunk->contents == 0) + ((h)->chunk->prev == 0 \ + && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \ + (h)->chunk->contents, \ + (h)->alignment_mask)) @@ -450,19 +428,19 @@ __extension__ \ # define obstack_make_room(h,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), (h)->temp), 0) : 0)) +( (h)->temp.tempint = (length), \ + (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0)) # define obstack_grow(h,where,length) \ -( (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), \ - (h)->next_free += (h)->temp) +( (h)->temp.tempint = (length), \ + (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \ + memcpy ((h)->next_free, where, (h)->temp.tempint), \ + (h)->next_free += (h)->temp.tempint) # 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), \ - (h)->next_free += (h)->temp, \ +( (h)->temp.tempint = (length), \ + (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \ + memcpy ((h)->next_free, where, (h)->temp.tempint), \ + (h)->next_free += (h)->temp.tempint, \ *((h)->next_free)++ = 0) @@ -491,6 +469,6 @@ __extension__ \ # define obstack_blank(h,length) \ -( (h)->temp = (length), \ - (((h)->chunk_limit - (h)->next_free < (h)->temp) \ - ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ - obstack_blank_fast (h, (h)->temp)) +( (h)->temp.tempint = (length), \ + (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \ + ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \ + obstack_blank_fast (h, (h)->temp.tempint)) @@ -509,6 +487,6 @@ __extension__ \ : 0), \ - (h)->temp = __PTR_TO_INT ((h)->object_base), \ + (h)->temp.tempptr = (h)->object_base, \ (h)->next_free \ - = __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \ - & ~ ((h)->alignment_mask)), \ + = __PTR_ALIGN ((h)->object_base, (h)->next_free, \ + (h)->alignment_mask), \ (((h)->next_free - (char *) (h)->chunk \ @@ -517,10 +495,11 @@ __extension__ \ (h)->object_base = (h)->next_free, \ - (void *) __INT_TO_PTR ((h)->temp)) + (h)->temp.tempptr) # define obstack_free(h,obj) \ -( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ - (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ +( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \ + ((((h)->temp.tempint > 0 \ + && (h)->temp.tempint < (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), 0))) + = (h)->temp.tempint + (char *) (h)->chunk) \ + : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0))) |