style: 更新 .clang-format 规则并重新格式化所有源文件

- 重构模块使用新的代码风格
- 老代码 (src 目录下的代码) 继续使用之前的代码风格

通过在需要不同代码风格的目录下放对应 .clang-format 配置文件实现
This commit is contained in:
2026-04-14 01:52:53 +08:00
parent 7b5404e8e0
commit 2fc4b33359
62 changed files with 1248 additions and 728 deletions

1
src/base/.clang-format Symbolic link
View File

@@ -0,0 +1 @@
../../.clang-format

View File

@@ -24,8 +24,12 @@ static inline size_t next_capacity(size_t capacity) {
* @param capacity 当前容量地址
* @param need 目标容量
*/
static inline void array_reserve_impl(void **items, size_t item_size,
size_t *capacity, size_t need) {
static inline void array_reserve_impl(
void **items,
size_t item_size,
size_t *capacity,
size_t need
) {
if (*capacity >= need) return;
size_t new_capacity = next_capacity(*capacity);
@@ -51,8 +55,12 @@ static inline void array_reserve_impl(void **items, size_t item_size,
*
* @return void* 新槽位地址
*/
static inline void *array_push_impl(void **items, size_t item_size,
size_t *count, size_t *capacity) {
static inline void *array_push_impl(
void **items,
size_t item_size,
size_t *count,
size_t *capacity
) {
array_reserve_impl(items, item_size, capacity, *count + 1);
void *slot = (char *)*items + *count * item_size;
@@ -71,14 +79,14 @@ static inline void *array_push_impl(void **items, size_t item_size,
* @return true 删除成功
* @return false 下标越界
*/
static inline bool array_erase_impl(void *items, size_t item_size,
size_t *count, size_t index) {
static inline bool
array_erase_impl(void *items, size_t item_size, size_t *count, size_t index) {
if (index >= *count) return false;
size_t tail_count = *count - index - 1;
if (tail_count > 0) {
char *dest = (char *)items + index * item_size;
char *src = dest + item_size;
char *src = dest + item_size;
memmove(dest, src, tail_count * item_size);
}

View File

@@ -5,14 +5,23 @@
#define fatal(format, ...) \
_fatal(__LINE__, __FUNCTION__, __FILE__, format, ##__VA_ARGS__)
void _fatal(int line, const char *function, const char *file,
const char *format, ...) __attribute__((noreturn))
__attribute__((format(printf, 4, 5)));
void _fatal(
int line,
const char *function,
const char *file,
const char *format,
...
) __attribute__((noreturn)) __attribute__((format(printf, 4, 5)));
#define warn(format, ...) \
_warn(__LINE__, __FUNCTION__, __FILE__, format, ##__VA_ARGS__)
void _warn(int line, const char *function, const char *file, const char *format,
...) __attribute__((format(printf, 4, 5)));
void _warn(
int line,
const char *function,
const char *file,
const char *format,
...
) __attribute__((format(printf, 4, 5)));
const char *current_time_str(void);

View File

@@ -7,10 +7,10 @@
#define countof(foo) (ssizeof(foo) / ssizeof(foo[0]))
#ifdef __GNUC__
#define likely(expr) __builtin_expect(!!(expr), 1)
#define likely(expr) __builtin_expect(!!(expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
#else
#define likely(expr) expr
#define likely(expr) expr
#define unlikely(expr) expr
#endif

View File

@@ -5,11 +5,11 @@
#include <string.h>
#include <sys/types.h>
#define p_alloc_nr(x) (((x) + 16) * 3 / 2)
#define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count)))
#define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))
#define p_alloc_nr(x) (((x) + 16) * 3 / 2)
#define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count)))
#define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))
#define p_realloc(pp, count) xrealloc((void *)(pp), sizeof(**(pp)) * (count))
#define p_copy(src, count) xmemcopy((src), sizeof(*(src)) * (count))
#define p_copy(src, count) xmemcopy((src), sizeof(*(src)) * (count))
#define p_delete(mem_p) \
do { \
@@ -64,8 +64,7 @@ static inline void *xmemcopy(const void *src, size_t n) {
}
static inline void xrealloc(void **ptr, ssize_t newsize) {
if (newsize <= 0)
p_delete(ptr);
if (newsize <= 0) p_delete(ptr);
else {
*ptr = realloc(*ptr, newsize);
if (!*ptr) abort();