[libvirt] [PATCH 4/5] util: XML: Introduce automatic reset of XPath's current node

Eric Blake eblake at redhat.com
Tue Feb 26 17:29:33 UTC 2019


On 2/26/19 11:08 AM, Peter Krempa wrote:
> Quite a few parts modify the XPath context current node to shif the

shift

> scope and allow easier queries. This also means that the node needs
> to be restored afterwards.
> 
> Introduce a macro based on 'VIR_AUTOCLEAN' which adds a local structure
> on the stack remembering the original node along with a function which
> will make sure that the node is reset when the local structure leaves
> scope.
> 
> Signed-off-by: Peter Krempa <pkrempa at redhat.com>
> ---
>  src/libvirt_private.syms |  1 +
>  src/util/virxml.c        | 10 ++++++++++
>  src/util/virxml.h        | 22 ++++++++++++++++++++++
>  3 files changed, 33 insertions(+)

Nice idea.


> +/**
> + * VIR_XPATH_NODE_AUTORESTORE:
> + * @ctxt: XML XPath context pointer
> + *
> + * This macro ensures that when the scope where it's used ends @ctxt's current

Reads better with s/ends/ends,/

> + * node pointer is reset to the original value when this macro was used.
> + */
> +# define VIR_XPATH_NODE_AUTORESTORE(ctxt) \
> +    VIR_AUTOCLEAN(virXPathContextNodeSave) ctxt ## CtxtSave = {(ctxt), (ctxt)->node}

Worth using C99 syntax as in { .ctxt = (ctxt), .node = (ctxt)->node, } ?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




More information about the libvir-list mailing list