]> xenbits.xensource.com Git - libvirt.git/commitdiff
virTypedParamsFilter: Adjust return type and docs
authorPeter Krempa <pkrempa@redhat.com>
Fri, 27 Sep 2024 08:55:00 +0000 (10:55 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Oct 2024 10:57:02 +0000 (12:57 +0200)
The 'virTypedParamsFilter' function can't fail and thus it never returns
negative values. Change the return type to 'size_t' and adjust callers
to not check the return value for being negative.

Adjust the docs to hilight this and also the fact that the filtered
typed param list returned via @ret is not a deep copy and thus callers
must not use the common function to free it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/util/virtypedparam.c
src/util/virtypedparam.h

index 1be249d855406a536d29fb1550e1145fdf658b91..634385aa977a21798d1dafdacf40baa9a01523a7 100644 (file)
@@ -394,18 +394,22 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
  * @ret: pointer to the returned array
  *
  * Filters @params retaining only the parameters named @name in the
- * resulting array @ret. Caller should free the @ret array but not
- * the items since they are pointing to the @params elements.
+ * resulting array @ret.
  *
- * Returns amount of elements in @ret on success, -1 on error.
+ * Important Caller should free the @ret array but not the items since they are
+ * pointing to the @params elements. I.e. callers must not use
+ * 'virTypedParamsFree' or equivalent on pointer returned via @ret.
+ *
+ * Returns amount of elements in @ret.
  */
-int
+size_t
 virTypedParamsFilter(virTypedParameterPtr params,
                      int nparams,
                      const char *name,
                      virTypedParameterPtr **ret)
 {
-    size_t i, n = 0;
+    size_t i;
+    size_t n = 0;
 
     *ret = g_new0(virTypedParameterPtr, nparams);
 
@@ -443,7 +447,7 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
                             const char ***values)
 {
     size_t i, n;
-    int nfiltered;
+    size_t nfiltered;
     virTypedParameterPtr *filtered = NULL;
 
     virCheckNonNullArgGoto(values, error);
@@ -451,9 +455,6 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
 
     nfiltered = virTypedParamsFilter(params, nparams, name, &filtered);
 
-    if (nfiltered < 0)
-        goto error;
-
     if (nfiltered)
         *values = g_new0(const char *, nfiltered);
 
index 7454ef3ce0f986561e5d9b696f12eb990a0acb9d..afd923aacbcc7c6b0452fad034471b90a96ecc10 100644 (file)
@@ -81,7 +81,7 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
                             int nparams,
                             const char *name,
                             const char ***values);
-int
+size_t
 virTypedParamsFilter(virTypedParameterPtr params,
                      int nparams,
                      const char *name,