diff options
author | Chris Robinson <[email protected]> | 2014-04-13 20:26:04 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-13 20:26:04 -0700 |
commit | 219a0e6352c27c1fec52bebd4eccfddbc2813737 (patch) | |
tree | 3985dae3d0ecbb6daa3384e83c2a3056ac93bbcb /Alc | |
parent | 0ef87227c19f71c063d9d78871663f20402b5924 (diff) |
Add a GCC-specific VECTOR_INSERT
This version is capable of doing a compile-time type checks, to ensure the
objects being inserted are compatible with the vector data type. It should
otherwise be functionally identical.
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/vector.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Alc/vector.h b/Alc/vector.h index d12b8ad1..2d13dd6a 100644 --- a/Alc/vector.h +++ b/Alc/vector.h @@ -36,7 +36,19 @@ ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t ob #define VECTOR_ITER_END(_x) ((_x)->Data + VECTOR_SIZE((_x))) ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend); +#ifdef __GNUC__ +#define TYPE_CHECK(T1, T2) __builtin_types_compatible_p(T1, T2) +#define VECTOR_INSERT(_x, _i, _s, _e) __extension__({ \ + ALboolean _r; \ + static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_i))), "Incompatible insertion iterator"); \ + static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_s))), "Incompatible insertion source type"); \ + static_assert(TYPE_CHECK(__typeof(*(_s)), __typeof(*(_e))), "Incompatible iterator sources"); \ + _r = vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)); \ + _r; \ +}) +#else #define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e))) +#endif #define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \ (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE)) |