Consolidate some redundant definitions of ARRAY_SIZE() macro.
authorPaul Berry <stereotype441@gmail.com>
Wed, 6 Feb 2013 17:50:22 +0000 (09:50 -0800)
committerPaul Berry <stereotype441@gmail.com>
Fri, 8 Feb 2013 14:51:22 +0000 (06:51 -0800)
Previous to this patch, there were 13 identical definitions of this
macro in Mesa source.  That's ridiculous.  This patch consolidates 6
of them to a single definition in src/mesa/main/macros.h.

Unfortunately, I wasn't able to eliminate the remaining definitions,
since they occur in places that don't include src/mesa/main/macros.h:

- include/pci_ids/pci_id_driver_map.h
- src/egl/drivers/dri2/egl_dri2.h
- src/egl/main/egldefines.h
- src/gbm/main/backend.c
- src/gbm/main/gbm.c
- src/glx/glxclient.h
- src/mapi/mapi/stub.c

I'm open to suggestions as to how to deal with the remaining redundancy.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/common/utils.c
src/mesa/drivers/dri/intel/intel_context.h
src/mesa/drivers/dri/intel/intel_fbo.h
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/main/hash_table.c
src/mesa/main/macros.h
src/mesa/main/set.c

index 062712bf335fdc9254b4f8b65248f730e56b5d2c..ac0773b0d4ca0fa4ec78bb651565ba1812298156 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdbool.h>
+#include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/cpuinfo.h"
 #include "main/extensions.h"
@@ -391,8 +392,6 @@ static const struct { unsigned int attrib, offset; } attribMap[] = {
     __ATTRIB(__DRI_ATTRIB_SWAP_METHOD,                 level)
 };
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 
 /**
  * Return the value of a configuration attribute.  The attribute is
index af49ab137c367382b8a764fe1521bef1906e0647..cae8ecf7a4fbf0c6ae3abbdac5663c1e9a549625 100644 (file)
@@ -348,8 +348,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 down to an alignment value
  *
index f135dead3ee11aed577dc2ce971041dc4824aefd..ce744bf13843dd98e319c613c4cb47b6b40d78d4 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdbool.h>
 #include <assert.h>
 #include "main/formats.h"
+#include "main/macros.h"
 #include "intel_context.h"
 #include "intel_screen.h"
 
index 7d1c0be4365baa2a4d54a4b4de345b52074290ae..ee77fc48134f9a5e384908db0fcbc29a8de60d38 100644 (file)
@@ -701,8 +701,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.
index 2bd1929aa9dd3b36462a1d53fda45fb14c3b440d..af0510da105296c70bdc544b730581dad62ff7e1 100644 (file)
 #include <string.h>
 
 #include "main/hash_table.h"
+#include "main/macros.h"
 #include "ralloc.h"
 
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
-
 static const uint32_t deleted_key_value;
 
 /**
index d1e81fe082c0e93940af6e7ee5c299919158e7b5..f6d38fb6480fe0d308855bf66e839c9e3e4177be 100644 (file)
@@ -766,5 +766,8 @@ DIFFERENT_SIGNS(GLfloat x, GLfloat y)
 #define ENUM_TO_DOUBLE(E)  ((GLdouble)(GLint)(E))
 #define ENUM_TO_BOOLEAN(E) ((E) ? GL_TRUE : GL_FALSE)
 
+/* Compute the size of an array */
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
 
 #endif
index 736841fc9c0f52e63f08101d3cab34b19dda54e0..2519b96947a64bac3bb59dd0e0cdfd610fb8c475 100644 (file)
 
 #include <stdlib.h>
 
+#include "macros.h"
 #include "set.h"
 #include "ralloc.h"
 
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
-
 /*
  * From Knuth -- a good choice for hash/rehash values is p, p-2 where
  * p and p-2 are both prime.  These tables are sized to have an extra 10%