refactor(debug): rename BLIZZARD_ASSERT to BC_ASSERT

This commit is contained in:
phaneron 2025-03-27 17:54:20 -04:00
parent 616ac87ad4
commit 3a9129f69c
12 changed files with 48 additions and 44 deletions

View file

@ -4,18 +4,18 @@
#include "bc/system/System_Debug.hpp" #include "bc/system/System_Debug.hpp"
#include <cstdint> #include <cstdint>
#if defined(NDEBUG) #if defined(WHOA_ASSERTIONS_ENABLED)
#define BLIZZARD_ASSERT(x) \ #define BC_ASSERT(x) \
(void)0
#else
#define BLIZZARD_ASSERT(x) \
if (!(x)) { \ if (!(x)) { \
Blizzard::Debug::Assert(#x, __FILE__, __LINE__); \ Blizzard::Debug::Assert(#x, __FILE__, __LINE__); \
} \ } \
(void)0 (void)0
#else
#define BC_ASSERT(x) \
(void)0
#endif #endif
#define BLIZZARD_VALIDATE(x, y, ...) \ #define BC_VALIDATE(x, y, ...) \
if (!(x)) { \ if (!(x)) { \
Blizzard::Debug::Assert(#y, __FILE__, __LINE__); \ Blizzard::Debug::Assert(#y, __FILE__, __LINE__); \
return __VA_ARGS__; \ return __VA_ARGS__; \

View file

@ -25,7 +25,7 @@ int32_t Blizzard::Lock::MutexCreate(Blizzard::Lock::Mutex& mutex) {
Blizzard::Lock::DoOnce(System_Lock::s_initMutexAttrOnce, System_Lock::InitAttr, nullptr); Blizzard::Lock::DoOnce(System_Lock::s_initMutexAttrOnce, System_Lock::InitAttr, nullptr);
auto result = pthread_mutex_init(&mutex, &System_Lock::s_mutexattr); auto result = pthread_mutex_init(&mutex, &System_Lock::s_mutexattr);
BLIZZARD_ASSERT(result == 0); BC_ASSERT(result == 0);
return result; return result;
#endif #endif
@ -38,7 +38,7 @@ int32_t Blizzard::Lock::MutexEnter(Blizzard::Lock::Mutex& mutex) {
return 0; return 0;
#elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) #elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
auto result = pthread_mutex_lock(&mutex); auto result = pthread_mutex_lock(&mutex);
BLIZZARD_ASSERT(result == 0); BC_ASSERT(result == 0);
return result; return result;
#endif #endif
@ -51,7 +51,7 @@ int32_t Blizzard::Lock::MutexLeave(Blizzard::Lock::Mutex& mutex) {
return 0; return 0;
#elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) #elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
auto result = pthread_mutex_unlock(&mutex); auto result = pthread_mutex_unlock(&mutex);
BLIZZARD_ASSERT(result == 0); BC_ASSERT(result == 0);
return result; return result;
#endif #endif

View file

@ -8,7 +8,7 @@ void Blizzard::Thread::AllocateLocalStorage(TLSSlot* slot) {
void* Blizzard::Thread::RegisterLocalStorage(TLSSlot* slot, void* (*constructor)(void*), void* userData, void (*destructor)(void*)) { void* Blizzard::Thread::RegisterLocalStorage(TLSSlot* slot, void* (*constructor)(void*), void* userData, void (*destructor)(void*)) {
if (!System_Thread::TLSSlotIsAllocated(slot) && !System_Thread::AllocateTLSSlot(slot, destructor)) { 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); 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) { 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); System_Thread::InternalSetLocalStorage(slot, value);
} }

View file

@ -225,13 +225,13 @@ done:
int32_t ConvertUTF8to16Len(const uint8_t* src, uint32_t srcmaxchars, uint32_t* srcchars) { int32_t ConvertUTF8to16Len(const uint8_t* src, uint32_t srcmaxchars, uint32_t* srcchars) {
// TODO // TODO
BLIZZARD_ASSERT(0); BC_ASSERT(0);
return -1; return -1;
} }
int32_t GetCodepointFromUTF8(const uint8_t** c) { int32_t GetCodepointFromUTF8(const uint8_t** c) {
// TODO // TODO
BLIZZARD_ASSERT(0); BC_ASSERT(0);
return -1; return -1;
} }

View file

@ -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) { 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); BC_VALIDATE(fileName, "invalid filename", HOSFILE_INVALID);
BLIZZARD_VALIDATE(desiredAccess != 0, "invalid desired access", HOSFILE_INVALID); BC_VALIDATE(desiredAccess != 0, "invalid desired access", HOSFILE_INVALID);
BLIZZARD_VALIDATE(createDisposition <= OS_TRUNCATE_EXISTING, "invalid create disposition", HOSFILE_INVALID); BC_VALIDATE(createDisposition <= OS_TRUNCATE_EXISTING, "invalid create disposition", HOSFILE_INVALID);
Blizzard::File::StreamRecord* file; Blizzard::File::StreamRecord* file;
if (!Blizzard::File::Open(fileName, OsCreateFileMode(desiredAccess, shareMode, createDisposition), 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<HOSFILE>(file); return reinterpret_cast<HOSFILE>(file);
} }

View file

@ -5,7 +5,7 @@
#include "bc/file/Defines.hpp" #include "bc/file/Defines.hpp"
int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t moveMethod) { int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t moveMethod) {
BLIZZARD_ASSERT(moveMethod <= 2); BC_ASSERT(moveMethod <= 2);
auto file = reinterpret_cast<Blizzard::File::StreamRecord*>(fileHandle); auto file = reinterpret_cast<Blizzard::File::StreamRecord*>(fileHandle);
@ -25,4 +25,4 @@ int64_t OsSetFilePointer(HOSFILE fileHandle, int64_t distanceToMove, uint32_t mo
} }
return offset + distanceToMove; return offset + distanceToMove;
} }

View file

@ -91,7 +91,7 @@ void ForceTrailingSeparator(char* buf, int32_t bufMax, char separator) {
} }
// Add (back*) trailing separator // Add (back*) trailing separator
BLIZZARD_ASSERT(len <= bufMax - 2); BC_ASSERT(len <= bufMax - 2);
buf[len] = separator; buf[len] = separator;
buf[len + 1] = '\0'; // pad null buf[len + 1] = '\0'; // pad null
} }

