Clearer macro conditions

This commit is contained in:
Imbus 2025-09-08 09:14:58 +02:00
parent de6aee3a3a
commit f29035319c

View file

@ -5,25 +5,24 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
/* Fiddle these around according to your need. Delete or check makefile */ /* Align to nearest multiple of align */
#ifdef FREELIST_NOALIGN static inline size_t align_up_to(size_t n, size_t align) {
#define ALIGN(x) (x) return (n + align - 1) & ~(align - 1);
#else // FREELIST_NOALIGN
/* Align to nearest multiple of sizeof(void*) */
static inline size_t align_up(size_t n) {
return (n + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
} }
#define ALIGN(x) (align_up(x)) /* Fiddle these around according to your need. Delete or check makefile */
#endif // FREELIST_NOALIGN #ifdef FREELIST_ALIGN
#define ALIGN(x) (align_up_to(x, sizeof(void *)))
#else
#define ALIGN(x) (x)
#endif
typedef struct FreeListBlock FreeListBlock; typedef struct FreeListBlock FreeListBlock;
typedef struct { typedef struct {
FreeListBlock *free;
uintptr_t start; uintptr_t start;
uintptr_t end; uintptr_t end;
FreeListBlock *free;
size_t size; size_t size;
size_t allocated; size_t allocated;
} FreeList; } FreeList;