提交 60f8546a 编写于 作者: M Markus Armbruster

qapi-visit: Rearrange code a bit

Move gen_visit_decl() to a better place.  Inline
generate_visit_struct_body().
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
Message-Id: <1442401589-24189-15-git-send-email-armbru@redhat.com>
上级 e98859a9
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册