From 5ac33ce64def4a54eeb3a680950ab027eded9952 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 4 Sep 2021 18:43:18 +0800 Subject: [PATCH 1/6] Do not export `FloatWrapper` under `no_float`. --- CHANGELOG.md | 6 ++++++ src/lib.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 121f589e..73928b0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Rhai Release Notes ================== +Version 1.0.5 +============= + +* `FloatWrapper` is no longer erroneously exported under `no_float+internals`. + + Version 1.0.4 ============= diff --git a/src/lib.rs b/src/lib.rs index 614a8fb8..f26ad35b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -227,10 +227,15 @@ pub use token::{InputStream, Token, TokenizeState, TokenizerControl, TokenizerCo #[cfg(feature = "internals")] #[deprecated = "this type is volatile and may change"] pub use ast::{ - ASTNode, BinaryExpr, CustomExpr, Expr, FloatWrapper, FnCallExpr, FnCallHashes, Ident, - OpAssignment, OptionFlags, ReturnType, ScriptFnDef, Stmt, StmtBlock, AST_OPTION_FLAGS::*, + ASTNode, BinaryExpr, CustomExpr, Expr, FnCallExpr, FnCallHashes, Ident, OpAssignment, + OptionFlags, ReturnType, ScriptFnDef, Stmt, StmtBlock, AST_OPTION_FLAGS::*, }; +#[cfg(feature = "internals")] +#[cfg(not(feature = "no_float"))] +#[deprecated = "this type is volatile and may change"] +pub use ast::FloatWrapper; + #[cfg(feature = "internals")] #[deprecated = "this type is volatile and may change"] pub use engine::{EvalState, FnResolutionCache, FnResolutionCacheEntry, Imports}; From 08155c0978c808dae273d54e8b85c36bbc145a9a Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 14 Sep 2021 22:33:10 +0800 Subject: [PATCH 2/6] Fix sign function for NaN. --- src/packages/arithmetic.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/packages/arithmetic.rs b/src/packages/arithmetic.rs index 074b19cf..66c05978 100644 --- a/src/packages/arithmetic.rs +++ b/src/packages/arithmetic.rs @@ -163,13 +163,7 @@ macro_rules! gen_signed_functions { } } pub fn sign(x: $arg_type) -> INT { - if x == 0 { - 0 - } else if x < 0 { - -1 - } else { - 1 - } + x.signum() as INT } } })* } @@ -249,6 +243,8 @@ gen_signed_functions!(signed_num_128 => i128); #[cfg(not(feature = "no_float"))] #[export_module] mod f32_functions { + use crate::EvalAltResult; + #[cfg(not(feature = "f32_float"))] pub mod basic_arithmetic { #[rhai_fn(name = "+")] @@ -329,13 +325,15 @@ mod f32_functions { pub fn abs(x: f32) -> f32 { x.abs() } - pub fn sign(x: f32) -> INT { + #[rhai_fn(return_raw)] + pub fn sign(x: f32) -> Result> { if x == 0.0 { - 0 - } else if x < 0.0 { - -1 + Ok(0) } else { - 1 + match x.signum() { + x if x.is_nan() => Err(make_err("Sign of NaN is undefined")), + x => Ok(x as INT), + } } } pub fn is_zero(x: f32) -> bool { @@ -437,13 +435,15 @@ mod f64_functions { pub fn abs(x: f64) -> f64 { x.abs() } - pub fn sign(x: f64) -> INT { + #[rhai_fn(return_raw)] + pub fn sign(x: f64) -> Result> { if x == 0.0 { - 0 - } else if x < 0.0 { - -1 + Ok(0) } else { - 1 + match x.signum() { + x if x.is_nan() => Err(make_err("Sign of NaN is undefined")), + x => Ok(x as INT), + } } } pub fn is_zero(x: f64) -> bool { From c23164619730f862dfe0ef4b70acd167ead76651 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 15 Sep 2021 10:31:46 +0800 Subject: [PATCH 3/6] Add sign function fixes. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73928b0f..d2c67a38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ Rhai Release Notes Version 1.0.5 ============= +Bug fixes +--------- + * `FloatWrapper` is no longer erroneously exported under `no_float+internals`. +* The `sign` function now works properly for float values that are `NaN`. Version 1.0.4 From 5d47ebf57a2bcb956396e377afb2b55804ed0d82 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 18 Sep 2021 10:14:54 +0800 Subject: [PATCH 4/6] Add test for constants to Scope::get_mut. --- src/scope.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scope.rs b/src/scope.rs index 823d640d..73934593 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -397,6 +397,9 @@ impl<'a> Scope<'a> { /// *ptr = 123_i64.into(); /// /// assert_eq!(my_scope.get_value::("x").unwrap(), 123); + /// + /// my_scope.push_constant("Z", 1_i64); + /// assert!(my_scope.get_mut("Z").is_none()); /// ``` #[inline] #[must_use] From 661d00bc94b04eb288f4b9d8b1bbbae18367ce0d Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 19 Sep 2021 22:08:29 +0800 Subject: [PATCH 5/6] Fix test output. --- codegen/ui_tests/rhai_fn_non_clonable_return.stderr | 5 ++++- codegen/ui_tests/rhai_mod_non_clonable_return.stderr | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/codegen/ui_tests/rhai_fn_non_clonable_return.stderr b/codegen/ui_tests/rhai_fn_non_clonable_return.stderr index d614b6bc..3dea1ebc 100644 --- a/codegen/ui_tests/rhai_fn_non_clonable_return.stderr +++ b/codegen/ui_tests/rhai_fn_non_clonable_return.stderr @@ -2,7 +2,10 @@ error[E0277]: the trait bound `NonClonable: Clone` is not satisfied --> $DIR/rhai_fn_non_clonable_return.rs:11:8 | 11 | pub fn test_fn(input: f32) -> NonClonable { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable` + | ^^^^^^^^^^^^^^^^^^^^^^^----------- + | | | + | | required by a bound introduced by this call + | the trait `Clone` is not implemented for `NonClonable` | note: required by a bound in `rhai::Dynamic::from` --> $DIR/dynamic.rs:1043:30 diff --git a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr index a660003d..aa542503 100644 --- a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr +++ b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr @@ -2,7 +2,10 @@ error[E0277]: the trait bound `NonClonable: Clone` is not satisfied --> $DIR/rhai_mod_non_clonable_return.rs:12:12 | 12 | pub fn test_fn(input: f32) -> NonClonable { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable` + | ^^^^^^^^^^^^^^^^^^^^^^^----------- + | | | + | | required by a bound introduced by this call + | the trait `Clone` is not implemented for `NonClonable` | note: required by a bound in `rhai::Dynamic::from` --> $DIR/dynamic.rs:1043:30 From caf3c7e698bc42fe33f2a8a19b16a9ed55916593 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 19 Sep 2021 22:31:50 +0800 Subject: [PATCH 6/6] Bump version. --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c67a38..85391dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Rhai Release Notes ================== +Version 1.0.6 +============= + + Version 1.0.5 ============= diff --git a/Cargo.toml b/Cargo.toml index e439d986..d4e7675d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "codegen"] [package] name = "rhai" -version = "1.0.5" +version = "1.0.6" edition = "2018" authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung", "jhwgh1968"] description = "Embedded scripting for Rust"