]> xenbits.xensource.com Git - libvirt.git/commitdiff
internal: Introduce macro for stealing pointers
authorPeter Krempa <pkrempa@redhat.com>
Sun, 31 Jul 2016 12:02:08 +0000 (14:02 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 5 Aug 2016 06:38:20 +0000 (08:38 +0200)
VIR_STEAL_PTR copies the pointer from the second argument into the
first argument and then sets the second to NULL.

src/internal.h

index 0dc34c755d63f44e76962bdaea6a62d09fea307e..d8cc5adc38f35613bb1b7bf6ecba7c74e553226c 100644 (file)
         (a) = (a) ^ (b);    \
     } 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