[PATCH weston 4/4] Unified multiple definitions of container_of() macro.

Jon A. Cruz jonc at osg.samsung.com
Fri Jun 12 21:25:05 PDT 2015


Removed duplicate definitions of the container_of() macro and
refactored sources to use the single implementation.

Signed-off-by: Jon A. Cruz <jonc at osg.samsung.com>
---
 clients/clickdot.c                  |  1 +
 clients/desktop-shell.c             |  1 +
 clients/window.h                    |  4 ----
 desktop-shell/exposay.c             |  1 +
 desktop-shell/input-panel.c         |  1 +
 fullscreen-shell/fullscreen-shell.c |  1 +
 ivi-shell/hmi-controller.c          |  1 +
 ivi-shell/input-panel-ivi.c         |  1 +
 ivi-shell/ivi-layout.c              |  1 +
 shared/config-parser.c              |  5 +----
 shared/helpers.h                    | 19 +++++++++++++++++++
 src/animation.c                     |  1 +
 src/bindings.c                      |  1 +
 src/clipboard.c                     |  1 +
 src/cms-colord.c                    |  1 +
 src/cms-static.c                    |  1 +
 src/compositor.h                    |  4 ----
 src/data-device.c                   |  1 +
 src/libinput-device.c               |  1 +
 src/libinput-seat.c                 |  1 +
 src/pixman-renderer.c               |  1 +
 src/rpi-renderer.c                  |  1 +
 src/screen-share.c                  |  1 +
 src/screenshooter.c                 |  1 +
 src/text-backend.c                  |  1 +
 src/zoom.c                          |  1 +
 tests/ivi_layout-test-plugin.c      |  1 +
 tests/weston-test.c                 |  2 ++
 xwayland/launcher.c                 |  1 +
 29 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/clients/clickdot.c b/clients/clickdot.c
index 5137ba6..06c905e 100644
--- a/clients/clickdot.c
+++ b/clients/clickdot.c
@@ -39,6 +39,7 @@
 #include <wayland-client.h>
 
 #include "window.h"
