From: Luiz Capitulino <lcapitulino@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws
Subject: [Qemu-devel] [PULL 08/20] qapi: Un-inline visit of implicit struct
Date: Fri, 16 May 2014 11:30:23 -0400 [thread overview]
Message-ID: <1400254235-9435-9-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1400254235-9435-1-git-send-email-lcapitulino@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
In preparation of error handling changes. Bonus: generates less
duplicated code.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
scripts/qapi-visit.py | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 1e368be..1ef753a 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -17,6 +17,31 @@ import os
import getopt
import errno
+implicit_structs = []
+
+def generate_visit_implicit_struct(type):
+ global implicit_structs
+ if type in implicit_structs:
+ return ''
+ implicit_structs.append(type)
+ return mcgen('''
+
+static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error **errp)
+{
+ Error *err = NULL;
+
+ visit_start_implicit_struct(m, (void **)obj, sizeof(%(c_type)s), &err);
+ if (!err) {
+ visit_type_%(c_type)s_fields(m, obj, &err);
+ error_propagate(errp, err);
+ err = NULL;
+ visit_end_implicit_struct(m, &err);
+ }
+ error_propagate(errp, err);
+}
+''',
+ c_type=type_name(type))
+
def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = None):
substructs = []
ret = ''
@@ -49,6 +74,9 @@ static void visit_type_%(full_name)s_field_%(c_name)s(Visitor *m, %(name)s **obj
}
''')
+ if base:
+ ret += generate_visit_implicit_struct(base)
+
ret += mcgen('''
static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error **errp)
@@ -60,13 +88,7 @@ static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error *
if base:
ret += mcgen('''
-visit_start_implicit_struct(m, (void**) &(*obj)->%(c_prefix)s%(c_name)s, sizeof(%(type)s), &err);
-if (!err) {
- visit_type_%(type)s_fields(m, &(*obj)->%(c_prefix)s%(c_name)s, &err);
- error_propagate(errp, err);
- err = NULL;
- visit_end_implicit_struct(m, &err);
-}
+visit_type_implicit_%(type)s(m, &(*obj)->%(c_prefix)s%(c_name)s, &err);
''',
c_prefix=c_var(field_prefix),
type=type_name(base), c_name=c_var('base'))
@@ -292,6 +314,10 @@ def generate_visit_union(expr):
del base_fields[discriminator]
ret += generate_visit_struct_fields(name, "", "", base_fields)
+ if discriminator:
+ for key in members:
+ ret += generate_visit_implicit_struct(members[key])
+
ret += mcgen('''
void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
@@ -330,13 +356,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
if not discriminator:
fmt = 'visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", &err);'
else:
- fmt = '''visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, sizeof(%(c_type)s), &err);
- if (!err) {
- visit_type_%(c_type)s_fields(m, &(*obj)->%(c_name)s, &err);
- error_propagate(errp, err);
- err = NULL;
- visit_end_implicit_struct(m, &err);
- }'''
+ fmt = 'visit_type_implicit_%(c_type)s(m, &(*obj)->%(c_name)s, &err);'
enum_full_value = generate_enum_full_value(disc_type, key)
ret += mcgen('''
--
1.9.0
next prev parent reply other threads:[~2014-05-16 15:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 15:30 [Qemu-devel] [PULL 00/20] QMP queue Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 01/20] qapi: Update qapi-code-gen.txt example to match current code Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 02/20] qapi: Normalize marshalling's visitor initialization and cleanup Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 03/20] qapi: Remove unused Visitor callbacks start_handle(), end_handle() Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 04/20] qapi: Replace start_optional()/end_optional() by optional() Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 05/20] qapi-visit.py: Clean up confusing push_indent() / pop_indent() use Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 06/20] qapi: Clean up shadowing of parameters and locals in inner scopes Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 07/20] qapi-visit.py: Clean up a sloppy use of field prefix Luiz Capitulino
2014-05-16 15:30 ` Luiz Capitulino [this message]
2014-05-16 15:30 ` [Qemu-devel] [PULL 09/20] hmp: Call visit_end_struct() after visit_start_struct() succeeds Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 10/20] hw: Don't call visit_end_struct() after visit_start_struct() fails Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 11/20] tests: " Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 12/20] qapi: Replace uncommon use of the error API by the common one Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 13/20] qapi: Show qapi-commands.py invocation in qapi-code-gen.txt Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 14/20] monitor: Convert sendkey to use command_completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 15/20] monitor: Add chardev-remove command completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 16/20] monitor: Add chardev-add backend argument completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 17/20] monitor: Add set_link arguments completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 18/20] monitor: Add netdev_add type argument completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 19/20] monitor: Add netdev_del id " Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 20/20] qapi: skip redundant includes Luiz Capitulino
2014-05-19 15:09 ` [Qemu-devel] [PULL 00/20] QMP queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400254235-9435-9-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).