virBufferFreeAndReset(childBuf);
return ret;
}
+
+
+void
+virXPathContextNodeRestore(virXPathContextNodeSavePtr save)
+{
+ if (!save->ctxt)
+ return;
+
+ save->ctxt->node = save->node;
+}
virBufferPtr attrBuf,
virBufferPtr childBuf);
+struct _virXPathContextNodeSave {
+ xmlXPathContextPtr ctxt;
+ xmlNodePtr node;
+};
+typedef struct _virXPathContextNodeSave virXPathContextNodeSave;
+typedef virXPathContextNodeSave *virXPathContextNodeSavePtr;
+
+void
+virXPathContextNodeRestore(virXPathContextNodeSavePtr save);
+
+VIR_DEFINE_AUTOCLEAN_FUNC(virXPathContextNodeSave, virXPathContextNodeRestore);
+
+/**
+ * VIR_XPATH_NODE_AUTORESTORE:
+ * @ctxt: XML XPath context pointer
+ *
+ * This macro ensures that when the scope where it's used ends, @ctxt's current
+ * 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 = _ctxt->node}; \
+ ignore_value(&_ctxt ## CtxtSave)
+
#endif /* LIBVIRT_VIRXML_H */