From 5b252d31ede521bea53c690693a2ab3d74c8fef4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 20 Jun 2019 16:07:00 -0400 Subject: [PATCH] Add a "flags" member to config_var_t Additionally, adjust the macros so that we can add new members like this more easily. --- src/lib/conf/confmacros.h | 2 +- src/lib/conf/conftesting.h | 4 ++-- src/lib/conf/conftypes.h | 3 ++- src/test/test_confparse.c | 16 +++++++--------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lib/conf/confmacros.h b/src/lib/conf/confmacros.h index 29040e1f55..4242137c5a 100644 --- a/src/lib/conf/confmacros.h +++ b/src/lib/conf/confmacros.h @@ -19,7 +19,7 @@ * Used to indicate the end of an array of configuration variables. **/ #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 membername of the structure diff --git a/src/lib/conf/conftesting.h b/src/lib/conf/conftesting.h index f4aca442a2..a40c9bc97c 100644 --- a/src/lib/conf/conftesting.h +++ b/src/lib/conf/conftesting.h @@ -68,8 +68,8 @@ typedef union { #define CONF_CHECK_VAR_TYPE(tp, conftype, member) \ { . conftype = &tp ## _dummy . member } #define CONF_TEST_MEMBERS(tp, conftype, member) \ - , CONF_CHECK_VAR_TYPE(tp, conftype, member) -#define DUMMY_CONF_TEST_MEMBERS , { .INT=NULL } + , .var_ptr_dummy=CONF_CHECK_VAR_TYPE(tp, conftype, member) +#define DUMMY_CONF_TEST_MEMBERS , .var_ptr_dummy={ .INT=NULL } #define DUMMY_TYPECHECK_INSTANCE(tp) \ static tp tp ## _dummy diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h index 72697e8ee4..028a889917 100644 --- a/src/lib/conf/conftypes.h +++ b/src/lib/conf/conftypes.h @@ -110,7 +110,8 @@ typedef struct config_var_t { struct_member_t member; /** A struct member corresponding to this * variable. */ 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 /** Used for compiler-magic to typecheck the corresponding field in the * corresponding struct. Only used in unit test mode, at compile-time. */ diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c index 2f408b5b6e..4bf66f3230 100644 --- a/src/test/test_confparse.c +++ b/src/test/test_confparse.c @@ -52,9 +52,8 @@ static test_struct_t test_struct_t_dummy; CONFIG_VAR_ETYPE(test_struct_t, varname, conftype, member, initvalue) #define V(member,conftype,initvalue) \ VAR(#member, conftype, member, initvalue) - -#define OBSOLETE(varname) \ - { { .name=varname, .type=CONFIG_TYPE_OBSOLETE }, NULL, {.INT=NULL} } +#define OBSOLETE(varname) \ + CONFIG_VAR_OBSOLETE(varname) static config_var_t test_vars[] = { V(s, STRING, "hello"), @@ -78,12 +77,11 @@ static config_var_t test_vars[] = { VAR("LineTypeB", LINELIST_S, mixed_lines, NULL), OBSOLETE("obsolete"), { - { .name = "routerset", - .type = CONFIG_TYPE_EXTENDED, - .type_def = &ROUTERSET_type_defn, - .offset = offsetof(test_struct_t, routerset), - }, - NULL, {.INT=NULL} + .member = { .name = "routerset", + .type = CONFIG_TYPE_EXTENDED, + .type_def = &ROUTERSET_type_defn, + .offset = offsetof(test_struct_t, routerset), + }, }, VAR("__HiddenInt", POSINT, hidden_int, "0"), VAR("MixedHiddenLines", LINELIST_V, mixed_hidden_lines, NULL),