[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] obstack uses casts as lvalues
From: |
Paul Eggert |
Subject: |
Re: [Bug-gnulib] obstack uses casts as lvalues |
Date: |
21 Oct 2003 22:14:12 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
I installed the following further cleanup patch to gnulib obstack.h
and obstack.c, to make it easier to merge gnulib's changes into libc
in the future.
2003-10-21 Paul Eggert <address@hidden>
* obstack.c: Merge from glibc.
[defined _LIBC]: Include <obstack.h>, 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 <libio/iolibio.h>.
* obstack.h: Indenting cleanup, to make it easier to merge with glibc.
(obstack_grow, obstack_grow0): Remove unnecessary parentheses around
arg to memcpy.
Index: lib/obstack.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/obstack.c,v
retrieving revision 1.21
diff -p -u -r1.21 obstack.c
--- lib/obstack.c 12 Sep 2003 20:14:10 -0000 1.21
+++ lib/obstack.c 22 Oct 2003 05:07:18 -0000
@@ -21,7 +21,11 @@
# include <config.h>
#endif
+#ifdef _LIBC
+#include <obstack.h>
+#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, in
/* 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,
# 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 *o
/* 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 <libio/iolibio.h>
-# define fputs(s, f) _IO_fputs (s, f)
# endif
# ifndef __attribute__
Index: lib/obstack.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/obstack.h,v
retrieving revision 1.24
diff -p -u -r1.24 obstack.h
--- lib/obstack.h 22 Oct 2003 01:02:48 -0000 1.24
+++ lib/obstack.h 22 Oct 2003 05:07:18 -0000
@@ -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 \