diff options
-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 |