diff --git a/Include/Aurora/Debug/SysErrors.hpp b/Include/Aurora/Debug/SysErrors.hpp index d251d2cb..4e872294 100644 --- a/Include/Aurora/Debug/SysErrors.hpp +++ b/Include/Aurora/Debug/SysErrors.hpp @@ -150,7 +150,6 @@ namespace Aurora::Debug #define SysSafeFunction __PRETTY_FUNCTION__ #endif - #define SysCheckReturn(x, ...) if (!(static_cast(x))) { Aurora::Debug::ErrorMakeNested(); return __VA_ARGS__; } #define SysPushErrorError(error, ...) do { Aurora::Debug::AddMemoryCrunch(); Aurora::Debug::SysPushError(Aurora::Debug::error, SysSafeLine, ## __VA_ARGS__) ;Aurora::Debug::DecMemoryCrunch(); } while (0) @@ -164,9 +163,21 @@ namespace Aurora::Debug #define SysPushErrorMem(...) SysPushErrorError(kFailureMemory, ## __VA_ARGS__) #if defined(AU_CFG_ID_INTERNAL) || defined(AU_CFG_ID_DEBUG) || defined(AU_INC_ARG_NAMES) - #define SysCheckArgNotNull(x, ...) if (!(static_cast(x))) { SysPushErrorArg(#x "must not be null"); return __VA_ARGS__; } + #define SysCheckArgNotNull(x, ...) if (!(static_cast(x))) { SysPushErrorArg(#x " must not be null"); return __VA_ARGS__; } + #define SysCheckNotNull(x, ...) if (!(static_cast(x))) { SysPushErrorGeneric(#x " must not be null"); return __VA_ARGS__; } + #define SysCheckNotNullMemory(x, ...) if (!(static_cast(x))) { SysPushErrorMemory(#x " must not be null"); return __VA_ARGS__; } #else - #define SysCheckArgNotNull(x, ...) if (!(static_cast(x))) { SysPushErrorArg(); return __VA_ARGS__; } + #define SysCheckArgNotNull(x, ...) if (!(static_cast(x))) { SysPushErrorArg(); return __VA_ARGS__; } + #define SysCheckNotNull(x, ...) if (!(static_cast(x))) { SysPushErrorGeneric(); return __VA_ARGS__; } + #define SysCheckNotNullMemory(x, ...) if (!(static_cast(x))) { SysPushErrorMemory(); return __VA_ARGS__; } +#endif + +#if defined(AU_CFG_ID_INTERNAL) || defined(AU_CFG_ID_DEBUG) || defined(AU_INC_ARG_NAMES) + #define SysCheckRetExpNotNull(x, ...) if (auto n = x) { return n; } else { SysPushErrorGeneric(#x " must not be null [return]"); return __VA_ARGS__; } + #define SysCheckRetExpNotNullMemory(x, ...) if (auto n = x) { return n; } else { SysPushErrorMemory(#x); return __VA_ARGS__; } +#else + #define SysCheckRetExpNotNull(x, ...) if (auto n = x) { return n; } else { SysPushErrorGeneric(); return __VA_ARGS__; } + #define SysCheckRetExpNotNullMemory(x, ...) if (auto n = x) { return n; } else { SysPushErrorMemory(); return __VA_ARGS__; } #endif // edge case diff --git a/Source/Compression/AuCompressionInterceptor.cpp b/Source/Compression/AuCompressionInterceptor.cpp index ecea1ac4..faca55ad 100644 --- a/Source/Compression/AuCompressionInterceptor.cpp +++ b/Source/Compression/AuCompressionInterceptor.cpp @@ -164,19 +164,11 @@ namespace Aurora::Compression AUKN_SYM AuSPtr NewDecompressionInterceptor(const DecompressInfo &info) { auto pInterceptor = AuMakeShared(); - if (!pInterceptor) - { - SysPushErrorMemory(); - return {}; - } + SysCheckNotNullMemory(pInterceptor, {}); auto pDecompressor = DecompressorShared(AuUnsafeRaiiToShared(pInterceptor.get()), info); - if (!pDecompressor) - { - SysPushErrorMemory(); - return {}; - } + SysCheckNotNullMemory(pDecompressor, {}); pInterceptor->Init(pDecompressor, AuStaticCast(pDecompressor)); @@ -187,19 +179,11 @@ namespace Aurora::Compression AUKN_SYM AuSPtr NewCompressionInterceptor(const CompressInfo &info) { auto pInterceptor = AuMakeShared(); - if (!pInterceptor) - { - SysPushErrorMemory(); - return {}; - } + SysCheckNotNullMemory(pInterceptor, {}); auto pCompressor = CompressorShared(AuUnsafeRaiiToShared(pInterceptor.get()), info); - if (!pCompressor) - { - SysPushErrorMemory(); - return {}; - } + SysCheckNotNullMemory(pCompressor, {}); pInterceptor->Init(pCompressor, AuStaticCast(pCompressor)); diff --git a/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp b/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp index 0065dcf3..c947a4be 100644 --- a/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp +++ b/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp @@ -196,11 +196,7 @@ namespace Aurora::IO::Adapters } auto newMem = AuMakeShared(uLength); - if (!newMem) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNull(newMem, {}); if (!newMem->IsValid()) { @@ -467,11 +463,7 @@ namespace Aurora::IO::Adapters } auto newMem = AuMakeShared(parameters.length); - if (!newMem) - { - SysPushErrorMem(); - return EStreamError::eErrorStreamInterrupted; - } + SysCheckNotNull(newMem, EStreamError::eErrorOutOfMemory); if (!newMem->IsValid()) { diff --git a/Source/IO/Adapters/AuIOAdapterByteBuffer.cpp b/Source/IO/Adapters/AuIOAdapterByteBuffer.cpp index 0b21a9e1..902bed9f 100644 --- a/Source/IO/Adapters/AuIOAdapterByteBuffer.cpp +++ b/Source/IO/Adapters/AuIOAdapterByteBuffer.cpp @@ -13,40 +13,25 @@ namespace Aurora::IO::Adapters { AUKN_SYM AuSPtr NewByteBufferReadAdapter(const AuSPtr &pBuffer) { - if (!pBuffer) - { - SysPushErrorArg(); - return {}; - } - - return AuMakeShared(pBuffer); + SysCheckArgNotNull(pBuffer, {}); + SysCheckRetExpNotNullMemory(AuMakeShared(pBuffer), {}); } AUKN_SYM AuSPtr NewByteBufferLinearSeekableAdapter(const AuSPtr &pBuffer) { - if (!pBuffer) - { - SysPushErrorArg(); - return {}; - } - + SysCheckArgNotNull(pBuffer, {}); if (pBuffer->flagCircular) { SysPushErrorIO("Seekable buffer must not be circular"); return {}; } - return AuMakeShared(pBuffer); + SysCheckRetExpNotNullMemory(AuMakeShared(pBuffer), {}); } AUKN_SYM AuSPtr NewByteBufferWriteAdapter(const AuSPtr &pBuffer) { - if (!pBuffer) - { - SysPushErrorArg(); - return {}; - } - - return AuMakeShared(pBuffer); + SysCheckArgNotNull(pBuffer, {}); + SysCheckRetExpNotNullMemory(AuMakeShared(pBuffer), {}); } } \ No newline at end of file diff --git a/Source/IO/Adapters/AuIOAdapterCompression.cpp b/Source/IO/Adapters/AuIOAdapterCompression.cpp index 61c91354..222b6f4b 100644 --- a/Source/IO/Adapters/AuIOAdapterCompression.cpp +++ b/Source/IO/Adapters/AuIOAdapterCompression.cpp @@ -108,12 +108,12 @@ namespace Aurora::IO::Adapters AUKN_SYM AuSPtr NewCompressionReadAdapter(const AuSPtr &pCompresionStream) { SysCheckArgNotNull(pCompresionStream, {}); - return AuMakeShared(pCompresionStream); + SysCheckRetExpNotNullMemory(AuMakeShared(pCompresionStream), {}); } AUKN_SYM AuSPtr NewCompressionSeekingAdapter(const AuSPtr &pCompresionStream) { SysCheckArgNotNull(pCompresionStream, {}); - return AuMakeShared(pCompresionStream); + SysCheckRetExpNotNullMemory(AuMakeShared(pCompresionStream), {}); } } \ No newline at end of file diff --git a/Source/IO/Adapters/AuIOAdapterMemoryView.cpp b/Source/IO/Adapters/AuIOAdapterMemoryView.cpp index df102a33..a17a6000 100644 --- a/Source/IO/Adapters/AuIOAdapterMemoryView.cpp +++ b/Source/IO/Adapters/AuIOAdapterMemoryView.cpp @@ -17,13 +17,9 @@ namespace Aurora::IO::Adapters SysCheckArgNotNull(pView, {}); auto pBuffer = AuMakeShared(pView, AuMemoryViewWrite { (void *)pView->ptr, pView->length }); - if (!pBuffer) - { - SysPushErrorArg(); - return {}; - } + SysCheckNotNull(pBuffer, {}); - return AuMakeShared(pBuffer); + SysCheckRetExpNotNullMemory(AuMakeShared(pBuffer), {}); } AUKN_SYM AuSPtr NewMemoryViewLinearSeekableAdapter(const AuSPtr &pView) @@ -31,13 +27,9 @@ namespace Aurora::IO::Adapters SysCheckArgNotNull(pView, {}); auto pBuffer = AuMakeShared(pView, AuMemoryViewWrite { (void *)pView->ptr, pView->length }); - if (!pBuffer) - { - SysPushErrorArg(); - return {}; - } + SysCheckNotNull(pBuffer, {}); - return AuMakeShared(pBuffer); + SysCheckRetExpNotNullMemory(AuMakeShared(pBuffer), {}); } AUKN_SYM AuSPtr NewMemoryViewWriteAdapter(const AuSPtr &pView) @@ -45,14 +37,10 @@ namespace Aurora::IO::Adapters SysCheckArgNotNull(pView, {}); auto pBuffer = AuMakeShared(pView, *pView); - if (!pBuffer) - { - SysPushErrorArg(); - return {}; - } + SysCheckNotNull(pBuffer, {}); pBuffer->writePtr = (AuUInt8 *)pView->ptr; - return AuMakeShared(pBuffer); + SysCheckRetExpNotNullMemory(AuMakeShared(pBuffer), {}); } } \ No newline at end of file diff --git a/Source/IO/Adapters/AuIOAdapterSeeking.cpp b/Source/IO/Adapters/AuIOAdapterSeeking.cpp index a3218eba..2d00f40e 100644 --- a/Source/IO/Adapters/AuIOAdapterSeeking.cpp +++ b/Source/IO/Adapters/AuIOAdapterSeeking.cpp @@ -42,6 +42,6 @@ namespace Aurora::IO::Adapters AUKN_SYM AuSPtr NewSeekingReadAdapter(const AuSPtr &pReader) { - return AuMakeShared(pReader); + SysCheckRetExpNotNullMemory(AuMakeShared(pReader), {}); } } \ No newline at end of file diff --git a/Source/IO/AuIOProcessor.cpp b/Source/IO/AuIOProcessor.cpp index 1501c467..3e6b72ca 100644 --- a/Source/IO/AuIOProcessor.cpp +++ b/Source/IO/AuIOProcessor.cpp @@ -946,11 +946,7 @@ namespace Aurora::IO static AuSPtr NewIOProcessorEx(bool tickOnly, const AuSPtr &queue, bool bIsNoQueue) { auto processor = AuMakeShared(0, tickOnly, AuOptionalEx {}, queue, bIsNoQueue); - if (!processor) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNullMemory(processor, {}); if (!processor->Init()) { @@ -964,11 +960,7 @@ namespace Aurora::IO AUKN_SYM AuSPtr NewIOProcessor(bool tickOnly, const AuSPtr &queue) { auto processor = AuMakeShared(0, tickOnly, AuOptionalEx {}, queue, false); - if (!processor) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNullMemory(processor, {}); if (!processor->Init()) { @@ -1002,11 +994,7 @@ namespace Aurora::IO } auto processor = AuMakeShared(AuUInt(thread.get()), tickOnly, id, queue, false); - if (!processor) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNullMemory(processor, {}); if (!processor->Init()) { @@ -1020,11 +1008,7 @@ namespace Aurora::IO AUKN_SYM AuSPtr NewIOProcessorNoQueue(bool tickOnly) { auto loop = AuLoop::NewLoopQueue(); - if (!loop) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNull(loop, {}); return NewIOProcessorEx(tickOnly, loop, true); } diff --git a/Source/IO/AuIOWaitableIOLoopSource.cpp b/Source/IO/AuIOWaitableIOLoopSource.cpp index df926648..0c808e71 100644 --- a/Source/IO/AuIOWaitableIOLoopSource.cpp +++ b/Source/IO/AuIOWaitableIOLoopSource.cpp @@ -80,11 +80,11 @@ namespace Aurora::IO AUKN_SYM AuSPtr NewWaitableLoopSource(const AuSPtr&pSource) { - return AuMakeShared(pSource); + SysCheckRetExpNotNullMemory(AuMakeShared(pSource), {}); } AUKN_SYM AuSPtr NewWaitableLoopSourceEx(const AuSPtr&pSource, AuUInt32 dwIoTimeoutMS) { - return AuMakeShared(pSource, dwIoTimeoutMS); + SysCheckRetExpNotNullMemory(AuMakeShared(pSource, dwIoTimeoutMS), {}); } } \ No newline at end of file diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index a2a6a60d..5e02122b 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -75,10 +75,7 @@ namespace Aurora::IO::FS AuSPtr NtAsyncFileStream::NewTransaction() { auto shared = AuMakeShared(); - if (!shared) - { - return {}; - } + SysCheckNotNullMemory(shared, {}); if (!shared->InitWeak(this->pHandle_)) { @@ -593,7 +590,7 @@ namespace Aurora::IO::FS AuSPtr NtAsyncFileTransaction::NewLoopSource() { - return AuMakeShared(AuSharedFromThis()); + SysCheckRetExpNotNullMemory(AuMakeShared(AuSharedFromThis()), {}); } AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, bool directIO, EFileAdvisoryLockLevel lock) diff --git a/Source/IO/FS/DirDeleter.cpp b/Source/IO/FS/DirDeleter.cpp index 6bf75a15..4927f9f3 100644 --- a/Source/IO/FS/DirDeleter.cpp +++ b/Source/IO/FS/DirDeleter.cpp @@ -105,11 +105,7 @@ namespace Aurora::IO::FS AUKN_SYM bool DirDeleter(const AuString &string) { auto pObj = AuMakeShared(); - if (!pObj) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNullMemory(pObj, false); if (!pObj->OpenDir(string)) { @@ -130,11 +126,7 @@ namespace Aurora::IO::FS AUKN_SYM bool DirDeleterEx(const AuString &string, AuList &failingPaths) { auto pObj = AuMakeShared(); - if (!pObj) - { - SysPushErrorMem(); - return {}; - } + SysCheckNotNullMemory(pObj, false); if (!pObj->OpenDir(string)) { diff --git a/Source/IO/FS/FSCompress.cpp b/Source/IO/FS/FSCompress.cpp index 60d975a3..b9a98dd6 100644 --- a/Source/IO/FS/FSCompress.cpp +++ b/Source/IO/FS/FSCompress.cpp @@ -58,18 +58,10 @@ namespace Aurora::IO::FS auto qwLength = pFileSrc->GetLength(); auto pFileStream = AuMakeShared(pFileSrc); - if (!pFileStream) - { - SysPushErrorMemory(); - return {}; - } + SysCheckNotNullMemory(pFileStream, {}); auto pDestStream = AuMakeShared(pFileDest); - if (!pDestStream) - { - SysPushErrorMemory(); - return {}; - } + SysCheckNotNullMemory(pDestStream, {}); AuCompression::CompressInfo compress { type }; compress.uCompressionLevel = level; diff --git a/Source/IO/FS/FileStream.NT.cpp b/Source/IO/FS/FileStream.NT.cpp index 7d56f562..7edb4b69 100644 --- a/Source/IO/FS/FileStream.NT.cpp +++ b/Source/IO/FS/FileStream.NT.cpp @@ -452,11 +452,7 @@ namespace Aurora::IO::FS AUKN_SYM AuSPtr OpenBlockingFileStreamFromHandle(AuSPtr pIOHandle) { auto pStream = AuMakeShared(); - if (!pStream) - { - SysPushErrorMemory(); - return nullptr; - } + SysCheckNotNullMemory(pStream, {}); pStream->Init(pIOHandle); return pStream; diff --git a/Source/IO/Loop/LoopQueue.NT.cpp b/Source/IO/Loop/LoopQueue.NT.cpp index ce71240d..2ec353a6 100644 --- a/Source/IO/Loop/LoopQueue.NT.cpp +++ b/Source/IO/Loop/LoopQueue.NT.cpp @@ -1525,6 +1525,6 @@ namespace Aurora::IO::Loop AUKN_SYM AuSPtr NewLoopQueue() { - return AuMakeShared(); + SysCheckRetExpNotNullMemory(AuMakeShared(), {}); } } \ No newline at end of file