Macro safe slot_allocator.h
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user