]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qapi: Replace dirty is_c_ptr() by method c_null()
authorMarkus Armbruster <armbru@redhat.com>
Wed, 16 Sep 2015 11:06:15 +0000 (13:06 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 21 Sep 2015 07:56:48 +0000 (09:56 +0200)
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: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1442401589-24189-13-git-send-email-armbru@redhat.com>

scripts/qapi-commands.py
scripts/qapi.py

index a68517a83a46604868672df50e6ad17ef5d17881..cbff3560f411900b176ece2fadb18fdfc21199a4 100644 (file)
@@ -91,18 +91,12 @@ def gen_visitor_input_vars_decl(args):
 bool has_%(argname)s = false;
 ''',
                              argname=c_name(memb.name))
-            if is_c_ptr(memb.type.c_type()):
-                ret += mcgen('''
-%(argtype)s %(argname)s = NULL;
-''',
-                             argname=c_name(memb.name),
-                             argtype=memb.type.c_type())
-            else:
-                ret += mcgen('''
-%(argtype)s %(argname)s = {0};
+            ret += mcgen('''
+%(c_type)s %(c_name)s = %(c_null)s;
 ''',
-                             argname=c_name(memb.name),
-                             argtype=memb.type.c_type())
+                         c_name=c_name(memb.name),
+                         c_type=memb.type.c_type(),
+                         c_null=memb.type.c_null())
 
     pop_indent()
     return ret
index ba32aace9997fa75d805cc1cf5e8b4aae7d96cb5..0ffd02d8c27fe682877bc031c98e9ae631212b73 100644 (file)
@@ -1441,9 +1441,6 @@ def c_type(value, is_param=False):
         assert isinstance(value, str) and value != ""
         return c_name(value) + pointer_suffix
 
-def is_c_ptr(value):
-    return value.endswith(pointer_suffix)
-
 def genindent(count):
     ret = ""
     for i in range(count):