提交 0d137906 编写于 作者: P Peter Krempa

util: alloc: Introduce VIR_AUTOUNREF macro

Add helper for utilizing __attribute__(cleanup())) for unref-ing
instances of sublasses of virObject.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 53a0fa73
......@@ -2511,6 +2511,7 @@ virClassForObjectRWLockable;
virClassIsDerivedFrom;
virClassName;
virClassNew;
virObjectAutoUnref;
virObjectFreeCallback;
virObjectFreeHashData;
virObjectIsClass;
......
......@@ -637,4 +637,14 @@ void virAllocTestHook(void (*func)(int, void*), void *data);
# 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 */
......@@ -362,6 +362,19 @@ virObjectUnref(void *anyobj)
}
/**
* virObjectAutoUnref:
*
* Helper used by VIR_AUTOUNREF
*/
void
virObjectAutoUnref(void *objptr)
{
virObjectPtr *obj = objptr;
virObjectUnref(*obj);
}
/**
* virObjectRef:
* @anyobj: any instance of virObjectPtr
......
......@@ -102,6 +102,9 @@ virObjectNew(virClassPtr klass)
bool
virObjectUnref(void *obj);
void
virObjectAutoUnref(void *objptr);
void *
virObjectRef(void *obj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册