[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] libxl: add support for yajl 2.x
2012/1/3 Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>: > 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. I haven't really though of this anymore, but this seems much more appropriate and less intrusive. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |