[PATCH v3 08/25] util: typedparam: Introduce 'virTypedParamListConcat'

Peter Krempa posted 25 patches 2 years, 9 months ago
[PATCH v3 08/25] util: typedparam: Introduce 'virTypedParamListConcat'
Posted by Peter Krempa 2 years, 9 months ago
Introduce a helper function to concatenate two virTypedParamLists. This
will allow us to refactor qemuDomainGetStatsBlock to not access the list
directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/virtypedparam.c | 24 ++++++++++++++++++++++++
 src/util/virtypedparam.h |  4 ++++
 3 files changed, 29 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c596ef0f87..0f42c2de0b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3555,6 +3555,7 @@ virTypedParamListAddLLong;
 virTypedParamListAddString;
 virTypedParamListAddUInt;
 virTypedParamListAddULLong;
+virTypedParamListConcat;
 virTypedParamListFree;
 virTypedParamListFromParams;
 virTypedParamListNew;
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index de3a4e76b4..f8dce9ed98 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -712,6 +712,30 @@ virTypedParamListNew(void)
 }


+/**
+ * virTypedParamListConcat:
+ *
+ * @to: typed param list to concatenate into
+ * @fromptr: pointer to pointer to a typed param list to concatenate into @from
+ *
+ * Concatenates all params from the virTypedParamList pointed to by @fromptr
+ * into @to and deallocates the list pointed to by @fromptr and clears the
+ * variable.
+ */
+void
+virTypedParamListConcat(virTypedParamList *to,
+                        virTypedParamList **fromptr)
+{
+    g_autoptr(virTypedParamList) from = g_steal_pointer(fromptr);
+
+    VIR_RESIZE_N(to->par, to->par_alloc, to->npar, from->npar);
+
+    memcpy(to->par + to->npar, from->par, sizeof(*(to->par)) * from->npar);
+    to->npar += from->npar;
+    from->npar = 0;
+}
+
+
 void
 virTypedParamListFree(virTypedParamList *list)
 {
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index 4aa597bc81..45422c2673 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -156,6 +156,10 @@ virTypedParamList *
 virTypedParamListFromParams(virTypedParameterPtr *params,
                             size_t nparams);

+void
+virTypedParamListConcat(virTypedParamList *to,
+                        virTypedParamList **fromptr);
+
 int
 virTypedParamListAddInt(virTypedParamList *list,
                         int value,
-- 
2.39.2
Re: [PATCH v3 08/25] util: typedparam: Introduce 'virTypedParamListConcat'
Posted by Martin Kletzander 2 years, 9 months ago
On Wed, Apr 19, 2023 at 02:04:25PM +0200, Peter Krempa wrote:
>Introduce a helper function to concatenate two virTypedParamLists. This
>will allow us to refactor qemuDomainGetStatsBlock to not access the list
>directly.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/libvirt_private.syms |  1 +
> src/util/virtypedparam.c | 24 ++++++++++++++++++++++++
> src/util/virtypedparam.h |  4 ++++
> 3 files changed, 29 insertions(+)
>
>diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>index c596ef0f87..0f42c2de0b 100644
>--- a/src/libvirt_private.syms
>+++ b/src/libvirt_private.syms
>@@ -3555,6 +3555,7 @@ virTypedParamListAddLLong;
> virTypedParamListAddString;
> virTypedParamListAddUInt;
> virTypedParamListAddULLong;
>+virTypedParamListConcat;
> virTypedParamListFree;
> virTypedParamListFromParams;
> virTypedParamListNew;
>diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
>index de3a4e76b4..f8dce9ed98 100644
>--- a/src/util/virtypedparam.c
>+++ b/src/util/virtypedparam.c
>@@ -712,6 +712,30 @@ virTypedParamListNew(void)
> }
>
>
>+/**
>+ * virTypedParamListConcat:
>+ *
>+ * @to: typed param list to concatenate into
>+ * @fromptr: pointer to pointer to a typed param list to concatenate into @from
>+ *
                                                                              ^
                                                                              |
These two lines are terrible to read, but I think you meant @to here --------´

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Re: [PATCH v3 08/25] util: typedparam: Introduce 'virTypedParamListConcat'
Posted by Ján Tomko 2 years, 9 months ago
On a Wednesday in 2023, Peter Krempa wrote:
>Introduce a helper function to concatenate two virTypedParamLists. This
>will allow us to refactor qemuDomainGetStatsBlock to not access the list
>directly.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/libvirt_private.syms |  1 +
> src/util/virtypedparam.c | 24 ++++++++++++++++++++++++
> src/util/virtypedparam.h |  4 ++++
> 3 files changed, 29 insertions(+)
>
>diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>index c596ef0f87..0f42c2de0b 100644
>--- a/src/libvirt_private.syms
>+++ b/src/libvirt_private.syms
>@@ -3555,6 +3555,7 @@ virTypedParamListAddLLong;
> virTypedParamListAddString;
> virTypedParamListAddUInt;
> virTypedParamListAddULLong;
>+virTypedParamListConcat;
> virTypedParamListFree;
> virTypedParamListFromParams;
> virTypedParamListNew;
>diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
>index de3a4e76b4..f8dce9ed98 100644
>--- a/src/util/virtypedparam.c
>+++ b/src/util/virtypedparam.c
>@@ -712,6 +712,30 @@ virTypedParamListNew(void)
> }
>
>
>+/**
>+ * virTypedParamListConcat:
>+ *
>+ * @to: typed param list to concatenate into
>+ * @fromptr: pointer to pointer to a typed param list to concatenate into @from

*to concatenate into @to

Jano