Compare commits

...

4 Commits

Author SHA1 Message Date
Alex Orlenko 78331ceebe v0.11.1 2025-07-15 22:43:18 +01:00
Alex Orlenko f945a35cbd Execute metatable destructor in Table::set_metatable at the end of invocation
Before this change, destructor was executed shortly after pushing metatable to ref_thread.
2025-07-15 19:14:46 +01:00
Alex Orlenko 459edb6816 Always grow aux ref stack considering the reserve 2025-07-15 16:32:22 +01:00
Alex Orlenko 00328b0b64 Protect Lua::push_c_function for Lua <5.2 2025-07-15 16:11:31 +01:00
5 changed files with 26 additions and 5 deletions
+5
View File
@@ -1,3 +1,8 @@
## v0.11.1 (Jul 15, 2025)
- Fixed bug exhausting Lua auxiliary stack and leaving it without reserve (#615)
- `Lua::push_c_function` now correctly handles OOM for Lua 5.1 and Luau
## v0.11.0 (Jul 14, 2025)
Changes since v0.11.0-beta.3
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "mlua"
version = "0.11.0" # remember to update mlua_derive
version = "0.11.1" # remember to update mlua_derive
authors = ["Aleksandr Orlenko <zxteam@pm.me>", "kyren <catherine@kyju.org>"]
rust-version = "1.79.0"
edition = "2021"
+18 -2
View File
@@ -1286,8 +1286,24 @@ impl Lua {
/// This function is unsafe because provides a way to execute unsafe C function.
pub unsafe fn create_c_function(&self, func: ffi::lua_CFunction) -> Result<Function> {
let lua = self.lock();
ffi::lua_pushcfunction(lua.ref_thread(), func);
Ok(Function(lua.pop_ref_thread()))
if cfg!(any(feature = "lua54", feature = "lua53", feature = "lua52")) {
ffi::lua_pushcfunction(lua.ref_thread(), func);
return Ok(Function(lua.pop_ref_thread()));
}
// Lua <5.2 requires memory allocation to push a C function
let state = lua.state();
{
let _sg = StackGuard::new(state);
check_stack(state, 3)?;
if lua.unlikely_memory_error() {
ffi::lua_pushcfunction(state, func);
} else {
protect_lua!(state, 0, 1, |state| ffi::lua_pushcfunction(state, func))?;
}
Ok(Function(lua.pop_ref()))
}
}
/// Wraps a Rust async function or closure, creating a callable Lua function handle to it.
+1 -1
View File
@@ -270,7 +270,7 @@ impl ExtraData {
// Try to grow max stack size
if self.ref_stack_top >= self.ref_stack_size {
let mut inc = self.ref_stack_size; // Try to double stack size
while inc > 0 && ffi::lua_checkstack(self.ref_thread, inc) == 0 {
while inc > 0 && ffi::lua_checkstack(self.ref_thread, inc + REF_STACK_RESERVE) == 0 {
inc /= 2;
}
if inc == 0 {
+1 -1
View File
@@ -510,7 +510,7 @@ impl Table {
let lua = self.0.lua.lock();
let ref_thread = lua.ref_thread();
unsafe {
if let Some(metatable) = metatable {
if let Some(metatable) = &metatable {
ffi::lua_pushvalue(ref_thread, metatable.0.index);
} else {
ffi::lua_pushnil(ref_thread);