OK I was able to fix the problem with the temp variables, although I'd need some thorough testing to verify that it works in all cases. Basically, what I needed to do is whenever an argument, local or static variable gets assigned, I need to check whether that same variable is currently on the stack. If so, I need to get a new temp variable and assigne it the value of the variable, and also replace the previous variable with the temp variable everywhere it shows up on the stack. Below is what the fixed function looks like:
Void VirtualString::Ctor_VirtualString(VirtualThread* pThread, VirtualString** pThis, Char* pStr)
{
// Ref type locals
VirtualString** temp0 = (VirtualString**)&pThread->StackPointer[1];
memset(&pThread->StackPointer[1], 0, sizeof(void*) * 1);
pThread->StackPointer += 1;
// Value type locals
Bool local0 = false;
Char* temp1 = null;
Char* temp2 = null;
IL_0000: // ldarg.0
IL_0001: // call Void .ctor()
(*pThis)->VirtualObject::Ctor_VirtualObject(pThread, (VirtualObject**)pThis);
IL_0006: // nop
IL_0007: // nop
IL_0008: // ldarg.0
IL_0009: // ldarg.1
IL_000a: // stfld Char* m_staticBuffer
(*pThis)->m_staticBuffer = pStr;
IL_000f: // ldarg.0
IL_0010: // ldc.i4.0
IL_0011: // stfld UInt16 m_length
(*pThis)->m_length = 0;
IL_0016: // ldarg.0
IL_0017: // ldfld Char* m_staticBuffer
IL_001c: // ldc.i4.0
IL_001d: // conv.u
IL_001e: // ceq
IL_0020: // ldc.i4.0
IL_0021: // ceq
IL_0023: // stloc.0
local0 = (((*pThis)->m_staticBuffer == (Int32)(UInt32)(0)) == 0);
IL_0024: // ldloc.0
IL_0025: // brtrue.s 2
if (local0 != 0)
goto IL_0029;
IL_0027: // br.s 36
goto IL_004d;
IL_0029: // br.s 15
goto IL_003a;
IL_002b: // ldarg.0
IL_002c: // dup
(*temp0) = *(pThis);
IL_002d: // ldfld UInt16 m_length
IL_0032: // ldc.i4.1
IL_0033: // add
IL_0034: // conv.u2
IL_0035: // stfld UInt16 m_length
(*pThis)->m_length = (Int32)(UInt16)(((Int32)(*temp0)->m_length + 1));
IL_003a: // ldarg.1
IL_003b: // dup
temp1 = pStr;
IL_003c: // ldc.i4.2
IL_003d: // conv.i
IL_003e: // add
IL_003f: // starg.s Char* pStr
temp2 = pStr;
pStr = (Char*)(((Int32)temp1 + (Int32)2));
IL_0041: // ldind.u2
IL_0042: // ldc.i4.0
IL_0043: // ceq
IL_0045: // ldc.i4.0
IL_0046: // ceq
IL_0048: // stloc.0
local0 = ((((UInt16)*(UInt16*)temp2) == 0) == 0);
IL_0049: // ldloc.0
IL_004a: // brtrue.s -33
if (local0 != 0)
goto IL_002b;
IL_004c: // nop
IL_004d: // ret
goto Exit;
Exit:
pThread->StackPointer -= 1;
}
Note at line IL_003f, a temp local is used to store the value of pStr before it is assigned a different value. At line IL_0048, that temp local is used instead of the now changed pStr. This fixes the bug with the off-by-one I was seeing previously.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.