X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fvppinfra%2Fvec.h;h=1fcb5f1a37471c06cbc34b058227c4ca8ec384ac;hb=06d82260d9913dbb6be98aef00830ef4967b1f55;hp=9054eaa5e5778b27420d4786aad3de4b8c4dc9eb;hpb=a690fdbfe179e0ea65818c03b52535bf9210efd0;p=vpp.git diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h index 9054eaa5e57..1fcb5f1a374 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((void *)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 @@ -375,6 +379,8 @@ do { \ */ #define vec_free(V) vec_free_h(V,0) +void vec_free_not_inline (void *v); + /**\brief Free vector user header (syntactic sugar) @param h vector header @void @@ -1040,12 +1046,16 @@ do { \ /** \brief Sort a vector using the supplied element comparison function + Does not depend on the underlying implementation to deal correctly + with null, zero-long, or 1-long vectors + @param vec vector to sort @param f comparison function */ -#define vec_sort_with_function(vec,f) \ -do { \ - qsort (vec, vec_len (vec), sizeof (vec[0]), (void *) (f)); \ +#define vec_sort_with_function(vec,f) \ +do { \ + if (vec_len (vec) > 1) \ + qsort (vec, vec_len (vec), sizeof (vec[0]), (void *) (f)); \ } while (0) /** \brief Make a vector containing a NULL terminated c-string.