]> Savannah Git Hosting - gnulib.git/commitdiff
stddef: support C11's max_align_t
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 12 Dec 2014 19:27:45 +0000 (11:27 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 12 Dec 2014 19:28:09 +0000 (11:28 -0800)
* doc/posix-headers/stddef.texi (stddef.h): Document max_align_t.
* lib/stddef.in.h (_@GUARD_PREFIX@_STDDEF_H) [__need_wint_t]:
Do not undef, as that might cause max_align_t to be defined twice.
Instead, change use to check for _GL_STDDEF_WINT_T too.
(max_align_t) [!HAVE_MAX_ALIGN_T]: New decl.
* m4/stddef_h.m4 (gl_STDDEF_H, gl_STDDEF_H_DEFAULTS):
Check for max_align_t.
* modules/stddef (stddef.h): Substitute HAVE_MAX_ALIGN_T.
* modules/stddef-tests (Depends-on): Add stdalign.
* tests/test-stddef.c: Test max_align_t.

ChangeLog
doc/posix-headers/stddef.texi
lib/stddef.in.h
m4/stddef_h.m4
modules/stddef
modules/stddef-tests
tests/test-stddef.c

index 2336ee58282263768a724d03a730114f67a29a04..df4d8d4f565a54e9190309b7af1e6108be27a0f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2014-12-12  Paul Eggert  <eggert@cs.ucla.edu>
+
+       stddef: support C11's max_align_t
+       * doc/posix-headers/stddef.texi (stddef.h): Document max_align_t.
+       * lib/stddef.in.h (_@GUARD_PREFIX@_STDDEF_H) [__need_wint_t]:
+       Do not undef, as that might cause max_align_t to be defined twice.
+       Instead, change use to check for _GL_STDDEF_WINT_T too.
+       (max_align_t) [!HAVE_MAX_ALIGN_T]: New decl.
+       * m4/stddef_h.m4 (gl_STDDEF_H, gl_STDDEF_H_DEFAULTS):
+       Check for max_align_t.
+       * modules/stddef (stddef.h): Substitute HAVE_MAX_ALIGN_T.
+       * modules/stddef-tests (Depends-on): Add stdalign.
+       * tests/test-stddef.c: Test max_align_t.
+
 2014-12-11  Daiki Ueno  <ueno@gnu.org>
 
        unistd: fix iOS check conditional
index 6174b1f3769da1be8ca9965907f1d0ffb9ab9acd..77b3d3b9b304510178e64c7aee62fa6783e182ec 100644 (file)
@@ -7,6 +7,9 @@ Gnulib module: stddef
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+Some platforms fail to provide @code{max_align_t}, which was added in C11.
+
 @item
 Some old platforms fail to provide @code{wchar_t}.
 
index 11b58bed76110b374fdb3c3a6d589b8bac3d2644..6032526cfa69b796fa60b01de051127a2291951e 100644 (file)
@@ -39,7 +39,6 @@
 
 # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
 #  ifdef __need_wint_t
-#   undef _@GUARD_PREFIX@_STDDEF_H
 #   define _GL_STDDEF_WINT_T
 #  endif
 #  @INCLUDE_NEXT@ @NEXT_STDDEF_H@
 
 #  @INCLUDE_NEXT@ @NEXT_STDDEF_H@
 
-#  ifndef _@GUARD_PREFIX@_STDDEF_H
-#   define _@GUARD_PREFIX@_STDDEF_H
-
 /* On NetBSD 5.0, the definition of NULL lacks proper parentheses.  */
-#if @REPLACE_NULL@
-# undef NULL
-# ifdef __cplusplus
+#  if (@REPLACE_NULL@ \
+       && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T))
+#   undef NULL
+#   ifdef __cplusplus
    /* ISO C++ says that the macro NULL must expand to an integer constant
       expression, hence '((void *) 0)' is not allowed in C++.  */
-#  if __GNUG__ >= 3
+#    if __GNUG__ >= 3
     /* GNU C++ has a __null macro that behaves like an integer ('int' or
        'long') but has the same size as a pointer.  Use that, to avoid
        warnings.  */
-#   define NULL __null
-#  else
-#   define NULL 0L
+#     define NULL __null
+#    else
+#     define NULL 0L
+#    endif
+#   else
+#    define NULL ((void *) 0)
+#   endif
 #  endif
