[+] TryResize test for bytebuffer type

[+] Added path in telemetry formats under NT FIO failures
[*] Various bug fixes
This commit is contained in:
Reece Wilson 2021-09-06 20:04:01 +01:00
parent de95a9de6f
commit eb6a1eaad0
9 changed files with 164 additions and 53 deletions

View File

@ -417,8 +417,15 @@ static inline bool AuTryResize(T &list, AuUInt length)
{
try
{
list.resize(length);
return true;
if constexpr (std::is_same_v<T, Aurora::Memory::ByteBuffer>)
{
return list.Resize(length);
}
else
{
list.resize(length);
return true;
}
}
catch (...)
{

View File

@ -68,7 +68,10 @@ namespace Aurora::Compression
return false;
}
this->_outbuffer.Resize(increase);
if (!this->_outbuffer.Resize(increase))
{
return false;
}
auto remaining = length - written;
written = this->_outbuffer.Write(reinterpret_cast<const AuUInt8 *>(a) + written,

View File

@ -19,9 +19,21 @@ namespace Aurora::Compression
{
static bool DecompressZSTD(const CompressionPipe &info)
{
AuList<AuUInt8> buffer;
AuList<AuUInt8> inflatedBuffer;
if (!info.writePipe)
{
return false;
}
if (!info.inPipe)
{
return false;
}
auto length = ZSTD_DStreamInSize();
AuList<AuUInt8> buffer;
auto ok = AuTryResize(buffer, length);
if (!ok)
{
@ -30,7 +42,6 @@ namespace Aurora::Compression
}
auto outFrameLength = ZSTD_DStreamOutSize();
AuList<AuUInt8> inflatedBuffer;
ok = AuTryResize(inflatedBuffer, outFrameLength);
if (!ok)
{
@ -79,11 +90,22 @@ namespace Aurora::Compression
static bool CompressZSTD(const CompressionPipe &stream, const CompressionInfo &info)
{
AuList<AuUInt8> inflatedBuffer;
AuList<AuUInt8> deflatedBuffer;
size_t ret;
const auto buffInSize = ZSTD_CStreamInSize();
const auto buffOutSize = ZSTD_CStreamOutSize();
if (!stream.writePipe)
{
return false;
}
if (!stream.inPipe)
{
return false;
}
AuList<AuUInt8> inflatedBuffer;
auto ok = AuTryResize(inflatedBuffer, buffInSize);
if (!ok)
{
@ -91,7 +113,6 @@ namespace Aurora::Compression
return false;
}
AuList<AuUInt8> deflatedBuffer;
ok = AuTryResize(deflatedBuffer, buffOutSize);
if (!ok)
{
@ -198,6 +219,16 @@ namespace Aurora::Compression
z_stream strm {};
unsigned char in[kChunkSize];
unsigned char out[kChunkSize];
if (!stream.writePipe)
{
return false;
}
if (!stream.inPipe)
{
return false;
}
ret = deflateInit(&strm, info.compressionLevel);
if (ret != Z_OK)
@ -259,6 +290,16 @@ namespace Aurora::Compression
z_stream strm {};
unsigned char in[kChunkSize];
unsigned char out[kChunkSize];
if (!stream.writePipe)
{
return false;
}
if (!stream.inPipe)
{
return false;
}
ret = inflateInit(&strm);
if (ret != Z_OK)
@ -290,6 +331,7 @@ namespace Aurora::Compression
if (ret != Z_OK)
{
SysPushErrorIO("Error: {}", ret);
inflateEnd(&strm);
return false;
}
@ -322,6 +364,16 @@ namespace Aurora::Compression
bz_stream strm {};
char in[kChunkSize];
char out[kChunkSize];
if (!stream.writePipe)
{
return false;
}
if (!stream.inPipe)
{
return false;
}
ret = BZ2_bzCompressInit(&strm, info.compressionLevel, 0, 0);
if (ret != BZ_OK)
@ -384,6 +436,16 @@ namespace Aurora::Compression
bz_stream strm {};
char in[kChunkSize];
char out[kChunkSize];
if (!stream.writePipe)
{
return false;
}
if (!stream.inPipe)
{
return false;
}
ret = BZ2_bzDecompressInit(&strm, 0, 0);
if (ret != Z_OK)
@ -518,6 +580,16 @@ namespace Aurora::Compression
LZ4F_decompressOptions_t opts {};
AuUInt32 lastFrameMaxSize {};
AuSPtr<char> bufferIn, bufferOut;
if (!pipe.writePipe)
{
return false;
}
if (!pipe.inPipe)
{
return false;
}
auto err = LZ4F_createDecompressionContext(&dctxPtr, LZ4F_getVersion());
if (LZ4F_isError(err))

View File

@ -133,7 +133,7 @@ namespace Aurora::IO::FS
if (!::ReadFile(fileHandle, &buffer[offset], blockSize, &read, NULL))
{
LogWarn("ReadFile IO Error: 0x%x", GetLastError());
LogWarn("ReadFile IO Error: 0x%x {}", GetLastError(), path);
SysPushErrorIO();
goto out;
}

View File

@ -39,7 +39,7 @@ namespace Aurora::IO::FS
if (SetFilePointerEx(handle_, distance, &pos, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
{
LogWarn("SetFilePointerEx IO Error: 0x%x", GetLastError());
LogWarn("SetFilePointerEx IO Error: 0x%x, {}", GetLastError(), path_);
SysPushErrorIO();
return 0;
}
@ -62,7 +62,7 @@ namespace Aurora::IO::FS
if (SetFilePointerEx(handle_, distance, &pos, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
{
LogWarn("SetFilePointerEx IO Error: 0x%x", GetLastError());
LogWarn("SetFilePointerEx IO Error: 0x%x, {}", GetLastError(), path_);
SysPushErrorIO();
return false;
}
@ -106,7 +106,7 @@ namespace Aurora::IO::FS
if (!::ReadFile(handle_, &reinterpret_cast<char *>(in)[offset], blockSize, &read, NULL))
{
LogWarn("ReadFile IO Error: 0x%x", GetLastError());
LogWarn("ReadFile IO Error: 0x%x, {}", GetLastError(), path_);
SysPushErrorIO();
break;
}
@ -140,7 +140,7 @@ namespace Aurora::IO::FS
if (!::WriteFile(handle_, &reinterpret_cast<const char *>(out)[offset], blockSize, &written, NULL))
{
LogWarn("WriteFileEx IO Error: 0x%x", GetLastError());
LogWarn("WriteFileEx IO Error: 0x%x, {}", GetLastError(), path_);
SysPushErrorIO();
return offset;
}

View File

@ -97,7 +97,7 @@ namespace Aurora::Locale::Encoding
reinterpret_cast<char *>(out) + outLen,
toNext);
return {fromNext - reinterpret_cast<const charin_t *>(in), toNext - out};
return {(fromNext - reinterpret_cast<const charin_t *>(in)) * sizeof(charin_t), toNext - out};
#endif
}

View File

@ -35,6 +35,17 @@ namespace Aurora::Locale::Encoding
{
AuStreamReadWrittenPair_t ret {};
if (!length)
{
return {};
}
if (!in)
{
return {};
}
if (((page == ECodePage::eSysUnk) &&
(GetInternalCodePage() == ECodePage::eUTF8)) ||
(page == ECodePage::eUTF8))
@ -59,6 +70,16 @@ namespace Aurora::Locale::Encoding
AuStreamReadWrittenPair_t EncoderAdapter::CPToUTF8(const void *in, AuUInt32 length, void *utf8, AuUInt32 utf8Max)
{
AuStreamReadWrittenPair_t ret {};
if (!length)
{
return {};
}
if (!in)
{
return {};
}
if (((page == ECodePage::eSysUnk) &&
(GetInternalCodePage() == ECodePage::eUTF8)) ||
@ -85,6 +106,16 @@ namespace Aurora::Locale::Encoding
{
AuStreamReadWrittenPair_t ret {};
if (!utf8)
{
return {};
}
if (!utf8Length)
{
return {};
}
if (((page == ECodePage::eSysUnk) &&
(GetInternalCodePage() == ECodePage::eUTF8)) ||
(page == ECodePage::eUTF8))

View File

@ -74,49 +74,17 @@ namespace Aurora::Locale::Encoding
}
auto pWideChars = (const wchar_t *)in;
AuUInt32 iCChars = inLength / sizeof(wchar_t);
AuUInt32 lastIdx = 0;
AuUInt32 lastEnd = 0;
AuUInt32 curIdx = 0;
for (curIdx = 0; curIdx < iCChars; curIdx++)
{
if (IS_LOW_SURROGATE(pWideChars[curIdx]))
{
if (curIdx + 2 > iCChars)
{
break;
}
if (!IS_HIGH_SURROGATE(pWideChars[curIdx + 1]))
{
break;
}
lastEnd = curIdx + 2;
}
else
{
lastEnd = curIdx + 1;
}
lastIdx = curIdx;
}
AuUInt32 cpLength;
if (!utf8)
{
cpLength = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t *)in, lastEnd, NULL, NULL, NULL, NULL);
return {lastEnd, cpLength};
auto cpLength = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t *)in, inLength / sizeof(wchar_t), NULL, NULL, NULL, NULL);
return {inLength, cpLength};
}
else
{
cpLength = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t *)in, lastEnd, (LPSTR)utf8, utf8Len, NULL, NULL);
#if 0
auto actLen = lastEnd;
#else
auto actLen = MultiByteToWideChar(CP_UTF8, 0, (LPSTR)utf8, utf8Len, NULL, 0); // this might be worth it in the long run
#endif
return {actLen, cpLength};
cpLength = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t *)in, inLength / sizeof(wchar_t), (LPSTR)utf8, utf8Len, NULL, NULL);
return {inLength, cpLength};
}
#else
@ -164,7 +132,7 @@ namespace Aurora::Locale::Encoding
read = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)utf16, chars, NULL, 0, NULL, NULL);
}
return {read, chars};
return {read, chars * sizeof(wchar_t)};
#else
return {};
#endif

View File

@ -86,6 +86,36 @@ namespace Aurora::Locale::Encoding
}
return i;
}
#define AU_HIGH_SURROGATE_START 0xd800
#define AU_HIGH_SURROGATE_END 0xdbff
#define AU_LOW_SURROGATE_START 0xdc00
#define AU_LOW_SURROGATE_END 0xdfff
#define AU_IS_HIGH_SURROGATE(wch) (((wch) >= AU_HIGH_SURROGATE_START) && ((wch) <= AU_HIGH_SURROGATE_END))
#define AU_IS_LOW_SURROGATE(wch) (((wch) >= AU_LOW_SURROGATE_START) && ((wch) <= AU_LOW_SURROGATE_END))
static int GetLenUC2CodePoint(const AuUInt8 *in, AuUInt32 len)
{
if (len < 2) return 0;
auto a = *reinterpret_cast<const AuUInt16 *>(in);
if (!AU_IS_HIGH_SURROGATE(a)) return 2;
if (len < 4) return 0;
auto b = *reinterpret_cast<const AuUInt16 *>(in + 2);
return AU_IS_LOW_SURROGATE(b) ? 4 : 0;
}
static int GetLenUC2String(const AuUInt8 *in, AuUInt32 len)
{
AuUInt32 i;
for (i = 0; i < len; )
{
auto next = GetLenUC2CodePoint(in + i, len - i);
if (next == 0) return i;
i += next;
}
return i;
}
AuStreamReadWrittenPair_t EncodeUTF8(TypeIn_t binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utfLen)
{
@ -136,9 +166,9 @@ namespace Aurora::Locale::Encoding
}
else if ((page == ECodePage::eUTF16) || (page == ECodePage::eUTF16BE))
{
binaryLength &= ~1;
binaryLength = GetLenUC2String(reinterpret_cast<TypeCast_t>(binary) + offset, binaryLength);
}
else if ((page == ECodePage::eUTF32) || (page == ECodePage::eUTF32))
else if ((page == ECodePage::eUTF32) || (page == ECodePage::eUTF32BE))
{
binaryLength &= ~3;
}