From 669bbbe43b56441837a46fbba22ceac4ee40cab6 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Mon, 14 Jun 2021 08:36:30 +0100 Subject: [PATCH 01/13] Merge pull request #208 from amethyst/fix_compilefail_207 Fix the tests, as of rust 1.52.1 and num-traits 0.2.14. --- Cargo.toml | 2 +- src/conversion.rs | 11 +++++++++++ tests/compile-fail/context_nounwindsafe.rs | 2 +- tests/compile-fail/lua_norefunwindsafe.rs | 2 +- tests/compile-fail/scope_callback_capture.rs | 3 +-- tests/compile-fail/scope_callback_inner.rs | 4 ++-- tests/compile-fail/scope_callback_outer.rs | 3 ++- tests/userdata.rs | 4 ++-- 8 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b3302db8..ebcd5210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ system-lua = ["pkg-config"] [dependencies] libc = { version = "0.2" } -num-traits = { version = "0.2.6" } +num-traits = { version = "0.2.14" } bitflags = { version = "1.0.4" } bstr = {version = "0.2", features = ["std"], default_features = false } diff --git a/src/conversion.rs b/src/conversion.rs index 2647ec6b..ecd85de5 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -359,6 +359,17 @@ macro_rules! lua_convert_float { message: Some("expected number or string coercible to number".to_string()), }) .and_then(|n| { + // We want out of range f32 to return an error instead + // of inf. + if std::mem::size_of::<$x>() < std::mem::size_of::() { + if n.is_finite() && n.abs() > (<$x>::MAX as f64) { + return Err(Error::FromLuaConversionError { + from: ty, + to: stringify!($x), + message: Some("number out of range".to_string()), + }); + } + } cast(n).ok_or_else(|| Error::FromLuaConversionError { from: ty, to: stringify!($x), diff --git a/tests/compile-fail/context_nounwindsafe.rs b/tests/compile-fail/context_nounwindsafe.rs index 1c2ec54b..5d43fe95 100644 --- a/tests/compile-fail/context_nounwindsafe.rs +++ b/tests/compile-fail/context_nounwindsafe.rs @@ -7,7 +7,7 @@ use rlua::Lua; fn main() { Lua::new().context(|lua| { catch_unwind(move || { - //~^ error: the type `std::cell::UnsafeCell<()>` may contain interior mutability and a reference + //~^ error: the type `UnsafeCell<()>` may contain interior mutability and a reference // may not be safely transferrable across a catch_unwind boundary lua.create_table().unwrap(); }); diff --git a/tests/compile-fail/lua_norefunwindsafe.rs b/tests/compile-fail/lua_norefunwindsafe.rs index 668eab43..3deb9d85 100644 --- a/tests/compile-fail/lua_norefunwindsafe.rs +++ b/tests/compile-fail/lua_norefunwindsafe.rs @@ -7,7 +7,7 @@ use rlua::Lua; fn main() { let lua = Lua::new(); catch_unwind(|| { - //~^ error: the type `std::cell::UnsafeCell<()>` may contain interior mutability and a reference + //~^ error: the type `UnsafeCell<()>` may contain interior mutability and a reference // may not be safely transferrable across a catch_unwind boundary lua.context(|lua| { lua.create_table().unwrap(); diff --git a/tests/compile-fail/scope_callback_capture.rs b/tests/compile-fail/scope_callback_capture.rs index 165baebc..59d93831 100644 --- a/tests/compile-fail/scope_callback_capture.rs +++ b/tests/compile-fail/scope_callback_capture.rs @@ -11,9 +11,8 @@ fn main() { lua.scope(|scope| { let mut inner: Option = None; let f = scope + //~^ error: borrowed data escapes outside of closure .create_function_mut(move |lua, t: Table| { - //~^ error: cannot infer an appropriate lifetime for autoref due to conflicting - // requirements if let Some(old) = inner.take() { // Access old callback `Lua`. } diff --git a/tests/compile-fail/scope_callback_inner.rs b/tests/compile-fail/scope_callback_inner.rs index b07dd970..823cdc31 100644 --- a/tests/compile-fail/scope_callback_inner.rs +++ b/tests/compile-fail/scope_callback_inner.rs @@ -11,9 +11,9 @@ fn main() { lua.scope(|scope| { let mut inner: Option
= None; let f = scope + //~^ error: borrowed data escapes outside of closure .create_function_mut(|_, t: Table| { - //~^ error: cannot infer an appropriate lifetime for autoref due to conflicting - // requirements + //~^ error: closure may outlive the current function, but it borrows `inner` inner = Some(t); Ok(()) }) diff --git a/tests/compile-fail/scope_callback_outer.rs b/tests/compile-fail/scope_callback_outer.rs index 795d0135..3983179b 100644 --- a/tests/compile-fail/scope_callback_outer.rs +++ b/tests/compile-fail/scope_callback_outer.rs @@ -11,9 +11,10 @@ fn main() { let mut outer: Option
= None; lua.scope(|scope| { let f = scope + //~^ error: borrowed data escapes outside of closure .create_function_mut(|_, t: Table| { - //~^^ error: borrowed data cannot be stored outside of its closure outer = Some(t); + //~^ error: `outer` does not live long enough Ok(()) }) .unwrap(); diff --git a/tests/userdata.rs b/tests/userdata.rs index 555643e7..f204b620 100644 --- a/tests/userdata.rs +++ b/tests/userdata.rs @@ -9,8 +9,8 @@ fn test_user_data() { struct UserData1(i64); struct UserData2(Box); - impl UserData for UserData1 {}; - impl UserData for UserData2 {}; + impl UserData for UserData1 {} + impl UserData for UserData2 {} Lua::new().context(|lua| { let userdata1 = lua.create_userdata(UserData1(1)).unwrap(); From c9cdb5f13e2fb6783888159d68cd11459f8e354f Mon Sep 17 00:00:00 2001 From: Robert Masen Date: Tue, 31 Aug 2021 15:04:27 -0500 Subject: [PATCH 02/13] add feature for LUA_COMPAT_MATHLIB --- Cargo.toml | 3 +++ build.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ebcd5210..8ecc4260 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,9 @@ builtin-lua = ["cc"] # the final binary manually. The builtin-lua and system-lua features are # mutually exclusive and enabling both will cause an error at build time. system-lua = ["pkg-config"] +# Enabled functions from the math module that have been deprecated +lua-compat-mathlib = [] + [dependencies] libc = { version = "0.2" } diff --git a/build.rs b/build.rs index d33aa6af..34d4c118 100644 --- a/build.rs +++ b/build.rs @@ -25,6 +25,9 @@ fn main() { if cfg!(debug_assertions) { config.define("LUA_USE_APICHECK", None); } + if cfg!(feature = "lua-compat-mathlib") { + config.define("LUA_COMPAT_MATHLIB", None); + } config .include("lua") From 08abb3ba62c984ff6f893a7b656d58c30a8dec8c Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Mon, 13 Sep 2021 20:13:54 +0100 Subject: [PATCH 03/13] Merge pull request #214 from amethyst/release_checklist Add initial release checklist. --- RELEASE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 RELEASE.md diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 00000000..91001fdb --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,11 @@ +# rlua release checklist + +* Basic README.md check +* Update CHANGELOG.md with important changes since last release +* For a maintenance release: + * Check if there are any bugfixes on master which should be included +* Update version number in Cargo.toml +* Check that CI is passing +* Run `cargo publish` +* Check that the version from crates.io looks good +* Update version number on branch to (next version)-alpha. From de424833fdab1c501cf2da8ebf1d656ab90559cb Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Mon, 13 Sep 2021 20:20:52 +0100 Subject: [PATCH 04/13] Update CHANGELOG.md for 0.17.1. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bcedd83..1809e2ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.17.1] +- Add "lua-compat-mathlib" feature, which enables Lua's LUA_COMPAT_MATHLIB + option. +- Bump num-traits version to 0.2.14 and fix some incompatibilities +- Fix some tests from improved diagnostics in recent rustc. + ## [0.17] - API incompatible change: depend on `bstr` crate and implement `ToLua` / `FromLua` for `BString` and `BStr` types (thanks @azdle!) From 7a6253800a8a7fd4d65794cfb8c63156132585c3 Mon Sep 17 00:00:00 2001 From: kyren Date: Sat, 30 Nov 2019 02:41:10 -0500 Subject: [PATCH 05/13] Merge pull request #156 from amberkowalski/patch-1 Fixed spelling errors in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c630048..92d7ecd0 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ If you encounter them, a bug report would be very welcome: ## Sandboxing and Untrusted Scripts The API now contains the pieces necessary to implement simple, limited -"sanboxing" of Lua scripts by controlling their environment, limiting their +"sandboxing" of Lua scripts by controlling their environment, limiting their allotted VM instructions, and limiting the amount of memory they may allocate. These features deserve a few words of warning: **Do not use them to run @@ -107,7 +107,7 @@ First, this library contains a huge amount of unsafe code, and I currently certainly bugs still lurking in this library! It is surprisingly, fiendishly difficult to use the Lua C API without the potential for unsafety. -Second, properly sandobxing Lua scripts can be quite difficult, much of the +Second, properly sandboxing Lua scripts can be quite difficult, much of the stdlib is unsafe, and sometimes in surprising ways. Some information on this can be found [here](http://lua-users.org/wiki/SandBoxes). From e8b53da30109166f1684e99d10512bcb760ce2d5 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Mon, 13 Sep 2021 20:25:57 +0100 Subject: [PATCH 06/13] Update Cargo.toml in preparation for 0.17.1 release. --- Cargo.toml | 6 +++--- RELEASE.md | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ecc4260..b05ed3aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "rlua" -version = "0.17.1-alpha.0" +version = "0.17.1" authors = ["kyren "] edition = "2018" description = "High level bindings to Lua 5.3" -repository = "https://github.com/kyren/rlua" +repository = "https://github.com/amethyst/rlua" documentation = "https://docs.rs/rlua" readme = "README.md" keywords = ["lua"] license = "MIT" [badges] -circle-ci = { repository = "kyren/rlua", branch = "master" } +circle-ci = { repository = "amethyst/rlua", branch = "master" } [features] default = ["builtin-lua"] diff --git a/RELEASE.md b/RELEASE.md index 91001fdb..87da988e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -5,6 +5,7 @@ * For a maintenance release: * Check if there are any bugfixes on master which should be included * Update version number in Cargo.toml +* Check other fields in Cargo.toml are sensible * Check that CI is passing * Run `cargo publish` * Check that the version from crates.io looks good From 5ec03cb160d63bfbe5f891cd6bd062dd43b35483 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Mon, 13 Sep 2021 20:29:40 +0100 Subject: [PATCH 07/13] Update some links for the new github location. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92d7ecd0..dbde8832 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # rlua -- High level bindings between Rust and Lua -[![Build Status](https://img.shields.io/circleci/project/github/kyren/rlua.svg)](https://circleci.com/gh/kyren/rlua) +[![Build Status](https://img.shields.io/circleci/project/github/amethyst/rlua.svg)](https://circleci.com/gh/amethyst/rlua) [![Latest Version](https://img.shields.io/crates/v/rlua.svg)](https://crates.io/crates/rlua) [![API Documentation](https://docs.rs/rlua/badge.svg)](https://docs.rs/rlua) From 1fb524f5db6c9665a03639203ef072637e7f3c7c Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Mon, 13 Sep 2021 20:39:35 +0100 Subject: [PATCH 08/13] Add tag to the release checklist. --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index 87da988e..f7edcd31 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -7,6 +7,7 @@ * Update version number in Cargo.toml * Check other fields in Cargo.toml are sensible * Check that CI is passing +* Tag the commit for the release * Run `cargo publish` * Check that the version from crates.io looks good * Update version number on branch to (next version)-alpha. From 4920ad24fb2f493ba67ae073b5f0ed66d6e3c23e Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Sun, 14 Nov 2021 22:20:50 +0000 Subject: [PATCH 09/13] Some updates to README.md. Mention multiple versions and update some links. --- README.md | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 92d7ecd0..174a9710 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # rlua -- High level bindings between Rust and Lua -[![Build Status](https://img.shields.io/circleci/project/github/kyren/rlua.svg)](https://circleci.com/gh/kyren/rlua) +[![Build Status](https://img.shields.io/circleci/project/github/amethyst/rlua.svg)](https://circleci.com/gh/amethyst/rlua) [![Latest Version](https://img.shields.io/crates/v/rlua.svg)](https://crates.io/crates/rlua) [![API Documentation](https://docs.rs/rlua/badge.svg)](https://docs.rs/rlua) @@ -22,14 +22,34 @@ something you feel could perform better, feel free to file a bug report. ## API stability Currently, this library follows a pre-1.0 semver, so all API changes should be -accompanied by 0.x version bumps. +accompanied by 0.x version bumps. See the [Version 1.0 +milestone](https://github.com/amethyst/rlua/milestone/1) for the work planned +to be done before a more stable 1.0 release. -*The new 0.16 release has a particularly large amount of API breakage which was -required to fix several long-standing limitations and bugs. The biggest change -by far is that most API usage now takes place through `Lua::context` callbacks -rather than directly on the main `Lua` state object. See CHANGELOG.md for -information about other API changes, and also see the guided tour for an example -of using the new `Context` API.* +## Lua versions supported + +As of release 0.18, the version of Lua can be configured at build time using +Cargo features. Lua 5.4 is the default. The rlua API stays the same with +different Lua versions, though there are a small number of limitations. Lua +code may, of course, behave a little differently between the versions. + +Only one can be selected at a time, so to select anything +other than the default (built-in Lua 5.4) you will need to disable default +features. + +The available features are: + +| Cargo feature | Lua version | +| ------------- | ----------- | +| builtin-lua54 | Lua 5.4 (source included in crate, default) | +| builtin-lua53 | Lua 5.3 (source included in crate) | +| system-lua51 | Lua 5.1 (installed on host system, found using pkg-config) | +| system-lua53 | Lua 5.3 (installed on host system, found using pkg-config) | +| system-lua54 | Lua 5.4 (installed on host system, found using pkg-config) | + +At current writing rlua has not been tested with alternative Lua +implementations (such as Luajit) which share PUC-Rio Lua's C API, but it is +expected that they can be made to work with little if any change to rlua. ## Safety and Panics @@ -79,7 +99,7 @@ If you encounter them, a bug report would be very welcome: define set. Any abort caused by this internal Lua API checking is definitely a bug, and is likely to be a soundness bug because without `LUA_USE_APICHECK` it would likely instead be UB. - * Lua C API errors are handled by lonjmp. All instances where the Lua C API + * Lua C API errors are handled by longjmp. All instances where the Lua C API would otherwise longjmp over calling stack frames should be guarded against, except in internal callbacks where this is intentional. If you detect that `rlua` is triggering a longjmp over your Rust stack frames, this is a bug! From d1a97dbc43ca98e43b04ecaf5f4e6ee9cca6cb70 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Sun, 14 Nov 2021 22:25:48 +0000 Subject: [PATCH 10/13] Update release checklist. --- RELEASE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index 91001fdb..f7edcd31 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -5,7 +5,9 @@ * For a maintenance release: * Check if there are any bugfixes on master which should be included * Update version number in Cargo.toml +* Check other fields in Cargo.toml are sensible * Check that CI is passing +* Tag the commit for the release * Run `cargo publish` * Check that the version from crates.io looks good * Update version number on branch to (next version)-alpha. From 74b8ce973fd570209bc60c840fd609903a9dde7f Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Sun, 14 Nov 2021 22:27:01 +0000 Subject: [PATCH 11/13] Fix repository link. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d00a0b63..048aef7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.18.0-alpha.0" authors = ["kyren "] edition = "2018" description = "High level bindings to Lua 5.x" -repository = "https://github.com/kyren/rlua" +repository = "https://github.com/amethyst/rlua" documentation = "https://docs.rs/rlua" readme = "README.md" keywords = ["lua"] From 1d9c1700db9bb18c6289dafa09a1d08d434ebe35 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Sun, 14 Nov 2021 22:39:31 +0000 Subject: [PATCH 12/13] Update changelog for 0.18.0-alpha.0 release. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1809e2ce..53f70a89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.18.0-alpha.0] +- Add support for multiple Lua versions, including 5.1, 5.3 and 5.4 (the default) +- Add implementations of `FromLua` and `ToLua` for `[T;N]`. + ## [0.17.1] - Add "lua-compat-mathlib" feature, which enables Lua's LUA_COMPAT_MATHLIB option. From ae00cc237d8c657a6193155eea4a04241fa2ed62 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Sun, 14 Nov 2021 22:43:42 +0000 Subject: [PATCH 13/13] Fix merge error in Cargo.toml. --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4c1de0cf..6b84e8f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "rlua" version = "0.18.0-alpha.0" -version = "0.17.1" authors = ["kyren "] edition = "2018" description = "High level bindings to Lua 5.x"