void *pa_dynarray_get(pa_dynarray *array, unsigned i) {
pa_assert(array);
- pa_assert(i < array->n_entries);
+
+ if (i >= array->n_entries)
+ return NULL;
return array->data[i];
}
void pa_dynarray_free(pa_dynarray *array);
void pa_dynarray_append(pa_dynarray *array, void *p);
+
+/* Returns NULL if i is out of bounds. */
void *pa_dynarray_get(pa_dynarray *array, unsigned i);
/* Returns the removed item, or NULL if the array is empty. */
unsigned pa_dynarray_size(pa_dynarray *array);
void * const *pa_dynarray_get_raw_array(pa_dynarray *array);
+#define PA_DYNARRAY_FOREACH(elem, array, idx) \
+ for ((idx) = 0; ((elem) = pa_dynarray_get(array, idx)); (idx)++)
+
#endif