Source-Changes-HG archive

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

[src/trunk]: src Import <stdalign.h>



details:   https://anonhg.NetBSD.org/src/rev/081cd07fc0d3
branches:  trunk
changeset: 818191:081cd07fc0d3
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Oct 02 17:19:00 2016 +0000

description:
Import <stdalign.h>

This header conforms to the C11 standard
Reference: ISO/IEC 9899:201x 7.15 Alignment <stdalign.h>

According to ISO/IEC 9899:201x (draft) 7.15 Alignment <stdalign.h> defines
four macros:
 - alignas which expands to _Alignas
 - alignof which expands to _Alignof
 - __alignas_is_defined and __alignof_is_defined which both expand to 1

The _Alignas declaration appears as one of the type specifiers to modify
the alignment requirement of the object being declared.

The _Alignof operator is used to query the alignment requirement of its
operand type.

ISO/IEC N3242=11-0012 (C++1x) and ISO/IEC N3797 (C++1y) both note a header
<cstdalign> which defines only __alignas_is_defined and shall not define
the alignas macro. It misses the alignof case as it's probably based on an
older C1x draft, which defined only alignas. Assume that this is a bug in
the standard and treat alignof the same way as alignas in C++11.

Allow to define alignas and alignof in C++ prior the C++11 standard. It
might be broken but a nonstandard C++ compiler might support C11-like
_Alignas and _Alignof. Note that it's fatal for g++(1) v.5.4.

diffstat:

 distrib/sets/lists/comp/mi |   3 +-
 include/Makefile           |   4 +-
 include/stdalign.h         |  55 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)

diffs (94 lines):

diff -r 23998c3ec3d1 -r 081cd07fc0d3 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sun Oct 02 16:52:27 2016 +0000
+++ b/distrib/sets/lists/comp/mi        Sun Oct 02 17:19:00 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2061 2016/10/02 13:09:24 kamil Exp $
+#      $NetBSD: mi,v 1.2062 2016/10/02 17:19:00 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -2739,6 +2739,7 @@
 ./usr/include/ssp/strings.h                    comp-c-include
 ./usr/include/ssp/unistd.h                     comp-c-include
 ./usr/include/stab.h                           comp-c-include
+./usr/include/stdalign.h                       comp-c-include
 ./usr/include/stdarg.h                         comp-c-include
 ./usr/include/stdbool.h                                comp-c-include
 ./usr/include/stddef.h                         comp-c-include
diff -r 23998c3ec3d1 -r 081cd07fc0d3 include/Makefile
--- a/include/Makefile  Sun Oct 02 16:52:27 2016 +0000
+++ b/include/Makefile  Sun Oct 02 17:19:00 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.142 2016/10/02 13:09:24 kamil Exp $
+#      $NetBSD: Makefile,v 1.143 2016/10/02 17:19:00 kamil Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/4/94
 
 # Doing a make includes builds /usr/include
@@ -18,7 +18,7 @@
        ndbm.h netconfig.h netdb.h netgroup.h nlist.h nl_types.h nsswitch.h \
        paths.h pwd.h quota.h randomid.h ranlib.h re_comp.h regex.h regexp.h \
        resolv.h res_update.h rmt.h sched.h search.h semaphore.h setjmp.h \
-       string.h sgtty.h signal.h spawn.h stab.h stddef.h stdio.h \
+       string.h sgtty.h signal.h spawn.h stab.h stdalign.h stddef.h stdio.h \
        stdlib.h stdnoreturn.h strings.h stringlist.h struct.h sysexits.h \
        tar.h time.h ttyent.h tzfile.h \
        ucontext.h ulimit.h unistd.h util.h utime.h utmp.h utmpx.h uuid.h \
diff -r 23998c3ec3d1 -r 081cd07fc0d3 include/stdalign.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/stdalign.h        Sun Oct 02 17:19:00 2016 +0000
@@ -0,0 +1,55 @@
+/*     $NetBSD: stdalign.h,v 1.1 2016/10/02 17:19:00 kamil Exp $       */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Kamil Rytarowski.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _STDALIGN_H_
+#define _STDALIGN_H_
+
+/*-
+ * ISO/IEC 9899:201x 7.15 Alignment <stdalign.h>
+ * ISO/IEC N3242=11-0012 (C++1x) 18.10 Other runtime support 6.
+ * ISO/IEC N3797 (C++1y) 18.10 Other runtime support 7.
+ */
+
+#ifndef __alignas_is_defined
+#if ((__cplusplus - 0) < 201103L)
+#define alignas        _Alignas
+#endif
+#define __alignas_is_defined 1
+#endif /* __alignas_is_defined */
+
+#ifndef __alignof_is_defined
+#if ((__cplusplus - 0) < 201103L)
+#define alignof        _Alignof
+#endif
+#define __alignof_is_defined 1
+#endif /* __alignof_is_defined */
+
+#endif



Home | Main Index | Thread Index | Old Index