+#include "shared/helpers.h"
 
 struct clickdot {
 	struct display *display;
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 70e9dfe..9da684a 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -44,6 +44,7 @@
 #include "window.h"
 #include "shared/cairo-util.h"
 #include "shared/config-parser.h"
+#include "shared/helpers.h"
 
 #include "desktop-shell-client-protocol.h"
 
diff --git a/clients/window.h b/clients/window.h
index 0535a38..cf2399a 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -32,10 +32,6 @@
 #include "shared/zalloc.h"
 #include "shared/platform.h"
 
-#define container_of(ptr, type, member) ({				\
-	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
-
 struct window;
 struct widget;
 struct display;
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index 78e45fb..13d8cd0 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -27,6 +27,7 @@
 #include <linux/input.h>
 
 #include "shell.h"
+#include "shared/helpers.h"
 
 struct exposay_surface {
 	struct desktop_shell *shell;
diff --git a/desktop-shell/input-panel.c b/desktop-shell/input-panel.c
index ffa3ade..97021d1 100644
--- a/desktop-shell/input-panel.c
+++ b/desktop-shell/input-panel.c
@@ -31,6 +31,7 @@
 #include "shell.h"
 #include "desktop-shell-server-protocol.h"
 #include "input-method-server-protocol.h"
+#include "shared/helpers.h"
 
 struct input_panel_surface {
 	struct wl_resource *resource;
diff --git a/fullscreen-shell/fullscreen-shell.c b/fullscreen-shell/fullscreen-shell.c
index 35e6d8f..7407ae5 100644
--- a/fullscreen-shell/fullscreen-shell.c
+++ b/fullscreen-shell/fullscreen-shell.c
@@ -31,6 +31,7 @@
 
 #include "compositor.h"
 #include "fullscreen-shell-server-protocol.h"
+#include "shared/helpers.h"
 
 struct fullscreen_shell {
 	struct wl_client *client;
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index 88e9333..094fd37 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -57,6 +57,7 @@
 
 #include "ivi-layout-export.h"
 #include "ivi-hmi-controller-server-protocol.h"
+#include "shared/helpers.h"
 
 /*****************************************************************************
  *  structure, globals
diff --git a/ivi-shell/input-panel-ivi.c b/ivi-shell/input-panel-ivi.c
index 6b89177..d17acbf 100644
--- a/ivi-shell/input-panel-ivi.c
+++ b/ivi-shell/input-panel-ivi.c
@@ -31,6 +31,7 @@
 #include "ivi-shell.h"
 #include "input-method-server-protocol.h"
 #include "ivi-layout-private.h"
+#include "shared/helpers.h"
 
 struct input_panel_surface {
 	struct wl_resource *resource;
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 297b033..f08c750 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -60,6 +60,7 @@
 #include "ivi-layout-export.h"
 #include "ivi-layout-private.h"
 
+#include "shared/helpers.h"
 #include "shared/os-compatibility.h"
 
 struct link_layer {
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 8519eb6..663de1f 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -36,10 +36,7 @@
 
 #include <wayland-util.h>
 #include "config-parser.h"
-
-#define container_of(ptr, type, member) ({				\
-	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
+#include "helpers.h"
 
 struct weston_config_entry {
 	char *key;
diff --git a/shared/helpers.h b/shared/helpers.h
index c56b4d0..bd81845 100644
--- a/shared/helpers.h
+++ b/shared/helpers.h
@@ -53,6 +53,25 @@ extern "C" {
 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
 #endif
 
+/**
+ * Returns a pointer the the containing struct of a given member item.
+ *
+ * @param ptr A valid pointer to the contained item.
+ *
+ * @param type A pointer to the type of content that the list item
+ * stores. Type does not need be a valid pointer; a null or
+ * an uninitialised pointer will suffice.
+ *
+ * @param member The named location of ptr within the sample type.
+ *
+ * @return The container for the specified pointer.
+ */
+#ifndef container_of
+#define container_of(ptr, type, member) ({				\
+	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
+	(type *)( (char *)__mptr - offsetof(type,member) );})
+#endif
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/animation.c b/src/animation.c
index 0febe41..254cf89 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 
 #include "compositor.h"
+#include "shared/helpers.h"
 
 WL_EXPORT void
 weston_spring_init(struct weston_spring *spring,
diff --git a/src/bindings.c b/src/bindings.c
index 6aeed91..141941a 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -26,6 +26,7 @@
 #include <linux/input.h>
 
 #include "compositor.h"
+#include "shared/helpers.h"
 
 struct weston_binding {
 	uint32_t key;
diff --git a/src/clipboard.c b/src/clipboard.c
index 994c301..f897c2c 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -30,6 +30,7 @@
 #include <sys/uio.h>
 
 #include "compositor.h"
+#include "shared/helpers.h"
 
 struct clipboard_source {
 	struct weston_data_source base;
diff --git a/src/cms-colord.c b/src/cms-colord.c
index a6b105c..4f3abcd 100644
--- a/src/cms-colord.c
+++ b/src/cms-colord.c
@@ -33,6 +33,7 @@
 
 #include "compositor.h"
 #include "cms-helper.h"
+#include "shared/helpers.h"
 
 struct cms_colord {
 	struct weston_compositor	*ec;
diff --git a/src/cms-static.c b/src/cms-static.c
index ad54fd1..cca9f60 100644
--- a/src/cms-static.c
+++ b/src/cms-static.c
@@ -27,6 +27,7 @@
 
 #include "compositor.h"
 #include "cms-helper.h"
+#include "shared/helpers.h"
 
 struct cms_static {
 	struct weston_compositor	*ec;
diff --git a/src/compositor.h b/src/compositor.h
index 4532d36..0f38fc5 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -42,10 +42,6 @@ extern "C" {
 #include "zalloc.h"
 #include "timeline-object.h"
 
-#define container_of(ptr, type, member) ({				\
-	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
-
 struct weston_transform {
 	struct weston_matrix matrix;
 	struct wl_list link;
diff --git a/src/data-device.c b/src/data-device.c
index 3e7baf9..91c65f3 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -29,6 +29,7 @@
 #include <assert.h>
 
 #include "compositor.h"
+#include "shared/helpers.h"
 
 struct weston_drag {
 	struct wl_client *client;
diff --git a/src/libinput-device.c b/src/libinput-device.c
index 567e5ea..4622dde 100644
--- a/src/libinput-device.c
+++ b/src/libinput-device.c
@@ -35,6 +35,7 @@
 
 #include "compositor.h"
 #include "libinput-device.h"
+#include "shared/helpers.h"
 
 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
 
diff --git a/src/libinput-seat.c b/src/libinput-seat.c
index c0a87ea..dd42903 100644
--- a/src/libinput-seat.c
+++ b/src/libinput-seat.c
@@ -34,6 +34,7 @@
 #include "launcher-util.h"
 #include "libinput-seat.h"
 #include "libinput-device.h"
+#include "shared/helpers.h"
 
 static const char default_seat[] = "seat0";
 static const char default_seat_name[] = "default";
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c
index c650d55..865b679 100644
--- a/src/pixman-renderer.c
+++ b/src/pixman-renderer.c
@@ -29,6 +29,7 @@
 #include <assert.h>
 
 #include "pixman-renderer.h"
+#include "shared/helpers.h"
 
 #include <linux/input.h>
 
diff --git a/src/rpi-renderer.c b/src/rpi-renderer.c
index b6cf125..a8c770f 100644
--- a/src/rpi-renderer.c
+++ b/src/rpi-renderer.c
@@ -34,6 +34,7 @@
 
 #include "compositor.h"
 #include "rpi-renderer.h"
+#include "shared/helpers.h"
 
 #ifdef ENABLE_EGL
 #include <EGL/egl.h>
diff --git a/src/screen-share.c b/src/screen-share.c
index a5e3ab8..27f7554 100644
--- a/src/screen-share.c
+++ b/src/screen-share.c
@@ -37,6 +37,7 @@
 #include <wayland-client.h>
 
 #include "compositor.h"
+#include "shared/helpers.h"
 #include "shared/os-compatibility.h"
 #include "fullscreen-shell-client-protocol.h"
 
diff --git a/src/screenshooter.c b/src/screenshooter.c
index cceafde..b82a4de 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -32,6 +32,7 @@
 
 #include "compositor.h"
 #include "screenshooter-server-protocol.h"
+#include "shared/helpers.h"
 
 #include "wcap/wcap-decode.h"
 
diff --git a/src/text-backend.c b/src/text-backend.c
index 06dfbda..2251785 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -32,6 +32,7 @@
 #include "compositor.h"
 #include "text-server-protocol.h"
 #include "input-method-server-protocol.h"
+#include "shared/helpers.h"
 
 struct text_input_manager;
 struct input_method;
diff --git a/src/zoom.c b/src/zoom.c
index bee038b..116a723 100644
--- a/src/zoom.c
+++ b/src/zoom.c
@@ -26,6 +26,7 @@
 
 #include "compositor.h"
 #include "text-cursor-position-server-protocol.h"
+#include "shared/helpers.h"
 
 static void
 weston_zoom_frame_z(struct weston_animation *animation,
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index d838dfc..15b31a5 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -32,6 +32,7 @@
 #include "weston-test-server-protocol.h"
 #include "ivi-test.h"
 #include "ivi-shell/ivi-layout-export.h"
+#include "shared/helpers.h"
 
 struct test_context;
 
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 911ee6d..e6406b1 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -37,6 +37,8 @@
 #include "src/weston-egl-ext.h"
 #endif /* ENABLE_EGL */
 
+#include "shared/helpers.h"
+
 struct weston_test {
 	struct weston_compositor *compositor;
 	struct weston_layer layer;
diff --git a/xwayland/launcher.c b/xwayland/launcher.c
index df2efd2..8316a45 100644
--- a/xwayland/launcher.c
+++ b/xwayland/launcher.c
@@ -33,6 +33,7 @@
 #include <signal.h>
 
 #include "xwayland.h"
+#include "shared/helpers.h"
 
 
 static int
-- 
2.1.0



More information about the wayland-devel mailing list