diff options
author | C Stout <[email protected]> | 2020-01-16 15:05:06 -0800 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-01-17 22:21:00 +0000 |
commit | c1104e4ceefd4949a33421da9db6be437e801ce9 (patch) | |
tree | 8614ff5ef5ae8cdfef32d6a191c5b8cb0847245b /src/util/u_vector.h | |
parent | b54b67e067da6ed22a7b8112cb6f8bed0e188272 (diff) |
util/vector: Fix u_vector_foreach when head rolls over
Also add unit tests for u_vector.
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3453>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3453>
Diffstat (limited to 'src/util/u_vector.h')
-rw-r--r-- | src/util/u_vector.h | 11 |
1 files changed, 9 insertions, 2 deletions
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 <stdlib.h> #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 |