From dbc3fe63f8feb5f532abdecf327ab2e995f73fc5 Mon Sep 17 00:00:00 2001 From: doylet Date: Sun, 20 Jul 2025 15:13:13 +1000 Subject: [PATCH] Cleanup CVT functions --- Single_Header/dn_single_header.cpp | 89 ++++++++++++----------- Single_Header/dn_single_header.h | 109 ++++++++++++++++------------- Source/Base/dn_base_containers.cpp | 6 +- Source/Base/dn_base_convert.cpp | 61 ++++++++-------- Source/Base/dn_base_convert.h | 103 ++++++++++++++------------- Source/Base/dn_base_mem.h | 4 +- Source/Core/dn_core_debug.cpp | 10 +-- Source/OS/dn_os.cpp | 2 +- Source/OS/dn_os_w32.cpp | 8 +-- 9 files changed, 202 insertions(+), 190 deletions(-) diff --git a/Single_Header/dn_single_header.cpp b/Single_Header/dn_single_header.cpp index 05840c9..5b999f3 100644 --- a/Single_Header/dn_single_header.cpp +++ b/Single_Header/dn_single_header.cpp @@ -1,4 +1,4 @@ -// Generated by the DN single header generator 2025-07-16 19:35:09 +// Generated by the DN single header generator 2025-07-20 15:12:51 #define DN_BASE_INC_CPP @@ -1478,9 +1478,9 @@ DN_U32 DN_DSMap_Hash(DN_DSMap const *map, DN_DSMapKey key) DN_U32 len = 0; DN_U32 h = seed; switch (key.type) { - case DN_DSMapKeyType_BufferAsU64NoHash: /*FALLTHRU*/ - case DN_DSMapKeyType_U64NoHash: DN_InvalidCodePath; /*FALLTHRU*/ - case DN_DSMapKeyType_Invalid: break; + case DN_DSMapKeyType_BufferAsU64NoHash: /*FALLTHRU*/ + case DN_DSMapKeyType_U64NoHash: DN_InvalidCodePath; /*FALLTHRU*/ + case DN_DSMapKeyType_Invalid: break; case DN_DSMapKeyType_Buffer: key_ptr = DN_CAST(char const *) key.buffer_data; @@ -2214,7 +2214,7 @@ DN_API int DN_CVT_FmtBuffer3DotTruncate(char *buffer, int size, DN_FMT_ATTRIB ch return result; } -DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8(uint64_t val, char separator) +DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8(DN_U64 val, char separator) { DN_CVTU64Str8 result = {}; if (val == 0) { @@ -2247,44 +2247,41 @@ DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8(uint64_t val, char separator) return result; } -DN_API DN_CVTU64ByteSize DN_CVT_U64ToByteSize(uint64_t bytes, DN_CVTU64ByteSizeType desired_type) +DN_API DN_CVTU64Bytes DN_CVT_U64ToBytes(DN_U64 bytes, DN_CVTBytesType type) { - DN_CVTU64ByteSize result = {}; + DN_Assert(type != DN_CVTBytesType_Count); + DN_CVTU64Bytes result = {}; result.bytes = DN_CAST(DN_F64) bytes; - if (!DN_Check(desired_type != DN_CVTU64ByteSizeType_Count)) { - result.suffix = DN_CVT_U64ByteSizeTypeString(result.type); - return result; - } - if (desired_type == DN_CVTU64ByteSizeType_Auto) - for (; result.type < DN_CVTU64ByteSizeType_Count && result.bytes >= 1024.0; result.type = DN_CAST(DN_CVTU64ByteSizeType)(DN_CAST(DN_USize) result.type + 1)) + if (type == DN_CVTBytesType_Auto) + for (; result.type < DN_CVTBytesType_Count && result.bytes >= 1024.0; result.type = DN_CAST(DN_CVTBytesType)(DN_CAST(DN_USize) result.type + 1)) result.bytes /= 1024.0; else - for (; result.type < desired_type; result.type = DN_CAST(DN_CVTU64ByteSizeType)(DN_CAST(DN_USize) result.type + 1)) + for (; result.type < type; result.type = DN_CAST(DN_CVTBytesType)(DN_CAST(DN_USize) result.type + 1)) result.bytes /= 1024.0; - result.suffix = DN_CVT_U64ByteSizeTypeString(result.type); + result.suffix = DN_CVT_BytesTypeToStr8(result.type); return result; } -DN_API DN_Str8 DN_CVT_U64ToByteSizeStr8(DN_Arena *arena, uint64_t bytes, DN_CVTU64ByteSizeType desired_type) +DN_API DN_Str8 DN_CVT_U64ToBytesStr8(DN_Arena *arena, DN_U64 bytes, DN_CVTBytesType desired_type) { - DN_CVTU64ByteSize byte_size = DN_CVT_U64ToByteSize(bytes, desired_type); - DN_Str8 result = DN_Str8_InitF(arena, "%.2f%.*s", byte_size.bytes, DN_STR_FMT(byte_size.suffix)); + DN_CVTU64Bytes byte_size = DN_CVT_U64ToBytes(bytes, desired_type); + DN_Str8 result = DN_Str8_InitF(arena, "%.2f%.*s", byte_size.bytes, DN_STR_FMT(byte_size.suffix)); return result; } -DN_API DN_Str8 DN_CVT_U64ByteSizeTypeString(DN_CVTU64ByteSizeType type) +DN_API DN_Str8 DN_CVT_BytesTypeToStr8(DN_CVTBytesType type) { DN_Str8 result = DN_STR8(""); switch (type) { - case DN_CVTU64ByteSizeType_B: result = DN_STR8("B"); break; - case DN_CVTU64ByteSizeType_KiB: result = DN_STR8("KiB"); break; - case DN_CVTU64ByteSizeType_MiB: result = DN_STR8("MiB"); break; - case DN_CVTU64ByteSizeType_GiB: result = DN_STR8("GiB"); break; - case DN_CVTU64ByteSizeType_TiB: result = DN_STR8("TiB"); break; - case DN_CVTU64ByteSizeType_Count: result = DN_STR8(""); break; - case DN_CVTU64ByteSizeType_Auto: result = DN_STR8(""); break; + case DN_CVTBytesType_B: result = DN_STR8("B"); break; + case DN_CVTBytesType_KiB: result = DN_STR8("KiB"); break; + case DN_CVTBytesType_MiB: result = DN_STR8("MiB"); break; + case DN_CVTBytesType_GiB: result = DN_STR8("GiB"); break; + case DN_CVTBytesType_TiB: result = DN_STR8("TiB"); break; + case DN_CVTBytesType_Count: result = DN_STR8(""); break; + case DN_CVTBytesType_Auto: result = DN_STR8(""); break; } return result; } @@ -2405,14 +2402,14 @@ DN_API DN_Str8 DN_CVT_F64ToAge(DN_Arena *arena, DN_F64 age_s, DN_CVTU64AgeUnit u return result; } -DN_API uint64_t DN_CVT_HexToU64(DN_Str8 hex) +DN_API DN_U64 DN_CVT_HexToU64(DN_Str8 hex) { DN_Str8 real_hex = DN_Str8_TrimPrefix(DN_Str8_TrimPrefix(hex, DN_STR8("0x")), DN_STR8("0X")); - DN_USize max_hex_size = sizeof(uint64_t) * 2 /*hex chars per byte*/; + DN_USize max_hex_size = sizeof(DN_U64) * 2 /*hex chars per byte*/; DN_Assert(real_hex.size <= max_hex_size); DN_USize size = DN_Min(max_hex_size, real_hex.size); - uint64_t result = 0; + DN_U64 result = 0; for (DN_USize index = 0; index < size; index++) { char ch = real_hex.data[index]; DN_CharHexToU8 val = DN_Char_HexToU8(ch); @@ -2423,13 +2420,13 @@ DN_API uint64_t DN_CVT_HexToU64(DN_Str8 hex) return result; } -DN_API DN_Str8 DN_CVT_U64ToHex(DN_Arena *arena, uint64_t number, uint32_t flags) +DN_API DN_Str8 DN_CVT_U64ToHex(DN_Arena *arena, DN_U64 number, uint32_t flags) { DN_Str8 prefix = {}; - if ((flags & DN_CVTHexU64Str8Flags_0xPrefix)) + if ((flags & DN_CVTU64HexStrFlags_0xPrefix)) prefix = DN_STR8("0x"); - char const *fmt = (flags & DN_CVTHexU64Str8Flags_UppercaseHex) ? "%I64X" : "%I64x"; + char const *fmt = (flags & DN_CVTU64HexStrFlags_UppercaseHex) ? "%I64X" : "%I64x"; DN_USize required_size = DN_CStr8_FSize(fmt, number) + prefix.size; DN_Str8 result = DN_Str8_Alloc(arena, required_size, DN_ZeroMem_No); @@ -2441,17 +2438,17 @@ DN_API DN_Str8 DN_CVT_U64ToHex(DN_Arena *arena, uint64_t number, uint32_t flags) return result; } -DN_API DN_CVTU64HexStr8 DN_CVT_U64ToHexStr8(uint64_t number, DN_CVTHexU64Str8Flags flags) +DN_API DN_CVTU64HexStr DN_CVT_U64ToHexStr8(DN_U64 number, DN_CVTU64HexStrFlags flags) { DN_Str8 prefix = {}; - if (flags & DN_CVTHexU64Str8Flags_0xPrefix) + if (flags & DN_CVTU64HexStrFlags_0xPrefix) prefix = DN_STR8("0x"); - DN_CVTU64HexStr8 result = {}; + DN_CVTU64HexStr result = {}; DN_Memcpy(result.data, prefix.data, prefix.size); result.size += DN_CAST(int8_t) prefix.size; - char const *fmt = (flags & DN_CVTHexU64Str8Flags_UppercaseHex) ? "%I64X" : "%I64x"; + char const *fmt = (flags & DN_CVTU64HexStrFlags_UppercaseHex) ? "%I64X" : "%I64x"; int size = DN_SNPrintF(result.data + result.size, DN_ArrayCountU(result.data) - result.size, fmt, number); result.size += DN_CAST(uint8_t) size; DN_Assert(result.size < DN_ArrayCountU(result.data)); @@ -5301,7 +5298,7 @@ DN_API DN_Str8 DN_OS_ReadAll(DN_Arena *arena, DN_Str8 path, DN_OSErrSink *error) result = DN_Str8_Alloc(arena, path_info.size, DN_ZeroMem_No); if (!DN_Str8_HasData(result)) { DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); - DN_Str8 buffer_size_str8 = DN_CVT_U64ToByteSizeStr8(tmem.arena, path_info.size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 buffer_size_str8 = DN_CVT_U64ToBytesStr8AutoFromTLS(path_info.size); DN_OS_ErrSinkAppendF(error, 1 /*error_code*/, "Failed to allocate %.*s for reading file '%.*s'", DN_STR_FMT(buffer_size_str8), DN_STR_FMT(path)); DN_Arena_TempMemEnd(temp_mem); result = {}; @@ -8445,7 +8442,7 @@ DN_API DN_OSFileRead DN_OS_FileRead(DN_OSFile *file, void *buffer, DN_USize size DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); if (!DN_Check(size <= (unsigned long)-1)) { - DN_Str8 buffer_size_str8 = DN_CVT_U64ToByteSizeStr8(tmem.arena, size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 buffer_size_str8 = DN_CVT_U64ToBytesStr8AutoFromTLS(size); DN_OS_ErrSinkAppendF( err, 1 /*error_code*/, @@ -8499,9 +8496,9 @@ DN_API bool DN_OS_FileWritePtr(DN_OSFile *file, void const *buffer, DN_USize siz } if (!result) { - DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); - DN_W32Error win_error = DN_W32_LastError(tmem.arena); - DN_Str8 buffer_size_str8 = DN_CVT_U64ToByteSizeStr8(tmem.arena, size, DN_CVTU64ByteSizeType_Auto); + DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); + DN_W32Error win_error = DN_W32_LastError(tmem.arena); + DN_Str8 buffer_size_str8 = DN_CVT_U64ToBytesStr8AutoFromTLS(size); DN_OS_ErrSinkAppendF(err, win_error.code, "Failed to write buffer (%.*s) to file handle: %.*s", DN_STR_FMT(buffer_size_str8), DN_STR_FMT(win_error.msg)); } return result; @@ -10020,8 +10017,8 @@ DN_API void DN_Debug_TrackAlloc(void *ptr, DN_USize size, bool leak_permitted) DN_DebugAlloc *alloc = alloc_entry.value; if (alloc_entry.found) { if ((alloc->flags & DN_DebugAllocFlag_Freed) == 0) { - DN_Str8 alloc_size = DN_CVT_U64ToByteSizeStr8(alloc_table->arena, alloc->size, DN_CVTU64ByteSizeType_Auto); - DN_Str8 new_alloc_size = DN_CVT_U64ToByteSizeStr8(alloc_table->arena, size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 alloc_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, alloc->size); + DN_Str8 new_alloc_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, size); DN_HardAssertF( alloc->flags & DN_DebugAllocFlag_Freed, "This pointer is already in the leak tracker, however it has not been freed yet. This " @@ -10078,7 +10075,7 @@ DN_API void DN_Debug_TrackDealloc(void *ptr) DN_DebugAlloc *alloc = alloc_entry.value; if (alloc->flags & DN_DebugAllocFlag_Freed) { - DN_Str8 freed_size = DN_CVT_U64ToByteSizeStr8(alloc_table->arena, alloc->freed_size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 freed_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, alloc->freed_size); DN_HardAssertF((alloc->flags & DN_DebugAllocFlag_Freed) == 0, "Double free detected, pointer to free was already marked " "as freed. Either the pointer was reallocated but not " @@ -10120,7 +10117,7 @@ DN_API void DN_Debug_DumpLeaks() if (alloc_leaked && !leak_permitted) { leaked_bytes += alloc->size; leak_count++; - DN_Str8 alloc_size = DN_CVT_U64ToByteSizeStr8(g_dn_core->alloc_table.arena, alloc->size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 alloc_size = DN_CVT_U64ToBytesStr8Auto(g_dn_core->alloc_table.arena, alloc->size); DN_LOG_WarningF("Pointer (0x%p) leaked %.*s at:\n" "%.*s", alloc->ptr, DN_STR_FMT(alloc_size), @@ -10131,7 +10128,7 @@ DN_API void DN_Debug_DumpLeaks() if (leak_count) { char buffer[512]; DN_Arena arena = DN_Arena_InitFromBuffer(buffer, sizeof(buffer), DN_ArenaFlags_Nil); - DN_Str8 leak_size = DN_CVT_U64ToByteSizeStr8(&arena, leaked_bytes, DN_CVTU64ByteSizeType_Auto); + DN_Str8 leak_size = DN_CVT_U64ToBytesStr8Auto(&arena, leaked_bytes); DN_LOG_WarningF("There were %I64u leaked allocations totalling %.*s", leak_count, DN_STR_FMT(leak_size)); } } diff --git a/Single_Header/dn_single_header.h b/Single_Header/dn_single_header.h index abab87f..ce80274 100644 --- a/Single_Header/dn_single_header.h +++ b/Single_Header/dn_single_header.h @@ -1,4 +1,4 @@ -// Generated by the DN single header generator 2025-07-16 19:35:09 +// Generated by the DN single header generator 2025-07-20 15:12:51 #if !defined(DN_BASE_INC_H) #define DN_BASE_INC_H @@ -1195,11 +1195,11 @@ struct DN_Pool { DN_Arena *arena; DN_PoolSlot *slots[DN_PoolSlotSize_Count]; - uint8_t align; + DN_U8 align; }; // NOTE: DN_Pool /////////////////////////////////////////////////////////////////////////////////// -DN_API DN_Pool DN_Pool_Init (DN_Arena *arena, uint8_t align); +DN_API DN_Pool DN_Pool_Init (DN_Arena *arena, DN_U8 align); DN_API bool DN_Pool_IsValid (DN_Pool const *pool); DN_API void * DN_Pool_Alloc (DN_Pool *pool, DN_USize size); DN_API DN_Str8 DN_Pool_AllocStr8FV (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, va_list args); @@ -4133,81 +4133,90 @@ template DN_Slice DN_List_To #if !defined(DN_BASE_CONVERT_H) #define DN_BASE_CONVERT_H +// DN: Single header generator commented out this header => #include "../dn_base_inc.h" + struct DN_CVTU64Str8 { char data[27 + 1]; // NOTE(dn): 27 is the maximum size of DN_U64 including a separator DN_U8 size; }; -enum DN_CVTU64ByteSizeType +enum DN_CVTBytesType { - DN_CVTU64ByteSizeType_B, - DN_CVTU64ByteSizeType_KiB, - DN_CVTU64ByteSizeType_MiB, - DN_CVTU64ByteSizeType_GiB, - DN_CVTU64ByteSizeType_TiB, - DN_CVTU64ByteSizeType_Count, - DN_CVTU64ByteSizeType_Auto, + DN_CVTBytesType_B, + DN_CVTBytesType_KiB, + DN_CVTBytesType_MiB, + DN_CVTBytesType_GiB, + DN_CVTBytesType_TiB, + DN_CVTBytesType_Count, + DN_CVTBytesType_Auto, }; -struct DN_CVTU64ByteSize +struct DN_CVTU64Bytes { - DN_CVTU64ByteSizeType type; - DN_Str8 suffix; // "KiB", "MiB", "GiB" .. e.t.c - DN_F64 bytes; + DN_CVTBytesType type; + DN_Str8 suffix; // "KiB", "MiB", "GiB" .. e.t.c + DN_F64 bytes; }; -struct DN_CVTU64HexStr8 +struct DN_CVTU64HexStr { char data[2 /*0x*/ + 16 /*hex*/ + 1 /*null-terminator*/]; DN_U8 size; }; -typedef DN_U32 DN_CVTHexU64Str8Flags; -enum DN_CVTHexU64Str8Flags_ +typedef DN_U32 DN_CVTU64HexStrFlags; +enum DN_CVTU64HexStrFlags_ { - DN_CVTHexU64Str8Flags_Nil = 0, - DN_CVTHexU64Str8Flags_0xPrefix = 1 << 0, /// Add the '0x' prefix from the string - DN_CVTHexU64Str8Flags_UppercaseHex = 1 << 1, /// Use uppercase ascii characters for hex + DN_CVTU64HexStrFlags_Nil = 0, + DN_CVTU64HexStrFlags_0xPrefix = 1 << 0, /// Add the '0x' prefix from the string + DN_CVTU64HexStrFlags_UppercaseHex = 1 << 1, /// Use uppercase ascii characters for hex }; typedef DN_U32 DN_CVTU64AgeUnit; enum DN_CVTU64AgeUnit_ { - DN_CVTU64AgeUnit_Sec = 1 << 0, - DN_CVTU64AgeUnit_Min = 1 << 1, - DN_CVTU64AgeUnit_Hr = 1 << 2, - DN_CVTU64AgeUnit_Day = 1 << 3, - DN_CVTU64AgeUnit_Week = 1 << 4, - DN_CVTU64AgeUnit_Year = 1 << 5, - DN_CVTU64AgeUnit_HMS = DN_CVTU64AgeUnit_Sec | DN_CVTU64AgeUnit_Min | DN_CVTU64AgeUnit_Hr, - DN_CVTU64AgeUnit_All = DN_CVTU64AgeUnit_HMS | DN_CVTU64AgeUnit_Day | DN_CVTU64AgeUnit_Week | DN_CVTU64AgeUnit_Year, + DN_CVTU64AgeUnit_Sec = 1 << 0, + DN_CVTU64AgeUnit_Min = 1 << 1, + DN_CVTU64AgeUnit_Hr = 1 << 2, + DN_CVTU64AgeUnit_Day = 1 << 3, + DN_CVTU64AgeUnit_Week = 1 << 4, + DN_CVTU64AgeUnit_Year = 1 << 5, + DN_CVTU64AgeUnit_HMS = DN_CVTU64AgeUnit_Sec | DN_CVTU64AgeUnit_Min | DN_CVTU64AgeUnit_Hr, + DN_CVTU64AgeUnit_All = DN_CVTU64AgeUnit_HMS | DN_CVTU64AgeUnit_Day | DN_CVTU64AgeUnit_Week | DN_CVTU64AgeUnit_Year, }; -DN_API int DN_CVT_FmtBuffer3DotTruncate (char *buffer, int size, DN_FMT_ATTRIB char const *fmt, ...); -DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8 (DN_U64 val, char separator); -DN_API DN_CVTU64ByteSize DN_CVT_U64ToByteSize (DN_U64 bytes, DN_CVTU64ByteSizeType type); -DN_API DN_Str8 DN_CVT_U64ToByteSizeStr8 (DN_Arena *arena, DN_U64 bytes, DN_CVTU64ByteSizeType desired_type); -DN_API DN_Str8 DN_CVT_U64ByteSizeTypeString (DN_CVTU64ByteSizeType type); -DN_API DN_Str8 DN_CVT_U64ToAge (DN_Arena *arena, DN_U64 age_s, DN_CVTU64AgeUnit unit); -DN_API DN_Str8 DN_CVT_F64ToAge (DN_Arena *arena, DN_F64 age_s, DN_CVTU64AgeUnit unit); +DN_API int DN_CVT_FmtBuffer3DotTruncate (char *buffer, int size, DN_FMT_ATTRIB char const *fmt, ...); +DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8 (DN_U64 val, char separator); +DN_API DN_CVTU64Bytes DN_CVT_U64ToBytes (DN_U64 bytes, DN_CVTBytesType type); +#define DN_CVT_U64ToBytesAuto(bytes) DN_CVT_U64ToBytes(bytes, DN_CVTBytesType_Auto) +DN_API DN_Str8 DN_CVT_U64ToBytesStr8 (DN_Arena *arena, DN_U64 bytes, DN_CVTBytesType type); +#define DN_CVT_U64ToBytesStr8Auto(arena, bytes) DN_CVT_U64ToBytesStr8(arena, bytes, DN_CVTBytesType_Auto) +#define DN_CVT_U64ToBytesStr8FromTLS(bytes, type) DN_CVT_U64ToBytesStr8(DN_OS_TLSTopArena(), bytes, type) +#define DN_CVT_U64ToBytesStr8AutoFromTLS(bytes) DN_CVT_U64ToBytesStr8(DN_OS_TLSTopArena(), bytes, DN_CVTBytesType_Auto) +#define DN_CVT_U64ToBytesStr8FromFrame(bytes, type) DN_CVT_U64ToBytesStr8(DN_OS_TLSFrameArena(), bytes, type) +#define DN_CVT_U64ToBytesStr8AutoFromFrame(bytes) DN_CVT_U64ToBytesStr8(DN_OS_TLSFrameArena(), bytes, DN_CVTBytesType_Auto) +DN_API DN_Str8 DN_CVT_BytesTypeToStr8 (DN_CVTBytesType type); +DN_API DN_Str8 DN_CVT_U64ToAge (DN_Arena *arena, DN_U64 age_s, DN_CVTU64AgeUnit unit); +DN_API DN_Str8 DN_CVT_F64ToAge (DN_Arena *arena, DN_F64 age_s, DN_CVTU64AgeUnit unit); -DN_API DN_U64 DN_CVT_HexToU64 (DN_Str8 hex); -DN_API DN_Str8 DN_CVT_U64ToHex (DN_Arena *arena, DN_U64 number, DN_CVTHexU64Str8Flags flags); -DN_API DN_CVTU64HexStr8 DN_CVT_U64ToHexStr8 (DN_U64 number, DN_U32 flags); +DN_API DN_U64 DN_CVT_HexToU64 (DN_Str8 hex); +DN_API DN_Str8 DN_CVT_U64ToHex (DN_Arena *arena, DN_U64 number, DN_CVTU64HexStrFlags flags); +#define DN_CVT_U64ToHexFromFrame(number, flags) DN_CVT_U64ToHex(DN_OS_TLSFrameArena(), number, flags) +DN_API DN_CVTU64HexStr DN_CVT_U64ToHexStr (DN_U64 number, DN_CVTU64HexStrFlags flags); -DN_API bool DN_CVT_BytesToHexPtr (void const *src, DN_USize src_size, char *dest, DN_USize dest_size); -DN_API DN_Str8 DN_CVT_BytesToHex (DN_Arena *arena, void const *src, DN_USize size); -#define DN_CVT_BytesToHexFromTLS(...) DN_CVT_BytesToHex(DN_OS_TLSTopArena(), __VA_ARGS__) -#define DN_CVT_BytesToHexFromFrame(...) DN_CVT_BytesToHex(DN_OS_TLSFrameArena(), __VA_ARGS__) +DN_API bool DN_CVT_BytesToHexPtr (void const *src, DN_USize src_size, char *dest, DN_USize dest_size); +DN_API DN_Str8 DN_CVT_BytesToHex (DN_Arena *arena, void const *src, DN_USize size); +#define DN_CVT_BytesToHexFromTLS(...) DN_CVT_BytesToHex(DN_OS_TLSTopArena(), __VA_ARGS__) +#define DN_CVT_BytesToHexFromFrame(...) DN_CVT_BytesToHex(DN_OS_TLSFrameArena(), __VA_ARGS__) -DN_API DN_USize DN_CVT_HexToBytesPtrUnchecked (DN_Str8 hex, void *dest, DN_USize dest_size); -DN_API DN_USize DN_CVT_HexToBytesPtr (DN_Str8 hex, void *dest, DN_USize dest_size); -DN_API DN_Str8 DN_CVT_HexToBytesUnchecked (DN_Arena *arena, DN_Str8 hex); -#define DN_CVT_HexToBytesUncheckedFromTLS(...) DN_CVT_HexToBytesUnchecked(DN_OS_TLSTopArena(), __VA_ARGS__) -DN_API DN_Str8 DN_CVT_HexToBytes (DN_Arena *arena, DN_Str8 hex); -#define DN_CVT_HexToBytesFromFrame(...) DN_CVT_HexToBytes(DN_OS_TLSFrameArena(), __VA_ARGS__) -#define DN_CVT_HexToBytesFromTLS(...) DN_CVT_HexToBytes(DN_OS_TLSTopArena(), __VA_ARGS__) +DN_API DN_USize DN_CVT_HexToBytesPtrUnchecked (DN_Str8 hex, void *dest, DN_USize dest_size); +DN_API DN_USize DN_CVT_HexToBytesPtr (DN_Str8 hex, void *dest, DN_USize dest_size); +DN_API DN_Str8 DN_CVT_HexToBytesUnchecked (DN_Arena *arena, DN_Str8 hex); +#define DN_CVT_HexToBytesUncheckedFromTLS(...) DN_CVT_HexToBytesUnchecked(DN_OS_TLSTopArena(), __VA_ARGS__) +DN_API DN_Str8 DN_CVT_HexToBytes (DN_Arena *arena, DN_Str8 hex); +#define DN_CVT_HexToBytesFromFrame(...) DN_CVT_HexToBytes(DN_OS_TLSFrameArena(), __VA_ARGS__) +#define DN_CVT_HexToBytesFromTLS(...) DN_CVT_HexToBytes(DN_OS_TLSTopArena(), __VA_ARGS__) #endif // defined(DN_BASE_CONVERT_H) #endif // !defined(DN_BASE_INC_H) diff --git a/Source/Base/dn_base_containers.cpp b/Source/Base/dn_base_containers.cpp index ec4c7f1..935844b 100644 --- a/Source/Base/dn_base_containers.cpp +++ b/Source/Base/dn_base_containers.cpp @@ -737,9 +737,9 @@ DN_U32 DN_DSMap_Hash(DN_DSMap const *map, DN_DSMapKey key) DN_U32 len = 0; DN_U32 h = seed; switch (key.type) { - case DN_DSMapKeyType_BufferAsU64NoHash: /*FALLTHRU*/ - case DN_DSMapKeyType_U64NoHash: DN_InvalidCodePath; /*FALLTHRU*/ - case DN_DSMapKeyType_Invalid: break; + case DN_DSMapKeyType_BufferAsU64NoHash: /*FALLTHRU*/ + case DN_DSMapKeyType_U64NoHash: DN_InvalidCodePath; /*FALLTHRU*/ + case DN_DSMapKeyType_Invalid: break; case DN_DSMapKeyType_Buffer: key_ptr = DN_CAST(char const *) key.buffer_data; diff --git a/Source/Base/dn_base_convert.cpp b/Source/Base/dn_base_convert.cpp index 7e04583..ebec28d 100644 --- a/Source/Base/dn_base_convert.cpp +++ b/Source/Base/dn_base_convert.cpp @@ -14,7 +14,7 @@ DN_API int DN_CVT_FmtBuffer3DotTruncate(char *buffer, int size, DN_FMT_ATTRIB ch return result; } -DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8(uint64_t val, char separator) +DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8(DN_U64 val, char separator) { DN_CVTU64Str8 result = {}; if (val == 0) { @@ -47,44 +47,41 @@ DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8(uint64_t val, char separator) return result; } -DN_API DN_CVTU64ByteSize DN_CVT_U64ToByteSize(uint64_t bytes, DN_CVTU64ByteSizeType desired_type) +DN_API DN_CVTU64Bytes DN_CVT_U64ToBytes(DN_U64 bytes, DN_CVTBytesType type) { - DN_CVTU64ByteSize result = {}; + DN_Assert(type != DN_CVTBytesType_Count); + DN_CVTU64Bytes result = {}; result.bytes = DN_CAST(DN_F64) bytes; - if (!DN_Check(desired_type != DN_CVTU64ByteSizeType_Count)) { - result.suffix = DN_CVT_U64ByteSizeTypeString(result.type); - return result; - } - if (desired_type == DN_CVTU64ByteSizeType_Auto) - for (; result.type < DN_CVTU64ByteSizeType_Count && result.bytes >= 1024.0; result.type = DN_CAST(DN_CVTU64ByteSizeType)(DN_CAST(DN_USize) result.type + 1)) + if (type == DN_CVTBytesType_Auto) + for (; result.type < DN_CVTBytesType_Count && result.bytes >= 1024.0; result.type = DN_CAST(DN_CVTBytesType)(DN_CAST(DN_USize) result.type + 1)) result.bytes /= 1024.0; else - for (; result.type < desired_type; result.type = DN_CAST(DN_CVTU64ByteSizeType)(DN_CAST(DN_USize) result.type + 1)) + for (; result.type < type; result.type = DN_CAST(DN_CVTBytesType)(DN_CAST(DN_USize) result.type + 1)) result.bytes /= 1024.0; - result.suffix = DN_CVT_U64ByteSizeTypeString(result.type); + result.suffix = DN_CVT_BytesTypeToStr8(result.type); return result; } -DN_API DN_Str8 DN_CVT_U64ToByteSizeStr8(DN_Arena *arena, uint64_t bytes, DN_CVTU64ByteSizeType desired_type) +DN_API DN_Str8 DN_CVT_U64ToBytesStr8(DN_Arena *arena, DN_U64 bytes, DN_CVTBytesType desired_type) { - DN_CVTU64ByteSize byte_size = DN_CVT_U64ToByteSize(bytes, desired_type); - DN_Str8 result = DN_Str8_InitF(arena, "%.2f%.*s", byte_size.bytes, DN_STR_FMT(byte_size.suffix)); + DN_CVTU64Bytes byte_size = DN_CVT_U64ToBytes(bytes, desired_type); + DN_Str8 result = DN_Str8_InitF(arena, "%.2f%.*s", byte_size.bytes, DN_STR_FMT(byte_size.suffix)); return result; } -DN_API DN_Str8 DN_CVT_U64ByteSizeTypeString(DN_CVTU64ByteSizeType type) +DN_API DN_Str8 DN_CVT_BytesTypeToStr8(DN_CVTBytesType type) { DN_Str8 result = DN_STR8(""); switch (type) { - case DN_CVTU64ByteSizeType_B: result = DN_STR8("B"); break; - case DN_CVTU64ByteSizeType_KiB: result = DN_STR8("KiB"); break; - case DN_CVTU64ByteSizeType_MiB: result = DN_STR8("MiB"); break; - case DN_CVTU64ByteSizeType_GiB: result = DN_STR8("GiB"); break; - case DN_CVTU64ByteSizeType_TiB: result = DN_STR8("TiB"); break; - case DN_CVTU64ByteSizeType_Count: result = DN_STR8(""); break; - case DN_CVTU64ByteSizeType_Auto: result = DN_STR8(""); break; + case DN_CVTBytesType_B: result = DN_STR8("B"); break; + case DN_CVTBytesType_KiB: result = DN_STR8("KiB"); break; + case DN_CVTBytesType_MiB: result = DN_STR8("MiB"); break; + case DN_CVTBytesType_GiB: result = DN_STR8("GiB"); break; + case DN_CVTBytesType_TiB: result = DN_STR8("TiB"); break; + case DN_CVTBytesType_Count: result = DN_STR8(""); break; + case DN_CVTBytesType_Auto: result = DN_STR8(""); break; } return result; } @@ -205,14 +202,14 @@ DN_API DN_Str8 DN_CVT_F64ToAge(DN_Arena *arena, DN_F64 age_s, DN_CVTU64AgeUnit u return result; } -DN_API uint64_t DN_CVT_HexToU64(DN_Str8 hex) +DN_API DN_U64 DN_CVT_HexToU64(DN_Str8 hex) { DN_Str8 real_hex = DN_Str8_TrimPrefix(DN_Str8_TrimPrefix(hex, DN_STR8("0x")), DN_STR8("0X")); - DN_USize max_hex_size = sizeof(uint64_t) * 2 /*hex chars per byte*/; + DN_USize max_hex_size = sizeof(DN_U64) * 2 /*hex chars per byte*/; DN_Assert(real_hex.size <= max_hex_size); DN_USize size = DN_Min(max_hex_size, real_hex.size); - uint64_t result = 0; + DN_U64 result = 0; for (DN_USize index = 0; index < size; index++) { char ch = real_hex.data[index]; DN_CharHexToU8 val = DN_Char_HexToU8(ch); @@ -223,13 +220,13 @@ DN_API uint64_t DN_CVT_HexToU64(DN_Str8 hex) return result; } -DN_API DN_Str8 DN_CVT_U64ToHex(DN_Arena *arena, uint64_t number, uint32_t flags) +DN_API DN_Str8 DN_CVT_U64ToHex(DN_Arena *arena, DN_U64 number, uint32_t flags) { DN_Str8 prefix = {}; - if ((flags & DN_CVTHexU64Str8Flags_0xPrefix)) + if ((flags & DN_CVTU64HexStrFlags_0xPrefix)) prefix = DN_STR8("0x"); - char const *fmt = (flags & DN_CVTHexU64Str8Flags_UppercaseHex) ? "%I64X" : "%I64x"; + char const *fmt = (flags & DN_CVTU64HexStrFlags_UppercaseHex) ? "%I64X" : "%I64x"; DN_USize required_size = DN_CStr8_FSize(fmt, number) + prefix.size; DN_Str8 result = DN_Str8_Alloc(arena, required_size, DN_ZeroMem_No); @@ -241,17 +238,17 @@ DN_API DN_Str8 DN_CVT_U64ToHex(DN_Arena *arena, uint64_t number, uint32_t flags) return result; } -DN_API DN_CVTU64HexStr8 DN_CVT_U64ToHexStr8(uint64_t number, DN_CVTHexU64Str8Flags flags) +DN_API DN_CVTU64HexStr DN_CVT_U64ToHexStr8(DN_U64 number, DN_CVTU64HexStrFlags flags) { DN_Str8 prefix = {}; - if (flags & DN_CVTHexU64Str8Flags_0xPrefix) + if (flags & DN_CVTU64HexStrFlags_0xPrefix) prefix = DN_STR8("0x"); - DN_CVTU64HexStr8 result = {}; + DN_CVTU64HexStr result = {}; DN_Memcpy(result.data, prefix.data, prefix.size); result.size += DN_CAST(int8_t) prefix.size; - char const *fmt = (flags & DN_CVTHexU64Str8Flags_UppercaseHex) ? "%I64X" : "%I64x"; + char const *fmt = (flags & DN_CVTU64HexStrFlags_UppercaseHex) ? "%I64X" : "%I64x"; int size = DN_SNPrintF(result.data + result.size, DN_ArrayCountU(result.data) - result.size, fmt, number); result.size += DN_CAST(uint8_t) size; DN_Assert(result.size < DN_ArrayCountU(result.data)); diff --git a/Source/Base/dn_base_convert.h b/Source/Base/dn_base_convert.h index e2d6fef..e2503ac 100644 --- a/Source/Base/dn_base_convert.h +++ b/Source/Base/dn_base_convert.h @@ -1,79 +1,88 @@ #if !defined(DN_BASE_CONVERT_H) #define DN_BASE_CONVERT_H +#include "../dn_base_inc.h" + struct DN_CVTU64Str8 { char data[27 + 1]; // NOTE(dn): 27 is the maximum size of DN_U64 including a separator DN_U8 size; }; -enum DN_CVTU64ByteSizeType +enum DN_CVTBytesType { - DN_CVTU64ByteSizeType_B, - DN_CVTU64ByteSizeType_KiB, - DN_CVTU64ByteSizeType_MiB, - DN_CVTU64ByteSizeType_GiB, - DN_CVTU64ByteSizeType_TiB, - DN_CVTU64ByteSizeType_Count, - DN_CVTU64ByteSizeType_Auto, + DN_CVTBytesType_B, + DN_CVTBytesType_KiB, + DN_CVTBytesType_MiB, + DN_CVTBytesType_GiB, + DN_CVTBytesType_TiB, + DN_CVTBytesType_Count, + DN_CVTBytesType_Auto, }; -struct DN_CVTU64ByteSize +struct DN_CVTU64Bytes { - DN_CVTU64ByteSizeType type; - DN_Str8 suffix; // "KiB", "MiB", "GiB" .. e.t.c - DN_F64 bytes; + DN_CVTBytesType type; + DN_Str8 suffix; // "KiB", "MiB", "GiB" .. e.t.c + DN_F64 bytes; }; -struct DN_CVTU64HexStr8 +struct DN_CVTU64HexStr { char data[2 /*0x*/ + 16 /*hex*/ + 1 /*null-terminator*/]; DN_U8 size; }; -typedef DN_U32 DN_CVTHexU64Str8Flags; -enum DN_CVTHexU64Str8Flags_ +typedef DN_U32 DN_CVTU64HexStrFlags; +enum DN_CVTU64HexStrFlags_ { - DN_CVTHexU64Str8Flags_Nil = 0, - DN_CVTHexU64Str8Flags_0xPrefix = 1 << 0, /// Add the '0x' prefix from the string - DN_CVTHexU64Str8Flags_UppercaseHex = 1 << 1, /// Use uppercase ascii characters for hex + DN_CVTU64HexStrFlags_Nil = 0, + DN_CVTU64HexStrFlags_0xPrefix = 1 << 0, /// Add the '0x' prefix from the string + DN_CVTU64HexStrFlags_UppercaseHex = 1 << 1, /// Use uppercase ascii characters for hex }; typedef DN_U32 DN_CVTU64AgeUnit; enum DN_CVTU64AgeUnit_ { - DN_CVTU64AgeUnit_Sec = 1 << 0, - DN_CVTU64AgeUnit_Min = 1 << 1, - DN_CVTU64AgeUnit_Hr = 1 << 2, - DN_CVTU64AgeUnit_Day = 1 << 3, - DN_CVTU64AgeUnit_Week = 1 << 4, - DN_CVTU64AgeUnit_Year = 1 << 5, - DN_CVTU64AgeUnit_HMS = DN_CVTU64AgeUnit_Sec | DN_CVTU64AgeUnit_Min | DN_CVTU64AgeUnit_Hr, - DN_CVTU64AgeUnit_All = DN_CVTU64AgeUnit_HMS | DN_CVTU64AgeUnit_Day | DN_CVTU64AgeUnit_Week | DN_CVTU64AgeUnit_Year, + DN_CVTU64AgeUnit_Sec = 1 << 0, + DN_CVTU64AgeUnit_Min = 1 << 1, + DN_CVTU64AgeUnit_Hr = 1 << 2, + DN_CVTU64AgeUnit_Day = 1 << 3, + DN_CVTU64AgeUnit_Week = 1 << 4, + DN_CVTU64AgeUnit_Year = 1 << 5, + DN_CVTU64AgeUnit_HMS = DN_CVTU64AgeUnit_Sec | DN_CVTU64AgeUnit_Min | DN_CVTU64AgeUnit_Hr, + DN_CVTU64AgeUnit_All = DN_CVTU64AgeUnit_HMS | DN_CVTU64AgeUnit_Day | DN_CVTU64AgeUnit_Week | DN_CVTU64AgeUnit_Year, }; -DN_API int DN_CVT_FmtBuffer3DotTruncate (char *buffer, int size, DN_FMT_ATTRIB char const *fmt, ...); -DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8 (DN_U64 val, char separator); -DN_API DN_CVTU64ByteSize DN_CVT_U64ToByteSize (DN_U64 bytes, DN_CVTU64ByteSizeType type); -DN_API DN_Str8 DN_CVT_U64ToByteSizeStr8 (DN_Arena *arena, DN_U64 bytes, DN_CVTU64ByteSizeType desired_type); -DN_API DN_Str8 DN_CVT_U64ByteSizeTypeString (DN_CVTU64ByteSizeType type); -DN_API DN_Str8 DN_CVT_U64ToAge (DN_Arena *arena, DN_U64 age_s, DN_CVTU64AgeUnit unit); -DN_API DN_Str8 DN_CVT_F64ToAge (DN_Arena *arena, DN_F64 age_s, DN_CVTU64AgeUnit unit); +DN_API int DN_CVT_FmtBuffer3DotTruncate (char *buffer, int size, DN_FMT_ATTRIB char const *fmt, ...); +DN_API DN_CVTU64Str8 DN_CVT_U64ToStr8 (DN_U64 val, char separator); +DN_API DN_CVTU64Bytes DN_CVT_U64ToBytes (DN_U64 bytes, DN_CVTBytesType type); +#define DN_CVT_U64ToBytesAuto(bytes) DN_CVT_U64ToBytes(bytes, DN_CVTBytesType_Auto) +DN_API DN_Str8 DN_CVT_U64ToBytesStr8 (DN_Arena *arena, DN_U64 bytes, DN_CVTBytesType type); +#define DN_CVT_U64ToBytesStr8Auto(arena, bytes) DN_CVT_U64ToBytesStr8(arena, bytes, DN_CVTBytesType_Auto) +#define DN_CVT_U64ToBytesStr8FromTLS(bytes, type) DN_CVT_U64ToBytesStr8(DN_OS_TLSTopArena(), bytes, type) +#define DN_CVT_U64ToBytesStr8AutoFromTLS(bytes) DN_CVT_U64ToBytesStr8(DN_OS_TLSTopArena(), bytes, DN_CVTBytesType_Auto) +#define DN_CVT_U64ToBytesStr8FromFrame(bytes, type) DN_CVT_U64ToBytesStr8(DN_OS_TLSFrameArena(), bytes, type) +#define DN_CVT_U64ToBytesStr8AutoFromFrame(bytes) DN_CVT_U64ToBytesStr8(DN_OS_TLSFrameArena(), bytes, DN_CVTBytesType_Auto) +DN_API DN_Str8 DN_CVT_BytesTypeToStr8 (DN_CVTBytesType type); +DN_API DN_Str8 DN_CVT_U64ToAge (DN_Arena *arena, DN_U64 age_s, DN_CVTU64AgeUnit unit); +DN_API DN_Str8 DN_CVT_F64ToAge (DN_Arena *arena, DN_F64 age_s, DN_CVTU64AgeUnit unit); -DN_API DN_U64 DN_CVT_HexToU64 (DN_Str8 hex); -DN_API DN_Str8 DN_CVT_U64ToHex (DN_Arena *arena, DN_U64 number, DN_CVTHexU64Str8Flags flags); -DN_API DN_CVTU64HexStr8 DN_CVT_U64ToHexStr8 (DN_U64 number, DN_U32 flags); +DN_API DN_U64 DN_CVT_HexToU64 (DN_Str8 hex); +DN_API DN_Str8 DN_CVT_U64ToHex (DN_Arena *arena, DN_U64 number, DN_CVTU64HexStrFlags flags); +#define DN_CVT_U64ToHexFromFrame(number, flags) DN_CVT_U64ToHex(DN_OS_TLSFrameArena(), number, flags) +DN_API DN_CVTU64HexStr DN_CVT_U64ToHexStr (DN_U64 number, DN_CVTU64HexStrFlags flags); -DN_API bool DN_CVT_BytesToHexPtr (void const *src, DN_USize src_size, char *dest, DN_USize dest_size); -DN_API DN_Str8 DN_CVT_BytesToHex (DN_Arena *arena, void const *src, DN_USize size); -#define DN_CVT_BytesToHexFromTLS(...) DN_CVT_BytesToHex(DN_OS_TLSTopArena(), __VA_ARGS__) -#define DN_CVT_BytesToHexFromFrame(...) DN_CVT_BytesToHex(DN_OS_TLSFrameArena(), __VA_ARGS__) +DN_API bool DN_CVT_BytesToHexPtr (void const *src, DN_USize src_size, char *dest, DN_USize dest_size); +DN_API DN_Str8 DN_CVT_BytesToHex (DN_Arena *arena, void const *src, DN_USize size); +#define DN_CVT_BytesToHexFromTLS(...) DN_CVT_BytesToHex(DN_OS_TLSTopArena(), __VA_ARGS__) +#define DN_CVT_BytesToHexFromFrame(...) DN_CVT_BytesToHex(DN_OS_TLSFrameArena(), __VA_ARGS__) -DN_API DN_USize DN_CVT_HexToBytesPtrUnchecked (DN_Str8 hex, void *dest, DN_USize dest_size); -DN_API DN_USize DN_CVT_HexToBytesPtr (DN_Str8 hex, void *dest, DN_USize dest_size); -DN_API DN_Str8 DN_CVT_HexToBytesUnchecked (DN_Arena *arena, DN_Str8 hex); -#define DN_CVT_HexToBytesUncheckedFromTLS(...) DN_CVT_HexToBytesUnchecked(DN_OS_TLSTopArena(), __VA_ARGS__) -DN_API DN_Str8 DN_CVT_HexToBytes (DN_Arena *arena, DN_Str8 hex); -#define DN_CVT_HexToBytesFromFrame(...) DN_CVT_HexToBytes(DN_OS_TLSFrameArena(), __VA_ARGS__) -#define DN_CVT_HexToBytesFromTLS(...) DN_CVT_HexToBytes(DN_OS_TLSTopArena(), __VA_ARGS__) +DN_API DN_USize DN_CVT_HexToBytesPtrUnchecked (DN_Str8 hex, void *dest, DN_USize dest_size); +DN_API DN_USize DN_CVT_HexToBytesPtr (DN_Str8 hex, void *dest, DN_USize dest_size); +DN_API DN_Str8 DN_CVT_HexToBytesUnchecked (DN_Arena *arena, DN_Str8 hex); +#define DN_CVT_HexToBytesUncheckedFromTLS(...) DN_CVT_HexToBytesUnchecked(DN_OS_TLSTopArena(), __VA_ARGS__) +DN_API DN_Str8 DN_CVT_HexToBytes (DN_Arena *arena, DN_Str8 hex); +#define DN_CVT_HexToBytesFromFrame(...) DN_CVT_HexToBytes(DN_OS_TLSFrameArena(), __VA_ARGS__) +#define DN_CVT_HexToBytesFromTLS(...) DN_CVT_HexToBytes(DN_OS_TLSTopArena(), __VA_ARGS__) #endif // defined(DN_BASE_CONVERT_H) diff --git a/Source/Base/dn_base_mem.h b/Source/Base/dn_base_mem.h index b9104f8..4e28e81 100644 --- a/Source/Base/dn_base_mem.h +++ b/Source/Base/dn_base_mem.h @@ -222,11 +222,11 @@ struct DN_Pool { DN_Arena *arena; DN_PoolSlot *slots[DN_PoolSlotSize_Count]; - uint8_t align; + DN_U8 align; }; // NOTE: DN_Pool /////////////////////////////////////////////////////////////////////////////////// -DN_API DN_Pool DN_Pool_Init (DN_Arena *arena, uint8_t align); +DN_API DN_Pool DN_Pool_Init (DN_Arena *arena, DN_U8 align); DN_API bool DN_Pool_IsValid (DN_Pool const *pool); DN_API void * DN_Pool_Alloc (DN_Pool *pool, DN_USize size); DN_API DN_Str8 DN_Pool_AllocStr8FV (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, va_list args); diff --git a/Source/Core/dn_core_debug.cpp b/Source/Core/dn_core_debug.cpp index 6f447eb..9ec93ca 100644 --- a/Source/Core/dn_core_debug.cpp +++ b/Source/Core/dn_core_debug.cpp @@ -229,8 +229,8 @@ DN_API void DN_Debug_TrackAlloc(void *ptr, DN_USize size, bool leak_permitted) DN_DebugAlloc *alloc = alloc_entry.value; if (alloc_entry.found) { if ((alloc->flags & DN_DebugAllocFlag_Freed) == 0) { - DN_Str8 alloc_size = DN_CVT_U64ToByteSizeStr8(alloc_table->arena, alloc->size, DN_CVTU64ByteSizeType_Auto); - DN_Str8 new_alloc_size = DN_CVT_U64ToByteSizeStr8(alloc_table->arena, size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 alloc_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, alloc->size); + DN_Str8 new_alloc_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, size); DN_HardAssertF( alloc->flags & DN_DebugAllocFlag_Freed, "This pointer is already in the leak tracker, however it has not been freed yet. This " @@ -287,7 +287,7 @@ DN_API void DN_Debug_TrackDealloc(void *ptr) DN_DebugAlloc *alloc = alloc_entry.value; if (alloc->flags & DN_DebugAllocFlag_Freed) { - DN_Str8 freed_size = DN_CVT_U64ToByteSizeStr8(alloc_table->arena, alloc->freed_size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 freed_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, alloc->freed_size); DN_HardAssertF((alloc->flags & DN_DebugAllocFlag_Freed) == 0, "Double free detected, pointer to free was already marked " "as freed. Either the pointer was reallocated but not " @@ -329,7 +329,7 @@ DN_API void DN_Debug_DumpLeaks() if (alloc_leaked && !leak_permitted) { leaked_bytes += alloc->size; leak_count++; - DN_Str8 alloc_size = DN_CVT_U64ToByteSizeStr8(g_dn_core->alloc_table.arena, alloc->size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 alloc_size = DN_CVT_U64ToBytesStr8Auto(g_dn_core->alloc_table.arena, alloc->size); DN_LOG_WarningF("Pointer (0x%p) leaked %.*s at:\n" "%.*s", alloc->ptr, DN_STR_FMT(alloc_size), @@ -340,7 +340,7 @@ DN_API void DN_Debug_DumpLeaks() if (leak_count) { char buffer[512]; DN_Arena arena = DN_Arena_InitFromBuffer(buffer, sizeof(buffer), DN_ArenaFlags_Nil); - DN_Str8 leak_size = DN_CVT_U64ToByteSizeStr8(&arena, leaked_bytes, DN_CVTU64ByteSizeType_Auto); + DN_Str8 leak_size = DN_CVT_U64ToBytesStr8Auto(&arena, leaked_bytes); DN_LOG_WarningF("There were %I64u leaked allocations totalling %.*s", leak_count, DN_STR_FMT(leak_size)); } } diff --git a/Source/OS/dn_os.cpp b/Source/OS/dn_os.cpp index 7b00fd6..b9188c7 100644 --- a/Source/OS/dn_os.cpp +++ b/Source/OS/dn_os.cpp @@ -463,7 +463,7 @@ DN_API DN_Str8 DN_OS_ReadAll(DN_Arena *arena, DN_Str8 path, DN_OSErrSink *error) result = DN_Str8_Alloc(arena, path_info.size, DN_ZeroMem_No); if (!DN_Str8_HasData(result)) { DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); - DN_Str8 buffer_size_str8 = DN_CVT_U64ToByteSizeStr8(tmem.arena, path_info.size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 buffer_size_str8 = DN_CVT_U64ToBytesStr8AutoFromTLS(path_info.size); DN_OS_ErrSinkAppendF(error, 1 /*error_code*/, "Failed to allocate %.*s for reading file '%.*s'", DN_STR_FMT(buffer_size_str8), DN_STR_FMT(path)); DN_Arena_TempMemEnd(temp_mem); result = {}; diff --git a/Source/OS/dn_os_w32.cpp b/Source/OS/dn_os_w32.cpp index aab8058..ecba495 100644 --- a/Source/OS/dn_os_w32.cpp +++ b/Source/OS/dn_os_w32.cpp @@ -604,7 +604,7 @@ DN_API DN_OSFileRead DN_OS_FileRead(DN_OSFile *file, void *buffer, DN_USize size DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); if (!DN_Check(size <= (unsigned long)-1)) { - DN_Str8 buffer_size_str8 = DN_CVT_U64ToByteSizeStr8(tmem.arena, size, DN_CVTU64ByteSizeType_Auto); + DN_Str8 buffer_size_str8 = DN_CVT_U64ToBytesStr8AutoFromTLS(size); DN_OS_ErrSinkAppendF( err, 1 /*error_code*/, @@ -658,9 +658,9 @@ DN_API bool DN_OS_FileWritePtr(DN_OSFile *file, void const *buffer, DN_USize siz } if (!result) { - DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); - DN_W32Error win_error = DN_W32_LastError(tmem.arena); - DN_Str8 buffer_size_str8 = DN_CVT_U64ToByteSizeStr8(tmem.arena, size, DN_CVTU64ByteSizeType_Auto); + DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr); + DN_W32Error win_error = DN_W32_LastError(tmem.arena); + DN_Str8 buffer_size_str8 = DN_CVT_U64ToBytesStr8AutoFromTLS(size); DN_OS_ErrSinkAppendF(err, win_error.code, "Failed to write buffer (%.*s) to file handle: %.*s", DN_STR_FMT(buffer_size_str8), DN_STR_FMT(win_error.msg)); } return result;