Pull latest DN from Seasight

This commit is contained in:
doylet 2025-09-07 22:23:08 +10:00
parent 5c150c08dc
commit 49c8515cb4
9 changed files with 43 additions and 29 deletions

View File

@ -1,4 +1,4 @@
// Generated by the DN single header generator 2025-09-07 18:46:16
// Generated by the DN single header generator 2025-09-07 22:22:46
#define DN_BASE_INC_CPP
@ -4258,13 +4258,19 @@ DN_API DN_Slice<DN_Str8> DN_Str8Builder_BuildSlice(DN_Str8Builder const *builder
return result;
}
DN_API DN_Str8 DN_LStr8_AppendFV(char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, va_list args)
{
*buf_size += DN_VSNPrintF(buf + *buf_size, DN_CAST(int)(buf_max - *buf_size), fmt, args);
DN_Str8 result = DN_Str8_Init(buf, *buf_size);
return result;
}
DN_API DN_Str8 DN_LStr8_AppendF(char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
*buf_size += DN_VSNPrintF(buf + *buf_size, DN_CAST(int)(buf_max - *buf_size), fmt, args);
DN_Str8 result = DN_LStr8_AppendFV(buf, buf_size, buf_max, fmt, args);
va_end(args);
DN_Str8 result = DN_Str8_Init(buf, *buf_size);
return result;
}

View File

