Skip to content

Commit 4afc9cf

Browse files
committed
Pin luaL_Buffer
Add `PhantomData<PhantomPinned>` to ensure that `luaL_Buffer` does not implement `Unpin`. Fixes #741
1 parent a186d46 commit 4afc9cf

7 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎mlua-sys/src/lua51/lauxlib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Contains definitions from `lauxlib.h`.
22
3+
use std::marker::{PhantomData, PhantomPinned};
34
use std::os::raw::{c_char, c_int, c_void};
45
use std::ptr;
56

@@ -169,6 +170,7 @@ pub struct luaL_Buffer {
169170
pub lvl: c_int, // number of strings in the stack
170171
pub L: *mut lua_State,
171172
pub buffer: [c_char; LUAL_BUFFERSIZE],
173+
_marker: PhantomData<PhantomPinned>,
172174
}
173175

174176
#[cfg_attr(all(windows, raw_dylib), link(name = "lua51", kind = "raw-dylib"))]

‎mlua-sys/src/lua52/lauxlib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Contains definitions from `lauxlib.h`.
22
3+
use std::marker::{PhantomData, PhantomPinned};
34
use std::os::raw::{c_char, c_int, c_void};
45
use std::ptr;
56

@@ -205,6 +206,7 @@ pub struct luaL_Buffer {
205206
pub n: usize, // number of characters in buffer
206207
pub L: *mut lua_State,
207208
pub initb: [c_char; LUAL_BUFFERSIZE], // initial buffer space
209+
_marker: PhantomData<PhantomPinned>,
208210
}
209211

210212
#[cfg_attr(all(windows, raw_dylib), link(name = "lua52", kind = "raw-dylib"))]

‎mlua-sys/src/lua53/lauxlib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Contains definitions from `lauxlib.h`.
22
3+
use std::marker::{PhantomData, PhantomPinned};
34
use std::os::raw::{c_char, c_int, c_void};
45
use std::{mem, ptr};
56

@@ -201,6 +202,7 @@ pub struct luaL_Buffer {
201202
pub n: usize, // number of characters in buffer
202203
pub L: *mut lua_State,
203204
pub initb: [c_char; LUAL_BUFFERSIZE], // initial buffer space
205+
_marker: PhantomData<PhantomPinned>,
204206
}
205207

206208
#[cfg_attr(all(windows, raw_dylib), link(name = "lua53", kind = "raw-dylib"))]

‎mlua-sys/src/lua54/lauxlib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Contains definitions from `lauxlib.h`.
22
3+
use std::marker::{PhantomData, PhantomPinned};
34
use std::os::raw::{c_char, c_double, c_int, c_long, c_void};
45
use std::{mem, ptr};
56

@@ -230,6 +231,7 @@ pub struct luaL_Buffer {
230231
pub n: usize, // number of characters in buffer
231232
pub L: *mut lua_State,
232233
pub init: luaL_BufferInit, // initial buffer (union with alignment)
234+
_marker: PhantomData<PhantomPinned>,
233235
}
234236

235237
#[cfg_attr(all(windows, raw_dylib), link(name = "lua54", kind = "raw-dylib"))]

‎mlua-sys/src/lua55/lauxlib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Contains definitions from `lauxlib.h`.
22
3+
use std::marker::{PhantomData, PhantomPinned};
34
use std::os::raw::{c_char, c_double, c_int, c_long, c_uint, c_void};
45
use std::{mem, ptr};
56

@@ -249,6 +250,7 @@ pub struct luaL_Buffer {
249250
pub n: usize, // number of characters in buffer
250251
pub L: *mut lua_State,
251252
pub init: luaL_BufferInit, // initial buffer (union with alignment)
253+
_marker: PhantomData<PhantomPinned>,
252254
}
253255

254256
#[cfg_attr(all(windows, raw_dylib), link(name = "lua55", kind = "raw-dylib"))]

‎mlua-sys/src/luau/lauxlib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Contains definitions from `lualib.h`.
22
3+
use std::marker::{PhantomData, PhantomPinned};
34
use std::os::raw::{c_char, c_float, c_int, c_void};
45
use std::ptr;
56

@@ -206,6 +207,7 @@ pub struct luaL_Strbuf {
206207
L: *mut lua_State,
207208
storage: *mut c_void, // TString
208209
buffer: [c_char; LUA_BUFFERSIZE],
210+
_marker: PhantomData<PhantomPinned>,
209211
}
210212

211213
// For compatibility

‎tests/ffi.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
fn test_buffer_not_unpin() {
3+
static_assertions::assert_not_impl_any!(mlua::ffi::luaL_Buffer: Unpin);
4+
}

0 commit comments

Comments
 (0)