Add helper for utilizing __attribute__(cleanup())) for unref-ing
instances of sublasses of virObject.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
virClassIsDerivedFrom;
virClassName;
virClassNew;
+virObjectAutoUnref;
virObjectFreeCallback;
virObjectFreeHashData;
virObjectIsClass;
# define VIR_AUTOPTR(type) \
__attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type *
+/**
+ * VIR_AUTOUNREF:
+ * @type: type of an virObject subclass to be unref'd automatically
+ *
+ * Declares a variable of @type which will be automatically unref'd when
+ * control goes out of the scope.
+ */
+# define VIR_AUTOUNREF(type) \
+ __attribute__((cleanup(virObjectAutoUnref))) type
+
#endif /* LIBVIRT_VIRALLOC_H */
}
+/**
+ * virObjectAutoUnref:
+ *
+ * Helper used by VIR_AUTOUNREF
+ */
+void
+virObjectAutoUnref(void *objptr)
+{
+ virObjectPtr *obj = objptr;
+ virObjectUnref(*obj);
+}
+
+
/**
* virObjectRef:
* @anyobj: any instance of virObjectPtr
bool
virObjectUnref(void *obj);
+void
+virObjectAutoUnref(void *objptr);
+
void *
virObjectRef(void *obj);