From: Vincent Bernat Date: Sat, 21 Jan 2012 20:31:52 +0000 (+0100) Subject: marshal: use shorter macro names X-Git-Tag: 0.6.0~68 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e73393be53d34655691f087bc94dabffe25da74;p=thirdparty%2Flldpd.git marshal: use shorter macro names --- diff --git a/src/marshal.h b/src/marshal.h index 1b988a6c..55e0a095 100644 --- a/src/marshal.h +++ b/src/marshal.h @@ -37,7 +37,7 @@ struct marshal_info { /* 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), \ @@ -46,27 +46,26 @@ struct marshal_info { { .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 *); diff --git a/tests/check_marshal.c b/tests/check_marshal.c index e00cc207..49e322f8 100644 --- a/tests/check_marshal.c +++ b/tests/check_marshal.c @@ -13,7 +13,7 @@ struct struct_simple { time_t a4; char a5[7]; }; -MARSHAL_DECLARE(struct_simple); +MARSHAL(struct_simple); START_TEST(test_simple_structure) { struct struct_simple source = { @@ -54,9 +54,9 @@ struct struct_sub { 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 = { @@ -106,9 +106,9 @@ struct struct_onepointer { 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 = { @@ -164,10 +164,10 @@ struct struct_nestedpointers { 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 = { @@ -290,11 +290,11 @@ struct struct_multipleref { 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 = { @@ -345,9 +345,9 @@ struct struct_circularref { 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 = { @@ -414,13 +414,13 @@ struct struct_simpleentry { 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 = { @@ -497,9 +497,9 @@ struct struct_withlist { 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 = {