-# else
-#  define NULL ((void *) 0)
-# endif
-#endif
+
+#  ifndef _@GUARD_PREFIX@_STDDEF_H
+#   define _@GUARD_PREFIX@_STDDEF_H
 
 /* Some platforms lack wchar_t.  */
 #if !@HAVE_WCHAR_T@
 # define wchar_t int
 #endif
 
+/* Some platforms lack max_align_t.  */
+#if !@HAVE_MAX_ALIGN_T@
+typedef union
+{
+  char *__p;
+  double __d;
+  long double __ld;
+  long int __i;
+} max_align_t;
+#endif
+
 #  endif /* _@GUARD_PREFIX@_STDDEF_H */
 # endif /* _@GUARD_PREFIX@_STDDEF_H */
 #endif /* __need_XXX */
index c555e29524458b98a7369b58e0f5470a5ded57a2..9659813bda6fcadbf9fbf9a9d723313f15fb3643 100644 (file)
@@ -1,5 +1,5 @@
-dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues.
-# stddef_h.m4 serial 4
+dnl A placeholder for <stddef.h>, for platforms that have issues.
+# stddef_h.m4 serial 5
 dnl Copyright (C) 2009-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,6 +10,9 @@ AC_DEFUN([gl_STDDEF_H],
   AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
   AC_REQUIRE([gt_TYPE_WCHAR_T])
   STDDEF_H=
+  AC_CHECK_TYPE([max_align_t], [], [HAVE_MAX_ALIGN_T=0; STDDEF_H=stddef.h],
+    [[#include <stddef.h>
+    ]])
   if test $gt_cv_c_wchar_t = no; then
     HAVE_WCHAR_T=0
     STDDEF_H=stddef.h
@@ -43,5 +46,6 @@ AC_DEFUN([gl_STDDEF_H_DEFAULTS],
 [
   dnl Assume proper GNU behavior unless another module says otherwise.
   REPLACE_NULL=0;                AC_SUBST([REPLACE_NULL])
+  HAVE_MAX_ALIGN_T=1;            AC_SUBST([HAVE_MAX_ALIGN_T])
   HAVE_WCHAR_T=1;                AC_SUBST([HAVE_WCHAR_T])
 ])
index fd4cf503d0c44aa05f2b907e03ec76df3b2bfcba..99794a9c6afba2a7617bbbd464aef1693b7db926 100644 (file)
@@ -26,6 +26,7 @@ stddef.h: stddef.in.h $(top_builddir)/config.status
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
+             -e 's|@''HAVE_MAX_ALIGN_T''@|$(HAVE_MAX_ALIGN_T)|g' \
              -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
              -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \
              < $(srcdir)/stddef.in.h; \
index 622ece50f0fc9f4b90fe73c44629dc640308662b..cef92fa6aa3934a3a22ea7728ed0270cb1eb4fd9 100644 (file)
@@ -2,6 +2,7 @@ Files:
 tests/test-stddef.c
 
 Depends-on:
+stdalign
 verify
 
 configure.ac:
index d5d887eb23339754b2778e50b2f2bbb6e3eca38a..0b8649d1260105fa11eff9a25ccd484c36dcc745 100644 (file)
 #include <config.h>
 
 #include <stddef.h>
-
+#include <stdalign.h>
 #include "verify.h"
 
 /* Check that appropriate types are defined.  */
 wchar_t a = 'c';
 ptrdiff_t b = 1;
 size_t c = 2;
+max_align_t x;
 
 /* Check that NULL can be passed through varargs as a pointer type,
    per POSIX 2008.  */
@@ -45,6 +46,16 @@ verify (sizeof (offsetof (struct d, e)) == sizeof (size_t));
 verify (offsetof (struct d, e) < -1); /* Must be unsigned.  */
 verify (offsetof (struct d, f) == 1);
 
+/* Check max_align_t's alignment.  */
+verify (alignof (double) <= alignof (max_align_t));
+verify (alignof (int) <= alignof (max_align_t));
+verify (alignof (long double) <= alignof (max_align_t));
+verify (alignof (long int) <= alignof (max_align_t));
+verify (alignof (ptrdiff_t) <= alignof (max_align_t));
+verify (alignof (size_t) <= alignof (max_align_t));
+verify (alignof (wchar_t) <= alignof (max_align_t));
+verify (alignof (struct d) <= alignof (max_align_t));
+
 int
 main (void)
 {