From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH V3 10/13] libxl/gentypes.py: include discriminator in JSON output Date: Thu, 24 Apr 2014 09:12:28 +0100 Message-ID: <20140424081228.GA21903@zion.uk.xensource.com> References: <1398272363-12133-1-git-send-email-wei.liu2@citrix.com> <1398272363-12133-11-git-send-email-wei.liu2@citrix.com> <53584158.4090306@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <53584158.4090306@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: Andrew Cooper Cc: ian.jackson@eu.citrix.com, Wei Liu , ian.campbell@citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Wed, Apr 23, 2014 at 11:40:24PM +0100, Andrew Cooper wrote: > 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. > Oh, I just wanted to be consistent with the reset of the file. :-) Wei. > ~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"