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

Soundness issue when borrowing Lua in a callback #33

Closed
kyren opened this issue Aug 1, 2017 · 3 comments
Closed

Soundness issue when borrowing Lua in a callback #33

kyren opened this issue Aug 1, 2017 · 3 comments

Comments

@kyren
Copy link
Contributor

kyren commented Aug 1, 2017

Currently this compiles, and that is a problem because lua does not have a stable address. Closures should go back to having a 'static lifetime.

    let lua = Lua::new();
    let globals = lua.globals();

    globals.set("boom", lua.create_function(|_, _| {
        lua.pack(lua.eval::<i32>("1 + 1", None)?)
    })).unwrap();
@jonas-schievink
Copy link
Contributor

Just to clarify: This example in itself is still fine, the issue is that the borrow of lua isn't tracked by Rust, allowing code to move it while it's still borrowed: Doing let moved = lua; after the code above would compile (after a bit of restructuring) and lead to a dangling pointer deref when the function is called.

@kyren
Copy link
Contributor Author

kyren commented Aug 1, 2017

Thanks for the clarification, that is exactly right. This is discussed further in #32 for anybody following along, but we should probably discuss it further here.

So, the proposed solution is simply to move callbacks back to 'static lifetime, and I don't see really any other way of solving this, but it sounds like you might have some ideas?

@jonas-schievink
Copy link
Contributor

Let's go back to 'static for now. Should I feel very motivated I might search for a better solution, but I don't think that's happening anytime soon.

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