Add a "flags" member to config_var_t

Additionally, adjust the macros so that we can add new members like
this more easily.
This commit is contained in:
Nick Mathewson 2019-06-20 16:07:00 -04:00
parent c553750e32
commit 5b252d31ed
4 changed files with 12 additions and 13 deletions

View File

@ -19,7 +19,7 @@
* Used to indicate the end of an array of configuration variables. * Used to indicate the end of an array of configuration variables.
**/ **/
#define END_OF_CONFIG_VARS \ #define END_OF_CONFIG_VARS \
{ { .name = NULL }, NULL DUMMY_CONF_TEST_MEMBERS } { .member = { .name = NULL } DUMMY_CONF_TEST_MEMBERS }
/** /**
* Declare a config_var_t as a member named <b>membername</b> of the structure * Declare a config_var_t as a member named <b>membername</b> of the structure

View File

@ -68,8 +68,8 @@ typedef union {
#define CONF_CHECK_VAR_TYPE(tp, conftype, member) \ #define CONF_CHECK_VAR_TYPE(tp, conftype, member) \
{ . conftype = &tp ## _dummy . member } { . conftype = &tp ## _dummy . member }
#define CONF_TEST_MEMBERS(tp, conftype, member) \ #define CONF_TEST_MEMBERS(tp, conftype, member) \
, CONF_CHECK_VAR_TYPE(tp, conftype, member) , .var_ptr_dummy=CONF_CHECK_VAR_TYPE(tp, conftype, member)
#define DUMMY_CONF_TEST_MEMBERS , { .INT=NULL } #define DUMMY_CONF_TEST_MEMBERS , .var_ptr_dummy={ .INT=NULL }
#define DUMMY_TYPECHECK_INSTANCE(tp) \ #define DUMMY_TYPECHECK_INSTANCE(tp) \
static tp tp ## _dummy static tp tp ## _dummy

View File

@ -110,7 +110,8 @@ typedef struct config_var_t {
struct_member_t member; /** A struct member corresponding to this struct_member_t member; /** A struct member corresponding to this
* variable. */ * variable. */
const char *initvalue; /**< String (or null) describing initial value. */ const char *initvalue; /**< String (or null) describing initial value. */
uint32_t flags; /**< One or more flags describing special handling for this
* variable */
#ifdef TOR_UNIT_TESTS #ifdef TOR_UNIT_TESTS
/** Used for compiler-magic to typecheck the corresponding field in the /** Used for compiler-magic to typecheck the corresponding field in the
* corresponding struct. Only used in unit test mode, at compile-time. */ * corresponding struct. Only used in unit test mode, at compile-time. */

View File

@ -52,9 +52,8 @@ static test_struct_t test_struct_t_dummy;
CONFIG_VAR_ETYPE(test_struct_t, varname, conftype, member, initvalue) CONFIG_VAR_ETYPE(test_struct_t, varname, conftype, member, initvalue)
#define V(member,conftype,initvalue) \ #define V(member,conftype,initvalue) \
VAR(#member, conftype, member, initvalue) VAR(#member, conftype, member, initvalue)
#define OBSOLETE(varname) \ #define OBSOLETE(varname) \
{ { .name=varname, .type=CONFIG_TYPE_OBSOLETE }, NULL, {.INT=NULL} } CONFIG_VAR_OBSOLETE(varname)
static config_var_t test_vars[] = { static config_var_t test_vars[] = {
V(s, STRING, "hello"), V(s, STRING, "hello"),
@ -78,12 +77,11 @@ static config_var_t test_vars[] = {
VAR("LineTypeB", LINELIST_S, mixed_lines, NULL), VAR("LineTypeB", LINELIST_S, mixed_lines, NULL),
OBSOLETE("obsolete"), OBSOLETE("obsolete"),
{ {
{ .name = "routerset", .member = { .name = "routerset",
.type = CONFIG_TYPE_EXTENDED, .type = CONFIG_TYPE_EXTENDED,
.type_def = &ROUTERSET_type_defn, .type_def = &ROUTERSET_type_defn,
.offset = offsetof(test_struct_t, routerset), .offset = offsetof(test_struct_t, routerset),
}, },
NULL, {.INT=NULL}
}, },
VAR("__HiddenInt", POSINT, hidden_int, "0"), VAR("__HiddenInt", POSINT, hidden_int, "0"),
VAR("MixedHiddenLines", LINELIST_V, mixed_hidden_lines, NULL), VAR("MixedHiddenLines", LINELIST_V, mixed_hidden_lines, NULL),