This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: RFC: Aligning data in buffers with a macro?
- From: Marek Polacek <polacek at redhat dot com>
- To: "Carlos O'Donell" <carlos at systemhalted dot org>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Sun, 1 Apr 2012 18:30:53 +0200
- Subject: Re: RFC: Aligning data in buffers with a macro?
- References: <CADZpyiwy12TMPteOu8A=w6eD=er82+GqhTy0DHM0gyyVOisYHA@mail.gmail.com>
On Sun, Apr 01, 2012 at 11:30:37AM -0400, Carlos O'Donell wrote:
> What do people think about creating some generic macros we can use for
> alignment?
>
> That way it's crystal clear what you intend with the code.
>
> For exmaple this...
>
> 628 # elif _STACK_GROWS_UP
> 629 char *guard = (char *) (((uintptr_t) pd - guardsize) &
> ~pagesize_m1);
> 630 #endif
>
> ... would become:
>
> 628 # elif _STACK_GROWS_UP
> 629 char *guard = (char *) ALIGN_DOWN((uintptr_t) pd -
> guardsize, pagesize_m1);
> 630 #endif
To be honest, that doesn't make much difference to me. The second
variant is not shorter nor more readable I suspect. Also I have
a qualm about these changes--they might be quite error-prone.
> Do the kernel headers have something we can crib or use here?
I see a lot of various *_ALIGN macros, e.g.
arch/powerpc/boot/page.h
25:#define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
26:#define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
include/linux/kernel.h
10:#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
and so on. There was an effort a few years back to unify these
align macros to one align.h header, but still there isn't any
such header. See e.g. this patch:
http://lkml.indiana.edu/hypermail/linux/kernel/0908.2/01641.html
Marek