Mercurial > hg > octave-nkf > gnulib-hg
changeset 17782:f6c039e09a3b
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 <alignof.h>.
(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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 29 Oct 2014 16:15:41 -0700 |
parents | 0885e560f726 |
children | 4761a2b66270 |
files | ChangeLog lib/obstack.c modules/obstack |
diffstat | 3 files changed, 29 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2014-10-29 Paul Eggert <eggert@cs.ucla.edu> + 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 <alignof.h>. + (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 <stdalign.h>. (struct fooalign): Remove.
--- a/lib/obstack.c +++ b/lib/obstack.c @@ -48,26 +48,30 @@ #endif #ifndef _OBSTACK_ELIDE_CODE -# include <stdalign.h> +# if !defined _LIBC && !defined __GNUC__ +# include <alignof.h> +# define __alignof__(type) alignof_type (type) +# endif # include <stdlib.h> # include <stdint.h> +# 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