From 7e0ab29cfd7edbbee27d913230bfea576c6e1867 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 16 Mar 2022 02:21:39 -0700 Subject: [PATCH] vulkan/util: Make STACK_ARRAY() work for arrays of pointers And add an explicit cast on the pointer returned by malloc() to make C++ happy. Reviewed-by: Jason Ekstrand Part-of: --- src/vulkan/util/vk_util.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index 9c7ce6c..019ab5b 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -279,8 +279,9 @@ vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info, #define STACK_ARRAY_SIZE 8 #define STACK_ARRAY(type, name, size) \ - type _stack_##name[STACK_ARRAY_SIZE] = {0}, *const name = \ - (size) <= STACK_ARRAY_SIZE ? _stack_##name : malloc((size) * sizeof(type)) + type _stack_##name[STACK_ARRAY_SIZE] = {0}; \ + type *const name = \ + ((size) <= STACK_ARRAY_SIZE ? _stack_##name : (type *)malloc((size) * sizeof(type))) #define STACK_ARRAY_FINISH(name) \ if (name != _stack_##name) free(name) -- 2.7.4