euddraft icon indicating copy to clipboard operation
euddraft copied to clipboard

var -= ConstExpr causes OverflowError

Open armoha opened this issue 3 years ago • 2 comments

Only reproducible when Cython enabled:

function afterTriggerExec() {
    var x;
    x -= Db(4);
}

[1/3 Step] Collecting objects... ========================================== [Error] Python int too large to convert to C unsigned long Traceback (most recent call last): File "E:\euddraft\applyeuddraft.py", line 186, in applyEUDDraft ep.SaveMap(ofname, payloadMain, sectorSize=sectorSize) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\maprw\savemap.py", line 73, in SaveMap applyInjector(chkt, root) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\maprw\injector\applyInjector.py", line 52, in applyInjector payload = c.CreatePayload(root) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\core\allocator\payload.py", line 376, in CreatePayload CollectObjects(root) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\core\allocator\payload.py", line 160, in CollectObjects obj.CollectDependency(objc) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\core\rawtrigger\rawtriggerdef.py", line 149, in CollectDependency act.CollectDependency(pbuffer) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\core\rawtrigger\action.py", line 141, in CollectDependency wdw(fld[5]) File "C:\Py\lib\site-packages\eudplib-0.67.1-py3.8-win32.egg\eudplib\core\allocator\payload.py", line 112, in WriteDword constexpr.Evaluate(number) File "eudplib\core\allocator\constexpr.pyx", line 216, in eudplib.core.allocator.constexpr.Evaluate File "eudplib\core\allocator\constexpr.pyx", line 221, in eudplib.core.allocator.constexpr.Evaluate File "eudplib\core\allocator\constexpr.pyx", line 52, in eudplib.core.allocator.constexpr.ConstExpr.Evaluate File "eudplib\core\allocator\constexpr.pyx", line 53, in eudplib.core.allocator.constexpr.ConstExpr.Evaluate File "eudplib\core\allocator\rlocint.pyx", line 80, in eudplib.core.allocator.rlocint.RlocInt_C.__mul__ File "eudplib\core\allocator\rlocint.pyx", line 35, in eudplib.core.allocator.rlocint.RlocInt_C.__cinit__ OverflowError: Python int too large to convert to C unsigned long

  • [ ] Negative ConstExpr.rlocmode loss its signedness
  • [ ] 4 * 4294967292 = 17179869168 is too large for size_t rlocmode of RlocInt_C

armoha avatar Nov 17 '21 18:11 armoha

Another footgun example)

const array = EUDArray(8);
function afterTriggerExec() {
    setcurpl(P1);
    const x = dwread_cp(EPD(array));
}

armoha avatar Jan 31 '22 14:01 armoha

Falsy optimization by negating ConstExpr

class EUDVariable(VariableBase):
    def __sub__(self, other):
        t = EUDVariable()
        # FIXME: unsupported EUD error after EUDStruct.free() with IsConstExpr
        if isinstance(other, int):
            SeqCompute(
                [
                    (t, bt.SetTo, -other),
                    (t, bt.Add, self),
                ]
            )
        else:
            SeqCompute(
                [
                    (t, bt.SetTo, 0xFFFFFFFF),
                    (t, bt.Subtract, other),
                    (t, bt.Add, 1),
                    (t, bt.Add, self),
                ]
            )
        return t.makeR()

armoha avatar Mar 01 '22 07:03 armoha