From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH V3 10/13] libxl/gentypes.py: include discriminator in JSON output Date: Wed, 23 Apr 2014 23:40:24 +0100 Message-ID: <53584158.4090306@citrix.com> References: <1398272363-12133-1-git-send-email-wei.liu2@citrix.com> <1398272363-12133-11-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1398272363-12133-11-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu , xen-devel@lists.xen.org Cc: ian.jackson@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org On 23/04/2014 17:59, Wei Liu wrote: > Parser relies on the discriminator to go to correct branch. > > Signed-off-by: Wei Liu > --- > tools/libxl/gentypes.py | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py > index 61a2b3d..8d7183a 100644 > --- a/tools/libxl/gentypes.py > +++ b/tools/libxl/gentypes.py > @@ -229,6 +229,11 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): > s += " goto out;\n" > s += " break;\n" > s += "}\n" > + s += "s = yajl_gen_string(hand, (const unsigned char *)\"%s\", sizeof(\"%s\")-1);\n" \ > + % (ty.keyvar.name, ty.keyvar.name) In python, all forms of string delimiter are equal, precisely to fix the problem demonstrated here. This line can be made more legible using single quotes for the main string, at which point the double quotes around %s don't need escaping. ~Andrew > + s += "if (s != yajl_gen_status_ok)\n" > + s += " goto out;\n" > + s += libxl_C_type_gen_json(ty.keyvar.type, (parent + ty.keyvar.name), indent, parent) > elif isinstance(ty, idl.Struct) and (parent is None or ty.json_gen_fn is None): > s += "s = yajl_gen_map_open(hand);\n" > s += "if (s != yajl_gen_status_ok)\n"