Commit Message
Joseph S. Myers wrote:
> Note that we can't use <stdalign.h> in glibc sources unless we move to
> requiring GCC >= 4.7
Ah, thanks for mentioning that; the attached patch should fix that. I pushed
this into gnulib.
From d91a04a3dfc05b42031e8fd00af2cd29b6fa585d Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 29 Oct 2014 16:15:41 -0700
Subject: [PATCH] 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.
---
ChangeLog | 11 +++++++++++
lib/obstack.c | 32 ++++++++++++++++++--------------
modules/obstack | 2 +-
3 files changed, 30 insertions(+), 15 deletions(-)
@@ -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.
@@ -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
@@ -6,9 +6,9 @@ lib/obstack.h
lib/obstack.c
Depends-on:
+alignof
gettext-h
exitfail
-stdalign
stdint
stdlib