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

Re: [Xen-devel] [PATCH RFC 4/9] libxl_internal: introduce libxl__json_object_is_{null, number, double}



On Mon, Apr 14, 2014 at 06:04:27PM +0100, Ian Campbell wrote:
> On Thu, 2014-04-10 at 16:40 +0100, Wei Liu wrote:
> > ... which return true if json object is valid and of type
> > JSON_{NULL,NUMBER,DOUBLE}.
> > 
> > Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
> 
> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
> 
> But... 
> > +static inline bool libxl__json_object_is_null(const libxl__json_object *o)
> > +{
> > +    return o != NULL && o->type == JSON_NULL;
> 
> Shouldn't these (new and existing) use the bit field stuff you just
> introduced?
> 

No, this tests on the exact type, because a JSON object only has one
type.

The previous bit-field patch is for a different purpose. When you try to
parse a libxl_FOO field from a JSON object, the JSON object can be of
different type. For example, (key, value) pair in key_value_list type,
the generated key in JSON object is a string, but the value can be a
string or null depending on the input to JSON object generator
(libxl__object_to_json).

The bit-field patch works like this, say, if we want to parse that (key,
value) pair, we will certainly expect (JSON_STRING | JSON_NULL) in

    x = libxl__json_map_get("value", o, JSON_STRING|JSON_NULL);

but later in the actual function that parses x, x can be either
JSON_STRING or JSON_NULL; it cannot be of two types at the same time.

Wei.

> Ian.

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