diff options
author | Simon Ser <contact@emersion.fr> | 2023-07-11 17:54:08 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-07-11 20:16:17 +0200 |
commit | fe06e5f49a12174ceeb5e307bf5c3d7f623177d5 (patch) | |
tree | 40984fb21cd0cbf6be531206a86167298ab2d537 /render/allocator | |
parent | c2c536de034cc27d3a15001cc478f5a327b8f910 (diff) | |
download | wlroots-fe06e5f49a12174ceeb5e307bf5c3d7f623177d5.tar.xz |
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]'
Diffstat (limited to 'render/allocator')
-rw-r--r-- | render/allocator/drm_dumb.c | 6 | ||||
-rw-r--r-- | render/allocator/gbm.c | 14 | ||||
-rw-r--r-- | render/allocator/shm.c | 3 |
3 files changed, 14 insertions, 9 deletions
diff --git a/render/allocator/drm_dumb.c b/render/allocator/drm_dumb.c index 684ba2e3..03ff8e3f 100644 --- a/render/allocator/drm_dumb.c +++ b/render/allocator/drm_dumb.c @@ -25,7 +25,8 @@ static const struct wlr_buffer_impl buffer_impl; static struct wlr_drm_dumb_buffer *drm_dumb_buffer_from_buffer( struct wlr_buffer *wlr_buf) { assert(wlr_buf->impl == &buffer_impl); - return (struct wlr_drm_dumb_buffer *)wlr_buf; + struct wlr_drm_dumb_buffer *buf = wl_container_of(wlr_buf, buf, base); + return buf; } static struct wlr_drm_dumb_buffer *create_buffer( @@ -163,7 +164,8 @@ static const struct wlr_allocator_interface allocator_impl; static struct wlr_drm_dumb_allocator *drm_dumb_alloc_from_alloc( struct wlr_allocator *wlr_alloc) { assert(wlr_alloc->impl == &allocator_impl); - return (struct wlr_drm_dumb_allocator *)wlr_alloc; + struct wlr_drm_dumb_allocator *alloc = wl_container_of(wlr_alloc, alloc, base); + return alloc; } static struct wlr_buffer *allocator_create_buffer( diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c index 149ff6b9..32636d30 100644 --- a/render/allocator/gbm.c +++ b/render/allocator/gbm.c @@ -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) { diff --git a/render/allocator/shm.c b/render/allocator/shm.c index 55a8fab2..b6d3138c 100644 --- a/render/allocator/shm.c +++ b/render/allocator/shm.c @@ -17,7 +17,8 @@ static const struct wlr_buffer_impl buffer_impl; static struct wlr_shm_buffer *shm_buffer_from_buffer( struct wlr_buffer *wlr_buffer) { assert(wlr_buffer->impl == &buffer_impl); - return (struct wlr_shm_buffer *)wlr_buffer; + struct wlr_shm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base); + return buffer; } static void buffer_destroy(struct wlr_buffer *wlr_buffer) { |