From 2c5af590ddbb08e0a46b7e37c5f0230b1805cd37 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Thu, 20 Nov 2014 12:19:47 -0800 Subject: Refactor ARRAY_LENGTH macro definitions in test code --- boilerplate/cairo-boilerplate-pdf.c | 2 -- boilerplate/cairo-boilerplate-private.h | 2 +- boilerplate/cairo-boilerplate.h | 4 ++++ perf/cairo-perf.h | 4 ---- test/any2ppm.c | 2 +- test/cairo-test.c | 4 ---- test/cairo-test.h | 4 ---- 7 files changed, 6 insertions(+), 16 deletions(-) diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c index d76d13951..177cdf174 100644 --- a/boilerplate/cairo-boilerplate-pdf.c +++ b/boilerplate/cairo-boilerplate-pdf.c @@ -54,8 +54,6 @@ typedef struct _pdf_target_closure cairo_surface_t *target; } pdf_target_closure_t; -#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) - static cairo_surface_t * _cairo_boilerplate_pdf_create_surface (const char *name, cairo_content_t content, diff --git a/boilerplate/cairo-boilerplate-private.h b/boilerplate/cairo-boilerplate-private.h index a7a2dd0eb..d16a645b2 100644 --- a/boilerplate/cairo-boilerplate-private.h +++ b/boilerplate/cairo-boilerplate-private.h @@ -41,7 +41,7 @@ _cairo_boilerplate_register_backend (const cairo_boilerplate_target_t *targets, void _register_##name__ (void); \ void _register_##name__ (void) { \ _cairo_boilerplate_register_backend (targets__, \ - sizeof (targets__) / sizeof (targets__[0])); \ + ARRAY_LENGTH(targets__)); \ } #define CAIRO_NO_BOILERPLATE(name__) \ diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h index 4f6b8fde9..515bb03bc 100644 --- a/boilerplate/cairo-boilerplate.h +++ b/boilerplate/cairo-boilerplate.h @@ -94,6 +94,10 @@ #define M_PI 3.14159265358979323846 #endif +#ifndef ARRAY_LENGTH +#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) +#endif + CAIRO_BEGIN_DECLS /* A fake format we use for the flattened ARGB output of the PS and diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h index b32b0e0ff..eb53d13c2 100644 --- a/perf/cairo-perf.h +++ b/perf/cairo-perf.h @@ -203,10 +203,6 @@ test_report_cmp_name (const void *a, #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif -#ifndef ARRAY_LENGTH -#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) -#endif - CAIRO_PERF_DECL (fill); CAIRO_PERF_DECL (paint); CAIRO_PERF_DECL (paint_with_alpha); diff --git a/test/any2ppm.c b/test/any2ppm.c index 665314f1e..b60b4d959 100644 --- a/test/any2ppm.c +++ b/test/any2ppm.c @@ -100,7 +100,7 @@ #endif #endif -#define ARRAY_LENGTH(A) (sizeof (A) / sizeof (A[0])) +#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) static int _cairo_writen (int fd, char *buf, int len) diff --git a/test/cairo-test.c b/test/cairo-test.c index 8dbf4c6af..a351b0174 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -83,10 +83,6 @@ #define TRUE !FALSE #endif -#ifndef ARRAY_LENGTH -#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) -#endif - #if ! HAVE_ALARM || ! defined(SIGALRM) #define alarm(X); #endif diff --git a/test/cairo-test.h b/test/cairo-test.h index c753728f0..7e9605f61 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -107,10 +107,6 @@ cairo_test_NaN (void) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif -#ifndef ARRAY_LENGTH -#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) -#endif - #define CAIRO_TEST_OUTPUT_DIR "output" #define CAIRO_TEST_LOG_SUFFIX ".log" -- cgit v1.2.1