From b2d56f8094717640487bed8f8b0b05da4922ba76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Mon, 21 Jul 2025 20:30:33 +0200 Subject: [PATCH] Macro safe slot_allocator.h --- include/ucore/slot_allocator.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/ucore/slot_allocator.h b/include/ucore/slot_allocator.h index ddc13e1..d0cdc7f 100644 --- a/include/ucore/slot_allocator.h +++ b/include/ucore/slot_allocator.h @@ -56,13 +56,13 @@ struct UCSlotAlloc { */ #define UC_SLOT_ALLOC_DEF(var_name, slot_size_, num_slots_) \ struct {\ - uc_bv_integer bitmap[UC_BV_LEN(num_slots_)]; \ - uint8_t memory[num_slots_ * slot_size_] __attribute__((aligned)); \ + uc_bv_integer bitmap[UC_BV_LEN((num_slots_))]; \ + uint8_t memory[(num_slots_) * (slot_size_)] __attribute__((aligned)); \ } var_name ## _memory = { \ }; \ UCSlotAlloc var_name = { \ - .slot_size = slot_size_, \ - .num_slots = num_slots_, \ + .slot_size = (slot_size_), \ + .num_slots = (num_slots_), \ .bitmap = UC_BV_STATIC_INIT(var_name ## _memory.bitmap), \ .slots = var_name ## _memory.memory \ }; @@ -72,12 +72,12 @@ UCSlotAlloc var_name = { \ * bits is also allocated for the bitmap with this definition */ #define UC_SLOT_ALLOC_DEF_EX(var_name, slot_size_, num_slots_, memory) \ -uc_bv_integer var_name ## _bitmap[UC_BV_LEN(num_slots_)] = {}; \ +uc_bv_integer var_name ## _bitmap[UC_BV_LEN((num_slots_))] = {}; \ UCSlotAlloc var_name = { \ - .slot_size = slot_size_, \ - .num_slots = num_slots_, \ + .slot_size = (slot_size_), \ + .num_slots = (num_slots_), \ .bitmap = UC_BV_STATIC_INIT(var_name ## _bitmap), \ - .slots = memory \ + .slots = (memory) \ }; /** Allocate a memory slot @@ -99,8 +99,8 @@ void uc_slot_free(UCSlotAlloc *restrict sa, void *restrict slot); /** uc_slot_free() where the slot can be a NULL pointer */ #define uc_slot_free_safe(sa, slot) \ do { \ - if (slot != NULL) { \ - uc_slot_free(sa, slot); \ + if ((slot) != NULL) { \ + uc_slot_free((sa), (slot)); \ } \ } while (0)