Skip to content

Commit

Permalink
Avoid static declarations of arrays with unknown size.
Browse files Browse the repository at this point in the history
Visual studio does not like it.

This commit is similar to commit 3815d6c
(Avoid designated initializers and static decls of arrays
of unknown size.) but touches more files.

Signed-off-by: Gurucharan Shetty <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
shettyg committed Apr 4, 2014
1 parent 79bda82 commit d2586fc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
11 changes: 8 additions & 3 deletions tests/test-jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@
#include "vlog.h"
#include "ovstest.h"

static struct command all_commands[];

static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
static struct command *get_all_commands(void);

static void
test_jsonrpc_main(int argc, char *argv[])
{
proctitle_init(argc, argv);
set_program_name(argv[0]);
parse_options(argc, argv);
run_command(argc - optind, argv + optind, all_commands);
run_command(argc - optind, argv + optind, get_all_commands());
}

static void
Expand Down Expand Up @@ -337,4 +336,10 @@ static struct command all_commands[] = {
{ NULL, 0, 0, NULL },
};

static struct command *
get_all_commands(void)
{
return all_commands;
}

OVSTEST_REGISTER("test-jsonrpc", test_jsonrpc_main);
28 changes: 14 additions & 14 deletions tests/test-lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct test {
void (*function)(void);
};

static const struct test tests[];
static void run_help(void);

#define CHECK(A, B) check(A, B, #A, #B, __FILE__, __LINE__)
static void
Expand Down Expand Up @@ -237,19 +237,6 @@ run_lock_symlink_to_dir(void)
lockfile_unlock(a);
}

static void
run_help(void)
{
size_t i;

printf("usage: %s TESTNAME\n"
"where TESTNAME is one of the following:\n",
program_name);
for (i = 0; tests[i].name; i++) {
fprintf(stderr, "\t%s\n", tests[i].name);
}
}

static const struct test tests[] = {
#define TEST(NAME) { #NAME, run_##NAME }
TEST(lock_and_unlock),
Expand All @@ -267,6 +254,19 @@ static const struct test tests[] = {
#undef TEST
};

static void
run_help(void)
{
size_t i;

printf("usage: %s TESTNAME\n"
"where TESTNAME is one of the following:\n",
program_name);
for (i = 0; tests[i].name; i++) {
fprintf(stderr, "\t%s\n", tests[i].name);
}
}

static void
test_lockfile_main(int argc, char *argv[])
{
Expand Down
11 changes: 8 additions & 3 deletions tests/test-ovsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@
#include "util.h"
#include "vlog.h"

static struct command all_commands[];

static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
static struct command *get_all_commands(void);

int
main(int argc, char *argv[])
{
set_program_name(argv[0]);
parse_options(argc, argv);
run_command(argc - optind, argv + optind, all_commands);
run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}

Expand Down Expand Up @@ -1993,3 +1992,9 @@ static struct command all_commands[] = {
{ "help", 0, INT_MAX, do_help },
{ NULL, 0, 0, NULL },
};

static struct command *
get_all_commands(void)
{
return all_commands;
}
13 changes: 9 additions & 4 deletions tests/test-reconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
static struct reconnect *reconnect;
static int now;

static const struct command commands[];

static void diff_stats(const struct reconnect_stats *old,
const struct reconnect_stats *new,
int delta);
static struct command *get_all_commands(void);

static void
test_reconnect_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
Expand Down Expand Up @@ -70,7 +69,7 @@ test_reconnect_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
svec_parse_words(&args, line);
svec_terminate(&args);
if (!svec_is_empty(&args)) {
run_command(args.n, args.names, commands);
run_command(args.n, args.names, get_all_commands());
}
svec_destroy(&args);

Expand Down Expand Up @@ -271,7 +270,7 @@ do_listen_error(int argc OVS_UNUSED, char *argv[])
reconnect_listen_error(reconnect, now, atoi(argv[1]));
}

static const struct command commands[] = {
static const struct command all_commands[] = {
{ "enable", 0, 0, do_enable },
{ "disable", 0, 0, do_disable },
{ "force-reconnect", 0, 0, do_force_reconnect },
Expand All @@ -290,4 +289,10 @@ static const struct command commands[] = {
{ NULL, 0, 0, NULL },
};

static struct command *
get_all_commands(void)
{
return all_commands;
}

OVSTEST_REGISTER("test-reconnect", test_reconnect_main);
13 changes: 8 additions & 5 deletions vtep/vtep-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ static int timeout;
/* Format for table output. */
static struct table_style table_style = TABLE_STYLE_DEFAULT;

/* All supported commands. */
static const struct vtep_ctl_command_syntax all_commands[];

/* The IDL we're using and the current transaction, if any.
* This is for use by vtep_ctl_exit() only, to allow it to clean up.
* Other code should use its context arguments. */
Expand Down Expand Up @@ -155,6 +152,7 @@ static bool is_condition_satisfied(const struct vtep_ctl_table_class *,
static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
const char *name,
bool must_exist);
static const struct vtep_ctl_command_syntax *get_all_commands(void);

int
main(int argc, char *argv[])
Expand Down Expand Up @@ -285,7 +283,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
options = xmemdup(global_long_options, sizeof global_long_options);
allocated_options = ARRAY_SIZE(global_long_options);
n_options = n_global_long_options;
for (p = all_commands; p->name; p++) {
for (p = get_all_commands(); p->name; p++) {
if (p->options[0]) {
char *save_ptr = NULL;
char *name;
Expand Down Expand Up @@ -544,7 +542,7 @@ find_command(const char *name)
if (shash_is_empty(&commands)) {
const struct vtep_ctl_command_syntax *p;

for (p = all_commands; p->name; p++) {
for (p = get_all_commands(); p->name; p++) {
shash_add_assert(&commands, p->name, p);
}
}
Expand Down Expand Up @@ -3890,3 +3888,8 @@ static const struct vtep_ctl_command_syntax all_commands[] = {
{NULL, 0, 0, NULL, NULL, NULL, NULL, RO},
};

static const struct vtep_ctl_command_syntax *
get_all_commands(void)
{
return all_commands;
}

0 comments on commit d2586fc

Please sign in to comment.