mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: alloc: Introduce virAppendElement helper
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>
This commit is contained in:
parent
853fb577d8
commit
51c8245847
@ -1760,6 +1760,7 @@ vir_g_strdup_vprintf;
|
||||
|
||||
|
||||
# util/viralloc.h
|
||||
virAppendElement;
|
||||
virDeleteElementsN;
|
||||
virExpandN;
|
||||
virInsertElementsN;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user