## Summary Standardize naming conventions across the entire wizapp-stdlib codebase by replacing inconsistent prefixes and snake_case with a unified `wp` prefix + CamelCase scheme. ## Changes ### Naming convention applied | Pattern | Before | After | |---|---|---| | Public functions | `wapp_module_function` | `wpModuleFunction` | | Public types | `GenericXxx`, bare `Xxx` | `WpXxx` | | Constants / enum values | `WAPP_XXX`, `SHELL_XXX` | `WP_XXX`, `WP_SHELL_XXX` | | Internal functions | `_module_function` | `_moduleFunction` | | Storage-class macros | `wapp_extern`, `wapp_intern` | `wp_extern`, `wp_intern` | ### Modules affected All 20 modules were renamed: `arena`, `array`, `dbl_list`, `queue`, `str8`, `mem_allocator`, `mem_utils`, `mem_os`, `file`, `cpath`, `log`, `shell_commander`, `shell_termcolour`, `shell_utils`, `prng/xorshift`, `uuid`, `tester`, `aliases`, `assert`, `misc_utils`, `platform` — plus their test files. ### Backward compatibility Added `src/oldnames.h` with `#define OLD_NAME NEW_NAME` for every renamed symbol, organized by module under Constants → Types → Functions sections. Existing code that includes this file will compile without changes. Reviewed-on: #12 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
+127
-127
@@ -8,209 +8,209 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define WAPP_ARRAY_MAGIC (u64)0x57415f415252
|
||||
#define WP_ARRAY_MAGIC (u64)0x57415f415252
|
||||
|
||||
#define _calc_array_count(TYPE, ...) wapp_misc_utils_va_args_count(TYPE, __VA_ARGS__)
|
||||
#define _calc_array_capacity(TYPE, ...) wapp_misc_utils_u64_round_up_pow2(_calc_array_count(TYPE, __VA_ARGS__) * 2)
|
||||
#define _calcArrayCount(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define _calcArrayCapacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(_calcArrayCount(TYPE, __VA_ARGS__) * 2)
|
||||
|
||||
typedef struct Str8 Str8;
|
||||
typedef struct WpStr8 WpStr8;
|
||||
|
||||
// NOTE (Abdelrahman): Typedefs to distinguish arrays from regular pointers
|
||||
typedef void *GenericArray;
|
||||
typedef void **VoidPtrArray;
|
||||
typedef c8 *C8Array;
|
||||
typedef c16 *C16Array;
|
||||
typedef c32 *C32Array;
|
||||
typedef u8 *U8Array;
|
||||
typedef u16 *U16Array;
|
||||
typedef u32 *U32Array;
|
||||
typedef u64 *U64Array;
|
||||
typedef b8 *B8Array;
|
||||
typedef i8 *I8Array;
|
||||
typedef i16 *I16Array;
|
||||
typedef i32 *I32Array;
|
||||
typedef i64 *I64Array;
|
||||
typedef f32 *F32Array;
|
||||
typedef f64 *F64Array;
|
||||
typedef f128 *F128Array;
|
||||
typedef uptr *UptrArray;
|
||||
typedef iptr *IptrArray;
|
||||
typedef Str8 *Str8Array;
|
||||
typedef void *WpArray;
|
||||
typedef void **WpVoidPtrArray;
|
||||
typedef c8 *WpC8Array;
|
||||
typedef c16 *WpC16Array;
|
||||
typedef c32 *WpC32Array;
|
||||
typedef u8 *WpU8Array;
|
||||
typedef u16 *WpU16Array;
|
||||
typedef u32 *WpU32Array;
|
||||
typedef u64 *WpU64Array;
|
||||
typedef b8 *WpB8Array;
|
||||
typedef i8 *WpI8Array;
|
||||
typedef i16 *WpI16Array;
|
||||
typedef i32 *WpI32Array;
|
||||
typedef i64 *WpI64Array;
|
||||
typedef f32 *WpF32Array;
|
||||
typedef f64 *WpF64Array;
|
||||
typedef f128 *WpF128Array;
|
||||
typedef uptr *WpUptrArray;
|
||||
typedef iptr *WpIptrArray;
|
||||
typedef WpStr8 *WpStr8Array;
|
||||
|
||||
typedef enum {
|
||||
ARRAY_INIT_NONE = 0,
|
||||
ARRAY_INIT_FILLED = 1 << 1,
|
||||
} ArrayInitFlags;
|
||||
WP_ARRAY_INIT_NONE = 0,
|
||||
WP_ARRAY_INIT_FILLED = 1 << 1,
|
||||
} WpArrayInitFlags;
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_array(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calc_array_capacity(TYPE, __VA_ARGS__); \
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpArray(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
\
|
||||
TYPE items[_calc_array_capacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
TYPE items[_calcArrayCapacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
\
|
||||
wapp_persist u8 array[ \
|
||||
sizeof(ArrayHeader) + _calc_array_capacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
wp_persist u8 array[ \
|
||||
sizeof(WpArrayHeader) + _calcArrayCapacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
ArrayHeader *header = (ArrayHeader *)array; \
|
||||
header->magic = WAPP_ARRAY_MAGIC; \
|
||||
header->count = _calc_array_count(TYPE, __VA_ARGS__); \
|
||||
header->capacity = _calc_array_capacity(TYPE, __VA_ARGS__); \
|
||||
WpArrayHeader *header = (WpArrayHeader *)array; \
|
||||
header->magic = WP_ARRAY_MAGIC; \
|
||||
header->count = _calcArrayCount(TYPE, __VA_ARGS__); \
|
||||
header->capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
u8 *buf = (u8 *)(header + 1); \
|
||||
memcpy(buf, items, capacity * sizeof(TYPE)); \
|
||||
return (TYPE *)buf; \
|
||||
}())
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FLAGS) ([&]() { \
|
||||
wapp_persist u8 array[ \
|
||||
sizeof(ArrayHeader) + CAPACITY * sizeof(TYPE) \
|
||||
#define wpArrayWithCapacity(TYPE, CAPACITY, FLAGS) ([&]() { \
|
||||
wp_persist u8 array[ \
|
||||
sizeof(WpArrayHeader) + CAPACITY * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
ArrayHeader *header = (ArrayHeader *)array; \
|
||||
header->magic = WAPP_ARRAY_MAGIC; \
|
||||
header->count = (FLAGS & ARRAY_INIT_FILLED) ? CAPACITY : 0; \
|
||||
WpArrayHeader *header = (WpArrayHeader *)array; \
|
||||
header->magic = WP_ARRAY_MAGIC; \
|
||||
header->count = (FLAGS & WP_ARRAY_INIT_FILLED) ? CAPACITY : 0; \
|
||||
header->capacity = CAPACITY; \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
return (TYPE *)(header + 1); \
|
||||
}())
|
||||
#define wapp_array_pop(TYPE, ARRAY) ([&]() { \
|
||||
if (ARRAY == NULL || _array_count((GenericArray)ARRAY) == 0) { \
|
||||
#define wpArrayPop(TYPE, ARRAY) ([&]() { \
|
||||
if (ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0) { \
|
||||
TYPE result{}; \
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
return *((TYPE *)_array_pop((GenericArray)ARRAY, sizeof(TYPE))); \
|
||||
return *((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))); \
|
||||
}())
|
||||
#else
|
||||
#define _stack_array(TYPE, SIZE) struct {ArrayHeader header; \
|
||||
#define _stackArray(TYPE, SIZE) struct {WpArrayHeader header; \
|
||||
TYPE items[SIZE]; \
|
||||
wapp_misc_utils_reserve_padding(sizeof(ArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wapp_array(TYPE, ...) \
|
||||
wpMiscUtilsReservePadding(sizeof(WpArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wpArray(TYPE, ...) \
|
||||
((TYPE *)( \
|
||||
(_stack_array(TYPE, _calc_array_capacity(TYPE, __VA_ARGS__))){ \
|
||||
(_stackArray(TYPE, _calcArrayCapacity(TYPE, __VA_ARGS__))){ \
|
||||
.header = { \
|
||||
.magic = WAPP_ARRAY_MAGIC, \
|
||||
.count = _calc_array_count(TYPE, __VA_ARGS__), \
|
||||
.capacity = _calc_array_capacity(TYPE, __VA_ARGS__), \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = _calcArrayCount(TYPE, __VA_ARGS__), \
|
||||
.capacity = _calcArrayCapacity(TYPE, __VA_ARGS__), \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
.items = {__VA_ARGS__}, \
|
||||
}.items \
|
||||
))
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FLAGS) \
|
||||
#define wpArrayWithCapacity(TYPE, CAPACITY, FLAGS) \
|
||||
((TYPE *)( \
|
||||
(_stack_array(TYPE, CAPACITY)){ \
|
||||
(_stackArray(TYPE, CAPACITY)){ \
|
||||
.header = { \
|
||||
.magic = WAPP_ARRAY_MAGIC, \
|
||||
.count = (FLAGS & ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = (FLAGS & WP_ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
.capacity = CAPACITY, \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
.items = {0}, \
|
||||
}.items \
|
||||
))
|
||||
#define wapp_array_pop(TYPE, ARRAY) \
|
||||
(ARRAY == NULL || _array_count((GenericArray)ARRAY) == 0 ? \
|
||||
#define wpArrayPop(TYPE, ARRAY) \
|
||||
(ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0 ? \
|
||||
(TYPE){0} : \
|
||||
*((TYPE *)_array_pop((GenericArray)ARRAY, sizeof(TYPE))) \
|
||||
*((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))) \
|
||||
)
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wapp_array_count(ARRAY) \
|
||||
(_array_count((GenericArray)ARRAY))
|
||||
#define wapp_array_capacity(ARRAY) \
|
||||
(_array_capacity((GenericArray)ARRAY))
|
||||
#define wapp_array_item_size(ARRAY) \
|
||||
(_array_item_size((GenericArray)ARRAY))
|
||||
#define wapp_array_set_count(ARRAY, COUNT) \
|
||||
(_array_set_count((GenericArray)ARRAY, COUNT))
|
||||
#define wapp_array_get(TYPE, ARRAY, INDEX) \
|
||||
((TYPE *)_array_get((GenericArray)ARRAY, \
|
||||
#define wpArrayCount(ARRAY) \
|
||||
(_arrayCount((WpArray)ARRAY))
|
||||
#define wpArrayCapacity(ARRAY) \
|
||||
(_arrayCapacity((WpArray)ARRAY))
|
||||
#define wpArrayItemSize(ARRAY) \
|
||||
(_arrayItemSize((WpArray)ARRAY))
|
||||
#define wpArraySetCount(ARRAY, COUNT) \
|
||||
(_arraySetCount((WpArray)ARRAY, COUNT))
|
||||
#define wpArrayGet(TYPE, ARRAY, INDEX) \
|
||||
((TYPE *)_arrayGet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_set(TYPE, ARRAY, INDEX, VALUE_PTR) \
|
||||
(_array_set((GenericArray)ARRAY, \
|
||||
#define wpArraySet(TYPE, ARRAY, INDEX, VALUE_PTR) \
|
||||
(_arraySet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_append_capped(TYPE, ARRAY, VALUE_PTR) \
|
||||
(_array_append_capped((GenericArray)ARRAY, \
|
||||
#define wpArrayAppendCapped(TYPE, ARRAY, VALUE_PTR) \
|
||||
(_arrayAppendCapped((WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_extend_capped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_array_extend_capped((GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayExtendCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayExtendCappend((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_copy_capped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_array_copy_capped((GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayCopyCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayCopyCapped((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_append_alloc(TYPE, ALLOCATOR_PTR, ARRAY, VALUE_PTR, FLAGS) \
|
||||
((TYPE *)_array_append_alloc(ALLOCATOR_PTR, \
|
||||
(GenericArray)ARRAY, \
|
||||
#define wpArrayAppendAlloc(TYPE, ALLOCATOR_PTR, ARRAY, VALUE_PTR, FLAGS) \
|
||||
((TYPE *)_arrayAppendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_extend_alloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_array_extend_alloc(ALLOCATOR_PTR, \
|
||||
(GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayExtendAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayExtendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_copy_alloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_array_copy_alloc(ALLOCATOR_PTR, \
|
||||
(GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayCopyAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayCopyAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_clear(TYPE, ARRAY) \
|
||||
(_array_clear((GenericArray)ARRAY, \
|
||||
#define wpArrayClear(TYPE, ARRAY) \
|
||||
(_arrayClear((WpArray)ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_calc_alloc_size(TYPE, CAPACITY) _array_calc_alloc_size(CAPACITY, sizeof(TYPE))
|
||||
#define wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
#define wapp_array_from_preallcated_buffer(TYPE, BUFFER, BUFFER_SIZE) \
|
||||
#define wpArrayCalcAllocSize(TYPE, CAPACITY) _arrayCalcAllocSize(CAPACITY, sizeof(TYPE))
|
||||
#define wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_arrayAllocCapacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
#define wpArrayFromPreallcatedBuffer(TYPE, BUFFER, BUFFER_SIZE) \
|
||||
((TYPE *)_array_from_preallcated_buffer(BUFFER, BUFFER_SIZE, sizeof(TYPE)))
|
||||
|
||||
|
||||
typedef struct header ArrayHeader;
|
||||
struct header {
|
||||
typedef struct WpArrayHeader WpArrayHeader;
|
||||
struct WpArrayHeader {
|
||||
u64 magic;
|
||||
u64 count;
|
||||
u64 capacity;
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
u64 _array_count(GenericArray array);
|
||||
u64 _array_capacity(GenericArray array);
|
||||
u64 _array_item_size(GenericArray array);
|
||||
void _array_set_count(GenericArray array, u64 count);
|
||||
void *_array_get(GenericArray array, u64 index, u64 item_size);
|
||||
void _array_set(GenericArray array, u64 index, void *value, u64 item_size);
|
||||
void _array_append_capped(GenericArray array, void *value, u64 item_size);
|
||||
void _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_size);
|
||||
void _array_copy_capped(GenericArray dst, const GenericArray src, u64 item_size);
|
||||
GenericArray _array_append_alloc(const Allocator *allocator, GenericArray array, void *value,
|
||||
ArrayInitFlags flags, u64 item_size);
|
||||
GenericArray _array_extend_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src,
|
||||
ArrayInitFlags flags, u64 item_size);
|
||||
GenericArray _array_copy_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src,
|
||||
ArrayInitFlags flags, u64 item_size);
|
||||
void *_array_pop(GenericArray array, u64 item_size);
|
||||
void _array_clear(GenericArray array, u64 item_size);
|
||||
u64 _array_calc_alloc_size(u64 capacity, u64 item_size);
|
||||
GenericArray _array_alloc_capacity(const Allocator *allocator, u64 capacity, ArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
GenericArray _array_from_preallocated_buffer(void *buffer, u64 buffer_size, ArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
u64 _arrayCount(WpArray array);
|
||||
u64 _arrayCapacity(WpArray array);
|
||||
u64 _arrayItemSize(WpArray array);
|
||||
void _arraySetCount(WpArray array, u64 count);
|
||||
void *_arrayGet(WpArray array, u64 index, u64 item_size);
|
||||
void _arraySet(WpArray array, u64 index, void *value, u64 item_size);
|
||||
void _arrayAppendCapped(WpArray array, void *value, u64 item_size);
|
||||
void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size);
|
||||
void _arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size);
|
||||
WpArray _arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
WpArray _arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
void *_arrayPop(WpArray array, u64 item_size);
|
||||
void _arrayClear(WpArray array, u64 item_size);
|
||||
u64 _arrayCalcAllocSize(u64 capacity, u64 item_size);
|
||||
WpArray _arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#endif // !ARRAY_H
|
||||
|
||||
Reference in New Issue
Block a user