mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 15:10:10 +01:00
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:
parent
6f138fe723
commit
f6f23dfdd1
1 changed files with 9 additions and 5 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue