diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-09-16 13:06:17 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-09-21 09:56:48 +0200 |
commit | 60f8546acd113e636bf2ba8af991ebe0f6e8ad66 (patch) | |
tree | 99e82f2fbe4935cf3f7c4a4bcff04c207833729a /scripts/qapi-visit.py | |
parent | e98859a9b96d71dea8f9af43325edd43c7effe66 (diff) |
qapi-visit: Rearrange code a bit
Move gen_visit_decl() to a better place. Inline
generate_visit_struct_body().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1442401589-24189-15-git-send-email-armbru@redhat.com>
Diffstat (limited to 'scripts/qapi-visit.py')
-rw-r--r-- | scripts/qapi-visit.py | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index fae70e2d24..97343cf7e9 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -19,6 +19,16 @@ implicit_structs_seen = set() struct_fields_seen = set() +def gen_visit_decl(name, scalar=False): + c_type = c_name(name) + ' *' + if not scalar: + c_type += '*' + return mcgen(''' +void visit_type_%(c_name)s(Visitor *m, %(c_type)sobj, const char *name, Error **errp); +''', + c_name=c_name(name), c_type=c_type) + + def gen_visit_implicit_struct(typ): if typ in implicit_structs_seen: return '' @@ -117,12 +127,17 @@ out: return ret -def gen_visit_struct_body(name): +def gen_visit_struct(name, base, members): + ret = gen_visit_struct_fields(name, base, members) + # FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to # *obj, but then visit_type_FOO_fields() fails, we should clean up *obj # rather than leaving it non-NULL. As currently written, the caller must # call qapi_free_FOO() to avoid a memory leak of the partial FOO. - ret = mcgen(''' + ret += mcgen(''' + +void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error **errp) +{ Error *err = NULL; visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err); @@ -133,25 +148,10 @@ def gen_visit_struct_body(name): visit_end_struct(m, &err); } error_propagate(errp, err); +} ''', - name=name, c_name=c_name(name)) - return ret - - -def gen_visit_struct(name, base, members): - ret = gen_visit_struct_fields(name, base, members) - ret += mcgen(''' - -void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error **errp) -{ -''', - c_name=c_name(name)) - - ret += gen_visit_struct_body(name) + name=name, c_name=c_name(name)) - ret += mcgen(''' -} -''') return ret @@ -342,16 +342,6 @@ out: return ret -def gen_visit_decl(name, scalar=False): - c_type = c_name(name) + ' *' - if not scalar: - c_type += '*' - return mcgen(''' -void visit_type_%(c_name)s(Visitor *m, %(c_type)sobj, const char *name, Error **errp); -''', - c_name=c_name(name), c_type=c_type) - - class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): def __init__(self): self.decl = None |