[libvirt-python 18/18] Bring some virTypedParams* API from libvirt

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

 



virTypedParamsClear() and virTypedParamsFree() were introduced in
libvirt 1.0.2. In an effort to keep the code clean bring these two
functions to libvirt-python if we're building against a version of
libvirt that's older than 1.0.2
---
 libvirt-utils.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 libvirt-utils.h |  6 ++++++
 2 files changed, 49 insertions(+)

diff --git a/libvirt-utils.c b/libvirt-utils.c
index 6866bf1..90d4719 100644
--- a/libvirt-utils.c
+++ b/libvirt-utils.c
@@ -134,3 +134,46 @@ int virFileClose(int *fdptr)
 
     return rc;
 }
+
+/**
+ * virTypedParamsClear:
+ * @params: the array of the typed parameters
+ * @nparams: number of parameters in the @params array
+ *
+ * Frees all memory used by string parameters. The memory occupied by @params
+ * is not free; use virTypedParamsFree if you want it to be freed too.
+ *
+ * Returns nothing.
+ */
+void
+virTypedParamsClear(virTypedParameterPtr params,
+                    int nparams)
+{
+    size_t i;
+
+    if (!params)
+        return;
+
+    for (i = 0; i < nparams; i++) {
+        if (params[i].type == VIR_TYPED_PARAM_STRING)
+            VIR_FREE(params[i].value.s);
+    }
+}
+
+/**
+ * virTypedParamsFree:
+ * @params: the array of the typed parameters
+ * @nparams: number of parameters in the @params array
+ *
+ * Frees all memory used by string parameters and the memory occuiped by
+ * @params.
+ *
+ * Returns nothing.
+ */
+void
+virTypedParamsFree(virTypedParameterPtr params,
+                   int nparams)
+{
+    virTypedParamsClear(params, nparams);
+    VIR_FREE(params);
+}
diff --git a/libvirt-utils.h b/libvirt-utils.h
index 6f920c6..70f6690 100644
--- a/libvirt-utils.h
+++ b/libvirt-utils.h
@@ -200,4 +200,10 @@ int virFileClose(int *fdptr)
 # define VIR_FORCE_CLOSE(FD) \
     ignore_value(virFileClose(&(FD)))
 
+# if ! LIBVIR_CHECK_VERSION(1,0,2)
+void virTypedParamsClear(virTypedParameterPtr params, int nparams);
+
+void virTypedParamsFree(virTypedParameterPtr params, int nparams);
+# endif /* ! LIBVIR_CHECK_VERSION(1,0,2) */
+
 #endif /* __LIBVIRT_UTILS_H__ */
-- 
1.8.3.2

--
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]