util: add UTIL_DYNARRAY_INIT sentinel

We have the invariant that zero-initializing is legal but it's not
obvious in the source code, so add a sentinel value for it to make code
that uses it crystal clear.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38189>
This commit is contained in:
Alyssa Rosenzweig 2025-10-31 13:46:42 -04:00 committed by Marge Bot
parent 6f138fe723
commit f6f23dfdd1

View file

@ -38,11 +38,8 @@ extern "C" {
extern unsigned util_dynarray_is_data_stack_allocated;
/* A zero-initialized version of this is guaranteed to represent an
* empty array.
*
* Also, size <= capacity and data != 0 if and only if capacity != 0
* capacity will always be the allocation size of data
/* Size <= capacity and data != 0 if and only if capacity != 0 capacity will
* always be the allocation size of data.
*/
struct util_dynarray
{
@ -52,6 +49,13 @@ struct util_dynarray
unsigned capacity;
};
/* A zero-initialized util_dynarray represents an empty array. */
#ifdef __cplusplus
#define UTIL_DYNARRAY_INIT { 0 }
#else
#define UTIL_DYNARRAY_INIT (struct util_dynarray){ .capacity = 0 }
#endif
static inline void
util_dynarray_init(struct util_dynarray *buf, void *mem_ctx)
{