Patchwork [v3,07/22] qapi: qapi_visit.py, support for visiting non-pointer/embedded structs

login
register
mail settings
Submitter Michael Roth
Date Oct. 4, 2012, 5:33 p.m.
Message ID <1349372021-31212-8-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/189283/
State New
Headers show

Comments

Michael Roth - Oct. 4, 2012, 5:33 p.m.
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 scripts/qapi_visit.py |    9 +++++++++
 1 file changed, 9 insertions(+)
Paolo Bonzini - Oct. 5, 2012, 8:09 a.m.
Il 04/10/2012 19:33, Michael Roth ha scritto:
> +                elif argentry.has_key('<embedded struct>'):

Just <embedded> perhaps?

Paolo

> +                    tmp_ptr_name = "%s_%s_ptr" % (c_var(field_prefix).replace(".", ""), c_var(argname))
> +                    ret += mcgen('''
> +%(type)s *%(tmp_ptr)s = &(*obj)->%(c_prefix)s%(c_name)s;
> +visit_type_%(type)s(m, (obj && *obj) ? &%(tmp_ptr)s : NULL, "%(name)s", errp);
> +''',
> +                                 c_prefix=c_var(field_prefix), prefix=field_prefix,
> +                                 type=type_name(argentry['type']), c_name=c_var(argname),
> +                                 name=argname, tmp_ptr=tmp_ptr_name)

Patch

diff --git a/scripts/qapi_visit.py b/scripts/qapi_visit.py
index af23770..ebff0f0 100644
--- a/scripts/qapi_visit.py
+++ b/scripts/qapi_visit.py
@@ -107,6 +107,15 @@  if (obj && (*obj)->%(prefix)shas_%(c_name)s) {
             if annotated:
                 if isinstance(argentry['type'], types.ListType):
                     ret += generate_visit_carray_body(argname, argentry)
+                elif argentry.has_key('<embedded struct>'):
+                    tmp_ptr_name = "%s_%s_ptr" % (c_var(field_prefix).replace(".", ""), c_var(argname))
+                    ret += mcgen('''
+%(type)s *%(tmp_ptr)s = &(*obj)->%(c_prefix)s%(c_name)s;
+visit_type_%(type)s(m, (obj && *obj) ? &%(tmp_ptr)s : NULL, "%(name)s", errp);
+''',
+                                 c_prefix=c_var(field_prefix), prefix=field_prefix,
+                                 type=type_name(argentry['type']), c_name=c_var(argname),
+                                 name=argname, tmp_ptr=tmp_ptr_name)
             else:
                 ret += mcgen('''
 visit_type_%(type)s(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : NULL, "%(name)s", errp);