[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] typed_var: Make flags into an unsigned OR of bits.
commit 03e41830433268650bd9ba7184a5c2a0f80df8e9
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Sep 5 11:48:38 2019 -0400
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.)
---
src/lib/confmgt/type_defs.c | 11 ++++-------
src/lib/confmgt/typedvar.c | 6 +++---
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 f8b2681aa..e311319c0 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 43040e1e0..751d15827 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 4157cb8ff..5eb97cff1 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) */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits