]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow for structural types to have flags
authorAlan T. DeKok <aland@freeradius.org>
Wed, 18 Sep 2024 15:07:02 +0000 (11:07 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 19 Sep 2024 12:23:17 +0000 (08:23 -0400)
by doing some sneaky overlaps of data structures.

src/bin/unit_test_module.c
src/lib/unlang/xlat_builtin.c
src/lib/util/pair.h
src/lib/util/value.h

index df913cb7497107e8c57373332031c7b2b5f20cde..3e1675de81868991b5e0c882b412bc2b8538467b 100644 (file)
@@ -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;
        }
index 9c363668560987f70620eb8a8c62ef0ce819d76c..a192a5f3b9d004ff351ca3742470fa537c76c3b5 100644 (file)
@@ -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();
index 3a11d9d0cf2627fb5a7ebab2487d9d0150d5bd80..d8ef88666cfa55be3e0f0153d9aa5e20c994de4a 100644 (file)
@@ -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;
 }
 
 
index 26e9c64673d2098b3fcc47438e4dadc45c32e76c..91e3647f41a75a2776738d2a88d4b2c66cb90847 100644 (file)
@@ -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
  *
  * @{