/* Declare a new marshal_info struct named after the type we want to
marshal. The marshalled type has to be a structure. */
-#define MARSHAL_DECLARE_BEGIN(type) struct marshal_info marshal_info_##type = \
+#define MARSHAL_BEGIN(type) struct marshal_info marshal_info_##type = \
{ \
.name = #type, \
.size = sizeof(struct type), \
{ .offset = offsetof(struct type, member), \
.kind = _kind, \
.mi = &marshal_info_##subtype },
-#define MARSHAL_ADD_POINTER(...) MARSHAL_ADD(pointer, ##__VA_ARGS__)
-#define MARSHAL_ADD_SUBSTRUCT(...) MARSHAL_ADD(substruct, ##__VA_ARGS__)
-#define MARSHAL_ADD_TQE(type, field) \
- MARSHAL_ADD_POINTER(type, type, field.tqe_next) \
- MARSHAL_ADD_POINTER(type, type, field.tqe_prev)
-#define MARSHAL_ADD_TQH(type, subtype) \
- MARSHAL_ADD_POINTER(type, subtype, tqh_first) \
- MARSHAL_ADD_POINTER(type, subtype, tqh_last)
-#define MARSHAL_ADD_SUBTQ(type, subtype,field) \
- MARSHAL_ADD_POINTER(type, subtype, field.tqh_first) \
- MARSHAL_ADD_POINTER(type, subtype, field.tqh_last)
-#define MARSHAL_DECLARE_END(type) \
- { .mi = NULL } } }
+#define MARSHAL_POINTER(...) MARSHAL_ADD(pointer, ##__VA_ARGS__)
+#define MARSHAL_SUBSTRUCT(...) MARSHAL_ADD(substruct, ##__VA_ARGS__)
+#define MARSHAL_TQE(type, field) \
+ MARSHAL_POINTER(type, type, field.tqe_next) \
+ MARSHAL_POINTER(type, type, field.tqe_prev)
+#define MARSHAL_TQH(type, subtype) \
+ MARSHAL_POINTER(type, subtype, tqh_first) \
+ MARSHAL_POINTER(type, subtype, tqh_last)
+#define MARSHAL_SUBTQ(type, subtype, field) \
+ MARSHAL_POINTER(type, subtype, field.tqh_first) \
+ MARSHAL_POINTER(type, subtype, field.tqh_last)
+#define MARSHAL_END { .mi = NULL } } }
/* Shortcuts */
-#define MARSHAL_DECLARE(type) \
- MARSHAL_DECLARE_BEGIN(type) \
- MARSHAL_DECLARE_END(type)
-#define MARSHAL_DECLARE_TQ(type, subtype) \
- MARSHAL_DECLARE_BEGIN(type) \
- MARSHAL_ADD_TQH(type, subtype) \
- MARSHAL_DECLARE_END(type)
+#define MARSHAL(type) \
+ MARSHAL_BEGIN(type) \
+ MARSHAL_END
+#define MARSHAL_TQ(type, subtype) \
+ MARSHAL_BEGIN(type) \
+ MARSHAL_TQH(type, subtype) \
+ MARSHAL_END
/* Serialization */
size_t _marshal_serialize(struct marshal_info *, void *, void **, int, void *);
time_t a4;
char a5[7];
};
-MARSHAL_DECLARE(struct_simple);
+MARSHAL(struct_simple);
START_TEST(test_simple_structure) {
struct struct_simple source = {
struct struct_simple e2;
char e3;
};
-MARSHAL_DECLARE_BEGIN(struct_sub)
-MARSHAL_ADD_SUBSTRUCT(struct_sub, struct_simple, e2)
-MARSHAL_DECLARE_END(struct_sub);
+MARSHAL_BEGIN(struct_sub)
+MARSHAL_SUBSTRUCT(struct_sub, struct_simple, e2)
+MARSHAL_END;
START_TEST(test_substruct_structure) {
struct struct_sub source = {
struct struct_simple *b4;
int b5;
};
-MARSHAL_DECLARE_BEGIN(struct_onepointer)
-MARSHAL_ADD_POINTER(struct_onepointer, struct_simple, b4)
-MARSHAL_DECLARE_END(struct_onepointer);
+MARSHAL_BEGIN(struct_onepointer)
+MARSHAL_POINTER(struct_onepointer, struct_simple, b4)
+MARSHAL_END;
START_TEST(test_pointer_structure) {
struct struct_simple source_simple = {
struct struct_onepointer *c4;
int c5;
};
-MARSHAL_DECLARE_BEGIN(struct_nestedpointers)
-MARSHAL_ADD_POINTER(struct_nestedpointers, struct_simple, c3)
-MARSHAL_ADD_POINTER(struct_nestedpointers, struct_onepointer, c4)
-MARSHAL_DECLARE_END(struct_nestedpointers);
+MARSHAL_BEGIN(struct_nestedpointers)
+MARSHAL_POINTER(struct_nestedpointers, struct_simple, c3)
+MARSHAL_POINTER(struct_nestedpointers, struct_onepointer, c4)
+MARSHAL_END;
START_TEST(test_several_pointers_structure) {
struct struct_simple source_simple1 = {
struct struct_simple* f3;
struct struct_nestedpointers* f4;
};
-MARSHAL_DECLARE_BEGIN(struct_multipleref)
-MARSHAL_ADD_POINTER(struct_multipleref, struct_simple, f2)
-MARSHAL_ADD_POINTER(struct_multipleref, struct_simple, f3)
-MARSHAL_ADD_POINTER(struct_multipleref, struct_nestedpointers, f4)
-MARSHAL_DECLARE_END(struct_multipleref);
+MARSHAL_BEGIN(struct_multipleref)
+MARSHAL_POINTER(struct_multipleref, struct_simple, f2)
+MARSHAL_POINTER(struct_multipleref, struct_simple, f3)
+MARSHAL_POINTER(struct_multipleref, struct_nestedpointers, f4)
+MARSHAL_END;
START_TEST(test_multiple_references) {
struct struct_simple source_simple = {
int g1;
struct struct_circularref* g2;
};
-MARSHAL_DECLARE_BEGIN(struct_circularref)
-MARSHAL_ADD_POINTER(struct_circularref, struct_circularref, g2)
-MARSHAL_DECLARE_END(struct_circularref);
+MARSHAL_BEGIN(struct_circularref)
+MARSHAL_POINTER(struct_circularref, struct_circularref, g2)
+MARSHAL_END;
START_TEST(test_circular_references) {
struct struct_circularref source = {
int g1;
struct struct_simple *g2;
};
-MARSHAL_DECLARE_BEGIN(struct_simpleentry)
-MARSHAL_ADD_TQE(struct_simpleentry, s_entries)
-MARSHAL_ADD_POINTER(struct_simpleentry, struct_simple, g2)
-MARSHAL_DECLARE_END(struct_simpleentry);
+MARSHAL_BEGIN(struct_simpleentry)
+MARSHAL_TQE(struct_simpleentry, s_entries)
+MARSHAL_POINTER(struct_simpleentry, struct_simple, g2)
+MARSHAL_END;
TAILQ_HEAD(list_simple, struct_simpleentry);
-MARSHAL_DECLARE_TQ(list_simple, struct_simpleentry);
+MARSHAL_TQ(list_simple, struct_simpleentry);
START_TEST(test_simple_list) {
struct struct_simple source_simple = {
TAILQ_HEAD(, struct_simpleentry) i2;
int i3;
};
-MARSHAL_DECLARE_BEGIN(struct_withlist)
-MARSHAL_ADD_SUBTQ(struct_withlist, struct_simpleentry, i2)
-MARSHAL_DECLARE_END(struct_withlist);
+MARSHAL_BEGIN(struct_withlist)
+MARSHAL_SUBTQ(struct_withlist, struct_simpleentry, i2)
+MARSHAL_END;
START_TEST(test_embedded_list) {
struct struct_withlist source = {