]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
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 5f27501cbc29d5d0ff2449f6470852b57fae36d4..db3305b930be47bc46448e8356ef946b624d5e90 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 67ef4ced735f14b0b5f6c84c0aa343def126c920..b104f32f43095b456377b3c1303ffbcc63d4a446 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 dcef7d7ff327887b67d32a743a9c7b8a3029a8ef..06e6c16b0d3334bafec6bc3117d0f81ce296e07d 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 365d89a3fc6ab267310e55433a742514f966fce9..b17c2b9f367251f89002fce947fb89dd853112a9 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