xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@entel.upc.edu>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] libxl: add support for yajl 2.x
Date: Tue, 3 Jan 2012 19:09:23 +0100	[thread overview]
Message-ID: <CAPLaKK7H44CpvDfgLOhr+80rbHuGgDHz4z9iZE7OQYhqVBfSfQ@mail.gmail.com> (raw)
In-Reply-To: <20227.16778.631463.62844@mariner.uk.xensource.com>

2012/1/3 Ian Jackson <Ian.Jackson@eu.citrix.com>:
> 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@lists.xensource.com
http://lists.xensource.com/xen-devel

      reply	other threads:[~2012-01-03 18:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-20  9:53 [PATCH] libxl: add support for yajl 2.x Roger Pau Monne
2011-12-22 14:19 ` Ian Campbell
2011-12-22 14:24   ` Roger Pau Monné
2012-01-03 17:57 ` Ian Jackson
2012-01-03 18:09   ` Roger Pau Monné [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPLaKK7H44CpvDfgLOhr+80rbHuGgDHz4z9iZE7OQYhqVBfSfQ@mail.gmail.com \
    --to=roger.pau@entel.upc.edu \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).