summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rwxr-xr-xMODULES.html.sh4
-rw-r--r--doc/gnulib.texi2
-rw-r--r--doc/posix-headers/stdalign.texi32
-rw-r--r--lib/stdalign.in.h61
-rw-r--r--m4/stdalign.m437
-rw-r--r--modules/stdalign38
7 files changed, 182 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index a9a0fa0a39..9fa90a7049 100644
--- 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.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index b51e283021..ba85225871 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2320,6 +2320,10 @@ func_all_modules ()
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
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index c11bcc80de..614c91f85c 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -1187,6 +1187,7 @@ which (known) portability problems are not worked around by Gnulib.
* setjmp.h::
* signal.h::
* spawn.h::
+* stdalign.h::
* stdarg.h::
* stdbool.h::
* stddef.h::
@@ -1273,6 +1274,7 @@ which (known) portability problems are not worked around by Gnulib.
@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
diff --git a/doc/posix-headers/stdalign.texi b/doc/posix-headers/stdalign.texi
new file mode 100644
index 0000000000..af37a381a2
--- /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
diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h
new file mode 100644
index 0000000000..092dfedae6
--- /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 */
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
new file mode 100644
index 0000000000..d90cee3756
--- /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"])
+])
diff --git a/modules/stdalign b/modules/stdalign
new file mode 100644
index 0000000000..824efbbb76
--- /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