From: Ian Jackson Subject: Re: [PATCH] libxl: add support for yajl 2.x Date: Tue, 3 Jan 2012 17:57:30 +0000 Message-ID: <20227.16778.631463.62844@mariner.uk.xensource.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Roger Pau Monne Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Roger Pau Monne writes ("[Xen-devel] [PATCH] libxl: add support for yajl 2.x"): > This patch adds support for yajl versions 2.x, while retaining 1.x > compatibility. This patch adds quite a lot of #ifdefs all over the > json code, so I'm open to suggestions if there's a better way to > handle this. I have some suggestions. The basic idea would be to try to put all of the ifdefs in one place in libxl_json.h. > +#ifdef HAVE_YAJL_V2 > +static int json_callback_number(void *opaque, const char *s, size_t len) > +#else > static int json_callback_number(void *opaque, const char *s, unsigned int len) > +#endif So how about: /* libxl_json.h */ #ifdef HAVE_YAJL_V2 typedef size_t libxl_yajl_length; ... #else typedef unsigned int libxl_yajl_length; ... #endif /* libxl_json.c */ static int json_callback_number(void *opaque, const char *s, libxl_yajl_length len) { ... > +#ifdef HAVE_YAJL_V2 > + yajl_ctx.hand = yajl_alloc(&callbacks, NULL, &yajl_ctx); > +#else > yajl_parser_config cfg = { > .allowComments = 1, > .checkUTF8 = 1, > }; > yajl_ctx.hand = yajl_alloc(&callbacks, &cfg, NULL, &yajl_ctx); > +#endif ... > status = yajl_parse(yajl_ctx.hand, (const unsigned char *)s, strlen(s)); > if (status != yajl_status_ok) > goto out; > + /* libxl_json.h */ #ifdef HAVE_YAJL_V2 ... static inline int libxl_yajl_alloc(...) { return yajl_alloc .... } ... #else ... static inline int libxl_yajl_alloc(...) { [version with cfg] } #define yajl_complete_parse yajl_parse_complete ... #endif etc. Ian.