From: Wei Liu Subject: Re: [PATCH V5 10/32] libxl: fix JSON generator for uint64_t Date: Tue, 20 May 2014 14:15:19 +0100 Message-ID: <20140520131519.GA18374@zion.uk.xensource.com> References: <1400018054-26038-1-git-send-email-wei.liu2@citrix.com> <1400018054-26038-11-git-send-email-wei.liu2@citrix.com> <1400590503.6946.42.camel@kazak.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1400590503.6946.42.camel@kazak.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: Ian Campbell Cc: ian.jackson@eu.citrix.com, Wei Liu , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, May 20, 2014 at 01:55:03PM +0100, Ian Campbell wrote: > On Tue, 2014-05-13 at 22:53 +0100, Wei Liu wrote: > > yajl_gen_integer cannot cope with uint64_t. > > Please can you describe how it fails and/or what it generates in > practice. Perhaps indicate if/how we would cope with it on parse? > No problem. > In particular I think the result of this change does *not* involve > adding quotes around the number? > Yes, you're right. > > A new function called > > libxl__uint64_gen_json is introduced to handle uint64_t. > > > > Also removed a duplicated definition of MemKB while I was there. > > > > Signed-off-by: Wei Liu > > --- > > tools/libxl/idl.py | 2 +- > > tools/libxl/libxl_json.c | 21 +++++++++++++++++++++ > > tools/libxl/libxl_json.h | 1 + > > tools/libxl/libxl_types.idl | 4 +--- > > 4 files changed, 24 insertions(+), 4 deletions(-) > > > > diff --git a/tools/libxl/idl.py b/tools/libxl/idl.py > > index e4dc79b..69e08e1 100644 > > --- a/tools/libxl/idl.py > > +++ b/tools/libxl/idl.py > > @@ -266,7 +266,7 @@ integer = Number("int", namespace = None, signed = True) > > uint8 = UInt(8) > > uint16 = UInt(16) > > uint32 = UInt(32) > > -uint64 = UInt(64) > > +uint64 = UInt(64, json_fn = "libxl__uint64_gen_json") > > > > string = Builtin("char *", namespace = None, dispose_fn = "free", > > json_fn = "libxl__string_gen_json", > > diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c > > index 3ea56a4..ff23376 100644 > > --- a/tools/libxl/libxl_json.c > > +++ b/tools/libxl/libxl_json.c > > @@ -794,6 +794,27 @@ out: > > return ret; > > } > > > > +yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val) > > +{ > > + char *num; > > + unsigned int len; > > + yajl_gen_status s; > > + > > + if (asprintf(&num, "%"PRIu64, val) == -1) { > > + s = yajl_gen_in_error_state; > > + goto out; > > + } > > + > > + len = strlen(num); > > asprintf returns len - 1 on success (I think, check for off by one in > my reading of the manpage). > OK, I will use that. Wei.