From: Gurucharan Shetty Date: Thu, 3 Apr 2014 23:07:43 +0000 (-0700) Subject: Avoid static declarations of arrays with unknown size. X-Git-Tag: v2.3~373 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;ds=sidebyside;h=d2586fce485240801bdfdd73ad4679b9c88bc659;p=cascardo%2Fovs.git Avoid static declarations of arrays with unknown size. Visual studio does not like it. This commit is similar to commit 3815d6c2c (Avoid designated initializers and static decls of arrays of unknown size.) but touches more files. Signed-off-by: Gurucharan Shetty Acked-by: Ben Pfaff --- diff --git a/tests/test-jsonrpc.c b/tests/test-jsonrpc.c index 4ace6dc63..7251265fe 100644 --- a/tests/test-jsonrpc.c +++ b/tests/test-jsonrpc.c @@ -35,10 +35,9 @@ #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[]) @@ -46,7 +45,7 @@ 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 @@ -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); diff --git a/tests/test-lockfile.c b/tests/test-lockfile.c index 80cc5a84a..0bf3fe6dd 100644 --- a/tests/test-lockfile.c +++ b/tests/test-lockfile.c @@ -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 @@ -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), @@ -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[]) { diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index aeb7a5e7f..29d75420f 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -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; } @@ -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; +} diff --git a/tests/test-reconnect.c b/tests/test-reconnect.c index d3ff6e82c..286405187 100644 --- a/tests/test-reconnect.c +++ b/tests/test-reconnect.c @@ -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) @@ -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); @@ -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 }, @@ -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); diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c index 25470ff1c..0b9463a90 100644 --- a/vtep/vtep-ctl.c +++ b/vtep/vtep-ctl.c @@ -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. */ @@ -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[]) @@ -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; @@ -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); } } @@ -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; +}