From: Alan T. DeKok Date: Wed, 18 Sep 2024 15:07:02 +0000 (-0400) Subject: allow for structural types to have flags X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17499ac9c7bec0b74a37ba57dd204ef83b1141be;p=thirdparty%2Ffreeradius-server.git allow for structural types to have flags by doing some sneaky overlaps of data structures. --- diff --git a/src/bin/unit_test_module.c b/src/bin/unit_test_module.c index df913cb7497..3e1675de818 100644 --- a/src/bin/unit_test_module.c +++ b/src/bin/unit_test_module.c @@ -117,7 +117,7 @@ static fr_client_t *client_alloc(TALLOC_CTX *ctx, char const *ip, char const *na static void pair_mutable(fr_pair_t *vp) { if (fr_type_is_leaf(vp->vp_type)) { - vp->data.immutable = false; + vp->vp_immutable = false; return; } diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 9c363668560..a192a5f3b9d 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -899,7 +899,7 @@ static xlat_action_t xlat_func_immutable_attr(UNUSED TALLOC_CTX *ctx, UNUSED fr_ for (vp = tmpl_dcursor_init(NULL, NULL, &cc, &cursor, request, vpt); vp; vp = fr_dcursor_next(&cursor)) { - if (fr_type_is_leaf(vp->vp_type)) fr_value_box_set_immutable(&vp->data); + fr_pair_set_immutable(vp); } tmpl_dcursor_clear(&cc); REXDENT(); diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index 3a11d9d0cf2..d8ef88666cf 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -92,7 +92,7 @@ struct value_pair_s { * This hack allows the majority of the fr_pair_list_t to overlap with the * fr_value_box_t which gives us much greater packing efficiency. */ - uint8_t pad[offsetof(fr_value_box_t, type) + sizeof(fr_type_t)]; + uint8_t pad[offsetof(fr_value_box_t, safe_for)]; fr_pair_list_t children; //!< Nested attributes of this pair. }; @@ -686,17 +686,13 @@ bool fr_pair_immutable(fr_pair_t const *vp) CC_HINT(nonnull); static inline CC_HINT(nonnull, always_inline) void fr_pair_set_immutable(fr_pair_t *vp) { - fr_assert(fr_type_is_leaf(vp->vp_type)); - - fr_value_box_set_immutable(&vp->data); + vp->vp_immutable = true; } static inline CC_HINT(nonnull, always_inline) void fr_pair_clear_immutable(fr_pair_t *vp) { - fr_assert(fr_type_is_leaf(vp->vp_type)); - - fr_value_box_clear_immutable(&vp->data); + vp->vp_immutable = false; } diff --git a/src/lib/util/value.h b/src/lib/util/value.h index 26e9c64673d..91e3647f41a 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -162,6 +162,10 @@ typedef uintptr_t fr_value_box_safe_for_t; * fr_type_t should be an enumeration of the values in this union. * * Don't change the order of the fields below without checking that the output of radsize doesn't change. + * + * The first few fields (before safe_for) are reused in the #fr_pair_t. This allows structural + * data types to have vp->vp_type, and to also use / set the various flags defined below. Do NOT + * change the order of the fields! */ struct value_box_s { /** Type and flags should appear together for packing efficiency @@ -1069,19 +1073,6 @@ void fr_value_box_set_secret(fr_value_box_t *box, bool secret) box->secret = secret; } -static inline CC_HINT(nonnull, always_inline) -void fr_value_box_set_immutable(fr_value_box_t *box) -{ - box->immutable = true; -} - -static inline CC_HINT(nonnull, always_inline) -void fr_value_box_clear_immutable(fr_value_box_t *box) -{ - box->immutable = false; -} - - /** @name Assign and manipulate binary-unsafe C strings * * @{