[CRIU] [PATCH v2 09/13] protobuf: show field cleanup

Kinsbursky Stanislav skinsbursky at openvz.org
Mon Aug 6 12:11:41 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Let's pass field structure to show functions. Hope, it makes the mess less
anoying...

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 protobuf.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)
-------------- next part --------------
diff --git a/protobuf.c b/protobuf.c
index 0a65fcd..50ce9af 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -34,26 +34,26 @@ struct pb_pr_ctrl_s {
 };
 
 typedef struct pb_pr_ctrl_s pb_pr_ctl_t;
-typedef void (*pb_pr_show_t)(void *obj, pb_pr_ctl_t *ctl);
+typedef void (*pb_pr_show_t)(pb_pr_field_t *field);
 
-static void pb_msg_int32x(void *obj, pb_pr_ctl_t *ctl)
+static void pb_msg_int32x(pb_pr_field_t *field)
 {
-	pr_msg("0x%08x", *(int *)obj);
+	pr_msg("0x%08x", *(int *)field->data);
 }
 
-static void pb_msg_int64x(void *obj, pb_pr_ctl_t *ctl)
+static void pb_msg_int64x(pb_pr_field_t *field)
 {
-	pr_msg("0x%016lx", *(long *)obj);
+	pr_msg("0x%016lx", *(long *)field->data);
 }
 
-static void pb_msg_string(void *obj, pb_pr_ctl_t *ctl)
+static void pb_msg_string(pb_pr_field_t *field)
 {
-	pr_msg("\"%s\"",	*(char **)obj);
+	pr_msg("\"%s\"",	*(char **)field->data);
 }
 
-static void pb_msg_unk(void *obj, pb_pr_ctl_t *ctl)
+static void pb_msg_unk(pb_pr_field_t *field)
 {
-	pr_msg("unknown object %p", obj);
+	pr_msg("unknown object %p", field->data);
 }
 
 static inline void print_tabs(pb_pr_ctl_t *ctl)
@@ -76,22 +76,25 @@ static void print_nested_message_braces(pb_pr_ctl_t *ctl, int right_brace)
 
 static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl);
 
-static void show_nested_message(void *msg, pb_pr_ctl_t *ctl)
+static void show_nested_message(pb_pr_field_t *field)
 {
+	pb_pr_ctl_t *ctl = container_of(field, pb_pr_ctl_t, cur);
+
 	print_nested_message_braces(ctl, 0);
-	ctl->cur.depth++;
-	pb_show_msg(msg, ctl);
-	ctl->cur.depth--;
+	field->depth++;
+	pb_show_msg(field->data, ctl);
+	field->depth--;
 	print_nested_message_braces(ctl, 1);
 }
 
-static void show_enum(void *msg, pb_pr_ctl_t *ctl)
+static void show_enum(pb_pr_field_t *field)
 {
+	pb_pr_ctl_t *ctl = container_of(field, pb_pr_ctl_t, cur);
 	ProtobufCEnumDescriptor *d = ctl->arg;
 	const char *val_name = NULL;
 	int val, i;
 
-	val = *(int *)msg;
+	val = *(int *)field->data;
 	for (i = 0; i < d->n_values; i++)
 		if (d->values[i].value == val) {
 			val_name = d->values[i].name;
@@ -185,12 +188,12 @@ static void do_show_field(pb_pr_ctl_t *ctl, int nr_fields, pb_pr_show_t show,
 	pb_pr_field_t *field = &ctl->cur;
 	unsigned long counter;
 
-	show(field->data, ctl);
+	show(field);
 	field->data += fsize;
 
 	for (counter = 0; counter < nr_fields - 1; counter++, field->data += fsize) {
 		pr_msg(":");
-		show(field->data, ctl);
+		show(field);
 	}
 
 	if (ctl->single_entry)


More information about the CRIU mailing list