Compare commits

...

5 Commits

Author SHA1 Message Date
Alex Orlenko e86ef9d755 v0.8.7 2023-01-04 16:15:23 +00:00
Alex Orlenko 05eb20f9c6 Fix subtraction overflow when calculating index for MultiValue::get().
Return `None` instead of panic in debug mode.
Fixes #232
2022-12-15 21:10:31 +00:00
Alex Orlenko 9716918517 Fix lifetime of DebugNames in Debug::names() and DebugSource in Debug::source().
This can cause use-after-free if used wrong.
Now invalid code would not compile.
Reported in #230
2022-12-09 23:55:38 +00:00
Alex Orlenko c88417a3b6 Redefine _VERSION for Luau to include version number.
https://github.com/khvzak/mlua/discussions/228
2022-12-03 21:21:28 +00:00
Alex Orlenko 6e95386f30 Update Luau to 0.555 (luau-src 0.5.0)
This version includes inreased LUAI_MAXCSTACK limit (100000)
2022-12-03 17:55:26 +00:00
9 changed files with 51 additions and 12 deletions
+7
View File
@@ -1,3 +1,10 @@
## v0.8.7
- Minimum Luau updated to 0.555 (`LUAI_MAXCSTACK` limit increased to 100000)
- `_VERSION` in Luau now includes version number
- Fixed lifetime of `DebugNames` in `Debug::names()` and `DebugSource` in `Debug::source()`
- Fixed subtraction overflow when calculating index for `MultiValue::get()`
## v0.8.6
- Fixed bug when recycled Registry slot can be set to Nil
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "mlua"
version = "0.8.6" # remember to update html_root_url and mlua_derive
version = "0.8.7" # remember to update html_root_url and mlua_derive
authors = ["Aleksandr Orlenko <zxteam@pm.me>", "kyren <catherine@chucklefish.org>"]
edition = "2021"
repository = "https://github.com/khvzak/mlua"
@@ -58,7 +58,7 @@ cc = { version = "1.0" }
pkg-config = { version = "0.3.17" }
lua-src = { version = ">= 544.0.0, < 550.0.0", optional = true }
luajit-src = { version = ">= 210.4.0, < 220.0.0", optional = true }
luau0-src = { version = "0.4.0", optional = true }
luau0-src = { version = "0.5.0", optional = true }
[dev-dependencies]
rustyline = "10.0"
+6 -3
View File
@@ -7,12 +7,15 @@ use std::ptr;
// Option for multiple returns in 'lua_pcall' and 'lua_call'
pub const LUA_MULTRET: c_int = -1;
// Max number of Lua stack slots
const LUAI_MAXCSTACK: c_int = 100000;
//
// Pseudo-indices
//
pub const LUA_REGISTRYINDEX: c_int = -10000;
pub const LUA_ENVIRONINDEX: c_int = -10001;
pub const LUA_GLOBALSINDEX: c_int = -10002;
pub const LUA_REGISTRYINDEX: c_int = -LUAI_MAXCSTACK - 2000;
pub const LUA_ENVIRONINDEX: c_int = -LUAI_MAXCSTACK - 2001;
pub const LUA_GLOBALSINDEX: c_int = -LUAI_MAXCSTACK - 2002;
pub const fn lua_upvalueindex(i: c_int) -> c_int {
LUA_GLOBALSINDEX - i
+2 -2
View File
@@ -63,7 +63,7 @@ impl<'lua> Debug<'lua> {
}
/// Corresponds to the `n` what mask.
pub fn names(&self) -> DebugNames<'lua> {
pub fn names(&self) -> DebugNames {
unsafe {
#[cfg(not(feature = "luau"))]
mlua_assert!(
@@ -87,7 +87,7 @@ impl<'lua> Debug<'lua> {
}
/// Corresponds to the `S` what mask.
pub fn source(&self) -> DebugSource<'lua> {
pub fn source(&self) -> DebugSource {
unsafe {
#[cfg(not(feature = "luau"))]
mlua_assert!(
+1 -1
View File
@@ -72,7 +72,7 @@
//! [`serde::Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html
// mlua types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/mlua/0.8.6")]
#![doc(html_root_url = "https://docs.rs/mlua/0.8.7")]
// Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any*
// warnings at all.
#![doc(test(attr(deny(warnings))))]
+6
View File
@@ -22,6 +22,12 @@ impl Lua {
globals.raw_set("require", self.create_function(lua_require)?)?;
globals.raw_set("vector", self.create_c_function(lua_vector)?)?;
// Set `_VERSION` global to include version number
// The environment variable `LUAU_VERSION` set by the build script
if let Some(version) = option_env!("LUAU_VERSION") {
globals.raw_set("_VERSION", format!("Luau {version}"))?;
}
Ok(())
}
}
+4 -2
View File
@@ -197,7 +197,6 @@ pub struct MultiValue<'lua>(Vec<Value<'lua>>);
impl<'lua> MultiValue<'lua> {
/// Creates an empty `MultiValue` containing no values.
#[inline]
pub const fn new() -> MultiValue<'lua> {
MultiValue(Vec::new())
}
@@ -276,7 +275,10 @@ impl<'lua> MultiValue<'lua> {
#[inline]
pub fn get(&self, index: usize) -> Option<&Value<'lua>> {
self.0.get(self.0.len() - index - 1)
if index < self.0.len() {
return self.0.get(self.0.len() - index - 1);
}
None
}
#[inline]
+4 -1
View File
@@ -276,7 +276,10 @@ fn test_error() -> Result<()> {
end, 3)
local function handler(err)
if string.match(_VERSION, ' 5%.1$') or string.match(_VERSION, ' 5%.2$') or _VERSION == "Luau" then
if string.match(_VERSION, " 5%.1$")
or string.match(_VERSION, " 5%.2$")
or string.match(_VERSION, "Luau")
then
-- Special case for Lua 5.1/5.2 and Luau
local caps = string.match(err, ': (%d+)$')
if caps then
+19 -1
View File
@@ -1,6 +1,6 @@
use std::ptr;
use mlua::{Lua, Result, Value};
use mlua::{Lua, MultiValue, Result, Value};
#[test]
fn test_value_eq() -> Result<()> {
@@ -63,3 +63,21 @@ fn test_value_eq() -> Result<()> {
Ok(())
}
#[test]
fn test_multi_value() {
let mut multi_value = MultiValue::new();
assert_eq!(multi_value.len(), 0);
assert_eq!(multi_value.get(0), None);
multi_value.push_front(Value::Number(2.));
multi_value.push_front(Value::Number(1.));
assert_eq!(multi_value.get(0), Some(&Value::Number(1.)));
assert_eq!(multi_value.get(1), Some(&Value::Number(2.)));
assert_eq!(multi_value.pop_front(), Some(Value::Number(1.)));
assert_eq!(multi_value[0], Value::Number(2.));
multi_value.clear();
assert!(multi_value.is_empty());
}