diff --git a/src/state.rs b/src/state.rs index 57bff326..ae05c72e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,7 +2,7 @@ use std::any::TypeId; use std::cell::RefCell; use std::marker::PhantomData; use std::ops::Deref; -use std::os::raw::{c_int, c_void}; +use std::os::raw::c_int; use std::panic::Location; use std::result::Result as StdResult; use std::{fmt, mem, ptr}; @@ -18,8 +18,8 @@ use crate::string::String; use crate::table::Table; use crate::thread::Thread; use crate::types::{ - AppDataRef, AppDataRefMut, ArcReentrantMutexGuard, Integer, LightUserData, MaybeSend, Number, - ReentrantMutex, ReentrantMutexGuard, RegistryKey, XRc, XWeak, + AppDataRef, AppDataRefMut, ArcReentrantMutexGuard, Integer, MaybeSend, Number, ReentrantMutex, + ReentrantMutexGuard, RegistryKey, XRc, XWeak, }; use crate::userdata::{AnyUserData, UserData, UserDataProxy, UserDataRegistry, UserDataStorage}; use crate::util::{ @@ -34,7 +34,10 @@ use crate::hook::HookTriggers; use crate::{chunk::Compiler, types::VmState}; #[cfg(feature = "async")] -use std::future::{self, Future}; +use { + crate::types::LightUserData, + std::future::{self, Future}, +}; #[cfg(feature = "serialize")] use serde::Serialize; @@ -284,6 +287,7 @@ impl Lua { /// /// This method ensures that the Lua instance is locked while the function is called /// and restores Lua stack after the function returns. + #[allow(clippy::missing_safety_doc)] pub unsafe fn with_raw_state( &self, args: impl IntoLuaMulti, @@ -648,7 +652,7 @@ impl Lua { F: Fn(&Lua, &str, bool) -> Result<()> + MaybeSend + 'static, { use std::ffi::CStr; - use std::os::raw::c_char; + use std::os::raw::{c_char, c_void}; use std::string::String as StdString; unsafe extern "C-unwind" fn warn_proc(ud: *mut c_void, msg: *const c_char, tocont: c_int) { @@ -1825,7 +1829,7 @@ impl Lua { #[inline(always)] pub fn poll_pending() -> LightUserData { static ASYNC_POLL_PENDING: u8 = 0; - LightUserData(&ASYNC_POLL_PENDING as *const u8 as *mut c_void) + LightUserData(&ASYNC_POLL_PENDING as *const u8 as *mut std::os::raw::c_void) } // Luau version located in `luau/mod.rs` @@ -1874,6 +1878,7 @@ impl Lua { /// Returns a handle to the unprotected Lua state without any synchronization. /// /// This is useful where we know that the lock is already held by the caller. + #[cfg(feature = "async")] #[inline(always)] pub(crate) unsafe fn raw_lua(&self) -> &RawLua { &*self.raw.data_ptr() diff --git a/src/state/raw.rs b/src/state/raw.rs index 3dcca2bf..4fbae99d 100644 --- a/src/state/raw.rs +++ b/src/state/raw.rs @@ -27,7 +27,7 @@ use crate::util::{ push_internal_userdata, push_string, push_table, rawset_field, safe_pcall, safe_xpcall, short_type_name, StackGuard, WrappedFailure, }; -use crate::value::{FromLuaMulti, IntoLua, MultiValue, Nil, Value}; +use crate::value::{IntoLua, Nil, Value}; use super::extra::ExtraData; use super::{Lua, LuaOptions, WeakLua}; @@ -38,6 +38,7 @@ use crate::hook::{Debug, HookTriggers}; #[cfg(feature = "async")] use { crate::types::{AsyncCallback, AsyncCallbackUpvalue, AsyncPollUpvalue}, + crate::value::{FromLuaMulti, MultiValue}, std::ptr::NonNull, std::task::{Context, Poll, Waker}, }; diff --git a/src/string.rs b/src/string.rs index a4707d37..39c1ddc7 100644 --- a/src/string.rs +++ b/src/string.rs @@ -105,22 +105,22 @@ impl String { unsafe fn to_slice(&self) -> (&[u8], Lua) { let lua = self.0.lua.upgrade(); - let rawlua = lua.lock(); - let ref_thread = rawlua.ref_thread(); - unsafe { + let slice = unsafe { + let rawlua = lua.lock(); + let ref_thread = rawlua.ref_thread(); + mlua_debug_assert!( ffi::lua_type(ref_thread, self.0.index) == ffi::LUA_TSTRING, "string ref is not string type" ); - let mut size = 0; // This will not trigger a 'm' error, because the reference is guaranteed to be of // string type + let mut size = 0; let data = ffi::lua_tolstring(ref_thread, self.0.index, &mut size); - - drop(rawlua); - (slice::from_raw_parts(data as *const u8, size + 1), lua) - } + slice::from_raw_parts(data as *const u8, size + 1) + }; + (slice, lua) } /// Converts this string to a generic C pointer. diff --git a/src/thread.rs b/src/thread.rs index c3b1f44f..c1c0a042 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -143,7 +143,7 @@ impl Thread { let state = lua.state(); let thread_state = self.state(); - let nargs = args.push_into_stack_multi(&lua)?; + let nargs = args.push_into_stack_multi(lua)?; if nargs > 0 { check_stack(thread_state, nargs)?; ffi::lua_xmove(state, thread_state, nargs); diff --git a/src/userdata/cell.rs b/src/userdata/cell.rs index b62c3ecb..e37590b0 100644 --- a/src/userdata/cell.rs +++ b/src/userdata/cell.rs @@ -9,7 +9,7 @@ use serde::ser::{Serialize, Serializer}; use crate::error::{Error, Result}; use crate::state::{Lua, RawLua}; -use crate::types::{MaybeSend, XRc}; +use crate::types::XRc; use crate::userdata::AnyUserData; use crate::util::get_userdata; use crate::value::{FromLua, Value}; @@ -391,7 +391,7 @@ impl UserDataStorage { #[inline(always)] pub(crate) fn new_ser(data: T) -> Self where - T: Serialize + MaybeSend, + T: Serialize + crate::types::MaybeSend, { let data = Box::new(data) as Box; Self::Owned(UserDataVariant::Serializable(XRc::new(UserDataCell::new(data)))) diff --git a/src/userdata/registry.rs b/src/userdata/registry.rs index ad4e3178..260a497e 100644 --- a/src/userdata/registry.rs +++ b/src/userdata/registry.rs @@ -9,16 +9,14 @@ use std::string::String as StdString; use crate::error::{Error, Result}; use crate::state::{Lua, RawLua}; use crate::types::{Callback, MaybeSend}; -use crate::userdata::{ - AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataRef, UserDataRefMut, - UserDataStorage, -}; +use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataStorage}; use crate::util::{get_userdata, short_type_name}; use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value}; #[cfg(feature = "async")] use { crate::types::AsyncCallback, + crate::userdata::{UserDataRef, UserDataRefMut}, std::future::{self, Future}, }; diff --git a/src/value.rs b/src/value.rs index d7de0029..276904a0 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,4 +1,3 @@ -use std::cell::RefCell; use std::cmp::Ordering; use std::collections::{vec_deque, HashSet, VecDeque}; use std::ops::{Deref, DerefMut}; @@ -24,12 +23,14 @@ use { crate::table::SerializableTable, rustc_hash::FxHashSet, serde::ser::{self, Serialize, Serializer}, - std::{rc::Rc, result::Result as StdResult}, + std::{cell::RefCell, rc::Rc, result::Result as StdResult}, }; -/// A dynamically typed Lua value. The `String`, `Table`, `Function`, `Thread`, and `UserData` -/// variants contain handle types into the internal Lua state. It is a logic error to mix handle -/// types between separate `Lua` instances, and doing so will result in a panic. +/// A dynamically typed Lua value. +/// +/// The `String`, `Table`, `Function`, `Thread`, and `UserData` variants contain handle types +/// into the internal Lua state. It is a logic error to mix handle types between separate +/// `Lua` instances, and doing so will result in a panic. #[derive(Clone)] pub enum Value { /// The Lua value `nil`.