autodetect alignment during _vec_resize 33/12433/4
authorDamjan Marion <damarion@cisco.com>
Fri, 4 May 2018 18:45:41 +0000 (20:45 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Sat, 5 May 2018 01:20:53 +0000 (01:20 +0000)
Change-Id: I2896dbde78b5d58dc706756f4c76632c303557ae
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vppinfra/hash.c
src/vppinfra/heap.h
src/vppinfra/serialize.c
src/vppinfra/sparse_vec.h
src/vppinfra/vec.h

index 121fa38..79103b6 100644 (file)
@@ -685,7 +685,7 @@ _hash_create (uword elts, hash_t * h_user)
   if (h_user)
     log2_pair_size = h_user->log2_pair_size;
 
-  v = _vec_resize (0,
+  v = _vec_resize ((void *) 0,
                   /* vec len: */ elts,
                   /* data bytes: */
                   (elts << log2_pair_size) * sizeof (hash_pair_t),
index 8c1aae4..70e34cb 100644 (file)
@@ -220,7 +220,7 @@ uword heap_bytes (void *v);
 always_inline void *
 _heap_new (u32 len, u32 n_elt_bytes)
 {
-  void *v = _vec_resize (0, len, (uword) len * n_elt_bytes,
+  void *v = _vec_resize ((void *) 0, len, (uword) len * n_elt_bytes,
                         sizeof (heap_header_t),
                         HEAP_DATA_ALIGN);
   heap_header (v)->elt_bytes = n_elt_bytes;
index fe2146a..a098aa2 100644 (file)
@@ -313,7 +313,7 @@ unserialize_vector_ha (serialize_main_t * m,
   if (l > max_length)
     serialize_error (&m->header,
                     clib_error_create ("bad vector length %d", l));
-  p = v = _vec_resize (0, l, (uword) l * elt_bytes, header_bytes,
+  p = v = _vec_resize ((void *) 0, l, (uword) l * elt_bytes, header_bytes,
                       /* align */ align);
 
   while (l != 0)
@@ -444,7 +444,8 @@ unserialize_pool_helper (serialize_main_t * m,
       return 0;
     }
 
-  v = _vec_resize (0, l, (uword) l * elt_bytes, sizeof (p[0]), align);
+  v = _vec_resize ((void *) 0, l, (uword) l * elt_bytes, sizeof (p[0]),
+                  align);
   p = pool_header (v);
 
   vec_unserialize (m, &p->free_indices, unserialize_vec_32);
index ec8f0a1..0da154d 100644 (file)
@@ -76,7 +76,7 @@ sparse_vec_new (uword elt_bytes, uword sparse_index_bits)
 
   ASSERT (sparse_index_bits <= 16);
 
-  v = _vec_resize (0,
+  v = _vec_resize ((void *) 0,
                   /* length increment */ 8,
                   /* data bytes */ 8 * elt_bytes,
                   /* header bytes */ sizeof (h[0]),
index a029630..f233ae1 100644 (file)
@@ -111,10 +111,13 @@ void *vec_resize_allocate_memory (void *v,
     @return v_prime pointer to resized vector, may or may not equal v
 */
 
+#define _vec_resize(V,L,DB,HB,A) \
+  _vec_resize_inline(V,L,DB,HB,clib_max((__alignof__((V)[0])),(A)))
+
 always_inline void *
-_vec_resize (void *v,
-            word length_increment,
-            uword data_bytes, uword header_bytes, uword data_align)
+_vec_resize_inline (void *v,
+                   word length_increment,
+                   uword data_bytes, uword header_bytes, uword data_align)
 {
   vec_header_t *vh = _vec_find (v);
   uword new_data_bytes, aligned_header_bytes;