From: Ian Campbell Subject: Re: [PATCH RFC v2 07/13] libxl: internal convenience macros Date: Mon, 31 Oct 2011 09:53:35 +0000 Message-ID: <1320054815.23193.30.camel@zakaz.uk.xensource.com> References: <1319827031-15395-1-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-2-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-3-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-4-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-5-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-6-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-7-git-send-email-ian.jackson@eu.citrix.com> <1319827031-15395-8-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1319827031-15395-8-git-send-email-ian.jackson@eu.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: Ian Jackson Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Fri, 2011-10-28 at 19:37 +0100, Ian Jackson wrote: > Provide some macros which are useful shorthands for use within libxl: > * GC_INIT to initialise a gc from a ctx and GC_FREE to free it > * CTX(gc) to give you back the ctx > * LIBXL_TAILQ_INSERT_SORTED for inserting things into sorted lists > > These will be used by later patches. > > Signed-off-by: Ian Jackson > --- > tools/libxl/libxl_internal.h | 48 ++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 48 insertions(+), 0 deletions(-) > > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h > index 31adbc8..8649788 100644 > --- a/tools/libxl/libxl_internal.h > +++ b/tools/libxl/libxl_internal.h > @@ -555,6 +555,54 @@ _hidden void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj); > > _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s); > > + > +/* > + * Convenience macros. > + */ > + > + > +/* > + * All of these assume (or define) > + * libxl__gc *gc; > + * as a local variable. > + */ > + > +#define GC_INIT(ctx) libxl__gc gc[1] = { LIBXL_INIT_GC(ctx) } Tricksy, I like it ;-) Acked-by: Ian Campbell Is there a massive conversion patch somewhere downseries? > +#define GC_FREE libxl__free_all(gc) > +#define CTX libxl__gc_owner(gc) > + > + > +/* > + * Inserts "elm_new" into the sorted list "head". > + * > + * "elm_search" must be a loop search variable of the same type as > + * "elm_new". "new_after_search_p" must be an expression which is > + * true iff the element "elm_new" sorts after the element > + * "elm_search". > + * > + * "search_body" can be empty, or some declaration(s) and statement(s) > + * needed for "new_after_search_p". > + */ > +#define LIBXL_TAILQ_INSERT_SORTED(head, entry, elm_new, elm_search, \ > + search_body, new_after_search_p) \ > + do { \ > + for ((elm_search) = LIBXL_TAILQ_FIRST((head)); \ > + (elm_search); \ > + (elm_search) = LIBXL_TAILQ_NEXT((elm_search), entry)) { \ > + search_body; \ > + if (!(new_after_search_p)) \ > + break; \ > + } \ > + /* now elm_search is either the element before which we want \ > + * to place elm_new, or NULL meaning we want to put elm_new at \ > + * the end */ \ > + if ((elm_search)) \ > + LIBXL_TAILQ_INSERT_BEFORE((elm_search), (elm_new), entry); \ > + else \ > + LIBXL_TAILQ_INSERT_TAIL((head), (elm_new), entry); \ > + } while(0) > + > + > #endif > > /*