[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/26] qapi: Replace dirty is_c_ptr() by method c_nul
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 12/26] qapi: Replace dirty is_c_ptr() by method c_null() |
Date: |
Mon, 21 Sep 2015 10:03:46 +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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Daniel P. Berrange <address@hidden>
Message-Id: <address@hidden>
---
scripts/qapi-commands.py | 16 +++++-----------
scripts/qapi.py | 3 ---
2 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index a68517a..cbff356 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -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;
+ ret += mcgen('''
+%(c_type)s %(c_name)s = %(c_null)s;
''',
- argname=c_name(memb.name),
- argtype=memb.type.c_type())
- else:
- ret += mcgen('''
-%(argtype)s %(argname)s = {0};
-''',
- 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
diff --git a/scripts/qapi.py b/scripts/qapi.py
index ba32aac..0ffd02d 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -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):
--
2.4.3
- [Qemu-devel] [PULL 00/26] qapi: QMP introspection, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 04/26] qapi: New QAPISchemaVisitor, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 01/26] qapi: Rename class QAPISchema to QAPISchemaParser, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 03/26] qapi: QAPISchema code generation helper methods, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 12/26] qapi: Replace dirty is_c_ptr() by method c_null(),
Markus Armbruster <=
- [Qemu-devel] [PULL 09/26] qapi: De-duplicate enum code generation, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 11/26] qapi-event: Convert to QAPISchemaVisitor, fixing data with base, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 08/26] qapi-commands: Convert to QAPISchemaVisitor, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 10/26] qapi-event: Eliminate global variable event_enum_value, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 14/26] qapi-visit: Rearrange code a bit, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 02/26] qapi: New QAPISchema intermediate reperesentation, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 23/26] qapi-schema: Fix up misleading specification of netdev_add, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 06/26] qapi-types: Convert to QAPISchemaVisitor, fixing flat unions, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 20/26] qapi: Make output visitor return qnull() instead of NULL, Markus Armbruster, 2015/09/21
- [Qemu-devel] [PULL 18/26] qapi-commands: De-duplicate output marshaling functions, Markus Armbruster, 2015/09/21