spa: utils: use SPA_N_ELEMENTS in for-each macros

This way the compiler is able to detect cases when
a pointer is specified instead of an array.

Furthermore, incompatible pointer types can also
be diagnosed in `SPA_FOR_EACH_ELEMENT()`.
This commit is contained in:
Barnabás Pőcze 2024-06-27 14:37:40 +02:00 committed by Wim Taymans
parent 7c40cafa7c
commit adc60af45b

View file

@ -133,10 +133,10 @@ struct spa_fraction {
* ```
*/
#define SPA_FOR_EACH_ELEMENT(arr, ptr) \
for ((ptr) = arr; (void*)(ptr) < SPA_PTROFF(arr, sizeof(arr), void); (ptr)++)
for ((ptr) = arr; (ptr) < (arr) + SPA_N_ELEMENTS(arr); (ptr)++)
#define SPA_FOR_EACH_ELEMENT_VAR(arr, var) \
for (__typeof__((arr)[0])* var = arr; (void*)(var) < SPA_PTROFF(arr, sizeof(arr), void); (var)++)
for (__typeof__((arr)[0])* var = arr; (var) < (arr) + SPA_N_ELEMENTS(arr); (var)++)
#define SPA_ABS(a) \
({ \