On Fri, Mar 08, 2013 at 10:26:13PM -0600, Jason Ekstrand wrote: > This commit adds a wl_resource_init function for initializing wl_resource > structures similar to wl_client_add_object. > > From this commit forward, wl_resource structures should not be initialized > manually, but should use wl_resource_init. In the event of a change to the > wl_resource structure, this allows us to protect against regressions by > filling > in added fields with reasonable defaults. In this way, while changing > wl_object or wl_resource still constitutes an ABI break, compositors following > this rule will only need to be recompiled in order to properly link against > the > new version.
I'm wondering if we should just make all wl_resource instances malloced and just use wl_client_add_object() and wl_client_new_object(). That will also allow us to allocate the wl_resource in the demarshal code for new_id arguments. It's a little bit more memory fragmentation and pointer jumping, but I doubt that will ever be an issue... Kristian > Signed-off-by: Jason Ekstrand <[email protected]> > --- > src/data-device.c | 16 ++++------------ > src/wayland-server.c | 6 +----- > src/wayland-server.h | 16 ++++++++++++++++ > src/wayland-shm.c | 24 ++++++------------------ > 4 files changed, 27 insertions(+), 35 deletions(-) > > diff --git a/src/data-device.c b/src/data-device.c > index 4255c13..92ceb12 100644 > --- a/src/data-device.c > +++ b/src/data-device.c > @@ -98,13 +98,9 @@ wl_data_source_send_offer(struct wl_data_source *source, > if (offer == NULL) > return NULL; > > + wl_resource_init(&offer->resource, &wl_data_offer_interface, > + &data_offer_interface, 0, offer); > offer->resource.destroy = destroy_data_offer; > - offer->resource.object.id = 0; > - offer->resource.object.interface = &wl_data_offer_interface; > - offer->resource.object.implementation = > - (void (**)(void)) &data_offer_interface; > - offer->resource.data = offer; > - wl_signal_init(&offer->resource.destroy_signal); > > offer->source = source; > offer->source_destroy_listener.notify = destroy_offer_data_source; > @@ -459,13 +455,9 @@ create_data_source(struct wl_client *client, > return; > } > > + wl_resource_init(&source->resource, &wl_data_source_interface, > + &data_source_interface, id, source); > source->resource.destroy = destroy_data_source; > - source->resource.object.id = id; > - source->resource.object.interface = &wl_data_source_interface; > - source->resource.object.implementation = > - (void (**)(void)) &data_source_interface; > - source->resource.data = source; > - wl_signal_init(&source->resource.destroy_signal); > > source->accept = client_source_accept; > source->send = client_source_send; > diff --git a/src/wayland-server.c b/src/wayland-server.c > index 130511d..dcb4435 100644 > --- a/src/wayland-server.c > +++ b/src/wayland-server.c > @@ -1396,13 +1396,9 @@ wl_client_add_object(struct wl_client *client, > return NULL; > } > > - resource->object.interface = interface; > - resource->object.implementation = implementation; > - resource->object.id = id; > + wl_resource_init(resource, interface, implementation, id, data); > resource->client = client; > - resource->data = data; > resource->destroy = (void *) free; > - wl_signal_init(&resource->destroy_signal); > > if (wl_map_insert_at(&client->objects, resource->object.id, resource) < > 0) { > wl_resource_post_error(client->display_resource, > diff --git a/src/wayland-server.h b/src/wayland-server.h > index c7369eb..38b8303 100644 > --- a/src/wayland-server.h > +++ b/src/wayland-server.h > @@ -190,6 +190,22 @@ struct wl_resource { > void *data; > }; > > +static inline void > +wl_resource_init(struct wl_resource *resource, > + const struct wl_interface *interface, > + const void *implementation, uint32_t id, void *data) > +{ > + resource->object.id = id; > + resource->object.interface = interface; > + resource->object.implementation = implementation; > + > + wl_signal_init(&resource->destroy_signal); > + > + resource->destroy = NULL; > + resource->client = NULL; > + resource->data = data; > +} > + > struct wl_buffer { > struct wl_resource resource; > int32_t width, height; > diff --git a/src/wayland-shm.c b/src/wayland-shm.c > index 47c126b..776c0f2 100644 > --- a/src/wayland-shm.c > +++ b/src/wayland-shm.c > @@ -128,12 +128,8 @@ shm_pool_create_buffer(struct wl_client *client, struct > wl_resource *resource, > buffer->pool = pool; > pool->refcount++; > > - buffer->buffer.resource.object.id = id; > - buffer->buffer.resource.object.interface = &wl_buffer_interface; > - buffer->buffer.resource.object.implementation = (void (**)(void)) > - &shm_buffer_interface; > - > - buffer->buffer.resource.data = buffer; > + wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface, > + &shm_buffer_interface, id, buffer); > buffer->buffer.resource.client = resource->client; > buffer->buffer.resource.destroy = destroy_buffer; > > @@ -211,12 +207,8 @@ shm_create_pool(struct wl_client *client, struct > wl_resource *resource, > } > close(fd); > > - pool->resource.object.id = id; > - pool->resource.object.interface = &wl_shm_pool_interface; > - pool->resource.object.implementation = > - (void (**)(void)) &shm_pool_interface; > - > - pool->resource.data = pool; > + wl_resource_init(&pool->resource, &wl_shm_pool_interface, > + &shm_pool_interface, id, pool); > pool->resource.client = client; > pool->resource.destroy = destroy_pool; > > @@ -283,12 +275,8 @@ wl_shm_buffer_create(struct wl_client *client, > buffer->offset = 0; > buffer->pool = NULL; > > - buffer->buffer.resource.object.id = id; > - buffer->buffer.resource.object.interface = &wl_buffer_interface; > - buffer->buffer.resource.object.implementation = (void (**)(void)) > - &shm_buffer_interface; > - > - buffer->buffer.resource.data = buffer; > + wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface, > + &shm_buffer_interface, id, buffer); > buffer->buffer.resource.client = client; > buffer->buffer.resource.destroy = destroy_buffer; > > -- > 1.8.1.4 > > _______________________________________________ > wayland-devel mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/wayland-devel _______________________________________________ wayland-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/wayland-devel
