summaryrefslogtreecommitdiff
path: root/lib/obstack.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-05-20 11:39:54 +0000
committerJim Meyering <jim@meyering.net>2004-05-20 11:39:54 +0000
commit994e9be511d98416c93055c164f961605bfaa96e (patch)
tree1044bfb20c4ba2366c662204486319facd658c92 /lib/obstack.c
parent142d646e01992762f46c142e797289bdb63f71e3 (diff)
downloadcoreutils-994e9be511d98416c93055c164f961605bfaa96e.tar.xz
Update from gnulib.
Diffstat (limited to 'lib/obstack.c')
-rw-r--r--lib/obstack.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/obstack.c b/lib/obstack.c
index 6a1ca0086..65e23e9d2 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -54,18 +54,26 @@
# include <wchar.h>
#endif
+#include <stddef.h>
+
#ifndef ELIDE_CODE
/* Determine default alignment. */
-struct fooalign {char x; double d;};
-# define DEFAULT_ALIGNMENT \
- ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
+union fooround
+{
+ long int i;
+ long double d;
+ void *p;
+};
/* 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))
+enum
+ {
+ DEFAULT_ALIGNMENT = offsetof (struct { char c; union fooround u; }, u),
+ 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;
@@ -94,11 +102,6 @@ int obstack_exit_failure = EXIT_FAILURE;
# 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;
-
/* Define a macro that either calls functions with the traditional malloc/free
calling interface, or calls functions with the mmalloc/mfree interface
(that adds an extra first argument), based on the state of use_extra_arg.
@@ -136,7 +139,7 @@ _obstack_begin (struct obstack *h,
register struct _obstack_chunk *chunk; /* points to new chunk */
if (alignment == 0)
- alignment = (int) DEFAULT_ALIGNMENT;
+ alignment = DEFAULT_ALIGNMENT;
if (size == 0)
/* Default size is what GNU malloc can fit in a 4096-byte block. */
{
@@ -182,7 +185,7 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment,
register struct _obstack_chunk *chunk; /* points to new chunk */
if (alignment == 0)
- alignment = (int) DEFAULT_ALIGNMENT;
+ alignment = DEFAULT_ALIGNMENT;
if (size == 0)
/* Default size is what GNU malloc can fit in a 4096-byte block. */
{
@@ -252,8 +255,7 @@ _obstack_newchunk (struct obstack *h, int length)
/* Compute an aligned object_base in the new chunk */
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);
/* Move the existing object to the new chunk.
Word at a time is fast and is safe if the object