Use struct initializers instead of memset()

This is a bit more type-safe.
This commit is contained in:
Simon Ser 2023-07-07 14:34:56 +02:00
parent 4966857f21
commit 7a9f8d8d6b
34 changed files with 134 additions and 113 deletions

View file

@ -22,9 +22,10 @@
void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl, uint32_t buffer_caps) {
assert(impl && impl->destroy && impl->create_buffer);
memset(alloc, 0, sizeof(*alloc));
alloc->impl = impl;
alloc->buffer_caps = buffer_caps;
*alloc = (struct wlr_allocator){
.impl = impl,
.buffer_caps = buffer_caps,
};
wl_signal_init(&alloc->events.destroy);
}

View file

@ -86,8 +86,9 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
}
void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format) {
memset(fmt, 0, sizeof(*fmt));
fmt->format = format;
*fmt = (struct wlr_drm_format){
.format = format,
};
}
bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) {

View file

@ -373,8 +373,9 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture,
struct wlr_gles2_texture_attribs *attribs) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
memset(attribs, 0, sizeof(*attribs));
attribs->target = texture->target;
attribs->tex = texture->tex;
attribs->has_alpha = texture->has_alpha;
*attribs = (struct wlr_gles2_texture_attribs){
.target = texture->target,
.tex = texture->tex,
.has_alpha = texture->has_alpha,
};
}

View file

@ -15,8 +15,9 @@ struct wlr_render_pass_legacy {
void wlr_render_pass_init(struct wlr_render_pass *render_pass,
const struct wlr_render_pass_impl *impl) {
assert(impl->submit && impl->add_texture && impl->add_rect);
memset(render_pass, 0, sizeof(*render_pass));
render_pass->impl = impl;
*render_pass = (struct wlr_render_pass){
.impl = impl,
};
}
bool wlr_render_pass_submit(struct wlr_render_pass *render_pass) {

View file

@ -42,7 +42,7 @@ static void slot_reset(struct wlr_swapchain_slot *slot) {
wl_list_remove(&slot->release.link);
}
wlr_buffer_drop(slot->buffer);
memset(slot, 0, sizeof(*slot));
*slot = (struct wlr_swapchain_slot){0};
}
void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) {

View file

@ -44,8 +44,9 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
assert(impl->get_shm_texture_formats);
assert(impl->get_render_buffer_caps);
memset(renderer, 0, sizeof(*renderer));
renderer->impl = impl;
*renderer = (struct wlr_renderer){
.impl = impl,
};
wl_signal_init(&renderer->events.destroy);
wl_signal_init(&renderer->events.lost);

View file

@ -10,11 +10,12 @@ void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *renderer
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
assert(renderer);
memset(texture, 0, sizeof(*texture));
texture->renderer = renderer;
texture->impl = impl;
texture->width = width;
texture->height = height;
*texture = (struct wlr_texture){
.renderer = renderer,
.impl = impl,
.width = width,
.height = height,
};
}
void wlr_texture_destroy(struct wlr_texture *texture) {