widl: Add the ARRAY_SIZE() macro.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
stable
Michael Stefaniuc 2019-09-26 17:50:59 +02:00 committed by Alexandre Julliard
parent fe91ae51f1
commit bbcf44eb97
4 changed files with 6 additions and 5 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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));

View File

@ -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 ))
{