Skip to content

Commit d7d87bd

Browse files
authored
Merge branch 'mlua-rs:main' into main
2 parents 09dfc9b + cd4091f commit d7d87bd

File tree

19 files changed

+160
-62
lines changed

19 files changed

+160
-62
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## v0.10.2 (Dec 1st, 2024)
2+
3+
- Switch proc-macro-error to proc-macro-error2 (#493)
4+
- Do not allow Lua to run GC finalizers on ref thread (#491)
5+
- Fix chunks loading in Luau when memory limit is enforced (#488)
6+
- Added `String::wrap` method to wrap arbitrary `AsRef<[u8]>` into `impl IntoLua`
7+
- Better FreeBSD/OpenBSD support (thanks to cos)
8+
- Delay "any" userdata metatable creation until first instance is created (#482)
9+
- Reduce amount of generated code for `UserData` (less generics)
10+
111
## v0.10.1 (Nov 9th, 2024)
212

313
- Minimal Luau updated to 0.650

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mlua"
3-
version = "0.10.1" # remember to update mlua_derive
3+
version = "0.10.2" # remember to update mlua_derive
44
authors = ["Aleksandr Orlenko <[email protected]>", "kyren <[email protected]>"]
55
rust-version = "1.79.0"
66
edition = "2021"
@@ -46,7 +46,7 @@ anyhow = ["dep:anyhow", "error-send"]
4646
userdata-wrappers = []
4747

4848
[dependencies]
49-
mlua_derive = { version = "=0.10.0", optional = true, path = "mlua_derive" }
49+
mlua_derive = { version = "=0.10.1", optional = true, path = "mlua_derive" }
5050
bstr = { version = "1.0", features = ["std"], default-features = false }
5151
either = "1.0"
5252
num-traits = { version = "0.2.14" }
@@ -58,7 +58,7 @@ serde-value = { version = "0.7", optional = true }
5858
parking_lot = { version = "0.12", features = ["arc_lock"] }
5959
anyhow = { version = "1.0", optional = true }
6060

61-
ffi = { package = "mlua-sys", version = "0.6.5", path = "mlua-sys" }
61+
ffi = { package = "mlua-sys", version = "0.6.6", path = "mlua-sys" }
6262

6363
[target.'cfg(unix)'.dependencies]
6464
libloading = { version = "0.8", optional = true }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Add to `Cargo.toml` :
133133

134134
``` toml
135135
[dependencies]
136-
mlua = { version = "0.10.1", features = ["lua54", "vendored"] }
136+
mlua = { version = "0.10.2", features = ["lua54", "vendored"] }
137137
```
138138

139139
`main.rs`
@@ -168,7 +168,7 @@ Add to `Cargo.toml` :
168168
crate-type = ["cdylib"]
169169

170170
[dependencies]
171-
mlua = { version = "0.10.1", features = ["lua54", "module"] }
171+
mlua = { version = "0.10.2", features = ["lua54", "module"] }
172172
```
173173

174174
`lib.rs` :

mlua-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mlua-sys"
3-
version = "0.6.5"
3+
version = "0.6.6"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
rust-version = "1.71"
66
edition = "2021"

mlua-sys/src/luau/compat.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,16 @@ pub unsafe fn luaL_loadbufferenv(
326326
mut size: usize,
327327
name: *const c_char,
328328
mode: *const c_char,
329-
env: c_int,
329+
mut env: c_int,
330330
) -> c_int {
331331
extern "C" {
332332
fn free(p: *mut c_void);
333333
}
334334

335+
unsafe extern "C-unwind" fn data_dtor(data: *mut c_void) {
336+
free(*(data as *mut *mut c_char) as *mut c_void);
337+
}
338+
335339
let chunk_is_text = size == 0 || (*data as u8) >= b'\t';
336340
if !mode.is_null() {
337341
let modeb = CStr::from_ptr(mode).to_bytes();
@@ -345,9 +349,16 @@ pub unsafe fn luaL_loadbufferenv(
345349
}
346350

347351
if chunk_is_text {
352+
if env < 0 {
353+
env -= 1;
354+
}
355+
let data_ud = lua_newuserdatadtor(L, mem::size_of::<*mut c_char>(), data_dtor) as *mut *mut c_char;
348356
let data = luau_compile_(data, size, ptr::null_mut(), &mut size);
357+
ptr::write(data_ud, data);
358+
// By deferring the `free(data)` to the userdata destructor, we ensure that
359+
// even if `luau_load` throws an error, the `data` is still released.
349360
let ok = luau_load(L, name, data, size, env) == 0;
350-
free(data as *mut c_void);
361+
lua_replace(L, -2); // replace data with the result
351362
if !ok {
352363
return LUA_ERRSYNTAX;
353364
}

mlua_derive/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mlua_derive"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
description = "Procedural macros for the mlua crate."
@@ -12,12 +12,12 @@ license = "MIT"
1212
proc-macro = true
1313

1414
[features]
15-
macros = ["proc-macro-error", "itertools", "regex", "once_cell"]
15+
macros = ["proc-macro-error2", "itertools", "regex", "once_cell"]
1616

1717
[dependencies]
1818
quote = "1.0"
1919
proc-macro2 = { version = "1.0", features = ["span-locations"] }
20-
proc-macro-error = { version = "1.0", optional = true }
20+
proc-macro-error2 = { version = "2.0.1", optional = true }
2121
syn = { version = "2.0", features = ["full"] }
2222
itertools = { version = "0.13", optional = true }
2323
regex = { version = "1.4", optional = true }

mlua_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syn::{parse_macro_input, ItemFn, LitStr, Result};
77
#[cfg(feature = "macros")]
88
use {
99
crate::chunk::Chunk, proc_macro::TokenTree, proc_macro2::TokenStream as TokenStream2,
10-
proc_macro_error::proc_macro_error,
10+
proc_macro_error2::proc_macro_error,
1111
};
1212

1313
#[derive(Default)]

mlua_derive/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn parse_pos(span: &Span) -> Option<(usize, usize)> {
7474
fn fallback_span_pos(span: &Span) -> (Pos, Pos) {
7575
let (start, end) = match parse_pos(span) {
7676
Some(v) => v,
77-
None => proc_macro_error::abort_call_site!("Cannot retrieve span information; please use nightly"),
77+
None => proc_macro_error2::abort_call_site!("Cannot retrieve span information; please use nightly"),
7878
};
7979
(Pos::new(1, start), Pos::new(1, end))
8080
}

src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,8 @@ impl Lua {
10431043
let state = lua.state();
10441044
unsafe {
10451045
if lua.unlikely_memory_error() {
1046-
crate::util::push_buffer(lua.ref_thread(), buf.as_ref(), false)?;
1047-
return Ok(Buffer(lua.pop_ref_thread()));
1046+
crate::util::push_buffer(state, buf.as_ref(), false)?;
1047+
return Ok(Buffer(lua.pop_ref()));
10481048
}
10491049

10501050
let _sg = StackGuard::new(state);

src/state/extra.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use super::{Lua, WeakLua};
2727
// Unique key to store `ExtraData` in the registry
2828
static EXTRA_REGISTRY_KEY: u8 = 0;
2929

30-
const WRAPPED_FAILURE_POOL_SIZE: usize = 64;
30+
const WRAPPED_FAILURE_POOL_DEFAULT_CAPACITY: usize = 64;
3131
const REF_STACK_RESERVE: c_int = 1;
3232

3333
/// Data associated with the Lua state.
@@ -60,6 +60,7 @@ pub(crate) struct ExtraData {
6060

6161
// Pool of `WrappedFailure` enums in the ref thread (as userdata)
6262
pub(super) wrapped_failure_pool: Vec<c_int>,
63+
pub(super) wrapped_failure_top: usize,
6364
// Pool of `Thread`s (coroutines) for async execution
6465
#[cfg(feature = "async")]
6566
pub(super) thread_pool: Vec<c_int>,
@@ -160,7 +161,8 @@ impl ExtraData {
160161
ref_stack_size: ffi::LUA_MINSTACK - REF_STACK_RESERVE,
161162
ref_stack_top: ffi::lua_gettop(ref_thread),
162163
ref_free: Vec::new(),
163-
wrapped_failure_pool: Vec::with_capacity(WRAPPED_FAILURE_POOL_SIZE),
164+
wrapped_failure_pool: Vec::with_capacity(WRAPPED_FAILURE_POOL_DEFAULT_CAPACITY),
165+
wrapped_failure_top: 0,
164166
#[cfg(feature = "async")]
165167
thread_pool: Vec::new(),
166168
wrapped_failure_mt_ptr,

0 commit comments

Comments
 (0)