From 59db6efb3de69b43fd649366bf5cc8945ab26f6c Mon Sep 17 00:00:00 2001 From: churchianity Date: Sun, 2 Jul 2023 22:45:08 -0400 Subject: [PATCH] things --- alloc.cpp | 3 +++ print.cpp | 15 +++++++++------ table.hpp | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/alloc.cpp b/alloc.cpp index 8db667d..d298418 100644 --- a/alloc.cpp +++ b/alloc.cpp @@ -175,7 +175,10 @@ void* Arena::Alloc(u32 sizeInBytes) { u8* p = this->buffer + this->index; u32 offset = (u32) alignForward2((u64) p, 64); + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" if ((void*)(offset + sizeInBytes) <= (this->buffer + this->bufferSizeInBytes)) { + #pragma clang diagnostic pop void* ptr = &this->buffer[offset]; this->index += offset + sizeInBytes; diff --git a/print.cpp b/print.cpp index 3b3d157..ad895d6 100644 --- a/print.cpp +++ b/print.cpp @@ -119,9 +119,11 @@ void trace(String* string) { // the names as provided by 'backtrace_symbols' are mangled for some reason. // we have to demangle them, using this weird api + // example mangled name (wrapped in double quotes): + // "2 shard_tracy 0x00000001032d5618 _ZL17drawSettingsPanelv + 904" char buffer[1024]; - const char* mangledNameBegin = String::firstCharOccurence(traces[i], '_'); - const char* mangledNameEnd = String::lastCharOccurence(traces[i], '+'); + const char* mangledNameBegin = String::lastCharOccurence(traces[i], '_'); + const char* mangledNameEnd = String::lastCharOccurence(traces[i], '+'); // it actually ends one char before. if (mangledNameBegin == null || mangledNameEnd == null) { // we can't demangle this name for some reason, just copy the mangled name to the buffer @@ -138,8 +140,9 @@ void trace(String* string) { s32 status = -1; char* trace = abi::__cxa_demangle(buffer, null, null, &status); if (trace == null) { - println("warning: failed to demangle name: %s", traces[i]); - continue; + println("warning: failed to demangle name: %s, exit status of attempt: %d", traces[i], status); + // just write back the original trace, un-demangled. + trace = traces[i]; } if (string == null) { @@ -225,7 +228,7 @@ static void writeMinidump(EXCEPTION_POINTERS* pep) { // for fatal errors which may occur at runtime, even on a release binary. // if a fatal error should not occur at runtime on a release binary, consider preferring 'massert' -// it's unclear when you should use asserts vs. die actually. idk man +// it's unclear when you should use asserts vs. die actually. idk man, they kinda do the same thing right now void die(const char* format, ...) { ULE_TYPES_H_FTAG; if (format == null) { @@ -258,7 +261,7 @@ void die(const char* format, ...) { } else { String string = String128f(""); - string.setfv(format, args); + string.appendfv(format, args); string.append("\n"); trace(&string); diff --git a/table.hpp b/table.hpp index 1384b50..cf719ff 100644 --- a/table.hpp +++ b/table.hpp @@ -198,8 +198,10 @@ static unsigned int APHash(const char* str, unsigned int length) } #endif +// this is a trick to perform modulus of some u32 |v|, by another u32 |c|, while avoiding a division instruction. +// https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/ static inline u32 fastModuloReductionDanielLemire(u32 v, u32 c) { - return (((u64)v) * ((u64)c)) >> 32; + return (u32)(((u64)v * (u64)c) >> 32); } static inline u32 hash(const char* key, u32 keyLength, u32 capacity) { @@ -261,7 +263,7 @@ struct Table { return (V) 0; } else { // entry already exists, replace its value - // pFree(entry->value); // @NOTE how to cleanup if overwriting an owned pointer? + // pFree(entry->value); // @NOTE how to cleanup if overwriting an owned pointer? V oldValue = entry->value; entry->value = value;