[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH V5 18/32] libxl/gentypes.py: special-case KeyedUnion map handle generation



On Tue, 2014-05-13 at 22:54 +0100, Wei Liu wrote:
> Generate JSON map handle according to KeyedUnion discriminator.

I know what this means because I've discussed it with you IRL, but I
suspect noone else (including you or I in 6 months time) will know what
this means.

I think an example of what is changing here would be invaluable.

You also need to mention the compatibility concerns and the rationale
for why it is OK to make this particular change (which IIRC was that the
existing syntax was so unusable no one could be using it).

From eye-balling the diff to the generated code that aspect looks fine.

Ian.
> 
> Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
> ---
>  tools/libxl/gentypes.py |   24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
> index 61a2b3d..01416e7 100644
> --- a/tools/libxl/gentypes.py
> +++ b/tools/libxl/gentypes.py
> @@ -186,6 +186,26 @@ def libxl_C_type_member_init(ty, field):
>      s += "\n"
>      return s
>  
> +def libxl_C_type_gen_map_key(f, parent, indent = ""):
> +    s = ""
> +    if isinstance(f.type, idl.KeyedUnion):
> +        s += "switch (%s) {\n" % (parent + f.type.keyvar.name)
> +        for x in f.type.fields:
> +            v = f.type.keyvar.name + "." + x.name
> +            s += "case %s:\n" % x.enumname
> +            s += "    s = yajl_gen_string(hand, (const unsigned char 
> *)\"%s\", sizeof(\"%s\")-1);\n" % (v, v)
> +            s += "    if (s != yajl_gen_status_ok)\n"
> +            s += "        goto out;\n"
> +            s += "    break;\n"
> +        s += "}\n"
> +    else:
> +        s += "s = yajl_gen_string(hand, (const unsigned char *)\"%s\", 
> sizeof(\"%s\")-1);\n" % (f.name, f.name)
> +        s += "if (s != yajl_gen_status_ok)\n"
> +        s += "    goto out;\n"
> +    if s != "":
> +        s = indent + s
> +    return s.replace("\n", "\n%s" % indent).rstrip(indent)
> +
>  def libxl_C_type_gen_json(ty, v, indent = "    ", parent = None):
>      s = ""
>      if parent is None:
> @@ -235,9 +255,7 @@ def libxl_C_type_gen_json(ty, v, indent = "    ", parent 
> = None):
>          s += "    goto out;\n"
>          for f in [f for f in ty.fields if not f.const and not 
> f.type.private]:
>              (nparent,fexpr) = ty.member(v, f, parent is None)
> -            s += "s = yajl_gen_string(hand, (const unsigned char *)\"%s\", 
> sizeof(\"%s\")-1);\n" % (f.name, f.name)
> -            s += "if (s != yajl_gen_status_ok)\n"
> -            s += "    goto out;\n"
> +            s += libxl_C_type_gen_map_key(f, nparent)
>              s += libxl_C_type_gen_json(f.type, fexpr, "", nparent)
>          s += "s = yajl_gen_map_close(hand);\n"
>          s += "if (s != yajl_gen_status_ok)\n"



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.