From 074163a98369876ee182d787705ba47d2ef37cad Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 21 Jun 2011 16:19:21 +0100 Subject: [PATCH 1/2] Add _DBUS_STATIC_ASSERT (based on GLib's G_STATIC_ASSERT) and use it Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39636 --- dbus/dbus-errors.c | 2 ++ dbus/dbus-hash.c | 2 ++ dbus/dbus-internals.h | 6 ++++++ dbus/dbus-string-private.h | 2 ++ 4 files changed, 12 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-errors.c b/dbus/dbus-errors.c index 5f27501..db3305b 100644 --- a/dbus/dbus-errors.c +++ b/dbus/dbus-errors.c @@ -78,6 +78,8 @@ typedef struct } DBusRealError; +_DBUS_STATIC_ASSERT (sizeof (DBusRealError) == sizeof (DBusError)); + /** * Returns a longer message describing an error name. * If the error name is unknown, returns the name diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c index 67ef4ce..b104f32 100644 --- a/dbus/dbus-hash.c +++ b/dbus/dbus-hash.c @@ -222,6 +222,8 @@ typedef struct int n_entries_on_init; /**< used to detect table resize since initialization */ } DBusRealHashIter; +_DBUS_STATIC_ASSERT (sizeof (DBusRealHashIter) == sizeof (DBusHashIter)); + static DBusHashEntry* find_direct_function (DBusHashTable *table, void *key, dbus_bool_t create_if_not_found, diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index dcef7d7..06e6c16 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -362,6 +362,12 @@ dbus_bool_t _dbus_read_uuid_file (const DBusString *filename, dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str); +#define _DBUS_PASTE2(a, b) a ## b +#define _DBUS_PASTE(a, b) _DBUS_PASTE2 (a, b) +#define _DBUS_STATIC_ASSERT(expr) \ + typedef struct { char _assertion[(expr) ? 1 : -1]; } \ + _DBUS_PASTE (_DBUS_STATIC_ASSERT_, __LINE__) + DBUS_END_DECLS #endif /* DBUS_INTERNALS_H */ diff --git a/dbus/dbus-string-private.h b/dbus/dbus-string-private.h index 365d89a..b17c2b9 100644 --- a/dbus/dbus-string-private.h +++ b/dbus/dbus-string-private.h @@ -24,6 +24,7 @@ #ifndef DBUS_STRING_PRIVATE_H #define DBUS_STRING_PRIVATE_H +#include #include #include @@ -51,6 +52,7 @@ typedef struct unsigned int align_offset : 3; /**< str - align_offset is the actual malloc block */ } DBusRealString; +_DBUS_STATIC_ASSERT (sizeof (DBusRealString) == sizeof (DBusString)); /** * @defgroup DBusStringInternals DBusString implementation details -- 1.7.5.4