From f71db80a740bdc1ecb0f178dea4a74a8bb772fd9 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 27 Aug 2021 14:43:25 +0100 Subject: [PATCH] Change definition of `lua_State` to opaque struct --- src/ffi/lua.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index 9244559..a48be1a 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -23,6 +23,7 @@ //! Contains definitions from `lua.h`. +use std::marker::{PhantomData, PhantomPinned}; #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))] use std::os::raw::c_uchar; use std::os::raw::{c_char, c_int, c_void}; @@ -81,7 +82,11 @@ pub const LUA_ERRERR: c_int = 5; pub const LUA_ERRERR: c_int = 6; /// A raw Lua state associated with a thread. -pub type lua_State = c_void; +#[repr(C)] +pub struct lua_State { + _data: [u8; 0], + _marker: PhantomData<(*mut u8, PhantomPinned)>, +} // basic types pub const LUA_TNONE: c_int = -1; @@ -621,7 +626,7 @@ extern "C" { #[cfg(any(feature = "lua54", feature = "lua53"))] #[inline(always)] pub unsafe fn lua_getextraspace(L: *mut lua_State) -> *mut c_void { - L.offset(-super::glue::LUA_EXTRASPACE as isize) as *mut c_void + (L as *mut c_char).offset(-super::glue::LUA_EXTRASPACE as isize) as *mut c_void } #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]