Don't use custom allocator for non-vendored LuaJIT (fixes #176)
This commit is contained in:
parent
d9ac7abff2
commit
ff0d923aae
18
src/lua.rs
18
src/lua.rs
|
@ -126,7 +126,6 @@ pub(crate) struct ExtraData {
|
||||||
sandboxed: bool,
|
sandboxed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(any(feature = "lua51", feature = "luajit"), allow(dead_code))]
|
|
||||||
struct MemoryInfo {
|
struct MemoryInfo {
|
||||||
used_memory: isize,
|
used_memory: isize,
|
||||||
memory_limit: isize,
|
memory_limit: isize,
|
||||||
|
@ -430,12 +429,19 @@ impl Lua {
|
||||||
new_ptr
|
new_ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
let mem_info = Box::into_raw(Box::new(MemoryInfo {
|
// Skip Rust allocator for non-vendored LuaJIT (see https://github.com/khvzak/mlua/issues/176)
|
||||||
used_memory: 0,
|
let use_rust_allocator = !(cfg!(feature = "luajit") && cfg!(not(feature = "vendored")));
|
||||||
memory_limit: 0,
|
|
||||||
}));
|
|
||||||
|
|
||||||
let state = ffi::lua_newstate(allocator, mem_info as *mut c_void);
|
let (state, mem_info) = if use_rust_allocator {
|
||||||
|
let mem_info = Box::into_raw(Box::new(MemoryInfo {
|
||||||
|
used_memory: 0,
|
||||||
|
memory_limit: 0,
|
||||||
|
}));
|
||||||
|
let state = ffi::lua_newstate(allocator, mem_info as *mut c_void);
|
||||||
|
(state, mem_info)
|
||||||
|
} else {
|
||||||
|
(ffi::luaL_newstate(), ptr::null_mut())
|
||||||
|
};
|
||||||
|
|
||||||
ffi::luaL_requiref(state, cstr!("_G"), ffi::luaopen_base, 1);
|
ffi::luaL_requiref(state, cstr!("_G"), ffi::luaopen_base, 1);
|
||||||
ffi::lua_pop(state, 1);
|
ffi::lua_pop(state, 1);
|
||||||
|
|
Loading…
Reference in New Issue