diff options
author | Bruno Haible <bruno@clisp.org> | 2002-11-19 14:09:45 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:08:52 +0200 |
commit | c458c4aa60ffabd3296f77e6d6f45993849a6cdd (patch) | |
tree | d86588b08a939126d706347f761c9088df06dfcc | |
parent | 813b61199d32c439b1424882cd1e58b251da4d87 (diff) | |
download | external_gettext-c458c4aa60ffabd3296f77e6d6f45993849a6cdd.zip external_gettext-c458c4aa60ffabd3296f77e6d6f45993849a6cdd.tar.gz external_gettext-c458c4aa60ffabd3296f77e6d6f45993849a6cdd.tar.bz2 |
Merge with gnulib.
-rw-r--r-- | lib/ChangeLog | 5 | ||||
-rw-r--r-- | lib/obstack.c | 197 | ||||
-rw-r--r-- | lib/obstack.h | 93 |
3 files changed, 169 insertions, 126 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index d96051b..e5c2529 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2002-11-19 Bruno Haible <bruno@clisp.org> + + * obstack.h: Update from current gnulib version. + * obstack.c: Update from current gnulib version. + 2002-11-06 Bruno Haible <bruno@clisp.org> * gcd.h (gcd): Change argument type to 'unsigned long'. diff --git a/lib/obstack.c b/lib/obstack.c index bf00cef..0ef6c91 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -1,27 +1,25 @@ /* obstack.c - subroutines used implicitly by object stack macros - Copyright (C) 1988-1994, 1996-1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1988-1994, 1996-1999, 2000-2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. Its master source is NOT part of + the C library, however. The master source lives in /gd/gnu/lib. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@gnu.org. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, + The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. */ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ #ifdef HAVE_CONFIG_H -#include <config.h> +# include <config.h> #endif #include "obstack.h" @@ -41,40 +39,43 @@ files, it is simpler to just do this in the source for each such file. */ #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 +#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 +# include <wchar.h> +#endif #ifndef ELIDE_CODE -#if defined (__STDC__) && __STDC__ -#define POINTER void * -#else -#define POINTER char * -#endif +# if defined __STDC__ && __STDC__ +# define POINTER void * +# else +# define POINTER char * +# endif /* Determine default alignment. */ struct fooalign {char x; double d;}; -#define DEFAULT_ALIGNMENT \ +# define DEFAULT_ALIGNMENT \ ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0)) /* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT. But in fact it might be less smart and round addresses to as much as DEFAULT_ROUNDING. So we prepare for it to do that. */ union fooround {long x; double d;}; -#define DEFAULT_ROUNDING (sizeof (union fooround)) +# define DEFAULT_ROUNDING (sizeof (union fooround)) /* When we copy a long block of data, this is the unit to do it with. On some machines, copying successive ints does not work; in such a case, redefine COPYING_UNIT to `long' (if that works) or `char' as a last resort. */ -#ifndef COPYING_UNIT -#define COPYING_UNIT int -#endif +# ifndef COPYING_UNIT +# define COPYING_UNIT int +# endif /* The functions allocating more room by calling `obstack_chunk_alloc' @@ -83,21 +84,21 @@ union fooround {long x; double d;}; abort gracefully or use longjump - but shouldn't return. This variable by default points to the internal function `print_and_abort'. */ -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ static void print_and_abort (void); void (*obstack_alloc_failed_handler) (void) = print_and_abort; -#else +# else static void print_and_abort (); void (*obstack_alloc_failed_handler) () = print_and_abort; -#endif +# endif /* Exit value used when `print_and_abort' is used. */ -#if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifndef EXIT_FAILURE -#define EXIT_FAILURE 1 -#endif +# if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H +# include <stdlib.h> +# endif +# ifndef EXIT_FAILURE +# define EXIT_FAILURE 1 +# endif int obstack_exit_failure = EXIT_FAILURE; /* The non-GNU-C macros copy the obstack into this global variable @@ -111,33 +112,33 @@ struct obstack *_obstack; For free, do not use ?:, since some compilers, like the MIPS compilers, do not allow (expr) ? void : void. */ -#if defined (__STDC__) && __STDC__ -#define CALL_CHUNKFUN(h, size) \ +# 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) \ +# 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) \ +# 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) \ +# 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 +# endif /* Initialize an obstack H for use. Specify chunk size SIZE (0 means default). @@ -153,13 +154,13 @@ _obstack_begin (h, size, alignment, chunkfun, freefun) struct obstack *h; int size; int alignment; -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ POINTER (*chunkfun) (long); void (*freefun) (void *); -#else +# else POINTER (*chunkfun) (); void (*freefun) (); -#endif +# endif { register struct _obstack_chunk *chunk; /* points to new chunk */ @@ -182,13 +183,13 @@ _obstack_begin (h, size, alignment, chunkfun, freefun) size = 4096 - extra; } -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun; h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; -#else +# else h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun; h->freefun = freefun; -#endif +# endif h->chunk_size = size; h->alignment_mask = alignment - 1; h->use_extra_arg = 0; @@ -211,13 +212,13 @@ _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg) struct obstack *h; int size; int alignment; -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ POINTER (*chunkfun) (POINTER, long); void (*freefun) (POINTER, POINTER); -#else +# else POINTER (*chunkfun) (); void (*freefun) (); -#endif +# endif POINTER arg; { register struct _obstack_chunk *chunk; /* points to new chunk */ @@ -241,13 +242,13 @@ _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg) size = 4096 - extra; } -#if defined(__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun; h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; -#else +# else h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun; h->freefun = freefun; -#endif +# endif h->chunk_size = size; h->alignment_mask = alignment - 1; h->extra_arg = arg; @@ -342,11 +343,11 @@ _obstack_newchunk (h, length) This is here for debugging. If you use it in a program, you are probably losing. */ -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ /* Suppress -Wmissing-prototypes warning. We don't want to declare this in obstack.h because it is just for debugging. */ int _obstack_allocated_p (struct obstack *h, POINTER obj); -#endif +# endif int _obstack_allocated_p (h, obj) @@ -371,7 +372,7 @@ _obstack_allocated_p (h, obj) /* Free objects in obstack H, including OBJ and everything allocate more recently than OBJ. If OBJ is zero, free everything in H. */ -#undef obstack_free +# undef obstack_free /* This function has two names with identical definitions. This is the first one, called from non-ANSI code. */ @@ -457,29 +458,51 @@ _obstack_memory_used (h) } /* Define the error handler. */ -#ifdef _LIBC -# include <libintl.h> -#else -# include "gettext.h" -#endif -#define _(msgid) gettext (msgid) +# ifdef _LIBC +# include <libintl.h> +# else +# include "gettext.h" +# endif +# define _(msgid) gettext (msgid) + +# if defined _LIBC && defined USE_IN_LIBIO +# include <libio/iolibio.h> +# define fputs(s, f) _IO_fputs (s, f) +# endif + +# ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +# endif static void +__attribute__ ((noreturn)) print_and_abort () { - fputs (_("memory exhausted"), stderr); - fputc ('\n', stderr); + /* Don't change any of these strings. Yes, it would be possible to add + the newline to the string and use fputs or so. But this must not + happen because the "memory exhausted" message appears in other places + like this and the translation should be reused instead of creating + a very similar string which requires a separate translation. */ +# 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 0 /* These are now turned off because the applications do not use it and it uses bcopy via obstack_grow, which causes trouble on sysV. */ /* Now define the functional versions of the obstack macros. Define them to simply use the corresponding macros to do the job. */ -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ /* These function definitions do not work with non-ANSI preprocessors; they won't pass through the macro names in parentheses. */ @@ -517,20 +540,20 @@ int (obstack_make_room) (obstack, length) return obstack_make_room (obstack, length); } -void (obstack_grow) (obstack, pointer, length) +void (obstack_grow) (obstack, data, length) struct obstack *obstack; - POINTER pointer; + const POINTER data; int length; { - obstack_grow (obstack, pointer, length); + obstack_grow (obstack, data, length); } -void (obstack_grow0) (obstack, pointer, length) +void (obstack_grow0) (obstack, data, length) struct obstack *obstack; - POINTER pointer; + const POINTER data; int length; { - obstack_grow0 (obstack, pointer, length); + obstack_grow0 (obstack, data, length); } void (obstack_1grow) (obstack, character) @@ -574,24 +597,24 @@ POINTER (obstack_alloc) (obstack, length) return obstack_alloc (obstack, length); } -POINTER (obstack_copy) (obstack, pointer, length) +POINTER (obstack_copy) (obstack, address, length) struct obstack *obstack; - POINTER pointer; + const POINTER address; int length; { - return obstack_copy (obstack, pointer, length); + return obstack_copy (obstack, address, length); } -POINTER (obstack_copy0) (obstack, pointer, length) +POINTER (obstack_copy0) (obstack, address, length) struct obstack *obstack; - POINTER pointer; + const POINTER address; int length; { - return obstack_copy0 (obstack, pointer, length); + return obstack_copy0 (obstack, address, length); } -#endif /* __STDC__ */ +# endif /* __STDC__ */ -#endif /* 0 */ +# endif /* 0 */ #endif /* !ELIDE_CODE */ diff --git a/lib/obstack.h b/lib/obstack.h index b81a977..c949730 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -1,6 +1,8 @@ /* obstack.h - object stack macros - Copyright (C) 1988-1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1988,89,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc. + This file is part of the GNU C Library. Its master source is NOT part of + the C library, however. The master source lives in /gd/gnu/lib. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@gnu.org. @@ -12,11 +14,11 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -289,21 +291,24 @@ extern int obstack_exit_failure; standard C version. */ #if defined __STDC__ && __STDC__ -# define obstack_init(h) \ - _obstack_begin ((h), 0, 0, \ - (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) +# define obstack_init(h) \ + _obstack_begin ((h), 0, 0, \ + (void *(*) (long)) obstack_chunk_alloc, \ + (void (*) (void *)) obstack_chunk_free) -# define obstack_begin(h, size) \ - _obstack_begin ((h), (size), 0, \ - (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) +# 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) \ - _obstack_begin ((h), (size), (alignment), \ - (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun)) + _obstack_begin ((h), (size), (alignment), \ + (void *(*) (long)) (chunkfun), \ + (void (*) (void *)) (freefun)) # define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ - _obstack_begin_1 ((h), (size), (alignment), \ - (void *(*) (void *, long)) (chunkfun), \ + _obstack_begin_1 ((h), (size), (alignment), \ + (void *(*) (void *, long)) (chunkfun), \ (void (*) (void *, void *)) (freefun), (arg)) # define obstack_chunkfun(h, newchunkfun) \ @@ -314,21 +319,25 @@ extern int obstack_exit_failure; #else -# define obstack_init(h) \ - _obstack_begin ((h), 0, 0, \ - (void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free) +# 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_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)) + _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)) + _obstack_begin_1 ((h), (size), (alignment), \ + (void *(*) ()) (chunkfun), \ + (void (*) ()) (freefun), (arg)) # define obstack_chunkfun(h, newchunkfun) \ ((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun)) @@ -386,7 +395,7 @@ __extension__ \ int __len = (length); \ if (__o->next_free + __len > __o->chunk_limit) \ _obstack_newchunk (__o, __len); \ - _obstack_memcpy (__o->next_free, (const char *) (where), __len); \ + _obstack_memcpy (__o->next_free, (where), __len); \ __o->next_free += __len; \ (void) 0; }) @@ -396,7 +405,7 @@ __extension__ \ int __len = (length); \ if (__o->next_free + __len + 1 > __o->chunk_limit) \ _obstack_newchunk (__o, __len + 1); \ - _obstack_memcpy (__o->next_free, (const char *) (where), __len); \ + _obstack_memcpy (__o->next_free, (where), __len); \ __o->next_free += __len; \ *(__o->next_free)++ = 0; \ (void) 0; }) @@ -409,8 +418,8 @@ __extension__ \ *(__o->next_free)++ = (datum); \ (void) 0; }) -/* These assume that the obstack alignment is good enough for pointers or ints, - and that the data added so far to the current object +/* These assume that the obstack alignment is good enough for pointers + or ints, and that the data added so far to the current object shares that much alignment. */ # define obstack_ptr_grow(OBSTACK,datum) \ @@ -418,7 +427,7 @@ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ if (__o->next_free + sizeof (void *) > __o->chunk_limit) \ _obstack_newchunk (__o, sizeof (void *)); \ - *((void **)__o->next_free)++ = ((const void *)datum); \ + *((void **)__o->next_free)++ = (datum); \ (void) 0; }) # define obstack_int_grow(OBSTACK,datum) \ @@ -426,11 +435,14 @@ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ if (__o->next_free + sizeof (int) > __o->chunk_limit) \ _obstack_newchunk (__o, sizeof (int)); \ - *((int *)__o->next_free)++ = ((int)datum); \ + *((int *)__o->next_free)++ = (datum); \ (void) 0; }) -# define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr) -# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) +# define obstack_ptr_grow_fast(h,aptr) \ + (*((void **) (h)->next_free)++ = (aptr)) + +# define obstack_int_grow_fast(h,aint) \ + (*((int *) (h)->next_free)++ = (aint)) # define obstack_blank(OBSTACK,length) \ __extension__ \ @@ -511,14 +523,14 @@ __extension__ \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ - _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \ + _obstack_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), \ - _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \ + _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ (h)->next_free += (h)->temp, \ *((h)->next_free)++ = 0) @@ -530,15 +542,18 @@ __extension__ \ # define obstack_ptr_grow(h,datum) \ ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \ - (*((char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) = ((char *) datum))) + (*((const char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) = (datum))) # define obstack_int_grow(h,datum) \ ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \ - (*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = ((int) datum))) + (*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = (datum))) + +# define obstack_ptr_grow_fast(h,aptr) \ + (*((const char **) (h)->next_free)++ = (aptr)) -# define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr) -# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) +# define obstack_int_grow_fast(h,aint) \ + (*((int *) (h)->next_free)++ = (aint)) # define obstack_blank(h,length) \ ( (h)->temp = (length), \ |