## 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:
+22
-22
@@ -6,15 +6,15 @@
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include <string.h>
|
||||
|
||||
void _queue_push(GenericQueue *queue, void *item, u64 item_size) {
|
||||
wapp_debug_assert(queue != NULL, "`queue` should not be NULL");
|
||||
wapp_runtime_assert(item_size == wapp_array_item_size(queue->items), "Invalid type");
|
||||
void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
u64 capacity = wapp_array_capacity(queue->items);
|
||||
u64 capacity = wpArrayCapacity(queue->items);
|
||||
if (queue->count >= capacity) { return; }
|
||||
|
||||
u64 index = (queue->back)++;
|
||||
_array_set(queue->items, index, item, item_size);
|
||||
_arraySet(queue->items, index, item, item_size);
|
||||
++(queue->count);
|
||||
|
||||
if (queue->back >= capacity) {
|
||||
@@ -22,30 +22,30 @@ void _queue_push(GenericQueue *queue, void *item, u64 item_size) {
|
||||
}
|
||||
}
|
||||
|
||||
GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, void *item, u64 item_size) {
|
||||
wapp_debug_assert(allocator != NULL && queue != NULL && item != NULL,
|
||||
WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL && queue != NULL && item != NULL,
|
||||
"`allocator`, `queue` and `item` should not be NULL");
|
||||
wapp_runtime_assert(item_size == wapp_array_item_size(queue->items), "Invalid type");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
GenericQueue *output = queue;
|
||||
WpQueue *output = queue;
|
||||
|
||||
u64 capacity = wapp_array_capacity(queue->items);
|
||||
u64 capacity = wpArrayCapacity(queue->items);
|
||||
|
||||
// NOTE (Abdelrahman): Extracted into variable to fix MSVC error
|
||||
b8 queue_full = queue->count >= capacity;
|
||||
if (queue_full) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(capacity * 2);
|
||||
u64 array_size = _array_calc_alloc_size(new_capacity, item_size);
|
||||
u64 alloc_size = sizeof(GenericQueue) + array_size;
|
||||
void *buffer = wapp_mem_allocator_alloc(allocator, alloc_size);
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2);
|
||||
u64 array_size = _arrayCalcAllocSize(new_capacity, item_size);
|
||||
u64 alloc_size = sizeof(WpQueue) + array_size;
|
||||
void *buffer = wpMemAllocatorAlloc(allocator, alloc_size);
|
||||
if (!buffer) {
|
||||
goto RETURN_QUEUE_PUSH_ALLOC;
|
||||
}
|
||||
|
||||
memset((void *)buffer, 0, alloc_size);
|
||||
|
||||
output = (GenericQueue *)buffer;
|
||||
output->items = _array_from_preallocated_buffer((void *)(output + 1), array_size, ARRAY_INIT_FILLED, item_size);
|
||||
output = (WpQueue *)buffer;
|
||||
output->items = _arrayFromPreallocatedBuffer((void *)(output + 1), array_size, WP_ARRAY_INIT_FILLED, item_size);
|
||||
|
||||
// NOTE (Abdelrahman): When the queue is full, the front and back indices should
|
||||
// always be the same
|
||||
@@ -84,25 +84,25 @@ GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue,
|
||||
output->count = queue->count;
|
||||
}
|
||||
|
||||
_queue_push(output, item, item_size);
|
||||
_queuePush(output, item, item_size);
|
||||
|
||||
RETURN_QUEUE_PUSH_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_queue_pop(GenericQueue *queue, u64 item_size) {
|
||||
wapp_debug_assert(queue != NULL, "`queue` should not be NULL");
|
||||
wapp_runtime_assert(item_size == wapp_array_item_size(queue->items), "Invalid type");
|
||||
void *_queuePop(WpQueue *queue, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
if (queue->count == 0) { return NULL; }
|
||||
|
||||
u64 index = (queue->front)++;
|
||||
--(queue->count);
|
||||
|
||||
u64 capacity = wapp_array_capacity(queue->items);
|
||||
u64 capacity = wpArrayCapacity(queue->items);
|
||||
if (queue->front >= capacity) {
|
||||
queue->front = 0;
|
||||
}
|
||||
|
||||
return _array_get(queue->items, index, item_size);
|
||||
return _arrayGet(queue->items, index, item_size);
|
||||
}
|
||||
|
||||
+49
-49
@@ -8,42 +8,42 @@
|
||||
#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
|
||||
|
||||
typedef struct {
|
||||
GenericArray items;
|
||||
WpArray items;
|
||||
u64 front;
|
||||
u64 back;
|
||||
u64 count;
|
||||
} GenericQueue;
|
||||
} WpQueue;
|
||||
|
||||
// NOTE (Abdelrahman): GenericQueue typedefs for readability
|
||||
typedef GenericQueue VoidPtrQueue;
|
||||
typedef GenericQueue C8Queue;
|
||||
typedef GenericQueue C16Queue;
|
||||
typedef GenericQueue C32Queue;
|
||||
typedef GenericQueue U8Queue;
|
||||
typedef GenericQueue U16Queue;
|
||||
typedef GenericQueue U32Queue;
|
||||
typedef GenericQueue U64Queue;
|
||||
typedef GenericQueue B8Queue;
|
||||
typedef GenericQueue I8Queue;
|
||||
typedef GenericQueue I16Queue;
|
||||
typedef GenericQueue I32Queue;
|
||||
typedef GenericQueue I64Queue;
|
||||
typedef GenericQueue F32Queue;
|
||||
typedef GenericQueue F64Queue;
|
||||
typedef GenericQueue F128Queue;
|
||||
typedef GenericQueue UptrQueue;
|
||||
typedef GenericQueue IptrQueue;
|
||||
typedef GenericQueue Str8Queue;
|
||||
// NOTE (Abdelrahman): WpQueue typedefs for readability
|
||||
typedef WpQueue WpVoidPtrQueue;
|
||||
typedef WpQueue WpC8Queue;
|
||||
typedef WpQueue WpC16Queue;
|
||||
typedef WpQueue WpC32Queue;
|
||||
typedef WpQueue WpU8Queue;
|
||||
typedef WpQueue WpU16Queue;
|
||||
typedef WpQueue WpU32Queue;
|
||||
typedef WpQueue WpU64Queue;
|
||||
typedef WpQueue WpB8Queue;
|
||||
typedef WpQueue WpI8Queue;
|
||||
typedef WpQueue WpI16Queue;
|
||||
typedef WpQueue WpI32Queue;
|
||||
typedef WpQueue WpI64Queue;
|
||||
typedef WpQueue WpF32Queue;
|
||||
typedef WpQueue WpF64Queue;
|
||||
typedef WpQueue WpF128Queue;
|
||||
typedef WpQueue WpUptrQueue;
|
||||
typedef WpQueue WpIptrQueue;
|
||||
typedef WpQueue WpStr8Queue;
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_queue(TYPE, CAPACITY) ([&]() { \
|
||||
wapp_persist GenericArray arr = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED); \
|
||||
wapp_persist GenericQueue queue = { \
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpQueue(TYPE, CAPACITY) ([&]() { \
|
||||
wp_persist WpArray arr = wpArrayWithCapacity(TYPE, CAPACITY, WP_ARRAY_INIT_FILLED); \
|
||||
wp_persist WpQueue queue = { \
|
||||
arr, \
|
||||
0, \
|
||||
0, \
|
||||
@@ -52,9 +52,9 @@ typedef GenericQueue Str8Queue;
|
||||
\
|
||||
return queue; \
|
||||
}())
|
||||
#define wapp_queue_alloc(TYPE, ALLOCATOR_PTR, CAPACITY) ([&]() { \
|
||||
wapp_persist GenericQueue queue = { \
|
||||
wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
|
||||
#define wpQueueAlloc(TYPE, ALLOCATOR_PTR, CAPACITY) ([&]() { \
|
||||
wp_persist WpQueue queue = { \
|
||||
wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
@@ -63,38 +63,38 @@ typedef GenericQueue Str8Queue;
|
||||
return queue; \
|
||||
}())
|
||||
#else
|
||||
#define wapp_queue(TYPE, CAPACITY) ((GenericQueue){ \
|
||||
.items = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED), \
|
||||
#define wpQueue(TYPE, CAPACITY) ((WpQueue){ \
|
||||
.items = wpArrayWithCapacity(TYPE, CAPACITY, WP_ARRAY_INIT_FILLED), \
|
||||
.front = 0, \
|
||||
.back = 0, \
|
||||
.count = 0, \
|
||||
})
|
||||
#define wapp_queue_alloc(TYPE, ALLOCATOR_PTR, CAPACITY) ((GenericQueue){ \
|
||||
.items = wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
|
||||
#define wpQueueAlloc(TYPE, ALLOCATOR_PTR, CAPACITY) ((WpQueue){ \
|
||||
.items = wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
|
||||
.front = 0, \
|
||||
.back = 0, \
|
||||
.count = 0, \
|
||||
})
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wapp_queue_capacity(QUEUE_PTR) (wapp_array_capacity((QUEUE_PTR)->items))
|
||||
#define wapp_queue_item_size(QUEUE_PTR) (wapp_array_item_size((QUEUE_PTR)->items))
|
||||
#define wapp_queue_push(TYPE, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queue_push(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
#define wpQueueCapacity(QUEUE_PTR) (wpArrayCapacity((QUEUE_PTR)->items))
|
||||
#define wpQueueItemSize(QUEUE_PTR) (wpArrayItemSize((QUEUE_PTR)->items))
|
||||
#define wpQueuePush(TYPE, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queuePush(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wapp_queue_push_alloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queue_push_alloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
#define wpQueuePushAlloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queuePushAlloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wapp_queue_pop(TYPE, QUEUE_PTR) ( \
|
||||
(TYPE *)_queue_pop(QUEUE_PTR, sizeof(TYPE)) \
|
||||
#define wpQueuePop(TYPE, QUEUE_PTR) ( \
|
||||
(TYPE *)_queuePop(QUEUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
|
||||
void _queue_push(GenericQueue *queue, void *item, u64 item_size);
|
||||
GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, void *item, u64 item_size);
|
||||
void *_queue_pop(GenericQueue *queue, u64 item_size);
|
||||
void _queuePush(WpQueue *queue, void *item, u64 item_size);
|
||||
WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size);
|
||||
void *_queuePop(WpQueue *queue, u64 item_size);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#endif // !QUEUE_H
|
||||
|
||||
Reference in New Issue
Block a user