Releases: rhaiscript/rhai
v1.20.0
Bug fixes
- (Fuzzing) An integer-overflow bug from an inclusive range in the bits iterator is fixed.
- (Fuzzing) An integer-underflow bug from an inclusive range is fixed.
- Copy strings if the strings interner is busy instead of panicing (thanks
@irevoire
917). - Deserialization of
Scope
now works correctly (thanks@AngelicosPhosphoros
918). - Support for
thumbv6m
target is fixed (thankschxry
919)
New features
- Added support for raw strings with the syntax
##..#" ... "#..##
(thanks@cellomath
908 910).
Enhancements
v1.19.0
Bug fixes
- Variable resolver now correctly resolves variables that are captured in a closure.
NativeCallContext<'_>
(with a lifetime parameter) now parses correctly in the#[export_module]
macro. This is to allow forrust_2018_idioms
lints (thanks@ltabis
864).- The
sync
feature now works properly inno-std
builds (thanks@misssonder
874). - More data-race conditions are caught and returned as errors instead of panicking.
- Missing
min
andmax
functions where both operands are floats orDecimal
are added. - Fixed stack overflow when calling closures recursively (thanks
@MageWeiG
880). Engine::call_fn
andEngine::call_fn_with_options
now correctly use theAST
'ssource
field.- (Fuzzing) Fixed crash when using
..=
in strings. - (Fuzzing) A recursive stack-overflow bug in
Dynamic::is_hashable
is fixed.
New features
- The
break
,continue
,return
andthrow
statements can now follow the??
operator to short-circuit operations where the value is()
. - A new symbol,
$func$
, is added to custom syntax to allow parsing of anonymous functions. - The
filter
,drain
andretain
methods are added to object maps.
v1.18.0
Starting from this version, we try to put contributors' names on features/enhancements/fixes that they contributed.
We apologize for neglecting to adopt this practice earlier, but late is better than never!
Bug fixes
- The position of an undefined operation call now points to the operator instead of the first operand.
- The
optimize
command inrhai-repl
now works properly and cycles throughNone
->Simple
->Full
. Engine::call_fn_XXX
no longer return errors unnecessarily wrapped inEvalAltResult::ErrorInFunctionCall
.- Some tests that panic on 32-bit architecture are fixed (thanks
@alexanderkjall
#851). - The optimizer no longer goes into an infinite loop when optimizing a
try
statement with an empty body.
Deprecated API's
- The plugin macros
export_fn
,register_exported_fn!
,set_exported_fn!
andset_exported_global_fn!
are deprecated because they do not add value over existing direct API's.
New features
- Sub-strings can now be selected from full strings by indexing via ranges, e.g.
s[1..4]
(thanks@zitsen
#845). - Doc-comments are now automatically added to function registrations and custom types via the
CustomType
derive macro (thanks@Itabis
#847). - New options
Engine::set_max_strings_interned
andEngine::max_strings_interned
are added to limit the maximum number of strings interned in theEngine
's string interner. - A new advanced callback,
Engine::on_invalid_array_index
, is added (gated under theinternals
feature) to handle access to missing properties in object maps. - A new advanced callback,
Engine::on_missing_map_property
, is added (gated under theinternals
feature) to handle out-of-bound index into arrays.
Enhancements
parse_json
is also available without themetadata
orserde
feature -- it usesEngine::parse_json
to parse the JSON text (thanks@Mathieu-Lala
#840).FuncRegistration::in_global_namespace
andFuncRegistration::in_internal_namespace
are added to avoid pulling inFnNamespace
.- Array/BLOB/string iterators are defined also within the
BasicIteratorPackage
in addition to the regular array/BLOB/string packages. LexError::Runtime
is added for use withEngine::on_parse_token
.- Shared values under
sync
are now handled more elegantly -- instead of deadlocking and hanging indefinitely, it spins for a number of tries (waiting one second between each), then errors out.
v1.17.1
v1.17.0
Starting from this version, the official preferred method of registering an API for a custom type is via the #[derive(CustomType)]
macro. The old API is still available for types that reside in external crates (and thus cannot implement CustomType
).
Starting from this version, the new FuncRegistration
API is preferred for registering native Rust functions into a Module
. The old API is still available but deprecated.
Starting from this version, fuzzing via Google OSS-Fuzz is used to flush out hidden bugs and edge cases. This should result in higher code quality, better stability and improved security. And indeed, a large number of bugs have been discovered from this and fixed.
Potentially breaking changes
ImmutableString
now derefs to&str
instead of&SmartString
. Normally this should not be a breaking change.- Traits implemented by
ImmutableString
are cleaned up. Normally this should not be a breaking change. EvalContext::new
,FloatWrapper
andConditionalExpr
are now gated underinternals
.- Previously, Rhai follows Unicode's definition for whitespace, which allows many exotic whitespace characters in scripts. Starting from this version, whitespace follows WhatWG's definition of five ASCII characters (TAB, SPACE, CR, LF and FF), which is the same as Rust. All other Unicode whitespace characters (not inside strings) are not considered whitespace by Rhai. If a script used to contain non-ASCII whitespace characters, it now fails to parse with a syntax error.
New features
#[derive(CustomType)]
is now available, driven by procedural macros inrhai_codegen
.- A new
FuncRegistration
API is added to assist in registering native Rust functions into modules with various settings. Some of the originalModule::set_fn...
API is now deprecated. - Functions defined in plugin modules can now be marked as
volatile
which prevents it from being optimized away even underOptimizationLevel::Full
. - Added
Engine::max_functions
andEngine::set_max_functions
to limit the maximum number of functions allowed in a script. This is to guard against DOS attacks -- e.g. a simple closure||
(two characters) is a function. Whenmax_function
is exceeded during script compilation, a new parse error,ParseErrorType::TooManyFunctions
, is returned. Engine::get_interned_string
is made public instead of gated underinternals
.
Deprecated API's
rhai::config::hashing::set_ahash_seed
,rhai::config::hashing::get_ahash_seed
and theRHAI_AHASH_SEED
environment variable are deprecated in favor ofrhai::config::hashing::set_hashing_seed
,rhai::config::hashing::get_hashing_seed
andRHAI_HASHING_SEED
.AST::clear_doc
is deprecated.- Much of the
Module::update_XXX
API is deprecated in favor of using theFuncRegistration
API. Module::gen_fn_signatures
is deprecated in favor ofModule::gen_fn_signatures_with_mapper
.
Fixes to bugs found via fuzzing
- Fixed crash when parsing multi-segment interpolated string longer than maximum.
- Fixed crash when parsing unterminated comment.
- Fixed crash when parsing deeply-nested right-associated operators such as
**
. - Fixed crash when parsing combo-chaining expressions such as
(a.b).c
. - Fixed crash when calling functions that have
Dynamic
parameters with more than 16 parameters. - Fixed crash when indexing into an empty array with negative index.
- Indexing into an array with a negative index that is larger than the length of the array now throws an out-of-bounds error (similar to positive indices) instead of defaulting to the first element.
- Fixed edge-case crash in timestamp functions.
- Fixed crash when indenting a block doc-comment with Unicode multi-byte space characters.
- Fixed improper parsing of numbers with too many decimal points.
- Fixed exponential running time when raising a decimal number to a very large power (> 1 million) -- it now returns an overflow error.
- Shared values that contain reference loops no longer cause a stack overflow when printing.
sleep
no longer panics onNaN
.switch
on ranges now work properly.
Other bug fixes
- Arrays in object maps now serialize to JSON correctly via
to_json()
when theserde
feature is not enabled. Engine::format_map_as_json
now serializes arrays correctly.Engine::gen_fn_signatures(false)
now properly skips functions in the standard library.TypeBuilder::with_name
now properly sets the display-name of the type for use in generating metadata.
Enhancements
- Avoid cloning values unless needed when performing constants propagation in optimization.
- Added
to_int
method for characters. Token::FloatConstant
andToken::DecimalConstant
now carry the original text representation for use in, say, a token mapper.Dynamic::is_fnptr
is made a public API.Scope::get_value_ref
andScope::get_value_mut
are added.TypeBuilder::with_name
now takes any&str
instead of just&'static str
.Engine::gen_fn_signatures
now formats the function signatures using pretty-print names of custom types.
v1.16.3
v1.16.2
v1.16.1
v1.16.0
This version is a general code cleanup such that it relies less on obscure hacks unless those tricks provide genuine performance benefits. It should make the code base easier to follow for new contributors.
The minimum Rust compiler version is raised to 1.66.0
.
Potentially-breaking changes
- Limit functions (e.g.
max_operations
,max_array_size
etc.) as well asEngine::ensure_data_size_within_limits
are no longer exported underunchecked
. This should be the correct behavior instead of returningNone
or zero. - The type
OptimizationLevel
is no longer exported underno_optimize
. Originally it was mapped to()
underno_optimize
. - O/S features such as file access and time are no longer disabled when using
wasm32-wasi
(or any WASM target other thanwasm32-unknown
).
Bug fixes
- Fixes a panic when using
this
as the first parameter in a namespace-qualified function call. - Comparing two different data types (e.g. a custom type and a standard type) now correctly defaults to
false
(except for!=
which defaults totrue
). max
andmin
for integers, strings and characters were missing from the standard library. They are now added.
Dependencies
- Minimal version numbers for dependencies are now specified in
Cargo.toml
to avoid breaking changes in future versions. bitflags
is bumped to version 2.syn
inrhai_codegen
is bumped to version 2.hashbrown
(used inno-std
builds) is bumped to version 0.14.
Deprecated API's
ParseErrorType::MalformedCallExpr
andParseErrorType::MalformedInExpr
are deprecated and will be removed in the next major version.Module::get_custom_type
is deprecated in favor ofModule::get_custom_type_display_by_name
and other new methods.
New features
- New
exit
function that terminates script evaluation regardless of where it is called, even inside deeply-nested function calls. - Added
Engine::max_variables
andEngine::set_max_variables
to limit the maximum number of variables allowed within a scope at any time. This is to guard against defining a huge number of variables containing large data just beyond individual data size limits. Whenmax_variables
is exceeded a new error,ErrorTooManyVariables
, is returned. - Added
zip
function for arrays. - Added
on_print
andon_debug
definitions forTypeBuilder
. - Doc-comments are now included in custom type definitions within plugin modules. They can be accessed via
Module::get_custom_type_raw
. These doc-comments for custom types are also exported in JSON viaEngine::gen_fn_metadata_to_json
.
Enhancements
once_cell
is used instd
environments instead of the home-brewSusLock
which is removed.- Originally, unit tests use the
?
operator liberally to simplify code. However, this causes the loss of proper line numbers when a test fails, making it difficult to identify the exact location of the failure. This is now fixed by changing tounwrap()
. - Many inlined collections are turned back into
Vec
because they are not transient and do not appear to improve performance. UsingVec
seems to be yield better performance as it probably enables more compiler optimizations. - General code clean-up to remove optimizations tricks that are not obviously beneficial in favor of clearer code.