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

[tor-commits] [tor/master] Make config_var and config_fmt const.



commit f8b193a74a3967d23bf55c8dcfb5bb2a16692c97
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Jun 21 11:20:21 2019 -0400

    Make config_var and config_fmt const.
    
    Now that we have a reasonable implementation for overriding the
    default options for TestingTorNetwork, we don't need to modify
    config_var_t structs any more.  And therefore, we can have constant
    format options, like reasonable people.
---
 src/app/config/config.c                   |  6 +++---
 src/app/config/config.h                   |  2 +-
 src/app/config/confparse.c                | 21 +++++++--------------
 src/app/config/confparse.h                | 13 ++++++-------
 src/app/config/statefile.c                |  2 +-
 src/feature/dirauth/shared_random_state.c |  4 ++--
 src/test/test_confparse.c                 |  4 ++--
 7 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 5ea6c2d40..4bc807a6f 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -191,7 +191,7 @@ static const char unix_q_socket_prefix[] = "unix:\"";
 
 /** A list of abbreviations and aliases to map command-line options, obsolete
  * option names, or alternative option names, to their current values. */
-static config_abbrev_t option_abbrevs_[] = {
+static const config_abbrev_t option_abbrevs_[] = {
   PLURAL(AuthDirBadDirCC),
   PLURAL(AuthDirBadExitCC),
   PLURAL(AuthDirInvalidCC),
@@ -301,7 +301,7 @@ DUMMY_TYPECHECK_INSTANCE(or_options_t);
  * abbreviations, order is significant, since the first matching option will
  * be chosen first.
  */
-static config_var_t option_vars_[] = {
+static const config_var_t option_vars_[] = {
   V(AccountingMax,               MEMUNIT,  "0 bytes"),
   VAR("AccountingRule",          STRING,   AccountingRule_option,  "max"),
   V(AccountingStart,             STRING,   NULL),
@@ -851,7 +851,7 @@ static void set_protocol_warning_severity_level(int warning_severity);
 #define OR_OPTIONS_MAGIC 9090909
 
 /** Configuration format for or_options_t. */
-STATIC config_format_t options_format = {
+STATIC const config_format_t options_format = {
   sizeof(or_options_t),
   {
    "or_options_t",
diff --git a/src/app/config/config.h b/src/app/config/config.h
index 46db02f94..c6feb89fe 100644
--- a/src/app/config/config.h
+++ b/src/app/config/config.h
@@ -248,7 +248,7 @@ int options_any_client_port_set(const or_options_t *options);
 
 STATIC int options_act(const or_options_t *old_options);
 #ifdef TOR_UNIT_TESTS
-extern struct config_format_t options_format;
+extern const struct config_format_t options_format;
 #endif
 
 STATIC port_cfg_t *port_cfg_new(size_t namelen);
diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index 450ff5e08..9bc0b1dc7 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -100,9 +100,13 @@ config_find_deprecation(const config_format_t *fmt, const char *key)
   return NULL;
 }
 
-/** As config_find_option, but return a non-const pointer. */
-config_var_t *
-config_find_option_mutable(config_format_t *fmt, const char *key)
+/** If <b>key</b> is a configuration option, return the corresponding const
+ * config_var_t.  Otherwise, if <b>key</b> is a non-standard abbreviation,
+ * warn, and return the corresponding const config_var_t.  Otherwise return
+ * NULL.
+ */
+const config_var_t *
+config_find_option(const config_format_t *fmt, const char *key)
 {
   int i;
   size_t keylen = strlen(key);
@@ -127,17 +131,6 @@ config_find_option_mutable(config_format_t *fmt, const char *key)
   return NULL;
 }
 
-/** If <b>key</b> is a configuration option, return the corresponding const
- * config_var_t.  Otherwise, if <b>key</b> is a non-standard abbreviation,
- * warn, and return the corresponding const config_var_t.  Otherwise return
- * NULL.
- */
-const config_var_t *
-config_find_option(const config_format_t *fmt, const char *key)
-{
-  return config_find_option_mutable((config_format_t*)fmt, key);
-}
-
 /** Return the number of option entries in <b>fmt</b>. */
 static int
 config_count_options(const config_format_t *fmt)
diff --git a/src/app/config/confparse.h b/src/app/config/confparse.h
index c53e3224d..65972d6fc 100644
--- a/src/app/config/confparse.h
+++ b/src/app/config/confparse.h
@@ -47,16 +47,17 @@ typedef void (*free_cfg_fn_t)(void*);
 typedef struct config_format_t {
   size_t size; /**< Size of the struct that everything gets parsed into. */
   struct_magic_decl_t magic; /**< Magic number info for this struct. */
-  config_abbrev_t *abbrevs; /**< List of abbreviations that we expand when
-                             * parsing this format. */
+  const config_abbrev_t *abbrevs; /**< List of abbreviations that we expand
+                             * when parsing this format. */
   const config_deprecation_t *deprecations; /** List of deprecated options */
-  config_var_t *vars; /**< List of variables we recognize, their default
-                       * values, and where we stick them in the structure. */
+  const config_var_t *vars; /**< List of variables we recognize, their default
+                             * values, and where we stick them in the
+                             * structure. */
   validate_fn_t validate_fn; /**< Function to validate config. */
   free_cfg_fn_t free_fn; /**< Function to free the configuration. */
   /** If present, extra denotes a LINELIST variable for unrecognized
    * lines.  Otherwise, unrecognized lines are an error. */
-  struct_member_t *extra;
+  const struct_member_t *extra;
 } config_format_t;
 
 /** Macro: assert that <b>cfg</b> has the right magic field for format
@@ -93,8 +94,6 @@ bool config_check_ok(const config_format_t *fmt, const void *options,
 int config_assign(const config_format_t *fmt, void *options,
                   struct config_line_t *list,
                   unsigned flags, char **msg);
-config_var_t *config_find_option_mutable(config_format_t *fmt,
-                                         const char *key);
 const char *config_find_deprecation(const config_format_t *fmt,
                                      const char *key);
 const config_var_t *config_find_option(const config_format_t *fmt,
diff --git a/src/app/config/statefile.c b/src/app/config/statefile.c
index 4fe415b8c..d997d3932 100644
--- a/src/app/config/statefile.c
+++ b/src/app/config/statefile.c
@@ -76,7 +76,7 @@ DUMMY_TYPECHECK_INSTANCE(or_state_t);
   VAR(#member, conftype, member, initvalue)
 
 /** Array of "state" variables saved to the ~/.tor/state file. */
-static config_var_t state_vars_[] = {
+static const config_var_t state_vars_[] = {
   /* Remember to document these in state-contents.txt ! */
 
   V(AccountingBytesReadInInterval,    MEMUNIT,  NULL),
diff --git a/src/feature/dirauth/shared_random_state.c b/src/feature/dirauth/shared_random_state.c
index d89f249a7..c2ad3e7cc 100644
--- a/src/feature/dirauth/shared_random_state.c
+++ b/src/feature/dirauth/shared_random_state.c
@@ -65,7 +65,7 @@ disk_state_validate_cb(void *old_state, void *state, void *default_state,
 static void disk_state_free_cb(void *);
 
 /* Array of variables that are saved to disk as a persistent state. */
-static config_var_t state_vars[] = {
+static const config_var_t state_vars[] = {
   V(Version,                    POSINT, "0"),
   V(TorVersion,                 STRING, NULL),
   V(ValidAfter,                 ISOTIME, NULL),
@@ -81,7 +81,7 @@ static config_var_t state_vars[] = {
 
 /* "Extra" variable in the state that receives lines we can't parse. This
  * lets us preserve options from versions of Tor newer than us. */
-static struct_member_t state_extra_var = {
+static const struct_member_t state_extra_var = {
   .name = "__extra",
   .type = CONFIG_TYPE_LINELIST,
   .offset = offsetof(sr_disk_state_t, ExtraLines),
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c
index 4612419df..ec018f0c5 100644
--- a/src/test/test_confparse.c
+++ b/src/test/test_confparse.c
@@ -55,7 +55,7 @@ static test_struct_t test_struct_t_dummy;
 #define OBSOLETE(varname)                       \
   CONFIG_VAR_OBSOLETE(varname)
 
-static config_var_t test_vars[] = {
+static const config_var_t test_vars[] = {
   V(s, STRING, "hello"),
   V(fn, FILENAME, NULL),
   V(pos, POSINT, NULL),
@@ -123,7 +123,7 @@ static void test_free_cb(void *options);
 
 #define TEST_MAGIC 0x1337
 
-static config_format_t test_fmt = {
+static const config_format_t test_fmt = {
   sizeof(test_struct_t),
   {
    "test_struct_t",



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