From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH V2 2/4] libxl_json: fix JSON parser debug code Date: Thu, 10 Apr 2014 16:26:32 +0100 Message-ID: <1397143594-15308-3-git-send-email-wei.liu2@citrix.com> References: <1397143594-15308-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1397143594-15308-1-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Wei Liu , ian.jackson@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org Two changes included: 1. implement DEBUG_GEN_ALLOC for YAJL2 2. use size_t for variable "len" without these two fixes it fails to compile when DEBUG_ANSWER is defined. Signed-off-by: Wei Liu --- tools/libxl/libxl_json.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c index 989ac3f..3ea56a4 100644 --- a/tools/libxl/libxl_json.c +++ b/tools/libxl/libxl_json.c @@ -34,11 +34,20 @@ struct libxl__yajl_ctx { }; #ifdef DEBUG_ANSWER -# define DEBUG_GEN_ALLOC(ctx) \ - if ((ctx)->g == NULL) { \ - yajl_gen_config conf = { 1, " " }; \ +#if YAJL_VERSION < 20000 +# define DEBUG_GEN_ALLOC(ctx) \ + if ((ctx)->g == NULL) { \ + yajl_gen_config conf = { 1, " " }; \ (ctx)->g = yajl_gen_alloc(&conf, NULL); \ } +#else /* YAJL2 */ +# define DEBUG_GEN_ALLOC(ctx) \ + if ((ctx)->g == NULL) { \ + (ctx)->g = yajl_gen_alloc(NULL); \ + yajl_gen_config((ctx)->g, yajl_gen_beautify, 1); \ + yajl_gen_config((ctx)->g, yajl_gen_indent_string, " "); \ + } +#endif # define DEBUG_GEN_FREE(ctx) \ if ((ctx)->g) yajl_gen_free((ctx)->g) # define DEBUG_GEN(ctx, type) yajl_gen_##type(ctx->g) @@ -48,7 +57,7 @@ struct libxl__yajl_ctx { # define DEBUG_GEN_REPORT(yajl_ctx) \ do { \ const unsigned char *buf = NULL; \ - unsigned int len = 0; \ + size_t len = 0; \ yajl_gen_get_buf((yajl_ctx)->g, &buf, &len); \ LIBXL__LOG(libxl__gc_owner((yajl_ctx)->gc), \ LIBXL__LOG_DEBUG, "response:\n%s", buf); \ -- 1.7.10.4