]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: alloc: Introduce virAppendElement helper
authorPeter Krempa <pkrempa@redhat.com>
Tue, 3 Aug 2021 12:11:23 +0000 (14:11 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 6 Aug 2021 06:53:25 +0000 (08:53 +0200)
The new wrapper calls virInsertElementInternal with the appropriate
arguments without any checks which are unnecessary for appension. This
allows to have no return value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/viralloc.c
src/util/viralloc.h

index aed40977b3339cfafbfd1a932a31f3560245c969..e4168a06b962ff10f866b9ad868911f1d7d65820 100644 (file)
@@ -1760,6 +1760,7 @@ vir_g_strdup_vprintf;
 
 
 # util/viralloc.h
+virAppendElement;
 virDeleteElementsN;
 virExpandN;
 virInsertElementsN;
index c1211a5f23efb83da0d8d2c2efebe6522d037812..17ce5f3dbe051bffa8a655b54dc5e9b2d3c075a1 100644 (file)
@@ -260,6 +260,36 @@ virInsertElementsN(void *ptrptr,
 }
 
 
+/**
+ * virAppendElement:
+ * @ptrptr:   pointer to hold address of allocated memory
+ * @size:     the size of one element in bytes
+ * @countptr: variable tracking number of elements currently allocated
+ * @typematchDummy: helper variable to consume results of compile time checks
+ * @newelem: pointer to a new element to append to @ptrptr
+ *           (the original will be zeroed out if clearOriginal is true)
+ * @clearOriginal: false if the new item in the array should be copied
+ *            from the original, and the original left intact.
+ *            true if the original should be 0'd out on success.
+ * @inPlace:  false if we should expand the allocated memory before
+ *            moving, true if we should assume someone else *has
+ *            already* done that.
+ *
+ * Re-allocate @ptrptr to fit an extra element and place @newelem at the end.
+ */
+void
+virAppendElement(void *ptrptr,
+                 size_t size,
+                 size_t *countptr,
+                 size_t typematchDummy G_GNUC_UNUSED,
+                 void *newelem,
+                 bool clearOriginal,
+                 bool inPlace)
+{
+    virInsertElementInternal(ptrptr, size, *countptr, countptr, newelem, clearOriginal, inPlace);
+}
+
+
 /**
  * virDeleteElementsN:
  * @ptrptr:   pointer to hold address of allocated memory
index b637bc2ca4e01d2c150cbae709ca26af27706c63..7669b12e895a193b32bb2bbb0cc50da429ffdd83 100644 (file)
@@ -46,6 +46,14 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
                        size_t typematchDummy, void *newelem,
                        bool clearOriginal, bool inPlace)
     G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+void virAppendElement(void *ptrptr,
+                      size_t size,
+                      size_t *countptr,
+                      size_t typematchDummy,
+                      void *newelem,
+                      bool clearOriginal,
+                      bool inPlace)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
 int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
                        size_t toremove, bool inPlace)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);