提交 5710153e 编写于 作者: M Markus Armbruster

qapi: Replace dirty is_c_ptr() by method c_null()

is_c_ptr() looks whether the end of the C text for the type looks like
a pointer.  Works, but is fragile.

We now have a better tool: use QAPISchemaType method c_null().  The
initializers for non-pointers become prettier: 0, false or the
enumeration constant with the value 0 instead of {0}.
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-13-git-send-email-armbru@redhat.com>
上级 05f43a96
...@@ -91,18 +91,12 @@ def gen_visitor_input_vars_decl(args): ...@@ -91,18 +91,12 @@ def gen_visitor_input_vars_decl(args):
bool has_%(argname)s = false; bool has_%(argname)s = false;
''', ''',
argname=c_name(memb.name)) argname=c_name(memb.name))
if is_c_ptr(memb.type.c_type()): ret += mcgen('''
ret += mcgen(''' %(c_type)s %(c_name)s = %(c_null)s;
%(argtype)s %(argname)s = NULL;
''',
argname=c_name(memb.name),
argtype=memb.type.c_type())
else:
ret += mcgen('''
%(argtype)s %(argname)s = {0};
''', ''',
argname=c_name(memb.name), c_name=c_name(memb.name),
argtype=memb.type.c_type()) c_type=memb.type.c_type(),
c_null=memb.type.c_null())
pop_indent() pop_indent()
return ret return ret
......
...@@ -1441,9 +1441,6 @@ def c_type(value, is_param=False): ...@@ -1441,9 +1441,6 @@ def c_type(value, is_param=False):
assert isinstance(value, str) and value != "" assert isinstance(value, str) and value != ""
return c_name(value) + pointer_suffix return c_name(value) + pointer_suffix
def is_c_ptr(value):
return value.endswith(pointer_suffix)
def genindent(count): def genindent(count):
ret = "" ret = ""
for i in range(count): for i in range(count):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册