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

Re: [Xen-devel] [PATCH V5 10/32] libxl: fix JSON generator for uint64_t



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 <wei.liu2@xxxxxxxxxx>
> > ---
> >  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.

_______________________________________________
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®.