changeset 15994:f0478fc67be5

stdalign: new module * doc/posix-headers/stdalign.texi, lib/stdalign.in.h, m4/stdalign.m4: * modules/stdalign: New files. * MODULES.html.sh (c1x_core_properties): Add stdalign. * doc/gnulib.texi (Header File Substitutes): Add stdalign.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 16 Oct 2011 16:56:59 -0700
parents 6a9f65b7d482
children d3ffa7ff0caf
files ChangeLog MODULES.html.sh doc/gnulib.texi doc/posix-headers/stdalign.texi lib/stdalign.in.h m4/stdalign.m4 modules/stdalign
diffstat 7 files changed, 182 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-10-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+	stdalign: new module
+	* doc/posix-headers/stdalign.texi, lib/stdalign.in.h, m4/stdalign.m4:
+	* modules/stdalign: New files.
+	* MODULES.html.sh (c1x_core_properties): Add stdalign.
+	* doc/gnulib.texi (Header File Substitutes): Add stdalign.
+
 2011-10-27  Bruno Haible  <bruno@clisp.org>
 
 	raise test: Avoid a test failure on Linux/MIPS.
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2320,6 +2320,10 @@
   func_wrap H3
   func_echo "$element"
 
+  func_begin_table
+  func_module stdalign
+  func_end_table
+
   element="Support for obsolete systems lacking POSIX:2008"
   func_section_wrap posix_sup_obsolete
   func_wrap H2
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -1187,6 +1187,7 @@
 * setjmp.h::
 * signal.h::
 * spawn.h::
+* stdalign.h::
 * stdarg.h::
 * stdbool.h::
 * stddef.h::
@@ -1273,6 +1274,7 @@
 @include posix-headers/setjmp.texi
 @include posix-headers/signal.texi
 @include posix-headers/spawn.texi
+@include posix-headers/stdalign.texi
 @include posix-headers/stdarg.texi
 @include posix-headers/stdbool.texi
 @include posix-headers/stddef.texi
new file mode 100644
--- /dev/null
+++ b/doc/posix-headers/stdalign.texi
@@ -0,0 +1,32 @@
+@node stdalign.h
+@section @file{stdalign.h}
+
+POSIX specification:@* Not in POSIX yet, but we expect it will be.
+ISO C1X @url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf}
+sections 6.5.3.4, 6.7.5, 7.15.
+C++0X @url{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf}
+section 18.10.
+
+Gnulib module: stdalign
+
+Portability problems fixed by Gnulib:
+@itemize
+@item
+This header file is missing on most circa-2011 platforms.
+@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@item
+@code{_Alignas} and @code{alignas} are not always supported;
+on platforms lacking support, the
+macro @code{__alignas_is_defined} is not defined.
+Supported platforms includes GCC 2 and later, Sun C 5.11 and later,
+and MSVC 7.0 or later.
+@item
+@code{<stdalign.h>} must be #included before @samp{_Alignas} and
+@samp{_Alignof} can be used.
+@item
+You cannot assume that @code{_Alignas} and @code{_Alignof} are reserved words;
+they might be macros.
+@end itemize
new file mode 100644
--- /dev/null
+++ b/lib/stdalign.in.h
@@ -0,0 +1,61 @@
+/* A substitute for ISO C 1x <stdalign.h>.
+
+   Copyright 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Paul Eggert and Bruno Haible.  */
+
+#ifndef _GL_STDALIGN_H
+#define _GL_STDALIGN_H
+
+/* ISO C1X <stdalign.h> for platforms that lack it.
+
+   References:
+   ISO C1X <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>
+   sections 6.5.3.4, 6.7.5, 7.15.
+   C++0X <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>
+   section 18.10. */
+
+/* Return the alignment of a structure slot (field) of TYPE,
+   as an integer constant expression.  The result cannot be used as a
+   value for an 'enum' constant, if you want to be portable to HP-UX
+   10.20 cc and AIX 3.2.5 xlc.
+
+   This is not the same as GCC's __alignof__ operator; for example, on
+   x86 with GCC, _Alignof (long long) is typically 4 whereas
+   __alignof__ (long long) is 8.  */
+#include <stddef.h>
+#if defined __cplusplus
+   template <class __t> struct __alignof_helper { char __a; __t __b; };
+# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+#else
+# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+#endif
+#define alignof _Alignof
+#define __alignof_is_defined 1
+
+/* Align a type or variable to the alignment A.  */
+#if @HAVE_ATTRIBUTE_ALIGNED@ && !defined __cplusplus
+# define _Alignas(a) __attribute__ ((__aligned__ (a)))
+#elif 1300 <= _MSC_VER
+# define _Alignas(a) __declspec ((align (a)))
+#endif
+#ifdef _Alignas
+# define alignas _Alignas
+# define __alignas_is_defined 1
+#endif
+
+#endif /* _GL_STDALIGN_H */
new file mode 100644
--- /dev/null
+++ b/m4/stdalign.m4
@@ -0,0 +1,37 @@
+# Check for stdalign.h that conforms to C1x.
+
+dnl Copyright 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Prepare for substituting <stdalign.h> if it is not supported.
+
+AC_DEFUN([gl_STDALIGN_H],
+[
+  AC_CHECK_HEADERS_ONCE([stdalign.h])
+  HAVE_ATTRIBUTE_ALIGNED='?'
+
+  if test "$ac_cv_header_stdalign_h" = yes; then
+    STDALIGN_H=''
+  else
+    STDALIGN_H='stdalign.h'
+    AC_CACHE_CHECK([for  __attribute__ ((__aligned__ (expr)))],
+      [gl_cv_attribute_aligned],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[char __attribute__ ((__aligned__ (1 << 3))) c;]],
+            [[]])],
+         [gl_cv_attribute_aligned=yes],
+         [gl_cv_attribute_aligned=no])])
+    if test $gl_cv_attribute_aligned = yes; then
+      HAVE_ATTRIBUTE_ALIGNED=1
+    else
+      HAVE_ATTRIBUTE_ALIGNED=0
+    fi
+  fi
+
+  AC_SUBST([HAVE_ATTRIBUTE_ALIGNED])
+  AC_SUBST([STDALIGN_H])
+  AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"])
+])
new file mode 100644
--- /dev/null
+++ b/modules/stdalign
@@ -0,0 +1,38 @@
+Description:
+A <stdalign.h> that nearly conforms to ISO C1X and C++0X.
+
+Files:
+lib/stdalign.in.h
+m4/stdalign.m4
+
+Depends-on:
+
+configure.ac:
+gl_STDALIGN_H
+
+Makefile.am:
+BUILT_SOURCES += $(STDALIGN_H)
+
+# We need the following in order to create <stdalign.h> when the system
+# doesn't have one that works.
+if GL_GENERATE_STDALIGN_H
+stdalign.h: stdalign.in.h $(top_builddir)/config.status
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's/@''HAVE_ATTRIBUTE_ALIGNED''@/$(HAVE_ATTRIBUTE_ALIGNED)/g' < $(srcdir)/stdalign.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+else
+stdalign.h: $(top_builddir)/config.status
+	rm -f $@
+endif
+MOSTLYCLEANFILES += stdalign.h stdalign.h-t
+
+Include:
+<stdalign.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Paul Eggert, Bruno Haible