]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add an MTYPE for bitfields
authorPat Ruddy <pat@voltanet.io>
Wed, 26 May 2021 11:25:46 +0000 (12:25 +0100)
committerPat Ruddy <pat@voltanet.io>
Fri, 18 Jun 2021 08:34:43 +0000 (09:34 +0100)
it is handy to be able to see allocated bitfields in the show
memory output.

Signed-off-by: Pat Ruddy <pat@voltanet.io>
lib/bitfield.h
lib/memory.c

index 244938933b4574a49a197b9a734914b72eea6821..a3f361ed9de66babb90724cdb2de8f761ce70b7f 100644 (file)
@@ -60,6 +60,8 @@ typedef unsigned int word_t;
  */
 typedef struct {word_t *data; size_t n, m; } bitfield_t;
 
+DECLARE_MTYPE(BITFIELD);
+
 /**
  * Initialize the bits.
  * @v: an instance of bitfield_t struct.
@@ -70,7 +72,7 @@ typedef struct {word_t *data; size_t n, m; } bitfield_t;
        do {                                                                   \
                (v).n = 0;                                                     \
                (v).m = ((N) / WORD_SIZE + 1);                                 \
-               (v).data = calloc(1, ((v).m * sizeof(word_t)));                \
+               (v).data = XCALLOC(MTYPE_BITFIELD, ((v).m * sizeof(word_t)));  \
        } while (0)
 
 /**
@@ -193,7 +195,7 @@ static inline unsigned int bf_find_next_set_bit(bitfield_t v,
  */
 #define bf_free(v)                                                             \
        do {                                                                   \
-               free((v).data);                                                \
+               XFREE(MTYPE_BITFIELD, (v).data);                               \
                (v).data = NULL;                                               \
        } while (0)
 
index 0dc8e905247acf462b9fec70a617f3fd34024856..18811777ae40b4aa8fd05b3b836b9ff4c95eadcf 100644 (file)
@@ -36,6 +36,7 @@ struct memgroup **mg_insert = &mg_first;
 
 DEFINE_MGROUP(LIB, "libfrr");
 DEFINE_MTYPE(LIB, TMP, "Temporary memory");
+DEFINE_MTYPE(LIB, BITFIELD, "Bitfield memory");
 
 static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr)
 {