mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 10:02:30 +00:00
refactor(debug): rename BLIZZARD_ASSERT to BC_ASSERT
This commit is contained in:
parent
616ac87ad4
commit
3a9129f69c
12 changed files with 48 additions and 44 deletions
12
bc/Debug.hpp
12
bc/Debug.hpp
|
|
@ -4,18 +4,18 @@
|
|||
#include "bc/system/System_Debug.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#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__; \
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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<Blizzard::File::StreamRecord*>(fileHandle);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<void*>(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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<int32_t>((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<int32_t>((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<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);
|
||||
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));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue