]> Savannah Git Hosting - gnulib.git/commitdiff
flexmember: new macro FLEXALIGNOF
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Sep 2016 23:42:13 +0000 (16:42 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Sep 2016 23:44:33 +0000 (16:44 -0700)
* lib/flexmember.h: Include <stddef.h>, for offsetof.
(FLEXALIGNOF): Rename from _GL_XALLOC_ALIGNOF, as Emacs can use
this macro.  Update comments.

ChangeLog
lib/flexmember.h

index 1786c81834e1e069b92993a2ed727677fbe5a8d2..3c65fdea4d08e75bc506663c7d72882855e4288f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       flexmember: new macro FLEXALIGNOF
+       * lib/flexmember.h: Include <stddef.h>, for offsetof.
+       (FLEXALIGNOF): Rename from _GL_XALLOC_ALIGNOF, as Emacs can use
+       this macro.  Update comments.
+
 2016-09-07  Jim Meyering  <meyering@fb.com>
 
        getprogname: port to systems with __argv (mingw, msvc)
index 00b084c985c08a459cc85aebb0b0df7c4bae3c29..62c556bae25feb4ccdbdeab48cf1caab4b45d3e3 100644 (file)
 
    Written by Paul Eggert.  */
 
+#include <stddef.h>
+
 /* 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))