Переглянути джерело

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.)
Nick Mathewson 4 роки тому
батько
коміт
03e4183043

+ 4 - 7
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 }
 };
 
 /**

+ 3 - 3
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;
 }

+ 24 - 11
src/lib/confmgt/var_type_def_st.h

@@ -133,6 +133,25 @@ struct var_type_fns_t {
   void (*mark_fragile)(void *value, const void *params);
 };
 
+/**
+ * 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) */