Commit bbcf44eb authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

widl: Add the ARRAY_SIZE() macro.

parent fe91ae51
...@@ -64,7 +64,6 @@ static const struct oatype { ...@@ -64,7 +64,6 @@ static const struct oatype {
{"VARIANT", VT_VARIANT}, {"VARIANT", VT_VARIANT},
{"VARIANT_BOOL", VT_BOOL} {"VARIANT_BOOL", VT_BOOL}
}; };
#define NTYPES (sizeof(oatypes)/sizeof(oatypes[0]))
#define KWP(p) ((const struct oatype *)(p)) #define KWP(p) ((const struct oatype *)(p))
static int kw_cmp_func(const void *s1, const void *s2) static int kw_cmp_func(const void *s1, const void *s2)
...@@ -79,11 +78,11 @@ static unsigned short builtin_vt(const type_t *t) ...@@ -79,11 +78,11 @@ static unsigned short builtin_vt(const type_t *t)
const struct oatype *kwp; const struct oatype *kwp;
key.kw = kw; key.kw = kw;
#ifdef KW_BSEARCH #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 #else
{ {
unsigned int i; 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])) { if (!kw_cmp_func(&key, &oatypes[i])) {
kwp = &oatypes[i]; kwp = &oatypes[i];
break; break;
......
...@@ -309,7 +309,7 @@ void add_output_to_resources( const char *type, const char *name ) ...@@ -309,7 +309,7 @@ void add_output_to_resources( const char *type, const char *name )
size_t data_size = output_buffer_pos; size_t data_size = output_buffer_pos;
size_t header_size = 5 * sizeof(unsigned int) + 2 * sizeof(unsigned short); 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); if (type[0] != '#') header_size += (strlen( type ) + 1) * sizeof(unsigned short);
else header_size += 2 * sizeof(unsigned short); else header_size += 2 * sizeof(unsigned short);
......
...@@ -34,6 +34,8 @@ int strendswith(const char* str, const char* end); ...@@ -34,6 +34,8 @@ int strendswith(const char* str, const char* end);
#define __attribute__(X) #define __attribute__(X)
#endif #endif
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
void parser_error(const char *s) __attribute__((noreturn)); void parser_error(const char *s) __attribute__((noreturn));
int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn)); void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn));
......
...@@ -302,7 +302,7 @@ static void set_target( const char *target ) ...@@ -302,7 +302,7 @@ static void set_target( const char *target )
if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target ); if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
*p++ = 0; *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 )) if (!strcmp( cpu_names[i].name, spec ))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment