[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Use named-member syntax for initializing config_format_t objects



commit 27dbf20bf477d3793d295b376713f71bccc7acaf
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Jul 25 09:43:50 2019 -0400

    Use named-member syntax for initializing config_format_t objects
    
    I'm about to mess with their lists of callbacks, and I don't want to
    proliferate lists where we say "NULL, NULL, NULL, ..."
---
 src/app/config/config.c                   | 17 ++++++++--------
 src/app/config/statefile.c                | 16 +++++++--------
 src/feature/dirauth/shared_random_state.c | 15 ++++++--------
 src/test/test_confparse.c                 | 33 ++++++++++++++-----------------
 4 files changed, 36 insertions(+), 45 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 187c27559..aafc8c5a7 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -864,19 +864,18 @@ static void options_clear_cb(const config_mgr_t *mgr, void *opts);
 
 /** Configuration format for or_options_t. */
 static const config_format_t options_format = {
-  sizeof(or_options_t),
-  {
+  .size = sizeof(or_options_t),
+  .magic = {
    "or_options_t",
    OR_OPTIONS_MAGIC,
    offsetof(or_options_t, magic_),
   },
-  option_abbrevs_,
-  option_deprecation_notes_,
-  option_vars_,
-  options_validate_cb,
-  options_clear_cb,
-  NULL,
-  offsetof(or_options_t, subconfigs_),
+  .abbrevs = option_abbrevs_,
+  .deprecations = option_deprecation_notes_,
+  .vars = option_vars_,
+  .validate_fn = options_validate_cb,
+  .clear_fn = options_clear_cb,
+  .config_suite_offset = offsetof(or_options_t, subconfigs_),
 };
 
 /*
diff --git a/src/app/config/statefile.c b/src/app/config/statefile.c
index 5c2e37490..2e5edc41c 100644
--- a/src/app/config/statefile.c
+++ b/src/app/config/statefile.c
@@ -157,19 +157,17 @@ static struct_member_t state_extra_var = {
 
 /** Configuration format for or_state_t. */
 static const config_format_t state_format = {
-  sizeof(or_state_t),
-  {
+  .size = sizeof(or_state_t),
+  .magic = {
    "or_state_t",
    OR_STATE_MAGIC,
    offsetof(or_state_t, magic_),
   },
-  state_abbrevs_,
-  NULL,
-  state_vars_,
-  or_state_validate_cb,
-  NULL,
-  &state_extra_var,
-  offsetof(or_state_t, substates_),
+  .abbrevs = state_abbrevs_,
+  .vars = state_vars_,
+  .validate_fn = or_state_validate_cb,
+  .extra = &state_extra_var,
+  .config_suite_offset = offsetof(or_state_t, substates_),
 };
 
 /* A global configuration manager for state-file objects */
diff --git a/src/feature/dirauth/shared_random_state.c b/src/feature/dirauth/shared_random_state.c
index 94743fdb7..2070e03aa 100644
--- a/src/feature/dirauth/shared_random_state.c
+++ b/src/feature/dirauth/shared_random_state.c
@@ -87,19 +87,16 @@ static const struct_member_t state_extra_var = {
 
 /** Configuration format of sr_disk_state_t. */
 static const config_format_t state_format = {
-  sizeof(sr_disk_state_t),
-  {
+  .size = sizeof(sr_disk_state_t),
+  .magic = {
    "sr_disk_state_t",
    SR_DISK_STATE_MAGIC,
    offsetof(sr_disk_state_t, magic_),
   },
-  NULL,
-  NULL,
-  state_vars,
-  disk_state_validate_cb,
-  NULL,
-  &state_extra_var,
-  -1,
+  .vars = state_vars,
+  .validate_fn = disk_state_validate_cb,
+  .extra = &state_extra_var,
+  .config_suite_offset = -1,
 };
 
 /** Global configuration manager for the shared-random state file */
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c
index 6702f3439..8cda96ba5 100644
--- a/src/test/test_confparse.c
+++ b/src/test/test_confparse.c
@@ -119,19 +119,17 @@ test_validate_cb(const void *old_options, void *options, char **msg)
 #define TEST_MAGIC 0x1337
 
 static const config_format_t test_fmt = {
-  sizeof(test_struct_t),
-  {
+  .size = sizeof(test_struct_t),
+  .magic = {
    "test_struct_t",
    TEST_MAGIC,
    offsetof(test_struct_t, magic),
   },
-  test_abbrevs,
-  test_deprecation_notes,
-  test_vars,
-  test_validate_cb,
-  NULL,
-  NULL,
-  -1,
+  .abbrevs = test_abbrevs,
+  .deprecations = test_deprecation_notes,
+  .vars = test_vars,
+  .validate_fn = test_validate_cb,
+  .config_suite_offset = -1,
 };
 
 /* Make sure that config_init sets everything to the right defaults. */
@@ -815,19 +813,18 @@ static struct_member_t extra = {
 };
 
 static config_format_t etest_fmt = {
-  sizeof(test_struct_t),
-  {
+  .size = sizeof(test_struct_t),
+  .magic = {
    "test_struct_t (with extra lines)",
    ETEST_MAGIC,
    offsetof(test_struct_t, magic),
   },
-  test_abbrevs,
-  test_deprecation_notes,
-  test_vars,
-  test_validate_cb,
-  NULL,
-  &extra,
-  -1,
+  .abbrevs = test_abbrevs,
+  .deprecations = test_deprecation_notes,
+  .vars = test_vars,
+  .validate_fn = test_validate_cb,
+  .extra = &extra,
+  .config_suite_offset = -1,
 };
 
 /* Try out the feature where we can store unrecognized lines and dump them



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits