[PATCH weston 2/4] Moved helper macro to a discrete include file.
Jon A. Cruz
jonc at osg.samsung.com
Fri Jun 12 21:25:03 PDT 2015
To help reduce code duplication and also 'kitchen-sink' includes
the ARRAY_LENGTH macro was moved to a stand-alone file and
referenced from the sources consuming it. Other macros will be
added in subsequent passes.
Signed-off-by: Jon A. Cruz <jonc at osg.samsung.com>
---
Makefile.am | 1 +
clients/calibrator.c | 3 +--
clients/dnd.c | 1 +
clients/editor.c | 1 +
clients/eventdemo.c | 1 +
clients/ivi-shell-user-interface.c | 2 +-
clients/nested.c | 1 +
clients/presentation-shm.c | 3 +--
clients/simple-touch.c | 3 +--
clients/stacking.c | 1 +
clients/subsurfaces.c | 1 +
clients/terminal.c | 1 +
clients/weston-info.c | 3 +--
clients/window.c | 1 +
clients/window.h | 2 --
clients/wscreensaver.c | 1 +
ivi-shell/ivi-shell.c | 1 +
shared/cairo-util.c | 3 +--
shared/helpers.h | 49 ++++++++++++++++++++++++++++++++++++++
shared/image-loader.c | 3 +--
src/compositor-drm.c | 1 +
src/compositor-fbdev.c | 1 +
src/compositor-headless.c | 1 +
src/compositor-rdp.c | 1 +
src/compositor-rpi.c | 1 +
src/compositor-wayland.c | 1 +
src/compositor-x11.c | 1 +
src/compositor.c | 1 +
src/compositor.h | 2 --
src/gl-renderer.c | 1 +
src/input.c | 1 +
tests/ivi_layout-test.c | 1 +
tests/presentation-test.c | 1 +
tests/vertex-clip-test.c | 1 +
tests/weston-test-runner.h | 4 ++--
xwayland/selection.c | 1 +
xwayland/window-manager.c | 1 +
37 files changed, 84 insertions(+), 19 deletions(-)
create mode 100644 shared/helpers.h
diff --git a/Makefile.am b/Makefile.am
index 5819b19..261798c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -189,6 +189,7 @@ westoninclude_HEADERS = \
src/timeline-object.h \
shared/matrix.h \
shared/config-parser.h \
+ shared/helpers.h \
shared/zalloc.h \
shared/platform.h
diff --git a/clients/calibrator.c b/clients/calibrator.c
index 4865095..1dad91d 100644
--- a/clients/calibrator.c
+++ b/clients/calibrator.c
@@ -34,10 +34,9 @@
#include <wayland-client.h>
#include "window.h"
+#include "shared/helpers.h"
#include "shared/matrix.h"
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
/* Our points for the calibration must be not be on a line */
static const struct {
float x_ratio, y_ratio;
diff --git a/clients/dnd.c b/clients/dnd.c
index 00e87a5..b8ecb64 100644
--- a/clients/dnd.c
+++ b/clients/dnd.c
@@ -40,6 +40,7 @@
#include "window.h"
#include "shared/cairo-util.h"
+#include "shared/helpers.h"
struct dnd_drag;
diff --git a/clients/editor.c b/clients/editor.c
index 5407337..d084c93 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -35,6 +35,7 @@
#include <pango/pangocairo.h>
+#include "shared/helpers.h"
#include "window.h"
#include "text-client-protocol.h"
diff --git a/clients/eventdemo.c b/clients/eventdemo.c
index 50a9cb4..daf5710 100644
--- a/clients/eventdemo.c
+++ b/clients/eventdemo.c
@@ -37,6 +37,7 @@
#include <cairo.h>
+#include "shared/helpers.h"
#include "window.h"
/** window title */
diff --git a/clients/ivi-shell-user-interface.c b/clients/ivi-shell-user-interface.c
index 1b8a45d..868747d 100644
--- a/clients/ivi-shell-user-interface.c
+++ b/clients/ivi-shell-user-interface.c
@@ -34,6 +34,7 @@
#include <wayland-cursor.h>
#include "shared/cairo-util.h"
#include "shared/config-parser.h"
+#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "ivi-application-client-protocol.h"
#include "ivi-hmi-controller-client-protocol.h"
@@ -174,7 +175,6 @@ mem_alloc(size_t size, char *file, int32_t line)
}
#define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__)
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
/*****************************************************************************
* Event Handler
diff --git a/clients/nested.c b/clients/nested.c
index 0b18dd5..12a4c0e 100644
--- a/clients/nested.c
+++ b/clients/nested.c
@@ -45,6 +45,7 @@
#define WL_HIDE_DEPRECATED
#include <wayland-server.h>
+#include "shared/helpers.h"
#include "window.h"
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
diff --git a/clients/presentation-shm.c b/clients/presentation-shm.c
index 0d62872..2f47dfb 100644
--- a/clients/presentation-shm.c
+++ b/clients/presentation-shm.c
@@ -35,11 +35,10 @@
#include <time.h>
#include <wayland-client.h>
+#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "presentation_timing-client-protocol.h"
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
enum run_mode {
RUN_MODE_FEEDBACK,
RUN_MODE_FEEDBACK_IDLE,
diff --git a/clients/simple-touch.c b/clients/simple-touch.c
index e187bcf..624ebca 100644
--- a/clients/simple-touch.c
+++ b/clients/simple-touch.c
@@ -32,10 +32,9 @@
#include <sys/mman.h>
#include <wayland-client.h>
+#include "shared/helpers.h"
#include "shared/os-compatibility.h"
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
struct seat {
struct touch *touch;
struct wl_seat *seat;
diff --git a/clients/stacking.c b/clients/stacking.c
index ea6101d..a09420a 100644
--- a/clients/stacking.c
+++ b/clients/stacking.c
@@ -31,6 +31,7 @@
#include <linux/input.h>
#include <cairo.h>
+#include "shared/helpers.h"
#include "window.h"
struct stacking {
diff --git a/clients/subsurfaces.c b/clients/subsurfaces.c
index 663e1e1..7b80db5 100644
--- a/clients/subsurfaces.c
+++ b/clients/subsurfaces.c
@@ -40,6 +40,7 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
+#include "shared/helpers.h"
#include "window.h"
#if 0
diff --git a/clients/terminal.c b/clients/terminal.c
index 77f9bd6..d1fc6cb 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -43,6 +43,7 @@
#include <wayland-client.h>
#include "shared/config-parser.h"
+#include "shared/helpers.h"
#include "window.h"
static int option_fullscreen;
diff --git a/clients/weston-info.c b/clients/weston-info.c
index 10924a9..480fd01 100644
--- a/clients/weston-info.c
+++ b/clients/weston-info.c
@@ -31,11 +31,10 @@
#include <wayland-client.h>
+#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "presentation_timing-client-protocol.h"
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
typedef void (*print_info_t)(void *info);
diff --git a/clients/window.c b/clients/window.c
index f2100fb..3af660b 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -66,6 +66,7 @@ typedef void *EGLContext;
#include <linux/input.h>
#include <wayland-client.h>
#include "shared/cairo-util.h"
+#include "shared/helpers.h"
#include "xdg-shell-client-protocol.h"
#include "text-cursor-position-client-protocol.h"
#include "workspaces-client-protocol.h"
diff --git a/clients/window.h b/clients/window.h
index 5d33997..0535a38 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -32,8 +32,6 @@
#include "shared/zalloc.h"
#include "shared/platform.h"
-#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) );})
diff --git a/clients/wscreensaver.c b/clients/wscreensaver.c
index f75d0d8..0ff6045 100644
--- a/clients/wscreensaver.c
+++ b/clients/wscreensaver.c
@@ -36,6 +36,7 @@
#include "desktop-shell-client-protocol.h"
#include "window.h"
+#include "shared/helpers.h"
extern struct wscreensaver_plugin glmatrix_screensaver;
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
index 8f1c3ca..b1ea3ba 100644
--- a/ivi-shell/ivi-shell.c
+++ b/ivi-shell/ivi-shell.c
@@ -42,6 +42,7 @@
#include "ivi-application-server-protocol.h"
#include "ivi-layout-export.h"
#include "ivi-layout-private.h"
+#include "shared/helpers.h"
/* Representation of ivi_surface protocol object. */
struct ivi_shell_surface
diff --git a/shared/cairo-util.c b/shared/cairo-util.c
index a73c08b..5a4f246 100644
--- a/shared/cairo-util.c
+++ b/shared/cairo-util.c
@@ -32,11 +32,10 @@
#include <cairo.h>
#include "cairo-util.h"
+#include "shared/helpers.h"
#include "image-loader.h"
#include "config-parser.h"
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
void
surface_flush_device(cairo_surface_t *surface)
{
diff --git a/shared/helpers.h b/shared/helpers.h
new file mode 100644
index 0000000..2e4ae44
--- /dev/null
+++ b/shared/helpers.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2015 Samsung Electronics Co., Ltd
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef WESTON_HELPERS_H
+#define WESTON_HELPERS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file
+ * Simple misc helper macros.
+ */
+
+/**
+ * Compile-time computation of number of items in a hardcoded array.
+ *
+ * @param a the array being measured.
+ * @return the number of items hardcoded into the array.
+ */
+#ifndef ARRAY_LENGTH
+#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* WESTON_HELPERS_H */
diff --git a/shared/image-loader.c b/shared/image-loader.c
index c4d763f..b7bc981 100644
--- a/shared/image-loader.c
+++ b/shared/image-loader.c
@@ -31,10 +31,9 @@
#include <png.h>
#include <pixman.h>
+#include "shared/helpers.h"
#include "image-loader.h"
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
#ifdef HAVE_WEBP
#include <webp/decode.h>
#endif
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index bf921be..abe8ec4 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -43,6 +43,7 @@
#include <gbm.h>
#include <libudev.h>
+#include "shared/helpers.h"
#include "libbacklight.h"
#include "compositor.h"
#include "gl-renderer.h"
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
index 3f3394f..6abfa8c 100644
--- a/src/compositor-fbdev.c
+++ b/src/compositor-fbdev.c
@@ -39,6 +39,7 @@
#include <libudev.h>
+#include "shared/helpers.h"
#include "compositor.h"
#include "launcher-util.h"
#include "pixman-renderer.h"
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
index fe35289..a4aeee0 100644
--- a/src/compositor-headless.c
+++ b/src/compositor-headless.c
@@ -28,6 +28,7 @@
#include <sys/time.h>
#include <stdbool.h>
+#include "shared/helpers.h"
#include "compositor.h"
#include "pixman-renderer.h"
#include "presentation_timing-server-protocol.h"
diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c
index 4091bac..29a1707 100644
--- a/src/compositor-rdp.c
+++ b/src/compositor-rdp.c
@@ -62,6 +62,7 @@
#include <freerdp/locale/keyboard.h>
#include <winpr/input.h>
+#include "shared/helpers.h"
#include "compositor.h"
#include "pixman-renderer.h"
diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c
index 1c0a783..3ecad99 100644
--- a/src/compositor-rpi.c
+++ b/src/compositor-rpi.c
@@ -43,6 +43,7 @@
# include "rpi-bcm-stubs.h"
#endif
+#include "shared/helpers.h"
#include "compositor.h"
#include "rpi-renderer.h"
#include "launcher-util.h"
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index cf2777c..2d08cbd 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -39,6 +39,7 @@
#include "compositor.h"
#include "gl-renderer.h"
#include "pixman-renderer.h"
+#include "shared/helpers.h"
#include "shared/image-loader.h"
#include "shared/os-compatibility.h"
#include "shared/cairo-util.h"
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index a7ca8d4..598a797 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -50,6 +50,7 @@
#include "gl-renderer.h"
#include "pixman-renderer.h"
#include "shared/config-parser.h"
+#include "shared/helpers.h"
#include "shared/image-loader.h"
#include "presentation_timing-server-protocol.h"
diff --git a/src/compositor.c b/src/compositor.c
index 5d5df16..49fc92c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -58,6 +58,7 @@
#include "compositor.h"
#include "scaler-server-protocol.h"
#include "presentation_timing-server-protocol.h"
+#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "git-version.h"
#include "version.h"
diff --git a/src/compositor.h b/src/compositor.h
index b414b5f..54cda7a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -46,8 +46,6 @@ extern "C" {
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#endif
-#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) );})
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index d18e124..c426bfc 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -37,6 +37,7 @@
#include "gl-renderer.h"
#include "vertex-clipping.h"
+#include "shared/helpers.h"
#include "weston-egl-ext.h"
struct gl_shader {
diff --git a/src/input.c b/src/input.c
index 8b2dfcc..d32bc6c 100644
--- a/src/input.c
+++ b/src/input.c
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <limits.h>
+#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "compositor.h"
diff --git a/tests/ivi_layout-test.c b/tests/ivi_layout-test.c
index daa9aa7..1dc82ec 100644
--- a/tests/ivi_layout-test.c
+++ b/tests/ivi_layout-test.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
+#include "shared/helpers.h"
#include "weston-test-client-helper.h"
#include "ivi-application-client-protocol.h"
#include "ivi-test.h"
diff --git a/tests/presentation-test.c b/tests/presentation-test.c
index ae17b84..45b783b 100644
--- a/tests/presentation-test.c
+++ b/tests/presentation-test.c
@@ -28,6 +28,7 @@
#include <assert.h>
#include <time.h>
+#include "shared/helpers.h"
#include "weston-test-client-helper.h"
#include "presentation_timing-client-protocol.h"
diff --git a/tests/vertex-clip-test.c b/tests/vertex-clip-test.c
index a1623a8..779b5c8 100644
--- a/tests/vertex-clip-test.c
+++ b/tests/vertex-clip-test.c
@@ -27,6 +27,7 @@
#include "weston-test-runner.h"
+#include "shared/helpers.h"
#include "src/vertex-clipping.h"
#define BOUNDING_BOX_TOP_Y 100.0f
diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h
index 193b76d..cdf2aad 100644
--- a/tests/weston-test-runner.h
+++ b/tests/weston-test-runner.h
@@ -28,6 +28,8 @@
#include <stdlib.h>
+#include "shared/helpers.h"
+
#ifdef NDEBUG
#error "Tests must not be built with NDEBUG defined, they rely on assert()."
#endif
@@ -41,8 +43,6 @@ struct weston_test {
int must_fail;
} __attribute__ ((aligned (32)));
-#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0]))
-
#define TEST_BEGIN(name, arg) \
static void name(arg)
diff --git a/xwayland/selection.c b/xwayland/selection.c
index 24bd56d..84e0ff3 100644
--- a/xwayland/selection.c
+++ b/xwayland/selection.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include "xwayland.h"
+#include "shared/helpers.h"
static int
writable_callback(int fd, uint32_t mask, void *data)
diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
index ca66203..ea1d9d3 100644
--- a/xwayland/window-manager.c
+++ b/xwayland/window-manager.c
@@ -39,6 +39,7 @@
#include "cairo-util.h"
#include "compositor.h"
#include "hash.h"
+#include "shared/helpers.h"
struct wm_size_hints {
uint32_t flags;
--
2.1.0
More information about the wayland-devel
mailing list