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

[libvirt] [PATCH 11/12] Introduce virTypedParamsClear public API



The function is just a renamed public version of former
virTypedParameterArrayClear.
---
 daemon/remote.c              | 34 +++++++++----------------
 include/libvirt/libvirt.h.in |  3 +++
 python/generator.py          |  1 +
 python/libvirt-override.c    | 59 +++++++++++++++-----------------------------
 src/libvirt_private.syms     |  1 -
 src/libvirt_public.syms      |  1 +
 src/remote/remote_driver.c   |  4 +--
 src/rpc/gendispatch.pl       |  3 +--
 src/util/virtypedparam.c     | 46 +++++++++++++++++++++-------------
 src/util/virtypedparam.h     |  2 --
 tools/virsh-domain.c         |  2 +-
 11 files changed, 70 insertions(+), 86 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 20c3858..51dbd01 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -987,8 +987,8 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val,
 
 cleanup:
     if (rv < 0) {
-        virTypedParameterArrayClear(params, i);
-        VIR_FREE(params);
+        virTypedParamsFree(params, i);
+        params = NULL;
     }
     return params;
 }
@@ -1037,8 +1037,7 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -1147,8 +1146,7 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -1336,8 +1334,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -1966,8 +1963,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -2031,8 +2027,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -2096,8 +2091,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -2358,8 +2352,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -3862,8 +3855,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -3937,8 +3929,7 @@ success:
 cleanup:
     if (rv < 0)
          virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, args->ncpus * args->nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, args->ncpus * args->nparams);
     if (dom)
         virDomainFree(dom);
     return rv;
@@ -4570,8 +4561,7 @@ success:
 cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return rv;
 }
 
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 23f2952..0983e54 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -608,6 +608,9 @@ virTypedParamsAddFromString(virTypedParameterPtr *params,
                          int type,
                          const char *value);
 void
+virTypedParamsClear     (virTypedParameterPtr params,
+                         int nparams);
+void
 virTypedParamsFree      (virTypedParameterPtr params,
                          int nparams);
 
diff --git a/python/generator.py b/python/generator.py
index 00e4858..f853d77 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -537,6 +537,7 @@ skip_function = (
     "virTypedParamsAddString",
     "virTypedParamsAddUInt",
     "virTypedParamsAddULLong",
+    "virTypedParamsClear",
     "virTypedParamsFree",
     "virTypedParamsGet",
     "virTypedParamsGetBoolean",
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 91e82c6..f9dff8c 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -367,8 +367,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -456,7 +455,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
 
             start_cpu += queried_ncpus;
             ncpus -= queried_ncpus;
-            virTypedParameterArrayClear(params, sumparams);
+            virTypedParamsClear(params, sumparams);
         }
     } else {
         LIBVIRT_BEGIN_ALLOW_THREADS;
@@ -498,13 +497,11 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
         Py_DECREF(total);
     }
 
-    virTypedParameterArrayClear(params, sumparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, sumparams);
     return ret;
 
 error:
-    virTypedParameterArrayClear(params, sumparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, sumparams);
     Py_DECREF(ret);
     return error;
 }
@@ -668,8 +665,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -717,8 +713,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -791,8 +786,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -868,8 +862,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -943,8 +936,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -991,8 +983,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -1065,8 +1056,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -1113,8 +1103,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -1187,8 +1176,7 @@ libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -1235,8 +1223,7 @@ libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -1310,8 +1297,7 @@ libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -1359,8 +1345,7 @@ libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -4305,8 +4290,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -4354,8 +4338,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
@@ -6466,8 +6449,7 @@ libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = VIR_PY_INT_SUCCESS;
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     VIR_FREE(new_params);
     return ret;
 }
@@ -6514,8 +6496,7 @@ libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
     ret = getPyVirTypedParameter(params, nparams);
 
 cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    virTypedParamsFree(params, nparams);
     return ret;
 }
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 521f8e0..fc23adc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1876,7 +1876,6 @@ virTimeStringThenRaw;
 
 
 # virtypedparam.h
-virTypedParameterArrayClear;
 virTypedParameterArrayValidate;
 virTypedParameterAssign;
 virTypedParameterAssignFromStr;
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 7631b19..9777703 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -591,6 +591,7 @@ LIBVIRT_1.0.2 {
         virTypedParamsAddString;
         virTypedParamsAddUInt;
         virTypedParamsAddULLong;
+        virTypedParamsClear;
         virTypedParamsFree;
         virTypedParamsGet;
         virTypedParamsGetBoolean;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a9072bb..3555dac 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1612,7 +1612,7 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
 
 cleanup:
     if (rv < 0)
-        virTypedParameterArrayClear(params, i);
+        virTypedParamsClear(params, i);
     return rv;
 }
 
