mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: alloc: Introduce VIR_AUTOUNREF macro
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>
This commit is contained in:
parent
53a0fa7366
commit
0d13790695
@ -2511,6 +2511,7 @@ virClassForObjectRWLockable;
|
|||||||
virClassIsDerivedFrom;
|
virClassIsDerivedFrom;
|
||||||
virClassName;
|
virClassName;
|
||||||
virClassNew;
|
virClassNew;
|
||||||
|
virObjectAutoUnref;
|
||||||
virObjectFreeCallback;
|
virObjectFreeCallback;
|
||||||
virObjectFreeHashData;
|
virObjectFreeHashData;
|
||||||
virObjectIsClass;
|
virObjectIsClass;
|
||||||
|
@ -637,4 +637,14 @@ void virAllocTestHook(void (*func)(int, void*), void *data);
|
|||||||
# define VIR_AUTOPTR(type) \
|
# define VIR_AUTOPTR(type) \
|
||||||
__attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) 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 */
|
#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:
|
* virObjectRef:
|
||||||
* @anyobj: any instance of virObjectPtr
|
* @anyobj: any instance of virObjectPtr
|
||||||
|
@ -102,6 +102,9 @@ virObjectNew(virClassPtr klass)
|
|||||||
bool
|
bool
|
||||||
virObjectUnref(void *obj);
|
virObjectUnref(void *obj);
|
||||||
|
|
||||||
|
void
|
||||||
|
virObjectAutoUnref(void *objptr);
|
||||||
|
|
||||||
void *
|
void *
|
||||||
virObjectRef(void *obj);
|
virObjectRef(void *obj);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user