@ -1,4 +1,4 @@
// Generated by the DN single header generator 2025-09-07 18:46:16
// Generated by the DN single header generator 2025-09-07 22:22:46
#if !defined(DN_BASE_INC_H)
#define DN_BASE_INC_H
@ -3272,6 +3272,7 @@ DN_API bool operator== (DN_Str8 const
DN_API bool operator!= (DN_Str8 const &lhs, DN_Str8 const &rhs);
#endif
DN_API DN_Str8 DN_LStr8_AppendFV (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, va_list args);
DN_API DN_Str8 DN_LStr8_AppendF (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, ...);
#define DN_IStr8_AppendF(struct_ptr, fmt, ...) DN_LStr8_AppendF((struct_ptr)->data, &(struct_ptr)->size, DN_ArrayCountU((struct_ptr)->data), fmt, ##__VA_ARGS__)
#define DN_Str8_FromIStr8(struct_ptr) DN_Str8_Init((struct_ptr)->data, (struct_ptr)->size)
@ -5950,7 +5951,7 @@ DN_API DN_OSMutex DN_OS_MutexInit ()
DN_API void DN_OS_MutexDeinit (DN_OSMutex *mutex);
DN_API void DN_OS_MutexLock (DN_OSMutex *mutex);
DN_API void DN_OS_MutexUnlock (DN_OSMutex *mutex);
#define DN_OS_MutexScope (mutex) DN_DeferLoop(DN_OS_MutexLock(mutex), DN_OS_MutexUnlock(mutex))
#define DN_OS_MutexScope(mutex) DN_DeferLoop(DN_OS_MutexLock(mutex), DN_OS_MutexUnlock(mutex))
DN_API DN_OSConditionVariable DN_OS_ConditionVariableInit ();
DN_API void DN_OS_ConditionVariableDeinit (DN_OSConditionVariable *cv);

View File

@ -1065,13 +1065,19 @@ DN_API DN_Slice<DN_Str8> DN_Str8Builder_BuildSlice(DN_Str8Builder const *builder
return result;
}
DN_API DN_Str8 DN_LStr8_AppendFV(char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, va_list args)
{
*buf_size += DN_VSNPrintF(buf + *buf_size, DN_CAST(int)(buf_max - *buf_size), fmt, args);
DN_Str8 result = DN_Str8_Init(buf, *buf_size);
return result;
}
DN_API DN_Str8 DN_LStr8_AppendF(char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
*buf_size += DN_VSNPrintF(buf + *buf_size, DN_CAST(int)(buf_max - *buf_size), fmt, args);
DN_Str8 result = DN_LStr8_AppendFV(buf, buf_size, buf_max, fmt, args);
va_end(args);
DN_Str8 result = DN_Str8_Init(buf, *buf_size);
return result;
}

View File

@ -191,6 +191,7 @@ DN_API bool operator== (DN_Str8 const
DN_API bool operator!= (DN_Str8 const &lhs, DN_Str8 const &rhs);
#endif
DN_API DN_Str8 DN_LStr8_AppendFV (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, va_list args);
DN_API DN_Str8 DN_LStr8_AppendF (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, ...);
#define DN_IStr8_AppendF(struct_ptr, fmt, ...) DN_LStr8_AppendF((struct_ptr)->data, &(struct_ptr)->size, DN_ArrayCountU((struct_ptr)->data), fmt, ##__VA_ARGS__)
#define DN_Str8_FromIStr8(struct_ptr) DN_Str8_Init((struct_ptr)->data, (struct_ptr)->size)

View File

@ -283,7 +283,7 @@ static bool DN_CGen_GatherTables_(DN_CGen *cgen, DN_OSErrSink *err)
return result;
}
DN_API DN_CGen DN_CGen_InitFilesArgV(int argc, char const **argv, DN_OSErrSink *err)
DN_API DN_CGen DN_CGen_FromFilesArgV(int argc, char const **argv, DN_OSErrSink *err)
{
DN_CGen result = {};
result.arena = MD_ArenaAlloc();
@ -376,8 +376,8 @@ DN_API void DN_CGen_LogF(MD_MessageKind kind, MD_Node *node, DN_OSErrSink *err,
if (!err)
return;
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
DN_Str8Builder builder = DN_Str8Builder_InitFromTLS();
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
DN_Str8Builder builder = DN_Str8Builder_FromTLS();
MD_String8 kind_string = MD_StringFromMessageKind(kind);
MD_CodeLoc loc = MD_CodeLocFromNode(node);
@ -972,7 +972,7 @@ DN_API void DN_CGen_EmitCodeForTables(DN_CGen *cgen, DN_CGenEmit emit, DN_CppFil
cpp_label_str8_padding = 1 + it.table->headers[cpp_label.index].longest_string - cpp_label.column.string.size;
}
DN_Str8Builder builder = DN_Str8Builder_InitFromTLS();
DN_Str8Builder builder = DN_Str8Builder_FromTLS();
// NOTE: row
DN_Str8Builder_AppendF(&builder, "{%2d, ", row_index);
@ -1092,7 +1092,7 @@ DN_API void DN_CGen_EmitCodeForTables(DN_CGen *cgen, DN_CGenEmit emit, DN_CppFil
fields = DN_Str8_FromF(tmem.arena, "g_%.*s_type_fields", DN_STR_FMT(type_name));
}
DN_Str8Builder builder = DN_Str8Builder_InitFromTLS();
DN_Str8Builder builder = DN_Str8Builder_FromTLS();
// NOTE: name
DN_Str8Builder_AppendF(&builder, "{DN_STR8(\"%.*s\"),%*s", DN_STR_FMT(type_name), name_padding, "");

View File

@ -30,7 +30,7 @@ static DN_NET2Response DN_NET2_WaitForAnyResponse(DN_NET2Core *net, DN_Arena *ar
result.http_status = response->http_status;
result.body = DN_Str8Builder_Build(&response->body, arena);
if (response->error.size)
result.error = DN_Str8_Copy(arena, response->error);
result.error = DN_Str8_FromStr8(arena, response->error);
// NOTE: Deallocate the memory used in the request
DN_Arena_PopTo(&request->arena, request->start_response_arena_pos);
@ -66,7 +66,7 @@ static DN_NET2Response DN_NET2_WaitForResponse(DN_NET2Core *net, DN_NET2Request
result.http_status = response->http_status;
result.body = DN_Str8Builder_Build(&response->body, arena);
if (response->error.size)
result.error = DN_Str8_Copy(arena, response->error);
result.error = DN_Str8_FromStr8(arena, response->error);
// NOTE: Deallocate the memory used in the request
DN_Arena_PopTo(&request_ptr->arena, request_ptr->start_response_arena_pos);
@ -130,7 +130,7 @@ static DN_USize DN_NET2_HTTPCallback_(char *payload, DN_USize size, DN_USize cou
static int32_t DN_NET2_ThreadEntryPoint_(DN_OSThread *thread)
{
DN_NET2Core *net = DN_CAST(DN_NET2Core *) thread->user_context;
DN_OS_ThreadSetName(DN_FStr8_ToStr8(&net->curl_thread.name));
DN_OS_ThreadSetName(DN_Str8_Init(net->curl_thread.name.data, net->curl_thread.name.size));
for (;;) {
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
@ -397,7 +397,7 @@ static void DN_NET2_Init(DN_NET2Core *net, char *ring_base, DN_USize ring_size,
DN_DLList_InitArena(net->ws_list, DN_NET2RequestInternal, &net->arena);
DN_DLList_InitArena(net->done_list, DN_NET2RequestInternal, &net->arena);
net->curl_thread.name = DN_FStr8_InitF<64>("NET (CURL)");
DN_IStr8_AppendF(&net->curl_thread.name, "NET (CURL)");
DN_OS_ThreadInit(&net->curl_thread, DN_NET2_ThreadEntryPoint_, net);
}
@ -484,21 +484,21 @@ static DN_NET2Request DN_NET2_DoRequest_(DN_NET2Core *net, DN_Str8 url, DN_Str8
request->type = type;
request->gen = DN_Max(request->gen + 1, 1);
request->url = DN_Str8_Copy(&request->arena, url);
request->method = DN_Str8_Copy(&request->arena, method);
request->url = DN_Str8_FromStr8(&request->arena, url);
request->method = DN_Str8_FromStr8(&request->arena, method);
if (args) {
request->args.flags = args->flags;
request->args.username = DN_Str8_Copy(&request->arena, args->username);
request->args.password = DN_Str8_Copy(&request->arena, args->password);
request->args.username = DN_Str8_FromStr8(&request->arena, args->username);
request->args.password = DN_Str8_FromStr8(&request->arena, args->password);
if (type == DN_NET2RequestType_HTTP)
request->args.payload = DN_Str8_Copy(&request->arena, args->payload);
request->args.payload = DN_Str8_FromStr8(&request->arena, args->payload);
request->args.headers = DN_Arena_NewArray(&request->arena, DN_Str8, args->headers_size, DN_ZeroMem_No);
DN_Assert(request->args.headers);
if (request->args.headers) {
for (DN_ForItSize(it, DN_Str8, args->headers, args->headers_size))
request->args.headers[it.index] = DN_Str8_Copy(&request->arena, *it.data);
request->args.headers[it.index] = DN_Str8_FromStr8(&request->arena, *it.data);
request->args.headers_size = args->headers_size;
}
}

View File

@ -31,7 +31,7 @@ enum DN_NET2WSType
struct DN_NET2CurlConn
{
struct CURL *curl;
void *curl;
struct curl_slist *curl_slist;
};
@ -134,7 +134,7 @@ struct DN_NET2Core
DN_OSThread curl_thread;
// NOTE: Networking thread only
struct CURLM *curlm;
void *curlm;
DN_NET2RequestInternal *http_list;
DN_NET2RequestInternal *ws_list;
};

View File

@ -431,7 +431,7 @@ DN_API DN_OSMutex DN_OS_MutexInit ()
DN_API void DN_OS_MutexDeinit (DN_OSMutex *mutex);
DN_API void DN_OS_MutexLock (DN_OSMutex *mutex);
DN_API void DN_OS_MutexUnlock (DN_OSMutex *mutex);
#define DN_OS_MutexScope (mutex) DN_DeferLoop(DN_OS_MutexLock(mutex), DN_OS_MutexUnlock(mutex))
#define DN_OS_MutexScope(mutex) DN_DeferLoop(DN_OS_MutexLock(mutex), DN_OS_MutexUnlock(mutex))
DN_API DN_OSConditionVariable DN_OS_ConditionVariableInit ();
DN_API void DN_OS_ConditionVariableDeinit (DN_OSConditionVariable *cv);

View File

@ -32,7 +32,7 @@ struct File
static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
{
DN_OSErrSink *err = DN_OS_ErrSinkBeginDefault();
DN_Str8 buffer = DN_OS_ReadAllFromTLS(cpp_path, err);
DN_Str8 buffer = DN_OS_FileReadAllTLS(cpp_path, err);
DN_OS_ErrSinkEndAndExitIfErrorF(err, -1, "Failed to load file from '%S' for appending", cpp_path);
for (DN_Str8 inc_walker = buffer;;) {
@ -90,7 +90,7 @@ int main(int argc, char **argv)
DN_Str8 dn_root_dir = DN_Str8_FromCStr8(argv[1]);
DN_Str8 output_dir = DN_Str8_FromCStr8(argv[2]);
if (!DN_OS_MakeDir(output_dir)) {
if (!DN_OS_PathMakeDir(output_dir)) {
DN_OS_PrintErrF("Failed to make requested output directory: %S", output_dir);
return -1;
}
@ -115,7 +115,7 @@ int main(int argc, char **argv)
DN_Str8 path = DN_OS_PathFFromTLS("%S/%S", dn_root_dir, it.data->file_name);
{
DN_OSErrSink *err = DN_OS_ErrSinkBeginDefault();
DN_Str8 file_buffer = DN_OS_ReadAllFromTLS(path, err);
DN_Str8 file_buffer = DN_OS_FileReadAllTLS(path, err);
DN_OS_ErrSinkEndAndExitIfErrorF(err, -1, "Failed to load file");
// NOTE: Walk the top-level dn_*_inc.[h|cpp] files
@ -173,7 +173,7 @@ int main(int argc, char **argv)
DN_Str8 buffer = DN_Str8_TrimWhitespaceAround(DN_Str8Builder_BuildFromTLS(&builder));
DN_Str8 single_header_path = DN_OS_PathFFromTLS("%S/dn_single_header.%S", output_dir, suffix);
DN_OSErrSink *err = DN_OS_ErrSinkBeginDefault();
DN_OS_WriteAllSafe(single_header_path, buffer, err);
DN_OS_FileWriteAllSafe(single_header_path, buffer, err);
DN_OS_ErrSinkEndAndExitIfErrorF(err, -1, "Failed to write Single header file '%S'", single_header_path);
}
}