mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-02-13 04:28:02 -05:00
server: Safe cast a "wl_object *" to "wl_resource *"
Client message observers 5/6 When given an array of wl_arguments for a wl_closure, the .o field is an opaque wl_object pointer, which the server implementation cannot really do anything with, without a potentially unsafe cast that assumes details about the internal implementation. By adding a wl_resource_from_object() function to the client interface, the client can safely get the wl_resource pointer. This can be used by server protocol loggers in particular to get the resource id and class name, for logging those details Signed-off-by: Lloyd Pique <lpique@google.com>
This commit is contained in:
parent
e5e7cc57fa
commit
7698137663
2 changed files with 25 additions and 0 deletions
|
|
@ -628,6 +628,9 @@ struct wl_listener *
|
|||
wl_resource_get_destroy_listener(struct wl_resource *resource,
|
||||
wl_notify_func_t notify);
|
||||
|
||||
struct wl_resource *
|
||||
wl_resource_from_object(struct wl_object *object);
|
||||
|
||||
#define wl_resource_for_each(resource, list) \
|
||||
for (resource = 0, resource = wl_resource_from_link((list)->next); \
|
||||
wl_resource_get_link(resource) != (list); \
|
||||
|
|
|
|||
|
|
@ -905,6 +905,28 @@ wl_resource_get_class(struct wl_resource *resource)
|
|||
return resource->object.interface->name;
|
||||
}
|
||||
|
||||
/** Safely converts an object into its corresponding resource
|
||||
*
|
||||
* \param object object to get the resource for
|
||||
* \return A corresponding resource, or NULL on failure
|
||||
*
|
||||
* Safely converts an object into its corresponding resource.
|
||||
*
|
||||
* This is useful for implementing functions that are given a \c wl_argument
|
||||
* array, and that need to do further introspection on the ".o" field, as it
|
||||
* is otherwise an opaque type.
|
||||
*
|
||||
* \memberof wl_resource
|
||||
*/
|
||||
WL_EXPORT struct wl_resource *
|
||||
wl_resource_from_object(struct wl_object *object)
|
||||
{
|
||||
struct wl_resource *resource;
|
||||
if (object == NULL)
|
||||
return NULL;
|
||||
return wl_container_of(object, resource, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener to be called at the beginning of wl_client destruction
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue