Michael Stefaniuc : widl: Add the ARRAY_SIZE() macro.

Alexandre Julliard julliard at winehq.org
Thu Sep 26 15:51:20 CDT 2019


Module: wine
Branch: master
Commit: bbcf44eb970761d8c40eecc5692cf58ce378a8c7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bbcf44eb970761d8c40eecc5692cf58ce378a8c7

Author: Michael Stefaniuc <mstefani at winehq.org>
Date:   Thu Sep 26 17:50:59 2019 +0200

widl: Add the ARRAY_SIZE() macro.

Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 tools/widl/typelib.c | 5 ++---
 tools/widl/utils.c   | 2 +-
 tools/widl/utils.h   | 2 ++
 tools/widl/widl.c    | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/widl/typelib.c b/tools/widl/typelib.c
index 79e72e0472..cf027558d0 100644
--- a/tools/widl/typelib.c
+++ b/tools/widl/typelib.c
@@ -64,7 +64,6 @@ static const struct oatype {
   {"VARIANT",       VT_VARIANT},
   {"VARIANT_BOOL",  VT_BOOL}
 };
-#define NTYPES (sizeof(oatypes)/sizeof(oatypes[0]))
 #define KWP(p) ((const struct oatype *)(p))
 
 static int kw_cmp_func(const void *s1, const void *s2)
@@ -79,11 +78,11 @@ static unsigned short builtin_vt(const type_t *t)
   const struct oatype *kwp;
   key.kw = kw;
 #ifdef KW_BSEARCH
-  kwp = bsearch(&key, oatypes, NTYPES, sizeof(oatypes[0]), kw_cmp_func);
+  kwp = bsearch(&key, oatypes, ARRAY_SIZE(oatypes), sizeof(oatypes[0]), kw_cmp_func);
 #else
   {
     unsigned int i;
-    for (kwp=NULL, i=0; i < NTYPES; i++)
+    for (kwp = NULL, i = 0; i < ARRAY_SIZE(oatypes); i++)
       if (!kw_cmp_func(&key, &oatypes[i])) {
         kwp = &oatypes[i];
         break;
diff --git a/tools/widl/utils.c b/tools/widl/utils.c
index 90668873aa..20c63064c7 100644
--- a/tools/widl/utils.c
+++ b/tools/widl/utils.c
@@ -309,7 +309,7 @@ void add_output_to_resources( const char *type, const char *name )
     size_t data_size = output_buffer_pos;
     size_t header_size = 5 * sizeof(unsigned int) + 2 * sizeof(unsigned short);
 
-    assert( nb_resources < sizeof(resources)/sizeof(resources[0]) );
+    assert( nb_resources < ARRAY_SIZE( resources ));
 
     if (type[0] != '#') header_size += (strlen( type ) + 1) * sizeof(unsigned short);
     else header_size += 2 * sizeof(unsigned short);
diff --git a/tools/widl/utils.h b/tools/widl/utils.h
index ec02fc7c37..74dba11d3c 100644
--- a/tools/widl/utils.h
+++ b/tools/widl/utils.h
@@ -34,6 +34,8 @@ int strendswith(const char* str, const char* end);
 #define __attribute__(X)
 #endif
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 void parser_error(const char *s) __attribute__((noreturn));
 int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
 void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn));
diff --git a/tools/widl/widl.c b/tools/widl/widl.c
index 1620dfdb3a..f5fa20c884 100644
--- a/tools/widl/widl.c
+++ b/tools/widl/widl.c
@@ -302,7 +302,7 @@ static void set_target( const char *target )
 
     if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
     *p++ = 0;
-    for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
+    for (i = 0; i < ARRAY_SIZE( cpu_names ); i++)
     {
         if (!strcmp( cpu_names[i].name, spec ))
         {




More information about the wine-cvs mailing list