[+] SysCheckNotNullMemory

[+] SysCheckNotNull
[+] SysCheckRetExpNotNull
[+] SysCheckRetExpNotNullMemory
This commit is contained in:
Reece Wilson 2023-10-24 17:43:00 +01:00
parent 69188d8c1e
commit 4ce49941ff
14 changed files with 49 additions and 128 deletions

View File

@ -150,7 +150,6 @@ namespace Aurora::Debug
#define SysSafeFunction __PRETTY_FUNCTION__
#endif
#define SysCheckReturn(x, ...) if (!(static_cast<bool>(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<bool>(x))) { SysPushErrorArg(#x "must not be null"); return __VA_ARGS__; }
#define SysCheckArgNotNull(x, ...) if (!(static_cast<bool>(x))) { SysPushErrorArg(#x " must not be null"); return __VA_ARGS__; }
#define SysCheckNotNull(x, ...) if (!(static_cast<bool>(x))) { SysPushErrorGeneric(#x " must not be null"); return __VA_ARGS__; }
#define SysCheckNotNullMemory(x, ...) if (!(static_cast<bool>(x))) { SysPushErrorMemory(#x " must not be null"); return __VA_ARGS__; }
#else
#define SysCheckArgNotNull(x, ...) if (!(static_cast<bool>(x))) { SysPushErrorArg(); return __VA_ARGS__; }
#define SysCheckArgNotNull(x, ...) if (!(static_cast<bool>(x))) { SysPushErrorArg(); return __VA_ARGS__; }
#define SysCheckNotNull(x, ...) if (!(static_cast<bool>(x))) { SysPushErrorGeneric(); return __VA_ARGS__; }
#define SysCheckNotNullMemory(x, ...) if (!(static_cast<bool>(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

View File

@ -164,19 +164,11 @@ namespace Aurora::Compression
AUKN_SYM AuSPtr<ICompressionInterceptor> NewDecompressionInterceptor(const DecompressInfo &info)
{
auto pInterceptor = AuMakeShared<CompressionInterceptor>();
if (!pInterceptor)
{
SysPushErrorMemory();
return {};
}
SysCheckNotNullMemory(pInterceptor, {});
auto pDecompressor = DecompressorShared(AuUnsafeRaiiToShared(pInterceptor.get()),
info);
if (!pDecompressor)
{
SysPushErrorMemory();
return {};
}
SysCheckNotNullMemory(pDecompressor, {});
pInterceptor->Init(pDecompressor,
AuStaticCast<Compression::BaseStream>(pDecompressor));
@ -187,19 +179,11 @@ namespace Aurora::Compression
AUKN_SYM AuSPtr<ICompressionInterceptor> NewCompressionInterceptor(const CompressInfo &info)
{
auto pInterceptor = AuMakeShared<CompressionInterceptor>();
if (!pInterceptor)
{
SysPushErrorMemory();
return {};
}
SysCheckNotNullMemory(pInterceptor, {});
auto pCompressor = CompressorShared(AuUnsafeRaiiToShared(pInterceptor.get()),
info);
if (!pCompressor)
{
SysPushErrorMemory();
return {};
}
SysCheckNotNullMemory(pCompressor, {});
pInterceptor->Init(pCompressor,
AuStaticCast<Compression::BaseStream>(pCompressor));

View File

@ -196,11 +196,7 @@ namespace Aurora::IO::Adapters
}
auto newMem = AuMakeShared<AsyncStreamMemory>(uLength);
if (!newMem)
{
SysPushErrorMem();
return {};
}
SysCheckNotNull(newMem, {});
if (!newMem->IsValid())
{
@ -467,11 +463,7 @@ namespace Aurora::IO::Adapters
}
auto newMem = AuMakeShared<AsyncStreamMemory>(parameters.length);
if (!newMem)
{
SysPushErrorMem();
return EStreamError::eErrorStreamInterrupted;
}
SysCheckNotNull(newMem, EStreamError::eErrorOutOfMemory);
if (!newMem->IsValid())
{

View File

@ -13,40 +13,25 @@ namespace Aurora::IO::Adapters
{
AUKN_SYM AuSPtr<IStreamReader> NewByteBufferReadAdapter(const AuSPtr<Memory::ByteBuffer> &pBuffer)
{
if (!pBuffer)
{
SysPushErrorArg();
return {};
}
return AuMakeShared<Buffered::BlobReader>(pBuffer);
SysCheckArgNotNull(pBuffer, {});
SysCheckRetExpNotNullMemory(AuMakeShared<Buffered::BlobReader>(pBuffer), {});
}
AUKN_SYM AuSPtr<ISeekingReader> NewByteBufferLinearSeekableAdapter(const AuSPtr<Memory::ByteBuffer> &pBuffer)
{
if (!pBuffer)
{
SysPushErrorArg();
return {};
}
SysCheckArgNotNull(pBuffer, {});
if (pBuffer->flagCircular)
{
SysPushErrorIO("Seekable buffer must not be circular");
return {};
}
return AuMakeShared<Buffered::BlobSeekableReader>(pBuffer);
SysCheckRetExpNotNullMemory(AuMakeShared<Buffered::BlobSeekableReader>(pBuffer), {});
}
AUKN_SYM AuSPtr<IStreamWriter> NewByteBufferWriteAdapter(const AuSPtr<Memory::ByteBuffer> &pBuffer)
{
if (!pBuffer)
{
SysPushErrorArg();
return {};
}
return AuMakeShared<Buffered::BlobWriter>(pBuffer);
SysCheckArgNotNull(pBuffer, {});
SysCheckRetExpNotNullMemory(AuMakeShared<Buffered::BlobWriter>(pBuffer), {});
}
}

View File

@ -108,12 +108,12 @@ namespace Aurora::IO::Adapters
AUKN_SYM AuSPtr<IStreamReader> NewCompressionReadAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream)
{
SysCheckArgNotNull(pCompresionStream, {});
return AuMakeShared<CompressionStreamReader>(pCompresionStream);
SysCheckRetExpNotNullMemory(AuMakeShared<CompressionStreamReader>(pCompresionStream), {});
}
AUKN_SYM AuSPtr<ISeekingReader> NewCompressionSeekingAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream)
{
SysCheckArgNotNull(pCompresionStream, {});
return AuMakeShared<CompressionSeekingReader>(pCompresionStream);
SysCheckRetExpNotNullMemory(AuMakeShared<CompressionSeekingReader>(pCompresionStream), {});
}
}

