The macro is used to automatically preserve the last error object on
cleanup paths which might override. Note that the 'ignore_value' is
required to silence clang's unused variable checker.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/util/virerror.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/util/virerror.h b/src/util/virerror.h
index 42f2835a85..ce0b48b3ad 100644
--- a/src/util/virerror.h
+++ b/src/util/virerror.h
@@ -207,3 +207,13 @@ void virLastErrorPrefixMessage(const char *fmt, ...)
G_GNUC_PRINTF(1, 2);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virError, virFreeError);
+
+/**
+ * VIR_ERROR_AUTO_PRESERVE_LAST:
+ *
+ * This macro ensures that the last error object is restored to the state it was
+ * at the point where the macro was expanded when the scope ends.
+ */
+#define VIR_ERROR_AUTOPRESERVE_LAST \
+ __attribute__((cleanup(virErrorRestore))) virErrorPtr orig_err_preserve =
virErrorPreserveLast(NULL); \
+ ignore_value(&orig_err_preserve)
--
2.26.2