From 3574ba6f1d5246384dd4582558fd520aeedb8b91 Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Wed, 29 Oct 2014 00:22:08 -0700
Subject: [PATCH 2/2] obstack: prefer alignof to calculating alignments by hand
* lib/obstack.c: Include .
(struct fooalign): Remove.
(DEFAULT_ALIGNMENT): Use alignof rather than the old offsetof hack.
* modules/obstack (Depends-on): Add stdalign.
---
ChangeLog | 8 ++++++++
lib/obstack.c | 8 ++------
modules/obstack | 1 +
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8bf2baa..ffe7285 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-10-29 Paul Eggert
+
+ obstack: prefer alignof to calculating alignments by hand
+ * lib/obstack.c: Include .
+ (struct fooalign): Remove.
+ (DEFAULT_ALIGNMENT): Use alignof rather than the old offsetof hack.
+ * modules/obstack (Depends-on): Add stdalign.
+
2014-10-28 Paul Eggert
obstack: use size_t alignments and check for overflow
diff --git a/lib/obstack.c b/lib/obstack.c
index 342f9f8..03281ae 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -48,6 +48,7 @@
#endif
#ifndef _OBSTACK_ELIDE_CODE
+# include
# include
# include
@@ -58,17 +59,12 @@ union fooround
long double d;
void *p;
};
-struct fooalign
-{
- char c;
- union fooround u;
-};
/* 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. */
enum
{
- DEFAULT_ALIGNMENT = offsetof (struct fooalign, u),
+ DEFAULT_ALIGNMENT = alignof (union fooround),
DEFAULT_ROUNDING = sizeof (union fooround)
};
diff --git a/modules/obstack b/modules/obstack
index bceecdc..c2c6390 100644
--- a/modules/obstack
+++ b/modules/obstack
@@ -8,6 +8,7 @@ lib/obstack.c
Depends-on:
gettext-h
exitfail
+stdalign
stdint
stdlib
--
1.9.3