From fac39a2f46879d7d716d824a1f0842e6bc87a3f5 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Thu, 20 Jul 2023 01:02:23 +0100 Subject: [PATCH] Drop openresty specific luajit extensions --- mlua-sys/src/lib.rs | 6 +----- mlua-sys/src/lua51/lua.rs | 3 --- src/lua.rs | 40 +++++++++++---------------------------- src/thread.rs | 22 ++++++--------------- tests/thread.rs | 6 +----- 5 files changed, 19 insertions(+), 58 deletions(-) diff --git a/mlua-sys/src/lib.rs b/mlua-sys/src/lib.rs index ea4967a..72a2fed 100644 --- a/mlua-sys/src/lib.rs +++ b/mlua-sys/src/lib.rs @@ -26,14 +26,10 @@ pub use luau::*; #[doc(hidden)] pub const LUA_MAX_UPVALUES: c_int = 255; -#[cfg(any(feature = "lua51", all(feature = "luajit", not(feature = "vendored"))))] +#[cfg(any(feature = "lua51", feature = "luajit"))] #[doc(hidden)] pub const LUA_MAX_UPVALUES: c_int = 60; -#[cfg(all(feature = "luajit", feature = "vendored"))] -#[doc(hidden)] -pub const LUA_MAX_UPVALUES: c_int = 120; - #[cfg(feature = "luau")] #[doc(hidden)] pub const LUA_MAX_UPVALUES: c_int = 200; diff --git a/mlua-sys/src/lua51/lua.rs b/mlua-sys/src/lua51/lua.rs index 9ca798c..a950db4 100644 --- a/mlua-sys/src/lua51/lua.rs +++ b/mlua-sys/src/lua51/lua.rs @@ -101,9 +101,6 @@ extern "C" { pub fn lua_close(L: *mut lua_State); pub fn lua_newthread(L: *mut lua_State) -> *mut lua_State; - #[cfg(all(feature = "luajit", feature = "vendored"))] - pub fn lua_resetthread(L: *mut lua_State, th: *mut lua_State); - pub fn lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction; // diff --git a/src/lua.rs b/src/lua.rs index 79f09c0..64ed3f7 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -173,7 +173,7 @@ pub struct LuaOptions { /// Max size of thread (coroutine) object pool used to execute asynchronous functions. /// - /// It works on Lua 5.4, LuaJIT (vendored) and Luau, where [`lua_resetthread`] function + /// It works on Lua 5.4 and Luau, where [`lua_resetthread`] function /// is available and allows to reuse old coroutines after resetting their state. /// /// Default: **0** (disabled) @@ -377,22 +377,14 @@ impl Lua { /// Creates a new Lua state with required `libs` and `options` unsafe fn inner_new(libs: StdLib, options: LuaOptions) -> Lua { - // Skip Rust allocator for non-vendored LuaJIT (see https://github.com/khvzak/mlua/issues/176) - let use_rust_allocator = !(cfg!(feature = "luajit") && cfg!(not(feature = "vendored"))); - - let (state, mem_state) = if use_rust_allocator { - let mut mem_state: *mut MemoryState = Box::into_raw(Box::default()); - let mut state = ffi::lua_newstate(ALLOCATOR, mem_state as *mut c_void); - // If state is null (it's possible for LuaJIT on non-x86 arch) then switch to Lua internal allocator - if state.is_null() { - drop(Box::from_raw(mem_state)); - mem_state = ptr::null_mut(); - state = ffi::luaL_newstate(); - } - (state, mem_state) - } else { - (ffi::luaL_newstate(), ptr::null_mut()) - }; + let mut mem_state: *mut MemoryState = Box::into_raw(Box::default()); + let mut state = ffi::lua_newstate(ALLOCATOR, mem_state as *mut c_void); + // If state is null then switch to Lua internal allocator + if state.is_null() { + drop(Box::from_raw(mem_state)); + mem_state = ptr::null_mut(); + state = ffi::luaL_newstate(); + } assert!(!state.is_null(), "Failed to instantiate Lua VM"); ffi::luaL_requiref(state, cstr!("_G"), ffi::luaopen_base, 1); @@ -1673,11 +1665,7 @@ impl Lua { &'lua self, func: &Function, ) -> Result> { - #[cfg(any( - feature = "lua54", - all(feature = "luajit", feature = "vendored"), - feature = "luau", - ))] + #[cfg(any(feature = "lua54", feature = "luau"))] unsafe { let state = self.state(); let _sg = StackGuard::new(state); @@ -1703,11 +1691,7 @@ impl Lua { /// Resets thread (coroutine) and returns to the pool for later use. #[cfg(feature = "async")] - #[cfg(any( - feature = "lua54", - all(feature = "luajit", feature = "vendored"), - feature = "luau", - ))] + #[cfg(any(feature = "lua54", feature = "luau"))] pub(crate) unsafe fn recycle_thread(&self, thread: &mut Thread) -> bool { let extra = &mut *self.extra.get(); if extra.thread_pool.len() < extra.thread_pool.capacity() { @@ -1721,8 +1705,6 @@ impl Lua { // Error object is on top, drop it ffi::lua_settop(thread_state, 0); } - #[cfg(all(feature = "luajit", feature = "vendored"))] - ffi::lua_resetthread(self.state(), thread_state); #[cfg(feature = "luau")] ffi::lua_resetthread(thread_state); extra.thread_pool.push(thread.0.index); diff --git a/src/thread.rs b/src/thread.rs index 75a6851..f062957 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -202,20 +202,16 @@ impl<'lua> Thread<'lua> { /// Returns a error in case of either the original error that stopped the thread or errors /// in closing methods. /// - /// In [LuaJIT] and Luau: resets to the initial state of a newly created Lua thread. + /// In Luau: resets to the initial state of a newly created Lua thread. /// Lua threads in arbitrary states (like yielded or errored) can be reset properly. /// /// Sets a Lua function for the thread afterwards. /// - /// Requires `feature = "lua54"` OR `feature = "luajit,vendored"` OR `feature = "luau"` + /// Requires `feature = "lua54"` OR `feature = "luau"`. /// - /// [Lua 5.4]: https://www.lua.org/manual/5.4/manual.html#lua_resetthread - /// [LuaJIT]: https://github.com/openresty/luajit2#lua_resetthread - #[cfg(any( - feature = "lua54", - all(feature = "luajit", feature = "vendored"), - feature = "luau", - ))] + /// [Lua 5.4]: https://www.lua.org/manual/5.4/manual.html#lua_closethread + #[cfg(any(feature = "lua54", feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn reset(&self, func: crate::function::Function<'lua>) -> Result<()> { let lua = self.0.lua; let state = lua.state(); @@ -234,8 +230,6 @@ impl<'lua> Thread<'lua> { if status != ffi::LUA_OK { return Err(pop_error(thread_state, status)); } - #[cfg(all(feature = "luajit", feature = "vendored"))] - ffi::lua_resetthread(state, thread_state); #[cfg(feature = "luau")] ffi::lua_resetthread(thread_state); @@ -375,11 +369,7 @@ impl<'lua, R> AsyncThread<'lua, R> { } #[cfg(feature = "async")] -#[cfg(any( - feature = "lua54", - all(feature = "luajit", feature = "vendored"), - feature = "luau", -))] +#[cfg(any(feature = "lua54", feature = "luau"))] impl<'lua, R> Drop for AsyncThread<'lua, R> { fn drop(&mut self) { if self.recycle { diff --git a/tests/thread.rs b/tests/thread.rs index b664053..8180676 100644 --- a/tests/thread.rs +++ b/tests/thread.rs @@ -94,11 +94,7 @@ fn test_thread() -> Result<()> { } #[test] -#[cfg(any( - feature = "lua54", - all(feature = "luajit", feature = "vendored"), - feature = "luau", -))] +#[cfg(any(feature = "lua54", feature = "luau"))] fn test_thread_reset() -> Result<()> { use mlua::{AnyUserData, UserData}; use std::sync::Arc;