From patchwork Thu Oct 30 00:58:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 3496 Received: (qmail 14675 invoked by alias); 30 Oct 2014 00:59:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 14659 invoked by uid 89); 30 Oct 2014 00:59:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: smtp.cs.ucla.edu Message-ID: <54518D50.1090503@cs.ucla.edu> Date: Wed, 29 Oct 2014 17:58:56 -0700 From: Paul Eggert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: "Joseph S. Myers" CC: Alan Modra , libc-alpha@sourceware.org, bug-gnulib@gnu.org Subject: Re: [PATCH 0/5] obstacks again References: <20141029033201.GI4267@bubble.grove.modra.org> <5450983F.3030608@cs.ucla.edu> In-Reply-To: Joseph S. Myers wrote: > Note that we can't use 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 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 . (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(-) diff --git a/ChangeLog b/ChangeLog index ffe7285..cea54fc 100644 --- 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 index 03281ae..ba7dff3 100644 --- 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 index c2c6390..36dc444 100644 --- a/modules/obstack +++ b/modules/obstack @@ -6,9 +6,9 @@ lib/obstack.h lib/obstack.c Depends-on: +alignof gettext-h exitfail -stdalign stdint stdlib