Skip to content

Commit fac39a2

Browse files
committed
Drop openresty specific luajit extensions
1 parent 483e6be commit fac39a2

5 files changed

Lines changed: 19 additions & 58 deletions

File tree

β€Žmlua-sys/src/lib.rsβ€Ž

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ pub use luau::*;
2626
#[doc(hidden)]
2727
pub const LUA_MAX_UPVALUES: c_int = 255;
2828

29-
#[cfg(any(feature = "lua51", all(feature = "luajit", not(feature = "vendored"))))]
29+
#[cfg(any(feature = "lua51", feature = "luajit"))]
3030
#[doc(hidden)]
3131
pub const LUA_MAX_UPVALUES: c_int = 60;
3232

33-
#[cfg(all(feature = "luajit", feature = "vendored"))]
34-
#[doc(hidden)]
35-
pub const LUA_MAX_UPVALUES: c_int = 120;
36-
3733
#[cfg(feature = "luau")]
3834
#[doc(hidden)]
3935
pub const LUA_MAX_UPVALUES: c_int = 200;

β€Žmlua-sys/src/lua51/lua.rsβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ extern "C" {
101101
pub fn lua_close(L: *mut lua_State);
102102
pub fn lua_newthread(L: *mut lua_State) -> *mut lua_State;
103103

104-
#[cfg(all(feature = "luajit", feature = "vendored"))]
105-
pub fn lua_resetthread(L: *mut lua_State, th: *mut lua_State);
106-
107104
pub fn lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction;
108105

109106
//

β€Žsrc/lua.rsβ€Ž

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub struct LuaOptions {
173173

174174
/// Max size of thread (coroutine) object pool used to execute asynchronous functions.
175175
///
176-
/// It works on Lua 5.4, LuaJIT (vendored) and Luau, where [`lua_resetthread`] function
176+
/// It works on Lua 5.4 and Luau, where [`lua_resetthread`] function
177177
/// is available and allows to reuse old coroutines after resetting their state.
178178
///
179179
/// Default: **0** (disabled)
@@ -377,22 +377,14 @@ impl Lua {
377377

378378
/// Creates a new Lua state with required `libs` and `options`
379379
unsafe fn inner_new(libs: StdLib, options: LuaOptions) -> Lua {
380-
// Skip Rust allocator for non-vendored LuaJIT (see https://github.com/khvzak/mlua/issues/176)
381-
let use_rust_allocator = !(cfg!(feature = "luajit") && cfg!(not(feature = "vendored")));
382-
383-
let (state, mem_state) = if use_rust_allocator {
384-
let mut mem_state: *mut MemoryState = Box::into_raw(Box::default());
385-
let mut state = ffi::lua_newstate(ALLOCATOR, mem_state as *mut c_void);
386-
// If state is null (it's possible for LuaJIT on non-x86 arch) then switch to Lua internal allocator
387-
if state.is_null() {
388-
drop(Box::from_raw(mem_state));
389-
mem_state = ptr::null_mut();
390-
state = ffi::luaL_newstate();
391-
}
392-
(state, mem_state)
393-
} else {
394-
(ffi::luaL_newstate(), ptr::null_mut())
395-
};
380+
let mut mem_state: *mut MemoryState = Box::into_raw(Box::default());
381+
let mut state = ffi::lua_newstate(ALLOCATOR, mem_state as *mut c_void);
382+
// If state is null then switch to Lua internal allocator
383+
if state.is_null() {
384+
drop(Box::from_raw(mem_state));
385+
mem_state = ptr::null_mut();
386+
state = ffi::luaL_newstate();
387+
}
396388
assert!(!state.is_null(), "Failed to instantiate Lua VM");
397389

398390
ffi::luaL_requiref(state, cstr!("_G"), ffi::luaopen_base, 1);
@@ -1673,11 +1665,7 @@ impl Lua {
16731665
&'lua self,
16741666
func: &Function,
16751667
) -> Result<Thread<'lua>> {
1676-
#[cfg(any(
1677-
feature = "lua54",
1678-
all(feature = "luajit", feature = "vendored"),
1679-
feature = "luau",
1680-
))]
1668+
#[cfg(any(feature = "lua54", feature = "luau"))]
16811669
unsafe {
16821670
let state = self.state();
16831671
let _sg = StackGuard::new(state);
@@ -1703,11 +1691,7 @@ impl Lua {
17031691

17041692
/// Resets thread (coroutine) and returns to the pool for later use.
17051693
#[cfg(feature = "async")]
1706-
#[cfg(any(
1707-
feature = "lua54",
1708-
all(feature = "luajit", feature = "vendored"),
1709-
feature = "luau",
1710-
))]
1694+
#[cfg(any(feature = "lua54", feature = "luau"))]
17111695
pub(crate) unsafe fn recycle_thread(&self, thread: &mut Thread) -> bool {
17121696
let extra = &mut *self.extra.get();
17131697
if extra.thread_pool.len() < extra.thread_pool.capacity() {
@@ -1721,8 +1705,6 @@ impl Lua {
17211705
// Error object is on top, drop it
17221706
ffi::lua_settop(thread_state, 0);
17231707
}
1724-
#[cfg(all(feature = "luajit", feature = "vendored"))]
1725-
ffi::lua_resetthread(self.state(), thread_state);
17261708
#[cfg(feature = "luau")]
17271709
ffi::lua_resetthread(thread_state);
17281710
extra.thread_pool.push(thread.0.index);

β€Žsrc/thread.rsβ€Ž

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,16 @@ impl<'lua> Thread<'lua> {
202202
/// Returns a error in case of either the original error that stopped the thread or errors
203203
/// in closing methods.
204204
///
205-
/// In [LuaJIT] and Luau: resets to the initial state of a newly created Lua thread.
205+
/// In Luau: resets to the initial state of a newly created Lua thread.
206206
/// Lua threads in arbitrary states (like yielded or errored) can be reset properly.
207207
///
208208
/// Sets a Lua function for the thread afterwards.
209209
///
210-
/// Requires `feature = "lua54"` OR `feature = "luajit,vendored"` OR `feature = "luau"`
210+
/// Requires `feature = "lua54"` OR `feature = "luau"`.
211211
///
212-
/// [Lua 5.4]: https://www.lua.org/manual/5.4/manual.html#lua_resetthread
213-
/// [LuaJIT]: https://github.com/openresty/luajit2#lua_resetthread
214-
#[cfg(any(
215-
feature = "lua54",
216-
all(feature = "luajit", feature = "vendored"),
217-
feature = "luau",
218-
))]
212+
/// [Lua 5.4]: https://www.lua.org/manual/5.4/manual.html#lua_closethread
213+
#[cfg(any(feature = "lua54", feature = "luau"))]
214+
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
219215
pub fn reset(&self, func: crate::function::Function<'lua>) -> Result<()> {
220216
let lua = self.0.lua;
221217
let state = lua.state();
@@ -234,8 +230,6 @@ impl<'lua> Thread<'lua> {
234230
if status != ffi::LUA_OK {
235231
return Err(pop_error(thread_state, status));
236232
}
237-
#[cfg(all(feature = "luajit", feature = "vendored"))]
238-
ffi::lua_resetthread(state, thread_state);
239233
#[cfg(feature = "luau")]
240234
ffi::lua_resetthread(thread_state);
241235

@@ -375,11 +369,7 @@ impl<'lua, R> AsyncThread<'lua, R> {
375369
}
376370

377371
#[cfg(feature = "async")]
378-
#[cfg(any(
379-
feature = "lua54",
380-
all(feature = "luajit", feature = "vendored"),
381-
feature = "luau",
382-
))]
372+
#[cfg(any(feature = "lua54", feature = "luau"))]
383373
impl<'lua, R> Drop for AsyncThread<'lua, R> {
384374
fn drop(&mut self) {
385375
if self.recycle {

β€Žtests/thread.rsβ€Ž

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ fn test_thread() -> Result<()> {
9494
}
9595

9696
#[test]
97-
#[cfg(any(
98-
feature = "lua54",
99-
all(feature = "luajit", feature = "vendored"),
100-
feature = "luau",
101-
))]
97+
#[cfg(any(feature = "lua54", feature = "luau"))]
10298
fn test_thread_reset() -> Result<()> {
10399
use mlua::{AnyUserData, UserData};
104100
use std::sync::Arc;

0 commit comments

Comments
 (0)