[PATCH 1/2] wayland-util: Remove container_of()

Chad Versace chad.versace at linux.intel.com
Thu Oct 18 09:15:07 PDT 2012


wayland-util.h defined two variants of the container_of macro:
__wl_container_of() and an unprefixed container_of(). The unprefixed
variant, of course, polluted the global namespace and caused symbol
collisions in projects that defined container_of slightly differently.

This patch removes the definition of container_of() and replaces each call
to it with a call to __wl_container_of().

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/data-device.c    | 25 ++++++++++++-------------
 src/event-loop.c     |  4 ++--
 src/wayland-client.c |  8 ++++----
 src/wayland-server.c |  6 +++---
 src/wayland-shm.c    |  2 +-
 src/wayland-util.h   |  4 ----
 6 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/src/data-device.c b/src/data-device.c
index 363a90d..884e73c 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -80,8 +80,7 @@ destroy_offer_data_source(struct wl_listener *listener, void *data)
 {
 	struct wl_data_offer *offer;
 
-	offer = container_of(listener, struct wl_data_offer,
-			     source_destroy_listener);
+	offer = __wl_container_of(listener, offer, source_destroy_listener);
 
 	offer->source = NULL;
 }
@@ -163,7 +162,7 @@ static void
 destroy_drag_focus(struct wl_listener *listener, void *data)
 {
 	struct wl_seat *seat =
-		container_of(listener, struct wl_seat, drag_focus_listener);
+		__wl_container_of(listener, seat, drag_focus_listener);
 
 	seat->drag_focus_resource = NULL;
 }
