summaryrefslogtreecommitdiffstats
path: root/lib/memory.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-11-14 00:21:10 +0100
committerDavid Lamparter <equinox@diac24.net>2019-12-13 06:22:34 +0100
commit33de8d1dd02dfb53f125c8213c896bc62f6c6d8e (patch)
tree649fe6c9e0d636d644e2341c3133554b9b746752 /lib/memory.h
parentlib: make rcu_free() NULL-safe (diff)
downloadfrr-33de8d1dd02dfb53f125c8213c896bc62f6c6d8e.tar.xz
frr-33de8d1dd02dfb53f125c8213c896bc62f6c6d8e.zip
lib: completely get rid of the MTYPE alias hack
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>
Diffstat (limited to '')
-rw-r--r--lib/memory.h23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/memory.h b/lib/memory.h
index 8de5c4c2b..44ea19b55 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -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)