Browse Source

things

master
churchianity 1 year ago
parent
commit
59db6efb3d
  1. 3
      alloc.cpp
  2. 15
      print.cpp
  3. 4
      table.hpp

3
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;

15
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);

4
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) {

Loading…
Cancel
Save