diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 2c4336773b3d8067206ee072d4f757a4484c2049..3e578eb50530039c4a859ae98b8bfa93dfa3efe5 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -177,6 +177,35 @@ * Unlocks a global lock */ +/* The build system should have checked for DBUS_SIZEOF_VOID_P */ +_DBUS_STATIC_ASSERT (sizeof (void *) == DBUS_SIZEOF_VOID_P); + +/* dbus currently assumes that function pointers are essentially + * interchangeable with data pointers. There's nothing special about + * DBusShutdownFunction, it's just an arbitrary function pointer type. + * If this assertion fails on your platform, some porting will be required. */ +_DBUS_STATIC_ASSERT (sizeof (void *) == sizeof (DBusShutdownFunction)); +_DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (void *) == _DBUS_ALIGNOF (DBusShutdownFunction)); + +/* This is meant to be true by definition. */ +_DBUS_STATIC_ASSERT (sizeof (void *) == sizeof (intptr_t)); +_DBUS_STATIC_ASSERT (sizeof (void *) == sizeof (uintptr_t)); + +/* + * Some frequent assumptions that we should *avoid* making include these, + * all of which are false on CHERI (which has 128-bit tagged pointers, + * but a 64-bit address space and therefore 64-bit sizes): + * + * sizeof (void *) <= sizeof (size_t) + * sizeof (void *) <= 8 + * _DBUS_ALIGNOF (void *) <= 8 + * + * We should also avoid making these assumptions, although we don't currently + * know a concrete example of platforms where they're false: + * + * sizeof (ptrdiff_t) == sizeof (size_t) + */ + /** * Fixed "out of memory" error message, just to avoid * making up a different string every time and wasting diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index 938e29230d2c963ea6a061b3d322e6d8f94ba2b4..1f5d54a4eedc5505f9ce544d2efc43663be9ec25 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -30,19 +30,10 @@ #include -#if defined(__GNUC__) && (__GNUC__ >= 4) -# define _DBUS_ASSERT_ALIGNMENT(type, op, val) \ - _DBUS_STATIC_ASSERT (__extension__ __alignof__ (type) op val) -# define _DBUS_ASSERT_CMP_ALIGNMENT(left, op, right) \ - _DBUS_STATIC_ASSERT (__extension__ __alignof__ (left) op __extension__ __alignof__ (right)) -#else - /* not gcc, so probably no alignof operator: just use a no-op statement - * that's valid in the same contexts */ -# define _DBUS_ASSERT_ALIGNMENT(type, op, val) \ - _DBUS_STATIC_ASSERT (TRUE) -# define _DBUS_ASSERT_CMP_ALIGNMENT(left, op, right) \ - _DBUS_STATIC_ASSERT (TRUE) -#endif +#define _DBUS_ASSERT_ALIGNMENT(type, op, val) \ + _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (type) op val) +#define _DBUS_ASSERT_CMP_ALIGNMENT(left, op, right) \ + _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (left) op _DBUS_ALIGNOF (right)) /* True by definition, but just for completeness... */ _DBUS_STATIC_ASSERT (sizeof (char) == 1);