From c1104e4ceefd4949a33421da9db6be437e801ce9 Mon Sep 17 00:00:00 2001 From: C Stout Date: Thu, 16 Jan 2020 15:05:06 -0800 Subject: util/vector: Fix u_vector_foreach when head rolls over Also add unit tests for u_vector. Tested-by: Marge Bot Part-of: --- src/util/u_vector.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/util/u_vector.h') diff --git a/src/util/u_vector.h b/src/util/u_vector.h index 95f35c59c7d..8edd63895a6 100644 --- a/src/util/u_vector.h +++ b/src/util/u_vector.h @@ -33,6 +33,10 @@ #include #include "util/macros.h" +#ifdef __cplusplus +extern "C" { +#endif + /* TODO - move to u_math.h - name it better etc */ static inline uint32_t u_align_u32(uint32_t v, uint32_t a) @@ -80,16 +84,19 @@ u_vector_finish(struct u_vector *queue) free(queue->data); } -#ifndef __GNUC__ +#if !defined(__GNUC__) || defined(__cplusplus) #define __builtin_types_compatible_p(t1, t2) 1 #endif #define u_vector_foreach(elem, queue) \ STATIC_ASSERT(__builtin_types_compatible_p(__typeof__(queue), struct u_vector *)); \ for (uint32_t __u_vector_offset = (queue)->tail; \ - elem = (void *)((char *)(queue)->data + (__u_vector_offset & ((queue)->size - 1))), __u_vector_offset < (queue)->head; \ + elem = (void *)((char *)(queue)->data + (__u_vector_offset & ((queue)->size - 1))), __u_vector_offset != (queue)->head; \ __u_vector_offset += (queue)->element_size) +#ifdef __cplusplus +} +#endif #endif -- cgit v1.2.3