]> Savannah Git Hosting - gnulib.git/commitdiff
obstack: prefer alignof to calculating alignments by hand
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 Oct 2014 07:22:08 +0000 (00:22 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 Oct 2014 07:23:39 +0000 (00:23 -0700)
* lib/obstack.c: Include <stdalign.h>.
(struct fooalign): Remove.
(DEFAULT_ALIGNMENT): Use alignof rather than the old offsetof hack.
* modules/obstack (Depends-on): Add stdalign.

ChangeLog
lib/obstack.c
modules/obstack

index 8bf2baa2a33f476e582099d249338083dd2357b5..ffe7285ace54f1a45911eba2c3bb4d35ddd3f3e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-10-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+       obstack: prefer alignof to calculating alignments by hand
+       * lib/obstack.c: Include <stdalign.h>.
+       (struct fooalign): Remove.
+       (DEFAULT_ALIGNMENT): Use alignof rather than the old offsetof hack.
+       * modules/obstack (Depends-on): Add stdalign.
+
 2014-10-28  Paul Eggert  <eggert@cs.ucla.edu>
 
        obstack: use size_t alignments and check for overflow
index 342f9f84040d7bec067b325a9ff72e9c72952f1d..03281aecd1c06a4ec7237ce1944f498f94cf69bb 100644 (file)
@@ -48,6 +48,7 @@
 #endif
 
 #ifndef _OBSTACK_ELIDE_CODE
+# include <stdalign.h>
 # include <stdlib.h>
 # include <stdint.h>
 
@@ -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)
 };
 
index bceecdc64cb15361d28c2d0116d1274631f63307..c2c6390d5dcce81d2e3cd45464183016511a4ba9 100644 (file)
@@ -8,6 +8,7 @@ lib/obstack.c
 Depends-on:
 gettext-h
 exitfail
+stdalign
 stdint
 stdlib