From: Ian Campbell Subject: Re: [PATCH V6 2/3] libxl: Introduce JSON parsing stuff. Date: Fri, 1 Jul 2011 09:14:34 +0100 Message-ID: <1309508074.634.13.camel@zakaz.uk.xensource.com> References: <1309455045-3062-1-git-send-email-anthony.perard@citrix.com> <1309455045-3062-3-git-send-email-anthony.perard@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1309455045-3062-3-git-send-email-anthony.perard@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Anthony PERARD Cc: Xen Devel , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org 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 > --- > 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