# HG changeset patch # User Paul Eggert # Date 1414624541 25200 # Node ID f6c039e09a3bec66e657bd3ff6fed9aa59d1e1bb # Parent 0885e560f72632b0cbf115c73b201102e695f95f obstack: prefer __alignof__ to alignof This is for portability to pre-4.7 GCC when compiling glibc. See Joseph S. Myers in: http://sourceware.org/ml/libc-alpha/2014-10/msg00703.html * lib/obstack.c (__alignof__) [!_LIBC && !__GNUC__]: New macro, defined by including and using . (MAX): New macro. (DEFAULT_ALIGNMENT, DEFAULT_ROUNDING): Redefine in terms of these. Do not use enums as they are not portable to some broken compilers. * modules/obstack (Depends-on): Depend on alignof, not stdalign. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2014-10-29 Paul Eggert + obstack: prefer __alignof__ to alignof + This is for portability to pre-4.7 GCC when compiling glibc. + See Joseph S. Myers in: + http://sourceware.org/ml/libc-alpha/2014-10/msg00703.html + * lib/obstack.c (__alignof__) [!_LIBC && !__GNUC__]: + New macro, defined by including and using . + (MAX): New macro. + (DEFAULT_ALIGNMENT, DEFAULT_ROUNDING): Redefine in terms of these. + Do not use enums as they are not portable to some broken compilers. + * modules/obstack (Depends-on): Depend on alignof, not stdalign. + obstack: prefer alignof to calculating alignments by hand * lib/obstack.c: Include . (struct fooalign): Remove. diff --git a/lib/obstack.c b/lib/obstack.c --- a/lib/obstack.c +++ b/lib/obstack.c @@ -48,26 +48,30 @@ #endif #ifndef _OBSTACK_ELIDE_CODE -# include +# if !defined _LIBC && !defined __GNUC__ +# include +# define __alignof__(type) alignof_type (type) +# endif # include # include +# ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +# endif + /* Determine default alignment. */ -union fooround -{ - uintmax_t 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. */ -enum -{ - DEFAULT_ALIGNMENT = alignof (union fooround), - DEFAULT_ROUNDING = sizeof (union fooround) -}; + DEFAULT_ROUNDING. So we prepare for it to do that. + DEFAULT_ALIGNMENT cannot be an enum constant; see gnulib's alignof.h. */ +#define DEFAULT_ALIGNMENT MAX (__alignof__ (long double), \ + MAX (__alignof__ (uintmax_t), \ + __alignof__ (void *))) +#define DEFAULT_ROUNDING MAX (sizeof (long double), \ + MAX (sizeof (uintmax_t), \ + sizeof (void *))) /* Define a macro that either calls functions with the traditional malloc/free calling interface, or calls functions with the mmalloc/mfree interface diff --git a/modules/obstack b/modules/obstack --- a/modules/obstack +++ b/modules/obstack @@ -6,9 +6,9 @@ lib/obstack.c Depends-on: +alignof gettext-h exitfail -stdalign stdint stdlib