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

login
register
mail settings
Submitter Michael Roth
Date July 24, 2012, 5:20 p.m.
Message ID <1343150454-4677-9-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/173037/
State New
Headers show

Comments

Michael Roth - July 24, 2012, 5:20 p.m.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 scripts/qapi_visit.py |    9 +++++++++
 1 file changed, 9 insertions(+)
Anthony Liguori - July 24, 2012, 10:21 p.m.
Michael Roth <mdroth@linux.vnet.ibm.com> writes:

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  scripts/qapi_visit.py |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/scripts/qapi_visit.py b/scripts/qapi_visit.py
> index 864acb2..8f8cdca 100644
> --- a/scripts/qapi_visit.py
> +++ b/scripts/qapi_visit.py
> @@ -105,6 +105,15 @@ if (obj && (*obj)->%(prefix)shas_%(c_name)s) {
>              if annotated:
>                  if isinstance(argentry['type'], types.ListType):
>                      ret += generate_visit_array_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);
> -- 
> 1.7.9.5

Patch

diff --git a/scripts/qapi_visit.py b/scripts/qapi_visit.py
index 864acb2..8f8cdca 100644
--- a/scripts/qapi_visit.py
+++ b/scripts/qapi_visit.py
@@ -105,6 +105,15 @@  if (obj && (*obj)->%(prefix)shas_%(c_name)s) {
             if annotated:
                 if isinstance(argentry['type'], types.ListType):
                     ret += generate_visit_array_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);