mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-25 12:52:19 +00:00
util: xml: Introduce VIR_XPATH_NODE_AUTORESTORE_NAME
VIR_XPATH_NODE_AUTORESTORE_NAME is a more generic version of the VIR_XPATH_NODE_AUTORESTORE macro used to save the 'node' inside a XPath context struct. The new macro allows specifying the name of the variable used to save the context so that it can be used multiple times inside a function's nested scopes. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
d9b8d0c6bd
commit
ad29c254b6
@ -379,6 +379,20 @@ virXPathContextNodeRestore(virXPathContextNodeSave *save);
|
|||||||
|
|
||||||
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRestore);
|
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRestore);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIR_XPATH_NODE_AUTORESTORE_NAME:
|
||||||
|
* @name: name of the temporary variable used to save @ctxt
|
||||||
|
* @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. The
|
||||||
|
* context is saved into a variable named @name;
|
||||||
|
*/
|
||||||
|
#define VIR_XPATH_NODE_AUTORESTORE_NAME(_name, _ctxt) \
|
||||||
|
VIR_WARNINGS_NO_UNUSED_VARIABLE \
|
||||||
|
g_auto(virXPathContextNodeSave) _name = { .ctxt = _ctxt,\
|
||||||
|
.node = _ctxt->node}; \
|
||||||
|
VIR_WARNINGS_RESET
|
||||||
/**
|
/**
|
||||||
* VIR_XPATH_NODE_AUTORESTORE:
|
* VIR_XPATH_NODE_AUTORESTORE:
|
||||||
* @ctxt: XML XPath context pointer
|
* @ctxt: XML XPath context pointer
|
||||||
@ -387,10 +401,7 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes
|
|||||||
* node pointer is reset to the original value when this macro was used.
|
* node pointer is reset to the original value when this macro was used.
|
||||||
*/
|
*/
|
||||||
#define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \
|
#define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \
|
||||||
VIR_WARNINGS_NO_UNUSED_VARIABLE \
|
VIR_XPATH_NODE_AUTORESTORE_NAME(_ctxt ## CtxtSave, _ctxt)
|
||||||
g_auto(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = _ctxt,\
|
|
||||||
.node = _ctxt->node}; \
|
|
||||||
VIR_WARNINGS_RESET
|
|
||||||
|
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc);
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc);
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext);
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user