[Mesa-dev] [PATCH 06/21] mesa/macros: Add ARRAY_SIZE helper macro core mesa

Brian Paul brianp at vmware.com
Mon Jun 11 08:07:19 PDT 2012


On 06/11/2012 12:59 AM, Pauli Nieminen wrote:
> The ARRAY_SIZE macro is usefull helper that is used already in many
> parts of core. But mesa core was missing it. I decided to add it to the
> macros.h when I wanted to use it in following patch.
>
> Signed-off-by: Pauli Nieminen<pauli.nieminen at linux.intel.com>
> ---
>   src/mesa/drivers/dri/intel/intel_context.h  |    3 +--
>   src/mesa/drivers/dri/radeon/radeon_screen.c |    2 --
>   src/mesa/main/macros.h                      |    3 +++
>   3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
> index cc3ee0d..4dc98d6 100644
> --- a/src/mesa/drivers/dri/intel/intel_context.h
> +++ b/src/mesa/drivers/dri/intel/intel_context.h
> @@ -33,6 +33,7 @@
>   #include<string.h>
>   #include "main/mtypes.h"
>   #include "main/mm.h"
> +#include "main/macros.h"
>
>   #ifdef __cplusplus
>   extern "C" {
> @@ -341,8 +342,6 @@ extern char *__progname;
>   #define SUBPIXEL_X 0.125
>   #define SUBPIXEL_Y 0.125
>
> -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
> -
>   /**
>    * Align a value up to an alignment value
>    *
> diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c
> index 85cfe17..b0545b5 100644
> --- a/src/mesa/drivers/dri/radeon/radeon_screen.c
> +++ b/src/mesa/drivers/dri/radeon/radeon_screen.c
> @@ -702,8 +702,6 @@ radeonDestroyBuffer(__DRIdrawable *driDrawPriv)
>       _mesa_reference_framebuffer((struct gl_framebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
>   }
>
> -#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
> -
>   /**
>    * This is the driver specific part of the createNewScreen entry point.
>    * Called when using DRI2.
> diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
> index d1df2ce..e05fa14 100644
> --- a/src/mesa/main/macros.h
> +++ b/src/mesa/main/macros.h
> @@ -679,5 +679,8 @@ do {                        \
>   #define ENUM_TO_DOUBLE(E)  ((GLdouble)(GLint)(E))
>   #define ENUM_TO_BOOLEAN(E) ((E) ? GL_TRUE : GL_FALSE)
>
> +#ifndef ARRAY_SIZE
> +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
> +#endif
>
>   #endif


Core Mesa uses the Element() macro for this, defined in compiler.h. 
We should just use one or the other.  I'd go with just using Element() 
everywhere for now to avoid churn.

-Brian


More information about the mesa-dev mailing list