]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: completely get rid of the MTYPE alias hack
authorDavid Lamparter <equinox@diac24.net>
Wed, 13 Nov 2019 23:21:10 +0000 (00:21 +0100)
committerDavid Lamparter <equinox@diac24.net>
Fri, 13 Dec 2019 05:22:34 +0000 (06:22 +0100)
Sometimes the easiest solution is hardest to find... the whole point of
all this "static const", aliasing, & co. was to make "MTYPE_FOO" usable
without adding the extra & as in "&MTYPE_FOO".  Making it a size-1 array
does that perfectly through the magic of ISO C array decay...

Signed-off-by: David Lamparter <equinox@diac24.net>
lib/frrcu.c
lib/memory.h

index d65a4a98bf631e4c5e3449aeeb748e8a5fde9ecc..7e6475b6487e5992a74b8cba5c83632ee5c2d480 100644 (file)
@@ -206,7 +206,7 @@ void rcu_thread_unprepare(struct rcu_thread *rt)
        rcu_bump();
        if (rt != &rcu_thread_main)
                /* this free() happens after seqlock_release() below */
-               rcu_free_internal(&_mt_RCU_THREAD, rt, rcu_head);
+               rcu_free_internal(MTYPE_RCU_THREAD, rt, rcu_head);
 
        rcu_threads_del(&rcu_threads, rt);
        seqlock_release(&rt->rcu);
@@ -269,7 +269,7 @@ static void rcu_bump(void)
         * "last item is being deleted - start over" case, and then we may end
         * up accessing old RCU queue items that are already free'd.
         */
-       rcu_free_internal(&_mt_RCU_NEXT, rn, head_free);
+       rcu_free_internal(MTYPE_RCU_NEXT, rn, head_free);
 
        /* Only allow the RCU sweeper to run after these 2 items are queued.
         *
index 8de5c4c2bf0b5627d36d55230c766b613c187271..44ea19b5579b17abedcc061f52ff269ed7eaa83a 100644 (file)
@@ -102,45 +102,42 @@ struct memgroup {
        }
 
 #define DECLARE_MTYPE(name)                                                    \
-       extern struct memtype _mt_##name;                                      \
-       extern struct memtype *const MTYPE_##name;                             \
+       extern struct memtype MTYPE_##name[1];                                 \
        /* end */
 
 #define DEFINE_MTYPE_ATTR(group, mname, attr, desc)                            \
-       attr struct memtype _mt_##mname                                        \
-               __attribute__((section(".data.mtypes"))) = {                   \
+       attr struct memtype MTYPE_##mname[1]                                   \
+               __attribute__((section(".data.mtypes"))) = { {                 \
                        .name = desc,                                          \
                        .next = NULL,                                          \
                        .n_alloc = 0,                                          \
                        .size = 0,                                             \
                        .ref = NULL,                                           \
-       };                                                                     \
+       } };                                                                   \
        static void _mtinit_##mname(void) __attribute__((_CONSTRUCTOR(1001))); \
        static void _mtinit_##mname(void)                                      \
        {                                                                      \
                if (_mg_##group.insert == NULL)                                \
                        _mg_##group.insert = &_mg_##group.types;               \
-               _mt_##mname.ref = _mg_##group.insert;                          \
-               *_mg_##group.insert = &_mt_##mname;                            \
-               _mg_##group.insert = &_mt_##mname.next;                        \
+               MTYPE_##mname->ref = _mg_##group.insert;                       \
+               *_mg_##group.insert = MTYPE_##mname;                           \
+               _mg_##group.insert = &MTYPE_##mname->next;                      \
        }                                                                      \
        static void _mtfini_##mname(void) __attribute__((_DESTRUCTOR(1001)));  \
        static void _mtfini_##mname(void)                                      \
        {                                                                      \
-               if (_mt_##mname.next)                                          \
-                       _mt_##mname.next->ref = _mt_##mname.ref;               \
-               *_mt_##mname.ref = _mt_##mname.next;                           \
+               if (MTYPE_##mname->next)                                       \
+                       MTYPE_##mname->next->ref = MTYPE_##mname->ref;         \
+               *MTYPE_##mname->ref = MTYPE_##mname->next;                     \
        }                                                                      \
        /* end */
 
 #define DEFINE_MTYPE(group, name, desc)                                        \
        DEFINE_MTYPE_ATTR(group, name, , desc)                                 \
-       struct memtype *const MTYPE_##name = &_mt_##name;                      \
        /* end */
 
 #define DEFINE_MTYPE_STATIC(group, name, desc)                                 \
        DEFINE_MTYPE_ATTR(group, name, static, desc)                           \
-       static struct memtype *const MTYPE_##name = &_mt_##name;               \
        /* end */
 
 DECLARE_MGROUP(LIB)