diff options
author | kyren <kerriganw@gmail.com> | 2018-02-16 22:00:58 -0500 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2018-02-16 22:01:41 -0500 |
commit | dec360f78f156e54a4b4a348e781aedac310b299 (patch) | |
tree | 6251544fa6fc0664a968daa67acc1d064b71544d | |
parent | 73de52dcce3e222367312ec79743e0b50a134a6c (diff) | |
download | mlua-dec360f78f156e54a4b4a348e781aedac310b299.zip |
Can.. can I do this? Is this a thing that actually works?
Drastic times and all that.
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | build.rs | 23 | ||||
-rw-r--r-- | src/function.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/lua.rs | 4 | ||||
-rw-r--r-- | src/util.rs | 16 |
6 files changed, 30 insertions, 23 deletions
@@ -22,12 +22,6 @@ default = ["builtin-lua"] # * LUA_NUMBER as double # * LUA_EXTRASPACE is sizeof(void*) builtin-lua = ["gcc"] -# Error handling is completely broken on windows with -# https://github.com/rust-lang/rust/pull/46833 merged, and this includes stable -# rustc 1.24.0+. This feature fixes error handling on windows, but requires -# nightly! See https://github.com/rust-lang/rust/issues/48251 and -# https://github.com/chucklefish/rlua/issues/71 for details. -unwind = [] [dependencies] libc = { version = "0.2" } @@ -1,16 +1,29 @@ #[cfg(feature = "builtin-lua")] extern crate gcc; +use std::env; + fn main() { + let target_os = env::var("CARGO_CFG_TARGET_OS"); + let target_family = env::var("CARGO_CFG_TARGET_FAMILY"); + + if target_family == Ok("windows".to_string()) { + // Error handling is completely broken on windows with + // https://github.com/rust-lang/rust/pull/46833 merged, and this includes stable rustc + // 1.24.0+. `#[unwind]` fixes error handling on windows, but requires nightly! This + // HORRIBLE HACK enables `#[unwind]` on stable rust by setting RUSTC_BOOTSTRAP=1 during + // build. This is very evil, don't do this kids. + // + // See https://github.com/rust-lang/rust/issues/48251 and + // https://github.com/chucklefish/rlua/issues/71 for more details. + println!("cargo:rustc-env=RUSTC_BOOTSTRAP=1"); + println!("cargo:rustc-cfg=unwind"); + } + #[cfg(feature = "builtin-lua")] { - use std::env; - let mut config = gcc::Build::new(); - let target_os = env::var("CARGO_CFG_TARGET_OS"); - let target_family = env::var("CARGO_CFG_TARGET_FAMILY"); - if target_os == Ok("linux".to_string()) { config.define("LUA_USE_LINUX", None); } else if target_os == Ok("macos".to_string()) { diff --git a/src/function.rs b/src/function.rs index 485a415..be4f396 100644 --- a/src/function.rs +++ b/src/function.rs @@ -122,7 +122,7 @@ impl<'lua> Function<'lua> { /// # } /// ``` pub fn bind<A: ToLuaMulti<'lua>>(&self, args: A) -> Result<Function<'lua>> { - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn bind_call_impl(state: *mut ffi::lua_State) -> c_int { let nargs = ffi::lua_gettop(state); let nbinds = ffi::lua_tointeger(state, ffi::lua_upvalueindex(2)) as c_int; @@ -1,4 +1,4 @@ -#![cfg_attr(feature = "unwind", feature(unwind_attributes))] +#![cfg_attr(unwind, feature(unwind_attributes))] //! # High-level bindings to Lua //! @@ -759,7 +759,7 @@ impl Lua { pub(crate) unsafe fn userdata_metatable<T: UserData>(&self) -> Result<c_int> { // Used if both an __index metamethod is set and regular methods, checks methods table // first, then __index metamethod. - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn meta_index_impl(state: *mut ffi::lua_State) -> c_int { ffi::luaL_checkstack(state, 2, ptr::null()); @@ -995,7 +995,7 @@ impl Lua { &'lua self, func: Callback<'callback, 'static>, ) -> Result<Function<'lua>> { - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn callback_call_impl(state: *mut ffi::lua_State) -> c_int { callback_error(state, || { let lua = Lua { diff --git a/src/util.rs b/src/util.rs index af6a50d..99377fb 100644 --- a/src/util.rs +++ b/src/util.rs @@ -121,7 +121,7 @@ where nresults: c_int, } - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn do_call<F, R>(state: *mut ffi::lua_State) -> c_int where F: FnOnce(*mut ffi::lua_State) -> R, @@ -272,7 +272,7 @@ pub unsafe fn take_userdata<T>(state: *mut ffi::lua_State) -> T { ptr::read(ud) } -#[cfg_attr(feature = "unwind", unwind)] +#[cfg_attr(unwind, unwind)] pub unsafe extern "C" fn userdata_destructor<T>(state: *mut ffi::lua_State) -> c_int { callback_error(state, || { take_userdata::<T>(state); @@ -306,7 +306,7 @@ where // Takes an error at the top of the stack, and if it is a WrappedError, converts it to an // Error::CallbackError with a traceback, if it is some lua type, prints the error along with a // traceback, and if it is a WrappedPanic, does not modify it. -#[cfg_attr(feature = "unwind", unwind)] +#[cfg_attr(unwind, unwind)] pub unsafe extern "C" fn error_traceback(state: *mut ffi::lua_State) -> c_int { ffi::luaL_checkstack(state, 2, ptr::null()); @@ -337,7 +337,7 @@ pub unsafe extern "C" fn error_traceback(state: *mut ffi::lua_State) -> c_int { } // A variant of pcall that does not allow lua to catch panic errors from callback_error -#[cfg_attr(feature = "unwind", unwind)] +#[cfg_attr(unwind, unwind)] pub unsafe extern "C" fn safe_pcall(state: *mut ffi::lua_State) -> c_int { ffi::luaL_checkstack(state, 2, ptr::null()); @@ -360,9 +360,9 @@ pub unsafe extern "C" fn safe_pcall(state: *mut ffi::lua_State) -> c_int { } // A variant of xpcall that does not allow lua to catch panic errors from callback_error -#[cfg_attr(feature = "unwind", unwind)] +#[cfg_attr(unwind, unwind)] pub unsafe extern "C" fn safe_xpcall(state: *mut ffi::lua_State) -> c_int { - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn xpcall_msgh(state: *mut ffi::lua_State) -> c_int { ffi::luaL_checkstack(state, 2, ptr::null()); @@ -510,7 +510,7 @@ unsafe fn is_wrapped_panic(state: *mut ffi::lua_State, index: c_int) -> bool { unsafe fn get_error_metatable(state: *mut ffi::lua_State) -> c_int { static ERROR_METATABLE_REGISTRY_KEY: u8 = 0; - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn error_tostring(state: *mut ffi::lua_State) -> c_int { ffi::luaL_checkstack(state, 2, ptr::null()); @@ -612,7 +612,7 @@ unsafe fn get_panic_metatable(state: *mut ffi::lua_State) -> c_int { unsafe fn get_destructed_userdata_metatable(state: *mut ffi::lua_State) -> c_int { static DESTRUCTED_USERDATA_METATABLE: u8 = 0; - #[cfg_attr(feature = "unwind", unwind)] + #[cfg_attr(unwind, unwind)] unsafe extern "C" fn destructed_error(state: *mut ffi::lua_State) -> c_int { ffi::luaL_checkstack(state, 2, ptr::null()); push_wrapped_error(state, Error::CallbackDestructed); |