aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/u_dynarray.h
Commit message (Collapse)AuthorAgeFilesLines
* u_dynarray: turn util_dynarray_{grow, resize} into element-oriented macrosNicolai Hähnle2019-06-121-14/+32
| | | | | | | | | | | | | | | | | | | | | | | | The main motivation for this change is API ergonomics: most operations on dynarrays are really on elements, not on bytes, so it's weird to have grow and resize as the odd operations out. The secondary motivation is memory safety. Users of the old byte-oriented functions would often multiply a number of elements with the element size, which could overflow, and checking for overflow is tedious. With this change, we only need to implement the overflow checks once. The checks are cheap: since eltsize is a compile-time constant and the functions should be inlined, they only add a single comparison and an unlikely branch. v2: - ensure operations are no-op when allocation fails - in util_dynarray_clone, call resize_bytes with a compile-time constant element size v3: - fix iris, lima, panfrost Reviewed-by: Marek Olšák <[email protected]>
* u_dynarray: return 0 on realloc failure and ensure no-opNicolai Hähnle2019-06-121-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | We're not very good at handling out-of-memory conditions in general, but this change at least gives the caller the option of handling it gracefully and without memory leaks. This happens to fix an error in out-of-memory handling in i965, which has the following code in brw_bufmgr.c: node = util_dynarray_grow(vma_list, sizeof(struct vma_bucket_node)); if (unlikely(!node)) return 0ull; Previously, allocation failure for util_dynarray_grow wouldn't actually return NULL when the dynarray was previously non-empty. v2: - make util_dynarray_ensure_cap a no-op on failure, add MUST_CHECK attribute - simplify the new capacity calculation: aside from avoiding a useless loop when newcap is very large, this also avoids an infinite loop when newcap is larger than 1 << 31 Reviewed-by: Marek Olšák <[email protected]>
* u_dynarray: add util_dynarray_grow_capQiang Yu2019-04-111-6/+17
| | | | | | | | | | | | | This is for the case that user only know a max size it wants to append to the array and enlarge the array capacity before writing into it. v2: - rename newsize to newcap - rename util_dynarray_enlarge to util_dynarray_grow_cap Signed-off-by: Qiang Yu <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
* util: s/0/NULL/ for pointerEric Engestrom2018-10-301-1/+1
| | | | | Signed-off-by: Eric Engestrom <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
* util: Add foreach_reverse for dynarrayCaio Marcelo de Oliveira Filho2018-10-151-0/+6
| | | | | | | | | Useful to walk the array removing elements by swapping them with the last element. v2: Change iteration to make sure we never underflow. (Jason) Reviewed-by: Jason Ekstrand <[email protected]>
* util: Add macro to get number of elements in dynarrayCaio Marcelo de Oliveira Filho2018-09-211-0/+1
| | | | Reviewed-by: Christian Gmeiner <[email protected]>
* util/dynarray: add a clone functionCaio Marcelo de Oliveira Filho2018-08-221-0/+9
| | | | | | | v2: Fix mem_ctx parameter type. (Thomas) Reviewed-by: Thomas Helland <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* util: include string.h in u_dynarray.hBrian Paul2018-01-171-0/+1
| | | | | | To get memset() prototype. Reviewed-by: Nicolai Hähnle <[email protected]>
* mesa/util: add util_dynarray_clear() helperSamuel Pitoiset2017-06-181-0/+6
| | | | | Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
* mesa/util: add new util_dynarray_delete_unordered helperSamuel Pitoiset2017-06-141-0/+14
| | | | | | | | This helper function will be used for managing dynamic arrays of resident texture/image handles. Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Nicolai Hähnle <[email protected]>
* u_dynarray: fix coverity warning about ignoring return value from rerallocDave Airlie2017-06-131-1/+1
| | | | | | | | >>> Ignoring storage allocated by "reralloc_size(buf->mem_ctx, buf->data, buf->size)" leaks it. Reviewed-by: Thomas Helland<[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
* util: Add extern c to u_dynarray.hThomas Helland2017-06-071-0/+8
| | | | | Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
* util: Port nir_array functionality to u_dynarrayThomas Helland2017-06-071-10/+37
| | | | | Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
* util: Remove unused includes and convert to lower-case memory opsThomas Helland2017-06-071-15/+12
| | | | | | | | Also, prepare for the next commit by correcting some coding style changes. This should be all non-functional changes. Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
* util: Move u_dynarray to src/utilThomas Helland2017-06-071-0/+114
This will be used as the basis for unification Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>