From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH RFC 4/9] libxl_internal: introduce libxl__json_object_is_{null, number, double} Date: Tue, 15 Apr 2014 10:29:56 +0100 Message-ID: <20140415092956.GI3635@zion.uk.xensource.com> References: <1397144422-18906-1-git-send-email-wei.liu2@citrix.com> <1397144422-18906-6-git-send-email-wei.liu2@citrix.com> <1397495067.7802.29.camel@dagon.hellion.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1397495067.7802.29.camel@dagon.hellion.org.uk> 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 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 > > Acked-by: Ian Campbell > > 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.