From: Ian Campbell Subject: Re: [PATCH RFC V2 08/10] libxl IDL: generate code to parse libxl__json_object to libxl_FOO struct Date: Tue, 22 Apr 2014 17:01:43 +0100 Message-ID: <1398182503.4880.79.camel@kazak.uk.xensource.com> References: <1397733191-31892-1-git-send-email-wei.liu2@citrix.com> <1397733191-31892-9-git-send-email-wei.liu2@citrix.com> <1398181573.4880.70.camel@kazak.uk.xensource.com> <20140422155418.GP7712@zion.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20140422155418.GP7712@zion.uk.xensource.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 Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, 2014-04-22 at 16:54 +0100, Wei Liu wrote: > > > > > > + (nparent,fexpr) = ty.member(v, f.type.keyvar, parent is None) > > > + s += libxl_C_type_parse_json(f.type.keyvar.type, "x", fexpr, " ", nparent) > > > + s += "}\n" > > > + s += "x = libxl__json_map_get(\"%s\", %s, %s);\n" % (f.name, w, f.type.json_parse_type) > > > + s += "if (x) {\n" > > > + (nparent,fexpr) = ty.member(v, f, parent is None) > > > + s += libxl_C_type_parse_json(f.type, "x", fexpr, " ", nparent) > > > + s += " x = x->parent;\n" > > > > What is this x->parent for? > > > > To make sure when we finishes processing this member, X points back to > its parent again, so that next call to libxl__json_map_get(x) is using > the right "x". Can we create temporary fixed scope "x"s for each field? It's ok if that shadows the existing "x" (for the parent) I think, or am I missing something? > > > + s += "}\n" > > > > > @@ -444,4 +533,17 @@ if __name__ == '__main__': > > > f.write("}\n") > > > f.write("\n") > > > > > > + for ty in [t for t in types if t.json_parse_fn is not None]: > > > + f.write("int %s_parse_json(libxl_ctx *ctx, const libxl__json_object *%s, %s)\n" % (ty.typename,"o",ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) > > > + f.write("{\n") > > > > Are we assuming/requiring the caller to have called the init function > > for the type? Did you consider having this function do it? > > > > Yes, I'm assuming so. > > But I can also make this function do it if you wish. I think that would be best, this function can be thought of as "init from this json", so it should probably do the whole job, which includes setting all the appropriate defaults if the json omits fields etc. Ian.