Add _DBUS_STATIC_ASSERT (based on GLib's G_STATIC_ASSERT) and use it

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39636
Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
This commit is contained in:
Simon McVittie 2011-06-21 16:19:21 +01:00
parent 70fb675a10
commit 213acdb71c
4 changed files with 12 additions and 0 deletions

View 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

View 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,

View 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 */

View 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