diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-09-05 11:48:38 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2019-09-11 09:42:19 -0400 |
commit | 03e41830433268650bd9ba7184a5c2a0f80df8e9 (patch) | |
tree | 3555e2341d67b843d92a4d921a77dd515e5103d1 /src/lib/confmgt | |
parent | 4f6b592691b0057dca55ce92beefc6b7e671a4ae (diff) | |
download | tor-03e41830433268650bd9ba7184a5c2a0f80df8e9.tar.gz tor-03e41830433268650bd9ba7184a5c2a0f80df8e9.zip |
typed_var: Make flags into an unsigned OR of bits.
Using a bitfield here will enable us to unify the var_type_def_t flags
with the config_var_t flags.
(This commit does not yet do that unification, and does not yet
rename or refactor any flags. It only changes booleans into bits.)
Diffstat (limited to 'src/lib/confmgt')
-rw-r--r-- | src/lib/confmgt/type_defs.c | 11 | ||||
-rw-r--r-- | src/lib/confmgt/typedvar.c | 6 | ||||
-rw-r--r-- | src/lib/confmgt/var_type_def_st.h | 35 |
3 files changed, 31 insertions, 21 deletions
diff --git a/src/lib/confmgt/type_defs.c b/src/lib/confmgt/type_defs.c index f8b2681aa0..e311319c09 100644 --- a/src/lib/confmgt/type_defs.c +++ b/src/lib/confmgt/type_defs.c @@ -725,16 +725,13 @@ static const var_type_def_t type_definitions_table[] = { [CONFIG_TYPE_CSV_INTERVAL] = { .name="TimeInterval", .fns=&legacy_csv_interval_fns, }, [CONFIG_TYPE_LINELIST] = { .name="LineList", .fns=&linelist_fns, - .is_cumulative=true}, + .flags=VTFLAG_CUMULATIVE }, [CONFIG_TYPE_LINELIST_S] = { .name="Dependent", .fns=&linelist_s_fns, - .is_cumulative=true, - .is_contained=true, }, + .flags=VTFLAG_CUMULATIVE|VTFLAG_CONTAINED }, [CONFIG_TYPE_LINELIST_V] = { .name="Virtual", .fns=&linelist_v_fns, - .is_cumulative=true, - .is_unsettable=true }, + .flags=VTFLAG_CUMULATIVE|VTFLAG_UNSETTABLE }, [CONFIG_TYPE_OBSOLETE] = { .name="Obsolete", .fns=&ignore_fns, - .is_unsettable=true, - .is_contained=true, } + .flags=VTFLAG_CONTAINED|VTFLAG_UNSETTABLE } }; /** diff --git a/src/lib/confmgt/typedvar.c b/src/lib/confmgt/typedvar.c index 43040e1e05..751d15827f 100644 --- a/src/lib/confmgt/typedvar.c +++ b/src/lib/confmgt/typedvar.c @@ -233,7 +233,7 @@ typed_var_mark_fragile(void *value, const var_type_def_t *def) bool var_type_is_cumulative(const var_type_def_t *def) { - return def->is_cumulative; + return (def->flags & VTFLAG_CUMULATIVE) != 0; } /** @@ -243,7 +243,7 @@ var_type_is_cumulative(const var_type_def_t *def) bool var_type_is_contained(const var_type_def_t *def) { - return def->is_contained; + return (def->flags & VTFLAG_CONTAINED) != 0; } /** @@ -252,5 +252,5 @@ var_type_is_contained(const var_type_def_t *def) bool var_type_is_settable(const var_type_def_t *def) { - return ! def->is_unsettable; + return (def->flags & VTFLAG_UNSETTABLE) == 0; } diff --git a/src/lib/confmgt/var_type_def_st.h b/src/lib/confmgt/var_type_def_st.h index 4157cb8ff6..5eb97cff12 100644 --- a/src/lib/confmgt/var_type_def_st.h +++ b/src/lib/confmgt/var_type_def_st.h @@ -134,6 +134,25 @@ struct var_type_fns_t { }; /** + * Flag for var_type_def_t. + * Set iff a variable of this type can never be set directly by name. + **/ +#define VTFLAG_UNSETTABLE (1u<<0) +/** + * Flag for var_type_def_t. + * Set iff a variable of this type is always contained in another + * variable, and as such doesn't need to be dumped or copied + * independently. + **/ +#define VTFLAG_CONTAINED (1u<<1) +/** + * Flag for var_type_def_t. + * Set iff a variable of this type can be set more than once without + * destroying older values. Such variables should implement "mark_fragile". + */ +#define VTFLAG_CUMULATIVE (1u<<2) + +/** * A structure describing a type that can be manipulated with the typedvar_* * functions. **/ @@ -151,17 +170,11 @@ struct var_type_def_t { * calling the functions in this type's function table. */ const void *params; - - /** True iff a variable of this type can never be set directly by name. */ - bool is_unsettable; - /** True iff a variable of this type is always contained in another - * variable, and as such doesn't need to be dumped or copied - * independently. */ - bool is_contained; - /** True iff a variable of this type can be set more than once without - * destroying older values. Such variables should implement "mark_fragile". - */ - bool is_cumulative; + /** + * A bitwise OR of one or more VTFLAG_* values, describing properties + * for all values of this type. + **/ + uint32_t flags; }; #endif /* !defined(TOR_LIB_CONFMGT_VAR_TYPE_DEF_ST_H) */ |