View File

@ -17,13 +17,9 @@ namespace Aurora::IO::Adapters
SysCheckArgNotNull(pView, {});
auto pBuffer = AuMakeShared<AuMemory::SharedByteBuffer>(pView, AuMemoryViewWrite { (void *)pView->ptr, pView->length });
if (!pBuffer)
{
SysPushErrorArg();
return {};
}
SysCheckNotNull(pBuffer, {});
return AuMakeShared<Buffered::BlobReader>(pBuffer);
SysCheckRetExpNotNullMemory(AuMakeShared<Buffered::BlobReader>(pBuffer), {});
}
AUKN_SYM AuSPtr<ISeekingReader> NewMemoryViewLinearSeekableAdapter(const AuSPtr<Memory::MemoryViewRead> &pView)
@ -31,13 +27,9 @@ namespace Aurora::IO::Adapters
SysCheckArgNotNull(pView, {});
auto pBuffer = AuMakeShared<AuMemory::SharedByteBuffer>(pView, AuMemoryViewWrite { (void *)pView->ptr, pView->length });
if (!pBuffer)
{
SysPushErrorArg();
return {};
}
SysCheckNotNull(pBuffer, {});
return AuMakeShared<Buffered::BlobSeekableReader>(pBuffer);
SysCheckRetExpNotNullMemory(AuMakeShared<Buffered::BlobSeekableReader>(pBuffer), {});
}
AUKN_SYM AuSPtr<IStreamWriter> NewMemoryViewWriteAdapter(const AuSPtr<Memory::MemoryViewWrite> &pView)
@ -45,14 +37,10 @@ namespace Aurora::IO::Adapters
SysCheckArgNotNull(pView, {});
auto pBuffer = AuMakeShared<AuMemory::SharedByteBuffer>(pView, *pView);
if (!pBuffer)
{
SysPushErrorArg();
return {};
}
SysCheckNotNull(pBuffer, {});
pBuffer->writePtr = (AuUInt8 *)pView->ptr;
return AuMakeShared<Buffered::BlobWriter>(pBuffer);
SysCheckRetExpNotNullMemory(AuMakeShared<Buffered::BlobWriter>(pBuffer), {});
}
}

View File

@ -42,6 +42,6 @@ namespace Aurora::IO::Adapters
AUKN_SYM AuSPtr<IStreamReader> NewSeekingReadAdapter(const AuSPtr<ISeekingReader> &pReader)
{
return AuMakeShared<SeekingReader>(pReader);
SysCheckRetExpNotNullMemory(AuMakeShared<SeekingReader>(pReader), {});
}
}

View File

