|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] libxl: add support for yajl 2.x
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.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |