Stop using "config_suite_offset=-1" to indicate "no config suite."

Instead, create a separate "has_config_suite" boolean, so that only
top-level formats with config_suites need to declare an offset at
all.
This commit is contained in:
Nick Mathewson
2019-11-05 10:18:47 -05:00
parent 0d8504e70b
commit 0f0a9bdf33
8 changed files with 18 additions and 10 deletions
+1
View File
@@ -880,6 +880,7 @@ static const config_format_t options_format = {
.legacy_validate_fn = options_validate_cb,
.check_transition_fn = options_check_transition_cb,
.clear_fn = options_clear_cb,
.has_config_suite = true,
.config_suite_offset = offsetof(or_options_t, subconfigs_),
};
+1
View File
@@ -169,6 +169,7 @@ static const config_format_t state_format = {
.vars = state_vars_,
.legacy_validate_fn = or_state_validate_cb,
.extra = &state_extra_var,
.has_config_suite = true,
.config_suite_offset = offsetof(or_state_t, substates_),
};
@@ -92,7 +92,6 @@ static const config_format_t state_format = {
},
.vars = state_vars,
.extra = &state_extra_var,
.config_suite_offset = -1,
};
/** Global configuration manager for the shared-random state file */
+8 -2
View File
@@ -335,8 +335,14 @@ typedef struct config_format_t {
/** If present, extra denotes a LINELIST variable for unrecognized
* lines. Otherwise, unrecognized lines are an error. */
const struct_member_t *extra;
/** The position of a config_suite_t pointer within the toplevel object,
* or -1 if there is no such pointer. */
/**
* If true, this format describes a top-level configuration, with
* a suite containing multiple sub-configuration objects.
*/
bool has_config_suite;
/** The position of a config_suite_t pointer within the toplevel object.
* Ignored unless have_config_suite is true.
*/
ptrdiff_t config_suite_offset;
} config_format_t;
+7 -2
View File
@@ -169,9 +169,14 @@ config_mgr_register_fmt(config_mgr_t *mgr,
"it had been frozen.");
if (object_idx != IDX_TOPLEVEL) {
tor_assertf(fmt->config_suite_offset < 0,
tor_assertf(! fmt->has_config_suite,
"Tried to register a toplevel format in a non-toplevel position");
}
if (fmt->config_suite_offset) {
tor_assertf(fmt->has_config_suite,
"config_suite_offset was set, but has_config_suite was not.");
}
tor_assertf(fmt != mgr->toplevel &&
! smartlist_contains(mgr->subconfigs, fmt),
"Tried to register an already-registered format.");
@@ -223,7 +228,7 @@ config_mgr_add_format(config_mgr_t *mgr,
static inline config_suite_t **
config_mgr_get_suite_ptr(const config_mgr_t *mgr, void *toplevel)
{
if (mgr->toplevel->config_suite_offset < 0)
if (! mgr->toplevel->has_config_suite)
return NULL;
return STRUCT_VAR_P(toplevel, mgr->toplevel->config_suite_offset);
}
-1
View File
@@ -293,7 +293,6 @@ static const config_format_t crypto_options_fmt = {
offsetof(crypto_options_t, magic) },
.vars = crypto_options_t_vars,
.validate_fn = crypto_options_validate,
.config_suite_offset = -1,
};
/**
+1 -2
View File
@@ -193,6 +193,7 @@ static const config_format_t pasture_fmt = {
offsetof(pasture_cfg_t, magic)
},
.vars = pasture_vars,
.has_config_suite = true,
.config_suite_offset = offsetof(pasture_cfg_t, subobjs),
.legacy_validate_fn = legacy_validate_pasture,
};
@@ -205,7 +206,6 @@ static const config_format_t llama_fmt = {
offsetof(llama_cfg_t, magic)
},
.vars = llama_vars,
.config_suite_offset = -1,
.deprecations = llama_deprecations,
.abbrevs = llama_abbrevs,
.clear_fn = clear_llama_cfg,
@@ -221,7 +221,6 @@ static const config_format_t alpaca_fmt = {
offsetof(alpaca_cfg_t, magic)
},
.vars = alpaca_vars,
.config_suite_offset = -1,
.deprecations = alpaca_deprecations,
.pre_normalize_fn = pre_normalize_alpaca,
.check_transition_fn = check_transition_alpaca,
-2
View File
@@ -129,7 +129,6 @@ static const config_format_t test_fmt = {
.deprecations = test_deprecation_notes,
.vars = test_vars,
.legacy_validate_fn = test_validate_cb,
.config_suite_offset = -1,
};
/* Make sure that config_init sets everything to the right defaults. */
@@ -824,7 +823,6 @@ static config_format_t etest_fmt = {
.vars = test_vars,
.legacy_validate_fn = test_validate_cb,
.extra = &extra,
.config_suite_offset = -1,
};
/* Try out the feature where we can store unrecognized lines and dump them