[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v10 07/13] qapi-visit: Less indirection in visit_typ
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v10 07/13] qapi-visit: Less indirection in visit_type_Foo_fields() |
Date: |
Mon, 15 Feb 2016 17:20:51 -0700 |
We were passing 'Foo **obj' to the internal helper function, but
all uses within the helper were via reads of '*obj'. Refactor
things to pass one less level of indirection, by having the
callers dereference before calling.
For an example of the generated code change:
|-static void visit_type_BalloonInfo_fields(Visitor *v, BalloonInfo **obj,
Error **errp)
|+static void visit_type_BalloonInfo_fields(Visitor *v, BalloonInfo *obj, Error
**errp)
| {
| Error *err = NULL;
|
|- visit_type_int(v, "actual", &(*obj)->actual, &err);
|+ visit_type_int(v, "actual", &obj->actual, &err);
| error_propagate(errp, err);
| }
|
|@@ -261,7 +261,7 @@ void visit_type_BalloonInfo(Visitor *v,
| if (!*obj) {
| goto out_obj;
| }
|- visit_type_BalloonInfo_fields(v, obj, &err);
|+ visit_type_BalloonInfo_fields(v, *obj, &err);
| out_obj:
The refactoring will also make it easier to reuse the helpers in
a future patch when implicit structs are stored directly in the
parent struct rather than boxed through a pointer.
Signed-off-by: Eric Blake <address@hidden>
---
v10: new patch
---
scripts/qapi-visit.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 786fe57..177dfc4 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -39,7 +39,7 @@ def gen_visit_fields_decl(typ):
if typ.name not in struct_fields_seen:
ret += mcgen('''
-static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s **obj, Error
**errp);
+static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error
**errp);
''',
c_type=typ.c_name())
struct_fields_seen.add(typ.name)
@@ -61,7 +61,7 @@ static void visit_type_implicit_%(c_type)s(Visitor *v,
%(c_type)s **obj, Error *
visit_start_implicit_struct(v, (void **)obj, sizeof(%(c_type)s), &err);
if (!err) {
- visit_type_%(c_type)s_fields(v, obj, errp);
+ visit_type_%(c_type)s_fields(v, *obj, errp);
visit_end_implicit_struct(v);
}
error_propagate(errp, err);
@@ -80,7 +80,7 @@ def gen_visit_struct_fields(name, base, members):
struct_fields_seen.add(name)
ret += mcgen('''
-static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error
**errp)
+static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error
**errp)
{
Error *err = NULL;
@@ -89,13 +89,13 @@ static void visit_type_%(c_name)s_fields(Visitor *v,
%(c_name)s **obj, Error **e
if base:
ret += mcgen('''
- visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err);
+ visit_type_%(c_type)s_fields(v, (%(c_type)s *)obj, &err);
''',
c_type=base.c_name())
if members:
ret += gen_err_check()
- ret += gen_visit_fields(members, prefix='(*obj)->', skiplast=True)
+ ret += gen_visit_fields(members, prefix='obj->', skiplast=True)
# 'goto out' produced for base, and by gen_visit_fields() for each
# member except the last
@@ -232,7 +232,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name,
%(c_name)s **obj, Error
if (!*obj) {
goto out_obj;
}
- visit_type_%(c_name)s_fields(v, obj, &err);
+ visit_type_%(c_name)s_fields(v, *obj, &err);
''',
c_name=c_name(name))
if variants:
--
2.5.0
- [Qemu-devel] [PATCH v10 00/13] prune some QAPI visitor cruft (was qapi cleanups subset E), Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 04/13] qapi: Drop pointless gotos in generated code, Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 03/13] qapi: Reposition error checks in gen_visit_fields(), Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 06/13] qapi-visit: Unify struct and union visit, Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 07/13] qapi-visit: Less indirection in visit_type_Foo_fields(),
Eric Blake <=
- [Qemu-devel] [PATCH v10 05/13] qapi-visit: Simplify how we visit common union members, Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 01/13] qapi: Simplify excess input reporting in input visitors, Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 02/13] qapi: Forbid empty unions and useless alternates, Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 08/13] qapi: Adjust layout of FooList types, Eric Blake, 2016/02/15
- [Qemu-devel] [PATCH v10 10/13] qapi: Don't box struct branch of alternate, Eric Blake, 2016/02/15