Various naming scheme updates

This commit is contained in:
2025-09-03 22:49:29 +10:00
parent af77df23f5
commit 338be96138
35 changed files with 1193 additions and 1723 deletions
+2 -2
View File
@@ -13,13 +13,13 @@ DN_API void DN_Core_Init(DN_Core *core, DN_CoreOnInit on_init)
#if defined(DN_LEAK_TRACKING)
// NOTE: Setup the allocation table with allocation tracking turned off on
// the arena we're using to initialise the table.
core->alloc_table_arena = DN_Arena_InitFromOSVMem(DN_Megabytes(1), DN_Kilobytes(512), DN_ArenaFlags_NoAllocTrack | DN_ArenaFlags_AllocCanLeak);
core->alloc_table_arena = DN_Arena_FromVMem(DN_Megabytes(1), DN_Kilobytes(512), DN_ArenaFlags_NoAllocTrack | DN_ArenaFlags_AllocCanLeak);
core->alloc_table = DN_DSMap_Init<DN_DebugAlloc>(&core->alloc_table_arena, 4096, DN_DSMapFlags_Nil);
#endif
// NOTE: Print out init features ///////////////////////////////////////////////////////////////
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
DN_Str8Builder builder = DN_Str8Builder_Init(tmem.arena);
DN_Str8Builder builder = DN_Str8Builder_FromArena(tmem.arena);
if (on_init & DN_CoreOnInit_LogLibFeatures) {
DN_Str8Builder_AppendRef(&builder, DN_STR8("DN initialised:\n"));
+9 -9
View File
@@ -100,7 +100,7 @@ DN_API DN_Str8 DN_StackTrace_WalkResultToStr8(DN_Arena *arena, DN_StackTraceWalk
return result;
DN_OSTLSTMem tmem = DN_OS_TLSTMem(arena);
DN_Str8Builder builder = DN_Str8Builder_Init(tmem.arena);
DN_Str8Builder builder = DN_Str8Builder_FromArena(tmem.arena);
DN_StackTrace_AddWalkToStr8Builder_(walk, &builder, skip);
result = DN_Str8Builder_Build(&builder, arena);
return result;
@@ -118,8 +118,8 @@ DN_API DN_Str8 DN_StackTrace_WalkStr8FromHeap(uint16_t limit, uint16_t skip)
{
// NOTE: We don't use WalkResultToStr8 because that uses the TLS arenas which
// does not use the OS heap.
DN_Arena arena = DN_Arena_InitFromOSHeap(DN_Kilobytes(64), DN_ArenaFlags_NoAllocTrack);
DN_Str8Builder builder = DN_Str8Builder_Init(&arena);
DN_Arena arena = DN_Arena_FromHeap(DN_Kilobytes(64), DN_ArenaFlags_NoAllocTrack);
DN_Str8Builder builder = DN_Str8Builder_FromArena(&arena);
DN_StackTraceWalkResult walk = DN_StackTrace_Walk(&arena, limit);
DN_StackTrace_AddWalkToStr8Builder_(&walk, &builder, skip);
DN_Str8 result = DN_Str8Builder_BuildFromOSHeap(&builder);
@@ -232,8 +232,8 @@ DN_API void DN_DBGTrackAlloc(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_U64ToBytesStr8Auto(alloc_table->arena, alloc->size);
DN_Str8 new_alloc_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, size);
DN_Str8 alloc_size = DN_CVT_BytesStr8FromU64Auto(alloc_table->arena, alloc->size);
DN_Str8 new_alloc_size = DN_CVT_BytesStr8FromU64Auto(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 "
@@ -290,7 +290,7 @@ DN_API void DN_DBGTrackDealloc(void *ptr)
DN_DebugAlloc *alloc = alloc_entry.value;
if (alloc->flags & DN_DebugAllocFlag_Freed) {
DN_Str8 freed_size = DN_CVT_U64ToBytesStr8Auto(alloc_table->arena, alloc->freed_size);
DN_Str8 freed_size = DN_CVT_BytesStr8FromU64Auto(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 "
@@ -332,7 +332,7 @@ DN_API void DN_DBGDumpLeaks()
if (alloc_leaked && !leak_permitted) {
leaked_bytes += alloc->size;
leak_count++;
DN_Str8 alloc_size = DN_CVT_U64ToBytesStr8Auto(g_dn_core->alloc_table.arena, alloc->size);
DN_Str8 alloc_size = DN_CVT_BytesStr8FromU64Auto(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),
@@ -342,8 +342,8 @@ DN_API void DN_DBGDumpLeaks()
if (leak_count) {
char buffer[512];
DN_Arena arena = DN_Arena_InitFromBuffer(buffer, sizeof(buffer), DN_ArenaFlags_Nil);
DN_Str8 leak_size = DN_CVT_U64ToBytesStr8Auto(&arena, leaked_bytes);
DN_Arena arena = DN_Arena_FromBuffer(buffer, sizeof(buffer), DN_ArenaFlags_Nil);
DN_Str8 leak_size = DN_CVT_BytesStr8FromU64Auto(&arena, leaked_bytes);
DN_LOG_WarningF("There were %I64u leaked allocations totalling %.*s", leak_count, DN_STR_FMT(leak_size));
}
}
+13 -24
View File
@@ -54,11 +54,11 @@ void DN_Docs_Demo()
}
}
// NOTE: DN_CVT_BytesToHex ////////////////////////////////////////////////////////////////////////
// NOTE: DN_CVT_HexFromBytes ////////////////////////////////////////////////////////////////////////
{
DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr);
unsigned char bytes[2] = {0xFA, 0xCE};
DN_Str8 hex = DN_CVT_BytesToHex(tmem.arena, bytes, sizeof(bytes));
DN_Str8 hex = DN_CVT_HexFromBytes(tmem.arena, bytes, sizeof(bytes));
DN_Assert(hex == DN_STR8("face")); // NOTE: Guaranteed to be null-terminated
}
@@ -154,7 +154,7 @@ void DN_Docs_Demo()
//
// A 'Deinit' of the map will similarly deallocate the passed in arena (as
// the map takes ownership of the arena).
DN_Arena arena = DN_Arena_InitFromOSVMem(0, 0, DN_ArenaFlags_Nil);
DN_Arena arena = DN_Arena_FromVMem(0, 0, DN_ArenaFlags_Nil);
DN_DSMap<int> map = DN_DSMap_Init<int>(&arena, /*size*/ 1024, DN_DSMapFlags_Nil); // Size must be PoT!
DN_Assert(DN_DSMap_IsValid(&map)); // Valid if no initialisation failure (e.g. mem alloc failure)
@@ -331,21 +331,10 @@ void DN_Docs_Demo()
}
}
// NOTE: DN_FStr8_Max /////////////////////////////////////////////////////////////////////////
//
// Return the maximum capacity of the string, e.g. the 'N' template
// parameter of FStr8<N>
// NOTE: DN_FStr8_ToStr8 //////////////////////////////////////////////////////////////////////
//
// Create a slice of the string into a pointer and length string (DN_Str8).
// The lifetime of the slice is bound to the lifetime of the FStr8 and is
// invalidated when the FStr8 is.
// NOTE: DN_CVT_HexToBytes ////////////////////////////////////////////////////////////////////////
// NOTE: DN_CVT_BytesFromHex ////////////////////////////////////////////////////////////////////////
{
unsigned char bytes[2];
DN_USize bytes_written = DN_CVT_HexToBytesPtr(DN_STR8("0xFACE"), bytes, sizeof(bytes));
DN_USize bytes_written = DN_CVT_BytesFromHexPtr(DN_STR8("0xFACE"), bytes, sizeof(bytes));
DN_Assert(bytes_written == 2);
DN_Assert(bytes[0] == 0xFA);
DN_Assert(bytes[1] == 0xCE);
@@ -776,21 +765,21 @@ void DN_Docs_Demo()
DN_Assert(string.data[string.size] == 0); // It is null-terminated!
}
// NOTE: DN_Str8_BinarySplit //////////////////////////////////////////////////////////////////
// NOTE: DN_Str8_BSplit //////////////////////////////////////////////////////////////////
//
// Splits a string into 2 substrings occuring prior and after the first
// occurence of the delimiter. Neither strings include the matched
// delimiter. If no delimiter is found, the 'rhs' of the split will be
// empty.
{
DN_Str8BinarySplitResult dot_split = DN_Str8_BinarySplit(/*string*/ DN_STR8("abc.def.ghi"), /*delimiter*/ DN_STR8("."));
DN_Str8BinarySplitResult slash_split = DN_Str8_BinarySplit(/*string*/ DN_STR8("abc.def.ghi"), /*delimiter*/ DN_STR8("/"));
DN_Str8BSplitResult dot_split = DN_Str8_BSplit(/*string*/ DN_STR8("abc.def.ghi"), /*delimiter*/ DN_STR8("."));
DN_Str8BSplitResult slash_split = DN_Str8_BSplit(/*string*/ DN_STR8("abc.def.ghi"), /*delimiter*/ DN_STR8("/"));
DN_Assert(dot_split.lhs == DN_STR8("abc") && dot_split.rhs == DN_STR8("def.ghi"));
DN_Assert(slash_split.lhs == DN_STR8("abc.def.ghi") && slash_split.rhs == DN_STR8(""));
// Loop that walks the string and produces ("abc", "def", "ghi")
for (DN_Str8 it = DN_STR8("abc.def.ghi"); it.size;) {
DN_Str8BinarySplitResult split = DN_Str8_BinarySplit(it, DN_STR8("."));
DN_Str8BSplitResult split = DN_Str8_BSplit(it, DN_STR8("."));
DN_Str8 chunk = split.lhs; // "abc", "def", ...
it = split.rhs;
(void)chunk;
@@ -1052,17 +1041,17 @@ void DN_Docs_Demo()
// @param[in] conflict_arena A pointer to the arena currently being used in the
// function
// NOTE: DN_CVT_U64ToStr8 /////////////////////////////////////////////////////////////////////////
// NOTE: DN_CVT_Str8FromU64 /////////////////////////////////////////////////////////////////////////
{
DN_CVTU64Str8 string = DN_CVT_U64ToStr8(123123, ',');
DN_CVTU64Str8 string = DN_CVT_Str8FromU64(123123, ',');
if (0) // Prints "123,123"
printf("%.*s", DN_STR_FMT(string));
}
// NOTE: DN_CVT_U64ToAge //////////////////////////////////////////////////////////////////////////
// NOTE: DN_CVT_AgeFromU64 //////////////////////////////////////////////////////////////////////////
{
DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr);
DN_Str8 string = DN_CVT_U64ToAge(tmem.arena, DN_HoursToSec(2) + DN_MinutesToSec(30), DN_CVTU64AgeUnit_All);
DN_Str8 string = DN_CVT_AgeFromU64(tmem.arena, DN_HoursToSec(2) + DN_MinutesToSec(30), DN_CVTU64AgeUnit_All);
DN_Assert(DN_Str8_Eq(string, DN_STR8("2h 30m")));
}