Add _DBUS_STATIC_ASSERT (based on GLib's G_STATIC_ASSERT) and use it
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 21 Jun 2011 15:19:21 +0000 (16:19 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 11 Aug 2011 10:51:43 +0000 (11:51 +0100)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39636
Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
dbus/dbus-errors.c
dbus/dbus-hash.c
dbus/dbus-internals.h
dbus/dbus-string-private.h

index 5f27501..db3305b 100644 (file)
@@ -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
index 67ef4ce..b104f32 100644 (file)
@@ -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,
index dcef7d7..06e6c16 100644 (file)
@@ -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 */
index 365d89a..b17c2b9 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef DBUS_STRING_PRIVATE_H
 #define DBUS_STRING_PRIVATE_H
 
+#include <dbus/dbus-internals.h>
 #include <dbus/dbus-memory.h>
 #include <dbus/dbus-types.h>
 
@@ -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