@@ -2754,7 +2754,7 @@ static int remoteDomainGetCPUStats(virDomainPtr domain,
     rv = ret.nparams;
 cleanup:
     if (rv < 0)
-        virTypedParameterArrayClear(params, nparams * ncpus);
+        virTypedParamsClear(params, nparams * ncpus);
 
     xdr_free((xdrproc_t) xdr_remote_domain_get_cpu_stats_ret,
              (char *) &ret);
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 899f4bc..f00ed7c 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -490,8 +490,7 @@ elsif ($opt_b) {
                                         "                                                   $2,\n" .
                                         "                                                   &n$1)) == NULL)\n" .
                                         "        goto cleanup;\n");
-                    push(@free_list, "    virTypedParameterArrayClear($1, n$1);");
-                    push(@free_list, "    VIR_FREE($1);");
+                    push(@free_list, "    virTypedParamsFree($1, n$1);");
                 } elsif ($args_member =~ m/<\S+>;/ or $args_member =~ m/\[\S+\];/) {
                     # just make all other array types fail
                     die "unhandled type for argument value: $args_member";
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 1b153a4..ae2855a 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -41,20 +41,6 @@ VIR_ENUM_IMPL(virTypedParameter, VIR_TYPED_PARAM_LAST,
               "boolean",
               "string")
 
-void
-virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
-{
-    int i;
-
-    if (!params)
-        return;
-
-    for (i = 0; i < nparams; i++) {
-        if (params[i].type == VIR_TYPED_PARAM_STRING)
-            VIR_FREE(params[i].value.s);
-    }
-}
-
 /* Validate that PARAMS contains only recognized parameter names with
  * correct types, and with no duplicates.  Pass in as many name/type
  * pairs as appropriate, and pass NULL to end the list of accepted
@@ -897,7 +883,7 @@ error:
  *
  * Adds new parameter called @name with char * type and sets its value to
  * @value. The function creates its own copy of @value string, which needs to
- * be freed using virTypedParamsFree. If @params array
+ * be freed using virTypedParamsFree or virTypedParamsClear. If @params array
  * points to NULL or to a space that is not large enough to accommodate the
  * new parameter (@maxparams < @nparams + 1), the function allocates more
  * space for it and updates @maxparams. On success, @nparams is incremented
@@ -959,7 +945,7 @@ error:
  * Adds new parameter called @name with the requested @type and parses its
  * value from the @value string. If the requested type is string, the function
  * creates its own copy of the @value string, which needs to be freed using
- * virTypedParamsFree. If @params array points to NULL
+ * virTypedParamsFree or virTypedParamsClear. If @params array points to NULL
  * or to a space that is not large enough to accommodate the new parameter
  * (@maxparams < @nparams + 1), the function allocates more space for it and
  * updates @maxparams. On success, @nparams is incremented by one. The
@@ -1001,6 +987,32 @@ error:
 
 
 /**
+ * virTypedParamsClear:
+ * @params: the array of typed parameters
+ * @nparams: number of parameters in the @params array
+ *
+ * Frees all memory used by string parameters. The memory occupied by @params
+ * is not freed; use virTypedParamsFree if you want it to be freed too.
+ *
+ * Returns nothing.
+ */
+void
+virTypedParamsClear(virTypedParameterPtr params,
+                    int nparams)
+{
+    int 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 typed parameters
  * @nparams: number of parameters in the @params array
@@ -1015,6 +1027,6 @@ virTypedParamsFree(virTypedParameterPtr params,
                    int nparams)
 {
     virResetLastError();
-    virTypedParameterArrayClear(params, nparams);
+    virTypedParamsClear(params, nparams);
     VIR_FREE(params);
 }
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index d46e9fe..c777a55 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -25,8 +25,6 @@
 
 # include "internal.h"
 
-void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
-
 int virTypedParameterArrayValidate(virTypedParameterPtr params, int nparams,
                                    /* const char *name, int type ... */ ...)
     ATTRIBUTE_SENTINEL ATTRIBUTE_RETURN_CHECK;
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 9d50298..e84af59 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5369,7 +5369,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
         }
         cpu += ncpus;
         show_count -= ncpus;
-        virTypedParameterArrayClear(params, nparams * ncpus);
+        virTypedParamsClear(params, nparams * ncpus);
     }
     VIR_FREE(params);
 
-- 
1.8.1.1


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