bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/5] stdalign: new module


From: Paul Eggert
Subject: [PATCH 1/5] stdalign: new module
Date: Sun, 16 Oct 2011 17:27:28 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15

A while ago Bruno drafted a Gnulib module that is a replacement for C1x.
This turns out to be useful for Emacs, so I've fleshed it out and used it in
an experimental version of Emacs.  Here's a proposed patch to add this
to Gnulib.  There are four followup patches, one to create a test module for
it, and the others to use it in other parts of Gnulib.

I have not tested this on Microsoft platforms, though there is a Microsoft
hook in there.  If that hook doesn't work we can easily remove it.

* 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.
---
 ChangeLog                       |    8 +++++
 MODULES.html.sh                 |    4 ++
 doc/gnulib.texi                 |    2 +
 doc/posix-headers/stdalign.texi |   32 ++++++++++++++++++++
 lib/stdalign.in.h               |   61 +++++++++++++++++++++++++++++++++++++++
 m4/stdalign.m4                  |   37 +++++++++++++++++++++++
 modules/stdalign                |   38 ++++++++++++++++++++++++
 7 files changed, 182 insertions(+), 0 deletions(-)
 create mode 100644 doc/posix-headers/stdalign.texi
 create mode 100644 lib/stdalign.in.h
 create mode 100644 m4/stdalign.m4
 create mode 100644 modules/stdalign

diff --git a/ChangeLog b/ChangeLog
index 28133a6..b3b3034 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-10-16  Paul Eggert  <address@hidden>
+
+       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-15  Bruno Haible  <address@hidden>
 
        xstrtoll: Fix compilation failure.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index f84d3b1..34ce6d5 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 c11bcc8..614c91f 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
address@hidden 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 0000000..af37a38
--- /dev/null
+++ b/doc/posix-headers/stdalign.texi
@@ -0,0 +1,32 @@
address@hidden stdalign.h
address@hidden @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:
address@hidden
address@hidden
+This header file is missing on most circa-2011 platforms.
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
address@hidden
address@hidden 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.
address@hidden
address@hidden<stdalign.h>} must be #included before @samp{_Alignas} and
address@hidden can be used.
address@hidden
+You cannot assume that @code{_Alignas} and @code{_Alignof} are reserved words;
+they might be macros.
address@hidden itemize
diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h
new file mode 100644
index 0000000..092dfed
--- /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 0000000..d90cee3
--- /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 0000000..824efbb
--- /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 address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's/@''HAVE_ATTRIBUTE_ALIGNED''@/$(HAVE_ATTRIBUTE_ALIGNED)/g' < 
$(srcdir)/stdalign.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+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
-- 
1.7.4.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]