[libvirt] [PATCH v2 1/3] internal: Introduce macro for stealing pointers

Peter Krempa pkrempa at redhat.com
Thu Aug 4 10:40:45 UTC 2016


VIR_STEAL_PTR copies the pointer from the second argument into the
first argument and then sets the second to NULL.
---
 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.9.2




More information about the libvir-list mailing list