X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmalloca.h;h=9432161eacce8220bbea7e1b3a8a97d6207b718a;hb=5bf4ad0bfa91baa20e4f39f47bfb8b4dd00df720;hp=2bf8501522732e6cfab2982a42e53521f1db92ea;hpb=37654ecf58fe14c16eb3fbea289151c2e493e8cf;p=gnulib.git diff --git a/lib/malloca.h b/lib/malloca.h index 2bf850152..9432161ea 100644 --- a/lib/malloca.h +++ b/lib/malloca.h @@ -1,5 +1,5 @@ /* Safe automatic memory allocation. - Copyright (C) 2003-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2003-2007, 2009-2011 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify @@ -23,8 +23,6 @@ #include #include -#include "alignof.h" - #ifdef __cplusplus extern "C" { @@ -56,7 +54,7 @@ extern "C" { the function returns. Upon failure, it returns NULL. */ #if HAVE_ALLOCA # define malloca(N) \ - ((N) < 4032 - sa_increment \ + ((N) < 4032 - sa_increment \ ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \ : mmalloca (N)) #else @@ -94,22 +92,40 @@ extern void * nmalloca (size_t n, size_t s); /* ------------------- Auxiliary, non-public definitions ------------------- */ +/* Determine the alignment of a type at compile time. */ +#if defined __GNUC__ +# define sa_alignof __alignof__ +#elif defined __cplusplus + template struct sa_alignof_helper { char __slot1; type __slot2; }; +# define sa_alignof(type) offsetof (sa_alignof_helper, __slot2) +#elif defined __hpux + /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof + values. */ +# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8) +#elif defined _AIX + /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof + values. */ +# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8) +#else +# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2) +#endif + enum { /* The desired alignment of memory allocations is the maximum alignment among all elementary types. */ - sa_alignment_long = alignof (long), - sa_alignment_double = alignof (double), + sa_alignment_long = sa_alignof (long), + sa_alignment_double = sa_alignof (double), #if HAVE_LONG_LONG_INT - sa_alignment_longlong = alignof (long long), + sa_alignment_longlong = sa_alignof (long long), #endif - sa_alignment_longdouble = alignof (long double), + sa_alignment_longdouble = sa_alignof (long double), sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1) #if HAVE_LONG_LONG_INT - | (sa_alignment_longlong - 1) + | (sa_alignment_longlong - 1) #endif - | (sa_alignment_longdouble - 1) - ) + 1, + | (sa_alignment_longdouble - 1) + ) + 1, /* The increment that guarantees room for a magic word must be >= sizeof (int) and a multiple of sa_alignment_max. */ sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max