Clang format pool (#255)

* Update comment prefix + add github action

* Clang Format pool

* fix clang format version

* Fix pool clang format
This commit is contained in:
Rickey
2025-11-27 10:41:13 -08:00
committed by GitHub
parent 184ee719b3
commit 1cacabdff6
3 changed files with 51 additions and 50 deletions
@@ -20,6 +20,7 @@ jobs:
run: > run: >
clang-format --dry-run -Werror clang-format --dry-run -Werror
include/bitset.h source/bitset.c include/bitset.h source/bitset.c
include/pool.h source/pool.c
include/card.h source/card.c include/card.h source/card.c
include/hand_analysis.h source/hand_analysis.c include/hand_analysis.h source/hand_analysis.c
include/list.h source/list.c include/list.h source/list.c
+11 -10
View File
@@ -1,11 +1,11 @@
#ifndef POOL_H #ifndef POOL_H
#define POOL_H #define POOL_H
#include <stdint.h>
#include <stdbool.h>
#include "bitset.h" #include "bitset.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef POOLS_TEST_ENV #ifdef POOLS_TEST_ENV
#define POOLS_DEF_FILE "def_test_mempool.h" #define POOLS_DEF_FILE "def_test_mempool.h"
#else #else
@@ -26,20 +26,21 @@
#define POOL_DEFINE_TYPE(type, capacity) \ #define POOL_DEFINE_TYPE(type, capacity) \
BITSET_DEFINE(type##_bitset, capacity) \ BITSET_DEFINE(type##_bitset, capacity) \
static type type##_storage[capacity]; \ static type type##_storage[capacity]; \
static type##Pool type##_pool = \ static type##Pool type##_pool = { \
{ \
.bitset = &type##_bitset, \ .bitset = &type##_bitset, \
.objects = type##_storage, \ .objects = type##_storage, \
}; \ }; \
type* pool_get_##type() \ type* pool_get_##type() \
{ \ { \
int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \ int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \
if(free_offset == -1) return NULL; \ if (free_offset == -1) \
return NULL; \
return &type##_pool.objects[free_offset]; \ return &type##_pool.objects[free_offset]; \
} \ } \
void pool_free_##type(type* entry) \ void pool_free_##type(type* entry) \
{ \ { \
if(entry == NULL) return; \ if (entry == NULL) \
return; \
int offset = entry - &type##_pool.objects[0]; \ int offset = entry - &type##_pool.objects[0]; \
bitset_set_idx(type##_pool.bitset, offset, false); \ bitset_set_idx(type##_pool.bitset, offset, false); \
} \ } \
@@ -49,7 +50,8 @@
} \ } \
type* pool_at_##type(int idx) \ type* pool_at_##type(int idx) \
{ \ { \
if(idx < 0 || idx >= (type##_pool.bitset)->cap) return NULL; \ if (idx < 0 || idx >= (type##_pool.bitset)->cap) \
return NULL; \
return &type##_pool.objects[idx]; \ return &type##_pool.objects[idx]; \
} }
@@ -58,8 +60,7 @@
#define POOL_IDX(type, obj) pool_idx_##type(obj) // the index of the object #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_AT(type, idx) pool_at_##type(idx) // the object at
#define POOL_ENTRY(name, capacity) \ #define POOL_ENTRY(name, capacity) POOL_DECLARE_TYPE(name);
POOL_DECLARE_TYPE(name);
#include POOLS_DEF_FILE #include POOLS_DEF_FILE
#undef POOL_ENTRY #undef POOL_ENTRY
+1 -2
View File
@@ -1,6 +1,5 @@
#include "pool.h" #include "pool.h"
#define POOL_ENTRY(name, capacity) \ #define POOL_ENTRY(name, capacity) POOL_DEFINE_TYPE(name, capacity);
POOL_DEFINE_TYPE(name, capacity);
#include POOLS_DEF_FILE #include POOLS_DEF_FILE
#undef POOL_ENTRY #undef POOL_ENTRY