[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by meth
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null() |
Date: |
Wed, 1 Jul 2015 22:22:17 +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}.
One place looks suspicious: we initialize pointers, but not
non-pointers. Either the initialization is superfluous and should be
deleted, or the non-pointers need it as well, or something subtle is
going on and needs a comment. Since I lack the time to figure it out
now, mark it FIXME.
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi-commands.py | 19 +++++++------------
scripts/qapi.py | 3 ---
2 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index a225bdd..d3bddb6 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
@@ -214,7 +208,8 @@ def gen_marshal_input(name, args, ret_type, middle_mode):
header=hdr)
if ret_type:
- if is_c_ptr(ret_type.c_type()):
+ # FIXME fishy: only pointers are initialized
+ if ret_type.c_null() == 'NULL':
retval = " %s retval = NULL;" % ret_type.c_type()
else:
retval = " %s retval;" % ret_type.c_type()
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 98488be..dd77a30 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1365,9 +1365,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):
--
1.9.3
- [Qemu-devel] [PATCH RFC v2 20/47] qapi: Rename class QAPISchema to QAPISchemaParser, (continued)
- [Qemu-devel] [PATCH RFC v2 20/47] qapi: Rename class QAPISchema to QAPISchemaParser, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 18/47] qapi-commands: Don't feed output of mcgen() to mcgen() again, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 08/47] qapi-visit: Fix generated code when schema has forward refs, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 06/47] qapi: Drop unused and useless parameters and variables, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(),
Markus Armbruster <=
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Eric Blake, 2015/07/22
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Markus Armbruster, 2015/07/28
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Eric Blake, 2015/07/28
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Markus Armbruster, 2015/07/29
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Eric Blake, 2015/07/29
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Markus Armbruster, 2015/07/29
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Eric Blake, 2015/07/30
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Markus Armbruster, 2015/07/30
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Eric Blake, 2015/07/30
- Re: [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Markus Armbruster, 2015/07/31