From d58e24f6a97bc80ab911aedcfd78c11dd27e6252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Tue, 21 Apr 2026 23:01:22 +0200 Subject: [PATCH] Minor cleanup --- include/ucore/slot_allocator.h | 11 ++++++----- src/spool.c | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/ucore/slot_allocator.h b/include/ucore/slot_allocator.h index 417df05..b7ca13f 100644 --- a/include/ucore/slot_allocator.h +++ b/include/ucore/slot_allocator.h @@ -5,9 +5,10 @@ #include //Free memory is reused to build a linked list of slots -typedef struct UCSlot UCSlot; -struct UCSlot { - UCSlot *next; +typedef union UCSlot UCSlot; +union UCSlot { + UCSlot *next; // next free block (when not allocated) + uint8_t data[0]; // data when allocated }; typedef struct UCSlotArena UCSlotArena; @@ -71,7 +72,7 @@ static inline void *uc_slot_alloc(UCSlotArena *arena) #endif } - return slot; + return &slot->data[0]; } /** * Free a slot. @@ -84,7 +85,7 @@ static inline void uc_slot_free(UCSlotArena *arena, void *memory) #ifdef DEBUG for (const UCSlot *slot = arena->free_list ; slot = slot->next) { if (slot == mem) { - assert("Double free detected"); + assert(0 && "Double free detected"); } } #endif diff --git a/src/spool.c b/src/spool.c index c40116e..decb58f 100644 --- a/src/spool.c +++ b/src/spool.c @@ -41,7 +41,7 @@ void uc_pool_init(UCPool *pool, void *buffer, size_t buffer_size, size_t block_s p->next = next; p = next; } - ((UCPoolBlock *)p)->next = NULL; // last element + p->next = NULL; // last element pool->free_list = (UCPoolBlock *)first_addr; } @@ -65,8 +65,6 @@ void *uc_pool_alloc(UCPool *pool) #endif return block->data; } -#include - void uc_pool_free(UCPool *pool, void *p) { if (p == NULL) { @@ -92,7 +90,6 @@ void uc_pool_free(UCPool *pool, void *p) pool->free_list = p; } - void uc_pool_reset(UCPool *pool) { if (pool->capacity == 0)