Use wl_container_of() instead of casts

This slightly improves type safety.

The culprits were found with:

    git grep -E '\([a-z0-9_ ]+ \*\)\W?[a-z]'
This commit is contained in:
Simon Ser 2023-07-11 17:54:08 +02:00
parent c2c536de03
commit fe06e5f49a
29 changed files with 85 additions and 55 deletions

View file

@ -17,9 +17,10 @@
static const struct wlr_buffer_impl buffer_impl;
static struct wlr_gbm_buffer *get_gbm_buffer_from_buffer(
struct wlr_buffer *buffer) {
assert(buffer->impl == &buffer_impl);
return (struct wlr_gbm_buffer *)buffer;
struct wlr_buffer *wlr_buffer) {
assert(wlr_buffer->impl == &buffer_impl);
struct wlr_gbm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
return buffer;
}
static bool export_gbm_bo(struct gbm_bo *bo,
@ -179,9 +180,10 @@ static const struct wlr_buffer_impl buffer_impl = {
static const struct wlr_allocator_interface allocator_impl;
static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc(
struct wlr_allocator *alloc) {
assert(alloc->impl == &allocator_impl);
return (struct wlr_gbm_allocator *)alloc;
struct wlr_allocator *wlr_alloc) {
assert(wlr_alloc->impl == &allocator_impl);
struct wlr_gbm_allocator *alloc = wl_container_of(wlr_alloc, alloc, base);
return alloc;
}
struct wlr_allocator *wlr_gbm_allocator_create(int fd) {