@ -946,11 +946,7 @@ namespace Aurora::IO
static AuSPtr<IIOProcessor> NewIOProcessorEx(bool tickOnly, const AuSPtr<AuLoop::ILoopQueue> &queue, bool bIsNoQueue)
{
auto processor = AuMakeShared<IOProcessor>(0, tickOnly, AuOptionalEx<AuAsync::WorkerPId_t> {}, queue, bIsNoQueue);
if (!processor)
{
SysPushErrorMem();
return {};
}
SysCheckNotNullMemory(processor, {});
if (!processor->Init())
{
@ -964,11 +960,7 @@ namespace Aurora::IO
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessor(bool tickOnly, const AuSPtr<AuLoop::ILoopQueue> &queue)
{
auto processor = AuMakeShared<IOProcessor>(0, tickOnly, AuOptionalEx<AuAsync::WorkerPId_t> {}, queue, false);
if (!processor)
{
SysPushErrorMem();
return {};
}
SysCheckNotNullMemory(processor, {});
if (!processor->Init())
{
@ -1002,11 +994,7 @@ namespace Aurora::IO
}
auto processor = AuMakeShared<IOProcessor>(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<IIOProcessor> NewIOProcessorNoQueue(bool tickOnly)
{
auto loop = AuLoop::NewLoopQueue();
if (!loop)
{
SysPushErrorMem();
return {};
}
SysCheckNotNull(loop, {});
return NewIOProcessorEx(tickOnly, loop, true);
}

View File

@ -80,11 +80,11 @@ namespace Aurora::IO
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource>&pSource)
{
return AuMakeShared<IOWatachableIOLoopSource>(pSource);
SysCheckRetExpNotNullMemory(AuMakeShared<IOWatachableIOLoopSource>(pSource), {});
}
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSourceEx(const AuSPtr<Loop::ILoopSource>&pSource, AuUInt32 dwIoTimeoutMS)
{
return AuMakeShared<IOWatachableIOLoopSource>(pSource, dwIoTimeoutMS);
SysCheckRetExpNotNullMemory(AuMakeShared<IOWatachableIOLoopSource>(pSource, dwIoTimeoutMS), {});
}
}

View File

@ -75,10 +75,7 @@ namespace Aurora::IO::FS
AuSPtr<IAsyncTransaction> NtAsyncFileStream::NewTransaction()
{
auto shared = AuMakeShared<NtAsyncFileTransaction>();
if (!shared)
{
return {};
}
SysCheckNotNullMemory(shared, {});
if (!shared->InitWeak(this->pHandle_))
{
@ -593,7 +590,7 @@ namespace Aurora::IO::FS
AuSPtr<AuLoop::ILoopSource> NtAsyncFileTransaction::NewLoopSource()
{
return AuMakeShared<NtAsyncFileTransactionLoopSource>(AuSharedFromThis());
SysCheckRetExpNotNullMemory(AuMakeShared<NtAsyncFileTransactionLoopSource>(AuSharedFromThis()), {});
}
AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, bool directIO, EFileAdvisoryLockLevel lock)

View File

@ -105,11 +105,7 @@ namespace Aurora::IO::FS
AUKN_SYM bool DirDeleter(const AuString &string)
{
auto pObj = AuMakeShared<RecursiveDirDeleter>();
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<AuString> &failingPaths)
{
auto pObj = AuMakeShared<RecursiveDirDeleter>();
if (!pObj)
{
SysPushErrorMem();
return {};
}
SysCheckNotNullMemory(pObj, false);
if (!pObj->OpenDir(string))
{

View File

@ -58,18 +58,10 @@ namespace Aurora::IO::FS
auto qwLength = pFileSrc->GetLength();
auto pFileStream = AuMakeShared<AuIO::FS::FileReader>(pFileSrc);
if (!pFileStream)
{
SysPushErrorMemory();
return {};
}
SysCheckNotNullMemory(pFileStream, {});
auto pDestStream = AuMakeShared<AuIO::FS::FileWriter>(pFileDest);
if (!pDestStream)
{
SysPushErrorMemory();
return {};
}
SysCheckNotNullMemory(pDestStream, {});
AuCompression::CompressInfo compress { type };
compress.uCompressionLevel = level;

View File

@ -452,11 +452,7 @@ namespace Aurora::IO::FS
AUKN_SYM AuSPtr<IFileStream> OpenBlockingFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle)
{
auto pStream = AuMakeShared<WinFileStream>();
if (!pStream)
{
SysPushErrorMemory();
return nullptr;
}
SysCheckNotNullMemory(pStream, {});
pStream->Init(pIOHandle);
return pStream;

View File

@ -1525,6 +1525,6 @@ namespace Aurora::IO::Loop
AUKN_SYM AuSPtr<ILoopQueue> NewLoopQueue()
{
return AuMakeShared<LoopQueue>();
SysCheckRetExpNotNullMemory(AuMakeShared<LoopQueue>(), {});
}
}