summaryrefslogtreecommitdiffstats
path: root/vppinfra/vppinfra/vec.c
diff options
context:
space:
mode:
Diffstat (limited to 'vppinfra/vppinfra/vec.c')
-rw-r--r--vppinfra/vppinfra/vec.c62
1 files changed, 41 insertions, 21 deletions
diff --git a/vppinfra/vppinfra/vec.c b/vppinfra/vppinfra/vec.c
index 912038d56eb..f711679b0a4 100644
--- a/vppinfra/vppinfra/vec.c
+++ b/vppinfra/vppinfra/vec.c
@@ -40,23 +40,25 @@
/* Vector resize operator. Called as needed by various macros such as
vec_add1() when we need to allocate memory. */
-void * vec_resize_allocate_memory (void * v,
- word length_increment,
- uword data_bytes,
- uword header_bytes,
- uword data_align)
+void *
+vec_resize_allocate_memory (void *v,
+ word length_increment,
+ uword data_bytes,
+ uword header_bytes, uword data_align)
{
- vec_header_t * vh = _vec_find (v);
+ vec_header_t *vh = _vec_find (v);
uword old_alloc_bytes, new_alloc_bytes;
- void * old, * new;
+ void *old, *new;
header_bytes = vec_header_bytes (header_bytes);
data_bytes += header_bytes;
- if (! v)
+ if (!v)
{
- new = clib_mem_alloc_aligned_at_offset (data_bytes, data_align, header_bytes);
+ new =
+ clib_mem_alloc_aligned_at_offset (data_bytes, data_align,
+ header_bytes);
data_bytes = clib_mem_size (new);
memset (new, 0, data_bytes);
v = new + header_bytes;
@@ -80,12 +82,15 @@ void * vec_resize_allocate_memory (void * v,
if (new_alloc_bytes < data_bytes)
new_alloc_bytes = data_bytes;
- new = clib_mem_alloc_aligned_at_offset (new_alloc_bytes, data_align, header_bytes);
+ new =
+ clib_mem_alloc_aligned_at_offset (new_alloc_bytes, data_align,
+ header_bytes);
/* FIXME fail gracefully. */
- if (! new)
- clib_panic ("vec_resize fails, length increment %d, data bytes %d, alignment %d",
- length_increment, data_bytes, data_align);
+ if (!new)
+ clib_panic
+ ("vec_resize fails, length increment %d, data bytes %d, alignment %d",
+ length_increment, data_bytes, data_align);
clib_memcpy (new, old, old_alloc_bytes);
clib_mem_free (old);
@@ -98,10 +103,13 @@ void * vec_resize_allocate_memory (void * v,
memset (v + old_alloc_bytes, 0, new_alloc_bytes - old_alloc_bytes);
return v + header_bytes;
-}
+}
-uword clib_mem_is_vec_h (void * v, uword header_bytes)
-{ return clib_mem_is_heap_object (vec_header (v, header_bytes)); }
+uword
+clib_mem_is_vec_h (void *v, uword header_bytes)
+{
+ return clib_mem_is_heap_object (vec_header (v, header_bytes));
+}
/** \cond */
@@ -109,16 +117,18 @@ uword clib_mem_is_vec_h (void * v, uword header_bytes)
#include <stdio.h>
-void main (int argc, char * argv[])
+void
+main (int argc, char *argv[])
{
word n = atoi (argv[1]);
- word i, * x = 0;
+ word i, *x = 0;
- typedef struct {
+ typedef struct
+ {
word x, y, z;
} FOO;
- FOO * foos = vec_init (FOO, 10), * f;
+ FOO *foos = vec_init (FOO, 10), *f;
vec_validate (foos, 100);
foos[100].x = 99;
@@ -128,7 +138,9 @@ void main (int argc, char * argv[])
{
vec_add1 (x, i);
vec_add2 (foos, f, 1);
- f->x = 2*i; f->y = 3*i; f->z = 4*i;
+ f->x = 2 * i;
+ f->y = 3 * i;
+ f->z = 4 * i;
}
{
@@ -149,3 +161,11 @@ void main (int argc, char * argv[])
}
#endif
/** \endcond */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */