[PATCH 6/6] viralloc: Remove VIR_ALLOC_VAR

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

 



The use case VIR_ALLOC_VAR deals with is very unlikely. We had just 2
legitimate uses, which were reimplemented locally using g_malloc0 and
sizeof instead as they used a static number of members of the trailing
array.

Remove VIR_ALLOC_VAR since in most cases the direct implementation is
shorter and clearer and there are no users of it currently.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 -
 src/util/viralloc.c      | 33 ---------------------------------
 src/util/viralloc.h      | 35 -----------------------------------
 3 files changed, 69 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 30589c08ac..0636b0d8c9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1724,7 +1724,6 @@ vir_g_strdup_vprintf;


 # util/viralloc.h
-virAllocVar;
 virDeleteElementsN;
 virExpandN;
 virInsertElementsN;
diff --git a/src/util/viralloc.c b/src/util/viralloc.c
index e4dc13b776..1317537c8a 100644
--- a/src/util/viralloc.c
+++ b/src/util/viralloc.c
@@ -260,36 +260,3 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t at,
         virShrinkN(ptrptr, size, countptr, toremove);
     return 0;
 }
-
-/**
- * virAllocVar:
- * @ptrptr: pointer to hold address of allocated memory
- * @struct_size: size of initial struct
- * @element_size: size of array elements
- * @count: number of array elements to allocate
- *
- * Allocate struct_size bytes plus an array of 'count' elements, each
- * of size element_size.  This sort of allocation is useful for
- * receiving the data of certain ioctls and other APIs which return a
- * struct in which the last element is an array of undefined length.
- * The caller of this type of API is expected to know the length of
- * the array that will be returned and allocate a suitable buffer to
- * contain the returned data.  C99 refers to these variable length
- * objects as structs containing flexible array members.
- *
- * Returns -1 on failure, 0 on success
- */
-int virAllocVar(void *ptrptr,
-                size_t struct_size,
-                size_t element_size,
-                size_t count)
-{
-    size_t alloc_size = 0;
-
-    if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size))
-        abort();
-
-    alloc_size = struct_size + (element_size * count);
-    *(void **)ptrptr = g_malloc0(alloc_size);
-    return 0;
-}
diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index 29e3224818..e3027622c4 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -49,8 +49,6 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
 int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
                        size_t toremove, bool inPlace)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
-int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count)
-    G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1);

 /**
  * VIR_REALLOC_N:
@@ -292,39 +290,6 @@ int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t co
 #define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \
     virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, true)

-/**
- * VIR_ALLOC_VAR_OVERSIZED:
- * @M: size of base structure
- * @N: number of array elements in trailing array
- * @S: size of trailing array elements
- *
- * Check to make sure that the requested allocation will not cause
- * arithmetic overflow in the allocation size.
- */
-#define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N))
-
-/**
- * VIR_ALLOC_VAR:
- * @ptr: pointer to hold address of allocated memory
- * @type: element type of trailing array
- * @count: number of array elements to allocate
- *
- * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each
- * sizeof('type').  This sort of allocation is useful for receiving
- * the data of certain ioctls and other APIs which return a struct in
- * which the last element is an array of undefined length.  The caller
- * of this type of API is expected to know the length of the array
- * that will be returned and allocate a suitable buffer to contain the
- * returned data.  C99 refers to these variable length objects as
- * structs containing flexible array members.
- *
- * This macro is safe to use on arguments with side effects.
- *
- * Returns 0 on success, aborts on OOM
- */
-#define VIR_ALLOC_VAR(ptr, type, count) \
-    virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count))
-
 /**
  * VIR_FREE:
  * @ptr: pointer holding address to be freed
-- 
2.29.2




[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