From 3a9129f69cf24d32274bfbf22fc01da268a2eed3 Mon Sep 17 00:00:00 2001 From: superp00t Date: Thu, 27 Mar 2025 17:54:20 -0400 Subject: [PATCH] refactor(debug): rename BLIZZARD_ASSERT to BC_ASSERT --- bc/Debug.hpp | 12 ++++++------ bc/Lock.cpp | 6 +++--- bc/Thread.cpp | 4 ++-- bc/Unicode.cpp | 4 ++-- bc/os/file/CreateFile.cpp | 8 ++++---- bc/os/file/SetFilePointer.cpp | 4 ++-- bc/string/Path.cpp | 2 +- bc/system/System_Thread.cpp | 8 ++++---- bc/system/System_Time.cpp | 2 +- bc/system/file/System_File.cpp | 4 ++-- bc/system/file/posix/Stacked.cpp | 8 ++++---- bc/system/file/win/Stacked.cpp | 30 +++++++++++++++++------------- 12 files changed, 48 insertions(+), 44 deletions(-) diff --git a/bc/Debug.hpp b/bc/Debug.hpp index c3fd3a8..9f19d52 100644 --- a/bc/Debug.hpp +++ b/bc/Debug.hpp @@ -4,18 +4,18 @@ #include "bc/system/System_Debug.hpp" #include -#if defined(NDEBUG) -#define BLIZZARD_ASSERT(x) \ - (void)0 -#else -#define BLIZZARD_ASSERT(x) \ +#if defined(WHOA_ASSERTIONS_ENABLED) +#define BC_ASSERT(x) \ if (!(x)) { \ Blizzard::Debug::Assert(#x, __FILE__, __LINE__); \ } \ (void)0 +#else +#define BC_ASSERT(x) \ + (void)0 #endif -#define BLIZZARD_VALIDATE(x, y, ...) \ +#define BC_VALIDATE(x, y, ...) \ if (!(x)) { \ Blizzard::Debug::Assert(#y, __FILE__, __LINE__); \ return __VA_ARGS__; \ diff --git a/bc/Lock.cpp b/bc/Lock.cpp index d405b13..a3f22f8 100644 --- a/bc/Lock.cpp +++ b/bc/Lock.cpp @@ -25,7 +25,7 @@ int32_t Blizzard::Lock::MutexCreate(Blizzard::Lock::Mutex& mutex) { Blizzard::Lock::DoOnce(System_Lock::s_initMutexAttrOnce, System_Lock::InitAttr, nullptr); auto result = pthread_mutex_init(&mutex, &System_Lock::s_mutexattr); - BLIZZARD_ASSERT(result == 0); + BC_ASSERT(result == 0); return result; #endif @@ -38,7 +38,7 @@ int32_t Blizzard::Lock::MutexEnter(Blizzard::Lock::Mutex& mutex) { return 0; #elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) auto result = pthread_mutex_lock(&mutex); - BLIZZARD_ASSERT(result == 0); + BC_ASSERT(result == 0); return result; #endif @@ -51,7 +51,7 @@ int32_t Blizzard::Lock::MutexLeave(Blizzard::Lock::Mutex& mutex) { return 0; #elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) auto result = pthread_mutex_unlock(&mutex); - BLIZZARD_ASSERT(result == 0); + BC_ASSERT(result == 0); return result; #endif diff --git a/bc/Thread.cpp b/bc/Thread.cpp index 434d796..dff38ab 100644 --- a/bc/Thread.cpp +++ b/bc/Thread.cpp @@ -8,7 +8,7 @@ void Blizzard::Thread::AllocateLocalStorage(TLSSlot* slot) { void* Blizzard::Thread::RegisterLocalStorage(TLSSlot* slot, void* (*constructor)(void*), void* userData, void (*destructor)(void*)) { if (!System_Thread::TLSSlotIsAllocated(slot) && !System_Thread::AllocateTLSSlot(slot, destructor)) { - BLIZZARD_ASSERT(!"Unable to allocate thread-local storage"); + BC_ASSERT(!"Unable to allocate thread-local storage"); } auto value = System_Thread::InternalGetLocalStorage(slot); @@ -23,7 +23,7 @@ void* Blizzard::Thread::RegisterLocalStorage(TLSSlot* slot, void* (*constructor) } void Blizzard::Thread::SetLocalStorage(const TLSSlot* slot, const void* value) { - BLIZZARD_ASSERT(Blizzard::Thread::TLSSlotIsAllocated(slot)); + BC_ASSERT(Blizzard::Thread::TLSSlotIsAllocated(slot)); System_Thread::InternalSetLocalStorage(slot, value); } diff --git a/bc/Unicode.cpp b/bc/Unicode.cpp index 4ee5e9d..188f88c 100644 --- a/bc/Unicode.cpp +++ b/bc/Unicode.cpp @@ -225,13 +225,13 @@ done: int32_t ConvertUTF8to16Len(const uint8_t* src, uint32_t srcmaxchars, uint32_t* srcchars) { // TODO - BLIZZARD_ASSERT(0); + BC_ASSERT(0); return -1; } int32_t GetCodepointFromUTF8(const uint8_t** c) { // TODO - BLIZZARD_ASSERT(0); + BC_ASSERT(0); return -1; } diff --git a/bc/os/file/CreateFile.cpp b/bc/os/file/CreateFile.cpp index 66b2350..542f9a7 100644 --- a/bc/os/file/CreateFile.cpp +++ b/bc/os/file/CreateFile.cpp @@ -50,9 +50,9 @@ int32_t OsCreateFileMode(uint32_t desiredAccess, uint32_t shareMode, uint32_t cr } HOSFILE OsCreateFile(const char* fileName, uint32_t desiredAccess, uint32_t shareMode, uint32_t createDisposition, uint32_t flagsAndAttributes, uint32_t extendedFileType) { - BLIZZARD_VALIDATE(fileName, "invalid filename", HOSFILE_INVALID); - BLIZZARD_VALIDATE(desiredAccess != 0, "invalid desired access", HOSFILE_INVALID); - BLIZZARD_VALIDATE(createDisposition <= OS_TRUNCATE_EXISTING, "invalid create disposition", HOSFILE_INVALID); + BC_VALIDATE(fileName, "invalid filename", HOSFILE_INVALID); + BC_VALIDATE(desiredAccess != 0, "invalid desired access", HOSFILE_INVALID); + BC_VALIDATE(createDisposition <= OS_TRUNCATE_EXISTING, "invalid create disposition", HOSFILE_INVALID); Blizzard::File::StreamRecord* file; if (!Blizzard::File::Open(fileName, OsCreateFileMode(desiredAccess, shareMode, createDisposition), file)) { @@ -64,4 +64,4 @@ HOSFILE OsCreateFile(const char* fileName, uint32_t desiredAccess, uint32_t shar } return reinterpret_cast(file); -} \ No newline at end of file +} diff --git a/bc/os/file/SetFilePointer.cpp b/bc/os/file/SetFilePointer.cpp index 732c671..a947405 100644 --- a/bc/os/file/SetFilePointer.cpp +++ b/bc/os/file/SetFilePointer.cpp @@ -5,7 +5,7 @@ #include "bc/file/Defines.hpp" int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t moveMethod) { - BLIZZARD_ASSERT(moveMethod <= 2); + BC_ASSERT(moveMethod <= 2); auto file = reinterpret_cast(fileHandle); @@ -25,4 +25,4 @@ int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t mo } return offset + distanceToMove; -} \ No newline at end of file +} diff --git a/bc/string/Path.cpp b/bc/string/Path.cpp index 76a4a96..542342e 100644 --- a/bc/string/Path.cpp +++ b/bc/string/Path.cpp @@ -91,7 +91,7 @@ void ForceTrailingSeparator(char* buf, int32_t bufMax, char separator) { } // Add (back*) trailing separator - BLIZZARD_ASSERT(len <= bufMax - 2); + BC_ASSERT(len <= bufMax - 2); buf[len] = separator; buf[len + 1] = '\0'; // pad null } diff --git a/bc/system/System_Thread.cpp b/bc/system/System_Thread.cpp index bdfcbac..116fff0 100644 --- a/bc/system/System_Thread.cpp +++ b/bc/system/System_Thread.cpp @@ -37,10 +37,10 @@ void Blizzard::System_Thread::AddToRegistry(Thread::ThreadRecord* thread) { bool Blizzard::System_Thread::AllocateLocalStorage(Thread::TLSSlot* slot, void (*destructor)(void*)) { System_Thread::InitThreadSystem(); - BLIZZARD_ASSERT(!System_Thread::TLSSlotIsAllocated(slot)); + BC_ASSERT(!System_Thread::TLSSlotIsAllocated(slot)); if (!System_Thread::InternalAllocateLocalStorage(slot, destructor)) { - BLIZZARD_ASSERT(!"failed to allocate TLS"); + BC_ASSERT(!"failed to allocate TLS"); return false; } @@ -124,10 +124,10 @@ void* Blizzard::System_Thread::InternalGetLocalStorage(const Thread::TLSSlot* sl void Blizzard::System_Thread::InternalSetLocalStorage(const Thread::TLSSlot* slot, const void* value) { #if defined(WHOA_SYSTEM_WIN) auto result = TlsSetValue(slot->key, const_cast(value)); - BLIZZARD_ASSERT(result); + BC_ASSERT(result); #elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) auto err = pthread_setspecific(slot->key, value); - BLIZZARD_ASSERT(err == 0); + BC_ASSERT(err == 0); #endif } diff --git a/bc/system/System_Time.cpp b/bc/system/System_Time.cpp index 04b3816..bf1f91c 100644 --- a/bc/system/System_Time.cpp +++ b/bc/system/System_Time.cpp @@ -85,7 +85,7 @@ Time::Timestamp Now() { void TimeInit() { // Record absolute clock beginning moment in raw CPU time ReadTSC(s_absBegin); - BLIZZARD_ASSERT(s_absBegin != 0); + BC_ASSERT(s_absBegin != 0); // Look at system clock's GMT/UTC time as nanoseconds // This associates a point in GMT with the more precise measurements obtained from reading the timestamp counter diff --git a/bc/system/file/System_File.cpp b/bc/system/file/System_File.cpp index 9f4045b..57981f9 100644 --- a/bc/system/file/System_File.cpp +++ b/bc/system/file/System_File.cpp @@ -122,7 +122,7 @@ bool Delete(Blizzard::File::Filesystem* fs, Stacked::FileParms* parms) { bool Read(Blizzard::File::StreamRecord* file, void* data, int64_t offset, int32_t* count) { // file must be open to read - BLIZZARD_ASSERT(file != nullptr && file->filefd != -1); + BC_ASSERT(file != nullptr && file->filefd != -1); if (count == nullptr || *count == 0) { return true; @@ -163,7 +163,7 @@ bool ReadP(Blizzard::File::Filesystem* fs, Stacked::FileParms* parms) { bool Write(Blizzard::File::StreamRecord* file, const void* data, int64_t offset, int32_t* count) { // file descriptor must be initialized - BLIZZARD_ASSERT(file != nullptr && file->filefd != -1); + BC_ASSERT(file != nullptr && file->filefd != -1); if (count == nullptr || *count == 0) { return true; diff --git a/bc/system/file/posix/Stacked.cpp b/bc/system/file/posix/Stacked.cpp index fad966a..dfcb7d8 100644 --- a/bc/system/file/posix/Stacked.cpp +++ b/bc/system/file/posix/Stacked.cpp @@ -51,7 +51,7 @@ bool SetWorkingDirectory(FileParms* parms) { // close bool Close(FileParms* parms) { auto file = parms->file; - BLIZZARD_ASSERT(file != nullptr); + BC_ASSERT(file != nullptr); ::close(file->filefd); FREE(file); @@ -157,7 +157,7 @@ bool Exists(FileParms* parms) { // flush bool Flush(FileParms* parms) { auto file = parms->file; - BLIZZARD_ASSERT(file != nullptr); + BC_ASSERT(file != nullptr); #if defined(WHOA_SYSTEM_MAC) // from BSD syscall manual: @@ -592,7 +592,7 @@ bool Open(FileParms* parms) { auto read = (parms->mode & Blizzard::File::Mode::read) != 0; auto write = (parms->mode & Blizzard::File::Mode::write) != 0; - BLIZZARD_ASSERT(read || write); + BC_ASSERT(read || write); if (!read && !write) { BC_FILE_SET_ERROR_MSG(8, "Posix Open - Bad file mode - %s", name.ToString()); return false; @@ -697,7 +697,7 @@ bool RemoveDirectory(FileParms* parms) { bool SetCacheMode(FileParms* parms) { #if defined(WHOA_SYSTEM_MAC) auto mode = parms->mode; - BLIZZARD_ASSERT(0 == (mode & ~Blizzard::File::Mode::nocache)); + BC_ASSERT(0 == (mode & ~Blizzard::File::Mode::nocache)); Blizzard::File::Flush(parms->file); return 0 == fcntl(parms->file->filefd, F_NOCACHE, mode & Blizzard::File::Mode::nocache); #endif diff --git a/bc/system/file/win/Stacked.cpp b/bc/system/file/win/Stacked.cpp index b6b9050..5a2d34a 100644 --- a/bc/system/file/win/Stacked.cpp +++ b/bc/system/file/win/Stacked.cpp @@ -194,7 +194,11 @@ namespace Stacked { // begin stacked file functions bool SetWorkingDirectory(FileParms* parms) { - BLIZZARD_ASSERT(parms->name); + BC_ASSERT(parms->name); + if (!parms->name) { + BC_FILE_SET_ERROR(8); + return false; + } return ::SetCurrentDirectory(PATH(parms->name)) != 0; } @@ -347,15 +351,15 @@ bool GetFreeSpace(FileParms* parms) { return false; } - char path[PATH_MAX]; - char shortpath[PATH_MAX]; - Blizzard::String::Copy(path, name, std::min(static_cast((Blizzard::String::FindFilename(name) + 1) - name), PATH_MAX)); + char path[MAX_PATH]; + char shortpath[MAX_PATH]; + Blizzard::String::Copy(path, name, std::min(static_cast((Blizzard::String::FindFilename(name) + 1) - name), MAX_PATH)); ULARGE_INTEGER freebytesavailable; ULARGE_INTEGER totalbytesavailable; - auto shortpathchars = ::GetShortPathName(PATH(path), shortpath, PATH_MAX); - if (shortpathchars && shortpathchars < PATH_MAX) { + auto shortpathchars = ::GetShortPathName(PATH(path), shortpath, MAX_PATH); + if (shortpathchars && shortpathchars < MAX_PATH) { if (!GetDiskFreeSpaceEx(shortpath, &freebytesavailable, &totalbytesavailable, nullptr)) { BC_FILE_SET_ERROR(8); return false; @@ -478,9 +482,9 @@ bool CreateDirectory(FileParms* parms) { return false; } - char pathbuffer[PATH_MAX]; + char pathbuffer[MAX_PATH]; auto pathsize = Blizzard::String::Length(parms->name) + 1; - auto path = pathsize > PATH_MAX ? new char[pathsize] : pathbuffer; + auto path = pathsize > MAX_PATH ? new char[pathsize] : pathbuffer; Blizzard::String::MakeBackslashPath(parms->name, path, pathsize); @@ -493,14 +497,14 @@ bool CreateDirectory(FileParms* parms) { } if (parms->recurse) { - char leadingpath[PATH_MAX]; + char leadingpath[MAX_PATH]; for (auto s = path; *s && s < (s + Blizzard::String::Length(s)); s++) { while (*s && *s != '\\') { s++; } - if (Blizzard::String::Copy(leadingpath, path, std::min(static_cast(s - path) + 2, PATH_MAX))) { + if (Blizzard::String::Copy(leadingpath, path, std::min(static_cast(s - path) + 2, MAX_PATH))) { BC_FILE_SET_ERROR(8); if (path != pathbuffer) { delete path; @@ -693,10 +697,10 @@ bool RemoveDirectory(FileParms* parms) { return false; } - char namebuffer[PATH_MAX]; + char namebuffer[MAX_PATH]; auto namesize = Blizzard::String::Length(parms->name) + 1; - auto name = namesize > PATH_MAX ? new char[namesize] : namebuffer; - Blizzard::String::MakeBackslashPath(parms->name, name, PATH_MAX); + auto name = namesize > MAX_PATH ? new char[namesize] : namebuffer; + Blizzard::String::MakeBackslashPath(parms->name, name, MAX_PATH); auto removed = ::RemoveDirectoryA(PATH(name));