mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-31 22:25:21 -04:00
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:
parent
c2c536de03
commit
fe06e5f49a
29 changed files with 85 additions and 55 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue