mirror of https://github.com/libAthena/athena.git
Don't rely on seek() to write alignment bytes
This commit is contained in:
parent
5df07a2039
commit
f3226c6102
|
@ -1870,26 +1870,19 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
|
|||
if (alignVal)
|
||||
{
|
||||
fileOut << " /* " << fieldName << " */\n";
|
||||
if (alignVal == 32)
|
||||
{
|
||||
if (!p)
|
||||
fileOut << " " ATHENA_DNA_READER ".seekAlign32();\n";
|
||||
else
|
||||
fileOut << " " ATHENA_DNA_WRITER ".seekAlign32();\n";
|
||||
}
|
||||
else if (align.isPowerOf2())
|
||||
if (align.isPowerOf2())
|
||||
{
|
||||
if (!p)
|
||||
fileOut << " " ATHENA_DNA_READER ".seek((" ATHENA_DNA_READER ".position() + " << alignVal-1 << ") & ~" << alignVal-1 << ", athena::Begin);\n";
|
||||
else
|
||||
fileOut << " " ATHENA_DNA_WRITER ".seek((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") & ~" << alignVal-1 << ", athena::Begin);\n";
|
||||
fileOut << " " ATHENA_DNA_WRITER ".writeZeroTo((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") & ~" << alignVal-1 << ");\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!p)
|
||||
fileOut << " " ATHENA_DNA_READER ".seek((" ATHENA_DNA_READER ".position() + " << alignVal-1 << ") / " << alignVal << " * " << alignVal << ", athena::Begin);\n";
|
||||
else
|
||||
fileOut << " " ATHENA_DNA_WRITER ".seek((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") / " << alignVal << " * " << alignVal << ", athena::Begin);\n";
|
||||
fileOut << " " ATHENA_DNA_WRITER ".writeZeroTo((" ATHENA_DNA_WRITER ".position() + " << alignVal-1 << ") / " << alignVal << " * " << alignVal << ");\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,17 @@ public:
|
|||
*/
|
||||
inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);}
|
||||
|
||||
/** @brief Writes zero up to specified absolute offset.<br />
|
||||
*/
|
||||
inline void writeZeroTo(atInt64 pos)
|
||||
{
|
||||
atInt64 delta = pos - position();
|
||||
if (delta <= 0)
|
||||
return;
|
||||
for (atInt64 i=0 ; i<delta ; ++i)
|
||||
writeUByte(0);
|
||||
}
|
||||
|
||||
/** @brief Returns whether or not the stream is at the end.
|
||||
*
|
||||
* @return True if at end; False otherwise.
|
||||
|
|
Loading…
Reference in New Issue