[PATCH v2 26/41] util: scsi: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
src/util/viralloc.h, define a new wrapper around an existing
cleanup function which will be called when a variable declared
with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant
viralloc.h include, since that has moved from the source module into
the header.

When variables of type virSCSIDevicePtr and virUsedByInfoPtr
are declared using VIR_AUTOPTR, the functions virSCSIDeviceFree
and virSCSIDeviceUsedByInfoFree, respectively, will be run
automatically on them when they go out of scope.

This commit also adds an intermediate typedef for virUsedByInfo
type for use with the cleanup macros.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx>
Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/util/virscsi.c | 5 +++--
 src/util/virscsi.h | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index b51103a..33292f6 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -37,7 +37,6 @@
 
 #include "virlog.h"
 #include "virscsi.h"
-#include "viralloc.h"
 #include "virfile.h"
 #include "virutil.h"
 #include "virstring.h"
@@ -54,7 +53,8 @@ struct _virUsedByInfo {
     char *drvname; /* which driver */
     char *domname; /* which domain */
 };
-typedef struct _virUsedByInfo *virUsedByInfoPtr;
+typedef struct _virUsedByInfo virUsedByInfo;
+typedef virUsedByInfo *virUsedByInfoPtr;
 
 struct _virSCSIDevice {
     unsigned int adapter;
@@ -264,6 +264,7 @@ virSCSIDeviceUsedByInfoFree(virUsedByInfoPtr used_by)
     VIR_FREE(used_by->domname);
     VIR_FREE(used_by);
 }
+VIR_DEFINE_AUTOPTR_FUNC(virUsedByInfo, virSCSIDeviceUsedByInfoFree)
 
 void
 virSCSIDeviceFree(virSCSIDevicePtr dev)
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
index 9f8b3ec..b96d862 100644
--- a/src/util/virscsi.h
+++ b/src/util/virscsi.h
@@ -26,6 +26,7 @@
 
 # include "internal.h"
 # include "virobject.h"
+# include "viralloc.h"
 
 typedef struct _virSCSIDevice virSCSIDevice;
 typedef virSCSIDevice *virSCSIDevicePtr;
@@ -95,4 +96,6 @@ void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
 virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list,
                                        virSCSIDevicePtr dev);
 
+VIR_DEFINE_AUTOPTR_FUNC(virSCSIDevice, virSCSIDeviceFree)
+
 #endif /* __VIR_SCSI_H__ */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux