[PATCH 03/23] util: alloc: Introduce virAppendElement helper

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

 



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@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/viralloc.c      | 30 ++++++++++++++++++++++++++++++
 src/util/viralloc.h      |  8 ++++++++
 3 files changed, 39 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6961cdb137..97ff884f7e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1760,6 +1760,7 @@ vir_g_strdup_vprintf;


 # util/viralloc.h
+virAppendElement;
 virDeleteElementsN;
 virExpandN;
 virInsertElementsN;
diff --git a/src/util/viralloc.c b/src/util/viralloc.c
index c1211a5f23..17ce5f3dbe 100644
--- a/src/util/viralloc.c
+++ b/src/util/viralloc.c
@@ -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
diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index b637bc2ca4..7669b12e89 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -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);
-- 
2.31.1




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

  Powered by Linux