@@ -172,7 +171,7 @@ static void
 drag_grab_focus(struct wl_pointer_grab *grab,
 		struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
 {
-	struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
+	struct wl_seat *seat = __wl_container_of(grab, seat, drag_grab);
 	struct wl_resource *resource, *offer = NULL;
 	struct wl_display *display;
 	uint32_t serial;
@@ -218,7 +217,7 @@ static void
 drag_grab_motion(struct wl_pointer_grab *grab,
 		 uint32_t time, wl_fixed_t x, wl_fixed_t y)
 {
-	struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
+	struct wl_seat *seat = __wl_container_of(grab, seat, drag_grab);
 
 	if (seat->drag_focus_resource)
 		wl_data_device_send_motion(seat->drag_focus_resource,
@@ -247,7 +246,7 @@ static void
 drag_grab_button(struct wl_pointer_grab *grab,
 		 uint32_t time, uint32_t button, uint32_t state_w)
 {
-	struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
+	struct wl_seat *seat = __wl_container_of(grab, seat, drag_grab);
 	enum wl_pointer_button_state state = state_w;
 
 	if (seat->drag_focus_resource &&
@@ -272,8 +271,8 @@ static const struct wl_pointer_grab_interface drag_grab_interface = {
 static void
 destroy_data_device_source(struct wl_listener *listener, void *data)
 {
-	struct wl_seat *seat = container_of(listener, struct wl_seat,
-					    drag_data_source_listener);
+	struct wl_seat *seat = __wl_container_of(listener, seat,
+						 drag_data_source_listener);
 
 	data_device_end_drag_grab(seat);
 }
@@ -281,8 +280,8 @@ destroy_data_device_source(struct wl_listener *listener, void *data)
 static void
 destroy_data_device_icon(struct wl_listener *listener, void *data)
 {
-	struct wl_seat *seat = container_of(listener, struct wl_seat,
-					    drag_icon_listener);
+	struct wl_seat *seat = __wl_container_of(listener, seat,
+						 drag_icon_listener);
 
 	seat->drag_surface = NULL;
 }
@@ -329,8 +328,8 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
 static void
 destroy_selection_data_source(struct wl_listener *listener, void *data)
 {
-	struct wl_seat *seat = container_of(listener, struct wl_seat,
-					    selection_data_source_listener);
+	struct wl_seat *seat = __wl_container_of(listener, seat,
+						 selection_data_source_listener);
 	struct wl_resource *data_device;
 	struct wl_resource *focus = NULL;
 
@@ -414,7 +413,7 @@ static void
 destroy_data_source(struct wl_resource *resource)
 {
 	struct wl_data_source *source =
-		container_of(resource, struct wl_data_source, resource);
+		__wl_container_of(resource, source, resource);
 	char **p;
 
 	wl_array_for_each(p, &source->mime_types)
diff --git a/src/event-loop.c b/src/event-loop.c
index e383300..65f8ea6 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -388,8 +388,8 @@ wl_event_loop_dispatch_idle(struct wl_event_loop *loop)
 	struct wl_event_source_idle *source;
 
 	while (!wl_list_empty(&loop->idle_list)) {
-		source = container_of(loop->idle_list.next,
-				      struct wl_event_source_idle, base.link);
+		source = __wl_container_of(loop->idle_list.next,
+					   source, base.link);
 		source->func(source->base.data);
 		wl_event_source_remove(&source->base);
 	}
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 9ac4edb..a838c8a 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -124,8 +124,8 @@ wl_event_queue_release(struct wl_event_queue *queue)
 	struct wl_closure *closure;
 
 	while (!wl_list_empty(&queue->event_list)) {
-		closure = container_of(queue->event_list.next,
-				       struct wl_closure, link);
+		closure = __wl_container_of(queue->event_list.next,
+					    closure, link);
 		wl_list_remove(&closure->link);
 		wl_closure_destroy(closure);
 	}
@@ -724,8 +724,8 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue)
 	uint32_t id;
 	int opcode, ret;
 
-	closure = container_of(queue->event_list.next,
-			       struct wl_closure, link);
+	closure = __wl_container_of(queue->event_list.next,
+				    closure, link);
 	wl_list_remove(&closure->link);
 	id = closure->buffer[0];
 	opcode = closure->buffer[1] & 0xffff;
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 41560f2..820faec 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -485,7 +485,7 @@ static void
 lose_pointer_focus(struct wl_listener *listener, void *data)
 {
 	struct wl_pointer *pointer =
-		container_of(listener, struct wl_pointer, focus_listener);
+		__wl_container_of(listener, pointer, focus_listener);
 
 	pointer->focus_resource = NULL;
 }
@@ -494,7 +494,7 @@ static void
 lose_keyboard_focus(struct wl_listener *listener, void *data)
 {
 	struct wl_keyboard *keyboard =
-		container_of(listener, struct wl_keyboard, focus_listener);
+		__wl_container_of(listener, keyboard, focus_listener);
 
 	keyboard->focus_resource = NULL;
 }
@@ -503,7 +503,7 @@ static void
 lose_touch_focus(struct wl_listener *listener, void *data)
 {
 	struct wl_touch *touch =
-		container_of(listener, struct wl_touch, focus_listener);
+		__wl_container_of(listener, touch, focus_listener);
 
 	touch->focus_resource = NULL;
 }
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 90c4cf7..85f9ffe 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -65,7 +65,7 @@ static void
 destroy_buffer(struct wl_resource *resource)
 {
 	struct wl_shm_buffer *buffer =
-		container_of(resource, struct wl_shm_buffer, buffer.resource);
+		__wl_container_of(resource, buffer, buffer.resource);
 
 	if (buffer->pool)
 		shm_pool_unref(buffer->pool);
diff --git a/src/wayland-util.h b/src/wayland-util.h
index f54077e..3a29840 100644
--- a/src/wayland-util.h
+++ b/src/wayland-util.h
@@ -41,10 +41,6 @@ extern "C" {
 
 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 
-#define container_of(ptr, type, member) ({				\
-	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
-
 struct wl_message {
 	const char *name;
 	const char *signature;
-- 
1.7.11.7



More information about the wayland-devel mailing list