[libvirt] [PATCH v1 07/40] util: hash: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Sukrit Bhatnagar posted 40 patches 7 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH v1 07/40] util: hash: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
Posted by Sukrit Bhatnagar 7 years, 6 months ago
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 virHashTablePtr are declared using
VIR_AUTOPTR, the function virHashFree will be run
automatically on it when it goes out of scope.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
---
 src/util/virhash.c | 1 -
 src/util/virhash.h | 4 ++++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/util/virhash.c b/src/util/virhash.c
index ecda55d..006ffd8 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -26,7 +26,6 @@
 
 #include "virerror.h"
 #include "virhash.h"
-#include "viralloc.h"
 #include "virlog.h"
 #include "virhashcode.h"
 #include "virrandom.h"
diff --git a/src/util/virhash.h b/src/util/virhash.h
index 5b24fc0..dd789c6 100644
--- a/src/util/virhash.h
+++ b/src/util/virhash.h
@@ -16,6 +16,8 @@
 # include <stdint.h>
 # include <stdbool.h>
 
+# include "viralloc.h"
+
 /*
  * The hash table.
  */
@@ -200,4 +202,6 @@ void *virHashSearch(const virHashTable *table, virHashSearcher iter,
 /* Convenience for when VIR_FREE(value) is sufficient as a data freer.  */
 void virHashValueFree(void *value, const void *name);
 
+VIR_DEFINE_AUTOPTR_FUNC(virHashTable, virHashFree)
+
 #endif                          /* ! __VIR_HASH_H__ */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 07/40] util: hash: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
Posted by Erik Skultety 7 years, 6 months ago
On Sat, Jul 21, 2018 at 05:36:39PM +0530, Sukrit Bhatnagar wrote:
> 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 virHashTablePtr are declared using
> VIR_AUTOPTR, the function virHashFree will be run
> automatically on it when it goes out of scope.
>
> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
> ---

Reviewed-by: Erik Skultety <eskultet@redhat.com>

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