[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: [PATCH V6 2/3] libxl: Introduce JSON parsing stuff.



On Thu, 2011-06-30 at 18:30 +0100, Anthony PERARD wrote:
> We use the yajl parser, but we need to make a tree from the parse result
> to use it outside the parser.
> 
> So this patch include json_object struct that is used to hold the JSON
> data.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
> ---
>  tools/libxl/Makefile         |    5 +-
>  tools/libxl/libxl_internal.h |   97 ++++++++
>  tools/libxl/libxl_json.c     |  521 
> ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 622 insertions(+), 1 deletions(-)
>  create mode 100644 tools/libxl/libxl_json.c
> 
> diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
> index a95cd5d..0306cb0 100644
> --- a/tools/libxl/Makefile
> +++ b/tools/libxl/Makefile
> @@ -32,9 +32,12 @@ endif
>  LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o
>  LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o
> 
> +LIBXL_LIBS += -lyajl
> +
>  LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
>                         libxl_dom.o libxl_exec.o libxl_xshelp.o 
> libxl_device.o \
> -                       libxl_internal.o libxl_utils.o libxl_uuid.o 
> $(LIBXL_OBJS-y)
> +                       libxl_internal.o libxl_utils.o libxl_uuid.o 
> libxl_json.o \
> +                       $(LIBXL_OBJS-y)
>  LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
> 
>  $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) 
> $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> index 71eb189..555d9f3 100644
> --- a/tools/libxl/libxl_internal.h
> +++ b/tools/libxl/libxl_internal.h
> @@ -381,4 +381,101 @@ _hidden int libxl__e820_alloc(libxl_ctx *ctx, uint32_t 
> domid, libxl_domain_confi
>  #define STRINGIFY(x) #x
>  #define TOSTRING(x) STRINGIFY(x)
> 
> +/* from libxl_json */
> +typedef enum {
> +    JSON_ERROR,
> +    JSON_NULL,
> +    JSON_TRUE,
> +    JSON_FALSE,
> +    JSON_INTEGER,
> +    JSON_DOUBLE,
> +    JSON_STRING,
> +    JSON_MAP,
> +    JSON_ARRAY,
> +    JSON_ANY
> +} libxl__json_node_type;

Could be internal IDL? Maybe no much point if you aren't using the
to_string functions etc?

> +
> +typedef struct libxl__json_object {
> +    libxl__json_node_type type;
> +    union {
> +        long i;
> +        double d;
> +        const char *string;

Is it really const? Seems to be malloc/freed?

> [...]+#ifdef DEBUG_ANSWER
> +#  define DEBUG_GEN_ALLOC(h) \
> +    if (h == NULL) { \
> +        yajl_gen_config conf = { 1, "  " }; \
> +        h = yajl_gen_alloc(&conf, NULL); \
> +    }

All the callers of these macros use ctx->g. I think you could push the
->g down into the macros.

[...]

Ian



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.