[PATCH 3/4] wl_resource: Add a private field to wl_resource
alexl at redhat.com
alexl at redhat.com
Thu May 23 10:31:23 PDT 2013
From: Alexander Larsson <alexl at redhat.com>
This takes the place of the second pointer in the old wl_list and
lets us add more fields to wl_resource in a backwards compat fashion.
---
src/wayland-private.h | 4 ++++
src/wayland-server.c | 17 ++++++++++++++++-
src/wayland-server.h | 4 +++-
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/wayland-private.h b/src/wayland-private.h
index c4ce6b0..105f9b9 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -47,6 +47,10 @@ struct wl_map {
uint32_t free_list;
};
+struct wl_resource_private {
+ uint32_t dummy;
+};
+
typedef void (*wl_iterator_func_t)(void *element, void *data);
void wl_map_init(struct wl_map *map);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index f1a6aac..e3a0376 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -377,6 +377,14 @@ WL_EXPORT uint32_t
wl_client_add_resource(struct wl_client *client,
struct wl_resource *resource)
{
+ struct wl_resource_private *priv;
+
+ priv = calloc(1, sizeof(struct wl_resource_private));
+ if (!priv) {
+ wl_resource_post_no_memory(resource);
+ return 0;
+ }
+
if (resource->object.id == 0) {
resource->object.id =
wl_map_insert_new(&client->objects,
@@ -387,9 +395,11 @@ wl_client_add_resource(struct wl_client *client,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid new id %d",
resource->object.id);
+ free(priv);
return 0;
}
+ resource->priv = priv;
resource->client = client;
wl_signal_init(&resource->destroy_signal);
@@ -413,11 +423,15 @@ static void
destroy_resource(void *element, void *data)
{
struct wl_resource *resource = element;
+ struct wl_resource_private *resource_priv = resource->priv;
wl_signal_emit(&resource->destroy_signal, resource);
if (resource->destroy)
resource->destroy(resource);
+
+ if (resource_priv != (struct wl_resource_private *)(resource + 1))
+ free (resource_priv);
}
WL_EXPORT void
@@ -906,13 +920,14 @@ wl_client_add_object(struct wl_client *client,
{
struct wl_resource *resource;
- resource = malloc(sizeof *resource);
+ resource = malloc(sizeof *resource + sizeof (struct wl_resource_private));
if (resource == NULL) {
wl_resource_post_no_memory(client->display_resource);
return NULL;
}
wl_resource_init(resource, interface, implementation, id, data);
+ resource->priv = (struct wl_resource_private *)(resource + 1);
resource->client = client;
resource->destroy = (void *) free;
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 4867652..3ac0351 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -177,11 +177,13 @@ wl_signal_emit(struct wl_signal *signal, void *data)
l->notify(l, data);
}
+struct wl_resource_private;
+
struct wl_resource {
struct wl_object object;
void (*destroy)(struct wl_resource *resource);
struct wl_slist link;
- void *reserved;
+ struct wl_resource_private *priv;
struct wl_signal destroy_signal;
struct wl_client *client;
void *data;
--
1.8.1.4
More information about the wayland-devel
mailing list