* @size: the size of one element in bytes
* @at: index within array where new elements should be added, -1 for end
* @countptr: variable tracking number of elements currently allocated
- * @add: number of elements to add
+ * @typematchDummy: helper variable to consume results of compile time checks
* @newelems: pointer to array of one or more new elements to move into
* place (the originals will be zeroed out if successful
* and if clearOriginal is true)
* already* done that.
*
* Re-allocate an array of *countptr elements, each sizeof(*ptrptr) bytes
- * long, to be *countptr+add elements long, then appropriately move
- * the elements starting at ptrptr[at] up by add elements, copy the
+ * long, to be *countptr elements long, then appropriately move
+ * the elements starting at ptrptr[at] up by 1 elements, copy the
* items from newelems into ptrptr[at], then store the address of
* allocated memory in *ptrptr and the new size in *countptr. If
* newelems is NULL, the new elements at ptrptr[at] are instead filled
int
virInsertElementsN(void *ptrptr, size_t size, size_t at,
size_t *countptr,
- size_t add, void *newelems,
+ size_t typematchDummy G_GNUC_UNUSED,
+ void *newelems,
bool clearOriginal, bool inPlace)
{
if (at == -1) {
at = *countptr;
} else if (at > *countptr) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("out of bounds index - count %zu at %zu add %zu"),
- *countptr, at, add);
+ _("out of bounds index - count %zu at %zu"),
+ *countptr, at);
return -1;
}
if (inPlace) {
- *countptr += add;
+ *countptr += 1;
} else {
- virExpandN(ptrptr, size, countptr, add);
+ virExpandN(ptrptr, size, countptr, 1);
}
/* memory was successfully re-allocated. Move up all elements from
* from their original location. Remember that *countptr has
* already been updated with new element count!
*/
- if (at < *countptr - add) {
- memmove(*(char**)ptrptr + (size * (at + add)),
+ if (at < *countptr - 1) {
+ memmove(*(char**)ptrptr + (size * (at + 1)),
*(char**)ptrptr + (size * at),
- size * (*countptr - add - at));
+ size * (*countptr - 1 - at));
}
if (newelems) {
- memcpy(*(char**)ptrptr + (size * at), newelems, size * add);
+ memcpy(*(char**)ptrptr + (size * at), newelems, size);
if (clearOriginal)
- memset((char*)newelems, 0, size * add);
- } else if (inPlace || (at < *countptr - add)) {
+ memset((char*)newelems, 0, size);
+ } else if (inPlace || (at < *countptr - 1)) {
/* NB: if inPlace, assume memory at the end wasn't initialized */
- memset(*(char**)ptrptr + (size * at), 0, size * add);
+ memset(*(char**)ptrptr + (size * at), 0, size);
}
return 0;
void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
- size_t add, void *newelem,
+ size_t typematchDummy, void *newelem,
bool clearOriginal, bool inPlace)
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
* VIR_INSERT_ELEMENT_INPLACE is identical, but assumes any necessary
* memory re-allocation has already been done.
*
- * Both functions need to send "1" as the "add" argument to
- * virInsertElementsN (which has the currently-unused capability of
- * inserting multiple items at once). We use this to our advantage by
- * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be
- * assured ptr and &newelem are of compatible types.
- *
* These macros are safe to use on arguments with side effects.
*
* Returns -1 on failure (with OOM error reported), 0 on success
* VIR_APPEND_ELEMENT_*INPLACE are identical, but assume any
* necessary memory re-allocation has already been done.
*
- * VIR_APPEND_ELEMENT_* all need to send "1" as the "add" argument to
- * virInsertElementsN (which has the currently-unused capability of
- * inserting multiple items at once). We use this to our advantage by
- * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be
- * assured ptr and &newelem are of compatible types.
- *
* These macros are safe to use on arguments with side effects.
*
* Returns -1 on failure (with OOM error reported), 0 on success