From 5b4c3a2f944283317025f44fe108d56f1ca2b60f Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 21 Mar 2019 15:36:16 -0500 Subject: [PATCH] comp: Use U_TYPED_CALLOC/U_TYPED_ARRAY_CALLOC --- src/xrt/compositor/common/comp_vk.c | 5 +++-- src/xrt/compositor/common/comp_vk_swapchain.c | 15 ++++++++------- src/xrt/compositor/main/comp_renderer.c | 8 +++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/xrt/compositor/common/comp_vk.c b/src/xrt/compositor/common/comp_vk.c index 0ad488760..54f1f0a31 100644 --- a/src/xrt/compositor/common/comp_vk.c +++ b/src/xrt/compositor/common/comp_vk.c @@ -12,7 +12,9 @@ #include #include +#include "util/u_misc.h" #include "util/u_debug.h" + #include "common/comp_vk.h" @@ -847,8 +849,7 @@ vk_find_graphics_queue(struct vk_bundle *vk, uint32_t *out_graphics_queue) &num_queues, NULL); VkQueueFamilyProperties *queue_family_props = - (VkQueueFamilyProperties *)malloc(sizeof(VkQueueFamilyProperties) * - num_queues); + U_TYPED_ARRAY_CALLOC(VkQueueFamilyProperties, num_queues); vk->vkGetPhysicalDeviceQueueFamilyProperties( vk->physical_device, &num_queues, queue_family_props); diff --git a/src/xrt/compositor/common/comp_vk_swapchain.c b/src/xrt/compositor/common/comp_vk_swapchain.c index 1a6c95207..ed054c036 100644 --- a/src/xrt/compositor/common/comp_vk_swapchain.c +++ b/src/xrt/compositor/common/comp_vk_swapchain.c @@ -14,6 +14,8 @@ #include #include +#include "util/u_misc.h" + #include "comp_vk_swapchain.h" @@ -241,8 +243,7 @@ _find_surface_format(struct vk_swapchain *sc, sc->vk->physical_device, surface, &num_formats, NULL); if (num_formats != 0) { - formats = (VkSurfaceFormatKHR *)malloc( - sizeof(VkSurfaceFormatKHR) * num_formats); + formats = U_TYPED_ARRAY_CALLOC(VkSurfaceFormatKHR, num_formats); sc->vk->vkGetPhysicalDeviceSurfaceFormatsKHR( sc->vk->physical_device, surface, &num_formats, formats); } else { @@ -276,8 +277,8 @@ _check_surface_present_mode(struct vk_bundle *vk, vk->physical_device, surface, &num_present_modes, NULL); if (num_present_modes != 0) { - present_modes = (VkPresentModeKHR *)malloc( - sizeof(VkPresentModeKHR) * num_present_modes); + present_modes = + U_TYPED_ARRAY_CALLOC(VkPresentModeKHR, num_present_modes); vk->vkGetPhysicalDeviceSurfacePresentModesKHR( vk->physical_device, surface, &num_present_modes, present_modes); @@ -306,7 +307,7 @@ vk_swapchain_create_image_views(struct vk_swapchain *sc) assert(sc->image_count > 0); VK_DEBUG(sc->vk, "Creating %d image views.", sc->image_count); - VkImage *images = (VkImage *)malloc(sizeof(VkImage) * sc->image_count); + VkImage *images = U_TYPED_ARRAY_CALLOC(VkImage, sc->image_count); sc->vk->vkGetSwapchainImagesKHR(sc->vk->device, sc->swap_chain, &sc->image_count, images); @@ -314,8 +315,8 @@ vk_swapchain_create_image_views(struct vk_swapchain *sc) free(sc->buffers); } - sc->buffers = (struct vk_swapchain_buffer *)malloc( - sizeof(struct vk_swapchain_buffer) * sc->image_count); + sc->buffers = + U_TYPED_ARRAY_CALLOC(struct vk_swapchain_buffer, sc->image_count); for (uint32_t i = 0; i < sc->image_count; i++) { sc->buffers[i].image = images[i]; diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index 9a8c47e21..6a312ad17 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -13,6 +13,8 @@ #include #include +#include "util/u_misc.h" + #include "xrt/xrt_compositor.h" #include "main/comp_distortion.h" @@ -144,7 +146,7 @@ renderer_destroy(struct comp_renderer *r); struct comp_renderer * comp_renderer_create(struct comp_compositor *c) { - struct comp_renderer *r = malloc(sizeof(struct comp_renderer)); + struct comp_renderer *r = U_TYPED_CALLOC(struct comp_renderer); renderer_create(r, c); renderer_init(r); @@ -690,7 +692,7 @@ renderer_allocate_command_buffers(struct comp_renderer *r, uint32_t count) r->num_cmd_buffers = count; - r->cmd_buffers = malloc(sizeof(VkCommandBuffer) * count); + r->cmd_buffers = U_TYPED_ARRAY_CALLOC(VkCommandBuffer, count); VkCommandBufferAllocateInfo cmd_buffer_info = { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, @@ -797,7 +799,7 @@ renderer_create_frame_buffers(struct comp_renderer *r, uint32_t count) if (r->frame_buffers != NULL) free(r->frame_buffers); - r->frame_buffers = malloc(sizeof(VkFramebuffer) * count); + r->frame_buffers = U_TYPED_ARRAY_CALLOC(VkFramebuffer, count); for (uint32_t i = 0; i < count; i++) { VkImageView attachments[1] = {