View file

@ -37,10 +37,10 @@ void Blizzard::System_Thread::AddToRegistry(Thread::ThreadRecord* thread) {
bool Blizzard::System_Thread::AllocateLocalStorage(Thread::TLSSlot* slot, void (*destructor)(void*)) { bool Blizzard::System_Thread::AllocateLocalStorage(Thread::TLSSlot* slot, void (*destructor)(void*)) {
System_Thread::InitThreadSystem(); System_Thread::InitThreadSystem();
BLIZZARD_ASSERT(!System_Thread::TLSSlotIsAllocated(slot)); BC_ASSERT(!System_Thread::TLSSlotIsAllocated(slot));
if (!System_Thread::InternalAllocateLocalStorage(slot, destructor)) { if (!System_Thread::InternalAllocateLocalStorage(slot, destructor)) {
BLIZZARD_ASSERT(!"failed to allocate TLS"); BC_ASSERT(!"failed to allocate TLS");
return false; 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) { void Blizzard::System_Thread::InternalSetLocalStorage(const Thread::TLSSlot* slot, const void* value) {
#if defined(WHOA_SYSTEM_WIN) #if defined(WHOA_SYSTEM_WIN)
auto result = TlsSetValue(slot->key, const_cast<void*>(value)); auto result = TlsSetValue(slot->key, const_cast<void*>(value));
BLIZZARD_ASSERT(result); BC_ASSERT(result);
#elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) #elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
auto err = pthread_setspecific(slot->key, value); auto err = pthread_setspecific(slot->key, value);
BLIZZARD_ASSERT(err == 0); BC_ASSERT(err == 0);
#endif #endif
} }

View file

@ -85,7 +85,7 @@ Time::Timestamp Now() {
void TimeInit() { void TimeInit() {
// Record absolute clock beginning moment in raw CPU time // Record absolute clock beginning moment in raw CPU time
ReadTSC(s_absBegin); ReadTSC(s_absBegin);
BLIZZARD_ASSERT(s_absBegin != 0); BC_ASSERT(s_absBegin != 0);
// Look at system clock's GMT/UTC time as nanoseconds // 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 // This associates a point in GMT with the more precise measurements obtained from reading the timestamp counter

View file

@ -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) { bool Read(Blizzard::File::StreamRecord* file, void* data, int64_t offset, int32_t* count) {
// file must be open to read // 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) { if (count == nullptr || *count == 0) {
return true; 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) { bool Write(Blizzard::File::StreamRecord* file, const void* data, int64_t offset, int32_t* count) {
// file descriptor must be initialized // file descriptor must be initialized
BLIZZARD_ASSERT(file != nullptr && file->filefd != -1); BC_ASSERT(file != nullptr && file->filefd != -1);
if (count == nullptr || *count == 0) { if (count == nullptr || *count == 0) {
return true; return true;

View file

@ -51,7 +51,7 @@ bool SetWorkingDirectory(FileParms* parms) {
// close // close
bool Close(FileParms* parms) { bool Close(FileParms* parms) {
auto file = parms->file; auto file = parms->file;
BLIZZARD_ASSERT(file != nullptr); BC_ASSERT(file != nullptr);
::close(file->filefd); ::close(file->filefd);
FREE(file); FREE(file);
@ -157,7 +157,7 @@ bool Exists(FileParms* parms) {
// flush // flush
bool Flush(FileParms* parms) { bool Flush(FileParms* parms) {
auto file = parms->file; auto file = parms->file;
BLIZZARD_ASSERT(file != nullptr); BC_ASSERT(file != nullptr);
#if defined(WHOA_SYSTEM_MAC) #if defined(WHOA_SYSTEM_MAC)
// from BSD syscall manual: // from BSD syscall manual:
@ -592,7 +592,7 @@ bool Open(FileParms* parms) {
auto read = (parms->mode & Blizzard::File::Mode::read) != 0; auto read = (parms->mode & Blizzard::File::Mode::read) != 0;
auto write = (parms->mode & Blizzard::File::Mode::write) != 0; auto write = (parms->mode & Blizzard::File::Mode::write) != 0;
BLIZZARD_ASSERT(read || write); BC_ASSERT(read || write);
if (!read && !write) { if (!read && !write) {
BC_FILE_SET_ERROR_MSG(8, "Posix Open - Bad file mode - %s", name.ToString()); BC_FILE_SET_ERROR_MSG(8, "Posix Open - Bad file mode - %s", name.ToString());
return false; return false;
@ -697,7 +697,7 @@ bool RemoveDirectory(FileParms* parms) {
bool SetCacheMode(FileParms* parms) { bool SetCacheMode(FileParms* parms) {
#if defined(WHOA_SYSTEM_MAC) #if defined(WHOA_SYSTEM_MAC)
auto mode = parms->mode; 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); Blizzard::File::Flush(parms->file);
return 0 == fcntl(parms->file->filefd, F_NOCACHE, mode & Blizzard::File::Mode::nocache); return 0 == fcntl(parms->file->filefd, F_NOCACHE, mode & Blizzard::File::Mode::nocache);
#endif #endif

View file

@ -194,7 +194,11 @@ namespace Stacked {
// begin stacked file functions // begin stacked file functions
bool SetWorkingDirectory(FileParms* parms) { 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; return ::SetCurrentDirectory(PATH(parms->name)) != 0;
} }
@ -347,15 +351,15 @@ bool GetFreeSpace(FileParms* parms) {
return false; return false;
} }
char path[PATH_MAX]; char path[MAX_PATH];
char shortpath[PATH_MAX]; char shortpath[MAX_PATH];
Blizzard::String::Copy(path, name, std::min(static_cast<int32_t>((Blizzard::String::FindFilename(name) + 1) - name), PATH_MAX)); Blizzard::String::Copy(path, name, std::min(static_cast<int32_t>((Blizzard::String::FindFilename(name) + 1) - name), MAX_PATH));
ULARGE_INTEGER freebytesavailable; ULARGE_INTEGER freebytesavailable;
ULARGE_INTEGER totalbytesavailable; ULARGE_INTEGER totalbytesavailable;
auto shortpathchars = ::GetShortPathName(PATH(path), shortpath, PATH_MAX); auto shortpathchars = ::GetShortPathName(PATH(path), shortpath, MAX_PATH);
if (shortpathchars && shortpathchars < PATH_MAX) { if (shortpathchars && shortpathchars < MAX_PATH) {
if (!GetDiskFreeSpaceEx(shortpath, &freebytesavailable, &totalbytesavailable, nullptr)) { if (!GetDiskFreeSpaceEx(shortpath, &freebytesavailable, &totalbytesavailable, nullptr)) {
BC_FILE_SET_ERROR(8); BC_FILE_SET_ERROR(8);
return false; return false;
@ -478,9 +482,9 @@ bool CreateDirectory(FileParms* parms) {
return false; return false;
} }
char pathbuffer[PATH_MAX]; char pathbuffer[MAX_PATH];
auto pathsize = Blizzard::String::Length(parms->name) + 1; 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); Blizzard::String::MakeBackslashPath(parms->name, path, pathsize);
@ -493,14 +497,14 @@ bool CreateDirectory(FileParms* parms) {
} }
if (parms->recurse) { if (parms->recurse) {
char leadingpath[PATH_MAX]; char leadingpath[MAX_PATH];
for (auto s = path; *s && s < (s + Blizzard::String::Length(s)); s++) { for (auto s = path; *s && s < (s + Blizzard::String::Length(s)); s++) {
while (*s && *s != '\\') { while (*s && *s != '\\') {
s++; s++;
} }
if (Blizzard::String::Copy(leadingpath, path, std::min(static_cast<int32_t>(s - path) + 2, PATH_MAX))) { if (Blizzard::String::Copy(leadingpath, path, std::min(static_cast<int32_t>(s - path) + 2, MAX_PATH))) {
BC_FILE_SET_ERROR(8); BC_FILE_SET_ERROR(8);
if (path != pathbuffer) { if (path != pathbuffer) {
delete path; delete path;
@ -693,10 +697,10 @@ bool RemoveDirectory(FileParms* parms) {
return false; return false;
} }
char namebuffer[PATH_MAX]; char namebuffer[MAX_PATH];
auto namesize = Blizzard::String::Length(parms->name) + 1; auto namesize = Blizzard::String::Length(parms->name) + 1;
auto name = namesize > PATH_MAX ? new char[namesize] : namebuffer; auto name = namesize > MAX_PATH ? new char[namesize] : namebuffer;
Blizzard::String::MakeBackslashPath(parms->name, name, PATH_MAX); Blizzard::String::MakeBackslashPath(parms->name, name, MAX_PATH);
auto removed = ::RemoveDirectoryA(PATH(name)); auto removed = ::RemoveDirectoryA(PATH(name));