vulkan/util: Make STACK_ARRAY() work for arrays of pointers
authorBoris Brezillon <boris.brezillon@collabora.com>
Wed, 16 Mar 2022 09:21:39 +0000 (02:21 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 25 Mar 2022 16:21:45 +0000 (16:21 +0000)
And add an explicit cast on the pointer returned by malloc() to
make C++ happy.

Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14766>

src/vulkan/util/vk_util.h

index 9c7ce6c..019ab5b 100644 (file)
@@ -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)