#include #include #include typedef struct DBusMessage DBusMessage; typedef struct DBusMessageIter DBusMessageIter; typedef struct DBusString DBusString; typedef struct DBusMessageRealIter DBusMessageRealIter; typedef struct DBusTypeReaderClass DBusTypeReaderClass; typedef struct DBusTypeReader DBusTypeReader; typedef struct DBusTypeWriter DBusTypeWriter; typedef uint32_t dbus_uint32_t; #define CHANGED_STAMP_BITS 21 /** * DBusMessageIter struct; contains no public fields. */ struct DBusMessageIter { void *dummy1; /**< Don't use this */ void *dummy2; /**< Don't use this */ dbus_uint32_t dummy3; /**< Don't use this */ int dummy4; /**< Don't use this */ int dummy5; /**< Don't use this */ int dummy6; /**< Don't use this */ int dummy7; /**< Don't use this */ int dummy8; /**< Don't use this */ int dummy9; /**< Don't use this */ int dummy10; /**< Don't use this */ int dummy11; /**< Don't use this */ int pad1; /**< Don't use this */ int pad2; /**< Don't use this */ void *pad3; /**< Don't use this */ }; struct DBusTypeReader { union { struct { dbus_uint32_t byte_order : 8; /**< byte order of the block */ dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases * where we don't have another way to tell */ dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */ } bitfields; dbus_uint32_t space; } bitfields; const DBusString *type_str; /**< string containing signature of block */ int type_pos; /**< current position in signature */ const DBusString *value_str; /**< string containing values of block */ int value_pos; /**< current position in values */ const DBusTypeReaderClass *klass; /**< the vtable for the reader */ union { struct { int start_pos; /**< for array readers, the start of the array values */ } array; } u; /**< class-specific data */ }; /** * The type writer is an iterator for writing to a block of values. */ struct DBusTypeWriter { union { struct { dbus_uint32_t byte_order : 8; /**< byte order to write values with */ dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */ dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */ dbus_uint32_t enabled : 1; /**< whether to write values */ } bitfields; dbus_uint32_t space; } bitfields; DBusString *type_str; /**< where to write typecodes (or read type expectations) */ int type_pos; /**< current pos in type_str */ DBusString *value_str; /**< where to write values */ int value_pos; /**< next position to write */ union { struct { int start_pos; /**< position of first element in the array */ int len_pos; /**< position of length of the array */ int element_type_pos; /**< position of array element type in type_str */ } array; } u; /**< class-specific data */ }; struct DBusMessageRealIter { DBusMessage *message; /**< Message used */ union { struct { dbus_uint32_t changed_stamp : CHANGED_STAMP_BITS; /**< stamp to detect invalid iters */ dbus_uint32_t iter_type : 3; /**< whether this is a reader or writer iter */ dbus_uint32_t sig_refcount : 8; /**< depth of open_signature() */ } bitfields; dbus_uint32_t space; } bitfields; union { DBusTypeWriter writer; /**< writer */ DBusTypeReader reader; /**< reader */ } u; /**< the type writer or reader that does all the work */ }; #define stringify(member) #define MEMBER(structure, member) \ printf ("%zu-%zu %s\n", __builtin_offsetof (structure, member), \ __builtin_offsetof (structure, member) + sizeof (((structure *) NULL)->member) - 1,\ #member) int main (void) { printf ("placeholder:\n"); MEMBER (DBusMessageIter, dummy1); MEMBER (DBusMessageIter, dummy2); MEMBER (DBusMessageIter, dummy3); MEMBER (DBusMessageIter, dummy4); MEMBER (DBusMessageIter, dummy5); MEMBER (DBusMessageIter, dummy6); MEMBER (DBusMessageIter, dummy7); MEMBER (DBusMessageIter, dummy8); MEMBER (DBusMessageIter, dummy9); MEMBER (DBusMessageIter, dummy10); MEMBER (DBusMessageIter, dummy11); MEMBER (DBusMessageIter, pad1); MEMBER (DBusMessageIter, pad2); MEMBER (DBusMessageIter, pad3); printf ("size: %zu\n", sizeof (DBusMessageIter)); printf ("\n"); printf ("reader:\n"); MEMBER (DBusMessageRealIter, message); MEMBER (DBusMessageRealIter, bitfields.space); MEMBER (DBusMessageRealIter, u.reader.bitfields.space); MEMBER (DBusMessageRealIter, u.reader.type_str); MEMBER (DBusMessageRealIter, u.reader.type_pos); MEMBER (DBusMessageRealIter, u.reader.value_str); MEMBER (DBusMessageRealIter, u.reader.value_pos); MEMBER (DBusMessageRealIter, u.reader.klass); MEMBER (DBusMessageRealIter, u.reader.u.array.start_pos); printf ("size: %zu\n", sizeof (DBusMessageRealIter)); printf ("\n"); printf ("writer:\n"); MEMBER (DBusMessageRealIter, message); MEMBER (DBusMessageRealIter, bitfields.space); MEMBER (DBusMessageRealIter, u.writer.bitfields.space); MEMBER (DBusMessageRealIter, u.writer.type_str); MEMBER (DBusMessageRealIter, u.writer.type_pos); MEMBER (DBusMessageRealIter, u.writer.value_str); MEMBER (DBusMessageRealIter, u.writer.value_pos); MEMBER (DBusMessageRealIter, u.writer.u.array.start_pos); MEMBER (DBusMessageRealIter, u.writer.u.array.len_pos); MEMBER (DBusMessageRealIter, u.writer.u.array.element_type_pos); printf ("size: %zu\n", sizeof (DBusMessageRealIter)); printf ("\n"); return 0; }