|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2] libxl: add support for yajl 2.x
On Tue, 2011-12-20 at 12:53 +0000, Roger Pau Monne wrote:
> # HG changeset patch
> # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
> # Date 1324385575 -3600
> # Node ID 716d6d48e647d1d4352f7206e74e693152a4f8fa
> # Parent f72b99fccfca694674259cc1c03c526a827b67ec
> 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.
>
> Tested with yajl 2.0.3 and 1.0.12.
>
> Changes since v1:
>
> * Check if yajl_version.h is present before trying to include it.
>
> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
>
> diff -r f72b99fccfca -r 716d6d48e647 Config.mk
> --- a/Config.mk Tue Dec 20 08:31:40 2011 +0100
> +++ b/Config.mk Tue Dec 20 13:52:55 2011 +0100
> @@ -186,6 +186,11 @@ CONFIG_LIBICONV := $(shell export OS="
> . $(XEN_ROOT)/tools/check/funcs.sh; \
> has_lib libiconv.so && echo 'y' || echo 'n')
>
> +CONFIG_YAJL_VERSION := $(shell export OS="`uname -s`"; \
> + export CHECK_INCLUDES="$(CHECK_INCLUDES)"; \
> + . $(XEN_ROOT)/tools/check/funcs.sh; \
> + has_header yajl/yajl_version.h && echo 'y' || echo
> 'n')
We've ended up with a few of this sort of thing recently. I wonder if it
is time to have a configuration/check phase which generates a config.h?
Ian.
> # Enable XSM security module (by default, Flask).
> XSM_ENABLE ?= n
> FLASK_ENABLE ?= $(XSM_ENABLE)
> diff -r f72b99fccfca -r 716d6d48e647 tools/check/check_yajl_lib
> --- a/tools/check/check_yajl_lib Tue Dec 20 08:31:40 2011 +0100
> +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
> @@ -1,6 +0,0 @@
> -#!/bin/sh
> -# CHECK-BUILD CHECK-INSTALL
> -
> -. ./funcs.sh
> -
> -has_lib libyajl.so.1 || fail "can't find libyajl.so.1 version 1"
> diff -r f72b99fccfca -r 716d6d48e647 tools/libxl/Makefile
> --- a/tools/libxl/Makefile Tue Dec 20 08:31:40 2011 +0100
> +++ b/tools/libxl/Makefile Tue Dec 20 13:52:55 2011 +0100
> @@ -19,6 +19,10 @@ ifeq ($(CONFIG_Linux),y)
> LIBUUID_LIBS += -luuid
> endif
>
> +ifeq ($(CONFIG_YAJL_VERSION),y)
> +CFLAGS += -DHAVE_YAJL_VERSION
> +endif
> +
> LIBXL_LIBS =
> LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest)
> $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(UTIL_LIBS) $(LIBUUID_LIBS)
>
> diff -r f72b99fccfca -r 716d6d48e647 tools/libxl/libxl_json.c
> --- a/tools/libxl/libxl_json.c Tue Dec 20 08:31:40 2011 +0100
> +++ b/tools/libxl/libxl_json.c Tue Dec 20 13:52:55 2011 +0100
> @@ -519,7 +519,11 @@ static bool is_decimal(const char *s, un
> return false;
> }
>
> +#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
> {
> libxl__yajl_ctx *ctx = opaque;
> libxl__json_object *obj = NULL;
> @@ -575,8 +579,13 @@ out:
> return 1;
> }
>
> +#ifdef HAVE_YAJL_V2
> +static int json_callback_string(void *opaque, const unsigned char *str,
> + size_t len)
> +#else
> static int json_callback_string(void *opaque, const unsigned char *str,
> unsigned int len)
> +#endif
> {
> libxl__yajl_ctx *ctx = opaque;
> char *t = NULL;
> @@ -608,8 +617,13 @@ static int json_callback_string(void *op
> return 1;
> }
>
> +#ifdef HAVE_YAJL_V2
> +static int json_callback_map_key(void *opaque, const unsigned char *str,
> + size_t len)
> +#else
> static int json_callback_map_key(void *opaque, const unsigned char *str,
> unsigned int len)
> +#endif
> {
> libxl__yajl_ctx *ctx = opaque;
> char *t = NULL;
> @@ -772,17 +786,26 @@ libxl__json_object *libxl__json_parse(li
> DEBUG_GEN_ALLOC(&yajl_ctx);
>
> if (yajl_ctx.hand == NULL) {
> +#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;
> +
> +#ifdef HAVE_YAJL_V2
> + status = yajl_complete_parse(yajl_ctx.hand);
> +#else
> + status = yajl_parse_complete(yajl_ctx.hand);
> +#endif
>
> - status = yajl_parse_complete(yajl_ctx.hand);
> if (status != yajl_status_ok)
> goto out;
>
> @@ -834,14 +857,25 @@ static const char *yajl_gen_status_to_st
> char *libxl__object_to_json(libxl_ctx *ctx, const char *type,
> libxl__gen_json_callback gen, void *p)
> {
> +#ifndef HAVE_YAJL_V2
> yajl_gen_config conf = { 1, " " };
> +#endif
> const unsigned char *buf;
> char *ret = NULL;
> +#ifdef HAVE_YAJL_V2
> + size_t len = 0;
> +#else
> unsigned int len = 0;
> +#endif
> yajl_gen_status s;
> yajl_gen hand;
>
> +#ifdef HAVE_YAJL_V2
> + hand = yajl_gen_alloc(NULL);
> +#else
> hand = yajl_gen_alloc(&conf, NULL);
> +#endif
> +
> if (!hand)
> return NULL;
>
> diff -r f72b99fccfca -r 716d6d48e647 tools/libxl/libxl_json.h
> --- a/tools/libxl/libxl_json.h Tue Dec 20 08:31:40 2011 +0100
> +++ b/tools/libxl/libxl_json.h Tue Dec 20 13:52:55 2011 +0100
> @@ -17,7 +17,16 @@
>
> #include <yajl/yajl_gen.h>
>
> +#ifdef HAVE_YAJL_VERSION
> +# include <yajl/yajl_version.h>
> +#endif
> +
> #include <_libxl_types_json.h>
> #include <_libxl_types_internal_json.h>
>
> +/* YAJL version check */
> +#if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
> +# define HAVE_YAJL_V2 1
> +#endif
> +
> #endif /* LIBXL_JSON_H */
> diff -r f72b99fccfca -r 716d6d48e647 tools/libxl/libxl_qmp.c
> --- a/tools/libxl/libxl_qmp.c Tue Dec 20 08:31:40 2011 +0100
> +++ b/tools/libxl/libxl_qmp.c Tue Dec 20 13:52:55 2011 +0100
> @@ -453,15 +453,26 @@ static char *qmp_send_prepare(libxl__gc
> qmp_callback_t callback, void *opaque,
> qmp_request_context *context)
> {
> +#ifndef HAVE_YAJL_V2
> yajl_gen_config conf = { 0, NULL };
> +#endif
> const unsigned char *buf = NULL;
> char *ret = NULL;
> +#ifdef HAVE_YAJL_V2
> + size_t len = 0;
> +#else
> unsigned int len = 0;
> +#endif
> yajl_gen_status s;
> yajl_gen hand;
> callback_id_pair *elm = NULL;
>
> +#ifdef HAVE_YAJL_V2
> + hand = yajl_gen_alloc(NULL);
> +#else
> hand = yajl_gen_alloc(&conf, NULL);
> +#endif
> +
> if (!hand) {
> return NULL;
> }
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |