From: Paul Eggert Date: Sun, 16 Oct 2011 23:56:59 +0000 (-0700) Subject: stdalign: new module X-Git-Tag: v0.1~1532 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=6dc2ffa573d23caeeb62c4ba3b9a630a1261e35d;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index a9a0fa0a3..9fa90a704 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-27 Paul Eggert + + 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 raise test: Avoid a test failure on Linux/MIPS. diff --git a/MODULES.html.sh b/MODULES.html.sh index b51e28302..ba8522587 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 c11bcc80d..614c91f85 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 000000000..af37a381a --- /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{} 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 000000000..092dfedae --- /dev/null +++ b/lib/stdalign.in.h @@ -0,0 +1,61 @@ +/* A substitute for ISO C 1x . + + 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 for platforms that lack it. + + References: + ISO C1X + sections 6.5.3.4, 6.7.5, 7.15. + C++0X + 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 +#if defined __cplusplus + template struct __alignof_helper { char __a; __t __b; }; +# define _Alignof(type) offsetof (__alignof_helper, __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 000000000..d90cee375 --- /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 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 000000000..824efbbb7 --- /dev/null +++ b/modules/stdalign @@ -0,0 +1,38 @@ +Description: +A 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 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: + + +License: +LGPLv2+ + +Maintainer: +Paul Eggert, Bruno Haible