Update to latest DN library

This commit is contained in:
2026-06-18 16:41:12 +10:00
parent cbf7416220
commit 2659f0316f
17 changed files with 602 additions and 140 deletions
+92 -37
View File
@@ -1,4 +1,4 @@
// Generated by the DN single header generator 2026-06-01 21:40:06
// Generated by the DN single header generator 2026-06-18 16:40:52
// DN: Single header generator commented out => #if defined(_CLANGD)
// #define DN_H_WITH_OS 1
@@ -4368,10 +4368,11 @@ DN_API DN_U8x32 DN_BytesFromHex64Ptr(char const *hex, DN_USize hex_count)
return result;
}
DN_API DN_HexU64Str8 DN_HexFromU64(DN_U64 value, DN_HexFromU64Type type)
DN_API DN_HexU64 DN_HexFromU64(DN_U64 value, DN_HexFromU64Type type)
{
DN_HexU64Str8 result = {};
DN_HexFromPtrBytes(&value, sizeof(value), result.data, sizeof(result.data), DN_TrimLeadingZero_No);
DN_HexU64 result = {};
DN_USize size = DN_HexFromPtrBytes(&value, sizeof(value), result.data, sizeof(result.data), DN_TrimLeadingZero_No);
result.size = DN_SaturateCastUSizeToU8(size);
if (type == DN_HexFromU64Type_Uppercase) {
for (DN_USize index = 0; index < result.size; index++)
result.data[index] = DN_CharToUpper(result.data[index]);
@@ -5544,7 +5545,8 @@ DN_API void DN_LogPrint(DN_LogTypeParam type, DN_CallSite call_site, DN_LogFlags
{
DN_Core *dn = DN_Get();
if (type.is_u32_enum) {
if (type.u32 < dn->log_level_to_show_from)
DN_Assert(dn->log_level_to_show_from >= 0);
if (type.u32 < DN_Cast(DN_U32)dn->log_level_to_show_from)
return;
}
@@ -7429,6 +7431,7 @@ DN_API void *DN_ArrayPopBack(void *data, DN_USize *size, DN_USize elem_size, DN_
DN_API DN_ArrayEraseResult DN_ArrayEraseRange(void *data, DN_USize *size, DN_USize elem_size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase)
{
DN_ArrayEraseResult result = {};
result.it_index = begin_index;
if (!data || !size || *size == 0 || count == 0)
return result;
@@ -7485,6 +7488,13 @@ DN_API void *DN_ArrayMakeArray(void *data, DN_USize *size, DN_USize max, DN_USiz
return result;
}
DN_API void *DN_ArrayMakeArrayAssert(void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site)
{
void *result = DN_ArrayMakeArray(data, size, max, elem_size, make_count, z_mem);
DN_AssertArgsF(result, call_site, "array=%p size=%zu max=%zu", data, *size, max);
return result;
}
DN_API void *DN_ArrayAddArray(void *data, DN_USize *size, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add)
{
void *result = DN_ArrayMakeArray(data, size, max, elem_size, elems_count, DN_ZMem_No);
@@ -7501,6 +7511,13 @@ DN_API void *DN_ArrayAddArray(void *data, DN_USize *size, DN_USize max, DN_USize
return result;
}
DN_API void *DN_ArrayAddArrayAssert(void *data, DN_USize *size, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site)
{
void *result = DN_ArrayAddArray(data, size, max, elem_size, elems, elems_count, add);
DN_AssertArgsF(result, call_site, "array=%p size=%zu max=%zu", data, *size, max);
return result;
}
DN_API bool DN_ArrayResizeFromArena(void **data, DN_USize *size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max)
{
bool result = true;
@@ -9000,8 +9017,8 @@ DN_API DN_OSExecResult DN_OS_ExecOrAbort(DN_Str8Slice cmd_line, DN_OSExecArgs *a
// NOTE: DN_OSThread
static void DN_OS_ThreadExecute_(void *user_context)
{
DN_OSThread *thread = DN_Cast(DN_OSThread *) user_context;
DN_TCInitFromMemFuncs(&thread->context, thread->thread_id, DN_TCInitArgsDefault(), DN_MemFuncsDefault());
DN_OSThread *thread = DN_Cast(DN_OSThread *) user_context;
DN_TCInitFromMemFuncs(&thread->context, thread->thread_id, thread->tc_init_args, DN_MemFuncsDefault());
DN_TCEquip(&thread->context);
if (thread->is_lane_set) {
DN_OS_TCThreadLaneEquip(thread->lane);
@@ -9063,7 +9080,7 @@ DN_API void DN_OS_ThreadLaneSync(DN_OSThreadLane *lane, void **ptr_to_share)
DN_OS_BarrierWait(&lane->barrier); // NOTE: Ensure the reading lanes have completed the read
}
DN_API DN_V2USize DN_OS_ThreadLaneRange(DN_OSThreadLane *lane, DN_USize values_count)
DN_API DN_V2USize DN_OS_ThreadLaneRange(DN_OSThreadLane const *lane, DN_USize values_count)
{
DN_USize values_per_thread = values_count / lane->count;
DN_USize rem_values = values_count % lane->count;
@@ -9084,6 +9101,44 @@ DN_API DN_V2USize DN_OS_ThreadLaneRange(DN_OSThreadLane *lane, DN_USize values_c
return result;
}
DN_API DN_OSThreadLaneway DN_OS_ThreadLanewayFromArgs(DN_OSThread* threads, DN_USize threads_count, DN_UPtr* shared_mem)
{
DN_OSThreadLaneway result = {};
result.threads = threads;
result.threads_count = threads_count;
result.shared_mem = shared_mem;
result.barrier = DN_OS_BarrierInit(DN_Cast(DN_U32) result.threads_count);
return result;
}
DN_API DN_OSThreadLaneway DN_OS_ThreadLanewayFromArena(DN_USize threads_count, DN_Arena* arena)
{
DN_U64 mem_p = DN_MemListPos(arena->mem);
DN_OSThreadLaneway result = {};
DN_OSThread* threads = DN_ArenaNewArray(arena, DN_OSThread, threads_count, DN_ZMem_No);
DN_UPtr* shared_mem = DN_ArenaNewZ(arena, DN_UPtr);
if (threads && shared_mem)
result = DN_OS_ThreadLanewayFromArgs(threads, threads_count, shared_mem);
else
DN_MemListPopTo(arena->mem, mem_p);
return result;
}
DN_API void DN_OS_ThreadLanewayDispatch(DN_OSThreadLaneway *laneway, DN_OSThreadFunc *entry_point, DN_TCInitArgs tc_init_args, void *user_context)
{
for (DN_ForItSize(it, DN_OSThread, laneway->threads, laneway->threads_count)) {
DN_OSThreadLane lane = DN_OS_ThreadLaneInit(it.index, laneway->threads_count, laneway->barrier, laneway->shared_mem);
DN_OS_ThreadInit(it.data, entry_point, &lane, tc_init_args, user_context);
}
}
DN_API void DN_OS_ThreadLanewayJoin(DN_OSThreadLaneway *laneway, DN_TCDeinitArenas deinit_arenas)
{
for (DN_ForItSize(it, DN_OSThread, laneway->threads, laneway->threads_count))
DN_OS_ThreadJoin(it.data, deinit_arenas);
DN_OS_BarrierDeinit(&laneway->barrier);
}
DN_API DN_OSThreadLane *DN_OS_TCThreadLane()
{
DN_TCCore *tc = DN_TCGet();
@@ -9531,7 +9586,7 @@ DN_API DN_StackTrace DN_StackTraceFromAllocator(DN_Allocator allocator, DN_U16 l
DN_Memcpy(result.base_addr, raw_frames, raw_frames_count * sizeof(raw_frames[0]));
#else
(void)limit;
(void)arena;
(void)allocator;
#endif
return result;
}
@@ -9940,7 +9995,7 @@ DN_API bool DN_OS_SetEnvVar(DN_Str8 name, DN_Str8 value)
DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
{
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
DN_OSDiskSpace result = {};
DN_Str8 path_z_terminated = DN_Str8FromStr8Arena(path, &scratch.arena);
struct statvfs info = {};
@@ -10099,7 +10154,7 @@ DN_API bool DN_OS_FileCopy(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink
result = (bytes_written == stat_existing.st_size);
if (!result) {
int error_code = errno;
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
DN_Str8 file_size_str8 = DN_Str8FromByteCount(scratch.arena, stat_existing.st_size, DN_ByteCountType_Auto);
DN_Str8 bytes_written_str8 = DN_Str8FromByteCount(scratch.arena, bytes_written, DN_ByteCountType_Auto);
DN_rrSinkAppendF(error,
@@ -10229,8 +10284,8 @@ DN_API DN_OSFileRead DN_OS_FileRead(DN_OSFile *file, void *buffer, DN_USize size
result.bytes_read = fread(buffer, 1, size, DN_Cast(FILE *) file->handle);
if (feof(DN_Cast(FILE*)file->handle)) {
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_Str8x32 buffer_size_str8 = DN_ByteCountStr8x32(size);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
DN_Str8x32 buffer_size_str8 = DN_Str8x32FromByteCountU64Auto(size);
DN_ErrSinkAppendF(err, 1, "Failed to read %S from file", buffer_size_str8);
DN_TCScratchEnd(&scratch);
return result;
@@ -10248,8 +10303,8 @@ DN_API bool DN_OS_FileWritePtr(DN_OSFile *file, void const *buffer, DN_USize siz
fwrite(buffer, DN_Cast(DN_USize) size, 1 /*count*/, DN_Cast(FILE *) file->handle) ==
1 /*count*/;
if (!result) {
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_Str8x32 buffer_size_str8 = DN_ByteCountStr8x32(size);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
DN_Str8x32 buffer_size_str8 = DN_Str8x32FromByteCountU64Auto(size);
DN_ErrSinkAppendF(err, 1, "Failed to write buffer (%s) to file handle", DN_Str8PrintFmt(buffer_size_str8));
DN_TCScratchEnd(&scratch);
}
@@ -10339,7 +10394,7 @@ DN_API bool DN_OS_PathIsDir(DN_Str8 path)
DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
{
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
bool result = true;
// TODO(doyle): Implement this without using the path indexes, it's not
@@ -10505,7 +10560,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle,
// NOTE: Read the data from the read end of the pipe
if (result.os_error_code == 0) {
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
if (arena && handle.stdout_read) {
char buffer[4096];
DN_Str8Builder builder = DN_Str8BuilderFromArena(&scratch.arena);
@@ -10517,7 +10572,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle,
DN_Str8BuilderAppendF(&builder, "%.*s", bytes_read, buffer);
}
result.stdout_text = DN_Str8BuilderBuild(&builder, arena);
result.stdout_text = DN_Str8FromStr8BuilderArena(&builder, arena);
}
if (arena && handle.stderr_read) {
@@ -10531,7 +10586,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle,
DN_Str8BuilderAppendF(&builder, "%.*s", bytes_read, buffer);
}
result.stderr_text = DN_Str8BuilderBuild(&builder, arena);
result.stderr_text = DN_Str8FromStr8BuilderArena(&builder, arena);
}
DN_TCScratchEnd(&scratch);
}
@@ -10554,7 +10609,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
if (cmd_line.count == 0)
return result;
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
DN_DEFER { DN_TCScratchEnd(&scratch); };
DN_Str8 cmd_rendered = DN_Str8SliceRender(cmd_line, DN_Str8Lit(" "), &scratch.arena);
int stdout_pipe[DN_OSPipeType__Count] = {};
@@ -10998,7 +11053,7 @@ static void *DN_OS_ThreadFunc_(void *user_context)
return nullptr;
}
DN_API bool DN_OS_ThreadInit(DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadLane *lane, void *user_context)
DN_API bool DN_OS_ThreadInit(DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadLane *lane, DN_TCInitArgs tc_init_args, void *user_context)
{
bool result = false;
if (!thread)
@@ -11008,6 +11063,7 @@ DN_API bool DN_OS_ThreadInit(DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSTh
thread->user_context = user_context;
thread->init_semaphore = DN_OS_SemaphoreInit(0 /*initial_count*/);
thread->lane = *lane;
thread->tc_init_args = tc_init_args;
// TODO(doyle): Check if semaphore is valid
// NOTE: pthread_t is essentially the thread ID. In Windows, the handle and
@@ -11082,7 +11138,7 @@ DN_API void DN_OS_PosixThreadSetName(DN_Str8 name)
#if defined(DN_PLATFORM_EMSCRIPTEN)
(void)name;
#else
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
DN_Str8 copy = DN_Str8FromStr8Arena(name, &scratch.arena);
pthread_t thread = pthread_self();
pthread_setname_np(thread, (char *)copy.data);
@@ -11106,7 +11162,7 @@ DN_API DN_OSPosixProcSelfStatus DN_OS_PosixProcSelfStatus()
DN_OSFile file = DN_OS_FileOpen(DN_Str8Lit("/proc/self/status"), DN_OSFileOpen_OpenIfExist, DN_OSFileAccess_Read, nullptr);
if (!file.error) {
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
char buf[256];
DN_Str8Builder builder = DN_Str8BuilderFromArena(&scratch.arena);
for (;;) {
@@ -11120,7 +11176,7 @@ DN_API DN_OSPosixProcSelfStatus DN_OS_PosixProcSelfStatus()
DN_Str8 const PID = DN_Str8Lit("Pid:");
DN_Str8 const VM_PEAK = DN_Str8Lit("VmPeak:");
DN_Str8 const VM_SIZE = DN_Str8Lit("VmSize:");
DN_Str8 status_buf = DN_Str8BuilderBuild(&builder, &scratch.arena);
DN_Str8 status_buf = DN_Str8FromStr8BuilderArena(&builder, &scratch.arena);
DN_Str8SplitResult lines = DN_Str8SplitArena(status_buf, DN_Str8Lit("\n"), DN_Str8SplitFlags_ExcludeEmptyStrings, &scratch.arena);
for (DN_ForItSize(line_it, DN_Str8, lines.data, lines.count)) {
@@ -11247,7 +11303,7 @@ DN_API void DN_OS_HttpRequestAsync(DN_OSHttpResponse *response,
response->builder.arena = response->scratch_arena.mem ? &response->scratch_arena : &response->tmp_arena;
DN_Arena *scratch = &response->scratch_arena;
DN_TCScratch scratch_ = DN_TCScratchBegin(&arena, 1);
DN_TCScratch scratch_ = DN_TCScratchBeginArena(&arena, 1);
DN_DEFER { DN_TCScratchEnd(&scratch_); };
if (!scratch)
scratch = &scratch_.arena;
@@ -12549,7 +12605,7 @@ static DWORD __stdcall DN_OS_ThreadFunc_(void *user_context)
return 0;
}
DN_API bool DN_OS_ThreadInit(DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadLane *lane, void *user_context)
DN_API bool DN_OS_ThreadInit(DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadLane *lane, DN_TCInitArgs tc_init_args, void *user_context)
{
bool result = false;
if (!thread)
@@ -12558,6 +12614,7 @@ DN_API bool DN_OS_ThreadInit(DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSTh
thread->func = func;
thread->user_context = user_context;
thread->init_semaphore = DN_OS_SemaphoreInit(0 /*initial_count*/);
thread->tc_init_args = tc_init_args;
if (lane) {
thread->is_lane_set = true;
thread->lane = *lane;
@@ -13620,7 +13677,7 @@ DN_API void DN_ASYNC_Init(DN_ASYNCCore *async, char *base, DN_USize base_size, D
async->threads = threads;
for (DN_ForIndexU(index, async->thread_count)) {
DN_OSThread *thread = async->threads + index;
DN_OS_ThreadInit(thread, DN_ASYNC_ThreadEntryPoint_, nullptr, async);
DN_OS_ThreadInit(thread, DN_ASYNC_ThreadEntryPoint_, /*lane=*/ nullptr, DN_TCInitArgsDefault(), async);
}
}
@@ -13822,8 +13879,6 @@ void DN_NET_EndFinishedRequest(DN_NETRequest *request)
{
// NOTE: Deallocate the memory used in the request and reset the string builder
DN_ArenaTempEnd(&request->start_response_arena, DN_ArenaReset_Yes);
// NOTE: Check that the request is completely detached
DN_Assert(request->next == nullptr);
}
#endif
@@ -15053,7 +15108,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 3, 2, DN_ArrayErase_Stable);
int expected[] = {0, 1, 2, 5, 6, 7, 8, 9};
DN_UT_Assert(&result, erase.items_erased == 2);
DN_UT_AssertF(&result, erase.it_index == 2, "erase.it_index=%zu", erase.it_index);
DN_UT_Assert(&result, erase.it_index == 3);
DN_UT_Assert(&result, size == 8);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -15064,7 +15119,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 5, -3, DN_ArrayErase_Stable);
int expected[] = {0, 1, 2, 6, 7, 8, 9};
DN_UT_Assert(&result, erase.items_erased == 3);
DN_UT_Assert(&result, erase.it_index == 2);
DN_UT_Assert(&result, erase.it_index == 3);
DN_UT_Assert(&result, size == 7);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -15075,7 +15130,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 5, -1, DN_ArrayErase_Stable);
int expected[] = {0, 1, 2, 3, 4, 6, 7, 8, 9};
DN_UT_Assert(&result, erase.items_erased == 1);
DN_UT_Assert(&result, erase.it_index == 4);
DN_UT_Assert(&result, erase.it_index == 5);
DN_UT_Assert(&result, size == 9);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -15086,7 +15141,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 3, 2, DN_ArrayErase_Unstable);
int expected[] = {0, 1, 2, 8, 9, 5, 6, 7};
DN_UT_Assert(&result, erase.items_erased == 2);
DN_UT_Assert(&result, erase.it_index == 2);
DN_UT_Assert(&result, erase.it_index == 3);
DN_UT_Assert(&result, size == 8);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -15097,7 +15152,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 5, -3, DN_ArrayErase_Unstable);
int expected[] = {0, 1, 2, 7, 8, 9, 6};
DN_UT_Assert(&result, erase.items_erased == 3);
DN_UT_Assert(&result, erase.it_index == 2);
DN_UT_Assert(&result, erase.it_index == 3);
DN_UT_Assert(&result, size == 7);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -15119,7 +15174,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 9, 2, DN_ArrayErase_Stable);
int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
DN_UT_Assert(&result, erase.items_erased == 1);
DN_UT_Assert(&result, erase.it_index == 8);
DN_UT_Assert(&result, erase.it_index == 9);
DN_UT_Assert(&result, size == 9);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -15165,7 +15220,7 @@ static DN_UTCore DN_TST_BaseArray()
DN_ArrayEraseResult erase = DN_ArrayEraseRange(arr, &size, sizeof(arr[0]), 15, 2, DN_ArrayErase_Stable);
int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
DN_UT_Assert(&result, erase.items_erased == 0);
DN_UT_Assert(&result, erase.it_index == 9);
DN_UT_Assert(&result, erase.it_index == 10);
DN_UT_Assert(&result, size == 10);
DN_UT_Assert(&result, DN_Memcmp(arr, expected, size * sizeof(arr[0])) == 0);
}
@@ -18471,7 +18526,7 @@ DN_API void DN_BinPackCBuffer(DN_BinPack *pack, DN_BinPackMode mode, char *ptr,
DN_API DN_Str8 DN_BinPackBuild(DN_BinPack const *pack, DN_Arena *arena)
{
DN_Str8 result = DN_Str8FromStr8BuilderArena(&pack->writer, arena);
DN_Str8 result = DN_Str8BuilderBuild(&pack->writer, arena);
return result;
}
#define DN_CSV_CPP