xrt: Use U_TYPED_CALLOC

This commit is contained in:
Ryan Pavlik 2019-03-21 15:19:52 -05:00
parent e57e858351
commit f7d990c7e3
16 changed files with 36 additions and 25 deletions

View file

@ -11,6 +11,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "client/comp_gl_api.h" #include "client/comp_gl_api.h"
#include "client/comp_gl_client.h" #include "client/comp_gl_client.h"
@ -185,7 +187,7 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
} }
struct client_gl_swapchain *sc = struct client_gl_swapchain *sc =
calloc(1, sizeof(struct client_gl_swapchain)); U_TYPED_CALLOC(struct client_gl_swapchain);
sc->base.base.destroy = client_gl_swapchain_destroy; sc->base.base.destroy = client_gl_swapchain_destroy;
sc->base.base.acquire_image = client_gl_swapchain_acquire_image; sc->base.base.acquire_image = client_gl_swapchain_acquire_image;
sc->base.base.wait_image = client_gl_swapchain_wait_image; sc->base.base.wait_image = client_gl_swapchain_wait_image;

View file

@ -11,6 +11,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "comp_vk_client.h" #include "comp_vk_client.h"
@ -199,7 +201,7 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
}; };
struct client_vk_swapchain *sc = struct client_vk_swapchain *sc =
calloc(1, sizeof(struct client_vk_swapchain)); U_TYPED_CALLOC(struct client_vk_swapchain);
sc->base.base.destroy = client_vk_swapchain_destroy; sc->base.base.destroy = client_vk_swapchain_destroy;
sc->base.base.acquire_image = client_vk_swapchain_acquire_image; sc->base.base.acquire_image = client_vk_swapchain_acquire_image;
sc->base.base.wait_image = client_vk_swapchain_wait_image; sc->base.base.wait_image = client_vk_swapchain_wait_image;
@ -243,7 +245,7 @@ client_vk_compositor_create(struct xrt_compositor_fd *xcfd,
{ {
VkResult ret; VkResult ret;
struct client_vk_compositor *c = struct client_vk_compositor *c =
calloc(1, sizeof(struct client_vk_compositor)); U_TYPED_CALLOC(struct client_vk_compositor);
c->base.base.create_swapchain = client_vk_swapchain_create; c->base.base.create_swapchain = client_vk_swapchain_create;
c->base.base.begin_session = client_vk_compositor_begin_session; c->base.base.begin_session = client_vk_compositor_begin_session;

View file

@ -10,6 +10,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "xrt/xrt_gfx_xlib.h" #include "xrt/xrt_gfx_xlib.h"
#include "client/comp_xlib_client.h" #include "client/comp_xlib_client.h"
@ -38,7 +40,7 @@ client_xlib_compositor_create(struct xrt_compositor_fd *xcfd,
GLXContext glxContext) GLXContext glxContext)
{ {
struct client_xlib_compositor *c = struct client_xlib_compositor *c =
calloc(1, sizeof(struct client_xlib_compositor)); U_TYPED_CALLOC(struct client_xlib_compositor);
if (!client_gl_compositor_init(&c->base, xcfd, glXGetProcAddress)) { if (!client_gl_compositor_init(&c->base, xcfd, glXGetProcAddress)) {
free(c); free(c);

View file

@ -13,6 +13,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "util/u_debug.h" #include "util/u_debug.h"
#include "util/u_misc.h"
#include "main/comp_compositor.h" #include "main/comp_compositor.h"
#include "main/comp_client_interface.h" #include "main/comp_client_interface.h"
@ -465,7 +466,7 @@ compositor_init_renderer(struct comp_compositor *c)
struct xrt_compositor_fd * struct xrt_compositor_fd *
comp_compositor_create(struct xrt_device *xdev, bool flip_y) comp_compositor_create(struct xrt_device *xdev, bool flip_y)
{ {
struct comp_compositor *c = calloc(1, sizeof(struct comp_compositor)); struct comp_compositor *c = U_TYPED_CALLOC(struct comp_compositor);
c->base.base.create_swapchain = comp_swapchain_create; c->base.base.create_swapchain = comp_swapchain_create;
c->base.base.begin_session = compositor_begin_session; c->base.base.begin_session = compositor_begin_session;

View file

@ -594,7 +594,7 @@ renderer_init(struct comp_renderer *r)
renderer_init_descriptor_pool(r); renderer_init_descriptor_pool(r);
r->distortion = calloc(1, sizeof(struct comp_distortion)); r->distortion = U_TYPED_CALLOC(struct comp_distortion);
comp_distortion_init(r->distortion, r->c, r->render_pass, comp_distortion_init(r->distortion, r->c, r->render_pass,
r->pipeline_cache, r->settings->distortion_model, r->pipeline_cache, r->settings->distortion_model,

View file

@ -10,6 +10,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "main/comp_compositor.h" #include "main/comp_compositor.h"
@ -223,7 +225,7 @@ comp_swapchain_create(struct xrt_compositor *xc,
VkResult ret; VkResult ret;
struct comp_swapchain *sc = calloc(1, sizeof(struct comp_swapchain)); struct comp_swapchain *sc = U_TYPED_CALLOC(struct comp_swapchain);
sc->base.base.destroy = swapchain_destroy; sc->base.base.destroy = swapchain_destroy;
sc->base.base.acquire_image = swapchain_acquire_image; sc->base.base.acquire_image = swapchain_acquire_image;
sc->base.base.wait_image = swapchain_wait_image; sc->base.base.wait_image = swapchain_wait_image;

View file

@ -242,8 +242,7 @@ hdk_device_create(hid_device *dev,
bool print_spew, bool print_spew,
bool print_debug) bool print_debug)
{ {
struct hdk_device *hd = struct hdk_device *hd = U_TYPED_CALLOC(struct hdk_device);
(struct hdk_device *)calloc(1, sizeof(struct hdk_device));
hd->base.blend_mode = XRT_BLEND_MODE_OPAQUE; hd->base.blend_mode = XRT_BLEND_MODE_OPAQUE;
hd->base.destroy = hdk_device_destroy; hd->base.destroy = hdk_device_destroy;
hd->base.get_tracked_pose = hdk_device_get_tracked_pose; hd->base.get_tracked_pose = hdk_device_get_tracked_pose;

View file

@ -115,8 +115,7 @@ hdk_prober_autoprobe(struct xrt_prober *p)
struct xrt_prober * struct xrt_prober *
hdk_create_prober() hdk_create_prober()
{ {
struct hdk_prober *hhp = struct hdk_prober *hhp = U_TYPED_CALLOC(struct hdk_prober);
(struct hdk_prober *)calloc(1, sizeof(struct hdk_prober));
hhp->base.destroy = hdk_prober_destroy; hhp->base.destroy = hdk_prober_destroy;
hhp->base.lelo_dallas_autoprobe = hdk_prober_autoprobe; hhp->base.lelo_dallas_autoprobe = hdk_prober_autoprobe;

View file

@ -216,8 +216,7 @@ oh_device_create(ohmd_context *ctx,
bool print_spew, bool print_spew,
bool print_debug) bool print_debug)
{ {
struct oh_device *ohd = struct oh_device *ohd = U_TYPED_CALLOC(struct oh_device);
(struct oh_device *)calloc(1, sizeof(struct oh_device));
ohd->base.destroy = oh_device_destroy; ohd->base.destroy = oh_device_destroy;
ohd->base.get_tracked_pose = oh_device_get_tracked_pose; ohd->base.get_tracked_pose = oh_device_get_tracked_pose;
ohd->base.get_view_pose = oh_device_get_view_pose; ohd->base.get_view_pose = oh_device_get_view_pose;

View file

@ -101,7 +101,7 @@ oh_prober_autoprobe(struct xrt_prober *p)
struct xrt_prober * struct xrt_prober *
oh_create_prober() oh_create_prober()
{ {
struct oh_prober *ohp = calloc(1, sizeof(struct oh_prober)); struct oh_prober *ohp = U_TYPED_CALLOC(struct oh_prober);
ohp->base.destroy = oh_prober_destroy; ohp->base.destroy = oh_prober_destroy;
ohp->base.lelo_dallas_autoprobe = oh_prober_autoprobe; ohp->base.lelo_dallas_autoprobe = oh_prober_autoprobe;
ohp->ctx = ohmd_ctx_create(); ohp->ctx = ohmd_ctx_create();

View file

@ -14,6 +14,7 @@
#include "util/u_debug.h" #include "util/u_debug.h"
#include "util/u_time.h" #include "util/u_time.h"
#include "util/u_misc.h"
#include "xrt/xrt_compiler.h" #include "xrt/xrt_compiler.h"
#include "xrt/xrt_prober.h" #include "xrt/xrt_prober.h"
@ -37,8 +38,7 @@ oxr_instance_create(struct oxr_logger *log,
const XrInstanceCreateInfo *createInfo, const XrInstanceCreateInfo *createInfo,
struct oxr_instance **out_instance) struct oxr_instance **out_instance)
{ {
struct oxr_instance *inst = struct oxr_instance *inst = U_TYPED_CALLOC(struct oxr_instance);
(struct oxr_instance *)calloc(1, sizeof(struct oxr_instance));
inst->debug = OXR_XR_DEBUG_INSTANCE; inst->debug = OXR_XR_DEBUG_INSTANCE;
inst->prober = xrt_create_prober(); inst->prober = xrt_create_prober();

View file

@ -10,6 +10,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "xrt/xrt_gfx_xlib.h" #include "xrt/xrt_gfx_xlib.h"
#include "oxr_objects.h" #include "oxr_objects.h"
@ -32,8 +34,7 @@ oxr_session_create_gl_xlib(struct oxr_logger *log,
" failed create a compositor"); " failed create a compositor");
} }
struct oxr_session *sess = struct oxr_session *sess = U_TYPED_CALLOC(struct oxr_session);
(struct oxr_session *)calloc(1, sizeof(struct oxr_session));
sess->debug = OXR_XR_DEBUG_SESSION; sess->debug = OXR_XR_DEBUG_SESSION;
sess->sys = sys; sess->sys = sys;

View file

@ -10,6 +10,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "xrt/xrt_gfx_vk.h" #include "xrt/xrt_gfx_vk.h"
#include "oxr_objects.h" #include "oxr_objects.h"
@ -36,8 +38,7 @@ oxr_session_create_vk(struct oxr_logger *log,
" failed create a compositor"); " failed create a compositor");
} }
struct oxr_session *sess = struct oxr_session *sess = U_TYPED_CALLOC(struct oxr_session);
(struct oxr_session *)calloc(1, sizeof(struct oxr_session));
sess->debug = OXR_XR_DEBUG_SESSION; sess->debug = OXR_XR_DEBUG_SESSION;
sess->sys = sys; sess->sys = sys;
sess->compositor = &xcvk->base; sess->compositor = &xcvk->base;

View file

@ -14,6 +14,7 @@
#include "math/m_api.h" #include "math/m_api.h"
#include "util/u_debug.h" #include "util/u_debug.h"
#include "util/u_misc.h"
#include "oxr_objects.h" #include "oxr_objects.h"
#include "oxr_logger.h" #include "oxr_logger.h"
@ -61,8 +62,7 @@ oxr_space_reference_create(struct oxr_logger *log,
"(createInfo->poseInReferenceSpace)"); "(createInfo->poseInReferenceSpace)");
} }
struct oxr_space *spc = struct oxr_space *spc = U_TYPED_CALLOC(struct oxr_space);
(struct oxr_space *)calloc(1, sizeof(struct oxr_space));
spc->debug = OXR_XR_DEBUG_SPACE; spc->debug = OXR_XR_DEBUG_SPACE;
spc->sess = sess; spc->sess = sess;
spc->is_reference = true; spc->is_reference = true;

View file

@ -10,7 +10,9 @@
#include <stdlib.h> #include <stdlib.h>
#include "xrt/xrt_gfx_xlib.h" #include "xrt/xrt_gfx_xlib.h"
#include "util/u_debug.h" #include "util/u_debug.h"
#include "util/u_misc.h"
#include "oxr_objects.h" #include "oxr_objects.h"
#include "oxr_logger.h" #include "oxr_logger.h"
@ -99,8 +101,7 @@ oxr_create_swapchain(struct oxr_logger *log,
" failed to create swapchain"); " failed to create swapchain");
} }
struct oxr_swapchain *sc = struct oxr_swapchain *sc = U_TYPED_CALLOC(struct oxr_swapchain);
(struct oxr_swapchain *)calloc(1, sizeof(struct oxr_swapchain));
sc->debug = OXR_XR_DEBUG_SWAPCHAIN; sc->debug = OXR_XR_DEBUG_SWAPCHAIN;
sc->sess = sess; sc->sess = sess;
sc->swapchain = xsc; sc->swapchain = xsc;

View file

@ -11,6 +11,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/u_misc.h"
#include "xrt/xrt_gfx_vk.h" #include "xrt/xrt_gfx_vk.h"
#include "oxr_objects.h" #include "oxr_objects.h"
@ -88,7 +90,7 @@ oxr_vk_get_physical_device(struct oxr_logger *log,
"VkPhysicalDevices"); "VkPhysicalDevices");
} }
VkPhysicalDevice *phys = calloc(count, sizeof(VkPhysicalDevice)); VkPhysicalDevice *phys = U_TYPED_ARRAY_CALLOC(VkPhysicalDevice, count);
vk_ret = vkEnumeratePhysicalDevices(vkInstance, &count, phys); vk_ret = vkEnumeratePhysicalDevices(vkInstance, &count, phys);
if (vk_ret != VK_SUCCESS) { if (vk_ret != VK_SUCCESS) {
free(phys); free(phys);