From: Paul Eggert Date: Wed, 7 Sep 2016 23:42:13 +0000 (-0700) Subject: flexmember: new macro FLEXALIGNOF X-Git-Tag: v1.0~6653 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=7da1068a87c331793af73359d8637d140d08a674;p=gnulib.git flexmember: new macro FLEXALIGNOF * lib/flexmember.h: Include , for offsetof. (FLEXALIGNOF): Rename from _GL_XALLOC_ALIGNOF, as Emacs can use this macro. Update comments. --- diff --git a/ChangeLog b/ChangeLog index 1786c81834..3c65fdea4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-09-07 Paul Eggert + + flexmember: new macro FLEXALIGNOF + * lib/flexmember.h: Include , for offsetof. + (FLEXALIGNOF): Rename from _GL_XALLOC_ALIGNOF, as Emacs can use + this macro. Update comments. + 2016-09-07 Jim Meyering getprogname: port to systems with __argv (mingw, msvc) diff --git a/lib/flexmember.h b/lib/flexmember.h index 00b084c985..62c556bae2 100644 --- a/lib/flexmember.h +++ b/lib/flexmember.h @@ -17,23 +17,26 @@ Written by Paul Eggert. */ +#include + /* Nonzero multiple of alignment of TYPE, suitable for FLEXSIZEOF below. On older platforms without _Alignof, use a pessimistic bound that is safe in practice even if FLEXIBLE_ARRAY_MEMBER is 1. On newer platforms, use _Alignof to get a tighter bound. */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 -# define _GL_XALLOC_ALIGNOF(type) (sizeof (type) & ~ (sizeof (type) - 1)) +# define FLEXALIGNOF(type) (sizeof (type) & ~ (sizeof (type) - 1)) #else -# define _GL_XALLOC_ALIGNOF(type) _Alignof (type) +# define FLEXALIGNOF(type) _Alignof (type) #endif /* Upper bound on the size of a struct of type TYPE with a flexible array member named MEMBER that is followed by N bytes of other data. This is not simply sizeof (TYPE) + N, since it may require - alignment and FLEXIBLE_ARRAY_MEMBER may be 1. Yield a value less - than N if and only if arithmetic overflow occurs. */ + alignment on unusually picky C11 platforms, and + FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. + Yield a value less than N if and only if arithmetic overflow occurs. */ #define FLEXSIZEOF(type, member, n) \ - ((offsetof (type, member) + _GL_XALLOC_ALIGNOF (type) - 1 + (n)) \ - & ~ (_GL_XALLOC_ALIGNOF (type) - 1)) + ((offsetof (type, member) + FLEXALIGNOF (type) - 1 + (n)) \ + & ~ (FLEXALIGNOF (type) - 1))