Source-Changes-HG archive

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

[src/trunk]: src/lib/libc Don't overalign _RuneStatePriv, it must share the a...



details:   https://anonhg.NetBSD.org/src/rev/f4d3c2f66e53
branches:  trunk
changeset: 972659:f4d3c2f66e53
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Jun 02 01:30:31 2020 +0000

description:
Don't overalign _RuneStatePriv, it must share the alignment of mbstate_t
it aliased with. Assert that the alignment actually used reflects the
alignment required by existing implementation and for newly build
modules assert that it is at most the guaranteed alignment.

diffstat:

 lib/libc/citrus/citrus_ctype_template.h |   7 ++++++-
 lib/libc/locale/multibyte.h             |  15 +++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diffs (80 lines):

diff -r fe421cdafb62 -r f4d3c2f66e53 lib/libc/citrus/citrus_ctype_template.h
--- a/lib/libc/citrus/citrus_ctype_template.h   Tue Jun 02 00:29:53 2020 +0000
+++ b/lib/libc/citrus/citrus_ctype_template.h   Tue Jun 02 01:30:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: citrus_ctype_template.h,v 1.37 2019/07/28 14:26:08 christos Exp $      */
+/*     $NetBSD: citrus_ctype_template.h,v 1.38 2020/06/02 01:30:31 joerg Exp $ */
 
 /*-
  * Copyright (c)2002 Citrus Project,
@@ -118,6 +118,7 @@
  *
  */
 
+#include <stdalign.h>
 
 /* prototypes */
 
@@ -506,6 +507,10 @@
        return (0);
 }
 
+/* Ensure alignment matches guarantees from locale/multibyte.h */
+__CTASSERT(alignof(_ENCODING_STATE) <= alignof(int) ||
+           alignof(_ENCODING_STATE) <= alignof(void *));
+
 static int
 _FUNCNAME(ctype_init)(void ** __restrict cl,
                      void * __restrict var, size_t lenvar, size_t lenps)
diff -r fe421cdafb62 -r f4d3c2f66e53 lib/libc/locale/multibyte.h
--- a/lib/libc/locale/multibyte.h       Tue Jun 02 00:29:53 2020 +0000
+++ b/lib/libc/locale/multibyte.h       Tue Jun 02 01:30:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: multibyte.h,v 1.6 2013/08/18 20:03:48 joerg Exp $      */
+/*     $NetBSD: multibyte.h,v 1.7 2020/06/02 01:30:31 joerg Exp $      */
 
 /*-
  * Copyright (c)2002 Citrus Project,
@@ -29,6 +29,8 @@
 #ifndef _MULTIBYTE_H_
 #define _MULTIBYTE_H_
 
+#include <stdalign.h>
+
 /* mbstate_t private */
 
 #ifdef _BSD_MBSTATE_T_
@@ -38,9 +40,14 @@
 
 typedef struct _RuneStatePriv {
        _RuneLocale     *__runelocale;
-       char            __private __attribute__((__aligned__));
+       char            __private[];
 } _RuneStatePriv;
 
+__CTASSERT(alignof(struct _RuneStatePriv) >= alignof(void *));
+__CTASSERT(sizeof(_RuneStatePriv) % alignof(void *) == 0);
+__CTASSERT(alignof(struct _RuneStatePriv) >= alignof(int));
+__CTASSERT(sizeof(_RuneStatePriv) % alignof(int) == 0);
+
 typedef union _RuneState {
        mbstate_t               __pad;
        struct _RuneStatePriv   __priv;
@@ -91,7 +98,7 @@
 {
        if (ps == NULL)
                return NULL;
-       return (void *)&_ps_to_runestate(ps)->rs_private;
+       return _ps_to_runestate(ps)->rs_private;
 }
 
 static __inline void const *
@@ -99,7 +106,7 @@
 {
        if (ps == NULL)
                return NULL;
-       return (void const *)&_ps_to_runestate_const(ps)->rs_private;
+       return _ps_to_runestate_const(ps)->rs_private;
 }
 
 static __inline void



Home | Main Index | Thread Index | Old Index