🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

[PATCH] Fixing issue with returning double value with JIT

Started by
2 comments, last by WitchLord 10 years, 1 month ago

Hi,

I have found an issue with the angelscript engine that erases the value register when it is not supposed to, which causes a problem when using the JIT developed by BlindMind studios (see this thread). I guess it may also have other side effects in some other cases, so you might want to fix it.

Please find below a patch proposal:

--- angelscript/source/as_callfunc.cpp (AS 2.29 WIP)
+++ angelscript/source/as_callfunc.cpp (working copy)
@@ -672,7 +672,7 @@
*(asDWORD*)&context->m_regs.valueRegister = (asDWORD)retQW;
#endif
}
- else
+ else if( sysFunc->hostReturnSize == 2 )
context->m_regs.valueRegister = retQW;
}

It simply verifies that hostReturnSize is appropriate before copying data to the value register. Without this line, a function that does NOT return anything will actually erase the value register with garbage...

Please tell me if this makes sense...

Advertisement

I'd say the root cause for your problem was in the JIT compiler, which from the other thread I see that ThyReaper already fixed.

The m_regs.valueRegister must be considered volatile and short lived. The JIT compiler (or even the VM itself) must not rely on it keeping its value over a function call. Even if the value wasn't overwritten by the uninitialized value of retQW, it could still have been modified in a valid way from within the function that was called.

In the end it was actually fortunate that the valueRegister was overwritten by the call in this case since it allow you to detect the bug in the JIT compiler in an easily reproduced way. It might not have been so easy to detect in another situation.

I thank you for the good intention of providing the patch, but I will not make this change since there is no benefit with it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for the reply. The root cause was indeed an issue in the JIT that was fixed. I am still learning how Angelscript works... I apologize for this unnecessary patch!

No need to apologize. :)

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement