diff --git a/Makefile.am b/Makefile.am index 5819b199..261798c7 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 c5ecbe92..04c1cfcb 100644 --- a/clients/calibrator.c +++ b/clients/calibrator.c @@ -35,10 +35,9 @@ #include #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 1ab20332..e6a0c399 100644 --- a/clients/dnd.c +++ b/clients/dnd.c @@ -41,6 +41,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 a86c590e..d0b7feed 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -36,6 +36,7 @@ #include +#include "shared/helpers.h" #include "window.h" #include "text-client-protocol.h" diff --git a/clients/eventdemo.c b/clients/eventdemo.c index 0f98869a..dc69fd66 100644 --- a/clients/eventdemo.c +++ b/clients/eventdemo.c @@ -38,6 +38,7 @@ #include +#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 cff7664f..0e99d25a 100644 --- a/clients/ivi-shell-user-interface.c +++ b/clients/ivi-shell-user-interface.c @@ -35,6 +35,7 @@ #include #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" @@ -175,7 +176,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 92720f40..f758fdc2 100644 --- a/clients/nested.c +++ b/clients/nested.c @@ -46,6 +46,7 @@ #define WL_HIDE_DEPRECATED #include +#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 e81f5f4c..cf4517c7 100644 --- a/clients/presentation-shm.c +++ b/clients/presentation-shm.c @@ -36,11 +36,10 @@ #include #include +#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 78643946..446f2cad 100644 --- a/clients/simple-touch.c +++ b/clients/simple-touch.c @@ -33,10 +33,9 @@ #include #include +#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 fc8f8fb2..ae9c3326 100644 --- a/clients/stacking.c +++ b/clients/stacking.c @@ -32,6 +32,7 @@ #include #include +#include "shared/helpers.h" #include "window.h" struct stacking { diff --git a/clients/subsurfaces.c b/clients/subsurfaces.c index 749e9bbb..32179db0 100644 --- a/clients/subsurfaces.c +++ b/clients/subsurfaces.c @@ -41,6 +41,7 @@ #include #include +#include "shared/helpers.h" #include "window.h" #if 0 diff --git a/clients/terminal.c b/clients/terminal.c index 67e8d1de..ad68a00f 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -44,6 +44,7 @@ #include #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 0eb589d9..58e8e833 100644 --- a/clients/weston-info.c +++ b/clients/weston-info.c @@ -32,11 +32,10 @@ #include +#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 67afabda..c5e6f5af 100644 --- a/clients/window.c +++ b/clients/window.c @@ -67,6 +67,7 @@ typedef void *EGLContext; #include #include #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 dc089a2e..c47aa515 100644 --- a/clients/window.h +++ b/clients/window.h @@ -33,8 +33,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 8d969633..804ab324 100644 --- a/clients/wscreensaver.c +++ b/clients/wscreensaver.c @@ -37,6 +37,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 ec3a52be..f9c25839 100644 --- a/ivi-shell/ivi-shell.c +++ b/ivi-shell/ivi-shell.c @@ -45,6 +45,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 f6d02a89..21fcbea5 100644 --- a/shared/cairo-util.c +++ b/shared/cairo-util.c @@ -35,11 +35,10 @@ #include #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 00000000..7502ff32 --- /dev/null +++ b/shared/helpers.h @@ -0,0 +1,48 @@ +/* + * Copyright © 2015 Samsung Electronics Co., Ltd + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * 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 b01266c8..ec75bd4f 100644 --- a/shared/image-loader.c +++ b/shared/image-loader.c @@ -34,10 +34,9 @@ #include #include +#include "shared/helpers.h" #include "image-loader.h" -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) - #ifdef HAVE_WEBP #include #endif diff --git a/src/compositor-drm.c b/src/compositor-drm.c index 33e2af6b..6d8684dd 100644 --- a/src/compositor-drm.c +++ b/src/compositor-drm.c @@ -46,6 +46,7 @@ #include #include +#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 04fb7188..a6fd8231 100644 --- a/src/compositor-fbdev.c +++ b/src/compositor-fbdev.c @@ -42,6 +42,7 @@ #include +#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 598eb33f..c0e35ce9 100644 --- a/src/compositor-headless.c +++ b/src/compositor-headless.c @@ -31,6 +31,7 @@ #include #include +#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 d155507d..6d4d1e4f 100644 --- a/src/compositor-rdp.c +++ b/src/compositor-rdp.c @@ -65,6 +65,7 @@ #include #include +#include "shared/helpers.h" #include "compositor.h" #include "pixman-renderer.h" diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c index 722cf9c3..8012461d 100644 --- a/src/compositor-rpi.c +++ b/src/compositor-rpi.c @@ -46,6 +46,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 46105527..ab738535 100644 --- a/src/compositor-wayland.c +++ b/src/compositor-wayland.c @@ -42,6 +42,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 c5dcfb9a..b85b1349 100644 --- a/src/compositor-x11.c +++ b/src/compositor-x11.c @@ -53,6 +53,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 2f7864f6..2f89b398 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -61,6 +61,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 1e4ca27c..685767e3 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -49,8 +49,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 ad7012a5..62eb4903 100644 --- a/src/gl-renderer.c +++ b/src/gl-renderer.c @@ -40,6 +40,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 65d2d092..568985f7 100644 --- a/src/input.c +++ b/src/input.c @@ -34,6 +34,7 @@ #include #include +#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 90dee296..d6401c4d 100644 --- a/tests/ivi_layout-test.c +++ b/tests/ivi_layout-test.c @@ -28,6 +28,7 @@ #include #include +#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 f3152f56..27f33daa 100644 --- a/tests/presentation-test.c +++ b/tests/presentation-test.c @@ -31,6 +31,7 @@ #include #include +#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 2a5ec10e..8a4e5a6b 100644 --- a/tests/vertex-clip-test.c +++ b/tests/vertex-clip-test.c @@ -30,6 +30,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 0ed131cd..a4436919 100644 --- a/tests/weston-test-runner.h +++ b/tests/weston-test-runner.h @@ -31,6 +31,8 @@ #include +#include "shared/helpers.h" + #ifdef NDEBUG #error "Tests must not be built with NDEBUG defined, they rely on assert()." #endif @@ -44,8 +46,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 82771c4d..572a0b59 100644 --- a/xwayland/selection.c +++ b/xwayland/selection.c @@ -31,6 +31,7 @@ #include #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 9b4e0886..c3a57c19 100644 --- a/xwayland/window-manager.c +++ b/xwayland/window-manager.c @@ -42,6 +42,7 @@ #include "cairo-util.h" #include "compositor.h" #include "hash.h" +#include "shared/helpers.h" struct wm_size_hints { uint32_t flags;