From 42a6d5d30c4f9cca3913996f6cccf6dd383a3fd3 Mon Sep 17 00:00:00 2001
Message-Id: <42a6d5d30c4f9cca3913996f6cccf6dd383a3fd3@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 24 Aug 2016 16:11:10 -0400
Subject: [PATCH] internal: Introduce macro for stealing pointers
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
VIR_STEAL_PTR copies the pointer from the second argument into the
first argument and then sets the second to NULL.
(cherry picked from commit 5b7dedc995a6b33a7be33a67290155627a133a7f)
---
src/internal.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/internal.h b/src/internal.h
index 0dc34c7..d8cc5ad 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -307,6 +307,18 @@
} while (0)
/**
+ * VIR_STEAL_PTR:
+ *
+ * Steals pointer passed as second argument into the first argument. Second
+ * argument must not have side effects.
+ */
+# define VIR_STEAL_PTR(a, b) \
+ do { \
+ (a) = (b); \
+ (b) = NULL; \
+ } while (0)
+
+/**
* virCheckFlags:
* @supported: an OR'ed set of supported flags
* @retval: return value in case unsupported flags were passed
--
2.10.0