-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safer handling of the Lua stack #188
Conversation
Can you review this, @scoder ? |
* Make lock_runtime return boolean and not raise error directly * If check_lua_stack fails on _LuaRuntimeStack.__enter__, unlocks LuaRuntime, avoiding the resource to be acquired forever * Use _LuaRuntimeStack in py_to_lua_custom (unrolls stack on Python error) * Use _LuaRuntimeStack in py_to_lua_overflow (catches error on py_to_lua_custom) * Add preconditions and postconditions to important functions/methods * Add assertion for extra >= 0 on check_lua_stack (would violate Lua C API precondition and probably cause undefined behaviour) * Lock LuaRuntime instance on _fix_args_kwargs and ensure 1 Lua stack slot
Did you test if this has any performance impact? (I.e., can you prove that it doesn't?) |
Previously, with the context handler it was 50% the speed. |
Note that |
I change my mind -- I think it's fine the way it is, explicit and efficient. |
Could you review this, @scoder? It makes Lupa more reliable, in that we guarantee we can push new values to the Lua stack. |
Yes, this looks very clean and helpful. |
Let's get this merged, @scoder ? I depend on it for future PRs. |
Works for me. Thanks! |
Some places don't lock the LuaRuntime before fiddling with the Lua stack, and many places don't ensure extra slots either.
This PR also involves other changes:
_LuaObject.__str__
__tostring
doesn't exist, use_LuaObject.__repr__
__tostring
returns non-string value, raise aTypeError
__tostring
raises an error, raise aLuaError
lua_pushglobaltable
instead of pushing_G
, which may not point to the global table.lock_runtime
return boolean and not raise error directlyLUA_NOREF
andLUA_REFNIL
constants for effective handling of Lua referencesLuaRuntime._state
is notNULL
, and if_LuaObject._runtime
isNone
, etc...)