From: Paul Eggert Date: Wed, 29 Oct 2014 07:22:08 +0000 (-0700) Subject: obstack: prefer alignof to calculating alignments by hand X-Git-Tag: v1.0~7277 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e8f86ce95e515ef9d2ed7c0cdf203fb31482c3d6;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 8bf2baa2a3..ffe7285ace 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 342f9f8404..03281aecd1 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 bceecdc64c..c2c6390d5d 100644 --- a/modules/obstack +++ b/modules/obstack @@ -8,6 +8,7 @@ lib/obstack.c Depends-on: gettext-h exitfail +stdalign stdint stdlib