mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Lower fastpath table creation limit to 1 << 26
When Lua is configured without memory restrictions, we use fastpath for table creation (unprotected mode). In generally it's safe as long as we `abort()` on allocation failure. However some Lua versions have additional restrictions on table size that we need to adhere in mlua too. Probably Luau has the lowest limits. Fixes #627
This commit is contained in:
+1
-1
@@ -122,7 +122,7 @@ pub(crate) unsafe fn push_table(
|
||||
) -> Result<()> {
|
||||
let narr: c_int = narr.try_into().unwrap_or(c_int::MAX);
|
||||
let nrec: c_int = nrec.try_into().unwrap_or(c_int::MAX);
|
||||
if protect || narr >= const { 1 << 30 } || nrec >= const { 1 << 27 } {
|
||||
if protect || narr >= const { 1 << 26 } || nrec >= const { 1 << 26 } {
|
||||
protect_lua!(state, 0, 1, |state| ffi::lua_createtable(state, narr, nrec))
|
||||
} else {
|
||||
ffi::lua_createtable(state, narr, nrec);
|
||||
|
||||
@@ -61,6 +61,15 @@ fn test_table() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")] // Linux allow overcommiting the memory (relevant for CI)
|
||||
fn test_table_with_large_capacity() {
|
||||
let lua = Lua::new();
|
||||
|
||||
let t = lua.create_table_with_capacity(1 << 26, 1 << 26);
|
||||
assert!(t.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_push_pop() -> Result<()> {
|
||||
let lua = Lua::new();
|
||||
|
||||
Reference in New Issue
Block a user