From 1cacabdff6c9b949eb33704073c9a94e085f930f Mon Sep 17 00:00:00 2001 From: Rickey Date: Thu, 27 Nov 2025 10:41:13 -0800 Subject: [PATCH] Clang format pool (#255) * Update comment prefix + add github action * Clang Format pool * fix clang format version * Fix pool clang format --- .github/workflows/run_tests_ci_workflow.yml | 5 +- include/pool.h | 93 +++++++++++---------- source/pool.c | 3 +- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/.github/workflows/run_tests_ci_workflow.yml b/.github/workflows/run_tests_ci_workflow.yml index db9e231..232b375 100644 --- a/.github/workflows/run_tests_ci_workflow.yml +++ b/.github/workflows/run_tests_ci_workflow.yml @@ -18,8 +18,9 @@ jobs: - name: Clang Format run: > - clang-format --dry-run -Werror - include/bitset.h source/bitset.c + clang-format --dry-run -Werror + include/bitset.h source/bitset.c + include/pool.h source/pool.c include/card.h source/card.c include/hand_analysis.h source/hand_analysis.c include/list.h source/list.c diff --git a/include/pool.h b/include/pool.h index fbfa114..b27a429 100644 --- a/include/pool.h +++ b/include/pool.h @@ -1,65 +1,66 @@ #ifndef POOL_H #define POOL_H -#include -#include - #include "bitset.h" +#include +#include + #ifdef POOLS_TEST_ENV #define POOLS_DEF_FILE "def_test_mempool.h" #else #define POOLS_DEF_FILE "def_balatro_mempool.h" #endif -#define POOL_DECLARE_TYPE(type) \ - typedef struct \ - { \ - Bitset* bitset; \ - type * objects; \ - } type##Pool; \ - type *pool_get_##type(); \ - void pool_free_##type(type *obj); \ - int pool_idx_##type(type *obj); \ - type *pool_at_##type(int idx); +#define POOL_DECLARE_TYPE(type) \ + typedef struct \ + { \ + Bitset* bitset; \ + type* objects; \ + } type##Pool; \ + type* pool_get_##type(); \ + void pool_free_##type(type* obj); \ + int pool_idx_##type(type* obj); \ + type* pool_at_##type(int idx); -#define POOL_DEFINE_TYPE(type, capacity) \ - BITSET_DEFINE(type##_bitset, capacity) \ - static type type##_storage[capacity]; \ - static type##Pool type##_pool = \ - { \ - .bitset = & type##_bitset, \ - .objects = type##_storage, \ - }; \ - type * pool_get_##type() \ - { \ - int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \ - if(free_offset == -1) return NULL; \ - return &type##_pool.objects[free_offset]; \ - } \ - void pool_free_##type(type *entry) \ - { \ - if(entry == NULL) return; \ - int offset = entry - &type##_pool.objects[0]; \ - bitset_set_idx(type##_pool.bitset, offset, false); \ - } \ - int pool_idx_##type(type *entry) \ - { \ - return entry - &type##_pool.objects[0]; \ - } \ - type *pool_at_##type(int idx) \ - { \ - if(idx < 0 || idx >= (type##_pool.bitset)->cap) return NULL; \ - return &type##_pool.objects[idx]; \ +#define POOL_DEFINE_TYPE(type, capacity) \ + BITSET_DEFINE(type##_bitset, capacity) \ + static type type##_storage[capacity]; \ + static type##Pool type##_pool = { \ + .bitset = &type##_bitset, \ + .objects = type##_storage, \ + }; \ + type* pool_get_##type() \ + { \ + int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \ + if (free_offset == -1) \ + return NULL; \ + return &type##_pool.objects[free_offset]; \ + } \ + void pool_free_##type(type* entry) \ + { \ + if (entry == NULL) \ + return; \ + int offset = entry - &type##_pool.objects[0]; \ + bitset_set_idx(type##_pool.bitset, offset, false); \ + } \ + int pool_idx_##type(type* entry) \ + { \ + return entry - &type##_pool.objects[0]; \ + } \ + type* pool_at_##type(int idx) \ + { \ + if (idx < 0 || idx >= (type##_pool.bitset)->cap) \ + return NULL; \ + return &type##_pool.objects[idx]; \ } -#define POOL_GET(type) pool_get_##type() +#define POOL_GET(type) pool_get_##type() #define POOL_FREE(type, obj) pool_free_##type(obj) -#define POOL_IDX(type, obj) pool_idx_##type(obj) // the index of the object -#define POOL_AT(type, idx) pool_at_##type(idx) // the object at +#define POOL_IDX(type, obj) pool_idx_##type(obj) // the index of the object +#define POOL_AT(type, idx) pool_at_##type(idx) // the object at -#define POOL_ENTRY(name, capacity) \ -POOL_DECLARE_TYPE(name); +#define POOL_ENTRY(name, capacity) POOL_DECLARE_TYPE(name); #include POOLS_DEF_FILE #undef POOL_ENTRY diff --git a/source/pool.c b/source/pool.c index 0d10721..7af3347 100644 --- a/source/pool.c +++ b/source/pool.c @@ -1,6 +1,5 @@ #include "pool.h" -#define POOL_ENTRY(name, capacity) \ -POOL_DEFINE_TYPE(name, capacity); +#define POOL_ENTRY(name, capacity) POOL_DEFINE_TYPE(name, capacity); #include POOLS_DEF_FILE #undef POOL_ENTRY