Rename Misc Utils
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define _array_header(ARRAY) (ArrayHeader *)(wapp_pointer_offset(ARRAY, (i64)sizeof(ArrayHeader) * -1))
|
||||
#define _array_header(ARRAY) (ArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(ArrayHeader) * -1))
|
||||
|
||||
wp_persist inline void _array_validate(const GenericArray array, u64 item_size);
|
||||
|
||||
@@ -54,7 +54,7 @@ void *_array_get(GenericArray array, u64 index, u64 item_size) {
|
||||
ArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(index < header->count, "`index` is out of bounds");
|
||||
|
||||
return wapp_pointer_offset(array, header->item_size * index);
|
||||
return wpMiscUtilsOffsetPointer(array, header->item_size * index);
|
||||
}
|
||||
|
||||
void _array_set(GenericArray array, u64 index, void *value, u64 item_size) {
|
||||
@@ -85,7 +85,7 @@ void _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_siz
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
|
||||
u64 copy_count = src_header->count < remaining_capacity ? src_header->count : remaining_capacity;
|
||||
void *dst_ptr = wapp_pointer_offset(dst, dst_header->count * dst_header->item_size);
|
||||
void *dst_ptr = wpMiscUtilsOffsetPointer(dst, dst_header->count * dst_header->item_size);
|
||||
memcpy(dst_ptr, src, copy_count * src_header->item_size);
|
||||
dst_header->count += copy_count;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ GenericArray _array_append_alloc(const Allocator *allocator, GenericArray array,
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
if (header->count >= header->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(header->capacity * 2);
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(header->capacity * 2);
|
||||
output = (GenericArray )_array_alloc_capacity(allocator, new_capacity, flags,
|
||||
header->item_size);
|
||||
if (!output) {
|
||||
@@ -145,7 +145,7 @@ GenericArray _array_extend_alloc(const Allocator *allocator, GenericArray dst, c
|
||||
ArrayHeader *dst_header = _array_header(dst);
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
if (src_header->count >= remaining_capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst_header->capacity * 2);
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (GenericArray )_array_alloc_capacity(allocator, new_capacity,
|
||||
flags, dst_header->item_size);
|
||||
if (!output) {
|
||||
@@ -176,7 +176,7 @@ GenericArray _array_copy_alloc(const Allocator *allocator, GenericArray dst, con
|
||||
ArrayHeader *src_header = _array_header(src);
|
||||
ArrayHeader *dst_header = _array_header(dst);
|
||||
if (src_header->count >= dst_header->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst_header->capacity * 2);
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (GenericArray )_array_alloc_capacity(allocator, new_capacity,
|
||||
flags, src_header->item_size);
|
||||
if (!output) {
|
||||
|
||||
@@ -14,8 +14,8 @@ BEGIN_C_LINKAGE
|
||||
|
||||
#define WAPP_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 _calc_array_count(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define _calc_array_capacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(_calc_array_count(TYPE, __VA_ARGS__) * 2)
|
||||
|
||||
typedef struct Str8 Str8;
|
||||
|
||||
@@ -88,7 +88,7 @@ typedef enum {
|
||||
#else
|
||||
#define _stack_array(TYPE, SIZE) struct {ArrayHeader header; \
|
||||
TYPE items[SIZE]; \
|
||||
wapp_misc_utils_reserve_padding(sizeof(ArrayHeader) + \
|
||||
wpMiscUtilsReservePadding(sizeof(ArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wapp_array(TYPE, ...) \
|
||||
((TYPE *)( \
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
void *wapp_mem_util_align_forward(void *ptr, u64 alignment) {
|
||||
wpDebugAssert(ptr != NULL, "`ptr` should not be NULL");
|
||||
wpRuntimeAssert(wapp_is_power_of_two(alignment), "`alignment` value is not a power of two");
|
||||
wpRuntimeAssert(wpMiscUtilsIsPowerOfTwo(alignment), "`alignment` value is not a power of two");
|
||||
|
||||
uptr p = (uptr)ptr;
|
||||
uptr align = (uptr)alignment;
|
||||
|
||||
@@ -34,7 +34,7 @@ GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue,
|
||||
// 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 new_capacity = wpMiscUtilsU64RoundUpPow2(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);
|
||||
|
||||
@@ -23,7 +23,7 @@ BEGIN_C_LINKAGE
|
||||
#define PB(SIZE) (TB(SIZE) * 1000llu)
|
||||
#define EB(SIZE) (PB(SIZE) * 1000llu)
|
||||
|
||||
#define wapp_misc_utils_reserve_padding(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))]
|
||||
#define wpMiscUtilsReservePadding(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))]
|
||||
|
||||
#define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1))
|
||||
#define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2))
|
||||
@@ -31,7 +31,7 @@ BEGIN_C_LINKAGE
|
||||
#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8))
|
||||
#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16))
|
||||
#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32))
|
||||
#define wapp_misc_utils_u64_round_up_pow2(X) ( \
|
||||
#define wpMiscUtilsU64RoundUpPow2(X) ( \
|
||||
( \
|
||||
U64_RSHIFT_OR_32( \
|
||||
U64_RSHIFT_OR_16( \
|
||||
@@ -47,17 +47,17 @@ BEGIN_C_LINKAGE
|
||||
) + 1 \
|
||||
)
|
||||
|
||||
#define wapp_is_power_of_two(NUM) ((NUM & (NUM - 1)) == 0)
|
||||
#define wapp_pointer_offset(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET)))
|
||||
#define wpMiscUtilsIsPowerOfTwo(NUM) ((NUM & (NUM - 1)) == 0)
|
||||
#define wpMiscUtilsOffsetPointer(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET)))
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#define wapp_misc_utils_va_args_count(T, ...) (std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value)
|
||||
#define wpMiscUtilsVaArgsCount(T, ...) (std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value)
|
||||
#else
|
||||
#define wapp_misc_utils_va_args_count(T, ...) (sizeof((T[]){__VA_ARGS__})/sizeof(T))
|
||||
#define wpMiscUtilsVaArgsCount(T, ...) (sizeof((T[]){__VA_ARGS__})/sizeof(T))
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#endif // !MISC_UTILS_H
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ typedef struct {
|
||||
WFile *errlog;
|
||||
LogLevel level;
|
||||
|
||||
wapp_misc_utils_reserve_padding(2 * sizeof(WFile *) + sizeof(LogLevel));
|
||||
wpMiscUtilsReservePadding(2 * sizeof(WFile *) + sizeof(LogLevel));
|
||||
} LogConfig;
|
||||
|
||||
wp_intern LogConfig LOG_CONFIG = {
|
||||
|
||||
@@ -29,7 +29,7 @@ struct Arena {
|
||||
ArenaStorageType type;
|
||||
b8 committed;
|
||||
|
||||
wapp_misc_utils_reserve_padding(sizeof(u8 *) * 3 + sizeof(u64) + sizeof(ArenaStorageType) + sizeof(b8));
|
||||
wpMiscUtilsReservePadding(sizeof(u8 *) * 3 + sizeof(u64) + sizeof(ArenaStorageType) + sizeof(b8));
|
||||
};
|
||||
|
||||
b8 wapp_mem_arena_init_buffer(Arena **arena, u8 *buffer, u64 buffer_size) {
|
||||
@@ -56,7 +56,7 @@ b8 wapp_mem_arena_init_allocated_custom(Arena **arena, u64 base_capacity, MemAll
|
||||
}
|
||||
|
||||
u64 size = sizeof(Arena) + (base_capacity >= ARENA_MINIMUM_CAPACITY ? base_capacity : ARENA_MINIMUM_CAPACITY);
|
||||
u64 alloc_size = wapp_misc_utils_u64_round_up_pow2(size);
|
||||
u64 alloc_size = wpMiscUtilsU64RoundUpPow2(size);
|
||||
u8 *allocated = (u8 *)wapp_os_mem_alloc(NULL, alloc_size, WAPP_MEM_ACCESS_READ_WRITE, flags,
|
||||
zero_buffer ? WAPP_MEM_INIT_INITIALISED : WAPP_MEM_INIT_UNINITIALISED);
|
||||
if (!allocated) {
|
||||
|
||||
@@ -32,7 +32,7 @@ struct CMDResult {
|
||||
CMDError error;
|
||||
b8 exited;
|
||||
|
||||
wapp_misc_utils_reserve_padding(sizeof(b8) + sizeof(i32) + sizeof(CMDError));
|
||||
wpMiscUtilsReservePadding(sizeof(b8) + sizeof(i32) + sizeof(CMDError));
|
||||
};
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
|
||||
@@ -19,7 +19,7 @@ struct TermcolourData {
|
||||
WORD default_colour;
|
||||
WORD current_colour;
|
||||
|
||||
wapp_misc_utils_reserve_padding(sizeof(HANDLE) + sizeof(WORD) + sizeof(WORD));
|
||||
wpMiscUtilsReservePadding(sizeof(HANDLE) + sizeof(WORD) + sizeof(WORD));
|
||||
};
|
||||
|
||||
wp_intern void init_data(TermcolourData *data);
|
||||
|
||||
@@ -22,7 +22,7 @@ struct TestFuncResult {
|
||||
Str8 name;
|
||||
b8 passed;
|
||||
|
||||
wapp_misc_utils_reserve_padding(sizeof(Str8) + sizeof(b8));
|
||||
wpMiscUtilsReservePadding(sizeof(Str8) + sizeof(b8));
|
||||
};
|
||||
|
||||
typedef TestFuncResult(TestFunc)(void);
|
||||
|
||||
Reference in New Issue
Block a user