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

2012-06-11 Thread Pauli Nieminen
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.niemi...@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
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2012-06-11 Thread Brian Paul

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 Nieminenpauli.niemi...@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 @@
  #includestring.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
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2012-06-11 Thread Eric Anholt
On Mon, 11 Jun 2012 09:07:19 -0600, Brian Paul bri...@vmware.com wrote:
 On 06/11/2012 12:59 AM, Pauli Nieminen wrote:
  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.

On the other hand, ARRAY_SIZE is the macro from the linux kernel, which
we also use in libdrm and the 2d driver and most of piglit.  It's nice
to be able to type the same thing across the driver project.  It's also
very clear what it does, unlike a macro named Elements in vbo-related
code which makes me think of vertex elements.

But I'm fine with Mesa core continuing with Elements to avoid churn.


pgphwayqagwy4.pgp
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev