aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorAndreas Schultz <andreas.schultz@travelping.com>2020-03-26 14:18:52 +0000
committerDamjan Marion <dmarion@me.com>2020-04-28 21:16:58 +0000
commitc458c493667bde30c22760e3a1839f2cac6e6447 (patch)
treed5e9d4ae3cdcb01266887c9d1ba9c0e83bec8103 /src/vppinfra
parent24e2c50bf34af37b688df83cd8d39a58345349c5 (diff)
vppinfra: type prove vec_new and vec_resize
Some vector functions (e.g. vec_new) pass the vector pointer through vec_resize. This turn the pointer from a real type into a void pointer. Explicitly cast the pointer back to its original type to catch type mismatches. Type: improvement Signed-off-by: Andreas Schultz <andreas.schultz@travelping.com> Change-Id: Id13e52d4f038af2cee28e5abf1aca720f8909378
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/vec.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h
index e9836107799..df913c2b144 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -116,8 +116,12 @@ void *vec_resize_allocate_memory (void *v,
@return v_prime pointer to resized vector, may or may not equal v
*/
-#define _vec_resize_numa(V,L,DB,HB,A,S) \
- _vec_resize_inline(V,L,DB,HB,clib_max((__alignof__((V)[0])),(A)),(S))
+#define _vec_resize_numa(V,L,DB,HB,A,S) \
+({ \
+ __typeof__ ((V)) _V; \
+ _V = _vec_resize_inline(V,L,DB,HB,clib_max((__alignof__((V)[0])),(A)),(S)); \
+ _V; \
+})
#define _vec_resize(V,L,DB,HB,A) \
_vec_resize_numa(V,L,DB,HB,A,VEC_NUMA_UNSPECIFIED)
@@ -330,10 +334,10 @@ do { \
@param A alignment (may be zero)
@return V new vector
*/
-#define vec_new_ha(T,N,H,A) \
-({ \
- word _v(n) = (N); \
- _vec_resize ((T *) 0, _v(n), _v(n) * sizeof (T), (H), (A)); \
+#define vec_new_ha(T,N,H,A) \
+({ \
+ word _v(n) = (N); \
+ (T *)_vec_resize ((T *) 0, _v(n), _v(n) * sizeof (T), (H), (A)); \
})
/** \brief Create new vector of given type and length