diff --git a/deps/ox/src/ox/fs/filesystem/directory.hpp b/deps/ox/src/ox/fs/filesystem/directory.hpp index 6f36a18e..7d82a0ff 100644 --- a/deps/ox/src/ox/fs/filesystem/directory.hpp +++ b/deps/ox/src/ox/fs/filesystem/directory.hpp @@ -203,9 +203,7 @@ Error Directory::write(PathIterator path, InodeId_t inode, oxTrace("ox::fs::Directory::write") << "Attempting to write to next sub-Directory: " << name->c_str() << " of " << path.fullPath(); - auto [nextChild, err] = findEntry(*name); - oxReturnError(err); - + oxRequire(nextChild, findEntry(*name)); oxTrace("ox::fs::Directory::write") << name->c_str() << ": " << nextChild; if (nextChild) { @@ -227,9 +225,8 @@ Error Directory::write(PathIterator path, InodeId_t inode, // find existing version of directory oxTrace("ox::fs::Directory::write") << "Searching for directory inode" << m_inodeId; - auto oldStat = m_fs.stat(m_inodeId); - oxReturnError(oldStat); - oxTrace("ox::fs::Directory::write") << "Found existing directory of size" << oldStat.value.size; + oxRequire(oldStat, m_fs.stat(m_inodeId)); + oxTrace("ox::fs::Directory::write") << "Found existing directory of size" << oldStat.size; auto old = m_fs.read(m_inodeId).template to(); if (!old.valid()) { oxTrace("ox::fs::Directory::write::fail") << "Could not read existing version of Directory"; @@ -238,8 +235,8 @@ Error Directory::write(PathIterator path, InodeId_t inode, const auto pathSize = name->len() + 1; const auto entryDataSize = DirectoryEntry::DirectoryEntryData::spaceNeeded(pathSize); - const auto newSize = oldStat.value.size + Buffer::spaceNeeded(entryDataSize); - auto cpy = ox_malloca(newSize, Buffer, *old, oldStat.value.size); + const auto newSize = oldStat.size + Buffer::spaceNeeded(entryDataSize); + auto cpy = ox_malloca(newSize, Buffer, *old, oldStat.size); if (cpy == nullptr) { oxTrace("ox::fs::Directory::write::fail") << "Could not allocate memory for copy of Directory"; return OxError(1); @@ -349,11 +346,10 @@ Result Directory::find(Path auto name = nameBuff; oxReturnError(path.get(name)); - auto v = findEntry(name->c_str()); - oxReturnError(v); + oxRequire(v, findEntry(name->c_str())); // recurse if not at end of path if (auto p = path.next(); p.valid()) { - Directory dir(m_fs, v.value); + Directory dir(m_fs, v); name = nullptr; return dir.find(p, nameBuff); } diff --git a/deps/ox/src/ox/mc/read.hpp b/deps/ox/src/ox/mc/read.hpp index d4448aff..2616ebf5 100644 --- a/deps/ox/src/ox/mc/read.hpp +++ b/deps/ox/src/ox/mc/read.hpp @@ -255,8 +255,7 @@ Error MetalClawReader::field(const char* name, ox::Vector *val) { if (m_unionIdx == -1 || m_unionIdx == m_field) { // set size of val if the field is present, don't worry about it if not if (m_fieldPresence.get(m_field)) { - const auto [len, err] = arrayLength(name, false); - oxReturnError(err); + oxRequire(len, arrayLength(name, false)); val->resize(len); } return field(name, val->data(), val->size()); diff --git a/deps/ox/src/ox/std/assert.cpp b/deps/ox/src/ox/std/assert.cpp index a7d5d594..f6583da6 100644 --- a/deps/ox/src/ox/std/assert.cpp +++ b/deps/ox/src/ox/std/assert.cpp @@ -18,7 +18,7 @@ namespace ox { template<> -void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *msg) { +void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *msg) noexcept { if (!pass) { #if defined(OX_USE_STDLIB) std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << msg << std::endl; @@ -32,7 +32,7 @@ void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line } template<> -void assertFunc(const char *file, int line, Error err, const char *assertMsg) { +void assertFunc(const char *file, int line, Error err, const char *assertMsg) noexcept { if (err) { #if defined(OX_USE_STDLIB) std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << assertMsg << '\n'; @@ -53,7 +53,7 @@ void assertFunc(const char *file, int line, Error err, const char *assert } #if defined(OX_USE_STDLIB) -void panic(const char *file, int line, const char *panicMsg, Error err) { +void panic(const char *file, int line, const char *panicMsg, Error err) noexcept { std::cerr << "\033[31;1;1mPANIC:\033[0m (" << file << ':' << line << "): " << panicMsg << '\n'; if (err.msg) { std::cerr << "\tError Message:\t" << err.msg << '\n'; diff --git a/deps/ox/src/ox/std/assert.hpp b/deps/ox/src/ox/std/assert.hpp index 830cdec2..e1ef7862 100644 --- a/deps/ox/src/ox/std/assert.hpp +++ b/deps/ox/src/ox/std/assert.hpp @@ -14,16 +14,16 @@ namespace ox { template -void assertFunc(const char*, int, T, const char*) { +void assertFunc(const char*, int, T, const char*) noexcept { } template<> -void assertFunc(const char *file, int line, bool pass, const char *msg); +void assertFunc(const char *file, int line, bool pass, const char *msg) noexcept; template<> -void assertFunc(const char *file, int line, Error err, const char*); +void assertFunc(const char *file, int line, Error err, const char*) noexcept; -void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *msg, [[maybe_unused]]Error err = OxError(0)); +void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *msg, [[maybe_unused]]Error err = OxError(0)) noexcept; } diff --git a/deps/ox/src/ox/std/byteswap.cpp b/deps/ox/src/ox/std/byteswap.cpp index 42be2766..5c9d1421 100644 --- a/deps/ox/src/ox/std/byteswap.cpp +++ b/deps/ox/src/ox/std/byteswap.cpp @@ -11,12 +11,12 @@ namespace ox { template -static constexpr bool testLittleEndian(T i) { +static constexpr bool testLittleEndian(T i) noexcept { return LittleEndian(i) == i; } template -static constexpr bool testBigEndian(T i) { +static constexpr bool testBigEndian(T i) noexcept { return BigEndian(i) == i; } diff --git a/deps/ox/src/ox/std/byteswap.hpp b/deps/ox/src/ox/std/byteswap.hpp index f987e811..b2ebfb2b 100644 --- a/deps/ox/src/ox/std/byteswap.hpp +++ b/deps/ox/src/ox/std/byteswap.hpp @@ -16,17 +16,20 @@ namespace ox { template -[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] +constexpr T byteSwap(typename enable_if::type i) noexcept { return i; } template -[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] +constexpr T byteSwap(typename enable_if::type i) noexcept { return (i << 8) | (i >> 8); } template -[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] +constexpr T byteSwap(typename enable_if::type i) noexcept { return ((i >> 24) & 0x000000ff) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | @@ -34,7 +37,8 @@ template } template -[[nodiscard]] constexpr inline T byteSwap(typename enable_if::type i) noexcept { +[[nodiscard]] +constexpr T byteSwap(typename enable_if::type i) noexcept { return ((i >> 56) & 0x00000000000000ff) | ((i >> 40) & 0x000000000000ff00) | ((i >> 24) & 0x0000000000ff0000) | @@ -50,7 +54,8 @@ template * Takes an int and byte swaps if the platform is the given condition is true. */ template -[[nodiscard]] constexpr inline T conditionalByteSwap(T i) noexcept { +[[nodiscard]] +constexpr T conditionalByteSwap(T i) noexcept { if constexpr(byteSwap) { return ox::byteSwap(i); } else { @@ -64,118 +69,119 @@ class OX_PACKED ByteSwapInteger { T m_value; public: - constexpr inline ByteSwapInteger() noexcept = default; + constexpr ByteSwapInteger() noexcept = default; - constexpr inline ByteSwapInteger(const ByteSwapInteger &other) noexcept { + constexpr ByteSwapInteger(const ByteSwapInteger &other) noexcept { m_value = other.m_value; } - constexpr inline ByteSwapInteger(T value) noexcept: m_value(ox::conditionalByteSwap(value)) { + constexpr ByteSwapInteger(T value) noexcept: m_value(ox::conditionalByteSwap(value)) { } - constexpr inline const ByteSwapInteger &operator=(const ByteSwapInteger &other) noexcept { + constexpr const ByteSwapInteger &operator=(const ByteSwapInteger &other) noexcept { m_value = other.m_value; return *this; } template - constexpr inline T operator=(I value) noexcept { + constexpr T operator=(I value) noexcept { m_value = ox::conditionalByteSwap(value); return value; } - constexpr inline operator T() const noexcept { + constexpr operator T() const noexcept { return ox::conditionalByteSwap(m_value); } template - constexpr inline T operator+=(I other) noexcept { + constexpr T operator+=(I other) noexcept { auto newVal = *this + other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator-=(I other) noexcept { + constexpr T operator-=(I other) noexcept { auto newVal = *this - other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator*=(I other) noexcept { + constexpr T operator*=(I other) noexcept { auto newVal = *this * other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator/=(I other) noexcept { + constexpr T operator/=(I other) noexcept { auto newVal = *this / other; m_value = ox::conditionalByteSwap(newVal); return newVal; } // Prefix increment - constexpr inline T operator++() noexcept { + constexpr T operator++() noexcept { return operator+=(1); } // Postfix increment - constexpr inline T operator++(int) noexcept { + constexpr T operator++(int) noexcept { auto old = *this; ++*this; return old; } // Prefix decrement - constexpr inline T operator--() noexcept { + constexpr T operator--() noexcept { return operator-=(1); } // Postfix decrement - constexpr inline T operator--(int) noexcept { + constexpr T operator--(int) noexcept { auto old = *this; --*this; return old; } template - constexpr inline T operator&=(I other) noexcept { + constexpr T operator&=(I other) noexcept { auto newVal = *this & other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator|=(I other) noexcept { + constexpr T operator|=(I other) noexcept { auto newVal = *this | other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator^=(I other) noexcept { + constexpr T operator^=(I other) noexcept { auto newVal = *this ^ other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator>>=(I other) noexcept { + constexpr T operator>>=(I other) noexcept { auto newVal = *this >> other; m_value = ox::conditionalByteSwap(newVal); return newVal; } template - constexpr inline T operator<<=(I other) noexcept { + constexpr T operator<<=(I other) noexcept { auto newVal = *this << other; m_value = ox::conditionalByteSwap(newVal); return newVal; } - [[nodiscard]] constexpr auto get() const noexcept -> T { + [[nodiscard]] + constexpr auto get() const noexcept -> T { return static_cast(*this); } @@ -184,7 +190,8 @@ class OX_PACKED ByteSwapInteger { * a little endian integer is returned regardless of the endianness of * the system. */ - [[nodiscard]] constexpr auto raw() const noexcept -> T { + [[nodiscard]] + constexpr auto raw() const noexcept -> T { return m_value; } diff --git a/deps/ox/src/ox/std/heapmgr.cpp b/deps/ox/src/ox/std/heapmgr.cpp index ccb31bd2..9a4f59ec 100644 --- a/deps/ox/src/ox/std/heapmgr.cpp +++ b/deps/ox/src/ox/std/heapmgr.cpp @@ -16,34 +16,34 @@ static struct HeapSegment *volatile g_heapBegin = nullptr; static struct HeapSegment *volatile g_heapEnd = nullptr; static struct HeapSegment *volatile heapIdx = nullptr; -static constexpr std::size_t alignedSize(std::size_t sz) { +static constexpr std::size_t alignedSize(std::size_t sz) noexcept { return sz + (sz & 7); } template -static constexpr std::size_t alignedSize(T = {}) { +static constexpr std::size_t alignedSize(T = {}) noexcept { return alignedSize(sizeof(T)); } -void HeapSegment::init(std::size_t maxSize = ox::bit_cast(g_heapEnd)) { +void HeapSegment::init(std::size_t maxSize = ox::bit_cast(g_heapEnd)) noexcept { this->size = maxSize - ox::bit_cast(this); this->inUse = false; } template -T *HeapSegment::data() { +T *HeapSegment::data() noexcept { return ox::bit_cast(ox::bit_cast(this) + alignedSize(this)); } template -T *HeapSegment::end() { +T *HeapSegment::end() noexcept { const auto size = alignedSize(this) + alignedSize(this->size); auto e = ox::bit_cast(ox::bit_cast(this) + size); return ox::bit_cast(e); } -void initHeap(char *heapBegin, char *heapEnd) { +void initHeap(char *heapBegin, char *heapEnd) noexcept { g_heapBegin = ox::bit_cast(heapBegin); g_heapEnd = ox::bit_cast(heapEnd); heapIdx = g_heapBegin; @@ -56,7 +56,7 @@ struct SegmentPair { HeapSegment *segment = nullptr; }; -static SegmentPair findSegmentOf(void *ptr) { +static SegmentPair findSegmentOf(void *ptr) noexcept { HeapSegment *prev = nullptr; for (auto seg = g_heapBegin; seg < g_heapEnd;) { if (seg->data() == ptr) { @@ -68,7 +68,7 @@ static SegmentPair findSegmentOf(void *ptr) { return {}; } -static HeapSegment *findSegmentFor(std::size_t sz) { +static HeapSegment *findSegmentFor(std::size_t sz) noexcept { for (auto s = g_heapBegin; s <= g_heapEnd; s = s->end()) { if (s->size >= sz && !s->inUse) { return s; @@ -78,7 +78,8 @@ static HeapSegment *findSegmentFor(std::size_t sz) { return nullptr; } -[[nodiscard]] void *malloc(std::size_t allocSize) { +[[nodiscard]] +void *malloc(std::size_t allocSize) noexcept { const auto targetSize = alignedSize(sizeof(HeapSegment)) + alignedSize(allocSize); auto seg = findSegmentFor(targetSize); if (seg == nullptr) { @@ -91,7 +92,7 @@ static HeapSegment *findSegmentFor(std::size_t sz) { return seg->data(); } -void free(void *ptr) { +void free(void *ptr) noexcept { auto p = findSegmentOf(ptr); if (p.anteSegment) { p.anteSegment->size += p.segment->size; @@ -108,35 +109,35 @@ void free(void *ptr) { using namespace ox; -void *operator new(std::size_t allocSize) { +void *operator new(std::size_t allocSize) noexcept { return heapmgr::malloc(allocSize); } -void *operator new[](std::size_t allocSize) { +void *operator new[](std::size_t allocSize) noexcept { return heapmgr::malloc(allocSize); } -void operator delete(void *ptr) { +void operator delete(void *ptr) noexcept { heapmgr::free(ptr); } -void operator delete[](void *ptr) { +void operator delete[](void *ptr) noexcept { heapmgr::free(ptr); } -void operator delete(void *ptr, unsigned) { +void operator delete(void *ptr, unsigned) noexcept { heapmgr::free(ptr); } -void operator delete[](void *ptr, unsigned) { +void operator delete[](void *ptr, unsigned) noexcept { heapmgr::free(ptr); } -void operator delete(void *ptr, unsigned long int) { +void operator delete(void *ptr, unsigned long int) noexcept { heapmgr::free(ptr); } -void operator delete[](void *ptr, unsigned long int) { +void operator delete[](void *ptr, unsigned long int) noexcept { heapmgr::free(ptr); } diff --git a/deps/ox/src/ox/std/heapmgr.hpp b/deps/ox/src/ox/std/heapmgr.hpp index 100ac7a1..81f44ffc 100644 --- a/deps/ox/src/ox/std/heapmgr.hpp +++ b/deps/ox/src/ox/std/heapmgr.hpp @@ -14,20 +14,23 @@ struct HeapSegment { std::size_t size; uint8_t inUse; - void init(std::size_t maxSize); + void init(std::size_t maxSize) noexcept; template - T *data(); + [[nodiscard]] + T *data() noexcept; template - T *end(); + [[nodiscard]] + T *end() noexcept; }; -void initHeap(char *heapBegin, char *heapEnd); +void initHeap(char *heapBegin, char *heapEnd) noexcept; -[[nodiscard]] void *malloc(std::size_t allocSize); +[[nodiscard]] +void *malloc(std::size_t allocSize) noexcept; -void free(void *ptr); +void free(void *ptr) noexcept; } diff --git a/deps/ox/src/ox/std/math.hpp b/deps/ox/src/ox/std/math.hpp index 43352401..7d92bbdc 100644 --- a/deps/ox/src/ox/std/math.hpp +++ b/deps/ox/src/ox/std/math.hpp @@ -13,17 +13,20 @@ namespace ox { template -inline constexpr const T &min(const T &a, const T &b) { +[[nodiscard]] +constexpr const T &min(const T &a, const T &b) noexcept { return a < b ? a : b; } template -inline constexpr const T &max(const T &a, const T &b) { +[[nodiscard]] +constexpr const T &max(const T &a, const T &b) noexcept { return a > b ? a : b; } template -inline constexpr I pow(I v, int e) { +[[nodiscard]] +constexpr I pow(I v, int e) noexcept { I out = 1; for (I i = 0; i < e; i++) { out *= v; diff --git a/deps/ox/src/ox/std/random.cpp b/deps/ox/src/ox/std/random.cpp index 98a6a882..ce27630a 100644 --- a/deps/ox/src/ox/std/random.cpp +++ b/deps/ox/src/ox/std/random.cpp @@ -11,17 +11,17 @@ namespace ox { -Random::Random() { +Random::Random() noexcept { m_seed[0] = 540932923848; m_seed[1] = 540932540932; } -Random::Random(RandomSeed seed) { +Random::Random(RandomSeed seed) noexcept { m_seed[0] = seed[0]; m_seed[1] = seed[1]; } -uint64_t Random::gen() { +uint64_t Random::gen() noexcept { // An implementation of the Xoroshiro128+ algorithm auto s0 = m_seed[0]; auto s1 = m_seed[1]; diff --git a/deps/ox/src/ox/std/random.hpp b/deps/ox/src/ox/std/random.hpp index c897fe8f..3f1c0a09 100644 --- a/deps/ox/src/ox/std/random.hpp +++ b/deps/ox/src/ox/std/random.hpp @@ -20,11 +20,11 @@ class OX_PACKED Random { RandomSeed m_seed; public: - Random(); + Random() noexcept; - explicit Random(RandomSeed seed); + explicit Random(RandomSeed seed) noexcept; - uint64_t gen(); + uint64_t gen() noexcept; }; } diff --git a/deps/ox/src/ox/std/stacktrace.cpp b/deps/ox/src/ox/std/stacktrace.cpp index 6febf771..85436627 100644 --- a/deps/ox/src/ox/std/stacktrace.cpp +++ b/deps/ox/src/ox/std/stacktrace.cpp @@ -17,7 +17,7 @@ namespace ox { -void printStackTrace([[maybe_unused]]int shave) { +void printStackTrace([[maybe_unused]]int shave) noexcept { #if defined(OX_USE_STDLIB) && __has_include() std::array frames; auto size = static_cast(backtrace(frames.data(), frames.size())); diff --git a/deps/ox/src/ox/std/stacktrace.hpp b/deps/ox/src/ox/std/stacktrace.hpp index 15d774fe..6045dc49 100644 --- a/deps/ox/src/ox/std/stacktrace.hpp +++ b/deps/ox/src/ox/std/stacktrace.hpp @@ -15,6 +15,6 @@ namespace ox { * * @param shave number of call levels to shave off the top */ -void printStackTrace(int shave = 1); +void printStackTrace(int shave = 1) noexcept; } diff --git a/deps/ox/src/ox/std/strongint.hpp b/deps/ox/src/ox/std/strongint.hpp index d67dd6b1..7cbeb47b 100644 --- a/deps/ox/src/ox/std/strongint.hpp +++ b/deps/ox/src/ox/std/strongint.hpp @@ -14,12 +14,12 @@ namespace ox { struct BaseInteger { - constexpr BaseInteger() = default; + constexpr BaseInteger() noexcept = default; - constexpr BaseInteger(const BaseInteger&) { + constexpr BaseInteger(const BaseInteger&) noexcept { } - constexpr BaseInteger operator=(const BaseInteger&) { + constexpr BaseInteger operator=(const BaseInteger&) noexcept { return *this; }