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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 26, 2019 at 11:29:33 -0600, Eric Blake wrote:
> 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@xxxxxxxxxx>
> > ---
> >  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, } ?

It would require renaming the argument of the macro as it would be
replaced otherwise. Interrestingly in most cases it would actually work
as in most cases the macro is used with 'ctxt'.

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux