From 575e0a52b1e0dfa773c0f8365f458ad61a620357 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 13 Sep 2026 02:31:46 +0100 Subject: [PATCH] Add labels to all typedef'd structs and enums --- src/base/array/array.h | 2 +- src/base/dbl_list/dbl_list.h | 4 +- src/base/hash/hasher/hasher.c | 44 ++++++++++++++++++++++ src/base/hash/hasher/hasher.h | 9 +++-- src/base/hash/hasher/murmur3.h | 2 +- src/base/hash/hasher/siphash.h | 4 +- src/base/mem/allocator/mem_allocator.h | 2 +- src/base/queue/queue.h | 2 +- src/base/stream/stream.h | 2 +- src/base/wapp_base.c | 1 + src/log/log.c | 2 +- src/log/log.h | 4 +- src/os/allocators/arena/mem_arena.c | 2 +- src/os/cpath/cpath.h | 2 +- src/os/file/file.h | 4 +- src/os/mem/mem_os_ops.h | 4 +- src/os/mem/posix/mem_os_posix.h | 2 +- src/os/mem/win/mem_os_win.h | 2 +- src/os/shell/commander/commander_output.h | 4 +- src/os/shell/termcolour/terminal_colours.h | 2 +- 20 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 src/base/hash/hasher/hasher.c diff --git a/src/base/array/array.h b/src/base/array/array.h index 2352093..6bdeaa5 100644 --- a/src/base/array/array.h +++ b/src/base/array/array.h @@ -41,7 +41,7 @@ typedef uptr *WpUptrArray; typedef iptr *WpIptrArray; typedef WpStr8 *WpStr8Array; -typedef enum { +typedef enum WpArrayInitFlags { WP_ARRAY_INIT_NONE = 0, WP_ARRAY_INIT_FILLED = 1 << 1, } WpArrayInitFlags; diff --git a/src/base/dbl_list/dbl_list.h b/src/base/dbl_list/dbl_list.h index 8306b52..67cfc68 100644 --- a/src/base/dbl_list/dbl_list.h +++ b/src/base/dbl_list/dbl_list.h @@ -16,7 +16,7 @@ BEGIN_C_LINKAGE typedef struct WpDblNode WpDblNode; -typedef struct { +typedef struct WpDblNodeHeader { u64 magic; u64 item_size; WpDblNode *prev; @@ -28,7 +28,7 @@ struct WpDblNode { void *item; }; -typedef struct { +typedef struct WpDblList { u64 magic; u64 node_count; u64 item_size; diff --git a/src/base/hash/hasher/hasher.c b/src/base/hash/hasher/hasher.c new file mode 100644 index 0000000..fc4f227 --- /dev/null +++ b/src/base/hash/hasher/hasher.c @@ -0,0 +1,44 @@ +// vim:fileencoding=utf-8:foldmethod=marker + +#include "hasher.h" +#include "../../../common/assert/assert.h" + +WpU128Hash wpHasherGetHash128(const WpHasher *hasher, WpU8Stream *stream, void *hasher_data) { + wpDebugAssert(hasher != NULL && stream != NULL, "hasher and stream shouldn't be NULL"); + + WpU128Hash output; + switch (hasher->type) { + case WP_HASH_TYPE_64: { + output.hash[0] = hasher->hasher_64(stream, hasher_data); + output.hash[1] = hasher->hasher_64(stream, hasher_data); + } break; + case WP_HASH_TYPE_128: { + output = hasher->hasher_128(stream, hasher_data); + } break; + default: { + wpRuntimeAssert(0, "Invalid hasher type"); + } break; + } + + return output; +} + +u64 wpHasherGetHash64(const WpHasher *hasher, WpU8Stream *stream, void *hasher_data) { + wpDebugAssert(hasher != NULL && stream != NULL, "hasher and stream shouldn't be NULL"); + + u64 output; + switch (hasher->type) { + case WP_HASH_TYPE_64: { + output = hasher->hasher_64(stream, hasher_data); + } break; + case WP_HASH_TYPE_128: { + WpU128Hash hash = hasher->hasher_128(stream, hasher_data); + output = hash.hash[0] ^ hash.hash[1]; + } break; + default: { + wpRuntimeAssert(0, "Invalid hasher type"); + } break; + } + + return output; +} diff --git a/src/base/hash/hasher/hasher.h b/src/base/hash/hasher/hasher.h index b541755..a7ae456 100644 --- a/src/base/hash/hasher/hasher.h +++ b/src/base/hash/hasher/hasher.h @@ -9,11 +9,11 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef struct { +typedef struct WpU128Hash { u64 hash[2]; } WpU128Hash; -typedef enum { +typedef enum WpHasherType { WP_HASH_TYPE_64, WP_HASH_TYPE_128, @@ -23,7 +23,7 @@ typedef enum { typedef u64 (*WpHasher64) (WpU8Stream *stream, void *hasher_data); typedef WpU128Hash (*WpHasher128)(WpU8Stream *stream, void *hasher_data); -typedef struct { +typedef struct WpHasher { WpHasherType type; union { WpHasher64 hasher_64; @@ -39,6 +39,9 @@ typedef struct { #define wpHasher128(HASHER) ((WpHasher){ .type = WP_HASH_TYPE_128, .hasher_128 = (HASHER) }) #endif +WpU128Hash wpHasherGetHash128(const WpHasher *hasher, WpU8Stream *stream, void *hasher_data); +u64 wpHasherGetHash64 (const WpHasher *hasher, WpU8Stream *stream, void *hasher_data); + #ifdef WP_PLATFORM_CPP END_C_LINKAGE #endif // !WP_PLATFORM_CPP diff --git a/src/base/hash/hasher/murmur3.h b/src/base/hash/hasher/murmur3.h index bb4019a..1d1efd2 100644 --- a/src/base/hash/hasher/murmur3.h +++ b/src/base/hash/hasher/murmur3.h @@ -19,7 +19,7 @@ BEGIN_C_LINKAGE #define WP_MUR3_HASHER_MAGIC wpU64Const(0x57504d4841534833) -typedef struct { +typedef struct WpMur3HasherData { u64 magic; u32 seed; } WpMur3HasherData; diff --git a/src/base/hash/hasher/siphash.h b/src/base/hash/hasher/siphash.h index f51c690..54562e0 100644 --- a/src/base/hash/hasher/siphash.h +++ b/src/base/hash/hasher/siphash.h @@ -19,12 +19,12 @@ BEGIN_C_LINKAGE #define WP_SIP_HASHER_MAGIC wpU64Const(0x5750534950485348) -typedef struct { +typedef struct WpSipHasherKey { u64 lo; u64 hi; } WpSipHasherKey; -typedef struct { +typedef struct WpSipHasherData { WpSipHasherKey key; u64 magic; u64 compression; diff --git a/src/base/mem/allocator/mem_allocator.h b/src/base/mem/allocator/mem_allocator.h index ea6e36f..d023133 100644 --- a/src/base/mem/allocator/mem_allocator.h +++ b/src/base/mem/allocator/mem_allocator.h @@ -11,7 +11,7 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef enum { +typedef enum WpMemOp { WP_MEM_OP_ALLOC, WP_MEM_OP_ALLOC_ALIGNED, WP_MEM_OP_REALLOC, diff --git a/src/base/queue/queue.h b/src/base/queue/queue.h index a32bada..01f545f 100644 --- a/src/base/queue/queue.h +++ b/src/base/queue/queue.h @@ -12,7 +12,7 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef struct { +typedef struct WpQueue { WpArray items; u64 front; u64 back; diff --git a/src/base/stream/stream.h b/src/base/stream/stream.h index 3027ce1..42cb17a 100644 --- a/src/base/stream/stream.h +++ b/src/base/stream/stream.h @@ -10,7 +10,7 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef struct { +typedef struct WpStream { void *data; u64 count; u64 position; diff --git a/src/base/wapp_base.c b/src/base/wapp_base.c index 059be82..15a4bc6 100644 --- a/src/base/wapp_base.c +++ b/src/base/wapp_base.c @@ -6,6 +6,7 @@ #include "wapp_base.h" #include "array/array.c" #include "dbl_list/dbl_list.c" +#include "hash/hasher/hasher.c" #include "hash/hasher/murmur3.c" #include "hash/hasher/siphash.c" #include "queue/queue.c" diff --git a/src/log/log.c b/src/log/log.c index 06a1ad5..4479c2f 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -15,7 +15,7 @@ wp_intern WpStr8RO L_BRACKET = wpStr8LitRo("["); wp_intern WpStr8RO R_BRACKET_SPACE = wpStr8LitRo("] "); wp_intern WpStr8RO R_BRACKET_NEWLINE = wpStr8LitRo("]\n"); -typedef struct { +typedef struct LogConfig { WpFile *outlog; WpFile *errlog; WpLogLevel level; diff --git a/src/log/log.h b/src/log/log.h index f8805f9..c52ca49 100644 --- a/src/log/log.h +++ b/src/log/log.h @@ -10,7 +10,7 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef enum { +typedef enum WpLogLevel { WP_LOG_LEVEL_FATAL, WP_LOG_LEVEL_CRITICAL, WP_LOG_LEVEL_ERROR, @@ -21,7 +21,7 @@ typedef enum { COUNT_LOG_LEVEL, } WpLogLevel; -typedef struct { +typedef struct WpLogger { WpStr8 name; } WpLogger; diff --git a/src/os/allocators/arena/mem_arena.c b/src/os/allocators/arena/mem_arena.c index 35f28c6..c939d2a 100644 --- a/src/os/allocators/arena/mem_arena.c +++ b/src/os/allocators/arena/mem_arena.c @@ -16,7 +16,7 @@ #define ARENA_MINIMUM_CAPACITY KiB(16) // Allocate minimum of 4 pages -typedef enum { +typedef enum WpCpathJoinResult { ARENA_STORAGE_TYPE_ALLOCATED, ARENA_STORAGE_TYPE_BUFFER, } ArenaStorageType; diff --git a/src/os/cpath/cpath.h b/src/os/cpath/cpath.h index 6e16943..c23a729 100644 --- a/src/os/cpath/cpath.h +++ b/src/os/cpath/cpath.h @@ -28,7 +28,7 @@ BEGIN_C_LINKAGE #define wpCpathDirname(ALLOCATOR, PATH) dirUp(ALLOCATOR, PATH, 1) #define wpCpathDirUp(ALLOCATOR, PATH, COUNT) dirUp(ALLOCATOR, PATH, COUNT) -typedef enum { +typedef enum WpCpathJoinResult { WP_CPATH_JOIN_RESULT_SUCCESS = 0, WP_CPATH_JOIN_RESULT_INVALID_ARGS, WP_CPATH_JOIN_RESULT_EMPTY_PARTS, diff --git a/src/os/file/file.h b/src/os/file/file.h index 38be003..571e851 100644 --- a/src/os/file/file.h +++ b/src/os/file/file.h @@ -13,7 +13,7 @@ BEGIN_C_LINKAGE typedef struct WpFile WpFile; -typedef enum { +typedef enum WpFileAccessMode { WP_ACCESS_READ, // Equivalent to r WP_ACCESS_WRITE, // Equivalent to w WP_ACCESS_APPEND, // Equivalent to a @@ -26,7 +26,7 @@ typedef enum { COUNT_FILE_ACCESS_MODE, } WpFileAccessMode; -typedef enum { +typedef enum WpFileSeekOrigin { WP_SEEK_START, WP_SEEK_CURRENT, WP_SEEK_END, diff --git a/src/os/mem/mem_os_ops.h b/src/os/mem/mem_os_ops.h index 8184e38..1cbb8b4 100644 --- a/src/os/mem/mem_os_ops.h +++ b/src/os/mem/mem_os_ops.h @@ -9,7 +9,7 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef enum { +typedef enum WpMemAccess { WP_MEM_ACCESS_NONE, WP_MEM_ACCESS_READ_ONLY, WP_MEM_ACCESS_EXEC_ONLY, @@ -18,7 +18,7 @@ typedef enum { WP_MEM_ACCESS_READ_WRITE_EXEC, } WpMemAccess; -typedef enum { +typedef enum WpMemInitType { WP_MEM_INIT_UNINITIALISED, WP_MEM_INIT_INITIALISED, } WpMemInitType; diff --git a/src/os/mem/posix/mem_os_posix.h b/src/os/mem/posix/mem_os_posix.h index 9f2805b..d4cf132 100644 --- a/src/os/mem/posix/mem_os_posix.h +++ b/src/os/mem/posix/mem_os_posix.h @@ -13,7 +13,7 @@ BEGIN_C_LINKAGE #include -typedef enum { +typedef enum WpMemAllocFlags { #if defined(WP_PLATFORM_LINUX) || defined(WP_PLATFORM_GNU) WP_MEM_ALLOC_RESERVE = 0, WP_MEM_ALLOC_COMMIT = MAP_POPULATE, diff --git a/src/os/mem/win/mem_os_win.h b/src/os/mem/win/mem_os_win.h index 229caad..c91b004 100644 --- a/src/os/mem/win/mem_os_win.h +++ b/src/os/mem/win/mem_os_win.h @@ -15,7 +15,7 @@ BEGIN_C_LINKAGE #include #include -typedef enum { +typedef enum WpMemAllocFlags { WP_MEM_ALLOC_RESERVE = MEM_RESERVE, WP_MEM_ALLOC_COMMIT = MEM_COMMIT, } WpMemAllocFlags; diff --git a/src/os/shell/commander/commander_output.h b/src/os/shell/commander/commander_output.h index 4d18d48..0c58945 100644 --- a/src/os/shell/commander/commander_output.h +++ b/src/os/shell/commander/commander_output.h @@ -11,13 +11,13 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef enum { +typedef enum WpCmdOutHandling { WP_SHELL_OUTPUT_DISCARD, WP_SHELL_OUTPUT_PRINT, WP_SHELL_OUTPUT_CAPTURE, } WpCmdOutHandling; -typedef enum { +typedef enum WpCmdError { WP_SHELL_ERR_NO_ERROR, WP_SHELL_ERR_INVALID_ARGS, WP_SHELL_ERR_ALLOCATION_FAIL, diff --git a/src/os/shell/termcolour/terminal_colours.h b/src/os/shell/termcolour/terminal_colours.h index 6c1a328..e5844f2 100644 --- a/src/os/shell/termcolour/terminal_colours.h +++ b/src/os/shell/termcolour/terminal_colours.h @@ -10,7 +10,7 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef enum { +typedef enum WpTerminalColour { WP_TERM_COLOUR_FG_BLACK, WP_TERM_COLOUR_FG_RED, WP_TERM_COLOUR_FG_GREEN,