From 35b2eaa989e4960501943c0753e2d5a3e687db92 Mon Sep 17 00:00:00 2001 From: Jon Cruz Date: Mon, 15 Jun 2015 15:37:08 -0700 Subject: Moved helper macro to a discrete include file. 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 Reviewed-by: Peter Hutterer Reviewed-by: Bryce Harrington --- shared/cairo-util.c | 3 +-- shared/helpers.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ shared/image-loader.c | 3 +-- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 shared/helpers.h (limited to 'shared') 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 -- cgit v1.2.1