Misc fixes
This commit is contained in:
+423
-415
File diff suppressed because it is too large
Load Diff
+120
-119
@@ -1,4 +1,4 @@
|
||||
// Generated by the DN single header generator 2026-07-17 17:54:42
|
||||
// Generated by the DN single header generator 2026-07-19 16:12:36
|
||||
|
||||
#if !defined(DN_H)
|
||||
#define DN_H
|
||||
@@ -31,7 +31,7 @@
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DN_Core core = {};
|
||||
DN_Init(&core, DN_InitFlags_Nil, DN_TCInitArgsDefault());
|
||||
DN_Init(&core, DN_InitFlags_Nil, DN_TcInitArgsDefault());
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
@@ -726,7 +726,7 @@ typedef DN_I32 DN_B32;
|
||||
|
||||
#define DN_CountLeadingZerosU64(value) __lzcnt64(value)
|
||||
#define DN_CountLeadingZerosU32(value) __lzcnt(value)
|
||||
#define DN_CPUGetTSC() __rdtsc()
|
||||
#define DN_CPUGetTsc() __rdtsc()
|
||||
#define DN_CompilerReadBarrierAndCPUReadFence _ReadBarrier(); _mm_lfence()
|
||||
#define DN_CompilerWriteBarrierAndCPUWriteFence _WriteBarrier(); _mm_sfence()
|
||||
#elif defined(DN_COMPILER_GCC) || defined(DN_COMPILER_CLANG)
|
||||
@@ -751,9 +751,9 @@ typedef DN_I32 DN_B32;
|
||||
#define DN_CountLeadingZerosU32(value) __builtin_clzl(value)
|
||||
|
||||
#if defined(DN_COMPILER_GCC)
|
||||
#define DN_CPUGetTSC() __rdtsc()
|
||||
#define DN_CPUGetTsc() __rdtsc()
|
||||
#else
|
||||
#define DN_CPUGetTSC() __builtin_readcyclecounter()
|
||||
#define DN_CPUGetTsc() __builtin_readcyclecounter()
|
||||
#endif
|
||||
|
||||
#if defined(DN_PLATFORM_EMSCRIPTEN)
|
||||
@@ -886,7 +886,7 @@ struct DN_CPUIDArgs { int eax; int ecx; };
|
||||
DN_CPU_FEAT_XENTRY(POPCNT) \
|
||||
DN_CPU_FEAT_XENTRY(RDRAND) \
|
||||
DN_CPU_FEAT_XENTRY(RDSEED) \
|
||||
DN_CPU_FEAT_XENTRY(RDTSCP) \
|
||||
DN_CPU_FEAT_XENTRY(RDTscP) \
|
||||
DN_CPU_FEAT_XENTRY(SHA) \
|
||||
DN_CPU_FEAT_XENTRY(SSE) \
|
||||
DN_CPU_FEAT_XENTRY(SSE2) \
|
||||
@@ -895,7 +895,7 @@ struct DN_CPUIDArgs { int eax; int ecx; };
|
||||
DN_CPU_FEAT_XENTRY(SSE42) \
|
||||
DN_CPU_FEAT_XENTRY(SSE4A) \
|
||||
DN_CPU_FEAT_XENTRY(SSSE3) \
|
||||
DN_CPU_FEAT_XENTRY(TSC) \
|
||||
DN_CPU_FEAT_XENTRY(Tsc) \
|
||||
DN_CPU_FEAT_XENTRY(TscInvariant) \
|
||||
DN_CPU_FEAT_XENTRY(VAES) \
|
||||
DN_CPU_FEAT_XENTRY(VPCMULQDQ)
|
||||
@@ -1386,7 +1386,7 @@ typedef DN_U32 DN_CodepointCountFlags;
|
||||
enum DN_CodepointCountFlags_
|
||||
{
|
||||
DN_CodepointCountFlags_Nil = 0,
|
||||
DN_CodepointCountFlags_SkipANSICode = 1 << 0,
|
||||
DN_CodepointCountFlags_SkipAnsiCode = 1 << 0,
|
||||
};
|
||||
|
||||
typedef struct DN_NibbleFromU8Result DN_NibbleFromU8Result;
|
||||
@@ -1590,7 +1590,7 @@ struct DN_ProfilerAnchorArray
|
||||
DN_USize count;
|
||||
};
|
||||
|
||||
typedef DN_U64 (DN_ProfilerTSCNowFunc)();
|
||||
typedef DN_U64 (DN_ProfilerTscNowFunc)();
|
||||
typedef struct DN_Profiler DN_Profiler;
|
||||
struct DN_Profiler
|
||||
{
|
||||
@@ -1600,7 +1600,7 @@ struct DN_Profiler
|
||||
DN_USize anchors_per_frame;
|
||||
DN_U16 parent_zone;
|
||||
bool paused;
|
||||
DN_ProfilerTSCNowFunc *tsc_now;
|
||||
DN_ProfilerTscNowFunc *tsc_now;
|
||||
DN_U64 tsc_frequency;
|
||||
DN_ProfilerZone frame_zone;
|
||||
DN_F64 frame_avg_tsc;
|
||||
@@ -1676,25 +1676,25 @@ struct DN_ErrSink
|
||||
DN_USize stack_size;
|
||||
};
|
||||
|
||||
typedef struct DN_TCScratch DN_TCScratch;
|
||||
struct DN_TCScratch
|
||||
typedef struct DN_TcScratch DN_TcScratch;
|
||||
struct DN_TcScratch
|
||||
{
|
||||
DN_Arena arena;
|
||||
DN_B32 destructed;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
typedef struct DN_TCScratchCpp DN_TCScratchCpp;
|
||||
struct DN_TCScratchCpp
|
||||
typedef struct DN_TcScratchCpp DN_TcScratchCpp;
|
||||
struct DN_TcScratchCpp
|
||||
{
|
||||
DN_TCScratchCpp(DN_Arena **conflicts, DN_USize count);
|
||||
~DN_TCScratchCpp();
|
||||
DN_TCScratch data;
|
||||
DN_TcScratchCpp(DN_Arena **conflicts, DN_USize count);
|
||||
~DN_TcScratchCpp();
|
||||
DN_TcScratch data;
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef struct DN_TCInitArgs DN_TCInitArgs;
|
||||
struct DN_TCInitArgs
|
||||
typedef struct DN_TcInitArgs DN_TcInitArgs;
|
||||
struct DN_TcInitArgs
|
||||
{
|
||||
DN_U64 main_reserve;
|
||||
DN_U64 main_commit;
|
||||
@@ -1705,8 +1705,8 @@ struct DN_TCInitArgs
|
||||
DN_U64 err_sink_commit;
|
||||
};
|
||||
|
||||
typedef struct DN_TCCore DN_TCCore;
|
||||
struct DN_TCCore // (T)hread (C)ontext sitting in thread-local storage
|
||||
typedef struct DN_TcCore DN_TcCore;
|
||||
struct DN_TcCore // (T)hread (C)ontext sitting in thread-local storage
|
||||
{
|
||||
DN_Str8x64 name;
|
||||
DN_U64 thread_id;
|
||||
@@ -1724,13 +1724,13 @@ struct DN_TCCore // (T)hread (C)ontext sitting in thread-local storage
|
||||
DN_Arena* frame_arena;
|
||||
};
|
||||
|
||||
typedef enum DN_TCDeinitArenas {
|
||||
DN_TCDeinitArenas_No,
|
||||
DN_TCDeinitArenas_Yes,
|
||||
} DN_TCDeinitArenas;
|
||||
typedef enum DN_TcDeinitArenas {
|
||||
DN_TcDeinitArenas_No,
|
||||
DN_TcDeinitArenas_Yes,
|
||||
} DN_TcDeinitArenas;
|
||||
|
||||
typedef struct DN_PCG32 DN_PCG32;
|
||||
struct DN_PCG32 { DN_U64 state; };
|
||||
typedef struct DN_Pcg32 DN_Pcg32;
|
||||
struct DN_Pcg32 { DN_U64 state; };
|
||||
|
||||
typedef struct DN_Murmur3 DN_Murmur3;
|
||||
struct DN_Murmur3 { DN_U64 e[2]; };
|
||||
@@ -1764,10 +1764,10 @@ struct DN_LogTypeParam
|
||||
DN_Str8 str8;
|
||||
};
|
||||
|
||||
typedef enum DN_ANSIColourMode {
|
||||
DN_ANSIColourMode_Fg,
|
||||
DN_ANSIColourMode_Bg,
|
||||
} DN_ANSIColourMode;
|
||||
typedef enum DN_AnsiColourMode {
|
||||
DN_AnsiColourMode_Fg,
|
||||
DN_AnsiColourMode_Bg,
|
||||
} DN_AnsiColourMode;
|
||||
|
||||
typedef struct DN_LogDate DN_LogDate;
|
||||
struct DN_LogDate
|
||||
@@ -4402,7 +4402,7 @@ struct DN_OSThreadInitArgs
|
||||
{
|
||||
// NOTE: Customise much memory the thread's TLS context will be initialised with which contains
|
||||
// persistent/temporary allocators and misc facilities that each thread has exclusive access to.
|
||||
DN_TCInitArgs tc_args;
|
||||
DN_TcInitArgs tc_args;
|
||||
|
||||
// NOTE: Set how much stack space in bytes the thread will have. Leave this value to 0 to defer
|
||||
// to the OS's default stack size.
|
||||
@@ -4433,7 +4433,7 @@ struct DN_OSThread
|
||||
{
|
||||
DN_OSThreadFlags flags;
|
||||
DN_Str8x64 name;
|
||||
DN_TCCore context;
|
||||
DN_TcCore context;
|
||||
DN_OSThreadLane lane;
|
||||
bool is_lane_set;
|
||||
void *handle;
|
||||
@@ -4445,7 +4445,7 @@ struct DN_OSThread
|
||||
#if !defined(DN_PLATFORM_WIN32)
|
||||
DN_OSSemaphore join_done_sem;
|
||||
#endif
|
||||
DN_TCInitArgs tc_init_args;
|
||||
DN_TcInitArgs tc_init_args;
|
||||
};
|
||||
|
||||
typedef DN_U32 DN_OSLogFlags;
|
||||
@@ -4453,7 +4453,7 @@ enum DN_OSLoggerFlags_
|
||||
{
|
||||
DN_OSLoggerFlags_Nil = 0,
|
||||
DN_OSLoggerFlags_File = 1 << 0, // Write the log to disk
|
||||
DN_OSLoggerFlags_NoColour = 1 << 2, // Prevent outputting logs with ANSI colour codes (note: logs written to disk never use colour)
|
||||
DN_OSLoggerFlags_NoColour = 1 << 2, // Prevent outputting logs with Ansi colour codes (note: logs written to disk never use colour)
|
||||
DN_OSLoggerFlags_NoOutput = 1 << 3, // Prevent outputting to the terminal
|
||||
|
||||
// NOTE: Internal flags, do not use
|
||||
@@ -4559,7 +4559,7 @@ typedef struct DN_Core DN_Core;
|
||||
struct DN_Core
|
||||
{
|
||||
DN_InitFlags init_flags;
|
||||
DN_TCCore main_tc;
|
||||
DN_TcCore main_tc;
|
||||
DN_USize mem_allocs_frame;
|
||||
DN_LeakTracker leak;
|
||||
|
||||
@@ -4590,10 +4590,10 @@ struct DN_Core
|
||||
// optionally call `DN_BeginFrame` which resets some metrics that are counted for example it
|
||||
// tracks the number of memory allocations for the current frame and that counter can be reset.
|
||||
//
|
||||
// For convenience you can opt into some sane defaults for the `DN_TCInitArgs` which customises
|
||||
// how thread-local storage is setup with `DN_TCInitArgsDefault()` which produces a
|
||||
// `DN_TCInitArgs` object you can pass in by value.
|
||||
DN_API void DN_Init (DN_Core *dn, DN_InitFlags flags, DN_TCInitArgs args);
|
||||
// For convenience you can opt into some sane defaults for the `DN_TcInitArgs` which customises
|
||||
// how thread-local storage is setup with `DN_TcInitArgsDefault()` which produces a
|
||||
// `DN_TcInitArgs` object you can pass in by value.
|
||||
DN_API void DN_Init (DN_Core *dn, DN_InitFlags flags, DN_TcInitArgs args);
|
||||
DN_API void DN_Set (DN_Core *dn);
|
||||
DN_API DN_Core* DN_Get ();
|
||||
DN_API void DN_BeginFrame ();
|
||||
@@ -4601,10 +4601,10 @@ DN_API void DN_BeginFrame
|
||||
DN_API bool DN_VerifyArgsF (DN_VerifyType type, bool expr, DN_CallSite call_site, DN_Str8 expr_str8, char const *fmt, ...);
|
||||
DN_API bool DN_VerifyArgs (DN_VerifyType type, bool expr, DN_CallSite call_site, DN_Str8 expr_str8);
|
||||
|
||||
#define DN_SPrintF(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__)
|
||||
#define DN_SNPrintF(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__)
|
||||
#define DN_VSPrintF(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__)
|
||||
#define DN_VSNPrintF(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__)
|
||||
#define DN_Sprintf(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__)
|
||||
#define DN_Snprintf(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__)
|
||||
#define DN_Vsprintf(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__)
|
||||
#define DN_Vsnprintf(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__)
|
||||
|
||||
DN_API bool DN_MemStartsWith (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
DN_API bool DN_MemEq (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
@@ -4672,7 +4672,7 @@ DN_API void DN_BitSetInplace
|
||||
DN_API bool DN_BitIsSet (DN_USize bits, DN_USize bits_to_set);
|
||||
DN_API bool DN_BitIsNotSet (DN_USize bits, DN_USize bits_to_check);
|
||||
DN_API bool DN_BitIsAny (DN_USize bits, DN_USize bits_to_check);
|
||||
#define DN_BitClearNextLSB(value) (value) & ((value) - 1)
|
||||
#define DN_BitClearNextLsb(value) (value) & ((value) - 1)
|
||||
|
||||
DN_API DN_I64 DN_SafeAddI64 (DN_I64 a, DN_I64 b);
|
||||
DN_API DN_I64 DN_SafeMulI64 (DN_I64 a, DN_I64 b);
|
||||
@@ -4901,24 +4901,24 @@ DN_API void DN_ErrSinkAppendFV_
|
||||
DN_API void DN_ErrSinkAppendF_ (DN_ErrSink *err, DN_U32 error_code, DN_CallSite call_site, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
#define DN_ErrSinkAppendF(error, error_code, fmt, ...) DN_ErrSinkAppendF_(error, error_code, DN_CallSiteNow, fmt, ##__VA_ARGS__)
|
||||
|
||||
DN_API DN_TCInitArgs DN_TCInitArgsDefault ();
|
||||
DN_API void DN_TCInit (DN_TCCore *tc, DN_U64 thread_id, DN_Arena *main_arena, DN_Arena *temp_arenas, DN_USize temp_arenas_count, DN_Arena *err_sink_arena);
|
||||
DN_API void DN_TCInitFromHeap (DN_TCCore *tc, DN_U64 thread_id, DN_TCInitArgs args, DN_Heap heap);
|
||||
DN_API void DN_TCDeinit (DN_TCCore *tc, DN_TCDeinitArenas deinit_arenas);
|
||||
DN_API void DN_TCEquip (DN_TCCore *tc);
|
||||
DN_API DN_TCCore* DN_TCGet ();
|
||||
DN_API DN_Arena* DN_TCMainArena ();
|
||||
DN_API DN_Pool* DN_TCMainPool ();
|
||||
DN_API DN_Arena DN_TCTempArenaFromAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_Arena DN_TCTempArenaFromArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API DN_TCScratch DN_TCScratchBeginAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_TCScratch DN_TCScratchBeginArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API void DN_TCScratchEnd (DN_TCScratch *scratch);
|
||||
DN_API void DN_TCSetFrameArena (DN_Arena *arena);
|
||||
DN_API DN_Arena* DN_TCFrameArena ();
|
||||
DN_API DN_ErrSink* DN_TCErrSink ();
|
||||
#define DN_TCErrSinkBegin(mode) DN_ErrSinkBegin(DN_TCErrSink(), mode)
|
||||
#define DN_TCErrSinkBeginDefault() DN_ErrSinkBeginDefault(DN_TCErrSink())
|
||||
DN_API DN_TcInitArgs DN_TcInitArgsDefault ();
|
||||
DN_API void DN_TcInit (DN_TcCore *tc, DN_U64 thread_id, DN_Arena *main_arena, DN_Arena *temp_arenas, DN_USize temp_arenas_count, DN_Arena *err_sink_arena);
|
||||
DN_API void DN_TcInitFromHeap (DN_TcCore *tc, DN_U64 thread_id, DN_TcInitArgs args, DN_Heap heap);
|
||||
DN_API void DN_TcDeinit (DN_TcCore *tc, DN_TcDeinitArenas deinit_arenas);
|
||||
DN_API void DN_TcEquip (DN_TcCore *tc);
|
||||
DN_API DN_TcCore* DN_TcGet ();
|
||||
DN_API DN_Arena* DN_TcMainArena ();
|
||||
DN_API DN_Pool* DN_TcMainPool ();
|
||||
DN_API DN_Arena DN_TcTempArenaFromAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_Arena DN_TcTempArenaFromArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API DN_TcScratch DN_TcScratchBeginAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_TcScratch DN_TcScratchBeginArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API void DN_TcScratchEnd (DN_TcScratch *scratch);
|
||||
DN_API void DN_TcSetFrameArena (DN_Arena *arena);
|
||||
DN_API DN_Arena* DN_TcFrameArena ();
|
||||
DN_API DN_ErrSink* DN_TcErrSink ();
|
||||
#define DN_TcErrSinkBegin(mode) DN_ErrSinkBegin(DN_TcErrSink(), mode)
|
||||
#define DN_TcErrSinkBeginDefault() DN_ErrSinkBeginDefault(DN_TcErrSink())
|
||||
|
||||
DN_API bool DN_CharIsAlphabet (char ch);
|
||||
DN_API bool DN_CharIsDigit (char ch);
|
||||
@@ -4992,12 +4992,12 @@ DN_API DN_Str8 DN_Str8FromPtrPool
|
||||
DN_API DN_Str8 DN_Str8FromStr8Allocator (DN_Str8 string, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Arena (DN_Str8 string, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Pool (DN_Str8 string, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8FromFmtVAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FromFmtVArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FromFmtAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromFmtArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromFmtVPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FromFmtPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtVAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FmtVArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FmtAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtVPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FmtPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
|
||||
DN_API DN_Str8x16 DN_Str8x16FromFmt (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8x16 DN_Str8x16FromFmtV (DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
@@ -5215,8 +5215,8 @@ DN_API DN_Str8x32 DN_Str8x32FromByteCountU64
|
||||
// API
|
||||
// DN_ProfilerInit
|
||||
// You can set `tsc_now` to NULL to use the default timer mechanic which relies on
|
||||
// DN_CPUGetTSC() which essentially uses __rdtsc. `tsc_frequency` must however always be
|
||||
// provided, for, DN_CPUGetTSC() you can use `DN_OS_EstimateTSCPerSecond()` to calculate the
|
||||
// DN_CPUGetTsc() which essentially uses __rdtsc. `tsc_frequency` must however always be
|
||||
// provided, for, DN_CPUGetTsc() you can use `DN_OS_EstimateTscPerSecond()` to calculate the
|
||||
// frequency of `__rdtsc`.
|
||||
// DN_ProfilerNewFrame
|
||||
// Always call `DN_ProfilerNewFrame` at-least once using the `Zone` family of functions as it
|
||||
@@ -5235,7 +5235,7 @@ DN_API DN_Str8x32 DN_Str8x32FromByteCountU64
|
||||
DN_ProfilerEndZone(DN_UniqueName(zone_)), DN_UniqueName(dummy_).begin_tsc = 1
|
||||
|
||||
#define DN_ProfilerZoneLoopAuto(prof, name) DN_ProfilerZoneLoop(prof, name, __COUNTER__ + 1)
|
||||
DN_API DN_Profiler DN_ProfilerInit (DN_ProfilerAnchor *anchors, DN_USize count, DN_USize anchors_per_frame, DN_ProfilerTSCNowFunc *tsc_now, DN_U64 tsc_frequency);
|
||||
DN_API DN_Profiler DN_ProfilerInit (DN_ProfilerAnchor *anchors, DN_USize count, DN_USize anchors_per_frame, DN_ProfilerTscNowFunc *tsc_now, DN_U64 tsc_frequency);
|
||||
DN_API DN_ProfilerZone DN_ProfilerBeginZone (DN_Profiler *profiler, DN_Str8 name, DN_U16 anchor_index);
|
||||
#define DN_ProfilerBeginZoneAuto(prof, name) DN_ProfilerBeginZone(prof, DN_Str8Lit(name), __COUNTER__ + 1)
|
||||
DN_API void DN_ProfilerEndZone (DN_ProfilerZone zone);
|
||||
@@ -5246,8 +5246,8 @@ DN_API void DN_ProfilerNewFrame
|
||||
DN_API DN_USize DN_ProfilerFmtAnchor (DN_ProfilerAnchor anchor, DN_U64 tsc_frequency, char *buffer, DN_USize count);
|
||||
DN_API DN_Str8 DN_ProfilerFmtAnchorStr8 (DN_ProfilerAnchor anchor, DN_U64 tsc_frequency, DN_Arena *arena);
|
||||
DN_API void DN_ProfilerFmtToStdout (DN_Profiler *profiler);
|
||||
DN_API DN_F64 DN_ProfilerSecFromTSC (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
DN_API DN_F64 DN_ProfilerMsFromTSC (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
DN_API DN_F64 DN_ProfilerSecFromTsc (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
DN_API DN_F64 DN_ProfilerMsFromTsc (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
|
||||
DN_API void DN_QSort (void *array, DN_USize array_size, DN_USize elem_size, void *user_context, DN_QSortCompareFunc *compare);
|
||||
DN_API bool DN_QSortCompareStr8NaturalAsc (void const* lhs, void const *rhs, void *user_context);
|
||||
@@ -5270,24 +5270,24 @@ DN_API DN_BSearchResult DN_BSearchUSize
|
||||
DN_API DN_BSearchResult DN_BSearchU64 (DN_U64 const *array, DN_USize count, DN_U64 find, DN_BSearchType type);
|
||||
DN_API DN_BSearchResult DN_BSearchU32 (DN_U32 const *array, DN_USize count, DN_U32 find, DN_BSearchType type);
|
||||
|
||||
DN_API DN_PCG32 DN_PCG32Init (DN_U64 seed);
|
||||
DN_API DN_U32 DN_PCG32Next (DN_PCG32 *rng);
|
||||
DN_API DN_U64 DN_PCG32Next64 (DN_PCG32 *rng);
|
||||
DN_API DN_U32 DN_PCG32Range (DN_PCG32 *rng, DN_U32 low, DN_U32 high);
|
||||
DN_API DN_F32 DN_PCG32NextF32 (DN_PCG32 *rng);
|
||||
DN_API DN_F64 DN_PCG32NextF64 (DN_PCG32 *rng);
|
||||
DN_API void DN_PCG32Advance (DN_PCG32 *rng, DN_U64 delta);
|
||||
DN_API DN_Pcg32 DN_Pcg32Init (DN_U64 seed);
|
||||
DN_API DN_U32 DN_Pcg32Next (DN_Pcg32 *rng);
|
||||
DN_API DN_U64 DN_Pcg32Next64 (DN_Pcg32 *rng);
|
||||
DN_API DN_U32 DN_Pcg32Range (DN_Pcg32 *rng, DN_U32 low, DN_U32 high);
|
||||
DN_API DN_F32 DN_Pcg32NextF32 (DN_Pcg32 *rng);
|
||||
DN_API DN_F64 DN_Pcg32NextF64 (DN_Pcg32 *rng);
|
||||
DN_API void DN_Pcg32Advance (DN_Pcg32 *rng, DN_U64 delta);
|
||||
|
||||
#if !defined(DN_FNV1A32_SEED)
|
||||
#define DN_FNV1A32_SEED 2166136261U
|
||||
#if !defined(DN_Fnv1a32_SEED)
|
||||
#define DN_Fnv1a32_SEED 2166136261U
|
||||
#endif
|
||||
|
||||
#if !defined(DN_FNV1A64_SEED)
|
||||
#define DN_FNV1A64_SEED 14695981039346656037ULL
|
||||
#if !defined(DN_Fnv1a64_SEED)
|
||||
#define DN_Fnv1a64_SEED 14695981039346656037ULL
|
||||
#endif
|
||||
|
||||
DN_API DN_U32 DN_FNV1AHashU32FromBytes (void const *bytes, DN_USize count, DN_U32 seed);
|
||||
DN_API DN_U64 DN_FNV1AHashU64FromBytes (void const *bytes, DN_USize count, DN_U64 seed);
|
||||
DN_API DN_U32 DN_Fnv1aHashU32FromBytes (void const *bytes, DN_USize count, DN_U32 seed);
|
||||
DN_API DN_U64 DN_Fnv1aHashU64FromBytes (void const *bytes, DN_USize count, DN_U64 seed);
|
||||
|
||||
DN_API DN_U32 DN_Murmur3HashU32FromBytesX86 (void const *bytes, int len, DN_U32 seed);
|
||||
DN_API DN_Murmur3 DN_Murmur3HashU128FromBytesX64 (void const *bytes, int len, DN_U32 seed);
|
||||
@@ -5300,15 +5300,15 @@ DN_API DN_U32 DN_Murmur3HashU32FromBytesX64
|
||||
#define DN_Murmur3HashU32FromBytes(bytes, len, seed) DN_Murmur3HashU32FromBytesX86(bytes, len, seed)
|
||||
#endif
|
||||
|
||||
#define DN_ANSICodeBoldLit "\x1b[1m"
|
||||
#define DN_ANSICodeResetLit "\x1b[0m"
|
||||
DN_API DN_Str8x32 DN_Str8x32FromANSIColourCodeU8RGB (DN_ANSIColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromANSIColourCodeV3F32RGB255 (DN_ANSIColourMode mode, DN_V3F32 rgb_255);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromANSIColourCodeU32RGB (DN_ANSIColourMode mode, DN_U32 value);
|
||||
DN_API DN_Str8 DN_Str8FromStr8ANSIColourU8RGBArena (DN_ANSIColourMode mode, DN_Str8 str8, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8ANSIColourV3F32RGB255Arena (DN_ANSIColourMode mode, DN_Str8 str8, DN_V3F32 rgb_255, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromFmtANSIColourU8RGBArena (DN_ANSIColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena, char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromFmtANSIColourV3F32RGB255Arena (DN_ANSIColourMode mode, DN_V3F32 rgb_255, DN_Arena *arena, char const *fmt, ...);
|
||||
#define DN_AnsiCodeBoldLit "\x1b[1m"
|
||||
#define DN_AnsiCodeResetLit "\x1b[0m"
|
||||
DN_API DN_Str8x32 DN_Str8x32FromAnsiColourCodeU8Rgb (DN_AnsiColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromAnsiColourCodeV3F32Rgb255 (DN_AnsiColourMode mode, DN_V3F32 rgb_255);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromAnsiColourCodeU32Rgb (DN_AnsiColourMode mode, DN_U32 value);
|
||||
DN_API DN_Str8 DN_Str8FromStr8AnsiColourU8RgbArena (DN_AnsiColourMode mode, DN_Str8 str8, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8AnsiColourV3F32Rgb255Arena (DN_AnsiColourMode mode, DN_Str8 str8, DN_V3F32 rgb_255, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FmtAnsiColourU8RgbArena (DN_AnsiColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena, char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtAnsiColourV3F32Rgb255Arena (DN_AnsiColourMode mode, DN_V3F32 rgb_255, DN_Arena *arena, char const *fmt, ...);
|
||||
|
||||
// NOTE: Create log printable lines with a date prefix, severity and message. The platform
|
||||
// implementation should call `SetPrintFunc` to intercept the log messages and output to the desired
|
||||
@@ -5510,7 +5510,7 @@ DN_API DN_F32 DN_V2F32Area
|
||||
|
||||
// NOTE: Grayscale co-efficients from:
|
||||
// https://github.com/EpicGames/UnrealEngine/blob/260bb2e1c5610b31c63a36206eedd289409c5f11/Engine/Source/Runtime/Core/Private/Math/Color.cpp#L304
|
||||
DN_V3F32 static const DN_V3F32_RGB_LUMINANCE = DN_V3F32From3N(0.3f, 0.59f, 0.11f);
|
||||
DN_V3F32 static const DN_V3F32_Rgb_LUMINANCE = DN_V3F32From3N(0.3f, 0.59f, 0.11f);
|
||||
|
||||
DN_API bool operator== (DN_V3F32 lhs, DN_V3F32 rhs);
|
||||
DN_API bool operator!= (DN_V3F32 lhs, DN_V3F32 rhs);
|
||||
@@ -5543,16 +5543,16 @@ DN_API DN_V3F32 DN_V3F32Normalise
|
||||
#define DN_V4F32From1N(x) DN_Literal(DN_V4F32){{(DN_F32)(x), (DN_F32)(x), (DN_F32)(x), (DN_F32)(x)}}
|
||||
#define DN_V4F32From4N(x, y, z, w) DN_Literal(DN_V4F32){{(DN_F32)(x), (DN_F32)(y), (DN_F32)(z), (DN_F32)(w)}}
|
||||
#define DN_V4F32FromV3And1N(xyz, w) DN_Literal(DN_V4F32){{xyz.x, xyz.y, xyz.z, w}}
|
||||
#define DN_V4F32RGBA01FromRGBAU8(r, g, b, a) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, a / 255.f}}
|
||||
#define DN_V4F32RGBA01FromRGBU8(r, g, b) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, 1.f}}
|
||||
#define DN_V4F32Rgba01FromRgbaU8(r, g, b, a) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, a / 255.f}}
|
||||
#define DN_V4F32Rgba01FromRgbU8(r, g, b) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, 1.f}}
|
||||
|
||||
DN_API DN_V4F32 DN_V4F32Lerp (DN_V4F32 lhs, DN_F32 t01, DN_V4F32 rhs);
|
||||
DN_API bool DN_V4F32RGBA01IsValid (DN_V4F32 rgba01);
|
||||
DN_API DN_V4F32 DN_V4F32RGBA01FromRGBU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32RGBA01FromRGBAU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01FromSRGB01 (DN_V4F32 rgb01);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01Desaturate (DN_V4F32 linear01, DN_F32 t01);
|
||||
DN_API DN_V4F32 DN_V4F32SRGB01FromLinear01 (DN_V4F32 linear01);
|
||||
DN_API bool DN_V4F32Rgba01IsValid (DN_V4F32 rgba01);
|
||||
DN_API DN_V4F32 DN_V4F32Rgba01FromRgbU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32Rgba01FromRgbaU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01FromSrgb01 (DN_V4F32 rgb01);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01Desaturate (DN_V4F32 linear01, DN_F32 t01);
|
||||
DN_API DN_V4F32 DN_V4F32Srgb01FromLinear01 (DN_V4F32 linear01);
|
||||
|
||||
#define DN_V4F32FromV4Alpha(v4, alpha) DN_V4F32FromV3And1N(v4.xyz, alpha)
|
||||
|
||||
@@ -6538,8 +6538,8 @@ DN_API DN_U64 DN_OS_DateLocalUnixTimeSFromUnixTimeS (D
|
||||
DN_API void DN_OS_GenBytesSecure (void *buffer, DN_U32 size);
|
||||
DN_API bool DN_OS_SetEnvVar (DN_Str8 name, DN_Str8 value);
|
||||
DN_API DN_OSDiskSpace DN_OS_DiskSpace (DN_Str8 path);
|
||||
DN_API DN_Str8 DN_OS_EXEPath (DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_OS_EXEDir (DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_OS_ExePath (DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_OS_ExeDir (DN_Arena *arena);
|
||||
DN_API void DN_OS_SleepMs (DN_UInt milliseconds);
|
||||
|
||||
DN_API DN_U64 DN_OS_PerfCounterNow ();
|
||||
@@ -6554,7 +6554,7 @@ DN_API DN_F64 DN_OS_TimerS (D
|
||||
DN_API DN_F64 DN_OS_TimerMs (DN_OSTimer timer);
|
||||
DN_API DN_F64 DN_OS_TimerUs (DN_OSTimer timer);
|
||||
DN_API DN_F64 DN_OS_TimerNs (DN_OSTimer timer);
|
||||
DN_API DN_U64 DN_OS_EstimateTSCPerSecond (uint64_t duration_ms_to_gauge_tsc_frequency);
|
||||
DN_API DN_U64 DN_OS_EstimateTscPerSecond (uint64_t duration_ms_to_gauge_tsc_frequency);
|
||||
|
||||
// NOTE: OS File
|
||||
// Overview
|
||||
@@ -6645,11 +6645,12 @@ DN_API DN_Str8 DN_OS_PathFmtPool (D
|
||||
#define DN_OS_PathBuild(allocator, fs_path) DN_OS_PathBuildWithSeparatorAllocator(allocator, fs_path, DN_OSPathSeparatorStr8)
|
||||
|
||||
DN_API void DN_OS_Exit (int32_t exit_code);
|
||||
DN_API DN_OSExecArgs DN_OS_ExecArgsDefault ();
|
||||
DN_API DN_OSExecResult DN_OS_ExecPump (DN_OSExecAsyncHandle handle, char *stdout_buffer, size_t *stdout_size, char *stderr_buffer, size_t *stderr_size, DN_U32 timeout_ms, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_ExecWait (DN_OSExecAsyncHandle handle, DN_Arena *arena, DN_ErrSink *err);
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync (DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_Exec (DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_Arena *arena, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_ExecOrAbort (DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_Arena *arena);
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync (DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_Exec (DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_Arena *arena, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_ExecOrAbort (DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_Arena *arena);
|
||||
|
||||
DN_API DN_OSSemaphore DN_OS_SemaphoreInit (DN_U32 initial_count);
|
||||
DN_API void DN_OS_SemaphoreDeinit (DN_OSSemaphore *semaphore);
|
||||
@@ -6685,7 +6686,7 @@ DN_API void DN_OS_ConditionVariableBroadcast (D
|
||||
//
|
||||
// `tc_init_args` customises how much memory is allocated for the thread's TLS context which
|
||||
// contains allocators that are exclusively owned by the thread. You may use
|
||||
// DN_TCInitArgsDefault() for sensible default values.
|
||||
// DN_TcInitArgsDefault() for sensible default values.
|
||||
//
|
||||
// Note not all fields in the thread will be initialised until the thread has itself run its
|
||||
// initialisation code which is entirely dependent on the OS scheduler, scheduling the thread to
|
||||
@@ -6710,7 +6711,7 @@ DN_API void DN_OS_ConditionVariableBroadcast (D
|
||||
// waiting for the thread to join.
|
||||
DN_API bool DN_OS_ThreadInitLane (DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadLane *lane, DN_OSThreadInitArgs init_args, void *user_context);
|
||||
DN_API bool DN_OS_ThreadInit (DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadInitArgs init_args, void *user_context);
|
||||
DN_API bool DN_OS_ThreadJoin (DN_OSThread *thread, DN_U32 timeout_ms, DN_TCDeinitArenas deinit_arenas);
|
||||
DN_API bool DN_OS_ThreadJoin (DN_OSThread *thread, DN_U32 timeout_ms, DN_TcDeinitArenas deinit_arenas);
|
||||
DN_API DN_U32 DN_OS_ThreadID ();
|
||||
DN_API DN_OSThreadInitArgs DN_OS_ThreadInitArgsDefault ();
|
||||
DN_API void DN_OS_ThreadSetNameFmt (char const *fmt, ...);
|
||||
@@ -6745,12 +6746,12 @@ DN_API void DN_OS_ThreadSetNameFmt (c
|
||||
// to broadcast the pointer must have a non-null pointer, all other lanes must pass in a
|
||||
// non-null pointer. A typical use case might look like:
|
||||
/*
|
||||
DN_OSThreadLane *lane = DN_OS_TCThreadLane(); // Get lane from current (t)hread (c)context
|
||||
DN_OSThreadLane *lane = DN_OS_TcThreadLane(); // Get lane from current (t)hread (c)context
|
||||
|
||||
// NOTE: Allocate buffer in lane 0
|
||||
DN_U8 *buffer = nullptr;
|
||||
if (lane->index == 0)
|
||||
buffer = DN_ArenaNewArray(DN_TCMainArena(), DN_U8, DN_Gigabytes(1), DN_ZMem_No);
|
||||
buffer = DN_ArenaNewArray(DN_TcMainArena(), DN_U8, DN_Gigabytes(1), DN_ZMem_No);
|
||||
|
||||
// NOTE: Lane 0 broadcasts the `buffer` pointer to lane 1..N
|
||||
DN_OS_ThreadLaneSync(lane, &buffer);
|
||||
@@ -6784,11 +6785,11 @@ DN_API DN_V2USize DN_OS_ThreadLaneRange (D
|
||||
DN_API DN_OSThreadLaneway DN_OS_ThreadLanewayFromArgs (DN_OSThread* threads, DN_USize threads_count, DN_UPtr* shared_mem);
|
||||
DN_API DN_OSThreadLaneway DN_OS_ThreadLanewayFromArena (DN_USize threads_count, DN_Arena* arena);
|
||||
DN_API void DN_OS_ThreadLanewayDispatch (DN_OSThreadLaneway *laneway, DN_OSThreadFunc *entry_point, DN_OSThreadInitArgs init_args, void *user_context);
|
||||
DN_API void DN_OS_ThreadLanewayJoin (DN_OSThreadLaneway *laneway, DN_U32 timeout_ms, DN_TCDeinitArenas deinit_arenas);
|
||||
DN_API void DN_OS_ThreadLanewayJoin (DN_OSThreadLaneway *laneway, DN_U32 timeout_ms, DN_TcDeinitArenas deinit_arenas);
|
||||
|
||||
DN_API DN_OSThreadLane* DN_OS_TCThreadLane ();
|
||||
DN_API void DN_OS_TCThreadLaneSync (void **ptr_to_share);
|
||||
DN_API DN_OSThreadLane DN_OS_TCThreadLaneEquip (DN_OSThreadLane lane);
|
||||
DN_API DN_OSThreadLane* DN_OS_TcThreadLane ();
|
||||
DN_API void DN_OS_TcThreadLaneSync (void **ptr_to_share);
|
||||
DN_API DN_OSThreadLane DN_OS_TcThreadLaneEquip (DN_OSThreadLane lane);
|
||||
|
||||
DN_API void DN_OS_AsyncInit (DN_OSAsyncCore *async, char *base, DN_USize base_size, DN_OSThread *threads, DN_U32 threads_size);
|
||||
DN_API void DN_OS_AsyncDeinit (DN_OSAsyncCore *async);
|
||||
|
||||
+58
-246
@@ -1,34 +1,17 @@
|
||||
#include "dn_seshc.h"
|
||||
|
||||
struct DN_SHMsgSendAsyncContext_
|
||||
{
|
||||
bool send_success;
|
||||
DN_Arena* arena;
|
||||
DN_SHCLIArgs args;
|
||||
DN_SHMsgSendData send;
|
||||
DN_Str8 msg;
|
||||
bool detached;
|
||||
};
|
||||
|
||||
DN_SHCLIArgs DN_SH_CLIArgsCopy(DN_SHCLIArgs const *src, DN_Arena *arena)
|
||||
{
|
||||
DN_SHCLIArgs result = {};
|
||||
result = *src;
|
||||
result.exe_path = DN_Str8FromStr8Arena(src->exe_path, arena);
|
||||
result.ini_path = DN_Str8FromStr8Arena(src->ini_path, arena);
|
||||
result.seed_node_url = DN_Str8FromStr8Arena(src->seed_node_url, arena);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_Str8 DN_SH_CLIOptionsStr8()
|
||||
{
|
||||
DN_Str8 result = DN_Str8Lit(
|
||||
"SESHC OPTIONS (note all options must be set to activate Seshc):\n"
|
||||
" --seshc-exe-path <path> Path to the Seshc EXE file to invoke for sending messages\n"
|
||||
" --seshc-ini-path <path> Path to the .ini file to load Seshc arguments from\n"
|
||||
" (such as account secrets, display name, recipient...)\n"
|
||||
" --seshc-seed-node <url> URL to the Session seed node for determining the nodes to\n"
|
||||
" send the message to\n"
|
||||
" --seshc-exe-path <path> Path to the Seshc EXE file to invoke for sending messages\n"
|
||||
" --seshc-account-secret <secret> Specify the secret of the Session account to send a message\n"
|
||||
" as (see --help on the Seshc EXE for more info)\n"
|
||||
" --seshc-seed-node <url> URL to the Session seed node for determining the nodes to\n"
|
||||
" send the message to\n"
|
||||
" --seshc-display-name <name> Display name to send the message as\n"
|
||||
" --seshc-recipient-pkey <name> Recipient to send the message as (must be 0x05 prefixed, 0x\n"
|
||||
" is optional)"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@@ -57,16 +40,10 @@ DN_SHCLIEatArgResult DN_SH_CLIEatArg(DN_SHCLIArgs *args, char const **arg_ptr, i
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.eaten && DN_Str8EqInsensitive(arg, DN_Str8Lit("--seshc-ini-path"))) {
|
||||
if (!result.eaten && DN_Str8EqInsensitive(arg, DN_Str8Lit("--seshc-account-secret"))) {
|
||||
(void)DN_ArgShift(result.arg_ptr, result.arg_count);
|
||||
result.eaten = true;
|
||||
args->ini_path = DN_Str8FromCStr8(DN_ArgShift(result.arg_ptr, result.arg_count));
|
||||
|
||||
if (DN_OS_PathInfo(args->ini_path).type != DN_OSPathInfoType_File) {
|
||||
result.error_msg = DN_Str8Lit("Seshc ini path does not point to a file");
|
||||
result.error_arg = args->ini_path;
|
||||
args->ini_path = {};
|
||||
}
|
||||
result.eaten = true;
|
||||
args->account_secret = DN_Str8FromCStr8(DN_ArgShift(result.arg_ptr, result.arg_count));
|
||||
}
|
||||
|
||||
if (!result.eaten && DN_Str8EqInsensitive(arg, DN_Str8Lit("--seshc-seed-node"))) {
|
||||
@@ -74,230 +51,65 @@ DN_SHCLIEatArgResult DN_SH_CLIEatArg(DN_SHCLIArgs *args, char const **arg_ptr, i
|
||||
result.eaten = true;
|
||||
args->seed_node_url = DN_Str8FromCStr8(DN_ArgShift(result.arg_ptr, result.arg_count));
|
||||
}
|
||||
|
||||
if (!result.eaten && DN_Str8EqInsensitive(arg, DN_Str8Lit("--seshc-display-name"))) {
|
||||
(void)DN_ArgShift(result.arg_ptr, result.arg_count);
|
||||
result.eaten = true;
|
||||
args->display_name = DN_Str8FromCStr8(DN_ArgShift(result.arg_ptr, result.arg_count));
|
||||
}
|
||||
|
||||
if (!result.eaten && DN_Str8EqInsensitive(arg, DN_Str8Lit("--seshc-recipient-pkey"))) {
|
||||
(void)DN_ArgShift(result.arg_ptr, result.arg_count);
|
||||
result.eaten = true;
|
||||
args->recipient_pkey = DN_Str8FromCStr8(DN_ArgShift(result.arg_ptr, result.arg_count));
|
||||
|
||||
DN_Str8 check = DN_Str8TrimHexPrefix(args->recipient_pkey);
|
||||
if (!DN_Str8StartsWithSensitive(check, DN_Str8Lit("05"))) {
|
||||
result.error_msg = DN_Str8Lit("Seshc recipient public key does not have a 05 prefix");
|
||||
result.error_arg = args->recipient_pkey;
|
||||
args->recipient_pkey = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args->seed_node_url.count && args->exe_path.count && args->ini_path.count)
|
||||
if (args->seed_node_url.count && args->account_secret.count && args->exe_path.count && args->display_name.count && args->recipient_pkey.count)
|
||||
args->valid = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DN_SH_MsgSendBlockingFmt(DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, char const *fmt, ...)
|
||||
{
|
||||
bool result = false;
|
||||
if (cli_args->valid) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DN_Str8 msg = DN_Str8FromFmtVArena(&scratch.arena, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
DN_Str8 account_secret_arg = DN_Str8Lit("--account-secret");
|
||||
DN_Str8 seed_node_url_arg = DN_Str8Lit("--seed-node-url");
|
||||
DN_Str8 display_name_arg = DN_Str8Lit("--display-name");
|
||||
DN_Str8 ini_path_arg = DN_Str8Lit("--ini-path");
|
||||
DN_Str8 send_arg = DN_Str8Lit("send");
|
||||
|
||||
DN_Str8 cmds[16] = {};
|
||||
DN_USize cmds_count = 0;
|
||||
DN_LArrayAppend(cmds, &cmds_count, cli_args->exe_path);
|
||||
|
||||
DN_LArrayAppend(cmds, &cmds_count, account_secret_arg);
|
||||
DN_LArrayAppend(cmds, &cmds_count, send.account_secret);
|
||||
|
||||
DN_LArrayAppend(cmds, &cmds_count, seed_node_url_arg);
|
||||
DN_LArrayAppend(cmds, &cmds_count, cli_args->seed_node_url);
|
||||
|
||||
if (send.display_name.count) {
|
||||
DN_LArrayAppend(cmds, &cmds_count, display_name_arg);
|
||||
DN_LArrayAppend(cmds, &cmds_count, send.display_name);
|
||||
}
|
||||
|
||||
DN_LArrayAppend(cmds, &cmds_count, ini_path_arg);
|
||||
DN_LArrayAppend(cmds, &cmds_count, cli_args->ini_path);
|
||||
|
||||
DN_LArrayAppend(cmds, &cmds_count, send_arg);
|
||||
DN_LArrayAppend(cmds, &cmds_count, send.recipient);
|
||||
|
||||
DN_LArrayAppend(cmds, &cmds_count, msg);
|
||||
|
||||
DN_Str8Slice cmd_line = {};
|
||||
cmd_line.data = cmds;
|
||||
cmd_line.count = cmds_count;
|
||||
|
||||
DN_OSExecArgs exec_args = {};
|
||||
exec_args.flags |= DN_OSExecFlags_SaveOutput;
|
||||
|
||||
DN_OSExecResult exec = DN_OS_Exec(cmd_line, &exec_args, &scratch.arena, nullptr);
|
||||
result = exec.os_error_code == 0 && exec.exit_code == 0;
|
||||
if (!result) {
|
||||
DN_LogErrorF("Error sending message to %.*s (exit code: %d, os: %d): %.*s",
|
||||
DN_Str8PrintFmt(send.recipient),
|
||||
exec.exit_code,
|
||||
exec.os_error_code,
|
||||
DN_Str8PrintFmt(exec.stderr_text));
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int DN_SH_MsgSendDetachedFmtThreadFunc_(DN_OSThread *thread)
|
||||
{
|
||||
DN_SHMsgSendAsyncContext_ *context = DN_Cast(DN_SHMsgSendAsyncContext_ *) thread->user_context;
|
||||
context->send_success = DN_SH_MsgSendBlockingFmt(context->send, &context->args, "%.*s", DN_Str8PrintFmt(context->msg));
|
||||
if (context->detached)
|
||||
DN_ArenaDeinit(context->arena);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DN_SHMsgSendAsyncHandle DN_SH_MsgSendAsyncFmtVMaybeDetached_(DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Arena *arena, bool detached, char const *fmt, va_list args)
|
||||
{
|
||||
DN_SHMsgSendAsyncHandle result = {};
|
||||
if (!cli_args->valid)
|
||||
return result;
|
||||
|
||||
// NOTE: Setup context
|
||||
DN_SHMsgSendAsyncContext_ *context = DN_ArenaNewZ(arena, DN_SHMsgSendAsyncContext_);
|
||||
context->args = DN_SH_CLIArgsCopy(cli_args, arena);
|
||||
context->send = send;
|
||||
context->arena = arena;
|
||||
context->msg = DN_Str8FromFmtVArena(arena, fmt, args);
|
||||
context->detached = detached;
|
||||
|
||||
// NOTE: Execute and forget
|
||||
DN_OSThreadInitArgs thread_args = DN_OS_ThreadInitArgsDefault();
|
||||
if (detached)
|
||||
thread_args.flags |= DN_OSThreadFlags_Detached;
|
||||
|
||||
DN_OS_ThreadInit(&result.thread, DN_SH_MsgSendDetachedFmtThreadFunc_, thread_args, context);
|
||||
return result;
|
||||
}
|
||||
|
||||
void DN_SH_MsgSendDetachedFmt(DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, char const *fmt, ...)
|
||||
{
|
||||
DN_Arena arena_stack = DN_OS_ArenaFromHeapVirtual(0, 0, DN_MemFlags_Nil);
|
||||
DN_Arena *arena = DN_ArenaNewZ(&arena_stack, DN_Arena);
|
||||
*arena = arena_stack;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DN_SH_MsgSendAsyncFmtVMaybeDetached_(send, cli_args, arena, /*detached=*/ true, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
DN_SHMsgSendAsyncHandle DN_SH_MsgSendAsyncFmt(DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Arena *arena, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DN_SHMsgSendAsyncHandle result = DN_SH_MsgSendAsyncFmtVMaybeDetached_(send, cli_args, arena, /*detached=*/ false, fmt, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_SHMsgSendAsyncStatus DN_SH_MsgSendAsyncWait(DN_SHMsgSendAsyncHandle *handle, DN_U32 timeout_ms)
|
||||
{
|
||||
DN_SHMsgSendAsyncStatus result = DN_SHMsgSendAsyncStatus_Success;
|
||||
if (handle && handle->thread.user_context) {
|
||||
bool joined = DN_OS_ThreadJoin(&handle->thread, timeout_ms, DN_TCDeinitArenas_Yes);
|
||||
if (joined) {
|
||||
DN_SHMsgSendAsyncContext_ *context = DN_Cast(DN_SHMsgSendAsyncContext_ *) handle->thread.user_context;
|
||||
result = context->send_success ? DN_SHMsgSendAsyncStatus_Success : DN_SHMsgSendAsyncStatus_Failed;
|
||||
*handle = {};
|
||||
} else {
|
||||
result = DN_SHMsgSendAsyncStatus_Timeout;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void DN_SH_LogBroadcastFmtV(DN_SHLogMode mode, DN_LogType type, DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Str8 short_desc, char const *fmt, va_list args)
|
||||
bool DN_SH_CLIArgsSendDMFmt(DN_SHCLIArgs *cli_args, DN_Str8 sesh_pkey_hex, char const *fmt, ...)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 msg = DN_Str8FromFmtVArena(&scratch.arena, fmt, args);
|
||||
DN_Str8 prefix = {};
|
||||
switch (type) {
|
||||
case DN_LogType_Debug: prefix = DN_Str8Lit("🐞 "); break;
|
||||
case DN_LogType_Info: prefix = DN_Str8Lit("ℹ️ "); break;
|
||||
case DN_LogType_Warning: prefix = DN_Str8Lit("⚠️ "); break;
|
||||
case DN_LogType_Error: prefix = DN_Str8Lit("🚨 "); break;
|
||||
case DN_LogType_Count: break;
|
||||
}
|
||||
DN_LogF(type, "%.*s%.*s\n%.*s", DN_Str8PrintFmt(prefix), DN_Str8PrintFmt(short_desc), DN_Str8PrintFmt(msg));
|
||||
|
||||
DN_Date date = DN_OS_DateLocalTimeNow();
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DN_Str8 msg = DN_Str8FromFmtVArena(&scratch.arena, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
// NOTE: 12-hour conversion
|
||||
DN_U8 hour12 = date.hour % 12;
|
||||
if (hour12 == 0)
|
||||
hour12 = 12;
|
||||
char const *am_pm = date.hour < 12 ? "AM" : "PM";
|
||||
DN_Str8 cmds[] = {
|
||||
cli_args->exe_path,
|
||||
DN_Str8Lit("--account-secret"),
|
||||
cli_args->account_secret,
|
||||
DN_Str8Lit("--seed-node-url"),
|
||||
cli_args->seed_node_url,
|
||||
DN_Str8Lit("--display-name"),
|
||||
DN_Str8FromFmtArena(&scratch.arena, "\"%.*s\"", DN_Str8PrintFmt(cli_args->display_name)),
|
||||
DN_Str8Lit("send"),
|
||||
sesh_pkey_hex,
|
||||
msg,
|
||||
};
|
||||
|
||||
// Time-of-day emoji
|
||||
DN_Str8 time_emoji = {};
|
||||
if (date.hour >= 5 && date.hour <= 11)
|
||||
time_emoji = DN_Str8Lit("☀️");
|
||||
else if (date.hour >= 12 && date.hour <= 16)
|
||||
time_emoji = DN_Str8Lit("🌤️");
|
||||
else if (date.hour >= 17 && date.hour <= 19)
|
||||
time_emoji = DN_Str8Lit("🌅");
|
||||
else if (date.hour >= 20 && date.hour <= 23)
|
||||
time_emoji = DN_Str8Lit("✨");
|
||||
else
|
||||
time_emoji = DN_Str8Lit("🌑");
|
||||
DN_Str8Slice cmd_line = {};
|
||||
cmd_line.data = cmds;
|
||||
cmd_line.count = DN_ArrayCountU(cmds);
|
||||
|
||||
if (mode == DN_SHLogMode_Detached) {
|
||||
DN_SH_MsgSendDetachedFmt(send,
|
||||
cli_args,
|
||||
"%.*s%.*s\n"
|
||||
"%.*s %u-%02u-%02u %u:%02u:%02u %s\n"
|
||||
"%.*s",
|
||||
DN_Str8PrintFmt(prefix),
|
||||
DN_Str8PrintFmt(short_desc),
|
||||
DN_Str8PrintFmt(time_emoji),
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
hour12,
|
||||
date.minutes,
|
||||
date.seconds,
|
||||
am_pm,
|
||||
DN_Str8PrintFmt(msg));
|
||||
} else {
|
||||
DN_Assert(mode == DN_SHLogMode_Blocking);
|
||||
DN_SH_MsgSendBlockingFmt(send,
|
||||
cli_args,
|
||||
"%.*s %.*s\n"
|
||||
"%.*s %u-%02u-%02u %u:%02u:%02u %s\n"
|
||||
"%.*s",
|
||||
DN_Str8PrintFmt(prefix),
|
||||
DN_Str8PrintFmt(short_desc),
|
||||
DN_Str8PrintFmt(time_emoji),
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
hour12,
|
||||
date.minutes,
|
||||
date.seconds,
|
||||
am_pm,
|
||||
DN_Str8PrintFmt(msg));
|
||||
}
|
||||
DN_OSExecArgs exec_args = {};
|
||||
exec_args.flags |= DN_OSExecFlags_SaveOutput;
|
||||
DN_OSExecResult exec = DN_OS_Exec(cmd_line, &exec_args, &scratch.arena, nullptr);
|
||||
DN_LogInfoF("OUT (exit code:%zu, os: %zu): %.*s", exec.exit_code, exec.os_error_code, DN_Str8PrintFmt(exec.stdout_text));
|
||||
DN_LogInfoF("ERR: %.*s", DN_Str8PrintFmt(exec.stderr_text));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
void DN_SH_LogBroadcastBlockingFmt(DN_LogType type, DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Str8 short_desc, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DN_SH_LogBroadcastFmtV(DN_SHLogMode_Blocking, type, send, cli_args, short_desc, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DN_SH_LogBroadcastDetachedFmt(DN_LogType type, DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Str8 short_desc, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DN_SH_LogBroadcastFmtV(DN_SHLogMode_Detached, type, send, cli_args, short_desc, fmt, args);
|
||||
va_end(args);
|
||||
bool result = exec.os_error_code == 0 && exec.exit_code == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
+6
-52
@@ -10,8 +10,10 @@ struct DN_SHCLIArgs
|
||||
{
|
||||
bool valid;
|
||||
DN_Str8 exe_path;
|
||||
DN_Str8 ini_path;
|
||||
DN_Str8 account_secret;
|
||||
DN_Str8 seed_node_url;
|
||||
DN_Str8 display_name;
|
||||
DN_Str8 recipient_pkey;
|
||||
};
|
||||
|
||||
struct DN_SHCLIEatArgResult
|
||||
@@ -23,60 +25,12 @@ struct DN_SHCLIEatArgResult
|
||||
DN_USize arg_count; // Next argument count that that the caller should assume
|
||||
};
|
||||
|
||||
struct DN_SHMsgSendData
|
||||
{
|
||||
DN_Str8 recipient; // Either `ini:<section.key>` or "05-prefix session account ID"
|
||||
DN_Str8 account_secret; // Seshc EXE --account-secret format
|
||||
DN_Str8 display_name;
|
||||
};
|
||||
|
||||
struct DN_SHMsgSendAsyncHandle
|
||||
{
|
||||
DN_OSThread thread;
|
||||
};
|
||||
|
||||
enum DN_SHLogMode
|
||||
{
|
||||
DN_SHLogMode_Blocking,
|
||||
DN_SHLogMode_Detached,
|
||||
};
|
||||
|
||||
enum DN_SHMsgSendAsyncStatus
|
||||
{
|
||||
DN_SHMsgSendAsyncStatus_Timeout,
|
||||
DN_SHMsgSendAsyncStatus_Success,
|
||||
DN_SHMsgSendAsyncStatus_Failed,
|
||||
};
|
||||
|
||||
|
||||
// NOTE: Seshc
|
||||
// Overview
|
||||
// Helper library that provides some useful APIs for programatically calling the Seshc CLI
|
||||
// executable to send messages from your C/C++ application.
|
||||
|
||||
// API
|
||||
// DN_SH_MsgSendDetachedFmt
|
||||
// Send a 1-on-1 message with a background thread that is spawned on demand and detached. If the
|
||||
// application exits before this thread has completed sending the message, the message will not
|
||||
// be sent.
|
||||
|
||||
// DN_SH_MsgSendBlockingFmt
|
||||
// Send a 1-on-1 message using the current executing thread, blocking control-flow until the
|
||||
// message has been sent. Returns true if the send was successful, false otherwise.
|
||||
|
||||
// DN_SH_MsgSendAsyncFmt
|
||||
// Send a 1-on-1 message with a background thread that is spawned on demand. A handle to the
|
||||
// thread is returned that can be waited on.
|
||||
|
||||
DN_SHCLIArgs DN_SH_CLIArgsCopy (DN_SHCLIArgs const *src, DN_Arena *arena);
|
||||
DN_Str8 DN_SH_CLIOptionsStr8 ();
|
||||
DN_SHCLIEatArgResult DN_SH_CLIEatArg (DN_SHCLIArgs *args, char const **arg_ptr, int arg_count);
|
||||
bool DN_SH_MsgSendBlockingFmt (DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, char const *fmt, ...);
|
||||
void DN_SH_MsgSendDetachedFmt (DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, char const *fmt, ...);
|
||||
DN_SHMsgSendAsyncHandle DN_SH_MsgSendAsyncFmt (DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Arena *arena, char const *fmt, ...);
|
||||
DN_SHMsgSendAsyncStatus DN_SH_MsgSendAsyncWait (DN_SHMsgSendAsyncHandle *handle, DN_U32 timeout_ms);
|
||||
void DN_SH_LogBroadcastFmtV (DN_SHLogMode mode, DN_LogType type, DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Str8 short_desc, char const *fmt, va_list args);
|
||||
void DN_SH_LogBroadcastBlockingFmt (DN_LogType type, DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Str8 short_desc, char const *fmt, ...);
|
||||
void DN_SH_LogBroadcastDetachedFmt (DN_LogType type, DN_SHMsgSendData send, DN_SHCLIArgs *cli_args, DN_Str8 short_desc, char const *fmt, ...);
|
||||
DN_Str8 DN_SH_CLIOptionsStr8 ();
|
||||
DN_SHCLIEatArgResult DN_SH_CLIEatArg (DN_SHCLIArgs *args, char const **arg_ptr, int arg_count);
|
||||
bool DN_SH_CLIArgsSendDMFmt(DN_SHCLIArgs *cli_args, DN_Str8 sesh_pkey_hex, char const *fmt, ...);
|
||||
|
||||
#endif // #if !defined(DN_SESHC_H)
|
||||
|
||||
+34
-34
@@ -228,7 +228,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_TCScratchBeginArena(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 = {};
|
||||
@@ -237,11 +237,11 @@ DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
|
||||
result.avail = info.f_bavail * info.f_frsize;
|
||||
result.size = info.f_blocks * info.f_frsize;
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_Str8 DN_OS_EXEPath(DN_Arena *arena)
|
||||
DN_API DN_Str8 DN_OS_ExePath(DN_Arena *arena)
|
||||
{
|
||||
DN_Str8 result = {};
|
||||
if (!arena)
|
||||
@@ -387,7 +387,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_TCScratchBeginArena(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,
|
||||
@@ -400,7 +400,7 @@ DN_API bool DN_OS_FileCopy(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink
|
||||
DN_Str8PrintFmt(file_size_str8),
|
||||
error_code,
|
||||
strerror(error_code));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -513,10 +513,10 @@ 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_TCScratchBeginArena(nullptr, 0);
|
||||
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);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -532,10 +532,10 @@ 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_TCScratchBeginArena(nullptr, 0);
|
||||
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);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -623,7 +623,7 @@ DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
|
||||
DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
bool result = true;
|
||||
|
||||
// TODO(doyle): Implement this without using the path indexes, it's not
|
||||
@@ -650,7 +650,7 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
// NOTE: There's something that exists in at this path, but
|
||||
// it's not a directory. This request to make a directory is
|
||||
// invalid.
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return false;
|
||||
} else if (DN_OS_PathIsDir(copy)) {
|
||||
// NOTE: We found a directory, we can stop here and start
|
||||
@@ -675,7 +675,7 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
if (index != 0)
|
||||
copy.data[path_index] = temp;
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -789,7 +789,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_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
if (arena && handle.stdout_read) {
|
||||
char buffer[4096];
|
||||
DN_Str8Builder builder = DN_Str8BuilderFromArena(&scratch.arena);
|
||||
@@ -817,7 +817,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle,
|
||||
|
||||
result.stderr_text = DN_Str8FromStr8BuilderArena(&builder, arena);
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
close(stdout_pipe[DN_OSPipeType__Read]);
|
||||
@@ -826,25 +826,25 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle,
|
||||
}
|
||||
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
DN_OSExecArgs *args,
|
||||
DN_OSExecArgs args,
|
||||
DN_ErrSink *error)
|
||||
{
|
||||
#if defined(DN_PLATFORM_EMSCRIPTEN)
|
||||
DN_AssertInvalidCodePathF("Unsupported operation");
|
||||
#endif
|
||||
DN_VerifyWarningF(args->environment.count == 0, "Environment variables are unimplemented in POSIX");
|
||||
DN_VerifyWarningF(args.environment.count == 0, "Environment variables are unimplemented in POSIX");
|
||||
DN_OSExecAsyncHandle result = {};
|
||||
if (cmd_line.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_DEFER { DN_TCScratchEnd(&scratch); };
|
||||
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] = {};
|
||||
int stderr_pipe[DN_OSPipeType__Count] = {};
|
||||
|
||||
// NOTE: Open stdout pipe
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStdout)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStdout)) {
|
||||
if (pipe(stdout_pipe) == -1) {
|
||||
result.os_error_code = errno;
|
||||
DN_ErrSinkAppendF(
|
||||
@@ -868,8 +868,8 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
};
|
||||
|
||||
// NOTE: Open stderr pipe //////////////////////////////////////////////////////////////////////
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStderr)) {
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStderr)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
stderr_pipe[DN_OSPipeType__Read] = stdout_pipe[DN_OSPipeType__Read];
|
||||
stderr_pipe[DN_OSPipeType__Write] = stdout_pipe[DN_OSPipeType__Write];
|
||||
} else if (pipe(stderr_pipe) == -1) {
|
||||
@@ -907,7 +907,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
}
|
||||
|
||||
if (child_pid == 0) { // Child process
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStdout) &&
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStdout) &&
|
||||
(dup2(stdout_pipe[DN_OSPipeType__Write], STDOUT_FILENO) == -1)) {
|
||||
result.os_error_code = errno;
|
||||
DN_ErrSinkAppendF(
|
||||
@@ -919,7 +919,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
return result;
|
||||
}
|
||||
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStderr) &&
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStderr) &&
|
||||
(dup2(stderr_pipe[DN_OSPipeType__Write], STDERR_FILENO) == -1)) {
|
||||
result.os_error_code = errno;
|
||||
DN_ErrSinkAppendF(
|
||||
@@ -962,9 +962,9 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
free(prev_working_dir);
|
||||
};
|
||||
|
||||
if (args->working_dir.count) {
|
||||
if (args.working_dir.count) {
|
||||
prev_working_dir = get_current_dir_name();
|
||||
DN_Str8 working_dir = DN_Str8FromStr8Arena(args->working_dir, &scratch.arena);
|
||||
DN_Str8 working_dir = DN_Str8FromStr8Arena(args.working_dir, &scratch.arena);
|
||||
if (chdir(working_dir.data) == -1) {
|
||||
result.os_error_code = errno;
|
||||
DN_ErrSinkAppendF(
|
||||
@@ -999,7 +999,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
&stdout_pipe[DN_OSPipeType__Write],
|
||||
sizeof(stdout_pipe[DN_OSPipeType__Write]));
|
||||
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStderr) && DN_BitIsNotSet(args->flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStderr) && DN_BitIsNotSet(args.flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
DN_Memcpy(&result.stderr_read,
|
||||
&stderr_pipe[DN_OSPipeType__Read],
|
||||
sizeof(stderr_pipe[DN_OSPipeType__Read]));
|
||||
@@ -1007,7 +1007,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
&stderr_pipe[DN_OSPipeType__Write],
|
||||
sizeof(stderr_pipe[DN_OSPipeType__Write]));
|
||||
}
|
||||
result.exec_flags = args->flags;
|
||||
result.exec_flags = args.flags;
|
||||
DN_Memcpy(&result.process, &child_pid, sizeof(child_pid));
|
||||
return result;
|
||||
}
|
||||
@@ -1017,7 +1017,7 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
size_t *stdout_size,
|
||||
char *stderr_buffer,
|
||||
size_t *stderr_size,
|
||||
DN_U32 timeout_ms,
|
||||
DN_U32 timeout_ms,
|
||||
DN_ErrSink *err)
|
||||
{
|
||||
DN_AssertInvalidCodePath;
|
||||
@@ -1322,7 +1322,7 @@ DN_API bool DN_OS_ThreadInitLane(DN_OSThread *thread, DN_OSThreadFunc *func, DN_
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API bool DN_OS_ThreadJoin(DN_OSThread *thread, DN_U32 timeout_ms, DN_TCDeinitArenas deinit_arenas)
|
||||
DN_API bool DN_OS_ThreadJoin(DN_OSThread *thread, DN_U32 timeout_ms, DN_TcDeinitArenas deinit_arenas)
|
||||
{
|
||||
bool result = true;
|
||||
if (thread && thread->handle) {
|
||||
@@ -1337,7 +1337,7 @@ DN_API bool DN_OS_ThreadJoin(DN_OSThread *thread, DN_U32 timeout_ms, DN_TCDeinit
|
||||
pthread_join(thread_id, &return_val);
|
||||
thread->handle = {};
|
||||
thread->thread_id = {};
|
||||
DN_TCDeinit(&thread->context, deinit_arenas);
|
||||
DN_TcDeinit(&thread->context, deinit_arenas);
|
||||
DN_OS_SemaphoreDeinit(&thread->join_done_sem);
|
||||
} else {
|
||||
result = false;
|
||||
@@ -1371,11 +1371,11 @@ DN_API void DN_OS_PosixThreadSetName(DN_Str8 name)
|
||||
#if defined(DN_PLATFORM_EMSCRIPTEN)
|
||||
(void)name;
|
||||
#else
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(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);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1395,7 +1395,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_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
char buf[256];
|
||||
DN_Str8Builder builder = DN_Str8BuilderFromArena(&scratch.arena);
|
||||
for (;;) {
|
||||
@@ -1439,7 +1439,7 @@ DN_API DN_OSPosixProcSelfStatus DN_OS_PosixProcSelfStatus()
|
||||
DN_Assert(to_u64.success);
|
||||
}
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
DN_OS_FileClose(&file);
|
||||
return result;
|
||||
|
||||
+81
-79
@@ -210,7 +210,7 @@ DN_API void DN_OS_GenBytesSecure(void *buffer, DN_U32 size)
|
||||
|
||||
DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_OSDiskSpace result = {};
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
|
||||
@@ -221,36 +221,36 @@ DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
|
||||
&free_bytes_avail_to_caller,
|
||||
&total_number_of_bytes,
|
||||
&total_number_of_free_bytes)) {
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.success = true;
|
||||
result.avail = free_bytes_avail_to_caller.QuadPart;
|
||||
result.size = total_number_of_bytes.QuadPart;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API bool DN_OS_SetEnvVar(DN_Str8 name, DN_Str8 value)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 name16 = DN_OS_W32Str8ToStr16(&scratch.arena, name);
|
||||
DN_Str16 value16 = DN_OS_W32Str8ToStr16(&scratch.arena, value);
|
||||
bool result = SetEnvironmentVariableW(name16.data, value16.data) != 0;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_Str8 DN_OS_EXEPath(DN_Arena *arena)
|
||||
DN_API DN_Str8 DN_OS_ExePath(DN_Arena *arena)
|
||||
{
|
||||
DN_Str8 result = {};
|
||||
if (!arena)
|
||||
return result;
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
DN_Str16 exe_dir16 = DN_OS_W32EXEPathW(&scratch.arena);
|
||||
result = DN_OS_W32Str16ToStr8(arena, exe_dir16);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ static DN_U64 DN_OS_W32FileTimeToSeconds_(FILETIME const *time)
|
||||
DN_API bool DN_OS_FileCopy(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink *err)
|
||||
{
|
||||
bool result = false;
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 src16 = DN_OS_W32Str8ToStr16(&scratch.arena, src);
|
||||
DN_Str16 dest16 = DN_OS_W32Str8ToStr16(&scratch.arena, dest);
|
||||
|
||||
@@ -304,14 +304,14 @@ DN_API bool DN_OS_FileCopy(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink
|
||||
win_error.code,
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API bool DN_OS_FileMove(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink *err)
|
||||
{
|
||||
bool result = false;
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 src16 = DN_OS_W32Str8ToStr16(&scratch.arena, src);
|
||||
DN_Str16 dest16 = DN_OS_W32Str8ToStr16(&scratch.arena, dest);
|
||||
|
||||
@@ -330,7 +330,7 @@ DN_API bool DN_OS_FileMove(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink
|
||||
win_error.code,
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ DN_API DN_OSFile DN_OS_FileOpen(DN_Str8 path, DN_OSFileOpen open_mode, DN_OSFile
|
||||
access_mode |= GENERIC_EXECUTE;
|
||||
}
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
void *handle = CreateFileW(/*LPCWSTR lpFileName*/ path16.data,
|
||||
/*DWORD dwDesiredAccess*/ access_mode,
|
||||
@@ -381,12 +381,12 @@ DN_API DN_OSFile DN_OS_FileOpen(DN_Str8 path, DN_OSFileOpen open_mode, DN_OSFile
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
result.error = true;
|
||||
DN_ErrSinkAppendF(err, win_error.code, "Failed to open file at '%.*s': '%.*s'", DN_Str8PrintFmt(path), DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.handle = handle;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -409,15 +409,15 @@ DN_API DN_OSFileRead DN_OS_FileRead(DN_OSFile *file, void *buffer, DN_USize size
|
||||
/*LPDWORD lpNumberOfByesRead*/ &bytes_read,
|
||||
/*LPOVERLAPPED lpOverlapped*/ nullptr);
|
||||
if (read_result == 0) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
DN_ErrSinkAppendF(err, win_error.code, "Failed to read data from file: (%u) %.*s", win_error.code, DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (bytes_read != size) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
DN_ErrSinkAppendF(
|
||||
err,
|
||||
@@ -427,7 +427,7 @@ DN_API DN_OSFileRead DN_OS_FileRead(DN_OSFile *file, void *buffer, DN_USize size
|
||||
DN_Cast(unsigned long) size,
|
||||
win_error.code,
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -451,11 +451,11 @@ DN_API bool DN_OS_FileWritePtr(DN_OSFile *file, void const *buffer, DN_USize siz
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
DN_Str8x32 buffer_size_str8 = DN_Str8x32FromByteCountU64Auto(size);
|
||||
DN_ErrSinkAppendF(err, win_error.code, "Failed to write buffer (%.*s) to file handle: %.*s", DN_Str8PrintFmt(buffer_size_str8), DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -467,10 +467,10 @@ DN_API bool DN_OS_FileFlush(DN_OSFile *file, DN_ErrSink *err)
|
||||
|
||||
BOOL result = FlushFileBuffers(DN_Cast(HANDLE) file->handle);
|
||||
if (!result) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
DN_ErrSinkAppendF(err, win_error.code, "Failed to flush file buffer to disk: %.*s", DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
return DN_Cast(bool) result;
|
||||
@@ -490,12 +490,12 @@ DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
if (!GetFileAttributesExW(path16.data, GetFileExInfoStandard, &attrib_data)) {
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
result.type = DN_OSPathInfoType_File;
|
||||
}
|
||||
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -526,14 +526,14 @@ DN_API bool DN_OS_PathDelete(DN_Str8 path)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.count) {
|
||||
result = DeleteFileW(path16.data);
|
||||
if (!result)
|
||||
result = RemoveDirectoryW(path16.data);
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.count) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
@@ -551,7 +551,7 @@ DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
result = (attrib_data.dwFileAttributes != INVALID_FILE_ATTRIBUTES) &&
|
||||
!(attrib_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.count) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
@@ -570,14 +570,14 @@ DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
(attrib_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
{
|
||||
bool result = true;
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
|
||||
// NOTE: Go back from the end of the string to all the directories in the
|
||||
@@ -610,7 +610,7 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
// NOTE: There's some kind of file that exists at the path
|
||||
// but it's not a directory. This request to make a
|
||||
// directory is invalid.
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -623,7 +623,7 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
path16.data[index] = temp; // Undo null termination
|
||||
}
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -632,7 +632,7 @@ DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
if (path.count == 0 || !it || path.count <= 0)
|
||||
return false;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32FolderIteratorW wide_it = {};
|
||||
DN_Str16 path16 = {};
|
||||
if (it->handle) {
|
||||
@@ -656,7 +656,7 @@ DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
|
||||
path16 = DN_OS_W32Str8ToStr16(&scratch.arena, adjusted_path);
|
||||
if (path16.count <= 0) { // Conversion error
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -668,7 +668,7 @@ DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
it->file_name = DN_Str8FromPtr(it->buffer, size);
|
||||
}
|
||||
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -712,9 +712,9 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DWORD stdout_bytes_available = 0;
|
||||
DWORD stderr_bytes_available = 0;
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DWORD stdout_bytes_available = 0;
|
||||
DWORD stderr_bytes_available = 0;
|
||||
PeekNamedPipe(handle.stdout_read, nullptr, 0, nullptr, &stdout_bytes_available, nullptr);
|
||||
PeekNamedPipe(handle.stderr_read, nullptr, 0, nullptr, &stderr_bytes_available, nullptr);
|
||||
|
||||
@@ -726,9 +726,11 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
result.os_error_code = win_error.code;
|
||||
DN_ErrSinkAppendF(err, result.os_error_code, "Executed command failed to terminate: %.*s", DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
} else if (exec_result == WAIT_TIMEOUT || exec_result == WAIT_OBJECT_0) {
|
||||
}
|
||||
|
||||
if (exec_result == WAIT_TIMEOUT || exec_result == WAIT_OBJECT_0) {
|
||||
// NOTE: Read stdout from process
|
||||
// If the pipes are full, the process will block. We periodically
|
||||
// flush the pipes to make sure this doesn't happen
|
||||
@@ -796,7 +798,7 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
|
||||
result.stdout_text = DN_Str8FromPtr(stdout_buffer, stdout_size ? *stdout_size : 0);
|
||||
result.stderr_text = DN_Str8FromPtr(stderr_buffer, stderr_size ? *stderr_size : 0);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -818,7 +820,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle, DN_Arena *are
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
DN_Str8Builder stdout_builder = {};
|
||||
DN_Str8Builder stderr_builder = {};
|
||||
if (arena) {
|
||||
@@ -843,11 +845,11 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle, DN_Arena *are
|
||||
// NOTE: Get stdout/stderr. If no arena is passed this is a no-op
|
||||
result.stdout_text = DN_Str8FromStr8BuilderArena(&stdout_builder, arena);
|
||||
result.stderr_text = DN_Str8FromStr8BuilderArena(&stderr_builder, arena);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_ErrSink *err)
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_ErrSink *err)
|
||||
{
|
||||
// NOTE: Pre-amble
|
||||
DN_OSExecAsyncHandle result = {};
|
||||
@@ -856,7 +858,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
|
||||
// NOTE: Render the command line into single string to pass into the Win32 API. We'll quote the
|
||||
// string on behalf of the user if there's whitespace in the string
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 cmd = {};
|
||||
{
|
||||
DN_USize count_req = 0;
|
||||
@@ -900,9 +902,9 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
DN_AssertF(cmd.count < DN_Kilobytes(32), "Command exceeds the allowable size in Win32");
|
||||
|
||||
DN_Str16 cmd16 = DN_OS_W32Str8ToStr16(&scratch.arena, cmd);
|
||||
DN_Str16 working_dir16 = DN_OS_W32Str8ToStr16(&scratch.arena, args->working_dir);
|
||||
DN_Str16 working_dir16 = DN_OS_W32Str8ToStr16(&scratch.arena, args.working_dir);
|
||||
DN_Str8Builder env_builder = DN_Str8BuilderFromArena(&scratch.arena);
|
||||
DN_Str8BuilderAppendArrayRef(&env_builder, args->environment.data, args->environment.count);
|
||||
DN_Str8BuilderAppendArrayRef(&env_builder, args.environment.data, args.environment.count);
|
||||
if (env_builder.string_size)
|
||||
DN_Str8BuilderAppendRef(&env_builder, DN_Str8Lit("\0"));
|
||||
|
||||
@@ -927,7 +929,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
}
|
||||
};
|
||||
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStdout)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStdout)) {
|
||||
if (!CreatePipe(&stdout_read, &stdout_write, &save_std_security_attribs, /*nSize*/ 0)) {
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
result.os_error_code = win_error.code;
|
||||
@@ -937,7 +939,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
"Failed to create stdout pipe to redirect the output of the command '%.*s': %.*s",
|
||||
DN_Str8PrintFmt(cmd),
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -950,7 +952,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
"execute command '%.*s': %.*s",
|
||||
DN_Str8PrintFmt(cmd),
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -966,8 +968,8 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
}
|
||||
};
|
||||
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStderr)) {
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStderr)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
stderr_read = stdout_read;
|
||||
stderr_write = stdout_write;
|
||||
} else {
|
||||
@@ -980,7 +982,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
"Failed to create stderr pipe to redirect the output of the command '%.*s': %.*s",
|
||||
DN_Str8PrintFmt(cmd),
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -993,7 +995,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
"execute command '%.*s': %.*s",
|
||||
DN_Str8PrintFmt(cmd),
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1021,7 +1023,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
result.os_error_code = win_error.code;
|
||||
DN_ErrSinkAppendF(err, result.os_error_code, "Failed to execute command '%.*s': %.*s", DN_Str8PrintFmt(cmd), DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1030,12 +1032,12 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
result.process = proc_info.hProcess;
|
||||
result.stdout_read = stdout_read;
|
||||
result.stdout_write = stdout_write;
|
||||
if (DN_BitIsSet(args->flags, DN_OSExecFlags_SaveStderr) && DN_BitIsNotSet(args->flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
if (DN_BitIsSet(args.flags, DN_OSExecFlags_SaveStderr) && DN_BitIsNotSet(args.flags, DN_OSExecFlags_MergeStderrToStdout)) {
|
||||
result.stderr_read = stderr_read;
|
||||
result.stderr_write = stderr_write;
|
||||
}
|
||||
result.exec_flags = args->flags;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
result.exec_flags = args.flags;
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1307,7 +1309,7 @@ DN_API bool DN_OS_ThreadInitLane(DN_OSThread *thread, DN_OSThreadFunc *func, DN_
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API bool DN_OS_ThreadJoin(DN_OSThread *thread, DN_U32 timeout_ms, DN_TCDeinitArenas deinit_arenas)
|
||||
DN_API bool DN_OS_ThreadJoin(DN_OSThread *thread, DN_U32 timeout_ms, DN_TcDeinitArenas deinit_arenas)
|
||||
{
|
||||
bool result = true;
|
||||
if (thread && thread->handle && thread->handle != INVALID_HANDLE_VALUE) {
|
||||
@@ -1318,7 +1320,7 @@ DN_API bool DN_OS_ThreadJoin(DN_OSThread *thread, DN_U32 timeout_ms, DN_TCDeinit
|
||||
CloseHandle(thread->handle);
|
||||
thread->handle = INVALID_HANDLE_VALUE;
|
||||
thread->thread_id = {};
|
||||
DN_TCDeinit(&thread->context, deinit_arenas);
|
||||
DN_TcDeinit(&thread->context, deinit_arenas);
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
@@ -1339,7 +1341,7 @@ DN_API void DN_OS_W32ThreadSetName(DN_Str8 name)
|
||||
//
|
||||
// See: https://learn.microsoft.com/en-us/windows/w32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
|
||||
DN_OSW32Core *w32 = DN_OS_W32GetCore();
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
if (w32->set_thread_description) {
|
||||
DN_Str16 name16 = DN_OS_W32Str8ToStr16(&scratch.arena, name);
|
||||
w32->set_thread_description(GetCurrentThread(), (WCHAR *)name16.data);
|
||||
@@ -1371,7 +1373,7 @@ DN_API void DN_OS_W32ThreadSetName(DN_Str8 name)
|
||||
}
|
||||
DN_MSVC_WARNING_POP
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code)
|
||||
@@ -1582,7 +1584,7 @@ DN_API DN_Str8 DN_OS_W32Str16ToStr8FromHeap(DN_Str16 src)
|
||||
// NOTE: Windows Executable Directory //////////////////////////////////////////
|
||||
DN_API DN_Str16 DN_OS_W32EXEPathW(DN_Arena *arena)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
DN_Str16 result = {};
|
||||
DN_USize module_size = 0;
|
||||
wchar_t *module_path = nullptr;
|
||||
@@ -1590,7 +1592,7 @@ DN_API DN_Str16 DN_OS_W32EXEPathW(DN_Arena *arena)
|
||||
module_size += 256;
|
||||
module_path = DN_ArenaNewArray(&scratch.arena, wchar_t, module_size, DN_ZMem_No);
|
||||
if (!module_path) {
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
module_size = DN_Cast(DN_USize) GetModuleFileNameW(nullptr /*module*/, module_path, DN_Cast(int) module_size);
|
||||
@@ -1604,14 +1606,14 @@ DN_API DN_Str16 DN_OS_W32EXEPathW(DN_Arena *arena)
|
||||
result.count = module_size;
|
||||
DN_Memcpy(result.data, module_path, sizeof(wchar_t) * result.count);
|
||||
result.data[result.count] = 0;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_Str16 DN_OS_W32EXEDirW(DN_Arena *arena)
|
||||
DN_API DN_Str16 DN_OS_W32ExeDirW(DN_Arena *arena)
|
||||
{
|
||||
// TODO(doyle): Implement a DN_Str16_BinarySearchReverse
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
DN_Str16 result = {};
|
||||
DN_USize module_size = 0;
|
||||
wchar_t *module_path = nullptr;
|
||||
@@ -1619,7 +1621,7 @@ DN_API DN_Str16 DN_OS_W32EXEDirW(DN_Arena *arena)
|
||||
module_size += 256;
|
||||
module_path = DN_ArenaNewArray(&scratch.arena, wchar_t, module_size, DN_ZMem_No);
|
||||
if (!module_path) {
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
module_size = DN_Cast(DN_USize) GetModuleFileNameW(nullptr /*module*/, module_path, DN_Cast(int) module_size);
|
||||
@@ -1633,17 +1635,17 @@ DN_API DN_Str16 DN_OS_W32EXEDirW(DN_Arena *arena)
|
||||
result.count = index_of_last_slash;
|
||||
DN_Memcpy(result.data, module_path, sizeof(wchar_t) * result.count);
|
||||
result.data[result.count] = 0;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_Str8 DN_OS_W32WorkingDir(DN_Arena *arena, DN_Str8 suffix)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
DN_Str16 suffix16 = DN_OS_W32Str8ToStr16(&scratch.arena, suffix);
|
||||
DN_Str16 dir16 = DN_OS_W32WorkingDirW(&scratch.arena, suffix16);
|
||||
DN_Str8 result = DN_OS_W32Str16ToStr8(arena, dir16);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1653,26 +1655,26 @@ DN_API DN_Str16 DN_OS_W32WorkingDirW(DN_Arena *arena, DN_Str16 suffix)
|
||||
DN_Str16 result = {};
|
||||
|
||||
// NOTE: required_size is the size required *including* the null-terminator
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&arena, 1);
|
||||
unsigned long required_size = GetCurrentDirectoryW(0, nullptr);
|
||||
unsigned long desired_size = required_size + DN_Cast(unsigned long) suffix.count;
|
||||
|
||||
wchar_t *scratch_w_path = DN_ArenaNewArray(&scratch.arena, wchar_t, desired_size, DN_ZMem_No);
|
||||
if (!scratch_w_path) {
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned long bytes_written_wo_null_terminator = GetCurrentDirectoryW(desired_size, scratch_w_path);
|
||||
if ((bytes_written_wo_null_terminator + 1) != required_size) {
|
||||
// TODO(dn): Error
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
wchar_t *w_path = DN_ArenaNewArray(arena, wchar_t, desired_size, DN_ZMem_No);
|
||||
if (!w_path) {
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1683,7 +1685,7 @@ DN_API DN_Str16 DN_OS_W32WorkingDirW(DN_Arena *arena, DN_Str16 suffix)
|
||||
}
|
||||
|
||||
result = DN_Str16{w_path, DN_Cast(DN_USize)(desired_size - 1)};
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -681,7 +681,7 @@ enum DN_SHA3TestHash
|
||||
|
||||
static void DN_SHA3_TestHashDispatch_(DN_TestCore *test, DN_SHA3TestHash hash_type, DN_Str8 input)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&test->arena, 1);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&test->arena, 1);
|
||||
DN_Str8 input_hex = DN_Str8HexFromPtrBytesArena(input.data, input.count, &scratch.arena, DN_TrimLeadingZero_No);
|
||||
switch (hash_type) {
|
||||
case DN_SHA3TestHash_Count: DN_AssertInvalidCodePath; break;
|
||||
@@ -741,7 +741,7 @@ static void DN_SHA3_TestHashDispatch_(DN_TestCore *test, DN_SHA3TestHash hash_ty
|
||||
DN_TestVerifyBytesEqF(test, DN_Str8FromLitArray(hash.data), DN_Str8FromLitArray(expect.data), "Input: %.*s", DN_Str8PrintFmt(input_hex));
|
||||
} break;
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
DN_TestCore DN_SHA3_TestSuite(DN_Arena *arena)
|
||||
@@ -780,13 +780,13 @@ DN_TestCore DN_SHA3_TestSuite(DN_Arena *arena)
|
||||
|
||||
// NOTE: Test SHA3 against some deterministic inputs generated from a PRNG
|
||||
for (DN_TestScopeF(&result, "[%.*s] Deterministic random inputs", DN_Str8PrintFmt(hash_name))) {
|
||||
DN_PCG32 rng = DN_PCG32Init(0xd48e'be21'2af8'733d);
|
||||
DN_Pcg32 rng = DN_Pcg32Init(0xd48e'be21'2af8'733d);
|
||||
for (DN_USize index = 0; index < 128; index++) {
|
||||
// NOTE: Create a 4kb buffer with the deterministic contents
|
||||
char src[4096] = {};
|
||||
DN_U32 src_size = DN_PCG32Range(&rng, 0, sizeof(src));
|
||||
DN_U32 src_size = DN_Pcg32Range(&rng, 0, sizeof(src));
|
||||
for (DN_USize src_index = 0; src_index < src_size; src_index++)
|
||||
src[src_index] = DN_Cast(char) DN_PCG32Range(&rng, 0, 255);
|
||||
src[src_index] = DN_Cast(char) DN_Pcg32Range(&rng, 0, 255);
|
||||
|
||||
// NOTE: Do the hashing
|
||||
DN_Str8 input = DN_Str8FromPtr(src, src_size);
|
||||
|
||||
+307
-301
File diff suppressed because it is too large
Load Diff
+119
-118
@@ -29,7 +29,7 @@
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DN_Core core = {};
|
||||
DN_Init(&core, DN_InitFlags_Nil, DN_TCInitArgsDefault());
|
||||
DN_Init(&core, DN_InitFlags_Nil, DN_TcInitArgsDefault());
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
@@ -724,7 +724,7 @@ typedef DN_I32 DN_B32;
|
||||
|
||||
#define DN_CountLeadingZerosU64(value) __lzcnt64(value)
|
||||
#define DN_CountLeadingZerosU32(value) __lzcnt(value)
|
||||
#define DN_CPUGetTSC() __rdtsc()
|
||||
#define DN_CPUGetTsc() __rdtsc()
|
||||
#define DN_CompilerReadBarrierAndCPUReadFence _ReadBarrier(); _mm_lfence()
|
||||
#define DN_CompilerWriteBarrierAndCPUWriteFence _WriteBarrier(); _mm_sfence()
|
||||
#elif defined(DN_COMPILER_GCC) || defined(DN_COMPILER_CLANG)
|
||||
@@ -749,9 +749,9 @@ typedef DN_I32 DN_B32;
|
||||
#define DN_CountLeadingZerosU32(value) __builtin_clzl(value)
|
||||
|
||||
#if defined(DN_COMPILER_GCC)
|
||||
#define DN_CPUGetTSC() __rdtsc()
|
||||
#define DN_CPUGetTsc() __rdtsc()
|
||||
#else
|
||||
#define DN_CPUGetTSC() __builtin_readcyclecounter()
|
||||
#define DN_CPUGetTsc() __builtin_readcyclecounter()
|
||||
#endif
|
||||
|
||||
#if defined(DN_PLATFORM_EMSCRIPTEN)
|
||||
@@ -884,7 +884,7 @@ struct DN_CPUIDArgs { int eax; int ecx; };
|
||||
DN_CPU_FEAT_XENTRY(POPCNT) \
|
||||
DN_CPU_FEAT_XENTRY(RDRAND) \
|
||||
DN_CPU_FEAT_XENTRY(RDSEED) \
|
||||
DN_CPU_FEAT_XENTRY(RDTSCP) \
|
||||
DN_CPU_FEAT_XENTRY(RDTscP) \
|
||||
DN_CPU_FEAT_XENTRY(SHA) \
|
||||
DN_CPU_FEAT_XENTRY(SSE) \
|
||||
DN_CPU_FEAT_XENTRY(SSE2) \
|
||||
@@ -893,7 +893,7 @@ struct DN_CPUIDArgs { int eax; int ecx; };
|
||||
DN_CPU_FEAT_XENTRY(SSE42) \
|
||||
DN_CPU_FEAT_XENTRY(SSE4A) \
|
||||
DN_CPU_FEAT_XENTRY(SSSE3) \
|
||||
DN_CPU_FEAT_XENTRY(TSC) \
|
||||
DN_CPU_FEAT_XENTRY(Tsc) \
|
||||
DN_CPU_FEAT_XENTRY(TscInvariant) \
|
||||
DN_CPU_FEAT_XENTRY(VAES) \
|
||||
DN_CPU_FEAT_XENTRY(VPCMULQDQ)
|
||||
@@ -1384,7 +1384,7 @@ typedef DN_U32 DN_CodepointCountFlags;
|
||||
enum DN_CodepointCountFlags_
|
||||
{
|
||||
DN_CodepointCountFlags_Nil = 0,
|
||||
DN_CodepointCountFlags_SkipANSICode = 1 << 0,
|
||||
DN_CodepointCountFlags_SkipAnsiCode = 1 << 0,
|
||||
};
|
||||
|
||||
typedef struct DN_NibbleFromU8Result DN_NibbleFromU8Result;
|
||||
@@ -1588,7 +1588,7 @@ struct DN_ProfilerAnchorArray
|
||||
DN_USize count;
|
||||
};
|
||||
|
||||
typedef DN_U64 (DN_ProfilerTSCNowFunc)();
|
||||
typedef DN_U64 (DN_ProfilerTscNowFunc)();
|
||||
typedef struct DN_Profiler DN_Profiler;
|
||||
struct DN_Profiler
|
||||
{
|
||||
@@ -1598,7 +1598,7 @@ struct DN_Profiler
|
||||
DN_USize anchors_per_frame;
|
||||
DN_U16 parent_zone;
|
||||
bool paused;
|
||||
DN_ProfilerTSCNowFunc *tsc_now;
|
||||
DN_ProfilerTscNowFunc *tsc_now;
|
||||
DN_U64 tsc_frequency;
|
||||
DN_ProfilerZone frame_zone;
|
||||
DN_F64 frame_avg_tsc;
|
||||
@@ -1674,25 +1674,25 @@ struct DN_ErrSink
|
||||
DN_USize stack_size;
|
||||
};
|
||||
|
||||
typedef struct DN_TCScratch DN_TCScratch;
|
||||
struct DN_TCScratch
|
||||
typedef struct DN_TcScratch DN_TcScratch;
|
||||
struct DN_TcScratch
|
||||
{
|
||||
DN_Arena arena;
|
||||
DN_B32 destructed;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
typedef struct DN_TCScratchCpp DN_TCScratchCpp;
|
||||
struct DN_TCScratchCpp
|
||||
typedef struct DN_TcScratchCpp DN_TcScratchCpp;
|
||||
struct DN_TcScratchCpp
|
||||
{
|
||||
DN_TCScratchCpp(DN_Arena **conflicts, DN_USize count);
|
||||
~DN_TCScratchCpp();
|
||||
DN_TCScratch data;
|
||||
DN_TcScratchCpp(DN_Arena **conflicts, DN_USize count);
|
||||
~DN_TcScratchCpp();
|
||||
DN_TcScratch data;
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef struct DN_TCInitArgs DN_TCInitArgs;
|
||||
struct DN_TCInitArgs
|
||||
typedef struct DN_TcInitArgs DN_TcInitArgs;
|
||||
struct DN_TcInitArgs
|
||||
{
|
||||
DN_U64 main_reserve;
|
||||
DN_U64 main_commit;
|
||||
@@ -1703,8 +1703,8 @@ struct DN_TCInitArgs
|
||||
DN_U64 err_sink_commit;
|
||||
};
|
||||
|
||||
typedef struct DN_TCCore DN_TCCore;
|
||||
struct DN_TCCore // (T)hread (C)ontext sitting in thread-local storage
|
||||
typedef struct DN_TcCore DN_TcCore;
|
||||
struct DN_TcCore // (T)hread (C)ontext sitting in thread-local storage
|
||||
{
|
||||
DN_Str8x64 name;
|
||||
DN_U64 thread_id;
|
||||
@@ -1722,13 +1722,13 @@ struct DN_TCCore // (T)hread (C)ontext sitting in thread-local storage
|
||||
DN_Arena* frame_arena;
|
||||
};
|
||||
|
||||
typedef enum DN_TCDeinitArenas {
|
||||
DN_TCDeinitArenas_No,
|
||||
DN_TCDeinitArenas_Yes,
|
||||
} DN_TCDeinitArenas;
|
||||
typedef enum DN_TcDeinitArenas {
|
||||
DN_TcDeinitArenas_No,
|
||||
DN_TcDeinitArenas_Yes,
|
||||
} DN_TcDeinitArenas;
|
||||
|
||||
typedef struct DN_PCG32 DN_PCG32;
|
||||
struct DN_PCG32 { DN_U64 state; };
|
||||
typedef struct DN_Pcg32 DN_Pcg32;
|
||||
struct DN_Pcg32 { DN_U64 state; };
|
||||
|
||||
typedef struct DN_Murmur3 DN_Murmur3;
|
||||
struct DN_Murmur3 { DN_U64 e[2]; };
|
||||
@@ -1762,10 +1762,10 @@ struct DN_LogTypeParam
|
||||
DN_Str8 str8;
|
||||
};
|
||||
|
||||
typedef enum DN_ANSIColourMode {
|
||||
DN_ANSIColourMode_Fg,
|
||||
DN_ANSIColourMode_Bg,
|
||||
} DN_ANSIColourMode;
|
||||
typedef enum DN_AnsiColourMode {
|
||||
DN_AnsiColourMode_Fg,
|
||||
DN_AnsiColourMode_Bg,
|
||||
} DN_AnsiColourMode;
|
||||
|
||||
typedef struct DN_LogDate DN_LogDate;
|
||||
struct DN_LogDate
|
||||
@@ -2472,7 +2472,7 @@ struct DN_OSThreadInitArgs
|
||||
{
|
||||
// NOTE: Customise much memory the thread's TLS context will be initialised with which contains
|
||||
// persistent/temporary allocators and misc facilities that each thread has exclusive access to.
|
||||
DN_TCInitArgs tc_args;
|
||||
DN_TcInitArgs tc_args;
|
||||
|
||||
// NOTE: Set how much stack space in bytes the thread will have. Leave this value to 0 to defer
|
||||
// to the OS's default stack size.
|
||||
@@ -2503,7 +2503,7 @@ struct DN_OSThread
|
||||
{
|
||||
DN_OSThreadFlags flags;
|
||||
DN_Str8x64 name;
|
||||
DN_TCCore context;
|
||||
DN_TcCore context;
|
||||
DN_OSThreadLane lane;
|
||||
bool is_lane_set;
|
||||
void *handle;
|
||||
@@ -2515,7 +2515,7 @@ struct DN_OSThread
|
||||
#if !defined(DN_PLATFORM_WIN32)
|
||||
DN_OSSemaphore join_done_sem;
|
||||
#endif
|
||||
DN_TCInitArgs tc_init_args;
|
||||
DN_TcInitArgs tc_init_args;
|
||||
};
|
||||
|
||||
typedef DN_U32 DN_OSLogFlags;
|
||||
@@ -2523,7 +2523,7 @@ enum DN_OSLoggerFlags_
|
||||
{
|
||||
DN_OSLoggerFlags_Nil = 0,
|
||||
DN_OSLoggerFlags_File = 1 << 0, // Write the log to disk
|
||||
DN_OSLoggerFlags_NoColour = 1 << 2, // Prevent outputting logs with ANSI colour codes (note: logs written to disk never use colour)
|
||||
DN_OSLoggerFlags_NoColour = 1 << 2, // Prevent outputting logs with Ansi colour codes (note: logs written to disk never use colour)
|
||||
DN_OSLoggerFlags_NoOutput = 1 << 3, // Prevent outputting to the terminal
|
||||
|
||||
// NOTE: Internal flags, do not use
|
||||
@@ -2629,7 +2629,7 @@ typedef struct DN_Core DN_Core;
|
||||
struct DN_Core
|
||||
{
|
||||
DN_InitFlags init_flags;
|
||||
DN_TCCore main_tc;
|
||||
DN_TcCore main_tc;
|
||||
DN_USize mem_allocs_frame;
|
||||
DN_LeakTracker leak;
|
||||
|
||||
@@ -2660,10 +2660,10 @@ struct DN_Core
|
||||
// optionally call `DN_BeginFrame` which resets some metrics that are counted for example it
|
||||
// tracks the number of memory allocations for the current frame and that counter can be reset.
|
||||
//
|
||||
// For convenience you can opt into some sane defaults for the `DN_TCInitArgs` which customises
|
||||
// how thread-local storage is setup with `DN_TCInitArgsDefault()` which produces a
|
||||
// `DN_TCInitArgs` object you can pass in by value.
|
||||
DN_API void DN_Init (DN_Core *dn, DN_InitFlags flags, DN_TCInitArgs args);
|
||||
// For convenience you can opt into some sane defaults for the `DN_TcInitArgs` which customises
|
||||
// how thread-local storage is setup with `DN_TcInitArgsDefault()` which produces a
|
||||
// `DN_TcInitArgs` object you can pass in by value.
|
||||
DN_API void DN_Init (DN_Core *dn, DN_InitFlags flags, DN_TcInitArgs args);
|
||||
DN_API void DN_Set (DN_Core *dn);
|
||||
DN_API DN_Core* DN_Get ();
|
||||
DN_API void DN_BeginFrame ();
|
||||
@@ -2671,10 +2671,10 @@ DN_API void DN_BeginFrame
|
||||
DN_API bool DN_VerifyArgsF (DN_VerifyType type, bool expr, DN_CallSite call_site, DN_Str8 expr_str8, char const *fmt, ...);
|
||||
DN_API bool DN_VerifyArgs (DN_VerifyType type, bool expr, DN_CallSite call_site, DN_Str8 expr_str8);
|
||||
|
||||
#define DN_SPrintF(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__)
|
||||
#define DN_SNPrintF(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__)
|
||||
#define DN_VSPrintF(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__)
|
||||
#define DN_VSNPrintF(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__)
|
||||
#define DN_Sprintf(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__)
|
||||
#define DN_Snprintf(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__)
|
||||
#define DN_Vsprintf(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__)
|
||||
#define DN_Vsnprintf(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__)
|
||||
|
||||
DN_API bool DN_MemStartsWith (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
DN_API bool DN_MemEq (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
@@ -2742,7 +2742,7 @@ DN_API void DN_BitSetInplace
|
||||
DN_API bool DN_BitIsSet (DN_USize bits, DN_USize bits_to_set);
|
||||
DN_API bool DN_BitIsNotSet (DN_USize bits, DN_USize bits_to_check);
|
||||
DN_API bool DN_BitIsAny (DN_USize bits, DN_USize bits_to_check);
|
||||
#define DN_BitClearNextLSB(value) (value) & ((value) - 1)
|
||||
#define DN_BitClearNextLsb(value) (value) & ((value) - 1)
|
||||
|
||||
DN_API DN_I64 DN_SafeAddI64 (DN_I64 a, DN_I64 b);
|
||||
DN_API DN_I64 DN_SafeMulI64 (DN_I64 a, DN_I64 b);
|
||||
@@ -2971,24 +2971,24 @@ DN_API void DN_ErrSinkAppendFV_
|
||||
DN_API void DN_ErrSinkAppendF_ (DN_ErrSink *err, DN_U32 error_code, DN_CallSite call_site, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
#define DN_ErrSinkAppendF(error, error_code, fmt, ...) DN_ErrSinkAppendF_(error, error_code, DN_CallSiteNow, fmt, ##__VA_ARGS__)
|
||||
|
||||
DN_API DN_TCInitArgs DN_TCInitArgsDefault ();
|
||||
DN_API void DN_TCInit (DN_TCCore *tc, DN_U64 thread_id, DN_Arena *main_arena, DN_Arena *temp_arenas, DN_USize temp_arenas_count, DN_Arena *err_sink_arena);
|
||||
DN_API void DN_TCInitFromHeap (DN_TCCore *tc, DN_U64 thread_id, DN_TCInitArgs args, DN_Heap heap);
|
||||
DN_API void DN_TCDeinit (DN_TCCore *tc, DN_TCDeinitArenas deinit_arenas);
|
||||
DN_API void DN_TCEquip (DN_TCCore *tc);
|
||||
DN_API DN_TCCore* DN_TCGet ();
|
||||
DN_API DN_Arena* DN_TCMainArena ();
|
||||
DN_API DN_Pool* DN_TCMainPool ();
|
||||
DN_API DN_Arena DN_TCTempArenaFromAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_Arena DN_TCTempArenaFromArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API DN_TCScratch DN_TCScratchBeginAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_TCScratch DN_TCScratchBeginArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API void DN_TCScratchEnd (DN_TCScratch *scratch);
|
||||
DN_API void DN_TCSetFrameArena (DN_Arena *arena);
|
||||
DN_API DN_Arena* DN_TCFrameArena ();
|
||||
DN_API DN_ErrSink* DN_TCErrSink ();
|
||||
#define DN_TCErrSinkBegin(mode) DN_ErrSinkBegin(DN_TCErrSink(), mode)
|
||||
#define DN_TCErrSinkBeginDefault() DN_ErrSinkBeginDefault(DN_TCErrSink())
|
||||
DN_API DN_TcInitArgs DN_TcInitArgsDefault ();
|
||||
DN_API void DN_TcInit (DN_TcCore *tc, DN_U64 thread_id, DN_Arena *main_arena, DN_Arena *temp_arenas, DN_USize temp_arenas_count, DN_Arena *err_sink_arena);
|
||||
DN_API void DN_TcInitFromHeap (DN_TcCore *tc, DN_U64 thread_id, DN_TcInitArgs args, DN_Heap heap);
|
||||
DN_API void DN_TcDeinit (DN_TcCore *tc, DN_TcDeinitArenas deinit_arenas);
|
||||
DN_API void DN_TcEquip (DN_TcCore *tc);
|
||||
DN_API DN_TcCore* DN_TcGet ();
|
||||
DN_API DN_Arena* DN_TcMainArena ();
|
||||
DN_API DN_Pool* DN_TcMainPool ();
|
||||
DN_API DN_Arena DN_TcTempArenaFromAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_Arena DN_TcTempArenaFromArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API DN_TcScratch DN_TcScratchBeginAllocator (DN_Allocator *conflicts, DN_USize count);
|
||||
DN_API DN_TcScratch DN_TcScratchBeginArena (DN_Arena **conflicts, DN_USize count);
|
||||
DN_API void DN_TcScratchEnd (DN_TcScratch *scratch);
|
||||
DN_API void DN_TcSetFrameArena (DN_Arena *arena);
|
||||
DN_API DN_Arena* DN_TcFrameArena ();
|
||||
DN_API DN_ErrSink* DN_TcErrSink ();
|
||||
#define DN_TcErrSinkBegin(mode) DN_ErrSinkBegin(DN_TcErrSink(), mode)
|
||||
#define DN_TcErrSinkBeginDefault() DN_ErrSinkBeginDefault(DN_TcErrSink())
|
||||
|
||||
DN_API bool DN_CharIsAlphabet (char ch);
|
||||
DN_API bool DN_CharIsDigit (char ch);
|
||||
@@ -3062,12 +3062,12 @@ DN_API DN_Str8 DN_Str8FromPtrPool
|
||||
DN_API DN_Str8 DN_Str8FromStr8Allocator (DN_Str8 string, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Arena (DN_Str8 string, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Pool (DN_Str8 string, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8FromFmtVAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FromFmtVArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FromFmtAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromFmtArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromFmtVPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FromFmtPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtVAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FmtVArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FmtAllocator (DN_Allocator allocator, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtArena (DN_Arena *arena, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtVPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FmtPool (DN_Pool *pool, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
|
||||
DN_API DN_Str8x16 DN_Str8x16FromFmt (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8x16 DN_Str8x16FromFmtV (DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
@@ -3285,8 +3285,8 @@ DN_API DN_Str8x32 DN_Str8x32FromByteCountU64
|
||||
// API
|
||||
// DN_ProfilerInit
|
||||
// You can set `tsc_now` to NULL to use the default timer mechanic which relies on
|
||||
// DN_CPUGetTSC() which essentially uses __rdtsc. `tsc_frequency` must however always be
|
||||
// provided, for, DN_CPUGetTSC() you can use `DN_OS_EstimateTSCPerSecond()` to calculate the
|
||||
// DN_CPUGetTsc() which essentially uses __rdtsc. `tsc_frequency` must however always be
|
||||
// provided, for, DN_CPUGetTsc() you can use `DN_OS_EstimateTscPerSecond()` to calculate the
|
||||
// frequency of `__rdtsc`.
|
||||
// DN_ProfilerNewFrame
|
||||
// Always call `DN_ProfilerNewFrame` at-least once using the `Zone` family of functions as it
|
||||
@@ -3305,7 +3305,7 @@ DN_API DN_Str8x32 DN_Str8x32FromByteCountU64
|
||||
DN_ProfilerEndZone(DN_UniqueName(zone_)), DN_UniqueName(dummy_).begin_tsc = 1
|
||||
|
||||
#define DN_ProfilerZoneLoopAuto(prof, name) DN_ProfilerZoneLoop(prof, name, __COUNTER__ + 1)
|
||||
DN_API DN_Profiler DN_ProfilerInit (DN_ProfilerAnchor *anchors, DN_USize count, DN_USize anchors_per_frame, DN_ProfilerTSCNowFunc *tsc_now, DN_U64 tsc_frequency);
|
||||
DN_API DN_Profiler DN_ProfilerInit (DN_ProfilerAnchor *anchors, DN_USize count, DN_USize anchors_per_frame, DN_ProfilerTscNowFunc *tsc_now, DN_U64 tsc_frequency);
|
||||
DN_API DN_ProfilerZone DN_ProfilerBeginZone (DN_Profiler *profiler, DN_Str8 name, DN_U16 anchor_index);
|
||||
#define DN_ProfilerBeginZoneAuto(prof, name) DN_ProfilerBeginZone(prof, DN_Str8Lit(name), __COUNTER__ + 1)
|
||||
DN_API void DN_ProfilerEndZone (DN_ProfilerZone zone);
|
||||
@@ -3316,8 +3316,8 @@ DN_API void DN_ProfilerNewFrame
|
||||
DN_API DN_USize DN_ProfilerFmtAnchor (DN_ProfilerAnchor anchor, DN_U64 tsc_frequency, char *buffer, DN_USize count);
|
||||
DN_API DN_Str8 DN_ProfilerFmtAnchorStr8 (DN_ProfilerAnchor anchor, DN_U64 tsc_frequency, DN_Arena *arena);
|
||||
DN_API void DN_ProfilerFmtToStdout (DN_Profiler *profiler);
|
||||
DN_API DN_F64 DN_ProfilerSecFromTSC (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
DN_API DN_F64 DN_ProfilerMsFromTSC (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
DN_API DN_F64 DN_ProfilerSecFromTsc (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
DN_API DN_F64 DN_ProfilerMsFromTsc (DN_Profiler *profiler, DN_U64 duration_tsc);
|
||||
|
||||
DN_API void DN_QSort (void *array, DN_USize array_size, DN_USize elem_size, void *user_context, DN_QSortCompareFunc *compare);
|
||||
DN_API bool DN_QSortCompareStr8NaturalAsc (void const* lhs, void const *rhs, void *user_context);
|
||||
@@ -3340,24 +3340,24 @@ DN_API DN_BSearchResult DN_BSearchUSize
|
||||
DN_API DN_BSearchResult DN_BSearchU64 (DN_U64 const *array, DN_USize count, DN_U64 find, DN_BSearchType type);
|
||||
DN_API DN_BSearchResult DN_BSearchU32 (DN_U32 const *array, DN_USize count, DN_U32 find, DN_BSearchType type);
|
||||
|
||||
DN_API DN_PCG32 DN_PCG32Init (DN_U64 seed);
|
||||
DN_API DN_U32 DN_PCG32Next (DN_PCG32 *rng);
|
||||
DN_API DN_U64 DN_PCG32Next64 (DN_PCG32 *rng);
|
||||
DN_API DN_U32 DN_PCG32Range (DN_PCG32 *rng, DN_U32 low, DN_U32 high);
|
||||
DN_API DN_F32 DN_PCG32NextF32 (DN_PCG32 *rng);
|
||||
DN_API DN_F64 DN_PCG32NextF64 (DN_PCG32 *rng);
|
||||
DN_API void DN_PCG32Advance (DN_PCG32 *rng, DN_U64 delta);
|
||||
DN_API DN_Pcg32 DN_Pcg32Init (DN_U64 seed);
|
||||
DN_API DN_U32 DN_Pcg32Next (DN_Pcg32 *rng);
|
||||
DN_API DN_U64 DN_Pcg32Next64 (DN_Pcg32 *rng);
|
||||
DN_API DN_U32 DN_Pcg32Range (DN_Pcg32 *rng, DN_U32 low, DN_U32 high);
|
||||
DN_API DN_F32 DN_Pcg32NextF32 (DN_Pcg32 *rng);
|
||||
DN_API DN_F64 DN_Pcg32NextF64 (DN_Pcg32 *rng);
|
||||
DN_API void DN_Pcg32Advance (DN_Pcg32 *rng, DN_U64 delta);
|
||||
|
||||
#if !defined(DN_FNV1A32_SEED)
|
||||
#define DN_FNV1A32_SEED 2166136261U
|
||||
#if !defined(DN_Fnv1a32_SEED)
|
||||
#define DN_Fnv1a32_SEED 2166136261U
|
||||
#endif
|
||||
|
||||
#if !defined(DN_FNV1A64_SEED)
|
||||
#define DN_FNV1A64_SEED 14695981039346656037ULL
|
||||
#if !defined(DN_Fnv1a64_SEED)
|
||||
#define DN_Fnv1a64_SEED 14695981039346656037ULL
|
||||
#endif
|
||||
|
||||
DN_API DN_U32 DN_FNV1AHashU32FromBytes (void const *bytes, DN_USize count, DN_U32 seed);
|
||||
DN_API DN_U64 DN_FNV1AHashU64FromBytes (void const *bytes, DN_USize count, DN_U64 seed);
|
||||
DN_API DN_U32 DN_Fnv1aHashU32FromBytes (void const *bytes, DN_USize count, DN_U32 seed);
|
||||
DN_API DN_U64 DN_Fnv1aHashU64FromBytes (void const *bytes, DN_USize count, DN_U64 seed);
|
||||
|
||||
DN_API DN_U32 DN_Murmur3HashU32FromBytesX86 (void const *bytes, int len, DN_U32 seed);
|
||||
DN_API DN_Murmur3 DN_Murmur3HashU128FromBytesX64 (void const *bytes, int len, DN_U32 seed);
|
||||
@@ -3370,15 +3370,15 @@ DN_API DN_U32 DN_Murmur3HashU32FromBytesX64
|
||||
#define DN_Murmur3HashU32FromBytes(bytes, len, seed) DN_Murmur3HashU32FromBytesX86(bytes, len, seed)
|
||||
#endif
|
||||
|
||||
#define DN_ANSICodeBoldLit "\x1b[1m"
|
||||
#define DN_ANSICodeResetLit "\x1b[0m"
|
||||
DN_API DN_Str8x32 DN_Str8x32FromANSIColourCodeU8RGB (DN_ANSIColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromANSIColourCodeV3F32RGB255 (DN_ANSIColourMode mode, DN_V3F32 rgb_255);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromANSIColourCodeU32RGB (DN_ANSIColourMode mode, DN_U32 value);
|
||||
DN_API DN_Str8 DN_Str8FromStr8ANSIColourU8RGBArena (DN_ANSIColourMode mode, DN_Str8 str8, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8ANSIColourV3F32RGB255Arena (DN_ANSIColourMode mode, DN_Str8 str8, DN_V3F32 rgb_255, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromFmtANSIColourU8RGBArena (DN_ANSIColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena, char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromFmtANSIColourV3F32RGB255Arena (DN_ANSIColourMode mode, DN_V3F32 rgb_255, DN_Arena *arena, char const *fmt, ...);
|
||||
#define DN_AnsiCodeBoldLit "\x1b[1m"
|
||||
#define DN_AnsiCodeResetLit "\x1b[0m"
|
||||
DN_API DN_Str8x32 DN_Str8x32FromAnsiColourCodeU8Rgb (DN_AnsiColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromAnsiColourCodeV3F32Rgb255 (DN_AnsiColourMode mode, DN_V3F32 rgb_255);
|
||||
DN_API DN_Str8x32 DN_Str8x32FromAnsiColourCodeU32Rgb (DN_AnsiColourMode mode, DN_U32 value);
|
||||
DN_API DN_Str8 DN_Str8FromStr8AnsiColourU8RgbArena (DN_AnsiColourMode mode, DN_Str8 str8, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8AnsiColourV3F32Rgb255Arena (DN_AnsiColourMode mode, DN_Str8 str8, DN_V3F32 rgb_255, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FmtAnsiColourU8RgbArena (DN_AnsiColourMode mode, DN_U8 r, DN_U8 g, DN_U8 b, DN_Arena *arena, char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FmtAnsiColourV3F32Rgb255Arena (DN_AnsiColourMode mode, DN_V3F32 rgb_255, DN_Arena *arena, char const *fmt, ...);
|
||||
|
||||
// NOTE: Create log printable lines with a date prefix, severity and message. The platform
|
||||
// implementation should call `SetPrintFunc` to intercept the log messages and output to the desired
|
||||
@@ -3580,7 +3580,7 @@ DN_API DN_F32 DN_V2F32Area
|
||||
|
||||
// NOTE: Grayscale co-efficients from:
|
||||
// https://github.com/EpicGames/UnrealEngine/blob/260bb2e1c5610b31c63a36206eedd289409c5f11/Engine/Source/Runtime/Core/Private/Math/Color.cpp#L304
|
||||
DN_V3F32 static const DN_V3F32_RGB_LUMINANCE = DN_V3F32From3N(0.3f, 0.59f, 0.11f);
|
||||
DN_V3F32 static const DN_V3F32_Rgb_LUMINANCE = DN_V3F32From3N(0.3f, 0.59f, 0.11f);
|
||||
|
||||
DN_API bool operator== (DN_V3F32 lhs, DN_V3F32 rhs);
|
||||
DN_API bool operator!= (DN_V3F32 lhs, DN_V3F32 rhs);
|
||||
@@ -3613,16 +3613,16 @@ DN_API DN_V3F32 DN_V3F32Normalise
|
||||
#define DN_V4F32From1N(x) DN_Literal(DN_V4F32){{(DN_F32)(x), (DN_F32)(x), (DN_F32)(x), (DN_F32)(x)}}
|
||||
#define DN_V4F32From4N(x, y, z, w) DN_Literal(DN_V4F32){{(DN_F32)(x), (DN_F32)(y), (DN_F32)(z), (DN_F32)(w)}}
|
||||
#define DN_V4F32FromV3And1N(xyz, w) DN_Literal(DN_V4F32){{xyz.x, xyz.y, xyz.z, w}}
|
||||
#define DN_V4F32RGBA01FromRGBAU8(r, g, b, a) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, a / 255.f}}
|
||||
#define DN_V4F32RGBA01FromRGBU8(r, g, b) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, 1.f}}
|
||||
#define DN_V4F32Rgba01FromRgbaU8(r, g, b, a) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, a / 255.f}}
|
||||
#define DN_V4F32Rgba01FromRgbU8(r, g, b) DN_Literal(DN_V4F32){{r / 255.f, g / 255.f, b / 255.f, 1.f}}
|
||||
|
||||
DN_API DN_V4F32 DN_V4F32Lerp (DN_V4F32 lhs, DN_F32 t01, DN_V4F32 rhs);
|
||||
DN_API bool DN_V4F32RGBA01IsValid (DN_V4F32 rgba01);
|
||||
DN_API DN_V4F32 DN_V4F32RGBA01FromRGBU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32RGBA01FromRGBAU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01FromSRGB01 (DN_V4F32 rgb01);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01Desaturate (DN_V4F32 linear01, DN_F32 t01);
|
||||
DN_API DN_V4F32 DN_V4F32SRGB01FromLinear01 (DN_V4F32 linear01);
|
||||
DN_API bool DN_V4F32Rgba01IsValid (DN_V4F32 rgba01);
|
||||
DN_API DN_V4F32 DN_V4F32Rgba01FromRgbU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32Rgba01FromRgbaU32 (DN_U32 u32);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01FromSrgb01 (DN_V4F32 rgb01);
|
||||
DN_API DN_V4F32 DN_V4F32Linear01Desaturate (DN_V4F32 linear01, DN_F32 t01);
|
||||
DN_API DN_V4F32 DN_V4F32Srgb01FromLinear01 (DN_V4F32 linear01);
|
||||
|
||||
#define DN_V4F32FromV4Alpha(v4, alpha) DN_V4F32FromV3And1N(v4.xyz, alpha)
|
||||
|
||||
@@ -4608,8 +4608,8 @@ DN_API DN_U64 DN_OS_DateLocalUnixTimeSFromUnixTimeS (D
|
||||
DN_API void DN_OS_GenBytesSecure (void *buffer, DN_U32 size);
|
||||
DN_API bool DN_OS_SetEnvVar (DN_Str8 name, DN_Str8 value);
|
||||
DN_API DN_OSDiskSpace DN_OS_DiskSpace (DN_Str8 path);
|
||||
DN_API DN_Str8 DN_OS_EXEPath (DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_OS_EXEDir (DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_OS_ExePath (DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_OS_ExeDir (DN_Arena *arena);
|
||||
DN_API void DN_OS_SleepMs (DN_UInt milliseconds);
|
||||
|
||||
DN_API DN_U64 DN_OS_PerfCounterNow ();
|
||||
@@ -4624,7 +4624,7 @@ DN_API DN_F64 DN_OS_TimerS (D
|
||||
DN_API DN_F64 DN_OS_TimerMs (DN_OSTimer timer);
|
||||
DN_API DN_F64 DN_OS_TimerUs (DN_OSTimer timer);
|
||||
DN_API DN_F64 DN_OS_TimerNs (DN_OSTimer timer);
|
||||
DN_API DN_U64 DN_OS_EstimateTSCPerSecond (uint64_t duration_ms_to_gauge_tsc_frequency);
|
||||
DN_API DN_U64 DN_OS_EstimateTscPerSecond (uint64_t duration_ms_to_gauge_tsc_frequency);
|
||||
|
||||
// NOTE: OS File
|
||||
// Overview
|
||||
@@ -4715,11 +4715,12 @@ DN_API DN_Str8 DN_OS_PathFmtPool (D
|
||||
#define DN_OS_PathBuild(allocator, fs_path) DN_OS_PathBuildWithSeparatorAllocator(allocator, fs_path, DN_OSPathSeparatorStr8)
|
||||
|
||||
DN_API void DN_OS_Exit (int32_t exit_code);
|
||||
DN_API DN_OSExecArgs DN_OS_ExecArgsDefault ();
|
||||
DN_API DN_OSExecResult DN_OS_ExecPump (DN_OSExecAsyncHandle handle, char *stdout_buffer, size_t *stdout_size, char *stderr_buffer, size_t *stderr_size, DN_U32 timeout_ms, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_ExecWait (DN_OSExecAsyncHandle handle, DN_Arena *arena, DN_ErrSink *err);
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync (DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_Exec (DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_Arena *arena, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_ExecOrAbort (DN_Str8Slice cmd_line, DN_OSExecArgs *args, DN_Arena *arena);
|
||||
DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync (DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_Exec (DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_Arena *arena, DN_ErrSink *err);
|
||||
DN_API DN_OSExecResult DN_OS_ExecOrAbort (DN_Str8Slice cmd_line, DN_OSExecArgs args, DN_Arena *arena);
|
||||
|
||||
DN_API DN_OSSemaphore DN_OS_SemaphoreInit (DN_U32 initial_count);
|
||||
DN_API void DN_OS_SemaphoreDeinit (DN_OSSemaphore *semaphore);
|
||||
@@ -4755,7 +4756,7 @@ DN_API void DN_OS_ConditionVariableBroadcast (D
|
||||
//
|
||||
// `tc_init_args` customises how much memory is allocated for the thread's TLS context which
|
||||
// contains allocators that are exclusively owned by the thread. You may use
|
||||
// DN_TCInitArgsDefault() for sensible default values.
|
||||
// DN_TcInitArgsDefault() for sensible default values.
|
||||
//
|
||||
// Note not all fields in the thread will be initialised until the thread has itself run its
|
||||
// initialisation code which is entirely dependent on the OS scheduler, scheduling the thread to
|
||||
@@ -4780,7 +4781,7 @@ DN_API void DN_OS_ConditionVariableBroadcast (D
|
||||
// waiting for the thread to join.
|
||||
DN_API bool DN_OS_ThreadInitLane (DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadLane *lane, DN_OSThreadInitArgs init_args, void *user_context);
|
||||
DN_API bool DN_OS_ThreadInit (DN_OSThread *thread, DN_OSThreadFunc *func, DN_OSThreadInitArgs init_args, void *user_context);
|
||||
DN_API bool DN_OS_ThreadJoin (DN_OSThread *thread, DN_U32 timeout_ms, DN_TCDeinitArenas deinit_arenas);
|
||||
DN_API bool DN_OS_ThreadJoin (DN_OSThread *thread, DN_U32 timeout_ms, DN_TcDeinitArenas deinit_arenas);
|
||||
DN_API DN_U32 DN_OS_ThreadID ();
|
||||
DN_API DN_OSThreadInitArgs DN_OS_ThreadInitArgsDefault ();
|
||||
DN_API void DN_OS_ThreadSetNameFmt (char const *fmt, ...);
|
||||
@@ -4815,12 +4816,12 @@ DN_API void DN_OS_ThreadSetNameFmt (c
|
||||
// to broadcast the pointer must have a non-null pointer, all other lanes must pass in a
|
||||
// non-null pointer. A typical use case might look like:
|
||||
/*
|
||||
DN_OSThreadLane *lane = DN_OS_TCThreadLane(); // Get lane from current (t)hread (c)context
|
||||
DN_OSThreadLane *lane = DN_OS_TcThreadLane(); // Get lane from current (t)hread (c)context
|
||||
|
||||
// NOTE: Allocate buffer in lane 0
|
||||
DN_U8 *buffer = nullptr;
|
||||
if (lane->index == 0)
|
||||
buffer = DN_ArenaNewArray(DN_TCMainArena(), DN_U8, DN_Gigabytes(1), DN_ZMem_No);
|
||||
buffer = DN_ArenaNewArray(DN_TcMainArena(), DN_U8, DN_Gigabytes(1), DN_ZMem_No);
|
||||
|
||||
// NOTE: Lane 0 broadcasts the `buffer` pointer to lane 1..N
|
||||
DN_OS_ThreadLaneSync(lane, &buffer);
|
||||
@@ -4854,11 +4855,11 @@ DN_API DN_V2USize DN_OS_ThreadLaneRange (D
|
||||
DN_API DN_OSThreadLaneway DN_OS_ThreadLanewayFromArgs (DN_OSThread* threads, DN_USize threads_count, DN_UPtr* shared_mem);
|
||||
DN_API DN_OSThreadLaneway DN_OS_ThreadLanewayFromArena (DN_USize threads_count, DN_Arena* arena);
|
||||
DN_API void DN_OS_ThreadLanewayDispatch (DN_OSThreadLaneway *laneway, DN_OSThreadFunc *entry_point, DN_OSThreadInitArgs init_args, void *user_context);
|
||||
DN_API void DN_OS_ThreadLanewayJoin (DN_OSThreadLaneway *laneway, DN_U32 timeout_ms, DN_TCDeinitArenas deinit_arenas);
|
||||
DN_API void DN_OS_ThreadLanewayJoin (DN_OSThreadLaneway *laneway, DN_U32 timeout_ms, DN_TcDeinitArenas deinit_arenas);
|
||||
|
||||
DN_API DN_OSThreadLane* DN_OS_TCThreadLane ();
|
||||
DN_API void DN_OS_TCThreadLaneSync (void **ptr_to_share);
|
||||
DN_API DN_OSThreadLane DN_OS_TCThreadLaneEquip (DN_OSThreadLane lane);
|
||||
DN_API DN_OSThreadLane* DN_OS_TcThreadLane ();
|
||||
DN_API void DN_OS_TcThreadLaneSync (void **ptr_to_share);
|
||||
DN_API DN_OSThreadLane DN_OS_TcThreadLaneEquip (DN_OSThreadLane lane);
|
||||
|
||||
DN_API void DN_OS_AsyncInit (DN_OSAsyncCore *async, char *base, DN_USize base_size, DN_OSThread *threads, DN_U32 threads_size);
|
||||
DN_API void DN_OS_AsyncDeinit (DN_OSAsyncCore *async);
|
||||
|
||||
+2
-2
@@ -27,9 +27,9 @@ DN_MSVC_WARNING_DISABLE(6262) // Function uses '29804' bytes of stack. Consider
|
||||
int main(int, char**)
|
||||
{
|
||||
DN_Core dn = {};
|
||||
DN_Init(&dn, DN_InitFlags_LogAllFeatures | DN_InitFlags_OS, DN_TCInitArgsDefault());
|
||||
DN_Init(&dn, DN_InitFlags_LogAllFeatures | DN_InitFlags_OS, DN_TcInitArgsDefault());
|
||||
|
||||
DN_Arena* arena = DN_TCMainArena();
|
||||
DN_Arena* arena = DN_TcMainArena();
|
||||
DN_TestCore dn_test = DN_TestSuite(arena);
|
||||
DN_TestCore sha3_test = DN_SHA3_TestSuite(arena);
|
||||
DN_Str8 dn_str8 = DN_Str8FromTestCore(&dn_test, arena, DN_Str8FromTestCoreFlags_Colour);
|
||||
|
||||
@@ -26,8 +26,8 @@ struct File
|
||||
|
||||
static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&dest->arena, 1);
|
||||
DN_ErrSink *err = DN_TCErrSinkBeginDefault();
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(&dest->arena, 1);
|
||||
DN_ErrSink *err = DN_TcErrSinkBeginDefault();
|
||||
DN_Str8 buffer = DN_OS_FileReadAllArena(&scratch.arena, cpp_path, err);
|
||||
DN_ErrSinkEndExitIfErrorF(err, -1, "Failed to load file from '%S' for appending", cpp_path);
|
||||
|
||||
@@ -44,7 +44,7 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
if (!inside_clangd_preprocessor_block) {
|
||||
DN_Str8FindResult find = DN_Str8FindStr8(line, DN_Str8Lit("#if defined(_CLANGD)"), DN_Str8EqCase_Sensitive);
|
||||
if (find.found) {
|
||||
line = DN_Str8FromFmtArena(&scratch.arena, "%S// DN: Single header generator commented out => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
line = DN_Str8FmtArena(&scratch.arena, "%S// DN: Single header generator commented out => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
commented_out = true;
|
||||
inside_clangd_preprocessor_block = true;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
if (!ignore.found) {
|
||||
DN_Str8FindResult find = DN_Str8FindStr8(line, DN_Str8Lit("#include \""), DN_Str8EqCase_Sensitive);
|
||||
if (find.found) {
|
||||
line = DN_Str8FromFmtArena(&scratch.arena, "%S// DN: Single header generator commented out => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
line = DN_Str8FmtArena(&scratch.arena, "%S// DN: Single header generator commented out => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
DN_Str8 rel_include_path = DN_Str8TrimWhitespaceAround(find.after_match_to_end_of_buffer);
|
||||
DN_Str8 root_dir = DN_Str8FileDirectoryFromPath(cpp_path);
|
||||
extra_include_path = DN_OS_PathFmtArena(&scratch.arena, "%S/%S", root_dir, DN_Str8TrimSuffixSensitive(rel_include_path, DN_Str8Lit("\"")));
|
||||
@@ -73,7 +73,7 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
// NOTE: Detect if we're at the end of the CLAND block
|
||||
if (inside_clangd_preprocessor_block) {
|
||||
if (!commented_out)
|
||||
line = DN_Str8FromFmtArena(&scratch.arena, "// %S", line);
|
||||
line = DN_Str8FmtArena(&scratch.arena, "// %S", line);
|
||||
if (DN_Str8FindStr8(line, DN_Str8Lit("#endif"), DN_Str8EqCase_Sensitive).found)
|
||||
inside_clangd_preprocessor_block = false;
|
||||
}
|
||||
@@ -84,13 +84,13 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
if (extra_include_path.count)
|
||||
AppendCppFileLineByLine(dest, extra_include_path);
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
DN_TcScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DN_Core dn = {};
|
||||
DN_Init(&dn, DN_InitFlags_OS, DN_TCInitArgsDefault());
|
||||
DN_Init(&dn, DN_InitFlags_OS, DN_TcInitArgsDefault());
|
||||
|
||||
if (argc != 3) {
|
||||
DN_OS_PrintErrF("USAGE: %s <path/to/dn/Source> <output_dir>", argv[0]);
|
||||
@@ -109,7 +109,7 @@ int main(int argc, char **argv)
|
||||
};
|
||||
|
||||
for (DN_ForIndexU(type, FileType_Count)) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_TcScratch scratch = DN_TcScratchBeginArena(nullptr, 0);
|
||||
DN_Str8Builder builder = DN_Str8BuilderFromArena(&scratch.arena);
|
||||
DN_Str8 suffix = type == FileType_Header ? DN_Str8Lit("h") : DN_Str8Lit("cpp");
|
||||
for (DN_ForItCArray(it, DN_Str8 const, REL_FILE_PATHS)) {
|
||||
@@ -122,7 +122,7 @@ int main(int argc, char **argv)
|
||||
|
||||
DN_Str8 buffer = DN_Str8TrimWhitespaceAround(DN_Str8FromStr8BuilderArena(&builder, &scratch.arena));
|
||||
DN_Str8 single_header_path = DN_OS_PathFmtArena(&scratch.arena, "%S/dn_single_header.%S", output_dir, suffix);
|
||||
DN_ErrSink *err = DN_TCErrSinkBeginDefault();
|
||||
DN_ErrSink *err = DN_TcErrSinkBeginDefault();
|
||||
DN_OS_FileWriteAllSafe(single_header_path, buffer, err);
|
||||
DN_ErrSinkEndExitIfErrorF(err, -1, "Failed to write Single header file '%S'", single_header_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user