Skip to content
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

[Question]Why luajit feature not support memory_limit #119

Closed
iiibui opened this issue Jan 8, 2022 · 4 comments
Closed

[Question]Why luajit feature not support memory_limit #119

iiibui opened this issue Jan 8, 2022 · 4 comments

Comments

@iiibui
Copy link

iiibui commented Jan 8, 2022

Related code:
https://github.com/khvzak/mlua/blob/cfb5d3fd45a810e5cde6811b039d154241d1444c/src/lua.rs#L332-L399

fn allocator include luajit feature, but it is not used when new lua state.

@khvzak
Copy link
Member

khvzak commented Jan 8, 2022

It's quite interesting question.

Mostly because In Lua 5.1/JIT lua_pushcfunction api call can trigger memory errors. Our protection mechanism to intercept Lua exceptions heavy relies on resilient lua_pushcfunction call. There is a way how to fail it and trigger uncought exception that would crash the program -- is enable memory limits for 5.1/JIT.
In Lua >= 5.2 this function never triggers memory errors.

Unfortunately I don't see a simple way how to enable memory limits in Lua 5.1/JIT 🤔

@iiibui
Copy link
Author

iiibui commented Jan 16, 2022

Thank you for your reply.

It's a little complicated for me, maybe I should use unsafe rust to call luajit c api directly😢

@khvzak
Copy link
Member

khvzak commented Jan 16, 2022

maybe I should use unsafe rust to call luajit c api directly

it does not matter actually, you would get crash unless wrap it to lua_cpcall.

@khvzak khvzak closed this as completed in ff35386 Mar 26, 2023
khvzak added a commit that referenced this issue Mar 26, 2023
Other versions already support this feature.
Closes #119
@khvzak
Copy link
Member

khvzak commented Mar 26, 2023

I believe I found a good workaround, so memory limits will be supported for any Lua in v0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants