From 2fd6757f39e218be142b951afa6d5bb290989826 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 16 May 2020 15:13:38 +0100 Subject: [PATCH] Add LuaJIT 2.0.5 stable support --- .github/workflows/main.yml | 22 ++++++++++++++++++++++ build/find_normal.rs | 2 +- src/lua.rs | 16 +++++++++++++--- tests/async.rs | 11 +++++++++++ tests/byte_string.rs | 12 ++++++++++++ tests/function.rs | 12 ++++++++++++ tests/memory.rs | 12 ++++++++++++ tests/scope.rs | 12 ++++++++++++ tests/string.rs | 12 ++++++++++++ tests/table.rs | 12 ++++++++++++ tests/tests.rs | 12 ++++++++++++ tests/thread.rs | 12 ++++++++++++ tests/types.rs | 12 ++++++++++++ tests/userdata.rs | 12 ++++++++++++ tests/value.rs | 12 ++++++++++++ 15 files changed, 179 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0a99fb5..3c9cc4b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,6 +60,7 @@ jobs: target: ${{ matrix.target }} override: true - name: Run ${{ matrix.lua }} tests + if: ${{ matrix.os != 'macos-latest' || matrix.lua != 'luajit' }} run: | cargo test --release --no-default-features --features "${{ matrix.lua }} vendored" cargo test --release --no-default-features --features "${{ matrix.lua }} vendored async send" @@ -71,6 +72,27 @@ jobs: cargo test --release --no-default-features --features "${{ matrix.lua }} vendored async send" -- --ignored shell: bash + test_luajit20: + name: Test LuaJIT on macOS + runs-on: macos-latest + needs: build + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + target: x86_64-apple-darwin + override: true + - name: Run LuaJIT 2.0.5 tests + run: | + brew install luajit pkg-config + cargo test --tests --release --no-default-features --features "luajit async send" + shell: bash + - name: Run LuaJIT vendored tests + run: | + cargo test --release --no-default-features --features "luajit vendored async send" + shell: bash + rustfmt: name: Rustfmt runs-on: ubuntu-18.04 diff --git a/build/find_normal.rs b/build/find_normal.rs index 4165e41..31be3e1 100644 --- a/build/find_normal.rs +++ b/build/find_normal.rs @@ -76,7 +76,7 @@ pub fn probe_lua() -> PathBuf { #[cfg(feature = "luajit")] { let lua = pkg_config::Config::new() - .range_version((Bound::Included("2.1.0"), Bound::Unbounded)) + .range_version((Bound::Included("2.0.5"), Bound::Unbounded)) .probe("luajit"); lua.unwrap().include_paths[0].clone() diff --git a/src/lua.rs b/src/lua.rs index a0d96a1..e635f40 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1,4 +1,3 @@ -use std::alloc; use std::any::TypeId; use std::cell::{RefCell, UnsafeCell}; use std::collections::HashMap; @@ -61,6 +60,7 @@ struct ExtraData { ref_free: Vec, } +#[cfg_attr(any(feature = "lua51", feature = "luajit"), allow(dead_code))] struct MemoryInfo { used_memory: isize, memory_limit: isize, @@ -173,12 +173,15 @@ impl Lua { /// /// [`StdLib`]: struct.StdLib.html pub unsafe fn unsafe_new_with(libs: StdLib) -> Lua { + #[cfg_attr(any(feature = "lua51", feature = "luajit"), allow(dead_code))] unsafe extern "C" fn allocator( extra_data: *mut c_void, ptr: *mut c_void, osize: usize, nsize: usize, ) -> *mut c_void { + use std::alloc; + let mem_info = &mut *(extra_data as *mut MemoryInfo); if nsize == 0 { @@ -227,19 +230,26 @@ impl Lua { new_ptr } + #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] let mem_info = Box::into_raw(Box::new(MemoryInfo { used_memory: 0, memory_limit: 0, })); + #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] let state = ffi::lua_newstate(allocator, mem_info as *mut c_void); + #[cfg(any(feature = "lua51", feature = "luajit"))] + let state = ffi::luaL_newstate(); ffi::luaL_requiref(state, cstr!("_G"), ffi::luaopen_base, 1); ffi::lua_pop(state, 1); let mut lua = Lua::init_from_ptr(state); lua.ephemeral = false; - lua.extra.lock().unwrap().mem_info = mem_info; + #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] + { + lua.extra.lock().unwrap().mem_info = mem_info; + } mlua_expect!( protect_lua_closure(lua.main_state, 0, 0, |state| { @@ -1536,7 +1546,7 @@ impl Lua { // Try to get an outer poll waker ffi::lua_pushlightuserdata( state, - &WAKER_REGISTRY_KEY as *const u8 as *mut ::std::os::raw::c_void, + &WAKER_REGISTRY_KEY as *const u8 as *mut c_void, ); ffi::lua_rawget(state, ffi::LUA_REGISTRYINDEX); if let Some(w) = get_gc_userdata::(state, -1).as_ref() { diff --git a/tests/async.rs b/tests/async.rs index 8f360ab..caadb00 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -1,4 +1,15 @@ #![cfg(feature = "async")] +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} use std::cell::Cell; use std::rc::Rc; diff --git a/tests/byte_string.rs b/tests/byte_string.rs index 3b05ee5..22752c8 100644 --- a/tests/byte_string.rs +++ b/tests/byte_string.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use bstr::{BStr, BString}; use mlua::{Lua, Result}; diff --git a/tests/function.rs b/tests/function.rs index cc1c9ab..f884d88 100644 --- a/tests/function.rs +++ b/tests/function.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use mlua::{Function, Lua, Result, String}; #[test] diff --git a/tests/memory.rs b/tests/memory.rs index aa0a809..b51ca3d 100644 --- a/tests/memory.rs +++ b/tests/memory.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::sync::Arc; use mlua::{Lua, Result, UserData}; diff --git a/tests/scope.rs b/tests/scope.rs index d622dfa..f7dc32d 100644 --- a/tests/scope.rs +++ b/tests/scope.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::cell::Cell; use std::rc::Rc; diff --git a/tests/string.rs b/tests/string.rs index abe8aaa..f7e551e 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::borrow::Cow; use mlua::{Lua, Result, String}; diff --git a/tests/table.rs b/tests/table.rs index 6378e5c..2417619 100644 --- a/tests/table.rs +++ b/tests/table.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use mlua::{Lua, Nil, Result, Table, TableExt, Value}; #[test] diff --git a/tests/tests.rs b/tests/tests.rs index bb202e3..b62a68d 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::iter::FromIterator; use std::panic::catch_unwind; use std::sync::Arc; diff --git a/tests/thread.rs b/tests/thread.rs index fd2f20c..1094052 100644 --- a/tests/thread.rs +++ b/tests/thread.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::panic::catch_unwind; use mlua::{Error, Function, Lua, Result, Thread, ThreadStatus}; diff --git a/tests/types.rs b/tests/types.rs index 72f9484..bbec13d 100644 --- a/tests/types.rs +++ b/tests/types.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::os::raw::c_void; use mlua::{Function, LightUserData, Lua, Result}; diff --git a/tests/userdata.rs b/tests/userdata.rs index 8afc795..8ed7232 100644 --- a/tests/userdata.rs +++ b/tests/userdata.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use std::sync::Arc; #[cfg(feature = "lua54")] diff --git a/tests/value.rs b/tests/value.rs index 9beb68c..7b59a51 100644 --- a/tests/value.rs +++ b/tests/value.rs @@ -1,3 +1,15 @@ +#![cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + feature(link_args) +)] + +#[cfg_attr( + all(feature = "luajit", target_os = "macos", target_arch = "x86_64"), + link_args = "-pagezero_size 10000 -image_base 100000000", + allow(unused_attributes) +)] +extern "system" {} + use mlua::{Lua, Result, Value}; #[test]